Skip to content

Commit

Permalink
fix: Damage to all characteristics should now be handled.
Browse files Browse the repository at this point in the history
Note that damage unlinked actors doesn't really work.
  • Loading branch information
xdy committed Dec 12, 2020
1 parent f61a208 commit caeaaf1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {TwodsixRolls} from "../utils/TwodsixRolls";
import {AbstractTwodsixActorSheet} from "./AbstractTwodsixActorSheet";
import type {UpdateData} from "../migration";
import {calcModFor} from "../utils/sheetUtils";
import {calcModFor, getKeyByValue} from "../utils/sheetUtils";
import {TWODSIX} from "../config";
import {CharacteristicType} from "../TwodsixSystem";
import TwodsixItem from "../entities/TwodsixItem";
Expand Down Expand Up @@ -79,21 +79,21 @@ export class TwodsixActorSheet extends AbstractTwodsixActorSheet {
characteristic.damage = damage;
characteristic.current = characteristic.value - characteristic.damage;
characteristic.mod = calcModFor(characteristic.current);
await this.updateHits();
await this.updateAfterDamage();
}


private async updateHits():Promise<void> {
private async updateAfterDamage():Promise<void> {
//TODO Maybe this should live on TwodsixActor instead? And get called at the end of prepareData?
const updateData = <UpdateData>{};
const characteristics = this.actor.data.data.characteristics;
updateData['data.hits.value'] = characteristics["endurance"].current + characteristics["strength"].current + characteristics["dexterity"].current;
updateData['data.hits.max'] = characteristics["endurance"].value + characteristics["strength"].value + characteristics["dexterity"].value;
updateData['data.characteristics.endurance.damage'] = characteristics["endurance"].damage;
updateData['data.characteristics.strength.damage'] = characteristics["strength"].damage;
updateData['data.characteristics.dexterity.damage'] = characteristics["dexterity"].damage;
updateData['data.characteristics.endurance.current'] = characteristics["endurance"].current;
updateData['data.characteristics.strength.current'] = characteristics["strength"].current;
updateData['data.characteristics.dexterity.current'] = characteristics["dexterity"].current;

for (const cha of Object.values(characteristics as Record<any, any>)) {
updateData[`data.characteristics.${cha.key}.current`] = cha.current;
updateData[`data.characteristics.${cha.key}.damage`] = cha.damage;
}
await this.actor.update(updateData);
}

Expand Down Expand Up @@ -152,7 +152,7 @@ export class TwodsixActorSheet extends AbstractTwodsixActorSheet {
if (remaining > 0) {
console.log(`Twodsix | Actor ${this.actor.name} was overkilled by ${remaining}`);
}
await this.updateHits();
await this.updateAfterDamage();
return remaining;
}

Expand Down

0 comments on commit caeaaf1

Please sign in to comment.