Skip to content

Commit

Permalink
Merge pull request #43 from g-bauer/fix_xp_diceroller
Browse files Browse the repository at this point in the history
Fix xp diceroller
  • Loading branch information
valentine195 authored Jun 26, 2022
2 parents b98213f + 695f96f commit 18e7090
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/encounter/ui/Encounter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
export let playerLevels: number[];
const creatureMap: Map<Creature, number> = new Map();
let totalXP: number;
let creatureMap: Map<Creature, number> = new Map();
const rollerMap: Map<Creature, StackRoller> = new Map();
let totalXP = [...creatureMap].reduce((a, c) => a + c[0].xp * c[1], 0);
for (let [creature, count] of creatures) {
let number: number = Number(count);
if (plugin.canUseDiceRoller) {
let roller = plugin.getRoller(`${count}`) as StackRoller;
roller.on("new-result", () => {
creatureMap.set(creature, roller.result);
creatureMap = creatureMap;
totalXP = [...creatureMap].reduce(
(a, c) => a + c[0].xp * c[1],
0
Expand All @@ -43,13 +44,17 @@
creatureMap.set(creature, number);
}
}
totalXP = [...creatureMap].reduce((a, c) => a + c[0].xp * c[1], 0);
let difficulty: DifficultyReport;
$: {
if (!isNaN(totalXP)) {
difficulty = encounterDifficulty(
playerLevels,
[...creatures].map((creature) => creature[0].xp)
);
[...creatureMap]
.map((creature) => Array(creature[1]).fill(creature[0].xp))
.flat()
);
}
}
Expand Down

0 comments on commit 18e7090

Please sign in to comment.