-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStats.js
175 lines (143 loc) · 3.98 KB
/
Stats.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
#pragma strict
function Start () {
var whoami : String = gameObject.name;
var X : float = 7; // From the design presetation
if (whoami == "Sidekick") {
loadStats(20, 0, 0, 1.5 * X, 5, 5);
} else if (whoami == "Hero") {
loadStats(100, 10, 2.0, X, 8, 5);
} else if (whoami == "Mob") {
loadStats(50, 5, 0.66, X, 5, 5);
} else {
print("Whoa! Stats here! I don't know how to handle " + whoami);
loadStats(0, 0, 0, 0, 0, 0);
}
}
// TODO: Move these out to public variables so they can be tracked in the UI
private var Health : int; // Health
private var MaxHealth : int; // Max Health
private var Attack : int; // Damage done per attack
private var BaseAttack : int; // Stores initial attack value in case attack is modified for a special effect
private var AttackRange : float; // Maximum distance that can still land a successful attack
// BaseAttackRange maybe in future. Nothing in prototype modifies attack range.
private var AttackSpeed : float; // How many attacks per second. 0.5 = Attack once every 2 seconds.
private var BaseAttackSpeed : float; // How many attacks per second. 0.5 = Attack once every 2 seconds.
private var MoveSpeed : float; // How fast it moves
private var BaseMoveSpeed : float; // Base speed
private var SightRange : float; // Visible forward distance
private var BaseSightRange : float; // Base value of the above
private var SpellRange : float; // Range of spell casting
private var BaseSpellRange :float; // Base value of the above
private var DamageRatio : float; // 1.0 = Normal, 0.5 = Takes Half Damage, 2.0 = Takes Double Damage
private function loadStats(maxHP : int, baseATK : int, baseATKSPD : float, baseMOVSPD : float, baseSight : float, baseSpellRange : float) {
MaxHealth = maxHP;
Health = maxHP;
BaseAttack = baseATK;
Attack = baseATK;
BaseAttackSpeed = baseATKSPD;
AttackSpeed = baseATKSPD;
BaseMoveSpeed = baseMOVSPD;
MoveSpeed = baseMOVSPD;
DamageRatio = 1;
AttackRange = 2; // Minimum to attack or be attacked by Hero (because he's so big)
BaseSightRange = baseSight;
SightRange = baseSight;
BaseSpellRange = baseSpellRange;
SpellRange = baseSight;
}
// Getters
function getHealth() {
return Health;
}
function getMaxHealth() {
return MaxHealth;
}
function getAttack() {
return Attack;
}
function getAttackRange() {
return AttackRange;
}
function getBaseAttack() {
return BaseAttack;
}
function getAttackSpeed() {
return AttackSpeed;
}
function getBaseAttackSpeed() {
return BaseAttackSpeed;
}
function getMoveSpeed() {
return MoveSpeed;
}
function getBaseMoveSpeed() {
return BaseMoveSpeed;
}
function getDamageRatio() {
return DamageRatio;
}
function getSightRange() {
return SightRange;
}
function getBaseSightRange() {
return BaseSightRange;
}
function getSpellRange() {
return SpellRange;
}
// Modifiers
function hurtHealth(damage : int) {
Health -= damage * DamageRatio;
}
function healHealth(life : int) {
if (Health + life > MaxHealth)
healAllHealth();
else
Health += life;
}
private var healOverTimeLength : int;
private var healOverTimeAmount : int;
function healOverTime(amount : int, time : int) {
healOverTimeAmount = amount;
healOverTimeLength = time;
InvokeRepeating("healOverTimeHelper", 0, 1);
}
function healOverTimeHelper() {
healOverTimeLength--;
healHealth(healOverTimeAmount);
if (healOverTimeLength <= 0) {
CancelInvoke("healOverTimeHelper");
healOverTimeAmount = 0;
healOverTimeLength = 0;
}
}
function healAllHealth() {
Health = MaxHealth;
}
function modAttack(ratio : float) {
Attack *= ratio;
}
function resetAttack() {
Attack = BaseAttack;
}
function modAttackSpeed(ratio : float) {
AttackSpeed *= ratio;
}
function resetAttackSpeed() {
AttackSpeed = BaseAttackSpeed;
}
function modMoveSpeed(ratio : float) {
MoveSpeed *= ratio;
}
function resetMoveSpeed() {
MoveSpeed = BaseMoveSpeed;
}
function setDamageRatio(ratio : float) {
DamageRatio = ratio;
}
function modSightRange(ratio : float) {
SightRange *= ratio;
}
function resetSightRange() {
SightRange = BaseSightRange;
}