2021-06-26 22:02:00 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
// SPDX-FileCopyrightText: 2021 Oliver RÜmpelein
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-03-22 10:18:43 +01:00
|
|
|
import { ModifiableDataBaseTotal } from "../common/common-data";
|
2021-01-25 01:09:51 +01:00
|
|
|
import { DS4 } from "../config";
|
2021-07-07 19:22:35 +02:00
|
|
|
import { getGame } from "../helpers";
|
2021-06-30 03:53:52 +02:00
|
|
|
import { DS4ArmorDataProperties, DS4ShieldDataProperties } from "../item/item-data-properties";
|
2021-07-07 19:22:35 +02:00
|
|
|
import { ItemType } from "../item/item-data-source";
|
2021-03-24 09:19:26 +01:00
|
|
|
import { createCheckRoll } from "../rolls/check-factory";
|
2021-06-30 02:17:54 +02:00
|
|
|
import { Check } from "./actor-data-properties";
|
2021-07-07 19:22:35 +02:00
|
|
|
import { isAttribute, isTrait } from "./actor-data-source";
|
2021-06-30 03:53:52 +02:00
|
|
|
|
|
|
|
declare global {
|
|
|
|
interface DocumentClassConfig {
|
|
|
|
Actor: typeof DS4Actor;
|
|
|
|
}
|
|
|
|
}
|
2020-12-23 18:23:26 +01:00
|
|
|
|
2021-02-07 11:51:36 +01:00
|
|
|
/**
|
|
|
|
* The Actor class for DS4
|
|
|
|
*/
|
2021-06-30 02:17:54 +02:00
|
|
|
export class DS4Actor extends Actor {
|
2021-01-25 01:09:51 +01:00
|
|
|
/** @override */
|
|
|
|
prepareData(): void {
|
2021-06-30 02:17:54 +02:00
|
|
|
this.data.reset();
|
2021-01-25 01:09:51 +01:00
|
|
|
this.prepareBaseData();
|
|
|
|
this.prepareEmbeddedEntities();
|
2021-02-16 16:34:23 +01:00
|
|
|
this.applyActiveEffectsToBaseData();
|
2021-01-25 01:09:51 +01:00
|
|
|
this.prepareDerivedData();
|
|
|
|
this.applyActiveEffectsToDerivedData();
|
2021-02-16 15:39:18 +01:00
|
|
|
this.prepareFinalDerivedData();
|
2021-01-25 01:09:51 +01:00
|
|
|
}
|
|
|
|
|
2021-01-25 10:32:13 +01:00
|
|
|
/** @override */
|
|
|
|
prepareBaseData(): void {
|
|
|
|
const data = this.data;
|
2021-02-16 16:34:23 +01:00
|
|
|
|
2021-03-04 00:54:41 +01:00
|
|
|
data.data.rolling = {
|
|
|
|
minimumFumbleResult: 20,
|
|
|
|
maximumCoupResult: 1,
|
|
|
|
};
|
2021-03-04 00:41:57 +01:00
|
|
|
|
2021-01-25 10:32:13 +01:00
|
|
|
const attributes = data.data.attributes;
|
|
|
|
Object.values(attributes).forEach(
|
2021-03-22 10:18:43 +01:00
|
|
|
(attribute: ModifiableDataBaseTotal<number>) => (attribute.total = attribute.base + attribute.mod),
|
2021-01-25 10:32:13 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const traits = data.data.traits;
|
2021-03-22 10:18:43 +01:00
|
|
|
Object.values(traits).forEach(
|
|
|
|
(trait: ModifiableDataBaseTotal<number>) => (trait.total = trait.base + trait.mod),
|
|
|
|
);
|
2021-01-25 10:32:13 +01:00
|
|
|
}
|
|
|
|
|
2021-06-30 02:17:54 +02:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
* We override this with an empty implementation because we have our own custom way of applying
|
|
|
|
* {@link ActiveEffect}s and {@link Actor#prepareEmbeddedEntities} calls this.
|
|
|
|
*/
|
|
|
|
applyActiveEffects(): void {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-16 16:34:23 +01:00
|
|
|
applyActiveEffectsToBaseData(): void {
|
2021-02-18 13:24:52 +01:00
|
|
|
// reset overrides because our variant of applying active effects does not set them, it only adds overrides
|
|
|
|
this.overrides = {};
|
2021-02-16 15:39:18 +01:00
|
|
|
this.applyActiveEffectsFiltered(
|
|
|
|
(change) =>
|
2021-02-18 13:42:59 +01:00
|
|
|
!this.derivedDataProperties.includes(change.key) &&
|
|
|
|
!this.finalDerivedDataProperties.includes(change.key),
|
2021-02-16 15:39:18 +01:00
|
|
|
);
|
2021-01-25 01:09:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
applyActiveEffectsToDerivedData(): void {
|
2021-02-18 13:42:59 +01:00
|
|
|
this.applyActiveEffectsFiltered((change) => this.derivedDataProperties.includes(change.key));
|
2021-01-25 01:09:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply ActiveEffectChanges to the Actor data which are caused by ActiveEffects and satisfy the given predicate.
|
|
|
|
*
|
2021-02-08 03:38:50 +01:00
|
|
|
* @param predicate - The predicate that ActiveEffectChanges need to satisfy in order to be applied
|
2021-01-25 01:09:51 +01:00
|
|
|
*/
|
2021-06-30 02:17:54 +02:00
|
|
|
applyActiveEffectsFiltered(predicate: (change: foundry.data.ActiveEffectData["changes"][number]) => boolean): void {
|
2021-02-08 03:24:36 +01:00
|
|
|
const overrides: Record<string, unknown> = {};
|
2021-01-25 01:09:51 +01:00
|
|
|
|
2021-08-19 03:04:40 +02:00
|
|
|
// Organize non-disabled and -surpressed effects by their application priority
|
2021-06-30 02:17:54 +02:00
|
|
|
const changes: (foundry.data.ActiveEffectData["changes"][number] & { effect: ActiveEffect })[] =
|
|
|
|
this.effects.reduce(
|
|
|
|
(changes: (foundry.data.ActiveEffectData["changes"][number] & { effect: ActiveEffect })[], e) => {
|
2021-08-19 03:04:40 +02:00
|
|
|
if (e.data.disabled || e.isSurpressed) return changes;
|
2021-06-30 02:17:54 +02:00
|
|
|
|
|
|
|
const newChanges = e.data.changes.filter(predicate).flatMap((c) => {
|
|
|
|
const changeSource = c.toObject();
|
|
|
|
changeSource.priority = changeSource.priority ?? changeSource.mode * 10;
|
2021-08-19 03:04:40 +02:00
|
|
|
return Array(e.factor).fill({ ...changeSource, effect: e });
|
2021-06-30 02:17:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return changes.concat(newChanges);
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
changes.sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0));
|
2021-01-25 01:09:51 +01:00
|
|
|
|
|
|
|
// Apply all changes
|
|
|
|
for (const change of changes) {
|
|
|
|
const result = change.effect.apply(this, change);
|
|
|
|
if (result !== null) overrides[change.key] = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand the set of final overrides
|
2021-07-01 01:08:30 +02:00
|
|
|
this.overrides = foundry.utils.expandObject({ ...foundry.utils.flattenObject(this.overrides), ...overrides });
|
2021-01-25 01:09:51 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 15:39:18 +01:00
|
|
|
/**
|
|
|
|
* Apply transformations to the Actor data after effects have been applied to the base data.
|
|
|
|
* @override
|
|
|
|
*/
|
2020-12-23 18:23:26 +01:00
|
|
|
prepareDerivedData(): void {
|
2021-01-19 03:31:40 +01:00
|
|
|
this._prepareCombatValues();
|
2021-03-24 09:19:26 +01:00
|
|
|
this._prepareChecks();
|
2020-12-23 16:52:20 +01:00
|
|
|
}
|
2021-01-11 00:55:49 +01:00
|
|
|
|
2021-02-16 15:39:18 +01:00
|
|
|
/**
|
|
|
|
* The list of properties that are derived from others, given in dot notation.
|
|
|
|
*/
|
2021-01-25 01:09:51 +01:00
|
|
|
get derivedDataProperties(): Array<string> {
|
2021-03-29 21:20:08 +02:00
|
|
|
const combatValueProperties = Object.keys(DS4.i18n.combatValues).map(
|
|
|
|
(combatValue) => `data.combatValues.${combatValue}.total`,
|
|
|
|
);
|
|
|
|
const checkProperties = Object.keys(DS4.i18n.checks)
|
|
|
|
.filter((check) => check !== "defend")
|
|
|
|
.map((check) => `data.checks.${check}`);
|
|
|
|
return combatValueProperties.concat(checkProperties);
|
2021-01-25 01:09:51 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 15:39:18 +01:00
|
|
|
/**
|
|
|
|
* Apply final transformations to the Actor data after all effects have been applied.
|
|
|
|
*/
|
|
|
|
prepareFinalDerivedData(): void {
|
|
|
|
this.data.data.combatValues.hitPoints.max = this.data.data.combatValues.hitPoints.total;
|
2021-03-24 09:19:26 +01:00
|
|
|
this.data.data.checks.defend = this.data.data.combatValues.defense.total;
|
2021-05-13 15:41:00 +02:00
|
|
|
if (this.data.type === "character") {
|
|
|
|
this.data.data.slayerPoints.max = 3;
|
|
|
|
}
|
2021-02-16 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-16 16:34:23 +01:00
|
|
|
* The list of properties that are completely derived (i.e. {@link ActiveEffect}s cannot be applied to them),
|
|
|
|
* given in dot notation.
|
2021-02-16 15:39:18 +01:00
|
|
|
*/
|
2021-02-18 13:42:59 +01:00
|
|
|
get finalDerivedDataProperties(): string[] {
|
2021-05-13 15:41:00 +02:00
|
|
|
return ["data.combatValues.hitPoints.max", "data.checks.defend"].concat(
|
|
|
|
this.data.type === "character" ? ["data.slayerPoints.max"] : [],
|
|
|
|
);
|
2021-02-16 15:39:18 +01:00
|
|
|
}
|
|
|
|
|
2021-01-11 00:55:49 +01:00
|
|
|
/**
|
|
|
|
* The list of item types that can be owned by this actor.
|
|
|
|
*/
|
|
|
|
get ownableItemTypes(): Array<ItemType> {
|
|
|
|
switch (this.data.type) {
|
|
|
|
case "character":
|
|
|
|
return [
|
|
|
|
"weapon",
|
|
|
|
"armor",
|
|
|
|
"shield",
|
|
|
|
"equipment",
|
2021-02-21 03:40:54 +01:00
|
|
|
"loot",
|
2021-01-13 17:20:25 +01:00
|
|
|
"spell",
|
2021-01-11 00:55:49 +01:00
|
|
|
"talent",
|
|
|
|
"racialAbility",
|
|
|
|
"language",
|
|
|
|
"alphabet",
|
|
|
|
];
|
|
|
|
case "creature":
|
2021-02-21 03:40:54 +01:00
|
|
|
return ["weapon", "armor", "shield", "equipment", "loot", "spell", "specialCreatureAbility"];
|
2021-01-11 00:55:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether or not the given item type can be owned by the actor.
|
2021-02-07 11:51:36 +01:00
|
|
|
* @param itemType - The item type to check
|
2021-01-11 00:55:49 +01:00
|
|
|
*/
|
|
|
|
canOwnItemType(itemType: ItemType): boolean {
|
|
|
|
return this.ownableItemTypes.includes(itemType);
|
|
|
|
}
|
2021-01-19 03:31:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares the combat values of the actor.
|
|
|
|
*/
|
2021-02-16 03:26:26 +01:00
|
|
|
protected _prepareCombatValues(): void {
|
2021-01-19 03:31:40 +01:00
|
|
|
const data = this.data.data;
|
|
|
|
const armorValueOfEquippedItems = this._calculateArmorValueOfEquippedItems();
|
2021-02-16 16:34:23 +01:00
|
|
|
|
2021-03-22 10:28:37 +01:00
|
|
|
data.combatValues.hitPoints.base = data.attributes.body.total + data.traits.constitution.total + 10;
|
2021-01-19 03:31:40 +01:00
|
|
|
data.combatValues.defense.base =
|
2021-03-22 10:28:37 +01:00
|
|
|
data.attributes.body.total + data.traits.constitution.total + armorValueOfEquippedItems;
|
|
|
|
data.combatValues.initiative.base = data.attributes.mobility.total + data.traits.agility.total;
|
|
|
|
data.combatValues.movement.base = data.attributes.mobility.total / 2 + 1;
|
|
|
|
data.combatValues.meleeAttack.base = data.attributes.body.total + data.traits.strength.total;
|
|
|
|
data.combatValues.rangedAttack.base = data.attributes.mobility.total + data.traits.dexterity.total;
|
2021-01-19 03:31:40 +01:00
|
|
|
data.combatValues.spellcasting.base =
|
2021-03-22 10:28:37 +01:00
|
|
|
data.attributes.mind.total + data.traits.aura.total - armorValueOfEquippedItems;
|
2021-01-19 03:31:40 +01:00
|
|
|
data.combatValues.targetedSpellcasting.base =
|
2021-03-22 10:28:37 +01:00
|
|
|
data.attributes.mind.total + data.traits.dexterity.total - armorValueOfEquippedItems;
|
2021-01-19 03:31:40 +01:00
|
|
|
|
|
|
|
Object.values(data.combatValues).forEach(
|
2021-03-22 10:18:43 +01:00
|
|
|
(combatValue: ModifiableDataBaseTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod),
|
2021-01-19 03:31:40 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the total armor value of all equipped items.
|
|
|
|
*/
|
2021-02-16 03:26:26 +01:00
|
|
|
protected _calculateArmorValueOfEquippedItems(): number {
|
2021-01-19 03:31:40 +01:00
|
|
|
return this.items
|
2021-06-26 11:42:50 +02:00
|
|
|
.map((item) => item.data)
|
|
|
|
.filter(
|
2021-06-30 02:17:54 +02:00
|
|
|
(data): data is foundry.data.ItemData & (DS4ArmorDataProperties | DS4ShieldDataProperties) =>
|
2021-06-26 11:42:50 +02:00
|
|
|
data.type === "armor" || data.type === "shield",
|
|
|
|
)
|
|
|
|
.filter((data) => data.data.equipped)
|
|
|
|
.map((data) => data.data.armorValue)
|
2021-01-19 03:31:40 +01:00
|
|
|
.reduce((a, b) => a + b, 0);
|
|
|
|
}
|
2021-01-23 23:51:21 +01:00
|
|
|
|
2021-03-24 09:19:26 +01:00
|
|
|
/**
|
|
|
|
* Prepares the check target numbers of checks for the actor.
|
|
|
|
*/
|
|
|
|
protected _prepareChecks(): void {
|
|
|
|
const data = this.data.data;
|
|
|
|
data.checks = {
|
|
|
|
appraise: data.attributes.mind.total + data.traits.intellect.total,
|
|
|
|
changeSpell: data.attributes.mind.total + data.traits.intellect.total,
|
|
|
|
climb: data.attributes.mobility.total + data.traits.strength.total,
|
|
|
|
communicate: data.attributes.mind.total + data.traits.dexterity.total,
|
|
|
|
decipherScript: data.attributes.mind.total + data.traits.intellect.total,
|
|
|
|
defend: 0, // assigned in prepareFinalDerivedData as it must always match data.combatValues.defense.total and is not changeable by effects
|
|
|
|
defyPoison: data.attributes.body.total + data.traits.constitution.total,
|
|
|
|
disableTraps: data.attributes.mind.total + data.traits.dexterity.total,
|
|
|
|
featOfStrength: data.attributes.body.total + data.traits.strength.total,
|
|
|
|
flirt: data.attributes.mind.total + data.traits.aura.total,
|
|
|
|
haggle: data.attributes.mind.total + Math.max(data.traits.intellect.total, data.traits.intellect.total),
|
|
|
|
hide: data.attributes.mobility.total + data.traits.agility.total,
|
2021-04-13 20:19:25 +02:00
|
|
|
identifyMagic: data.attributes.mind.total + data.traits.intellect.total,
|
2021-03-24 09:19:26 +01:00
|
|
|
jump: data.attributes.mobility.total + data.traits.agility.total,
|
|
|
|
knowledge: data.attributes.mind.total + data.traits.intellect.total,
|
|
|
|
openLock: data.attributes.mind.total + data.traits.dexterity.total,
|
|
|
|
perception: Math.max(data.attributes.mind.total + data.traits.intellect.total, 8),
|
|
|
|
pickPocket: data.attributes.mobility.total + data.traits.dexterity.total,
|
|
|
|
readTracks: data.attributes.mind.total + data.traits.intellect.total,
|
|
|
|
resistDisease: data.attributes.body.total + data.traits.constitution.total,
|
|
|
|
ride: data.attributes.mobility.total + Math.max(data.traits.agility.total, data.traits.aura.total),
|
|
|
|
search: Math.max(data.attributes.mind.total + data.traits.intellect.total, 8),
|
2021-04-13 20:19:25 +02:00
|
|
|
senseMagic: data.attributes.mind.total + data.traits.aura.total,
|
2021-03-24 09:19:26 +01:00
|
|
|
sneak: data.attributes.mobility.total + data.traits.agility.total,
|
|
|
|
startFire: data.attributes.mind.total + data.traits.dexterity.total,
|
|
|
|
swim: data.attributes.mobility.total + data.traits.strength.total,
|
|
|
|
wakeUp: data.attributes.mind.total + data.traits.intellect.total,
|
|
|
|
workMechanism:
|
|
|
|
data.attributes.mind.total + Math.max(data.traits.dexterity.total, data.traits.intellect.total),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-23 23:51:21 +01:00
|
|
|
/**
|
|
|
|
* Handle how changes to a Token attribute bar are applied to the Actor.
|
|
|
|
* This only differs from the base implementation by also allowing negative values.
|
|
|
|
* @override
|
|
|
|
*/
|
2021-06-30 02:17:54 +02:00
|
|
|
async modifyTokenAttribute(
|
|
|
|
attribute: string,
|
|
|
|
value: number,
|
|
|
|
isDelta = false,
|
|
|
|
isBar = true,
|
|
|
|
): Promise<this | undefined> {
|
2021-07-01 01:08:30 +02:00
|
|
|
const current = foundry.utils.getProperty(this.data.data, attribute);
|
2021-01-23 23:51:21 +01:00
|
|
|
|
|
|
|
// Determine the updates to make to the actor data
|
|
|
|
let updates: Record<string, number>;
|
|
|
|
if (isBar) {
|
|
|
|
if (isDelta) value = Math.min(Number(current.value) + value, current.max);
|
|
|
|
updates = { [`data.${attribute}.value`]: value };
|
|
|
|
} else {
|
|
|
|
if (isDelta) value = Number(current) + value;
|
|
|
|
updates = { [`data.${attribute}`]: value };
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call a hook to handle token resource bar updates
|
|
|
|
const allowed = Hooks.call("modifyTokenAttribute", { attribute, value, isDelta, isBar }, updates);
|
|
|
|
return allowed !== false ? this.update(updates) : this;
|
|
|
|
}
|
2021-03-24 09:19:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Roll for a given check.
|
2021-03-24 09:24:14 +01:00
|
|
|
* @param check - The check to perform
|
2021-09-19 20:12:01 +02:00
|
|
|
* @param options - Additional options to customize the roll
|
2021-03-24 09:19:26 +01:00
|
|
|
*/
|
2021-09-19 20:12:01 +02:00
|
|
|
async rollCheck(
|
|
|
|
check: Check,
|
|
|
|
options: { speaker?: { token?: TokenDocument; alias?: string } } = {},
|
|
|
|
): Promise<void> {
|
|
|
|
const speaker = ChatMessage.getSpeaker({ actor: this, ...options.speaker });
|
2021-03-24 09:19:26 +01:00
|
|
|
await createCheckRoll(this.data.data.checks[check], {
|
2021-07-07 19:22:35 +02:00
|
|
|
rollMode: getGame().settings.get("core", "rollMode"),
|
2021-03-24 09:19:26 +01:00
|
|
|
maximumCoupResult: this.data.data.rolling.maximumCoupResult,
|
|
|
|
minimumFumbleResult: this.data.data.rolling.minimumFumbleResult,
|
2021-09-19 12:23:52 +02:00
|
|
|
flavor: "DS4.ActorCheckFlavor",
|
2021-09-19 20:12:01 +02:00
|
|
|
flavorData: { actor: speaker.alias ?? this.name, check: DS4.i18nKeys.checks[check] },
|
|
|
|
speaker,
|
2021-03-24 09:19:26 +01:00
|
|
|
});
|
|
|
|
}
|
2021-05-13 21:39:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Roll a generic check. A dialog is presented to select the combination of
|
|
|
|
* Attribute and Trait to perform the check against.
|
2021-09-19 20:12:01 +02:00
|
|
|
* @param options - Additional options to customize the roll
|
2021-05-13 21:39:42 +02:00
|
|
|
*/
|
2021-09-19 20:12:01 +02:00
|
|
|
async rollGenericCheck(options: { speaker?: { token?: TokenDocument; alias?: string } } = {}): Promise<void> {
|
2021-05-13 21:39:42 +02:00
|
|
|
const { attribute, trait } = await this.selectAttributeAndTrait();
|
|
|
|
const checkTargetNumber = this.data.data.attributes[attribute].total + this.data.data.traits[trait].total;
|
2021-09-19 20:12:01 +02:00
|
|
|
const speaker = ChatMessage.getSpeaker({ actor: this, ...options.speaker });
|
2021-05-13 21:39:42 +02:00
|
|
|
await createCheckRoll(checkTargetNumber, {
|
2021-07-07 19:22:35 +02:00
|
|
|
rollMode: getGame().settings.get("core", "rollMode"),
|
2021-05-13 21:39:42 +02:00
|
|
|
maximumCoupResult: this.data.data.rolling.maximumCoupResult,
|
|
|
|
minimumFumbleResult: this.data.data.rolling.minimumFumbleResult,
|
2021-09-19 20:12:01 +02:00
|
|
|
flavor: "DS4.ActorGenericCheckFlavor",
|
|
|
|
flavorData: {
|
|
|
|
actor: speaker.alias ?? this.name,
|
2021-05-13 21:39:42 +02:00
|
|
|
attribute: DS4.i18n.attributes[attribute],
|
|
|
|
trait: DS4.i18n.traits[trait],
|
2021-09-19 20:12:01 +02:00
|
|
|
},
|
|
|
|
speaker,
|
2021-05-13 21:39:42 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async selectAttributeAndTrait(): Promise<{
|
|
|
|
attribute: keyof typeof DS4.i18n.attributes;
|
|
|
|
trait: keyof typeof DS4.i18n.traits;
|
|
|
|
}> {
|
|
|
|
const attributeIdentifier = "attribute-trait-selection-attribute";
|
|
|
|
const traitIdentifier = "attribute-trait-selection-trait";
|
|
|
|
return Dialog.prompt({
|
2021-07-07 19:22:35 +02:00
|
|
|
title: getGame().i18n.localize("DS4.DialogAttributeTraitSelection"),
|
2021-05-13 21:39:42 +02:00
|
|
|
content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", {
|
|
|
|
selects: [
|
|
|
|
{
|
2021-07-07 19:22:35 +02:00
|
|
|
label: getGame().i18n.localize("DS4.Attribute"),
|
2021-05-13 21:39:42 +02:00
|
|
|
identifier: attributeIdentifier,
|
|
|
|
options: DS4.i18n.attributes,
|
|
|
|
},
|
|
|
|
{
|
2021-07-07 19:22:35 +02:00
|
|
|
label: getGame().i18n.localize("DS4.Trait"),
|
2021-05-13 21:39:42 +02:00
|
|
|
identifier: traitIdentifier,
|
|
|
|
options: DS4.i18n.traits,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2021-07-07 19:22:35 +02:00
|
|
|
label: getGame().i18n.localize("DS4.GenericOkButton"),
|
2021-05-13 21:39:42 +02:00
|
|
|
callback: (html) => {
|
|
|
|
const selectedAttribute = html.find(`#${attributeIdentifier}`).val();
|
2021-05-13 22:03:32 +02:00
|
|
|
if (!isAttribute(selectedAttribute)) {
|
2021-05-13 21:39:42 +02:00
|
|
|
throw new Error(
|
2021-07-07 19:22:35 +02:00
|
|
|
getGame().i18n.format("DS4.ErrorUnexpectedAttribute", {
|
2021-05-13 21:39:42 +02:00
|
|
|
actualAttribute: selectedAttribute,
|
2021-06-26 11:42:50 +02:00
|
|
|
expectedTypes: Object.keys(DS4.i18n.attributes)
|
|
|
|
.map((attribute) => `'${attribute}'`)
|
|
|
|
.join(", "),
|
2021-05-13 21:39:42 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const selectedTrait = html.find(`#${traitIdentifier}`).val();
|
2021-05-13 22:03:32 +02:00
|
|
|
if (!isTrait(selectedTrait)) {
|
2021-05-13 21:39:42 +02:00
|
|
|
throw new Error(
|
2021-07-07 19:22:35 +02:00
|
|
|
getGame().i18n.format("DS4.ErrorUnexpectedTrait", {
|
2021-05-13 22:03:32 +02:00
|
|
|
actualTrait: selectedTrait,
|
2021-06-26 11:42:50 +02:00
|
|
|
expectedTypes: Object.keys(DS4.i18n.traits)
|
|
|
|
.map((attribute) => `'${attribute}'`)
|
|
|
|
.join(", "),
|
2021-05-13 21:39:42 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
attribute: selectedAttribute,
|
|
|
|
trait: selectedTrait,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-02-16 02:07:34 +01:00
|
|
|
}
|