-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabilities.py
299 lines (219 loc) · 8.98 KB
/
abilities.py
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
import soldiers;
import towers;
class Ability(object):
def __init__(self, owner):
self.targetType = None;
self.group = "foes"; # friends/foes/traps
self.frequency = "battle"; # battle/constant/# for uses/0.# for probability
self.owner = owner;
def applyTo(self, target, friends, foes, traps=[]):
if (not self.isApplicable(target, friends, foes, traps)):
# DEBUG LINES
#print "Not applicable to " + type(target).__name__ + " in " +\
#self.group + " group.";
return None; # Indicate problem
#print "Applying " + type(self).__name__ + " to " +\
#str(target) + ".";
return target;
def isApplicable(self, target, friends, foes, traps=[]):
# DEBUG LINES
#print "Self.group:" + str(eval(self.group));
return isinstance(target, self.targetType) and (target in eval(self.group));
def __str__(self):
try:
return self.msg;
except:
return object.__str__(self);
class Heal(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType =soldiers.SoldierClass;
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, friends, foes);
if (target == None):
return target;
target.currentHp += 0.10 * target.hp;
return target;
class Harm(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.currentHp -= 0.10 * target.hp;
self.msg = "* %s HARMS %s, who now has %d hp remaining."%(str(self.owner), str(target), target.currentHp);
return target;
class Haste(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType =soldiers.SoldierClass;
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.attackSpeed *= 2.0;
return target;
class Slow(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType =soldiers.SoldierClass;
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.attackSpeed /= 2.0;
self.msg = "* %s SLOWS %s, who now has %d attacks per minute."%(str(self.owner), str(target), target.attackSpeed);
return target;
class DustToDust(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = towers.TowerClass;
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.currentHp /= 10.0;
self.msg = "* %s casts DUST TO DUST on %s, which now has %d hp remaining."%(str(self.owner), str(target), target.currentHp);
return target;
class BowAttack(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "2";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.currentHp -= max(0.1 * self.owner.attack, 1);
self.msg = "* %s attacks %s with a BOW, leaving the latter with %d hp."%(str(self.owner), str(target), target.currentHp);
return target;
class DaggerThrownAttack(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "5";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.currentHp -= max(0.05 * self.owner.attack, 1);
self.msg = "* %s THROWS A DAGGER to %s, leaving the latter with %d hp."%(str(self.owner), str(target), target.currentHp);
return target;
class CriticalAttack(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "0.1";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.currentHp -= max(self.owner.attack, 1);
self.msg = "* %s causes a CRITICAL HIT to %s, leaving the latter with %d hp."%(str(self.owner), str(target), target.currentHp);
return target;
class CharmFoe(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "0.05";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
foes.remove(target);
friends.append(target);
self.msg = "* %s CHARMS %s, who now changes sides!"%(str(self.owner), str(target));
return target;
class Rage(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "constant";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
self.owner.defence /= 1.0 + (self.owner.hp - self.owner.currentHp) / (5 * self.owner.hp);
self.owner.attackSpeed *= 1.0 + (self.owner.hp - self.owner.currentHp ) / (20 * self.owner.hp);
self.msg = "* %s is enraged! Defense is decreased. Attack speed is increased. Now defence is %4.2f and attack speed is %4.2f."%(str(self.owner), self.owner.defence, self.owner.attackSpeed);
return target;
class Exhaust(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "0.10";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.fullness -= 10;
self.msg = "* %s EXHAUSTS %s. Now fullness of the latter is %4.2f."%(str(self.owner), str(target), target.fullness);
return target;
class Poison(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "0.20";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.attack *= 0.9;
target.attackSpeed *= 0.9;
target.defence *= 0.9;
self.msg = "* %s POISONS %s. Now attack, defence and speed of the latter are reduced."%(str(self.owner), str(target));
return target;
class Disease(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = soldiers.SoldierClass;
self.frequency = "0.20";
def applyTo(self, target, friends, foes, traps=[]):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.vulnerabilities += ['physical'];
self.msg = "* %s causes DISEASE to %s. Now the target is vulnerable to physical attacks."%(str(self.owner), str(target));
return target;
from traps import *;
class MapLabyrinth(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = Labyrinth;
self.group = "traps";
self.frequency = "0.90";
def applyTo(self, target, friends, foes, traps):
target = Ability.applyTo(self, target, friends, foes);
if (target == None):
return None;
target.hp = 0;
self.msg = "* %s MAPS %s, rendering it useless."%(str(self.owner), str(target));
return target;
class DisarmTrap(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = ArrowSlit;
self.group = "traps";
self.frequency = "0.90";
def applyTo(self, target, friends, foes, traps):
target = Ability.applyTo(self, target, friends, foes, traps);
if (target == None):
return None;
target.hp = 0;
self.msg = "* %s DISABLES %s, rendering it useless."%(str(self.owner), str(target));
return target;
class BridgeGap(Ability):
def __init__(self, owner):
Ability.__init__(self, owner);
self.targetType = Pit;
self.group = "traps";
self.frequency = "0.90";
def applyTo(self, target, friends, foes, traps):
target = Ability.applyTo(self, target, friends, foes, traps);
if (target == None):
return None;
target.hp = 0;
self.msg = "* %s COVERS %s, rendering it useless."%(str(self.owner), str(target));
return target;