-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelements.js
308 lines (307 loc) · 9.05 KB
/
elements.js
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
//#region Dirt
class Dirt extends Elemental {
static title = `Dirt`;
static color = new Color(150, 100, 80);
constructor() {
super();
this._title = Dirt.title;
this._color = Dirt.color;
}
}
board.cases.set(Dirt, 90);
//#endregion
//#region Grass
class Grass extends Elemental {
static title = `Grass`;
static color = new Color(0, 128, 0);
static durationGrow = 10;
constructor() {
super();
this._title = Grass.title;
this._color = Grass.color;
this.abilities.push(this.#grow);
}
#grow = new Ability(`Grow`, () => {
const positions = [
new Vector(this.position.x - 1, this.position.y - 1),
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x + 1, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x - 1, this.position.y + 1),
new Vector(this.position.x, this.position.y + 1),
new Vector(this.position.x + 1, this.position.y + 1)
];
const targets = board.getElementsOfType(positions, Dirt);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Grass());
return true;
} else {
return false;
}
}, Grass.durationGrow);
}
board.cases.set(Grass, 4);
//#endregion
//#region Fire
class Fire extends Elemental {
static title = `Fire`;
static color = new Color(255, 150, 0);
static durationBurn = 4;
static durationFade = 16;
constructor() {
super();
this._title = Fire.title;
this._color = Fire.color;
this.abilities.push(this.#burn, this.#fade);
}
#burn = new Ability(`Burn`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Grass);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Fire());
this.#fade.progress = 0;
return true;
} else {
return false;
}
}, Fire.durationBurn);
#fade = new Ability(`Fade`, () => {
board.set(this.position, new Dirt());
return false;
}, Fire.durationFade);
}
board.cases.set(Fire, 2);
//#endregion
//#region Water
class Water extends Elemental {
static title = `Water`;
static color = new Color(0, 50, 255);
static durationFlow = 8;
static durationEvaporate = 8;
constructor() {
super();
this._title = Water.title;
this._color = Water.color;
this.abilities.push(this.#flow, this.#evaporate);
}
#flow = new Ability(`Flow`, () => {
const positions = [
new Vector(this.position.x - 1, this.position.y - 1),
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x + 1, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x - 1, this.position.y + 1),
new Vector(this.position.x, this.position.y + 1),
new Vector(this.position.x + 1, this.position.y + 1)
];
const targets = board.getElementsOfType(positions, Dirt);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Water());
return true;
} else {
return false;
}
}, Water.durationFlow);
#evaporate = new Ability(`Evaporate`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Fire);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Dirt());
board.set(this.position, new Dirt());
return true;
} else {
return false;
}
}, Water.durationEvaporate);
}
board.cases.set(Water, 2);
//#endregion
//#region Lava
class Lava extends Elemental {
static title = `Lava`;
static color = new Color(255, 0, 0);
static maxDensity = 3;
static durationFlow = 15;
static durationBurn = 8;
static durationFade = 4;
/**
*
* @param {Number} density
*/
constructor(density = Lava.maxDensity) {
super();
this._title = Lava.title;
this.#density = density;
this._color = new Color(
((Lava.color.red - Fire.color.red) * this.#density / Lava.maxDensity) + Fire.color.red,
((Lava.color.green - Fire.color.green) * this.#density / Lava.maxDensity) + Fire.color.green,
((Lava.color.blue - Fire.color.blue) * this.#density / Lava.maxDensity) + Fire.color.blue,
);
this.abilities.push(this.#flow, this.#burn, this.#fade);
}
/** @type {Number} */ #density;
get density() {
return this.#density;
}
set density(value) {
this.#density = value;
if (this.#density <= 0) {
board.set(this.position, new Dirt());
}
}
#flow = new Ability(`Flow`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Dirt);
const lifespan = this.#density - 1;
if (targets.length > 0 && lifespan > 0) {
const target = Random.item(targets);
board.set(target.position, new Lava(lifespan));
return true;
} else {
return false;
}
}, Lava.durationFlow);
#burn = new Ability(`Burn`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Grass);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Fire());
return true;
} else {
return false;
}
}, Lava.durationBurn);
#fade = new Ability(`Fade`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Water);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Dirt());
this.density--;
return true;
} else {
return false;
}
}, Lava.durationFade);
}
board.cases.set(Lava, 1);
//#endregion
//#region Ice
class Ice extends Elemental {
static title = `Ice`;
static color = new Color(0, 200, 255);
static maxDensity = 3;
static durationFlow = 12;
static durationMelt = 4;
static durationEvaporate = 4;
/**
*
* @param {Number} density
*/
constructor(density = Ice.maxDensity) {
super();
this._title = Ice.title;
this.#density = density;
this._color = new Color(
((Ice.color.red - Water.color.red) * this.#density / Ice.maxDensity) + Water.color.red,
((Ice.color.green - Water.color.green) * this.#density / Ice.maxDensity) + Water.color.green,
((Ice.color.blue - Water.color.blue) * this.#density / Ice.maxDensity) + Water.color.blue,
);
this.abilities.push(this.#flow, this.#melt, this.#evaporate);
}
/** @type {Number} */ #density;
get density() {
return this.#density;
}
set density(value) {
this.#density = value;
if (this.#density <= 0) {
board.set(this.position, new Water());
}
}
#flow = new Ability(`Flow`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Dirt);
const lifespan = this.#density - 1;
if (targets.length > 0 && lifespan > 0) {
const target = Random.item(targets);
board.set(target.position, new Ice(lifespan));
return true;
} else {
return false;
}
}, Ice.durationFlow);
#melt = new Ability(`Melt`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Fire);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Lava());
this.density--;
return true;
} else {
return false;
}
}, Ice.durationMelt);
#evaporate = new Ability(`Evaporate`, () => {
const positions = [
new Vector(this.position.x, this.position.y - 1),
new Vector(this.position.x - 1, this.position.y),
new Vector(this.position.x + 1, this.position.y),
new Vector(this.position.x, this.position.y + 1),
];
const targets = board.getElementsOfType(positions, Lava);
if (targets.length > 0) {
const target = Random.item(targets);
board.set(target.position, new Dirt());
board.set(this.position, new Dirt());
return true;
} else {
return false;
}
}, Ice.durationEvaporate);
}
board.cases.set(Ice, 1);
//#endregion