-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonsters_models.py
More file actions
1468 lines (1281 loc) · 51.2 KB
/
Copy pathmonsters_models.py
File metadata and controls
1468 lines (1281 loc) · 51.2 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
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
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Cruel Monsters - Data Models
AQW-themed Pokemon system with full admin customization
"""
from dataclasses import dataclass, field
from typing import List, Dict, Optional, Any, Set
from enum import Enum
from datetime import datetime, timezone
import json
# ==================== ENUMS ====================
class MonsterRarity(str, Enum):
STARTER = "starter"
COMMON = "common"
UNCOMMON = "uncommon"
RARE = "rare"
EPIC = "epic"
LEGENDARY = "legendary"
MYTHIC = "mythic"
class MonsterStatus(str, Enum):
TESTING = "testing"
LIVE = "live"
DISABLED = "disabled"
class ElementType(str, Enum):
FIRE = "Fire"
WATER = "Water"
ICE = "Ice"
NATURE = "Nature"
EARTH = "Earth"
ELECTRIC = "Electric"
METAL = "Metal"
LIGHT = "Light"
DARK = "Dark"
CHAOS = "Chaos"
DRAGON = "Dragon"
NORMAL = "Normal"
class DamageCategory(str, Enum):
PHYSICAL = "physical" # ATK vs DEF
SPECIAL = "special" # MATK vs MDEF
class StatusEffectType(str, Enum):
BURN = "burn" # DOT
POISON = "poison" # DOT (stacking)
FREEZE = "freeze" # Skip turn (thaws after)
PARALYZE = "paralyze" # 50% skip turn
SLEEP = "sleep" # Skip turns until wake
CONFUSION = "confusion" # May hit self
SHIELD = "shield" # Absorb damage
BUFF = "buff" # Stat increase
DEBUFF = "debuff" # Stat decrease
class EffectType(str, Enum):
DAMAGE = "damage"
HEAL = "heal"
SHIELD = "shield"
DOT = "dot"
BUFF = "buff"
DEBUFF = "debuff"
STATUS = "status" # Apply status effect
CLEANSE = "cleanse" # Remove status
DRAIN = "drain" # Damage + heal
RECOIL = "recoil" # Self damage
MARK = "mark" # Apply mark/tag for combos
SPREAD = "spread" # Spread effect to other targets
CHAIN = "chain" # Multi-hit
EXECUTE = "execute" # Bonus damage based on HP threshold
class AbilityRole(str, Enum):
"""What job does this ability do?"""
NUKE = "nuke" # High single-target damage
AOE = "aoe" # Multi-target damage
SETUP = "setup" # Applies status/marks for combos
FINISHER = "finisher" # Execute bonus
SUSTAIN = "sustain" # Healing/shielding
CONTROL = "control" # CC effects
UTILITY = "utility" # Buffs, cleanses, etc.
COMBO = "combo" # Stack consumer
MODE = "mode" # Stance switcher
class TriggerType(str, Enum):
"""When does the payoff activate?"""
NONE = "none"
STATUS_ON_TARGET = "status_on_target"
STATUS_ON_SELF = "status_on_self"
TARGET_HP_BELOW = "target_hp_below"
TARGET_HP_ABOVE = "target_hp_above"
SELF_HP_BELOW = "self_hp_below"
SELF_HP_ABOVE = "self_hp_above"
STACK_COUNT = "stack_count"
ON_CRIT = "on_crit"
ON_KILL = "on_kill"
RANDOM_CHANCE = "random_chance"
TURN_NUMBER = "turn_number"
class CostType(str, Enum):
"""What's the tradeoff?"""
NONE = "none"
RECOIL_PERCENT = "recoil_percent"
RECOIL_FLAT = "recoil_flat"
SELF_DEBUFF = "self_debuff"
CONSUME_BUFF = "consume_buff"
ACCURACY_PENALTY = "accuracy_penalty"
HP_THRESHOLD = "hp_threshold"
class StatTemplate(str, Enum):
"""Predefined stat distributions for quick monster creation"""
BALANCED = "balanced" # Even stats
TANK = "tank" # High HP/DEF
GLASS_CANNON = "glass_cannon" # High ATK, low DEF
SPEEDY = "speedy" # High SPD
MAGE = "mage" # High MATK/MDEF
BRUISER = "bruiser" # High HP/ATK
WALL = "wall" # Very high DEF/MDEF
# ==================== STAT TEMPLATES ====================
STAT_TEMPLATES = {
StatTemplate.BALANCED: {"hp": 50, "atk": 50, "def": 50, "matk": 50, "mdef": 50, "spd": 50},
StatTemplate.TANK: {"hp": 75, "atk": 40, "def": 70, "matk": 35, "mdef": 60, "spd": 30},
StatTemplate.GLASS_CANNON: {"hp": 35, "atk": 80, "def": 30, "matk": 75, "mdef": 35, "spd": 65},
StatTemplate.SPEEDY: {"hp": 45, "atk": 55, "def": 40, "matk": 50, "mdef": 45, "spd": 85},
StatTemplate.MAGE: {"hp": 45, "atk": 30, "def": 40, "matk": 80, "mdef": 70, "spd": 55},
StatTemplate.BRUISER: {"hp": 70, "atk": 70, "def": 50, "matk": 40, "mdef": 45, "spd": 45},
StatTemplate.WALL: {"hp": 60, "atk": 35, "def": 80, "matk": 35, "mdef": 75, "spd": 25},
}
# Rarity stat multipliers (higher rarity = stronger)
RARITY_MULTIPLIERS = {
MonsterRarity.STARTER: 1.0,
MonsterRarity.COMMON: 0.85,
MonsterRarity.UNCOMMON: 1.0,
MonsterRarity.RARE: 1.15,
MonsterRarity.EPIC: 1.3,
MonsterRarity.LEGENDARY: 1.45,
MonsterRarity.MYTHIC: 1.6,
}
# Rarity spawn weights (lower = rarer)
RARITY_SPAWN_WEIGHTS = {
MonsterRarity.COMMON: 50,
MonsterRarity.UNCOMMON: 30,
MonsterRarity.RARE: 12,
MonsterRarity.EPIC: 5,
MonsterRarity.LEGENDARY: 2.5,
MonsterRarity.MYTHIC: 0.5,
}
# ==================== EFFECT MODELS ====================
@dataclass
class Effect:
"""Single effect that an ability can apply"""
type: EffectType
# For damage/heal/drain/recoil
min_value: Optional[int] = None
max_value: Optional[int] = None
category: Optional[DamageCategory] = None # physical or special
# For DOT/shield
value: Optional[int] = None
duration: Optional[int] = None
# For buff/debuff
stat: Optional[str] = None # hp, atk, def, matk, mdef, spd
# For status
status_type: Optional[StatusEffectType] = None
status_chance: Optional[int] = 100 # Percentage chance
# For cleanse
cleanse_target: Optional[str] = None # "self" or "all_negative" or specific status
# For drain
drain_percent: Optional[int] = None # % of damage to heal
# NEW: Scaling
scaling_stat: Optional[str] = None # "atk", "matk", "spd", "missing_hp", "max_hp"
scaling_percent: Optional[int] = None # % of stat to add as bonus
# NEW: Marks/Tags
mark_id: Optional[str] = None # Custom mark identifier
mark_stacks: Optional[int] = 1 # Stacks to add/require
consume_marks: Optional[bool] = False # Consume marks when triggered
# NEW: Multi-target
spread_count: Optional[int] = None # Spread to N other targets
chain_count: Optional[int] = None # Hit N times
# NEW: Execute
execute_threshold: Optional[int] = None # HP % threshold
execute_multiplier: Optional[float] = None # Damage multiplier
# NEW: Targeting
target: Optional[str] = "enemy" # "enemy", "self", "ally", "all_enemies", "random"
# NEW: Bonus modifier (for payoffs)
bonus_percent: Optional[int] = None # +X% to effect
def to_dict(self) -> Dict:
result = {"type": self.type.value}
for attr in ["min_value", "max_value", "value", "duration", "stat",
"status_chance", "cleanse_target", "drain_percent",
"scaling_stat", "scaling_percent", "mark_id", "mark_stacks",
"consume_marks", "spread_count", "chain_count",
"execute_threshold", "execute_multiplier", "target", "bonus_percent"]:
val = getattr(self, attr)
if val is not None:
result[attr] = val
if self.category:
result["category"] = self.category.value
if self.status_type:
result["status_type"] = self.status_type.value
return result
@staticmethod
def from_dict(data: Dict) -> 'Effect':
return Effect(
type=EffectType(data["type"]),
min_value=data.get("min_value"),
max_value=data.get("max_value"),
category=DamageCategory(data["category"]) if data.get("category") else None,
value=data.get("value"),
duration=data.get("duration"),
stat=data.get("stat"),
status_type=StatusEffectType(data["status_type"]) if data.get("status_type") else None,
status_chance=data.get("status_chance", 100),
cleanse_target=data.get("cleanse_target"),
drain_percent=data.get("drain_percent"),
scaling_stat=data.get("scaling_stat"),
scaling_percent=data.get("scaling_percent"),
mark_id=data.get("mark_id"),
mark_stacks=data.get("mark_stacks", 1),
consume_marks=data.get("consume_marks", False),
spread_count=data.get("spread_count"),
chain_count=data.get("chain_count"),
execute_threshold=data.get("execute_threshold"),
execute_multiplier=data.get("execute_multiplier"),
target=data.get("target", "enemy"),
bonus_percent=data.get("bonus_percent"),
)
# ==================== CONDITIONS (for combos) ====================
@dataclass
class Condition:
"""Condition for triggering conditional effects (combos)"""
# Only one should be set per condition
last_ability_id: Optional[str] = None # If last ability used was X
self_hp_below: Optional[int] = None # If own HP below X%
self_hp_above: Optional[int] = None # If own HP above X%
target_hp_below: Optional[int] = None # If target HP below X%
target_has_status: Optional[str] = None # If target has status X
self_has_status: Optional[str] = None # If self has status X
turn_number_gte: Optional[int] = None # If turn >= X
def to_dict(self) -> Dict:
result = {}
for attr in ["last_ability_id", "self_hp_below", "self_hp_above",
"target_hp_below", "target_has_status", "self_has_status",
"turn_number_gte"]:
val = getattr(self, attr)
if val is not None:
result[attr] = val
return result
@staticmethod
def from_dict(data: Dict) -> 'Condition':
return Condition(**data)
@dataclass
class ConditionalEffect:
"""Effect that only applies when condition is met"""
condition: Condition
effects: List[Effect]
description: Optional[str] = None # Display text like "Combo!"
def to_dict(self) -> Dict:
return {
"condition": self.condition.to_dict(),
"effects": [e.to_dict() for e in self.effects],
"description": self.description
}
@staticmethod
def from_dict(data: Dict) -> 'ConditionalEffect':
return ConditionalEffect(
condition=Condition.from_dict(data["condition"]),
effects=[Effect.from_dict(e) for e in data["effects"]],
description=data.get("description")
)
# ==================== NEW TRIGGER SYSTEM ====================
@dataclass
class Trigger:
"""Advanced trigger for ability payoffs"""
type: TriggerType = TriggerType.NONE
# Status-based triggers
required_status: Optional[str] = None # Status type name
status_on: Optional[str] = "target" # "target" or "self"
# HP-based triggers
hp_threshold: Optional[int] = None # % HP
hp_comparison: Optional[str] = "below" # "below" or "above"
hp_target: Optional[str] = "target" # "target" or "self"
# Stack-based triggers
mark_id: Optional[str] = None
required_stacks: Optional[int] = None
consume_stacks: Optional[bool] = False
# Other triggers
crit_trigger: Optional[bool] = False
kill_trigger: Optional[bool] = False
random_chance: Optional[int] = None # % chance
turn_number: Optional[int] = None
def to_dict(self) -> Dict:
result = {"type": self.type.value}
for attr in ["required_status", "status_on", "hp_threshold", "hp_comparison",
"hp_target", "mark_id", "required_stacks", "consume_stacks",
"crit_trigger", "kill_trigger", "random_chance", "turn_number"]:
val = getattr(self, attr)
if val is not None:
result[attr] = val
return result
@staticmethod
def from_dict(data: Dict) -> 'Trigger':
return Trigger(
type=TriggerType(data.get("type", "none")),
required_status=data.get("required_status"),
status_on=data.get("status_on", "target"),
hp_threshold=data.get("hp_threshold"),
hp_comparison=data.get("hp_comparison", "below"),
hp_target=data.get("hp_target", "target"),
mark_id=data.get("mark_id"),
required_stacks=data.get("required_stacks"),
consume_stacks=data.get("consume_stacks", False),
crit_trigger=data.get("crit_trigger", False),
kill_trigger=data.get("kill_trigger", False),
random_chance=data.get("random_chance"),
turn_number=data.get("turn_number"),
)
def get_description(self) -> str:
"""Get human-readable trigger description"""
if self.type == TriggerType.NONE:
return "Always"
elif self.type == TriggerType.STATUS_ON_TARGET:
return f"If target has {self.required_status}"
elif self.type == TriggerType.STATUS_ON_SELF:
return f"If you have {self.required_status}"
elif self.type == TriggerType.TARGET_HP_BELOW:
return f"If target below {self.hp_threshold}% HP"
elif self.type == TriggerType.TARGET_HP_ABOVE:
return f"If target above {self.hp_threshold}% HP"
elif self.type == TriggerType.SELF_HP_BELOW:
return f"If you below {self.hp_threshold}% HP"
elif self.type == TriggerType.SELF_HP_ABOVE:
return f"If you above {self.hp_threshold}% HP"
elif self.type == TriggerType.STACK_COUNT:
return f"At {self.required_stacks}+ {self.mark_id} stacks"
elif self.type == TriggerType.ON_CRIT:
return "On critical hit"
elif self.type == TriggerType.ON_KILL:
return "On kill"
elif self.type == TriggerType.RANDOM_CHANCE:
return f"{self.random_chance}% chance"
return "Unknown trigger"
@dataclass
class Cost:
"""Cost/tradeoff for using an ability"""
type: CostType = CostType.NONE
# Recoil
recoil_percent: Optional[int] = None # % of damage dealt
recoil_flat: Optional[int] = None # Flat HP loss
# Self-debuff
debuff_stat: Optional[str] = None
debuff_value: Optional[int] = None
debuff_duration: Optional[int] = None
# Accuracy
accuracy_penalty: Optional[int] = None # % miss chance
# HP threshold to use
hp_required_below: Optional[int] = None # Must be below X% HP to use
def to_dict(self) -> Dict:
result = {"type": self.type.value}
for attr in ["recoil_percent", "recoil_flat", "debuff_stat", "debuff_value",
"debuff_duration", "accuracy_penalty", "hp_required_below"]:
val = getattr(self, attr)
if val is not None:
result[attr] = val
return result
@staticmethod
def from_dict(data: Dict) -> 'Cost':
return Cost(
type=CostType(data.get("type", "none")),
recoil_percent=data.get("recoil_percent"),
recoil_flat=data.get("recoil_flat"),
debuff_stat=data.get("debuff_stat"),
debuff_value=data.get("debuff_value"),
debuff_duration=data.get("debuff_duration"),
accuracy_penalty=data.get("accuracy_penalty"),
hp_required_below=data.get("hp_required_below"),
)
def get_description(self) -> str:
"""Get human-readable cost description"""
if self.type == CostType.NONE:
return "None"
elif self.type == CostType.RECOIL_PERCENT:
return f"{self.recoil_percent}% recoil"
elif self.type == CostType.RECOIL_FLAT:
return f"-{self.recoil_flat} HP recoil"
elif self.type == CostType.SELF_DEBUFF:
return f"-{self.debuff_value} {self.debuff_stat.upper()} ({self.debuff_duration}t)"
elif self.type == CostType.ACCURACY_PENALTY:
return f"{self.accuracy_penalty}% miss chance"
elif self.type == CostType.HP_THRESHOLD:
return f"Requires <{self.hp_required_below}% HP"
return "Unknown cost"
# ==================== ABILITY DEFINITION ====================
@dataclass
class AbilityDefinition:
"""Reusable ability in the library - Enhanced with DNA system"""
id: str
name: str
description: str
element_type: ElementType
category: DamageCategory
cooldown: int # 0-5 turns
base_effects: List[Effect]
conditional_effects: List[ConditionalEffect] = field(default_factory=list)
# NEW: Ability DNA system
role: AbilityRole = AbilityRole.NUKE
triggers: List[Trigger] = field(default_factory=list)
payoffs: List[Effect] = field(default_factory=list)
costs: List[Cost] = field(default_factory=list)
# NEW: Metadata
power_budget: int = 0 # Calculated power level
tags: List[str] = field(default_factory=list) # For filtering
created_by: Optional[int] = None
created_at: Optional[str] = None
def to_dict(self) -> Dict:
return {
"id": self.id,
"name": self.name,
"description": self.description,
"element_type": self.element_type.value,
"category": self.category.value,
"cooldown": self.cooldown,
"base_effects": [e.to_dict() for e in self.base_effects],
"conditional_effects": [c.to_dict() for c in self.conditional_effects],
"role": self.role.value,
"triggers": [t.to_dict() for t in self.triggers],
"payoffs": [p.to_dict() for p in self.payoffs],
"costs": [c.to_dict() for c in self.costs],
"power_budget": self.power_budget,
"tags": self.tags,
"created_by": self.created_by,
"created_at": self.created_at,
}
@staticmethod
def from_dict(data: Dict) -> 'AbilityDefinition':
return AbilityDefinition(
id=data["id"],
name=data["name"],
description=data["description"],
element_type=ElementType(data["element_type"]),
category=DamageCategory(data["category"]),
cooldown=data["cooldown"],
base_effects=[Effect.from_dict(e) for e in data["base_effects"]],
conditional_effects=[ConditionalEffect.from_dict(c) for c in data.get("conditional_effects", [])],
role=AbilityRole(data.get("role", "nuke")),
triggers=[Trigger.from_dict(t) for t in data.get("triggers", [])],
payoffs=[Effect.from_dict(p) for p in data.get("payoffs", [])],
costs=[Cost.from_dict(c) for c in data.get("costs", [])],
power_budget=data.get("power_budget", 0),
tags=data.get("tags", []),
created_by=data.get("created_by"),
created_at=data.get("created_at"),
)
def get_description_short(self) -> str:
"""Generate short description for battle UI"""
parts = []
for eff in self.base_effects:
if eff.type == EffectType.DAMAGE:
parts.append(f"{eff.min_value}-{eff.max_value} dmg")
elif eff.type == EffectType.HEAL:
parts.append(f"Heal {eff.value}")
elif eff.type == EffectType.SHIELD:
parts.append(f"+{eff.value} 🛡️")
elif eff.type == EffectType.STATUS and eff.status_type:
status_emoji = {
StatusEffectType.BURN: "🔥",
StatusEffectType.POISON: "☠️",
StatusEffectType.FREEZE: "❄️",
StatusEffectType.PARALYZE: "⚡",
StatusEffectType.SLEEP: "💤",
StatusEffectType.CONFUSION: "😵",
}.get(eff.status_type, "")
parts.append(f"+{status_emoji}")
elif eff.type == EffectType.BUFF:
parts.append(f"+{eff.stat.upper()}")
elif eff.type == EffectType.DEBUFF:
parts.append(f"-{eff.stat.upper()}")
return " | ".join(parts) if parts else self.description[:30]
def get_natural_language(self) -> str:
"""Generate natural language description of ability"""
lines = []
# Core effects
for eff in self.base_effects:
lines.append(self._effect_to_text(eff))
# Triggers and payoffs
if self.triggers and self.payoffs:
trigger_text = self.triggers[0].get_description()
payoff_texts = [self._effect_to_text(p) for p in self.payoffs]
lines.append(f"{trigger_text}: {', '.join(payoff_texts)}")
# Costs
for cost in self.costs:
if cost.type != CostType.NONE:
lines.append(f"Cost: {cost.get_description()}")
return " ".join(lines)
def _effect_to_text(self, eff: Effect) -> str:
"""Convert single effect to text"""
if eff.type == EffectType.DAMAGE:
base = f"Deal {eff.min_value}-{eff.max_value} damage"
if eff.bonus_percent:
base = f"+{eff.bonus_percent}% damage"
return base
elif eff.type == EffectType.HEAL:
return f"Heal {eff.value} HP"
elif eff.type == EffectType.SHIELD:
return f"Gain {eff.value} shield"
elif eff.type == EffectType.STATUS:
return f"Apply {eff.status_type.value.title()} ({eff.status_chance}%)"
elif eff.type == EffectType.BUFF:
return f"+{eff.value} {eff.stat.upper()} ({eff.duration}t)"
elif eff.type == EffectType.DEBUFF:
return f"-{eff.value} {eff.stat.upper()} ({eff.duration}t)"
elif eff.type == EffectType.DRAIN:
return f"Drain {eff.drain_percent}% of damage"
elif eff.type == EffectType.MARK:
return f"Apply {eff.mark_stacks}x {eff.mark_id}"
elif eff.type == EffectType.SPREAD:
return f"Spread to {eff.spread_count} enemies"
return str(eff.type.value)
def get_summary_chips(self) -> str:
"""Get compact chip summary for builder"""
chips = []
# Core
for eff in self.base_effects:
chips.append(self._effect_to_chip(eff))
# Trigger
if self.triggers:
t = self.triggers[0]
chips.append(f"⚡ {t.get_description()[:20]}")
# Payoffs
for eff in self.payoffs:
chips.append(f"🎯 {self._effect_to_chip(eff)}")
# Costs
for cost in self.costs:
if cost.type != CostType.NONE:
chips.append(f"💀 {cost.get_description()[:15]}")
return " | ".join(chips[:5]) # Limit for Discord
def _effect_to_chip(self, eff: Effect) -> str:
"""Convert effect to short chip"""
if eff.type == EffectType.DAMAGE:
if eff.bonus_percent:
return f"+{eff.bonus_percent}%"
return f"{eff.min_value}dmg"
elif eff.type == EffectType.HEAL:
return f"+{eff.value}hp"
elif eff.type == EffectType.STATUS:
emoji = {"burn": "🔥", "poison": "☠️", "freeze": "❄️", "paralyze": "⚡"}.get(eff.status_type.value, "💫")
return emoji
elif eff.type == EffectType.BUFF:
return f"+{eff.stat[:3].upper()}"
elif eff.type == EffectType.DEBUFF:
return f"-{eff.stat[:3].upper()}"
elif eff.type == EffectType.MARK:
return f"🏷️{eff.mark_stacks}"
elif eff.type == EffectType.SPREAD:
return f"×{eff.spread_count}"
return eff.type.value[:4]
def calculate_power_budget(self) -> int:
"""Calculate power budget for validation"""
budget = 0
# Core effects
for eff in self.base_effects:
budget += self._effect_power(eff)
# Payoffs (discounted since conditional)
for eff in self.payoffs:
budget += int(self._effect_power(eff) * 0.6)
# Costs reduce budget
for cost in self.costs:
budget -= self._cost_reduction(cost)
# Cooldown reduces budget
budget -= self.cooldown * 8
return max(0, budget)
def _effect_power(self, eff: Effect) -> int:
"""Calculate power cost of single effect"""
if eff.type == EffectType.DAMAGE:
avg = ((eff.min_value or 0) + (eff.max_value or 0)) // 2
return avg // 5
elif eff.type == EffectType.HEAL:
return (eff.value or 0) // 4
elif eff.type == EffectType.SHIELD:
return (eff.value or 0) // 4
elif eff.type == EffectType.STATUS:
base = 15
if eff.status_type in [StatusEffectType.FREEZE, StatusEffectType.SLEEP]:
base = 25 # CC is stronger
return int(base * (eff.status_chance or 100) / 100)
elif eff.type == EffectType.BUFF:
return (eff.value or 0) * (eff.duration or 1)
elif eff.type == EffectType.DEBUFF:
return (eff.value or 0) * (eff.duration or 1)
elif eff.type == EffectType.DRAIN:
return 20
elif eff.type == EffectType.SPREAD:
return 15 * (eff.spread_count or 1)
return 5
def _cost_reduction(self, cost: Cost) -> int:
"""Calculate budget reduction from cost"""
if cost.type == CostType.RECOIL_PERCENT:
return (cost.recoil_percent or 0) // 2
elif cost.type == CostType.RECOIL_FLAT:
return (cost.recoil_flat or 0) // 3
elif cost.type == CostType.SELF_DEBUFF:
return (cost.debuff_value or 0) * (cost.debuff_duration or 1)
elif cost.type == CostType.ACCURACY_PENALTY:
return (cost.accuracy_penalty or 0) // 2
elif cost.type == CostType.HP_THRESHOLD:
return 15 # Risk of not being able to use
return 0
def validate(self) -> List[str]:
"""Validate ability and return warnings"""
warnings = []
# Check power budget
self.power_budget = self.calculate_power_budget()
if self.power_budget > 100:
warnings.append(f"⚠️ High power ({self.power_budget}/100) - consider higher CD or add cost")
# Check payoffs without triggers
if self.payoffs and not self.triggers:
warnings.append("❌ Payoffs without triggers - bonus will never activate")
# Check triggers without payoffs
if self.triggers and not self.payoffs:
warnings.append("⚠️ Trigger without payoffs - consider adding bonus effects")
# Check execute on low CD
has_execute = any(e.execute_threshold for e in self.base_effects + self.payoffs)
if has_execute and self.cooldown < 3:
warnings.append("⚠️ Execute on low CD may feel unfair - suggest CD 3+")
# Recommend CD
recommended_cd = self._recommended_cd()
if self.cooldown < recommended_cd - 1:
warnings.append(f"💡 Recommended CD: {recommended_cd} (current: {self.cooldown})")
return warnings
def _recommended_cd(self) -> int:
"""Calculate recommended cooldown"""
budget = self.power_budget
if budget <= 30:
return 0
elif budget <= 50:
return 1
elif budget <= 70:
return 2
elif budget <= 90:
return 3
elif budget <= 110:
return 4
return 5
def infer_role(self) -> AbilityRole:
"""Infer the role from ability effects if not explicitly set"""
# Check for specific patterns in base_effects
has_damage = any(e.type == EffectType.DAMAGE for e in self.base_effects)
has_heal = any(e.type == EffectType.HEAL for e in self.base_effects)
has_shield = any(e.type == EffectType.SHIELD for e in self.base_effects)
has_drain = any(e.type == EffectType.DRAIN for e in self.base_effects)
has_status = any(e.type == EffectType.STATUS for e in self.base_effects)
has_buff = any(e.type == EffectType.BUFF for e in self.base_effects)
has_debuff = any(e.type == EffectType.DEBUFF for e in self.base_effects)
has_mark = any(e.type == EffectType.MARK for e in self.base_effects)
# Check for CC statuses
cc_statuses = [StatusEffectType.FREEZE, StatusEffectType.SLEEP, StatusEffectType.PARALYZE]
has_cc = any(
e.type == EffectType.STATUS and e.status_type in cc_statuses
for e in self.base_effects
)
# Has execute trigger?
has_execute = any(t.type == TriggerType.TARGET_HP_BELOW for t in self.triggers) or \
any(e.execute_threshold for e in self.base_effects + self.payoffs)
# Determine role based on patterns
if has_execute:
return AbilityRole.FINISHER
elif has_heal or has_shield or has_drain:
return AbilityRole.SUSTAIN
elif has_cc:
return AbilityRole.CONTROL
elif has_mark or (has_status and not has_cc):
return AbilityRole.SETUP
elif has_buff:
return AbilityRole.UTILITY
elif has_debuff and not has_damage:
return AbilityRole.CONTROL
elif self.triggers and self.payoffs:
return AbilityRole.COMBO
elif has_damage:
# High damage = NUKE, low damage might be setup
total_dmg = sum(
((e.min_value or 0) + (e.max_value or 0)) // 2
for e in self.base_effects if e.type == EffectType.DAMAGE
)
if total_dmg >= 25:
return AbilityRole.NUKE
else:
return AbilityRole.SETUP
return AbilityRole.UTILITY
def get_display_role(self) -> AbilityRole:
"""Get role for display - uses explicit role if set meaningfully, otherwise infers"""
# If role was explicitly set to something other than default NUKE, use it
if self.role != AbilityRole.NUKE:
return self.role
# Otherwise infer from effects
return self.infer_role()
# ==================== ABILITY TEMPLATES ====================
ABILITY_TEMPLATES = {
"basic_attack": {
"name": "Basic Attack",
"role": AbilityRole.NUKE,
"description": "Simple damage ability",
"cooldown": 0,
"base_effects": [{"type": "damage", "min_value": 50, "max_value": 60, "category": "physical"}],
},
"burn_starter": {
"name": "Burn Starter",
"role": AbilityRole.SETUP,
"description": "Deal damage and apply Burn for combos",
"cooldown": 0,
"base_effects": [
{"type": "damage", "min_value": 40, "max_value": 50, "category": "physical"},
{"type": "status", "status_type": "burn", "value": 10, "duration": 3}
],
},
"execute": {
"name": "Execute",
"role": AbilityRole.FINISHER,
"description": "Bonus damage to low HP targets",
"cooldown": 3,
"base_effects": [{"type": "damage", "min_value": 70, "max_value": 80, "category": "physical"}],
"triggers": [{"type": "target_hp_below", "hp_threshold": 30}],
"payoffs": [{"type": "damage", "bonus_percent": 100}],
},
"heal": {
"name": "Healing",
"role": AbilityRole.SUSTAIN,
"description": "Restore HP",
"cooldown": 2,
"base_effects": [{"type": "heal", "value": 60, "target": "self"}],
},
"drain": {
"name": "Life Drain",
"role": AbilityRole.SUSTAIN,
"description": "Deal damage and heal",
"cooldown": 2,
"base_effects": [
{"type": "damage", "min_value": 50, "max_value": 60, "category": "special"},
{"type": "drain", "drain_percent": 50}
],
},
"stack_builder": {
"name": "Stack Builder",
"role": AbilityRole.SETUP,
"description": "Apply stacks for combo payoff",
"cooldown": 0,
"base_effects": [
{"type": "damage", "min_value": 30, "max_value": 40, "category": "physical"},
{"type": "mark", "mark_id": "venom", "mark_stacks": 1}
],
},
"stack_consumer": {
"name": "Stack Consumer",
"role": AbilityRole.COMBO,
"description": "Consume stacks for burst",
"cooldown": 3,
"base_effects": [{"type": "damage", "min_value": 20, "max_value": 30, "category": "physical"}],
"triggers": [{"type": "stack_count", "mark_id": "venom", "required_stacks": 3, "consume_stacks": True}],
"payoffs": [{"type": "damage", "bonus_percent": 200}],
},
"risky_nuke": {
"name": "Risky Nuke",
"role": AbilityRole.NUKE,
"description": "High damage with recoil",
"cooldown": 1,
"base_effects": [{"type": "damage", "min_value": 100, "max_value": 120, "category": "physical"}],
"costs": [{"type": "recoil_percent", "recoil_percent": 25}],
},
"control": {
"name": "Control",
"role": AbilityRole.CONTROL,
"description": "Apply crowd control",
"cooldown": 3,
"base_effects": [
{"type": "damage", "min_value": 30, "max_value": 40, "category": "special"},
{"type": "status", "status_type": "freeze", "status_chance": 80}
],
},
}
# ==================== PASSIVE DEFINITION ====================
@dataclass
class PassiveDefinition:
"""Passive ability (always active)"""
id: str
name: str
description: str
effect_type: str # Custom identifiers for engine to handle
value: Optional[int] = None
stat: Optional[str] = None
def to_dict(self) -> Dict:
result = {
"id": self.id,
"name": self.name,
"description": self.description,
"effect_type": self.effect_type
}
if self.value is not None:
result["value"] = self.value
if self.stat is not None:
result["stat"] = self.stat
return result
@staticmethod
def from_dict(data: Dict) -> 'PassiveDefinition':
return PassiveDefinition(
id=data["id"],
name=data["name"],
description=data["description"],
effect_type=data["effect_type"],
value=data.get("value"),
stat=data.get("stat")
)
# ==================== MONSTER DEFINITION ====================
@dataclass
class MonsterDefinition:
"""Monster species template (admin-created)"""
id: str
name: str
description: str
type1: ElementType
type2: Optional[ElementType]
rarity: MonsterRarity
status: MonsterStatus
# Base stats
base_hp: int
base_atk: int
base_def: int
base_matk: int
base_mdef: int
base_spd: int
# Abilities (4 ability IDs from library)
ability_ids: List[str]
# Passive (1 passive ID from library)
passive_id: Optional[str] = None
# Evolution
evolves_from: Optional[str] = None
evolves_to: Optional[str] = None
evolve_level: Optional[int] = None
# Catch rate modifier (1.0 = normal)
catch_rate: float = 1.0
def to_dict(self) -> Dict:
return {
"id": self.id,
"name": self.name,
"description": self.description,
"type1": self.type1.value,
"type2": self.type2.value if self.type2 else None,
"rarity": self.rarity.value,
"status": self.status.value,
"base_hp": self.base_hp,
"base_atk": self.base_atk,
"base_def": self.base_def,
"base_matk": self.base_matk,
"base_mdef": self.base_mdef,
"base_spd": self.base_spd,
"ability_ids": self.ability_ids,
"passive_id": self.passive_id,
"evolves_from": self.evolves_from,
"evolves_to": self.evolves_to,
"evolve_level": self.evolve_level,
"catch_rate": self.catch_rate
}
@staticmethod
def from_dict(data: Dict) -> 'MonsterDefinition':
return MonsterDefinition(
id=data["id"],
name=data["name"],
description=data["description"],
type1=ElementType(data["type1"]),
type2=ElementType(data["type2"]) if data.get("type2") else None,
rarity=MonsterRarity(data["rarity"]),
status=MonsterStatus(data["status"]),
base_hp=data["base_hp"],
base_atk=data["base_atk"],
base_def=data["base_def"],
base_matk=data["base_matk"],
base_mdef=data["base_mdef"],
base_spd=data["base_spd"],
ability_ids=data["ability_ids"],
passive_id=data.get("passive_id"),
evolves_from=data.get("evolves_from"),
evolves_to=data.get("evolves_to"),
evolve_level=data.get("evolve_level"),
catch_rate=data.get("catch_rate", 1.0)
)
def get_type_string(self) -> str:
if self.type2:
return f"{self.type1.value}/{self.type2.value}"
return self.type1.value
# ==================== MONSTER INSTANCE (Caught) ====================
@dataclass
class MonsterInstance: