Skip to content

Commit e6832a8

Browse files
committed
Implement delayed event triggering for Heal
1 parent 15f3bd2 commit e6832a8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

fireplace/actions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def __init__(self, *args, **kwargs):
304304
self.source = kwargs.pop("source", None)
305305
super().__init__(*args, **kwargs)
306306
self.times = 1
307+
self.event_queue = []
307308

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

381+
for args in self.event_queue:
382+
self.broadcast(*args)
383+
self.event_queue = []
384+
380385
return ret
381386

382387

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

607612

608613
class ManaThisTurn(TargetedAction):

tests/test_interactions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from utils import *
2+
3+
4+
def test_event_queue_heal():
5+
"""
6+
Test the event queue for mass hits.
7+
Events are supposed to be processed in two phases:
8+
1. Event queuing
9+
2. Triggers (in order of play)
10+
This means that playing a Refreshment Vendor on a board with a
11+
Shadowboxer, and two heroes damaged by 1 will result in the enemy
12+
hero being damaged by 28. Shadowboxer will trigger twice, after
13+
both heals have triggered.
14+
"""
15+
game = prepare_game()
16+
game.player1.give(MOONFIRE).play(target=game.player1.hero)
17+
game.player1.give(MOONFIRE).play(target=game.player2.hero)
18+
shadowboxer = game.player1.give("GVG_072")
19+
shadowboxer.play()
20+
vendor = game.player1.give("AT_111")
21+
vendor.play()
22+
assert game.player1.hero.health == 30
23+
assert game.player2.hero.health == 28

0 commit comments

Comments
 (0)