From eab329e3c4bd1d6e075f9825b15eab2f081c26b1 Mon Sep 17 00:00:00 2001 From: shinoi2 Date: Tue, 2 Apr 2024 11:59:50 +0800 Subject: [PATCH] Rewrite Twinspell --- fireplace/actions.py | 6 ++++++ fireplace/card.py | 11 +++++++++++ fireplace/cards/dalaran/druid.py | 18 ++++++------------ fireplace/cards/dalaran/hunter.py | 18 ++++++------------ fireplace/cards/dalaran/mage.py | 26 ++++++-------------------- fireplace/cards/dalaran/paladin.py | 26 ++++++-------------------- fireplace/managers.py | 2 ++ tests/test_dalaran.py | 10 ++++++++++ 8 files changed, 53 insertions(+), 64 deletions(-) diff --git a/fireplace/actions.py b/fireplace/actions.py index b5345aee6..2a641b7d1 100644 --- a/fireplace/actions.py +++ b/fireplace/actions.py @@ -488,6 +488,9 @@ def do(self, source, card, target, index, choose): # We need to fake a Summon broadcast. summon_action = Summon(player, card) + if card.type == CardType.SPELL and card.twinspell: + source.game.queue_actions(card, [Give(player, card.twinspell_copy)]) + if card.type in (CardType.MINION, CardType.WEAPON): self.queue_broadcast(summon_action, (player, EventListener.ON, player, card)) self.broadcast(player, EventListener.ON, player, card, target) @@ -1800,6 +1803,9 @@ def do(self, source, card, targets): player = source.controller old_choice = player.choice player.choice = None + + if card.twinspell: + source.game.queue_actions(card, [Give(player, card.twinspell_copy)]) if card.must_choose_one: card = random.choice(card.choose_cards) for target in targets: diff --git a/fireplace/card.py b/fireplace/card.py index 83deab598..4071da112 100644 --- a/fireplace/card.py +++ b/fireplace/card.py @@ -1139,12 +1139,23 @@ def can_attack(self, target=None): class Spell(PlayableCard): spelltype = enums.SpellType.INVALID + twinspell = boolean_property("twinspell") def __init__(self, data): self.immune_to_spellpower = False self.receives_double_spelldamage_bonus = False super().__init__(data) + @property + def twinspell_copy(self): + if self._twinspell_copy: + return cards.db.dbf[self._twinspell_copy] + return None + + @twinspell_copy.setter + def twinspell_copy(self, value): + self._twinspell_copy = value + def dump(self): data = super().dump() data["spelltype"] = int(self.spelltype) diff --git a/fireplace/cards/dalaran/druid.py b/fireplace/cards/dalaran/druid.py index 1ef553a5f..a852abff9 100644 --- a/fireplace/cards/dalaran/druid.py +++ b/fireplace/cards/dalaran/druid.py @@ -58,14 +58,11 @@ class DAL_256: requirements = { PlayReq.REQ_NUM_MINION_SLOTS: 1, } - play = Give(CONTROLLER, "DAL_256ts"), Summon(CONTROLLER, "DAL_256t2") * 5 + play = Summon(CONTROLLER, "DAL_256t2") * 5 -class DAL_256ts: - requirements = { - PlayReq.REQ_NUM_MINION_SLOTS: 1, - } - play = Summon(CONTROLLER, "DAL_256t2") * 5 +class DAL_256ts(DAL_256): + pass class DAL_350: @@ -99,14 +96,11 @@ class DAL_351: requirements = { PlayReq.REQ_MINION_TARGET: 0, } - play = Give(CONTROLLER, "DAL_351ts"), Buff(FRIENDLY_MINIONS, "DAL_351e") + play = Buff(FRIENDLY_MINIONS, "DAL_351e") -class DAL_351ts: - requirements = { - PlayReq.REQ_MINION_TARGET: 0, - } - play = Buff(FRIENDLY_MINIONS, "DAL_351e") +class DAL_351ts(DAL_351): + pass DAL_351e = buff(+1, +1) diff --git a/fireplace/cards/dalaran/hunter.py b/fireplace/cards/dalaran/hunter.py index cd78b80aa..184742083 100644 --- a/fireplace/cards/dalaran/hunter.py +++ b/fireplace/cards/dalaran/hunter.py @@ -65,14 +65,11 @@ class DAL_373: requirements = { PlayReq.REQ_TARGET_TO_PLAY: 0, } - play = Give(CONTROLLER, "DAL_373ts"), Hit(TARGET, 1) + play = Hit(TARGET, 1) -class DAL_373ts: - requirements = { - PlayReq.REQ_TARGET_TO_PLAY: 0, - } - play = Hit(TARGET, 1) +class DAL_373ts(DAL_373): + pass class DAL_377: @@ -96,14 +93,11 @@ class DAL_378: requirements = { PlayReq.REQ_NUM_MINION_SLOTS: 1, } - play = Give(CONTROLLER, "DAL_378ts"), Summon(CONTROLLER, "DAL_378t1") + play = Summon(CONTROLLER, "DAL_378t1") -class DAL_378ts: - requirements = { - PlayReq.REQ_NUM_MINION_SLOTS: 1, - } - play = Summon(CONTROLLER, "DAL_378t1") +class DAL_378ts(DAL_378): + pass class DAL_589: diff --git a/fireplace/cards/dalaran/mage.py b/fireplace/cards/dalaran/mage.py index 0b0d33223..20b4afb8a 100644 --- a/fireplace/cards/dalaran/mage.py +++ b/fireplace/cards/dalaran/mage.py @@ -63,18 +63,11 @@ class DAL_177: PlayReq.REQ_TARGET_TO_PLAY: 0, PlayReq.REQ_MINION_TARGET: 0, } - play = ( - Give(CONTROLLER, "DAL_177ts"), - Destroy(TARGET), Summon(CONTROLLER, RandomMinion(cost=COST(TARGET))) * 2 - ) + play = Destroy(TARGET), Summon(CONTROLLER, RandomMinion(cost=COST(TARGET))) * 2 -class DAL_177ts: - requirements = { - PlayReq.REQ_TARGET_TO_PLAY: 0, - PlayReq.REQ_MINION_TARGET: 0, - } - play = Destroy(TARGET), Summon(CONTROLLER, RandomMinion(cost=COST(TARGET))) * 2 +class DAL_177ts(DAL_177): + pass class DAL_577: @@ -85,18 +78,11 @@ class DAL_577: PlayReq.REQ_TARGET_TO_PLAY: 0, PlayReq.REQ_MINION_TARGET: 0, } - play = ( - Give(CONTROLLER, "DAL_577ts"), - Find(TARGET + FROZEN) & Hit(TARGET, 2) | Freeze(TARGET) - ) + play = Find(TARGET + FROZEN) & Hit(TARGET, 2) | Freeze(TARGET) -class DAL_577ts: - requirements = { - PlayReq.REQ_TARGET_TO_PLAY: 0, - PlayReq.REQ_MINION_TARGET: 0, - } - play = Find(TARGET + FROZEN) & Hit(TARGET, 2) | Freeze(TARGET) +class DAL_577ts(DAL_577): + pass class DAL_578: diff --git a/fireplace/cards/dalaran/paladin.py b/fireplace/cards/dalaran/paladin.py index 1e446a2eb..502cb9677 100644 --- a/fireplace/cards/dalaran/paladin.py +++ b/fireplace/cards/dalaran/paladin.py @@ -40,17 +40,11 @@ class DAL_141: requirements = { PlayReq.REQ_SECRET_ZONE_CAP_FOR_NON_SECRET: 0, } - play = ( - Give(CONTROLLER, "DAL_141ts"), - CastSpell(RandomSpell(secret=True, card_class=CardClass.PALADIN)) - ) + play = CastSpell(RandomSpell(secret=True, card_class=CardClass.PALADIN)) -class DAL_141ts: - requirements = { - PlayReq.REQ_SECRET_ZONE_CAP_FOR_NON_SECRET: 0, - } - play = CastSpell(RandomSpell(secret=True, card_class=CardClass.PALADIN)) +class DAL_141ts(DAL_141): + pass class DAL_568: @@ -61,19 +55,11 @@ class DAL_568: PlayReq.REQ_MINION_TARGET: 0, PlayReq.REQ_FRIENDLY_TARGET: 0, } - play = ( - Give(CONTROLLER, "DAL_568ts"), - GiveLifesteal(TARGET) - ) + play = GiveLifesteal(TARGET) -class DAL_568ts: - requirements = { - PlayReq.REQ_TARGET_TO_PLAY: 0, - PlayReq.REQ_MINION_TARGET: 0, - PlayReq.REQ_FRIENDLY_TARGET: 0, - } - play = GiveLifesteal(TARGET) +class DAL_568ts(DAL_568): + pass class DAL_570: diff --git a/fireplace/managers.py b/fireplace/managers.py index dfd56524f..e485678ec 100644 --- a/fireplace/managers.py +++ b/fireplace/managers.py @@ -224,6 +224,8 @@ class PlayerManager(Manager): GameTag.NUM_ATTACKS_THIS_TURN: "num_attacks", GameTag.NUM_TURNS_IN_PLAY: "turns_in_play", GameTag.TAG_ONE_TURN_EFFECT: "one_turn_effect", + GameTag.TWINSPELL: "twinspell", + GameTag.TWINSPELL_COPY: "twinspell_copy", GameTag.OVERLOAD: "overload", GameTag.OVERKILL: "has_overkill", GameTag.PARENT_CARD: "parent_card", diff --git a/tests/test_dalaran.py b/tests/test_dalaran.py index d44820ada..a27d512d9 100644 --- a/tests/test_dalaran.py +++ b/tests/test_dalaran.py @@ -253,3 +253,13 @@ def test_zayle(): game.start() assert len(game.player1.starting_deck) == 30 assert len(game.player2.starting_deck) == 30 + + +def test_twin_spell(): + game = prepare_game() + twin_spell = game.player1.give("DAL_141") + game.player1.give("EX1_095").play() + while len(game.player1.hand) < game.player1.max_hand_size: + game.player1.give(WISP) + twin_spell.play() + assert game.player1.hand[-1].id == "DAL_141ts"