-
Notifications
You must be signed in to change notification settings - Fork 7
/
buildings.py
339 lines (267 loc) · 9.33 KB
/
buildings.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import game_object
class Building(game_object.GameObject):
def __init__(self, hp=1, dps=0, splash=False, level=1, pos=(0, 0),
attack_range=1, name="archer", size=3, gold=0, elixir=0,
dark=0):
super(Building, self).__init__(pos, size)
self._hp = hp
self._dps = dps
self._splash = splash
self._level = level
self._range = attack_range
self._name = name
self._gold = gold
self._elixir = elixir
self._dark = dark
self._orig_hp = hp
self._target = None
# resource ratios
self._elixir_ratio = self._elixir / self._hp
self._gold_ratio = self._gold / self._hp
def get_size(self):
return self._size
def __repr__(self):
return super(Building, self).__repr__() + " " + self._name
def get_percent(self):
return self._hp / self._orig_hp
def take_damage(self, damage):
self._hp -= damage
self._elixir -= self._elixir_ratio * damage
self._gold -= self._gold_ratio * damage
def set_size(self, size):
self._size = size
def get_pos(self):
return self._pos
def get_gold(self):
return self._gold
def get_elixir(self):
return self._elixir
def get_hp(self):
return self._hp
def set_hp(self, hp):
self._hp = hp
def get_dps(self):
return self._dps
def set_pos(self, pos):
self._pos = pos
self.update_loc_list()
def get_range(self):
return self._range
def get_name(self):
return self._name
def get_level(self):
return self._level
def is_defensive(self):
return self._dps > 0
def create_html(self):
return (
'<div class ="coc-b coc-%s b-l%d" id="b-0" '
+ ' style="left: %dpx; visibility: visible; top: %dpx;" >'
+ ' <span class ="bi" > </span>'
+ ' <span class ="radius level-1" style="opacity: 0.195;" > </span>'
+ ' <span class ="level-s level-u" > </span> '
+ ' <span class ="level-s level-n" > %d </span> '
+ ' <span class ="level-s level-d" > </span>'
+ ' <span class ="coc-drag-arr" style="" > </span > </div >'
) % (
self._name,
self._level,
self._pos[1] * 20,
self._pos[0] * 20,
self._level,
)
def in_attack_range(self, other):
return self.in_range_l2(other, self._range)
def attack(self, army):
# check if target can still be hit
if (
self._target is None
or not self._target.is_alive()
or self._target not in army
or not self.in_attack_range(self._target)
):
self._target = min([(troop, self.distance_l2(troop)) for troop in army], key=lambda x: x[1])[0]
if self.in_attack_range(self._target):
# single target
if not self._splash:
self._target.set_hp(self._target.get_hp() - self._dps)
# destroy troop if dead
if not self._target.is_alive():
army.remove(self._target)
# splash damage
else:
for troop in army:
# for now set all splash ranges to 1
if troop.distance_l2(self._target) < 1:
troop.set_hp(troop.get_hp() - self._dps)
# destroy troop if dead
if not troop.is_alive():
army.remove(troop)
return army
class Cannon(Building):
HPS = [0, 400, 450, 500, 550, 590, 610, 630, 660, 690, 750, 900, 1080]
DPS = [0, 9, 11, 15, 19, 25, 31, 40, 48, 56, 65, 75, 86, 86]
def __init__(self, pos, level=7):
super(Cannon, self).__init__(
pos=pos,
name="cannon",
hp=Cannon.HPS[level],
dps=Cannon.DPS[level],
level=level,
attack_range=10
)
class ArcherTower(Building):
HPS = [0, 400, 450, 500, 550, 590, 610, 630, 660, 690, 750, 900, 1080]
DPS = [0, 11, 15, 19, 25, 30, 35, 42, 48, 56, 65, 75, 86, 98]
def __init__(self, pos, level=7):
super(ArcherTower, self).__init__(
pos=pos,
name="archer",
hp=ArcherTower.HPS[level],
dps=ArcherTower.DPS[level],
level=level,
attack_range=11
)
class TownHall(Building):
HPS = [0, 1500, 1600, 1850, 2100, 2400, 2800, 3200, 3900, 4600, 5500, 6800,
0, 0]
def __init__(self, pos, level=3):
super(TownHall, self).__init__(
pos=pos,
name="townhall",
hp=TownHall.HPS[level],
dps=0,
level=level,
size=4
)
class Wall(Building):
HPS = [0, 300, 500, 700, 900, 1400, 2e3, 2500, 3e3, 4e3, 5500, 7e3, 0, 0]
def __init__(self, pos, level=7):
super(Wall, self).__init__(
pos=pos,
name="wall",
hp=Wall.HPS[level],
dps=0,
level=level,
size=1
)
def create_html(self):
return (
'<div id="wall-39-17" class="wall lvl%d w3" '
+ 'style="left: %dpx; top: %dpx; display: block;"></div>\n'
) % (
self._level,
self._pos[1] * 20,
self._pos[0] * 20,
)
class Mortar(Building):
HPS = [0, 400, 450, 500, 550, 590, 610, 640, 0, 0, 0, 0, 0, 0]
DPS = [0, 4, 5, 6, 7, 8, 9, 11, 13]
def __init__(self, pos, level=7):
super(Mortar, self).__init__(
pos=pos,
name="mortar",
hp=Mortar.HPS[level],
dps=Mortar.DPS[level],
level=level,
attack_range=12
)
class Empty(Building):
def __init__(self, size=0, pos=(0, 0), level=0):
super(Empty, self).__init__(size=size, pos=pos)
class ElixirStorage(Building):
HPS = [0, 400, 600, 800, 1e3, 1200, 1500, 1600, 1700, 1800, 1900, 2100,
2500, 0]
RESOURCES = [0, 1500, 3000, 6000, 12000, 25000, 45000, 100000, 225000,
450000, 850000, 1750000, 2000000, 2500000]
def __init__(self, pos, level=4):
super(ElixirStorage, self).__init__(
pos=pos,
name="elixerstorage",
hp=ElixirStorage.HPS[level],
elixir=ElixirStorage.RESOURCES[level],
level=level,
)
class GoldStorage(Building):
HPS = [0, 400, 600, 800, 1e3, 1200, 1500, 1600, 1700, 1800, 1900, 2100,
2500, 0]
RESOURCES = [0, 1500, 3000, 6000, 12000, 25000, 45000, 100000, 225000,
450000, 850000, 1750000, 2000000, 2500000]
def __init__(self, pos, level=4):
super(GoldStorage, self).__init__(
pos=pos,
name="goldstorage",
hp=GoldStorage.HPS[level],
gold=GoldStorage.RESOURCES[level],
level=level,
)
class GoldCollector(Building):
HPS = [0, 400, 450, 500, 550, 590, 610, 630, 660, 680, 710, 750, 0, 0]
RESOURCES = [0,500,1000,1500,2500,10000,20000,30000,50000,75000,100000,150000,200000,250000]
def __init__(self, pos, level=4):
super(GoldCollector, self).__init__(
pos=pos,
name="gold",
gold=GoldCollector.RESOURCES[level],
hp=GoldCollector.HPS[level],
level=level,
)
class ElixirCollector(Building):
HPS = [0, 400, 450, 500, 550, 590, 610, 630, 660, 680, 710, 750, 0, 0]
RESOURCES = [0,500,1000,1500,2500,10000,20000,30000,50000,75000,100000,150000,200000,250000]
def __init__(self, pos, level=4):
super(ElixirCollector, self).__init__(
pos=pos,
name="elixer",
hp=ElixirCollector.HPS[level],
elixir=ElixirCollector.RESOURCES[level],
level=level,
)
class Barracks(Building):
HPS = [0, 250, 270, 280, 290, 310, 320, 340, 350, 390, 420, 0, 0, 0]
def __init__(self, pos, level=4):
super(Barracks, self).__init__(
pos=pos,
name="barracks",
hp=Barracks.HPS[level],
level=level,
)
class ClanCastle(Building):
HPS = [0, 1e3, 1400, 2e3, 2600, 3e3, 0, 0, 0, 0, 0, 0, 0, 0]
def __init__(self, pos, level=4):
super(ClanCastle, self).__init__(
pos=pos,
name="castle",
hp=ClanCastle.HPS[level],
level=level,
)
class ArmyCamps(Building):
HPS = [0, 400, 500, 600, 700, 800, 1e3, 1200, 1400, 0, 0, 0, 0, 0]
def __init__(self, pos, level=4):
super(ArmyCamps, self).__init__(
pos=pos,
name="army",
hp=ArmyCamps.HPS[level],
level=level,
size=5
)
class Labratory(Building):
HPS = [0, 500, 550, 600, 650, 700, 750, 830, 950, 1070, 0, 0, 0, 0]
def __init__(self, pos, level=4):
super(Labratory, self).__init__(
pos=pos,
name="research",
hp=Labratory.HPS[level],
level=level,
size=4
)
class Builder(Building):
HPS = [0, 250, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0]
def __init__(self, pos, level=4):
super(Builder, self).__init__(
pos=pos,
name="builder",
hp=Builder.HPS[level],
level=level,
size=2
)