-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus.ts
190 lines (170 loc) · 4.67 KB
/
status.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
type StatusType = 'berzerk' | 'islandCurse' | 'angeredGods' | 'poison' | 'bleeding' | 'outOfTown';
const STATUSES: Array<StatusType> = ['berzerk', 'islandCurse', 'angeredGods', 'poison', 'bleeding', 'outOfTown'];
interface StatusItemCore extends ClockActions {
active: boolean;
year: number; // Expiry time.
season: number;
term: number;
tock: number;
tick: number;
name: string;
}
interface StatusItem extends Clock {
name: string;
strmod: number;
dexmod: number;
conmod: number;
intmod: number;
wismod: number;
chamod: number;
preventAttack: boolean;
preventHeal: boolean;
damagePerTick: number;
damagePerTock: number;
enrage: boolean;
}
interface StatusItemInput extends ClockInput {
name: string;
strmod?: number;
dexmod?: number;
conmod?: number;
intmod?: number;
wismod?: number;
chamod?: number;
preventAttack?: boolean;
preventHeal?: boolean;
damagePerTick?: number;
damagePerTock?: number;
enrage?: boolean;
}
function statusItemInput(status: StatusItemInput) {
return {
name: status.name,
...clockInput(status),
strmod: status.strmod || 0,
dexmod: status.dexmod || 0,
conmod: status.conmod || 0,
intmod: status.intmod || 0,
wismod: status.wismod || 0,
chamod: status.chamod || 0,
preventAttack: status.preventAttack || false,
preventHeal: status.preventHeal || false,
damagePerTick: status.damagePerTick || 0,
damagePerTock: status.damagePerTock || 0,
enrage: status.enrage || false,
};
}
function statusIsExpired(game: Game, status: StatusItemCore) {
if (status.year == 0 && status.term == 0 && status.tock == 0 && status.tick == 0)
return false;
else if (game.year < status.year) return false;
else if (game.year > status.year) return true;
else if (game.season < status.season) return false;
else if (game.season > status.season) return true;
else if (game.term < status.term) return false;
else if (game.term > status.term) return true;
else if (game.tock < status.tock) return false;
else if (game.tock > status.tock) return true;
return game.tick >= status.tick;
}
function statusSetExpiry(game: Game, status: Clock, length: ClockInput) {
const clock = clockAdd(game, clockInput(length))
status.year = clock.year;
status.season = clock.season;
status.term = clock.term;
status.tock = clock.tock;
status.tick = clock.tick;
clockUnwrap(status);
}
class Status {
berzerk: StatusItemCore;
islandCurse: StatusItemCore;
angeredGods: StatusItemCore;
poison: StatusItemCore;
bleeding: StatusItemCore;
outOfTown: StatusItemCore;
other: Array<StatusItem>;
constructor() {
const defaults = { active: false, year: 0, season: 0, term: 0, tock: 0, tick: 0 };
this.berzerk = {
...defaults,
name: 'Berzerk',
doTickActions: (game: Game) => {
if (!game.fightingBoss) {
game.log('Your party is berzerk and fights the boss, "I didn\'t hear a bell!"');
game.fightBoss();
}
},
};
this.islandCurse = {
...defaults,
name: 'Island Curse',
};
this.angeredGods = {
...defaults,
name: 'Angered Gods',
};
this.poison = {
...defaults,
name: 'Poison',
};
this.bleeding = {
...defaults,
name: 'Bleeding',
};
this.outOfTown = {
...defaults,
name: 'Out of Town',
};
this.other = [];
}
doTickActions(game: Game) {
const nextOther = [];
for (const status of this.other) {
if (clockCompare(game, status) >= 0) {
this._unapplyStatus(game, status);
} else {
nextOther.push(status);
}
}
this.other = nextOther;
}
hasPreventAttack() {
for (const status of this.other) {
if (status.preventAttack) {
return true;
}
}
return false;
}
hasEnrage() {
for (const status of this.other) {
if (status.enrage) {
return true;
}
}
return false;
}
addStatus(game: Game, status: StatusItemInput) {
const s = statusItemInput(status);
statusSetExpiry(game, s, status);
this.other.push(s);
this._applyStatus(game, s);
}
_applyStatus(game: Game, status: StatusItem) {
game.party.strmod += status.strmod;
game.party.dexmod += status.dexmod;
game.party.conmod += status.conmod;
game.party.intmod += status.intmod;
game.party.wismod += status.wismod;
game.party.chamod += status.chamod;
}
_unapplyStatus(game: Game, status: StatusItem) {
game.party.strmod -= status.strmod;
game.party.dexmod -= status.dexmod;
game.party.conmod -= status.conmod;
game.party.intmod -= status.intmod;
game.party.wismod -= status.wismod;
game.party.chamod -= status.chamod;
}
}