From 5298c55c3e7723bd4f097896f7357047b9921c90 Mon Sep 17 00:00:00 2001 From: "Rifle D. Luffy" Date: Wed, 4 Aug 2021 20:59:23 +0300 Subject: [PATCH] Added Birchee/Brichard Organism and TurnStartEvent class Also made Winkit/Gleamur's ability use the TurnStartEvent class --- Game.py | 11 +++++++++++ Organism.py | 45 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Game.py b/Game.py index 71ac09e..c71bde0 100644 --- a/Game.py +++ b/Game.py @@ -16,6 +16,7 @@ def __init__(self, player1, player2): self._actions_buffer = [] self._shuffle_water = False self._start() + self.turn_start_events = [] self.turn_end_events = [] def draw(self): @@ -153,6 +154,16 @@ def process_move(self, index, player_inputs): # Shuffling water tiles at start of turn if self._shuffle_water: self._shuffle_water_tiles() + + # Running turn start events + # Birchee's berries come on YOUR turn. Added check for player against game's curr_player + print(self.turn_start_events) + for event in self.turn_start_events: + if self.curr_player == event.curr_player: + event.act() + + # Removing unsubscribed turn start events + self.turn_start_events = [event for event in self.turn_start_events if event.subscribed] return 1 def _shuffle_water_tiles(self): diff --git a/Organism.py b/Organism.py index fa3a807..779cd76 100644 --- a/Organism.py +++ b/Organism.py @@ -170,6 +170,21 @@ def ability(self): self.game.next_player.change_HP(-20) self.game.grid.convert_tiles(self.mana_type_index, 2) +class TurnStartEvent(ABC): + def __init__(self, max_num_turns_active, game): + self.curr_num_turns_active = 0 + self.max_num_turns_active = max_num_turns_active + self.game = game + # Caching the players, cause current and next player switch around + self.curr_player = self.game.curr_player + self.next_player = self.game.next_player + self.subscribed = True + + def act(self): + # Unsubscribing the event + self.curr_num_turns_active += 1 + if self.curr_num_turns_active == self.max_num_turns_active: + self.subscribed = False class TurnEndEvent(ABC): def __init__(self, max_num_turns_active, game): @@ -229,7 +244,7 @@ def __init__(self): def ability(self): self.game.next_player.change_HP(-15) - self.game.turn_end_events.append(Starblitz(2, self.game)) + self.game.turn_start_events.append(Starblitz(1, self.game)) class Winklit(Organism): @@ -238,7 +253,7 @@ def __init__(self): def ability(self): self.game.next_player.change_HP(-10) - self.game.turn_end_events.append(Starblitz(2, self.game)) + self.game.turn_start_events.append(Starblitz(1, self.game)) class Flambagant(Organism): @@ -319,6 +334,30 @@ def __init__(self): def ability(self): self.game.next_player.change_HP(-35) self.game.turn_end_events.append(Punish(2, self.game)) + +class Harvest(TurnStartEvent): + def __init__(self, max_num_turns_active, game, berries): + super().__init__(max_num_turns_active, game) + self.berries = berries + + def act(self): + self.curr_player.change_num_berries(berries) + super().act() + +class Birchard(Organism): + def __init__(self): + super().__init__("Birchard", 'Harvest+: Attacks for 15 HP & adds 2 berries at the start of your next turn.', 5, mana_indexes['grass'], None) + def ability(self): + self.game.next_player.change_HP(-15) + self.game.turn_start_events.append(Harvest(1, self.game, 2)) + +class Birchee(Organism): + def __init__(self): + super()__init__("Birchee", 'Harvest: Attacks for 10 HP & adds 1 berry on your next turn for 2 turns.', 6, mana_indexes['grass'], Birchard) -stage_1_organisms = [Bonzumi(), Pelijet(), Turtleisk(), Slickitty(), Barbenin(), Pyrokun(), Trashark(), Elfini(), Winklit(), Timingo(), Criminook(), Nerverack()] + def ability(self): + self.game.next_player.change_HP(-10) + self.game.turn_start_events.append(Harvest(2, self.game, 1)) + +stage_1_organisms = [Bonzumi(), Pelijet(), Turtleisk(), Slickitty(), Barbenin(), Pyrokun(), Trashark(), Elfini(), Winklit(), Timingo(), Criminook(), Nerverack(), Birchee()]