|
4 | 4 |
|
5 | 5 | import logging |
6 | 6 | from dataclasses import dataclass |
| 7 | +from typing import ClassVar |
7 | 8 |
|
8 | 9 | from tuxemon.db import SpatialCondition |
9 | 10 | from tuxemon.event.eventcondition import EventCondition |
@@ -47,35 +48,31 @@ class BattleOutcomeCountCondition(EventCondition): |
47 | 48 | Checks if the 'player' has won at least 2 times against 'npc_maple'. |
48 | 49 | """ |
49 | 50 |
|
50 | | - name = "battle_outcome_count" |
| 51 | + name: ClassVar[str] = "battle_outcome_count" |
| 52 | + fighter: str |
| 53 | + outcome: str |
| 54 | + opponent: str |
| 55 | + required_count: int |
51 | 56 |
|
52 | 57 | def test(self, session: Session, condition: SpatialCondition) -> bool: |
53 | | - try: |
54 | | - fighter, outcome, opponent, count_str = condition.parameters[:4] |
55 | | - required_count = int(count_str) |
56 | | - except (ValueError, IndexError) as e: |
57 | | - logger.error( |
58 | | - f"Invalid parameters for battle_outcome_count: {condition.parameters}" |
59 | | - ) |
60 | | - return False |
61 | 58 |
|
62 | | - if outcome not in {"won", "lost", "draw"}: |
63 | | - logger.error(f"Invalid outcome '{outcome}'") |
| 59 | + if self.outcome not in {"won", "lost", "draw"}: |
| 60 | + logger.error(f"Invalid outcome '{self.outcome}'") |
64 | 61 | return False |
65 | 62 |
|
66 | | - character = session.get_npc(fighter) |
| 63 | + character = session.get_npc(self.fighter) |
67 | 64 | if character is None or not character.battle_handler: |
68 | 65 | logger.error( |
69 | | - f"Character '{fighter}' not found or has no battle handler" |
| 66 | + f"Character '{self.fighter}' not found or has no battle handler" |
70 | 67 | ) |
71 | 68 | return False |
72 | 69 |
|
73 | 70 | actual_count = sum( |
74 | 71 | 1 |
75 | 72 | for battle in character.battle_handler.get_battles() |
76 | | - if battle.fighter == fighter |
77 | | - and battle.opponent == opponent |
78 | | - and battle.outcome.value == outcome |
| 73 | + if battle.fighter == self.fighter |
| 74 | + and battle.opponent == self.opponent |
| 75 | + and battle.outcome.value == self.outcome |
79 | 76 | ) |
80 | 77 |
|
81 | | - return actual_count >= required_count |
| 78 | + return actual_count >= self.required_count |
0 commit comments