-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemies.py
811 lines (729 loc) · 23.3 KB
/
enemies.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
import random
from typing import Dict, List, Any, Tuple
def calculate_npc_hp(base_hp: int, level: int) -> int:
return int(base_hp * (1 + 0.20 * (level - 1))) # 20% increase per level
def calculate_damage(base_min_damage: int, base_max_damage: int, level: int) -> Tuple[int, int]:
scaling_factor = 1 + 0.1 * (level - 1) # 10% increase per level
min_damage = int(base_min_damage * scaling_factor)
max_damage = int(base_max_damage * scaling_factor)
return min_damage, max_damage
def calculate_armor(base_armor: int, level: int) -> int:
return base_armor + int(0.5 * (level - 1)) # 0.5 armor increase per level
def calculate_experience(experience_value: int, level: int) -> int:
return int(experience_value * (1 + 0.05 * (level - 1))) # 5% increase per level
def calculate_evasion(evasion_chance: float, level: int) -> float:
return evasion_chance + (0.002 * (level - 1)) # 0.2% increase per level
def calculate_block(block_chance: float, level: int) -> float:
return block_chance + (0.002 * (level - 1)) # 0.2% increase per level
class Enemy:
type = "enemy"
base_hp = 100
base_min_damage = 1
base_max_damage = 2
base_armor = 0
crit_chance = 0.05
crit_damage = 1.5
drop_chance = 0.1
regular_drop: Dict[str, int] = {}
probability = 0
map_size = 1000
max_entities = None
max_entities_total = None
herd_probability = 0.5
min_level = 1
max_level = 100
experience_value = 10
evasion_chance = 0.0
block_chance = 0.0
block_reduction = 0.5
biome = "any"
def __init__(self, level: int):
self.level = max(self.min_level, min(level, self.max_level))
self.max_hp = calculate_npc_hp(self.base_hp, self.level)
self.hp = self.max_hp
self.min_damage, self.max_damage = calculate_damage(self.base_min_damage, self.base_max_damage, self.level)
self.armor = calculate_armor(self.base_armor, self.level)
self.alive = True
self.experience = calculate_experience(self.experience_value, self.level)
self.evasion = calculate_evasion(self.evasion_chance, self.level)
self.block = calculate_block(self.block_chance, self.level)
def roll_damage(self):
damage = random.randint(self.min_damage, self.max_damage)
message = "normal hit"
if random.random() < self.crit_chance:
damage = int(damage * self.crit_damage)
message = "critical hit"
return {"damage": damage, "message": message}
def attempt_evasion(self):
return random.random() < self.evasion
def attempt_block(self):
return random.random() < self.block
def take_damage(self, damage: int) -> Dict[str, Any]:
mitigated_damage = max(0, damage - self.armor)
self.hp -= mitigated_damage
message = f"The {self.type} took {mitigated_damage} damage."
special_effect = self.process_special_effects()
if special_effect:
message += f" {special_effect}"
return {
"damage_taken": damage,
"current_hp": self.hp,
"message": message,
"is_defeated": self.hp <= 0
}
def process_special_effects(self) -> str:
"""
Process any special effects that occur when the enemy takes damage.
Override this method in subclasses to implement enemy-specific effects.
"""
return ""
def get_actions(self, user: str) -> List[Dict[str, str]]:
return [{"name": "fight", "action": f"/fight?target={self.type}"}]
def to_dict(self) -> Dict:
return {
"type": self.type,
"level": self.level,
}
class Skeleton(Enemy):
type = "skeleton"
base_hp = 50
base_min_damage = 5
base_max_damage = 10
base_armor = 2
crit_chance = 0.2
crit_damage = 1.5
drop_chance = 0.5
regular_drop = {"bone": 2}
probability = 0.24
max_entities = 300
max_entities_total = 500
herd_probability = 0.4
min_level = 5
max_level = 30
experience_value = 20
reassemble_chance = 0.2
block_chance = 0.1
block_reduction = 0.3
biome = "graveyard"
def __init__(self, level: int):
super().__init__(level)
self.has_reassembled = False
def process_special_effects(self) -> str:
if self.hp <= 0 and not self.has_reassembled and random.random() < self.reassemble_chance:
self.hp = self.calculate_npc_hp() // 2 # Reassemble with half HP
self.has_reassembled = True
return "The skeleton has reassembled itself!"
return ""
class Boar(Enemy):
type = "boar"
base_hp = 35
base_min_damage = 2
base_max_damage = 4
crit_chance = 0.1
crit_damage = 1.5
drop_chance = 0.6
regular_drop = {"food": 1}
probability = 0.1
max_entities = 500
max_entities_total = 1500
herd_probability = 0.7
min_level = 5
max_level = 20
experience_value = 10
block_chance = 0.1
block_reduction = 0.3
biome="forest"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return [{"name": "hunt", "action": f"/fight?target={self.type}"}]
class Wolf(Enemy):
type = "wolf"
base_hp = 60
base_min_damage = 3
base_max_damage = 7
crit_chance = 0.25
crit_damage = 1.8
drop_chance = 0.6
regular_drop = {"wolf pelt": 1}
probability = 0.2
max_entities = 500
max_entities_total = 1000
herd_probability = 0.8
min_level = 8
max_level = 25
experience_value = 15
evasion_chance = 0.15
biome="forest"
def get_actions(self, user: str) -> List[Dict[str, str]]:
return [{"name": "hunt", "action": f"/fight?target={self.type}"}]
class Goblin(Enemy):
type = "goblin"
base_hp = 45
base_min_damage = 4
base_max_damage = 6
base_armor = 1
crit_chance = 0.15
crit_damage = 1.6
drop_chance = 0.4
regular_drop = {"gold": 5}
probability = 0.24
max_entities = 200
max_entities_total = 1000
herd_probability = 0.5
min_level = 5
max_level = 45
experience_value = 12
evasion_chance = 0.1
block_chance = 0.05
block_reduction = 0.2
biome="pond"
class Specter(Enemy):
type = "specter"
base_hp = 80
base_min_damage = 10
base_max_damage = 20
crit_chance = 0.3
crit_damage = 2.0
drop_chance = 0.6
regular_drop = {"ectoplasm": 1}
probability = 0.24
max_entities = 100
max_entities_total = 1000
herd_probability = 0.3
min_level = 20
max_level = 65
experience_value = 40
evasion_chance = 0.25
biome="cavern"
def roll_damage(self):
damage_info = super().roll_damage()
if damage_info["message"] == "critical hit":
# Specters drain health on critical hits
self.hp += damage_info["damage"] // 2
return damage_info
class Hatchling(Enemy):
type = "hatchling"
base_hp = 150
base_min_damage = 15
base_max_damage = 25
base_armor = 5
crit_chance = 0.2
crit_damage = 1.8
drop_chance = 0.8
regular_drop = {"dragon scale": 1}
probability = 0.24
max_entities = 50
max_entities_total = 1000
herd_probability = 0.2
min_level = 30
max_level = 70
experience_value = 80
block_chance = 0.15
block_reduction = 0.4
biome="cavern"
def __init__(self, level: int):
super().__init__(level)
self.breath_attack_cooldown = 0
def roll_damage(self):
if self.breath_attack_cooldown == 0:
# Use breath attack
damage = random.randint(int(self.max_damage * 1.5), int(self.max_damage * 2))
self.breath_attack_cooldown = 3
return {"damage": damage, "message": "breath attack"}
else:
# Normal attack
damage_info = super().roll_damage()
self.breath_attack_cooldown -= 1
return damage_info
class Bandit(Enemy):
type = "bandit"
base_hp = 70
base_min_damage = 8
base_max_damage = 15
base_armor = 2
crit_chance = 0.2
crit_damage = 1.7
drop_chance = 0.5
regular_drop = {"gold": 10}
probability = 0.24
max_entities = 250
max_entities_total = 1000
herd_probability = 0.4
min_level = 10
max_level = 75
experience_value = 25
evasion_chance = 0.1
block_chance = 0.1
block_reduction = 0.3
biome = "cavern"
def roll_damage(self):
damage_info = super().roll_damage()
if random.random() < 0.1: # 10% chance to steal gold
damage_info["message"] += " and stole some gold"
return damage_info
class Troll(Enemy):
type = "troll"
base_hp = 200
base_min_damage = 15
base_max_damage = 30
base_armor = 8
crit_chance = 0.1
crit_damage = 2.0
drop_chance = 0.7
regular_drop = {"troll hide": 1}
probability = 0.24
max_entities = 100
max_entities_total = 1000
herd_probability = 0.2
min_level = 25
max_level = 80
experience_value = 70
regeneration_rate = 5
block_chance = 0.2
block_reduction = 0.5
biome = "mountain"
def calculate_npc_hp(self):
hp = super().calculate_npc_hp()
return hp + self.regeneration_rate * (self.level - 1) # Additional HP from regeneration
class Harpy(Enemy):
type = "harpy"
base_hp = 90
base_min_damage = 12
base_max_damage = 18
base_armor = 1
crit_chance = 0.3
crit_damage = 1.6
drop_chance = 0.6
regular_drop = {"feather": 3}
probability = 0.24
max_entities = 150
max_entities_total = 1000
herd_probability = 0.5
min_level = 15
max_level = 110
experience_value = 35
evasion_chance = 0.2
biome = "mountain"
def roll_damage(self):
damage_info = super().roll_damage()
if self.attempt_evasion():
damage_info["damage"] = 0
damage_info["message"] = "evaded your attack"
return damage_info
class Orc(Enemy):
type = "orc"
base_hp = 120
base_min_damage = 10
base_max_damage = 18
base_armor = 4
crit_chance = 0.12
crit_damage = 1.8
drop_chance = 0.6
regular_drop = {"orc tusk": 1}
probability = 0.24
max_entities = 150
max_entities_total = 1000
herd_probability = 0.4
min_level = 20
max_level = 200
experience_value = 50
block_chance = 0.15
block_reduction = 0.35
biome = "cavern"
class Spider(Enemy):
type = "spider"
base_hp = 65
base_min_damage = 6
base_max_damage = 12
base_armor = 2
crit_chance = 0.18
crit_damage = 1.7
drop_chance = 0.5
regular_drop = {"spider silk": 1, "venom sac": 1}
probability = 0.24
max_entities = 180
max_entities_total = 1000
herd_probability = 0.6
min_level = 12
max_level = 60
experience_value = 30
poison_chance = 0.15
poison_duration = 3
poison_damage = 2
evasion_chance = 0.15
biome = "cavern"
def roll_damage(self):
damage_info = super().roll_damage()
if random.random() < self.poison_chance:
damage_info["message"] += f" and poisoned for {self.poison_damage} damage over {self.poison_duration} turns"
return damage_info
class Rat(Enemy):
type = "rat"
base_hp = 20
base_min_damage = 1
base_max_damage = 2
crit_chance = 0.05
crit_damage = 1.3
drop_chance = 0.8
regular_drop = {"rat tail": 1}
probability = 0.24
max_entities = 1000
max_entities_total = 1000
herd_probability = 0.8
min_level = 1
max_level = 10
experience_value = 5
evasion_chance = 0.2 # Rats are small and quick, so they have a higher base evasion
biome = "cavern"
class Minotaur(Enemy):
type = "minotaur"
base_hp = 300
base_min_damage = 25
base_max_damage = 40
base_armor = 10
crit_chance = 0.15
crit_damage = 2.2
drop_chance = 0.8
regular_drop = {"minotaur horn": 1}
probability = 0.24
max_entities = 50
max_entities_total = 1000
herd_probability = 0.1
min_level = 25
max_level = 80
experience_value = 100
block_chance = 0.25
block_reduction = 0.6
biome = "rock"
def __init__(self, level: int):
super().__init__(level)
self.charge_cooldown = 0
def roll_damage(self):
if self.charge_cooldown == 0:
damage = random.randint(int(self.max_damage * 1.5), int(self.max_damage * 2.5))
self.charge_cooldown = 3
return {"damage": damage, "message": "charging attack"}
else:
damage_info = super().roll_damage()
self.charge_cooldown -= 1
return damage_info
class Wraith(Enemy):
type = "wraith"
base_hp = 120
base_min_damage = 18
base_max_damage = 25
crit_chance = 0.25
crit_damage = 1.9
drop_chance = 0.7
regular_drop = {"soul essence": 1}
probability = 0.24
max_entities = 120
max_entities_total = 1000
herd_probability = 0.3
min_level = 25
max_level = 70
experience_value = 75
phase_chance = 0.3
evasion_chance = 0.3
biome = "pond"
def roll_damage(self):
damage_info = super().roll_damage()
if random.random() < self.phase_chance:
damage_info["damage"] = int(damage_info["damage"] * 1.5) # Wraith phases through armor
damage_info["message"] += " (phased)"
return damage_info
class Dragon(Enemy):
type = "dragon"
base_hp = 500
base_min_damage = 40
base_max_damage = 60
base_armor = 20
crit_chance = 0.2
crit_damage = 2.5
drop_chance = 1.0
regular_drop = {"dragon scale": 3, "dragon tooth": 1}
probability = 0.12
max_entities = 50
max_entities_total = 250
herd_probability = 0
min_level = 100
max_level = 1000
experience_value = 500
block_chance = 0.3
block_reduction = 0.7
biome = "cavern"
def __init__(self, level: int):
super().__init__(level)
self.breath_attack_cooldown = 0
def roll_damage(self):
if self.breath_attack_cooldown == 0:
# Use breath attack
damage = random.randint(int(self.max_damage * 2), int(self.max_damage * 3))
self.breath_attack_cooldown = 3
return {"damage": damage, "message": "devastating breath attack"}
else:
# Normal attack
damage_info = super().roll_damage()
self.breath_attack_cooldown -= 1
return damage_info
class Lizarian(Enemy):
type = "lizarian"
base_hp = 400
base_min_damage = 35
base_max_damage = 55
base_armor = 15
crit_chance = 0.2
crit_damage = 2.2
drop_chance = 0.9
regular_drop = {"lizard scale": 2, "magic essence": 1}
probability = 0.15
max_entities = 75
max_entities_total = 300
herd_probability = 0.1
min_level = 35
max_level = 750
experience_value = 300
evasion_chance = 0.15
block_chance = 0.2
block_reduction = 0.5
biome = "desert"
def __init__(self, level: int):
super().__init__(level)
self.spell_charges = 3
def roll_damage(self):
if self.spell_charges > 0:
spell_type = random.choice(["fireball", "ice shard", "lightning bolt", "personal data theft"])
damage = random.randint(int(self.max_damage * 1.5), int(self.max_damage * 2.5))
self.spell_charges -= 1
return {"damage": damage, "message": f"cast {spell_type}"}
else:
damage_info = super().roll_damage()
if random.random() < 0.2: # 20% chance to regain a spell charge
self.spell_charges = min(self.spell_charges + 1, 3)
damage_info["message"] += " (regained spell charge)"
return damage_info
class Golem(Enemy):
type = "golem"
base_hp = 600
base_min_damage = 45
base_max_damage = 70
base_armor = 30
crit_chance = 0.1
crit_damage = 2.0
drop_chance = 0.95
regular_drop = {"golem core": 1, "enchanted stone": 3}
probability = 0.12
max_entities = 60
max_entities_total = 250
herd_probability = 0.05
min_level = 45
max_level = 400
experience_value = 400
block_chance = 0.4
block_reduction = 0.8
biome = "rock"
def __init__(self, level: int):
super().__init__(level)
self.elemental_state = "neutral"
self.state_duration = 0
def roll_damage(self):
if self.state_duration <= 0:
self.elemental_state = random.choice(["fire", "ice", "lightning"])
self.state_duration = 3
damage_info = super().roll_damage()
if self.elemental_state == "fire":
damage_info["damage"] = int(damage_info["damage"] * 1.3)
damage_info["message"] += " (fire enhanced)"
elif self.elemental_state == "ice":
self.armor += 10
damage_info["message"] += " (ice armored)"
elif self.elemental_state == "lightning":
if random.random() < 0.3:
damage_info["damage"] *= 2
damage_info["message"] += " (lightning strike)"
self.state_duration -= 1
return damage_info
def calculate_armor(self):
return super().calculate_armor() + int(0.2 * self.level) # Additional armor scaling
class Zombie(Enemy):
type = "zombie"
base_hp = 450
base_min_damage = 40
base_max_damage = 60
base_armor = 10
crit_chance = 0.15
crit_damage = 1.8
drop_chance = 0.85
regular_drop = {"rotten flesh": 2, "zombie brain": 1}
probability = 0.18
max_entities = 100
max_entities_total = 400
herd_probability = 0.4
min_level = 20
max_level = 240
experience_value = 250
block_chance = 0.1
block_reduction = 0.3
biome = "graveyard"
def __init__(self, level: int):
super().__init__(level)
self.infection_chance = 0.2
self.frenzy_threshold = 0.3
def roll_damage(self):
damage_info = super().roll_damage()
if random.random() < self.infection_chance:
damage_info["damage"] += int(self.max_damage * 0.5)
damage_info["message"] += " (infected)"
if self.hp / self.max_hp <= self.frenzy_threshold:
damage_info["damage"] = int(damage_info["damage"] * 1.5)
damage_info["message"] += " (frenzy)"
return damage_info
def calculate_npc_hp(self):
return super().calculate_npc_hp() + int(2 * self.level)
class Basilisk(Enemy):
type = "basilisk"
base_hp = 180
base_min_damage = 20
base_max_damage = 35
base_armor = 12
crit_chance = 0.15
crit_damage = 2.0
drop_chance = 0.7
regular_drop = {"basilisk scale": 2, "petrified venom": 1}
probability = 0.2
max_entities = 80
max_entities_total = 300
herd_probability = 0.1
min_level = 30
max_level = 90
experience_value = 150
petrify_chance = 0.2
block_chance = 0.2
block_reduction = 0.5
biome = "desert"
def roll_damage(self):
damage_info = super().roll_damage()
if random.random() < self.petrify_chance:
damage_info["damage"] *= 2 # Double damage on petrify
damage_info["message"] += " (petrifying gaze)"
return damage_info
class Djinn(Enemy):
type = "djinn"
base_hp = 250
base_min_damage = 30
base_max_damage = 45
base_armor = 8
crit_chance = 0.2
crit_damage = 2.2
drop_chance = 0.8
regular_drop = {"magical essence": 3, "djinn's lamp": 1}
probability = 0.15
max_entities = 60
max_entities_total = 200
herd_probability = 0.05
min_level = 40
max_level = 100
experience_value = 200
wish_chance = 0.25
evasion_chance = 0.3
biome = "desert"
def roll_damage(self):
if random.random() < self.wish_chance:
effect = random.choice(["heal", "power", "defense"])
if effect == "heal":
self.hp = min(self.hp + self.max_hp // 4, self.max_hp)
return {"damage": 0, "message": "granted a wish of healing"}
elif effect == "power":
damage = random.randint(self.max_damage, self.max_damage * 2)
return {"damage": damage, "message": "granted a wish of power"}
else: # defense
self.armor *= 2 # Temporary armor boost
return {"damage": 0, "message": "granted a wish of protection"}
return super().roll_damage()
class Manticore(Enemy):
type = "manticore"
base_hp = 300
base_min_damage = 35
base_max_damage = 50
base_armor = 15
crit_chance = 0.18
crit_damage = 2.1
drop_chance = 0.75
regular_drop = {"manticore spike": 3, "lion's mane": 1}
probability = 0.18
max_entities = 70
max_entities_total = 250
herd_probability = 0.15
min_level = 55
max_level = 110
experience_value = 250
spike_volley_chance = 0.3
block_chance = 0.15
block_reduction = 0.4
biome = "desert"
def roll_damage(self):
if random.random() < self.spike_volley_chance:
num_spikes = random.randint(3, 6)
total_damage = sum(random.randint(self.base_min_damage, self.base_max_damage) for _ in range(num_spikes))
return {"damage": total_damage, "message": f"launched a volley of {num_spikes} spikes"}
return super().roll_damage()
class Sandworm(Enemy):
type = "sandworm"
base_hp = 400
base_min_damage = 40
base_max_damage = 60
base_armor = 20
crit_chance = 0.1
crit_damage = 2.5
drop_chance = 0.9
regular_drop = {"sandworm segment": 5, "desert spice": 2}
probability = 0.12
max_entities = 50
max_entities_total = 150
herd_probability = 0
min_level = 70
max_level = 150
experience_value = 350
burrow_chance = 0.4
swallow_chance = 0.15
block_chance = 0.25
block_reduction = 0.6
biome = "desert"
def __init__(self, level: int):
super().__init__(level)
self.is_burrowed = False
def roll_damage(self):
if self.is_burrowed:
self.is_burrowed = False
damage = random.randint(int(self.max_damage * 1.5), int(self.max_damage * 2.5))
return {"damage": damage, "message": "erupted from the sand with a devastating attack"}
elif random.random() < self.burrow_chance:
self.is_burrowed = True
return {"damage": 0, "message": "burrowed into the sand"}
elif random.random() < self.swallow_chance:
damage = self.max_damage * 2
return {"damage": damage, "message": "attempted to swallow you whole"}
return super().roll_damage()
def take_damage(self, damage: int) -> Dict[str, Any]:
if self.is_burrowed:
damage = damage // 2 # Half damage while burrowed
return super().take_damage(damage)
def get_all_enemy_subclasses():
all_subclasses = set()
classes_to_check = list(Enemy.__subclasses__())
while classes_to_check:
subclass = classes_to_check.pop()
if subclass not in all_subclasses:
all_subclasses.add(subclass)
classes_to_check.extend(subclass.__subclasses__())
return all_subclasses
# The rest of the code remains the same
enemy_types = {}
for cls in get_all_enemy_subclasses():
if hasattr(cls, 'type'):
enemy_types[cls.type] = cls
else:
print(f"Warning: {cls.__name__} does not have a 'type' attribute.")
# Optionally, you can print out the collected enemy types for verification
print("Collected enemy types:")
for enemy_type, enemy_class in enemy_types.items():
print(f"{enemy_type}: {enemy_class.__name__}")