Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve targeting checks for cards that are not supposed to target an…
…ything

Fixes #141
  • Loading branch information
jleclanche committed Aug 26, 2015
1 parent f2f2eec commit 3024b43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions fireplace/targeting.py
Expand Up @@ -4,6 +4,15 @@
from .enums import CardType, PlayReq, Rarity


TARGETING_PREREQUISITES = (
PlayReq.REQ_TARGET_TO_PLAY,
PlayReq.REQ_TARGET_FOR_COMBO,
PlayReq.REQ_TARGET_IF_AVAILABLE,
PlayReq.REQ_TARGET_IF_AVAILABLE_AND_DRAGON_IN_HAND,
PlayReq.REQ_TARGET_IF_AVAILABLE_AND_MINIMUM_FRIENDLY_MINIONS,
)


# Requirements-based targeting
def is_valid_target(self, target, requirements=None):
if target is self:
Expand All @@ -28,6 +37,13 @@ def is_valid_target(self, target, requirements=None):
if requirements is None:
requirements = self.requirements

# Check if the entity can ever target other entities
for req in TARGETING_PREREQUISITES:
if req in requirements:
break
else:
return False

for req, param in requirements.items():
if req == PlayReq.REQ_MINION_TARGET:
if target.type != CardType.MINION:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_main.py
Expand Up @@ -4844,15 +4844,21 @@ def test_force_of_nature():

def test_warlock():
game = prepare_game(WARLOCK, WARLOCK)
game.player1.discard_hand()
assert not game.player1.hero.power.targets
assert game.player1.hero.power.is_usable()
game.player1.hero.power.use()
assert len(game.player1.hand) == 1
assert game.player1.hero.health == 28

sacpact = game.current_player.give("NEW1_003")
assert not sacpact.is_playable()
flameimp = game.current_player.give("EX1_319")
flameimp.play()
assert game.current_player.hero.health == 27
assert game.current_player.hero.health == 25
assert sacpact.is_playable()
sacpact.play(target=flameimp)
assert game.current_player.hero.health == 30
game.end_turn()


def test_resurrect():
Expand Down

0 comments on commit 3024b43

Please sign in to comment.