-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_effects.py
More file actions
740 lines (576 loc) · 30.8 KB
/
status_effects.py
File metadata and controls
740 lines (576 loc) · 30.8 KB
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
import random
from typing import Dict, List, Tuple, Optional, Any
from enum import Enum
class StatusType(Enum):
BURN = "burn"
PARALYSIS = "paralysis"
FREEZE = "freeze"
SLEEP = "sleep"
POISON = "poison"
TOXIC = "toxic"
class StatusEffect:
def __init__(self, status_type: str, duration: int = -1, counter: int = 0):
self.status_type = status_type
self.duration = duration
self.counter = counter
self.config = STATUS_EFFECTS_CONFIG.get(status_type, {})
self.name = self.config.get('name', status_type.title())
self.is_major = self.config.get('is_major', False)
# Initialize sleep duration if this is a sleep status
if status_type == StatusType.SLEEP.value and duration == -1:
duration_range = self.config.get('duration_range', (1, 3))
self.duration = random.randint(*duration_range)
def can_apply(self, pokemon) -> bool:
# Major status conditions cannot be applied if Pokemon already has one
if self.is_major and hasattr(pokemon, 'major_status') and pokemon.major_status:
return False
# Cannot apply the same status twice
if hasattr(pokemon, 'status_effects') and self.status_type in pokemon.status_effects:
return False
return True
def apply(self, pokemon) -> str:
# Check for specific failure reasons and return appropriate messages
if hasattr(pokemon, 'status_effects') and self.status_type in pokemon.status_effects:
# Pokemon already has this specific status
message_template = self.config.get('messages', {}).get('fail_already_has', "{pokemon} already has {status}!")
return message_template.format(pokemon=pokemon.name.capitalize(), status=self.name.lower())
if self.is_major and hasattr(pokemon, 'major_status') and pokemon.major_status:
# Pokemon already has a major status condition
message_template = self.config.get('messages', {}).get('fail_major_status', "{pokemon} already has a major status condition!")
return message_template.format(pokemon=pokemon.name.capitalize())
if not self.can_apply(pokemon):
# Generic failure case
return ""
# Apply the status effect
if not hasattr(pokemon, 'status_effects'):
pokemon.status_effects = {}
if not hasattr(pokemon, 'major_status'):
pokemon.major_status = None
pokemon.status_effects[self.status_type] = self
if self.is_major:
pokemon.major_status = self.status_type
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_applied', self.status_type, self.name)
# Return application message
message_template = self.config.get('messages', {}).get('apply', "{pokemon} was affected by {status}!")
return message_template.format(pokemon=pokemon.name.capitalize(), status=self.name)
def process_turn_start(self, pokemon) -> List[str]:
messages = []
# Handle freeze thaw chance
if self.status_type == StatusType.FREEZE.value:
recovery_chance = self.config.get('recovery_chance', 0)
if random.random() < recovery_chance:
messages.append(self._recover_status(pokemon))
return messages
# Handle sleep wake up
if self.status_type == StatusType.SLEEP.value:
if self.duration > 0:
self.duration -= 1
if self.duration <= 0:
messages.append(self._recover_status(pokemon))
return messages
return messages
def process_turn_end(self, pokemon) -> List[str]:
messages = []
# Handle damage-dealing status effects
turn_damage = self.config.get('turn_damage', 0)
if turn_damage == 'escalating' or (isinstance(turn_damage, (int, float)) and turn_damage > 0):
if self.status_type == StatusType.TOXIC.value:
# Toxic damage increases each turn
self.counter += 1
damage = int(pokemon.max_hp * (self.counter / 16))
else:
# Regular damage (burn, poison)
damage = int(pokemon.max_hp * turn_damage)
# Apply damage (but don't let poison kill the Pokemon)
if self.status_type == StatusType.POISON.value and pokemon.current_hp <= damage:
damage = max(0, pokemon.current_hp - 1)
if damage > 0:
pokemon.current_hp = max(0, pokemon.current_hp - damage)
damage_message = self.config.get('messages', {}).get('damage', "{pokemon} is hurt by {status}!")
messages.append(damage_message.format(pokemon=pokemon.name.capitalize(), status=self.name))
return messages
def affects_move_usage(self, pokemon) -> Tuple[bool, str]:
prevents_move = self.config.get('prevents_move', False)
if not prevents_move:
return False, ""
# Handle chance-based move prevention (paralysis)
if self.status_type == StatusType.PARALYSIS.value:
prevention_chance = self.config.get('move_prevention_chance', 0)
if random.random() < prevention_chance:
message = self.config.get('messages', {}).get('prevent_move', "{pokemon} can't move!")
return True, message.format(pokemon=pokemon.name.capitalize())
return False, ""
# Handle guaranteed move prevention (freeze, sleep)
if self.status_type in [StatusType.FREEZE.value, StatusType.SLEEP.value]:
message = self.config.get('messages', {}).get('prevent_move', "{pokemon} can't move!")
return True, message.format(pokemon=pokemon.name.capitalize())
return False, ""
def modify_stat(self, pokemon, stat_name: str, stat_value: int) -> int:
stat_modifiers = self.config.get('stat_modifiers', {})
if stat_name in stat_modifiers:
modifier = stat_modifiers[stat_name]
return int(stat_value * modifier)
return stat_value
def _recover_status(self, pokemon) -> str:
# Remove status from Pokemon
if hasattr(pokemon, 'status_effects') and self.status_type in pokemon.status_effects:
del pokemon.status_effects[self.status_type]
if hasattr(pokemon, 'major_status') and pokemon.major_status == self.status_type:
pokemon.major_status = None
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_removed', self.status_type, self.name)
# Return recovery message
message_template = self.config.get('messages', {}).get('recover', "{pokemon} recovered from {status}!")
return message_template.format(pokemon=pokemon.name.capitalize(), status=self.name)
# Status Effects Configuration Dictionary
STATUS_EFFECTS_CONFIG = {
StatusType.BURN.value: {
'name': 'Burn',
'is_major': True,
'turn_damage': 1/16, # 1/16 of max HP per turn
'stat_modifiers': {'attack': 0.5}, # Physical attack halved
'prevents_move': False,
'recovery_chance': 0, # Never recovers naturally
'messages': {
'apply': "{pokemon} was burned!",
'damage': "{pokemon} is hurt by its burn!",
'fail_already_has': "{pokemon} is already burned!",
'fail_major_status': "{pokemon} already has a major status condition!"
}
},
StatusType.PARALYSIS.value: {
'name': 'Paralysis',
'is_major': True,
'turn_damage': 0,
'stat_modifiers': {'speed': 0.5}, # Speed halved
'prevents_move': True,
'move_prevention_chance': 0.25, # 25% chance to be unable to move
'recovery_chance': 0,
'messages': {
'apply': "{pokemon} is paralyzed! It may be unable to move!",
'prevent_move': "{pokemon} is paralyzed! It can't move!",
'fail_already_has': "{pokemon} is already paralyzed!",
'fail_major_status': "{pokemon} already has a major status condition!"
}
},
StatusType.FREEZE.value: {
'name': 'Freeze',
'is_major': True,
'turn_damage': 0,
'prevents_move': True,
'move_prevention_chance': 1.0, # Always prevents moves
'recovery_chance': 0.2, # 20% chance to thaw each turn
'messages': {
'apply': "{pokemon} was frozen solid!",
'prevent_move': "{pokemon} is frozen solid!",
'recover': "{pokemon} thawed out!",
'fail_already_has': "{pokemon} is already frozen!",
'fail_major_status': "{pokemon} already has a major status condition!"
}
},
StatusType.SLEEP.value: {
'name': 'Sleep',
'is_major': True,
'turn_damage': 0,
'prevents_move': True,
'move_prevention_chance': 1.0, # Always prevents moves
'duration_range': (1, 3), # Sleep for 1-3 turns
'messages': {
'apply': "{pokemon} fell asleep!",
'prevent_move': "{pokemon} is fast asleep.",
'recover': "{pokemon} woke up!",
'fail_already_has': "{pokemon} is already asleep!",
'fail_major_status': "{pokemon} already has a major status condition!"
}
},
StatusType.POISON.value: {
'name': 'Poison',
'is_major': True,
'turn_damage': 1/8, # 1/8 max HP per turn
'prevents_move': False,
'recovery_chance': 0,
'messages': {
'apply': "{pokemon} was poisoned!",
'damage': "{pokemon} is hurt by poison!",
'fail_already_has': "{pokemon} is already poisoned!",
'fail_major_status': "{pokemon} already has a major status condition!"
}
},
StatusType.TOXIC.value: {
'name': 'Badly Poisoned',
'is_major': True,
'turn_damage': 'escalating', # Handled specially in process_turn_end
'prevents_move': False,
'recovery_chance': 0,
'messages': {
'apply': "{pokemon} was badly poisoned!",
'damage': "{pokemon} is hurt by poison!",
'fail_already_has': "{pokemon} is already badly poisoned!",
'fail_major_status': "{pokemon} already has a major status condition!"
}
}
}
class BurnStatusEffect(StatusEffect):
def __init__(self, **kwargs):
super().__init__(StatusType.BURN.value, **kwargs)
def process_turn_end(self, pokemon) -> List[str]:
messages = []
# Calculate burn damage (1/16 of max HP)
damage = int(pokemon.max_hp * (1/16))
if damage > 0:
pokemon.current_hp = max(0, pokemon.current_hp - damage)
damage_message = self.config.get('messages', {}).get('damage', "{pokemon} is hurt by its burn!")
messages.append(damage_message.format(pokemon=pokemon.name.capitalize()))
return messages
def modify_stat(self, pokemon, stat_name: str, stat_value: int) -> int:
if stat_name == 'attack':
return int(stat_value * 0.5)
return stat_value
def can_apply(self, pokemon) -> bool:
# Check for existing major status
if hasattr(pokemon, 'major_status') and pokemon.major_status:
return False
# Check for existing burn
if hasattr(pokemon, 'status_effects') and StatusType.BURN.value in pokemon.status_effects:
return False
return True
def apply(self, pokemon) -> str:
# Check for specific failure reasons and return appropriate messages
if hasattr(pokemon, 'status_effects') and StatusType.BURN.value in pokemon.status_effects:
# Pokemon already has burn
message_template = self.config.get('messages', {}).get('fail_already_has', "{pokemon} is already burned!")
return message_template.format(pokemon=pokemon.name.capitalize())
if hasattr(pokemon, 'major_status') and pokemon.major_status:
# Pokemon already has a major status condition
message_template = self.config.get('messages', {}).get('fail_major_status', "{pokemon} already has a major status condition!")
return message_template.format(pokemon=pokemon.name.capitalize())
if not self.can_apply(pokemon):
return ""
# Initialize status tracking if needed
if not hasattr(pokemon, 'status_effects'):
pokemon.status_effects = {}
if not hasattr(pokemon, 'major_status'):
pokemon.major_status = None
# Apply burn status
pokemon.status_effects[StatusType.BURN.value] = self
pokemon.major_status = StatusType.BURN.value
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_applied', StatusType.BURN.value, 'Burn')
# Return application message
return "{pokemon} was burned!".format(pokemon=pokemon.name.capitalize())
class ParalysisStatusEffect(StatusEffect):
def __init__(self, **kwargs):
"""Initialize paralysis status effect."""
super().__init__(StatusType.PARALYSIS.value, **kwargs)
def affects_move_usage(self, pokemon) -> Tuple[bool, str]:
# 25% chance to prevent move usage
prevention_chance = 0.25
if random.random() < prevention_chance:
message = "{pokemon} is paralyzed! It can't move!".format(pokemon=pokemon.name.capitalize())
return True, message
return False, ""
def modify_stat(self, pokemon, stat_name: str, stat_value: int) -> int:
if stat_name == 'speed':
return int(stat_value * 0.5)
return stat_value
def can_apply(self, pokemon) -> bool:
# Check for existing major status
if hasattr(pokemon, 'major_status') and pokemon.major_status:
return False
# Check for existing paralysis
if hasattr(pokemon, 'status_effects') and StatusType.PARALYSIS.value in pokemon.status_effects:
return False
return True
def apply(self, pokemon) -> str:
# Check for specific failure reasons and return appropriate messages
if hasattr(pokemon, 'status_effects') and StatusType.PARALYSIS.value in pokemon.status_effects:
# Pokemon already has paralysis
message_template = self.config.get('messages', {}).get('fail_already_has', "{pokemon} is already paralyzed!")
return message_template.format(pokemon=pokemon.name.capitalize())
if hasattr(pokemon, 'major_status') and pokemon.major_status:
# Pokemon already has a major status condition
message_template = self.config.get('messages', {}).get('fail_major_status', "{pokemon} already has a major status condition!")
return message_template.format(pokemon=pokemon.name.capitalize())
if not self.can_apply(pokemon):
return ""
# Initialize status tracking if needed
if not hasattr(pokemon, 'status_effects'):
pokemon.status_effects = {}
if not hasattr(pokemon, 'major_status'):
pokemon.major_status = None
# Apply paralysis status
pokemon.status_effects[StatusType.PARALYSIS.value] = self
pokemon.major_status = StatusType.PARALYSIS.value
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_applied', StatusType.PARALYSIS.value, 'Paralysis')
# Return application message
return "{pokemon} is paralyzed! It may be unable to move!".format(pokemon=pokemon.name.capitalize())
def process_turn_start(self, pokemon) -> List[str]:
return []
def process_turn_end(self, pokemon) -> List[str]:
return []
class FreezeStatusEffect(StatusEffect):
def __init__(self, **kwargs):
super().__init__(StatusType.FREEZE.value, **kwargs)
def affects_move_usage(self, pokemon) -> Tuple[bool, str]:
message = "{pokemon} is frozen solid!".format(pokemon=pokemon.name.capitalize())
return True, message
def process_turn_start(self, pokemon) -> List[str]:
messages = []
# 20% chance to thaw out
recovery_chance = 0.2
if random.random() < recovery_chance:
messages.append(self._recover_status(pokemon))
return messages
def process_turn_end(self, pokemon) -> List[str]:
return []
def can_apply(self, pokemon) -> bool:
# Check for existing major status
if hasattr(pokemon, 'major_status') and pokemon.major_status:
return False
# Check for existing freeze
if hasattr(pokemon, 'status_effects') and StatusType.FREEZE.value in pokemon.status_effects:
return False
return True
def apply(self, pokemon) -> str:
# Check for specific failure reasons and return appropriate messages
if hasattr(pokemon, 'status_effects') and StatusType.FREEZE.value in pokemon.status_effects:
# Pokemon already has freeze
message_template = self.config.get('messages', {}).get('fail_already_has', "{pokemon} is already frozen!")
return message_template.format(pokemon=pokemon.name.capitalize())
if hasattr(pokemon, 'major_status') and pokemon.major_status:
# Pokemon already has a major status condition
message_template = self.config.get('messages', {}).get('fail_major_status', "{pokemon} already has a major status condition!")
return message_template.format(pokemon=pokemon.name.capitalize())
if not self.can_apply(pokemon):
return ""
# Initialize status tracking if needed
if not hasattr(pokemon, 'status_effects'):
pokemon.status_effects = {}
if not hasattr(pokemon, 'major_status'):
pokemon.major_status = None
# Apply freeze status
pokemon.status_effects[StatusType.FREEZE.value] = self
pokemon.major_status = StatusType.FREEZE.value
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_applied', StatusType.FREEZE.value, 'Freeze')
# Return application message
return "{pokemon} was frozen solid!".format(pokemon=pokemon.name.capitalize())
def _recover_status(self, pokemon) -> str:
# Remove freeze status from Pokemon
if hasattr(pokemon, 'status_effects') and StatusType.FREEZE.value in pokemon.status_effects:
del pokemon.status_effects[StatusType.FREEZE.value]
if hasattr(pokemon, 'major_status') and pokemon.major_status == StatusType.FREEZE.value:
pokemon.major_status = None
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_removed', StatusType.FREEZE.value, 'Freeze')
# Return thaw message
return "{pokemon} thawed out!".format(pokemon=pokemon.name.capitalize())
class SleepStatusEffect(StatusEffect):
def __init__(self, **kwargs):
"""Initialize sleep status effect with random duration."""
# Set random duration if not provided
if 'duration' not in kwargs or kwargs['duration'] == -1:
duration_range = STATUS_EFFECTS_CONFIG[StatusType.SLEEP.value].get('duration_range', (1, 3))
kwargs['duration'] = random.randint(*duration_range)
super().__init__(StatusType.SLEEP.value, **kwargs)
def affects_move_usage(self, pokemon) -> Tuple[bool, str]:
message = "{pokemon} is fast asleep.".format(pokemon=pokemon.name.capitalize())
return True, message
def process_turn_start(self, pokemon) -> List[str]:
messages = []
# Decrease sleep duration
if self.duration > 0:
self.duration -= 1
# Check if Pokemon should wake up
if self.duration <= 0:
messages.append(self._recover_status(pokemon))
return messages
def process_turn_end(self, pokemon) -> List[str]:
return []
def can_apply(self, pokemon) -> bool:
# Check for existing major status
if hasattr(pokemon, 'major_status') and pokemon.major_status:
return False
# Check for existing sleep
if hasattr(pokemon, 'status_effects') and StatusType.SLEEP.value in pokemon.status_effects:
return False
return True
def apply(self, pokemon) -> str:
# Check for specific failure reasons and return appropriate messages
if hasattr(pokemon, 'status_effects') and StatusType.SLEEP.value in pokemon.status_effects:
# Pokemon already has sleep
message_template = self.config.get('messages', {}).get('fail_already_has', "{pokemon} is already asleep!")
return message_template.format(pokemon=pokemon.name.capitalize())
if hasattr(pokemon, 'major_status') and pokemon.major_status:
# Pokemon already has a major status condition
message_template = self.config.get('messages', {}).get('fail_major_status', "{pokemon} already has a major status condition!")
return message_template.format(pokemon=pokemon.name.capitalize())
if not self.can_apply(pokemon):
return ""
# Initialize status tracking if needed
if not hasattr(pokemon, 'status_effects'):
pokemon.status_effects = {}
if not hasattr(pokemon, 'major_status'):
pokemon.major_status = None
# Apply sleep status
pokemon.status_effects[StatusType.SLEEP.value] = self
pokemon.major_status = StatusType.SLEEP.value
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_applied', StatusType.SLEEP.value, 'Sleep')
# Return application message
return "{pokemon} fell asleep!".format(pokemon=pokemon.name.capitalize())
def _recover_status(self, pokemon) -> str:
# Remove sleep status from Pokemon
if hasattr(pokemon, 'status_effects') and StatusType.SLEEP.value in pokemon.status_effects:
del pokemon.status_effects[StatusType.SLEEP.value]
if hasattr(pokemon, 'major_status') and pokemon.major_status == StatusType.SLEEP.value:
pokemon.major_status = None
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_removed', StatusType.SLEEP.value, 'Sleep')
# Return wake up message
return "{pokemon} woke up!".format(pokemon=pokemon.name.capitalize())
class PoisonStatusEffect(StatusEffect):
def __init__(self, **kwargs):
super().__init__(StatusType.POISON.value, **kwargs)
def process_turn_end(self, pokemon) -> List[str]:
messages = []
# Calculate poison damage (1/8 of max HP)
damage = int(pokemon.max_hp * (1/8))
# Prevent poison from reducing HP below 1
if pokemon.current_hp <= damage:
damage = max(0, pokemon.current_hp - 1)
if damage > 0:
pokemon.current_hp = max(1, pokemon.current_hp - damage)
damage_message = self.config.get('messages', {}).get('damage', "{pokemon} is hurt by poison!")
messages.append(damage_message.format(pokemon=pokemon.name.capitalize()))
return messages
def process_turn_start(self, pokemon) -> List[str]:
return []
def affects_move_usage(self, pokemon) -> Tuple[bool, str]:
return False, ""
def modify_stat(self, pokemon, stat_name: str, stat_value: int) -> int:
return stat_value
def can_apply(self, pokemon) -> bool:
# Check for existing major status
if hasattr(pokemon, 'major_status') and pokemon.major_status:
return False
# Check for existing poison
if hasattr(pokemon, 'status_effects') and StatusType.POISON.value in pokemon.status_effects:
return False
return True
def apply(self, pokemon) -> str:
# Check for specific failure reasons and return appropriate messages
if hasattr(pokemon, 'status_effects') and StatusType.POISON.value in pokemon.status_effects:
# Pokemon already has poison
message_template = self.config.get('messages', {}).get('fail_already_has', "{pokemon} is already poisoned!")
return message_template.format(pokemon=pokemon.name.capitalize())
if hasattr(pokemon, 'major_status') and pokemon.major_status:
# Pokemon already has a major status condition
message_template = self.config.get('messages', {}).get('fail_major_status', "{pokemon} already has a major status condition!")
return message_template.format(pokemon=pokemon.name.capitalize())
if not self.can_apply(pokemon):
return ""
# Initialize status tracking if needed
if not hasattr(pokemon, 'status_effects'):
pokemon.status_effects = {}
if not hasattr(pokemon, 'major_status'):
pokemon.major_status = None
# Apply poison status
pokemon.status_effects[StatusType.POISON.value] = self
pokemon.major_status = StatusType.POISON.value
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_applied', StatusType.POISON.value, 'Poison')
# Return application message
return "{pokemon} was poisoned!".format(pokemon=pokemon.name.capitalize())
class ToxicStatusEffect(StatusEffect):
def __init__(self, **kwargs):
"""Initialize toxic status effect."""
super().__init__(StatusType.TOXIC.value, **kwargs)
self.counter = 0 # Track turns for escalating damage
def process_turn_end(self, pokemon) -> List[str]:
messages = []
# Increment counter for escalating damage
self.counter += 1
# Calculate toxic damage (counter/16 of max HP)
damage = int(pokemon.max_hp * (self.counter / 16))
# Prevent toxic from reducing HP below 1
if pokemon.current_hp <= damage:
damage = max(0, pokemon.current_hp - 1)
if damage > 0:
pokemon.current_hp = max(1, pokemon.current_hp - damage)
damage_message = self.config.get('messages', {}).get('damage', "{pokemon} is hurt by poison!")
messages.append(damage_message.format(pokemon=pokemon.name.capitalize()))
return messages
def process_turn_start(self, pokemon) -> List[str]:
return []
def affects_move_usage(self, pokemon) -> Tuple[bool, str]:
return False, ""
def modify_stat(self, pokemon, stat_name: str, stat_value: int) -> int:
return stat_value
def can_apply(self, pokemon) -> bool:
# Check for existing major status
if hasattr(pokemon, 'major_status') and pokemon.major_status:
return False
# Check for existing poison or toxic
if hasattr(pokemon, 'status_effects'):
if StatusType.POISON.value in pokemon.status_effects or StatusType.TOXIC.value in pokemon.status_effects:
return False
return True
def apply(self, pokemon) -> str:
# Check for specific failure reasons and return appropriate messages
if hasattr(pokemon, 'status_effects'):
if StatusType.TOXIC.value in pokemon.status_effects:
# Pokemon already has toxic
message_template = self.config.get('messages', {}).get('fail_already_has', "{pokemon} is already badly poisoned!")
return message_template.format(pokemon=pokemon.name.capitalize())
elif StatusType.POISON.value in pokemon.status_effects:
# Pokemon already has regular poison
return "{pokemon} is already poisoned!".format(pokemon=pokemon.name.capitalize())
if hasattr(pokemon, 'major_status') and pokemon.major_status:
# Pokemon already has a major status condition
message_template = self.config.get('messages', {}).get('fail_major_status', "{pokemon} already has a major status condition!")
return message_template.format(pokemon=pokemon.name.capitalize())
if not self.can_apply(pokemon):
return ""
# Initialize status tracking if needed
if not hasattr(pokemon, 'status_effects'):
pokemon.status_effects = {}
if not hasattr(pokemon, 'major_status'):
pokemon.major_status = None
# Apply toxic status
pokemon.status_effects[StatusType.TOXIC.value] = self
pokemon.major_status = StatusType.TOXIC.value
# Generate status change event
if hasattr(pokemon, '_add_status_change_event'):
pokemon._add_status_change_event('status_applied', StatusType.TOXIC.value, 'Badly Poisoned')
# Return application message
return "{pokemon} was badly poisoned!".format(pokemon=pokemon.name.capitalize())
def create_status_effect(status_type: str, **kwargs) -> Optional[StatusEffect]:
if status_type not in STATUS_EFFECTS_CONFIG:
return None
# Create specific status effect classes
if status_type == StatusType.BURN.value:
return BurnStatusEffect(**kwargs)
elif status_type == StatusType.PARALYSIS.value:
return ParalysisStatusEffect(**kwargs)
elif status_type == StatusType.FREEZE.value:
return FreezeStatusEffect(**kwargs)
elif status_type == StatusType.SLEEP.value:
return SleepStatusEffect(**kwargs)
elif status_type == StatusType.POISON.value:
return PoisonStatusEffect(**kwargs)
elif status_type == StatusType.TOXIC.value:
return ToxicStatusEffect(**kwargs)
# Default to base StatusEffect for other types
return StatusEffect(status_type, **kwargs)