Remove some unnecessary casts and fallbacks

This commit is contained in:
Johannes Loher 2021-03-22 10:28:37 +01:00
parent 17633ced68
commit cb5ad74a71
2 changed files with 11 additions and 13 deletions

View file

@ -75,7 +75,7 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
return changes.concat( return changes.concat(
e.data.changes.filter(predicate).flatMap((c) => { e.data.changes.filter(predicate).flatMap((c) => {
const duplicatedChange = duplicate(c) as ActiveEffect.Change; const duplicatedChange = duplicate(c);
duplicatedChange.priority = duplicatedChange.priority ?? duplicatedChange.mode * 10; duplicatedChange.priority = duplicatedChange.priority ?? duplicatedChange.mode * 10;
return Array(factor).fill({ return Array(factor).fill({
...duplicatedChange, ...duplicatedChange,
@ -172,19 +172,17 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
const data = this.data.data; const data = this.data.data;
const armorValueOfEquippedItems = this._calculateArmorValueOfEquippedItems(); const armorValueOfEquippedItems = this._calculateArmorValueOfEquippedItems();
data.combatValues.hitPoints.base = data.combatValues.hitPoints.base = data.attributes.body.total + data.traits.constitution.total + 10;
(data.attributes.body.total ?? 0) + (data.traits.constitution.total ?? 0) + 10;
data.combatValues.defense.base = data.combatValues.defense.base =
(data.attributes.body.total ?? 0) + (data.traits.constitution.total ?? 0) + armorValueOfEquippedItems; data.attributes.body.total + data.traits.constitution.total + armorValueOfEquippedItems;
data.combatValues.initiative.base = (data.attributes.mobility.total ?? 0) + (data.traits.agility.total ?? 0); data.combatValues.initiative.base = data.attributes.mobility.total + data.traits.agility.total;
data.combatValues.movement.base = (data.attributes.mobility.total ?? 0) / 2 + 1; data.combatValues.movement.base = data.attributes.mobility.total / 2 + 1;
data.combatValues.meleeAttack.base = (data.attributes.body.total ?? 0) + (data.traits.strength.total ?? 0); data.combatValues.meleeAttack.base = data.attributes.body.total + data.traits.strength.total;
data.combatValues.rangedAttack.base = data.combatValues.rangedAttack.base = data.attributes.mobility.total + data.traits.dexterity.total;
(data.attributes.mobility.total ?? 0) + (data.traits.dexterity.total ?? 0);
data.combatValues.spellcasting.base = data.combatValues.spellcasting.base =
(data.attributes.mind.total ?? 0) + (data.traits.aura.total ?? 0) - armorValueOfEquippedItems; data.attributes.mind.total + data.traits.aura.total - armorValueOfEquippedItems;
data.combatValues.targetedSpellcasting.base = data.combatValues.targetedSpellcasting.base =
(data.attributes.mind.total ?? 0) + (data.traits.dexterity.total ?? 0) - armorValueOfEquippedItems; data.attributes.mind.total + data.traits.dexterity.total - armorValueOfEquippedItems;
Object.values(data.combatValues).forEach( Object.values(data.combatValues).forEach(
(combatValue: ModifiableDataBaseTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod), (combatValue: ModifiableDataBaseTotal<number>) => (combatValue.total = combatValue.base + combatValue.mod),

View file

@ -94,7 +94,7 @@ export class DS4Item extends Item<DS4ItemData, DS4ItemPreparedData> {
const ownerDataData = actor.data.data; const ownerDataData = actor.data.data;
const weaponBonus = this.data.data.weaponBonus; const weaponBonus = this.data.data.weaponBonus;
const combatValue = await this.getCombatValueKeyForAttackType(this.data.data.attackType); const combatValue = await this.getCombatValueKeyForAttackType(this.data.data.attackType);
const checkTargetNumber = (ownerDataData.combatValues[combatValue].total as number) + weaponBonus; const checkTargetNumber = ownerDataData.combatValues[combatValue].total + weaponBonus;
await createCheckRoll(checkTargetNumber, { await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode") as Const.DiceRollMode, // TODO(types): Type this setting in upstream rollMode: game.settings.get("core", "rollMode") as Const.DiceRollMode, // TODO(types): Type this setting in upstream
@ -138,7 +138,7 @@ export class DS4Item extends Item<DS4ItemData, DS4ItemPreparedData> {
); );
} }
const spellType = this.data.data.spellType; const spellType = this.data.data.spellType;
const checkTargetNumber = (ownerDataData.combatValues[spellType].total as number) + (spellBonus ?? 0); const checkTargetNumber = ownerDataData.combatValues[spellType].total + (spellBonus ?? 0);
await createCheckRoll(checkTargetNumber, { await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode") as Const.DiceRollMode, // TODO(types): Type this setting in upstream rollMode: game.settings.get("core", "rollMode") as Const.DiceRollMode, // TODO(types): Type this setting in upstream