/
buff-action.ts
80 lines (66 loc) · 2.15 KB
/
buff-action.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Simulation } from '../../simulation/simulation';
import { ActionType } from './action-type';
import { Buff } from '../buff.enum';
import { CraftingAction } from './crafting-action';
import { EffectiveBuff } from '../effective-buff';
import { StepState } from '../step-state';
export abstract class BuffAction extends CraftingAction {
public getType(): ActionType {
return ActionType.BUFF;
}
abstract getDuration(simulation: Simulation): number;
canBeClipped(): boolean {
return false;
}
execute(simulation: Simulation): void {
for (const buffToOverride of this.getOverrides()) {
simulation.removeBuff(buffToOverride);
}
simulation.buffs.push(this.getAppliedBuff(simulation));
}
_canBeUsed(simulationState: Simulation): boolean {
if (this.canBeClipped()) {
return true;
}
return !simulationState.hasBuff(this.getBuff());
}
getDurabilityCost(simulationState: Simulation): number {
return 0;
}
_getSuccessRate(simulationState: Simulation): number {
return 100;
}
skipOnFail(): boolean {
return true;
}
/**
* Override this method if the buff overrides other buffs (steady hands for instance).
* Don't forget to add super.getOverrides() to the array you'll return
* @returns {Buff | null}
*/
public getOverrides(): Buff[] {
return [this.getBuff()];
}
abstract getBuff(): Buff;
abstract getInitialStacks(): number;
protected abstract getTick():
| ((simulation: Simulation, linear?: boolean, action?: CraftingAction) => void)
| undefined;
protected getOnExpire(): ((simulation: Simulation, linear?: boolean) => void) | undefined {
// Adding a return here to avoid typescript compilation error due to empty block.
return undefined;
}
private getAppliedBuff(simulation: Simulation): EffectiveBuff {
return {
duration:
simulation.state === StepState.PRIMED
? this.getDuration(simulation) + 2
: this.getDuration(simulation),
tick: this.getTick(),
onExpire: this.getOnExpire(),
stacks: this.getInitialStacks(),
buff: this.getBuff(),
appliedStep: simulation.steps.length,
};
}
}