forked from xiv-gear-planner/gear-planner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request xiv-gear-planner#191 from xiv-gear-planner/fix-buf…
…f-applicability Fix applicability of buffs on start vs snapshot
- Loading branch information
Showing
5 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {Buff} from "./sim_types"; | ||
|
||
function nonZero(number: number): boolean { | ||
return (number ?? 0) > 0; | ||
} | ||
|
||
/** | ||
* Whether a buff is relevant at the start of an action. | ||
* | ||
* e.g. for haste/swiftcast-style buffs, this would be true. It is also true | ||
* of the buff has any 'beforeAbility' hook. | ||
* | ||
* @param buff | ||
*/ | ||
export function buffRelevantAtStart(buff: Buff): boolean { | ||
return nonZero(buff.effects?.haste) || (buff.beforeAbility !== undefined); | ||
} | ||
|
||
/** | ||
* Whether a buff is relevant at the point where an action snapshots. This | ||
* is true for any buff with damage-increasing effects, or with either a beforeSnapshot | ||
* or modifyDamage hook. In addition, it {@link buffRelevantAtStart} returns false, | ||
* this will return true to ensure that at least one of the two functions returns true | ||
* in either case. | ||
* | ||
* @param buff | ||
*/ | ||
export function buffRelevantAtSnapshot(buff: Buff): boolean { | ||
return nonZero(buff.effects?.critChanceIncrease) | ||
|| nonZero(buff.effects?.dhitChanceIncrease) | ||
|| nonZero(buff.effects?.dmgIncrease) | ||
|| (buff.effects?.forceCrit) | ||
|| (buff.effects?.forceDhit) | ||
|| (buff.beforeSnapshot !== undefined) | ||
|| (buff.modifyDamage !== undefined) | ||
// As a fallback, also force this to return true if the buff is not relevant at start | ||
|| !buffRelevantAtStart(buff); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import {Buff} from "../sims/sim_types"; | ||
import {expect} from "chai"; | ||
import {buffRelevantAtSnapshot, buffRelevantAtStart} from "../sims/buff_helpers"; | ||
|
||
describe("Buff Helpers", () => { | ||
describe('simple damage buff', () => { | ||
const buff: Buff = { | ||
duration: 15, | ||
selfOnly: true, | ||
name: "Test buff", | ||
effects: { | ||
dmgIncrease: 0.5 | ||
}, | ||
}; | ||
|
||
it('is not relevant at start', () => { | ||
expect(buffRelevantAtStart(buff)).to.be.false; | ||
}); | ||
|
||
it('is relevant at snapshot', () => { | ||
expect(buffRelevantAtSnapshot(buff)).to.be.true; | ||
}); | ||
|
||
}); | ||
|
||
describe('simple haste buff', () => { | ||
const buff: Buff = { | ||
duration: 15, | ||
selfOnly: true, | ||
name: "Test buff", | ||
effects: { | ||
haste: 10 | ||
}, | ||
}; | ||
|
||
it('is relevant at start', () => { | ||
expect(buffRelevantAtStart(buff)).to.be.true; | ||
}); | ||
|
||
it('is not relevant at snapshot', () => { | ||
expect(buffRelevantAtSnapshot(buff)).to.be.false; | ||
}); | ||
|
||
}); | ||
|
||
describe('no-op buff', () => { | ||
|
||
const buff: Buff = { | ||
duration: 15, | ||
selfOnly: true, | ||
name: "Test buff", | ||
effects: {}, | ||
}; | ||
|
||
it('is not relevant at start', () => { | ||
expect(buffRelevantAtStart(buff)).to.be.false; | ||
}); | ||
|
||
it('is relevant at snapshot', () => { | ||
expect(buffRelevantAtSnapshot(buff)).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('damage + haste buff', () => { | ||
const buff: Buff = { | ||
duration: 15, | ||
selfOnly: true, | ||
name: "Test buff", | ||
effects: { | ||
haste: 10, | ||
dmgIncrease: 0.1 | ||
}, | ||
}; | ||
|
||
it('is relevant at start', () => { | ||
expect(buffRelevantAtStart(buff)).to.be.true; | ||
}); | ||
|
||
it('is relevant at snapshot', () => { | ||
expect(buffRelevantAtSnapshot(buff)).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('buff with beforeAbility hook', () => { | ||
const buff: Buff = { | ||
duration: 15, | ||
selfOnly: true, | ||
name: "Test buff", | ||
beforeAbility() { | ||
}, | ||
effects: {}, | ||
}; | ||
|
||
it('is relevant at start', () => { | ||
expect(buffRelevantAtStart(buff)).to.be.true; | ||
}); | ||
|
||
it('is not relevant at snapshot', () => { | ||
expect(buffRelevantAtSnapshot(buff)).to.be.false; | ||
}); | ||
|
||
}); | ||
|
||
describe('buff with beforeSnapshot hook', () => { | ||
const buff: Buff = { | ||
duration: 15, | ||
selfOnly: true, | ||
name: "Test buff", | ||
beforeSnapshot() { | ||
}, | ||
effects: {}, | ||
}; | ||
|
||
it('is not relevant at start', () => { | ||
expect(buffRelevantAtStart(buff)).to.be.false; | ||
}); | ||
|
||
it('is relevant at snapshot', () => { | ||
expect(buffRelevantAtSnapshot(buff)).to.be.true; | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('buff with modifyDamage hook', () => { | ||
const buff: Buff = { | ||
duration: 15, | ||
selfOnly: true, | ||
name: "Test buff", | ||
modifyDamage() { | ||
}, | ||
effects: {}, | ||
}; | ||
|
||
it('is not relevant at start', () => { | ||
expect(buffRelevantAtStart(buff)).to.be.false; | ||
}); | ||
|
||
it('is relevant at snapshot', () => { | ||
expect(buffRelevantAtSnapshot(buff)).to.be.true; | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters