-
Notifications
You must be signed in to change notification settings - Fork 0
/
Beast.js
87 lines (72 loc) · 1.58 KB
/
Beast.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
const { getRandom } = require("./utils");
/**
* Beast class definition
*/
class Beast {
health;
strength;
defence;
speed;
luck;
static heroStats = {
health: [60, 90],
strength: [60, 90],
defence: [40, 60],
speed: [40, 60],
luck: [25, 40],
};
constructor() {
// populate beast stats
// at object creation
this.health = getRandom(
Beast.heroStats.health[0],
Beast.heroStats.health[1]
);
this.strength = getRandom(
Beast.heroStats.strength[0],
Beast.heroStats.strength[1]
);
this.defence = getRandom(
Beast.heroStats.defence[0],
Beast.heroStats.defence[1]
);
this.speed = getRandom(Beast.heroStats.speed[0], Beast.heroStats.speed[1]);
this.luck = getRandom(Beast.heroStats.luck[0], Beast.heroStats.luck[1]);
}
getHealth() {
return this.health;
}
getDefence() {
return this.defence;
}
getSpeed() {
return this.speed;
}
getLuck() {
return this.luck;
}
/**
* Stats that are generated at every invokation
*/
isLucky() {
return getRandom(0, this.getLuck()) === this.getLuck();
}
/**
* ENDOF
* Stats that are generated at every invokation
*/
setHealth(health) {
this.health = health;
}
doAttack(orderusLucky, orderusDefence, orderusMagicShield) {
// This time Orderus is lucky
if (orderusLucky) {
return 0;
}
const damage = this.strength - orderusDefence;
// if Orderus has magic shield enabled
// it suffers half less
return orderusMagicShield ? damage / 2 : damage;
}
}
exports.Beast = Beast;