Permalink
Browse files

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 3024b43cd2f615852305ff61e73e214b15ccdb98
Showing with 24 additions and 2 deletions.
  1. +16 −0 fireplace/targeting.py
  2. +8 −2 tests/test_main.py
@@ -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:
@@ -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:
@@ -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():

0 comments on commit 3024b43

Please sign in to comment.