Skip to content
Permalink
Browse files

Reorder the Player.play() logic so that play triggers are part of Car…

…d.summon()

This paves the way to the correct play ordering:

 1. Play the card
 2. Pay it forward
 3. Broadcast it
 4. Summon it
 5. Battlecry
 6. After* triggers
  • Loading branch information...
jleclanche committed May 4, 2015
1 parent bfc2235 commit 14ea8d106af3238b6c580acf4d8268ee84e76618
Showing with 32 additions and 25 deletions.
  1. +20 −1 fireplace/actions.py
  2. +9 −0 fireplace/card.py
  3. +3 −24 fireplace/player.py
@@ -149,7 +149,26 @@ def get_args(self, source, game):
return (source, ) + self._args

def do(self, source, game):
source._play(self.card, self.target, self.choose)
card = self.card
if card.hasTarget():
assert self.target
card.target = self.target

if self.choose:
# Choose One cards replace the action on the played card
assert self.choose in card.data.chooseCards
chosen = game.card(self.choose)
chosen.controller = source
logging.info("Choose One from %r: %r", card, chosen)
if chosen.hasTarget():
chosen.target = self.target
card.chosen = chosen
card.choose = self.choose

source._play(card)

card.target = None
card.choose = None


class TargetedAction(Action):
@@ -210,19 +210,28 @@ def _setZone(self, zone):
if zone == Zone.HAND:
self.clearBuffs()

def summon(self):
super().summon()
if self.controller.lastCardPlayed is self:
self.action()

def action(self):
kwargs = {}
if self.target:
kwargs["target"] = self.target
elif PlayReq.REQ_TARGET_IF_AVAILABLE in self.requirements:
logging.info("%r has no target, action exits early" % (self))
return

if self.hasCombo and self.controller.combo:
logging.info("Activating %r combo targeting %r" % (self, self.target))
actions = self.data.scripts.combo
elif hasattr(self.data.scripts, "action"):
logging.info("Activating %r action targeting %r" % (self, self.target))
actions = self.data.scripts.action
elif self.choose:
logging.info("Activating %r Choose One: %r", self, self.chosen)
return self.chosen.action()
else:
return

@@ -196,16 +196,13 @@ def summon(self, card):
def play(self, card, target=None, choose=None):
return self.game.queueActions(self, [Play(card, target, choose)])

def _play(self, card, target, choose):
def _play(self, card):
"""
Plays \a card from the player's hand
"""
logging.info("%s plays %r from their hand" % (self, card))
assert card.controller
cost = card.cost
if card.hasTarget():
assert target
card.target = target
if self.tempMana:
# The coin, Innervate etc
cost -= self.tempMana
@@ -214,27 +211,9 @@ def _play(self, card, target, choose):
if card.overload:
logging.info("%s overloads for %i mana", self, card.overload)
self.overloaded += card.overload
self.summon(card)
# Card must already be on the field for action()
if choose:
# Choose One cards replace the action on the played card
assert choose in card.data.chooseCards
chosen = self.game.card(choose)
chosen.controller = self
logging.info("Choose One from %r: %r", card, chosen)
card.action = chosen.action
if chosen.hasTarget():
chosen.target = target
chosen.action()
if chosen.target:
chosen.target = None
else:
card.action()
if not self.combo:
self.combo = True
if card.target:
card.target = None
self.lastCardPlayed = card
self.summon(card)
self.combo = True
self.cardsPlayedThisTurn += 1
if card.type == CardType.MINION:
self.minionsPlayedThisTurn += 1

0 comments on commit 14ea8d1

Please sign in to comment.
You can’t perform that action at this time.