Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement delayed event triggering for Heal
  • Loading branch information
jleclanche committed Sep 29, 2015
1 parent 15f3bd2 commit e6832a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fireplace/actions.py
Expand Up @@ -304,6 +304,7 @@ def __init__(self, *args, **kwargs):
self.source = kwargs.pop("source", None)
super().__init__(*args, **kwargs)
self.times = 1
self.event_queue = []

def __repr__(self):
args = ["%s=%r" % (k, v) for k, v in zip(self._argnames[1:], self._args[1:])]
Expand Down Expand Up @@ -377,6 +378,10 @@ def trigger(self, source):
ret.append(self.do(source, target, *target_args))
source.game.manager.action_end(self, source, targets, *self._args)

for args in self.event_queue:
self.broadcast(*args)
self.event_queue = []

return ret


Expand Down Expand Up @@ -602,7 +607,7 @@ def do(self, source, target, amount):
# Undamaged targets do not receive heals
logger.info("%r heals %r for %i", source, target, amount)
target.damage -= amount
self.broadcast(source, EventListener.ON, target, amount)
self.event_queue.append((source, EventListener.ON, target, amount))


class ManaThisTurn(TargetedAction):
Expand Down
23 changes: 23 additions & 0 deletions tests/test_interactions.py
@@ -0,0 +1,23 @@
from utils import *


def test_event_queue_heal():
"""
Test the event queue for mass hits.
Events are supposed to be processed in two phases:
1. Event queuing
2. Triggers (in order of play)
This means that playing a Refreshment Vendor on a board with a
Shadowboxer, and two heroes damaged by 1 will result in the enemy
hero being damaged by 28. Shadowboxer will trigger twice, after
both heals have triggered.
"""
game = prepare_game()
game.player1.give(MOONFIRE).play(target=game.player1.hero)
game.player1.give(MOONFIRE).play(target=game.player2.hero)
shadowboxer = game.player1.give("GVG_072")
shadowboxer.play()
vendor = game.player1.give("AT_111")
vendor.play()
assert game.player1.hero.health == 30
assert game.player2.hero.health == 28

0 comments on commit e6832a8

Please sign in to comment.