Skip to content

Commit 3024b43

Browse files
committed
Improve targeting checks for cards that are not supposed to target anything
Fixes #141
1 parent f2f2eec commit 3024b43

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

fireplace/targeting.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
from .enums import CardType, PlayReq, Rarity
55

66

7+
TARGETING_PREREQUISITES = (
8+
PlayReq.REQ_TARGET_TO_PLAY,
9+
PlayReq.REQ_TARGET_FOR_COMBO,
10+
PlayReq.REQ_TARGET_IF_AVAILABLE,
11+
PlayReq.REQ_TARGET_IF_AVAILABLE_AND_DRAGON_IN_HAND,
12+
PlayReq.REQ_TARGET_IF_AVAILABLE_AND_MINIMUM_FRIENDLY_MINIONS,
13+
)
14+
15+
716
# Requirements-based targeting
817
def is_valid_target(self, target, requirements=None):
918
if target is self:
@@ -28,6 +37,13 @@ def is_valid_target(self, target, requirements=None):
2837
if requirements is None:
2938
requirements = self.requirements
3039

40+
# Check if the entity can ever target other entities
41+
for req in TARGETING_PREREQUISITES:
42+
if req in requirements:
43+
break
44+
else:
45+
return False
46+
3147
for req, param in requirements.items():
3248
if req == PlayReq.REQ_MINION_TARGET:
3349
if target.type != CardType.MINION:

tests/test_main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4844,15 +4844,21 @@ def test_force_of_nature():
48444844

48454845
def test_warlock():
48464846
game = prepare_game(WARLOCK, WARLOCK)
4847+
game.player1.discard_hand()
4848+
assert not game.player1.hero.power.targets
4849+
assert game.player1.hero.power.is_usable()
4850+
game.player1.hero.power.use()
4851+
assert len(game.player1.hand) == 1
4852+
assert game.player1.hero.health == 28
4853+
48474854
sacpact = game.current_player.give("NEW1_003")
48484855
assert not sacpact.is_playable()
48494856
flameimp = game.current_player.give("EX1_319")
48504857
flameimp.play()
4851-
assert game.current_player.hero.health == 27
4858+
assert game.current_player.hero.health == 25
48524859
assert sacpact.is_playable()
48534860
sacpact.play(target=flameimp)
48544861
assert game.current_player.hero.health == 30
4855-
game.end_turn()
48564862

48574863

48584864
def test_resurrect():

0 commit comments

Comments
 (0)