Skip to content

Commit

Permalink
fix(math): fix rounding error for progress actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyuusokuna committed May 10, 2022
1 parent 49a4b1b commit f2c99e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/model/actions/other/delicate-synthesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class DelicateSynthesis extends GeneralAction {

execute(simulation: Simulation): void {
// Progress
const progressionIncrease = this.getBaseProgression(simulation);
const progressionIncrease = Math.floor(this.getBaseProgression(simulation));
const progressPotency = this.getPotency(simulation);
let progressBuffMod = this.getBaseBonus(simulation);
let progressConditionMod = this.getBaseCondition(simulation);
Expand All @@ -37,11 +37,9 @@ export class DelicateSynthesis extends GeneralAction {
progressBuffMod += 0.5;
}

const progressEfficiency = (progressPotency * progressBuffMod) / 100;
const progressEfficiency = progressPotency * progressBuffMod;

simulation.progression += Math.floor(
Math.floor(progressionIncrease) * progressConditionMod * progressEfficiency
);
simulation.progression += Math.floor((progressionIncrease * progressConditionMod * progressEfficiency) / 100);

if (
simulation.hasBuff(Buff.FINAL_APPRAISAL) &&
Expand Down
8 changes: 3 additions & 5 deletions src/model/actions/progress-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export abstract class ProgressAction extends GeneralAction {
let buffMod = this.getBaseBonus(simulation);
let conditionMod = this.getBaseCondition(simulation);
const potency = this.getPotency(simulation);
const progressionIncrease = this.getBaseProgression(simulation);
const progressionIncrease = Math.floor(this.getBaseProgression(simulation));

switch (simulation.state) {
case StepState.MALLEABLE:
Expand All @@ -31,11 +31,9 @@ export abstract class ProgressAction extends GeneralAction {
buffMod += 0.5;
}

const efficiency = Math.fround((potency * buffMod) / 100);
const efficiency = potency * buffMod;

simulation.progression += Math.floor(
Math.floor(progressionIncrease) * conditionMod * efficiency
);
simulation.progression += Math.floor((progressionIncrease * conditionMod * efficiency) / 100);

if (
simulation.hasBuff(Buff.FINAL_APPRAISAL) &&
Expand Down
14 changes: 14 additions & 0 deletions test/simulation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,18 @@ describe('Craft simulator tests', () => {
simulation.run();
expect(simulation.quality).toBeGreaterThan(0);
});

it('Progress flooring', () => {
const simulation = new Simulation(
generateRecipe(535, 3000, 6700, 125, 109),
[
new CarefulSynthesis(),
],
generateStats(90, 2606, 2457, 507)
);

simulation.run(true);

expect(simulation.progression).toBe(378);
});
});

0 comments on commit f2c99e8

Please sign in to comment.