Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite death process #507

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions fireplace/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,19 @@ def deathrattles(self):

@property
def dead(self):
return self.zone == Zone.GRAVEYARD or self.to_be_destroyed
return (
self.zone == Zone.GRAVEYARD or
self.to_be_destroyed or
getattr(self, self.health_attribute) <= 0
)

@property
def delayed_destruction(self):
return self.zone == Zone.PLAY

@property
def to_be_destroyed(self):
return getattr(self, self.health_attribute) == 0 or self._to_be_destroyed
return self._to_be_destroyed

@to_be_destroyed.setter
def to_be_destroyed(self, value):
Expand Down Expand Up @@ -698,7 +702,7 @@ def attack(self, target):

@property
def health(self):
return max(0, self.max_health - self.damage)
return self.max_health - self.damage

@property
def targets(self):
Expand Down Expand Up @@ -1082,7 +1086,7 @@ def __init__(self, *args):

@property
def durability(self):
return max(0, self.max_durability - self.damage)
return self.max_durability - self.damage

@property
def max_durability(self):
Expand Down
2 changes: 1 addition & 1 deletion fireplace/cards/classic/neutral_rare.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,4 @@ class NEW1_037:

class NEW1_041:
"""Stampeding Kodo"""
play = Destroy(RANDOM(ENEMY_MINIONS + (ATK <= 2)))
play = Destroy(RANDOM(ENEMY_MINIONS - DEAD + (ATK <= 2)))
2 changes: 1 addition & 1 deletion fireplace/cards/gangs/mage.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ class CFM_620:

class CFM_623:
"""Greater Arcane Missiles"""
play = Hit(RANDOM(ENEMY_CHARACTERS), 3) * 3
play = Hit(RANDOM_ENEMY_CHARACTER, 3) * 3
2 changes: 1 addition & 1 deletion fireplace/cards/tgt/warlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ class AT_024:
class AT_025:
"""Dark Bargain"""
requirements = {PlayReq.REQ_MINIMUM_ENEMY_MINIONS: 1}
play = Destroy(RANDOM(ENEMY_MINIONS) * 2), Discard(RANDOM(FRIENDLY_HAND) * 2)
play = Destroy(RANDOM_ENEMY_MINION * 2), Discard(RANDOM(FRIENDLY_HAND) * 2)
2 changes: 1 addition & 1 deletion fireplace/cards/ungoro/hunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UNG_915:
class UNG_919:
"""Swamp King Dred"""
events = Play(OPPONENT, MINION).after(
Find(Play.CARD + IN_PLAY - MORTALLY_WOUNDED) & (
Find(Play.CARD + IN_PLAY - DEAD) & (
Find(SELF - FROZEN) &
Attack(SELF, Play.CARD)
)
Expand Down
2 changes: 1 addition & 1 deletion fireplace/cards/wog/mage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OG_083:

class OG_085:
"""Demented Frostcaller"""
events = OWN_SPELL_PLAY.after(Freeze(RANDOM(ENEMY_CHARACTERS - MORTALLY_WOUNDED - FROZEN)))
events = OWN_SPELL_PLAY.after(Freeze(RANDOM(ENEMY_CHARACTERS - DEAD - FROZEN)))


class OG_120:
Expand Down
10 changes: 7 additions & 3 deletions fireplace/dsl/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ def __mul__(self, other):

RANDOM = RandomSelector

MORTALLY_WOUNDED = CURRENT_HEALTH <= 0
DEAD = FuncSelector(
lambda entities, source: [
e for e in entities
if hasattr(e, "dead") and e.dead
])

# Selects the highest and lowest attack entities, respectively
HIGHEST_ATK = lambda sel: (
Expand Down Expand Up @@ -518,8 +522,8 @@ def CONTROLLED_BY(selector):
RANDOM_FRIENDLY_MINION = RANDOM(FRIENDLY_MINIONS)
RANDOM_OTHER_FRIENDLY_MINION = RANDOM(FRIENDLY_MINIONS - SELF)
RANDOM_FRIENDLY_CHARACTER = RANDOM(FRIENDLY_CHARACTERS)
RANDOM_ENEMY_MINION = RANDOM(ENEMY_MINIONS - MORTALLY_WOUNDED)
RANDOM_ENEMY_CHARACTER = RANDOM(ENEMY_CHARACTERS - MORTALLY_WOUNDED)
RANDOM_ENEMY_MINION = RANDOM(ENEMY_MINIONS - DEAD)
RANDOM_ENEMY_CHARACTER = RANDOM(ENEMY_CHARACTERS - DEAD)

DAMAGED_CHARACTERS = ALL_CHARACTERS + DAMAGED
CTHUN = FRIENDLY + ID("OG_280")
Expand Down
9 changes: 5 additions & 4 deletions fireplace/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,18 @@ def process_deaths(self):
cards = []
destroy_cards = []
for card in self.live_entities:
if card.to_be_destroyed:
if card.dead:
cards.append(card)
if card._to_be_destroyed:
if card.to_be_destroyed:
card.zone = Zone.GRAVEYARD
destroy_cards.append(card)

if cards:
self.action_start(type, self, 0, None)
for card in cards:
if card.to_be_destroyed or card in destroy_cards:
card.zone = Zone.GRAVEYARD
if card.dead:
if card not in destroy_cards:
card.zone = Zone.GRAVEYARD
self.check_for_end_game()
self.refresh_auras()
self.trigger(self, [Death(card)], event_args=None)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_naxxramas.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ def test_avenge_board_clear():
assert game.player1.field[0].atk == 4
assert game.player1.field[0].health == 2

game = prepare_game()
avenge = game.player1.give("FP1_020")
wisp1 = game.player1.give(WISP)
wisp2 = game.player1.give(WISP)
avenge.play()
wisp1.play()
wisp2.play()
game.end_turn()

nether = game.player2.give("EX1_312")
nether.play()
assert avenge in game.player1.secrets
assert len(game.player1.field) == 0


def test_baron_rivendare():
game = prepare_game()
Expand Down