Skip to content

Commit

Permalink
Fix bugs (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinoi2 authored Dec 13, 2023
1 parent 5be70ee commit e52b863
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
3 changes: 0 additions & 3 deletions fireplace/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,6 @@ class Silence(TargetedAction):
def do(self, source, target):
log.info("Silencing %r", self)
self.broadcast(source, EventListener.ON, target)
old_health = target.health
target.clear_buffs()
for attr in target.silenceable_attributes:
if getattr(target, attr):
Expand All @@ -1286,8 +1285,6 @@ def do(self, source, target):
# Wipe the event listeners
target._events = []
target.silenced = True
if target.health < old_health:
target.damage = max(target.damage - (old_health - target.health), 0)


class Summon(TargetedAction):
Expand Down
6 changes: 6 additions & 0 deletions fireplace/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,15 @@ def _set_zone(self, zone):
# Can happen if a Destroy is queued after a bounce, for example
self.logger.warning("Trying to remove %r which is already gone", self)
return
if hasattr(self.owner, "health"):
old_health = self.owner.health
self.owner.buffs.remove(self)
if self in self.game.active_aura_buffs:
self.game.active_aura_buffs.remove(self)
if hasattr(self.owner, "health"):
if self.owner.health < old_health:
self.owner.damage = max(self.owner.damage - (old_health - self.owner.health), 0)

super()._set_zone(zone)

def apply(self, target):
Expand Down
5 changes: 4 additions & 1 deletion fireplace/dsl/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ def copy(self, source, entity):
ret.damage = entity.damage
for buff in entity.buffs:
# Recreate the buff stack
entity.buff(ret, buff.id)
new_buff = buff.source.buff(ret, buff.id)
if buff in source.game.active_aura_buffs:
new_buff.tick = buff.tick
source.game.active_aura_buffs.append(new_buff)
return ret
49 changes: 48 additions & 1 deletion tests/test_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,13 @@ def test_angry_chicken():
assert chicken.enrage
assert not chicken.enraged
assert chicken.atk == chicken.health == 2
game.skip_turn()
game.player1.give(MOONFIRE).play(target=chicken)
assert chicken.enraged
assert chicken.atk == 1 + 1 + 5
assert chicken.health == 1
stormwind.destroy()
game.player1.give(FIREBALL).play(target=stormwind)
assert len(game.player1.field) == 1
assert chicken.atk == chicken.health == 1
assert not chicken.enraged

Expand Down Expand Up @@ -3747,3 +3749,48 @@ def test_ysera_awakens():
assert game.player1.hero.health == game.player2.hero.health == 30 - 5
assert len(game.board) == 1
assert ysera.health == 12


def test_mirror_entity_aura():
# https://github.com/jleclanche/fireplace/issues/221
game = prepare_game()
game.end_turn()
game.player2.give("CS2_222").play() # Stormwind Champion
game.end_turn()

mirror = game.player1.give("EX1_294")
mirror.play()
game.end_turn()

# Mirror entity copies the exact nature of the card when it hits the field.
blademaster = game.player2.give("CS2_181")
blademaster.play()
assert len(game.player1.field) == 1
assert len(game.player2.field) == 2
assert game.player1.field[0].health == 4
assert game.player1.field[0].max_health == 7
assert game.player2.field[1].health == 4
assert game.player2.field[1].max_health == 8


def test_stormwind_champion_heal():
# https://github.com/jleclanche/fireplace/issues/226
game = prepare_game()

goldshire = game.player1.summon(GOLDSHIRE_FOOTMAN)
assert goldshire.atk == 1
assert goldshire.health == 2
stormwind = game.player1.give("CS2_222")
stormwind.play()
assert goldshire.atk == 2
assert goldshire.health == 3

game.player1.give(MOONFIRE).play(target=goldshire)
assert goldshire.atk == 2
assert goldshire.health == 2
game.end_turn()

# Destroy with Fireball
game.player2.give(FIREBALL).play(target=stormwind)
assert goldshire.atk == 1
assert goldshire.health == 2

0 comments on commit e52b863

Please sign in to comment.