Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues #502

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fireplace/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ def do(self, source, card, target, index, choose):
# NOTE: A Play is not a summon! But it sure looks like one.
# We need to fake a Summon broadcast.
summon_action = Summon(player, card)
if card.type == CardType.MINION and card.race == Race.TOTEM:
card.controller.times_totem_summoned_this_game += 1

if card.type in (CardType.MINION, CardType.WEAPON):
self.queue_broadcast(summon_action, (player, EventListener.ON, player, card))
Expand All @@ -452,6 +450,8 @@ def do(self, source, card, target, index, choose):
player.cards_played_this_turn += 1
if card.type == CardType.MINION:
player.minions_played_this_turn += 1
if card.race == Race.TOTEM:
card.controller.times_totem_summoned_this_game += 1
if card.race == Race.ELEMENTAL:
player.elemental_played_this_turn += 1
player.cards_played_this_game.append(card)
Expand Down
4 changes: 2 additions & 2 deletions fireplace/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _set_zone(self, value):
caches[value].append(self)
self._zone = value

if value == Zone.PLAY:
if value == Zone.PLAY or value == Zone.SECRET:
self.play_counter = self.game.play_counter
self.game.play_counter += 1

Expand Down Expand Up @@ -749,6 +749,7 @@ def _getattr(self, attr, i):
return ret

def _set_zone(self, value):
super()._set_zone(value)
if value == Zone.PLAY:
old_hero = self.controller.hero
self.controller.hero = self
Expand All @@ -761,7 +762,6 @@ def _set_zone(self, value):
self.power.zone = Zone.GRAVEYARD
if self.controller.hero is self:
self.controller.playstate = PlayState.LOSING
super()._set_zone(value)

def _hit(self, amount):
amount = super()._hit(amount)
Expand Down
5 changes: 1 addition & 4 deletions fireplace/cards/classic/shaman.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class CS2_049:
PlayReq.REQ_ENTIRE_ENTOURAGE_NOT_IN_PLAY: 0,
PlayReq.REQ_NUM_MINION_SLOTS: 1}
entourage = ["CS2_050", "CS2_051", "CS2_052", "NEW1_009"]

def activate(self):
totems = [t for t in self.entourage if not self.controller.field.contains(t)]
yield Summon(CONTROLLER, random.choice(totems))
activate = Summon(CONTROLLER, RandomEntourage(exclude=FRIENDLY_MINIONS))


class CS2_049_H1:
Expand Down
2 changes: 1 addition & 1 deletion fireplace/cards/debug/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def play(self):

class XXX_016:
"""Snake Ball"""
play = Summon("EX1_554t") * 5
play = Summon(CONTROLLER, "EX1_554t") * 5


class XXX_017:
Expand Down
6 changes: 1 addition & 5 deletions fireplace/cards/icecrown/paladin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ class ICC_829:

class ICC_829p:
entourage = ["ICC_829t2", "ICC_829t3", "ICC_829t4", "ICC_829t5"]

def activate(self):
totems = [t for t in self.entourage if not self.controller.field.contains(t)]
yield Summon(CONTROLLER, random.choice(totems))

activate = Summon(CONTROLLER, RandomEntourage(exclude=FRIENDLY_MINIONS))
update = FindAll(
FRIENDLY_MINIONS + ID("ICC_829t2"),
FRIENDLY_MINIONS + ID("ICC_829t3"),
Expand Down
2 changes: 1 addition & 1 deletion fireplace/cards/kobolds/neutral_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LOOT_152:
class LOOT_153:
"""Violet Wurm"""
# <b>Deathrattle:</b> Summon seven 1/1 Grubs.
deathrattle = Summon("LOOT_153t1") * 7
deathrattle = Summon(CONTROLLER, "LOOT_153t1") * 7


class LOOT_167:
Expand Down
4 changes: 2 additions & 2 deletions fireplace/cards/league/adventure.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class LOEA09_2H:

class LOEA09_3:
"""Getting Hungry"""
activate = Summon("LOEA09_5").then(
activate = Summon(CONTROLLER, "LOEA09_5").then(
Buff(Summon.CARD, "LOEA09_3a") * Attr(
CONTROLLER, GameTag.NUM_TIMES_HERO_POWER_USED_THIS_GAME
)
Expand All @@ -319,7 +319,7 @@ class LOEA09_3:

class LOEA09_3H:
"""Getting Hungry (Heroic)"""
activate = Summon("LOEA09_5").then(
activate = Summon(CONTROLLER, "LOEA09_5").then(
Buff(Summon.CARD, "LOEA09_3aH") * Attr(
CONTROLLER, GameTag.NUM_TIMES_HERO_POWER_USED_THIS_GAME
)
Expand Down
2 changes: 1 addition & 1 deletion fireplace/cards/league/collectible.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class LOE_073:

class LOE_076:
"""Sir Finley Mrrgglton"""
play = GenericChoice(CONTROLLER, RandomBasicHeroPower() * 3)
play = GenericChoice(CONTROLLER, RandomBasicHeroPower(exclude=FRIENDLY_HERO_POWER) * 3)


class LOE_077:
Expand Down
6 changes: 3 additions & 3 deletions fireplace/cards/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@

THE_COIN = "GAME_005"

RandomBasicTotem = lambda *args: RandomID(*BASIC_TOTEMS)
RandomBasicHeroPower = lambda *args: RandomID(*BASIC_HERO_POWERS)
RandomPotion = lambda *args: RandomID(*POTIONS)
RandomBasicTotem = lambda *args, **kw: RandomID(*BASIC_TOTEMS, **kw)
RandomBasicHeroPower = lambda *args, **kw: RandomID(*BASIC_HERO_POWERS, **kw)
RandomPotion = lambda *args, **kw: RandomID(*POTIONS, **kw)

# 50% chance to attack the wrong enemy.
FORGETFUL = Attack(SELF).on(
Expand Down
12 changes: 10 additions & 2 deletions fireplace/dsl/random_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def evaluate(self, source, cards=None) -> str:
if cards:
# Use specific card list if given
self.weights = [1]
if "exclude" in self.filters:
exclude = self.filters["exclude"]
if isinstance(exclude, LazyValue):
exclude = exclude.evaluate(source)
elif isinstance(exclude, Selector):
exclude = exclude.eval(source.game, source)
exclude = [card.id for card in exclude]
cards = [card for card in cards if card not in exclude]
card_sets = [list(cards)]
elif not self.weightedfilters:
# Use global filters if no weighted filter sets given
Expand Down Expand Up @@ -118,8 +126,8 @@ def evaluate(self, source):


class RandomID(RandomCardPicker):
def __init__(self, *args):
super().__init__()
def __init__(self, *args, **kw):
super().__init__(**kw)
self._cards = args

def clone(self, memo):
Expand Down
16 changes: 12 additions & 4 deletions fireplace/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def is_standard(self):

@property
def board(self):
return CardList(chain(self.players[0].field, self.players[1].field))
ret = CardList(chain(self.players[0].field, self.players[1].field))
ret.sort(key=lambda e: e.play_counter)
return ret

@property
def decks(self):
Expand All @@ -70,19 +72,25 @@ def hands(self):

@property
def characters(self):
return CardList(chain(self.players[0].characters, self.players[1].characters))
ret = CardList(chain(self.players[0].characters, self.players[1].characters))
ret.sort(key=lambda e: e.play_counter)
return ret

@property
def graveyard(self):
return CardList(chain(self.players[0].graveyard, self.players[1].graveyard))

@property
def entities(self):
return CardList(chain([self], self.players[0].entities, self.players[1].entities))
ret = CardList(chain([self], self.players[0].entities, self.players[1].entities))
ret.sort(key=lambda e: e.play_counter)
return ret

@property
def live_entities(self):
return CardList(chain(self.players[0].live_entities, self.players[1].live_entities))
ret = CardList(chain(self.players[0].live_entities, self.players[1].live_entities))
ret.sort(key=lambda e: e.play_counter)
return ret

@property
def minions_killed_this_turn(self):
Expand Down
2 changes: 0 additions & 2 deletions fireplace/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ def card(self, id, source=None, parent=None, zone=Zone.SETASIDE):
card = Card(id)
card.controller = self
card.zone = zone
card.play_counter = self.game.play_counter
self.game.play_counter += 1
if source is not None:
card.creator = source
if parent is not None:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3810,3 +3810,14 @@ def test_gruul_ragnaros():
assert len(game.player1.field) == 1
assert gruul.atk == 9
assert (gruul.damage == 8) ^ (game.player1.hero.damage == 8)


def test_sorted_deathrattle():
game = prepare_game()
game.player1.give("LOOT_153").play()
game.player1.give("OG_241").play(index=0)
game.end_turn()
game.player2.give("EX1_312").play()
assert len(game.player1.field) == 7
for minion in game.player1.field:
assert minion.id == "LOOT_153t1"