Skip to content

Commit

Permalink
Mojomaster Zihi bug (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinoi2 authored Jan 9, 2024
1 parent 83a5c63 commit 2c1000f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 88 deletions.
95 changes: 19 additions & 76 deletions fireplace/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,8 @@ class SetMana(TargetedAction):
def do(self, source, target, amount):
old_mana = target.mana
target.max_mana = amount
if old_mana > target.mana:
target.used_mana -= old_mana - target.mana
target.used_mana = max(
0, target.max_mana - target.overload_locked - old_mana + target.temp_mana)


class Give(TargetedAction):
Expand Down Expand Up @@ -1485,9 +1485,16 @@ def do(self, source, target, cost):
if cost <= 0:
return
tiger = target.controller.card("TRL_309t")
tiger.atk = cost
tiger.max_health = cost
tiger.cost = cost
tiger.custom_card = True

def create_custom_card(tiger):
tiger.atk = cost
tiger.max_health = cost
tiger.cost = cost

tiger.create_custom_card = create_custom_card
tiger.create_custom_card(tiger)

if tiger.is_summonable():
source.game.queue_actions(source, [Summon(target, tiger)])

Expand Down Expand Up @@ -1628,14 +1635,13 @@ def do(self, source, card, targets):
if card.must_choose_one:
card = random.choice(card.choose_cards)
for target in targets:
if not target:
if card.requires_target():
if len(card.targets):
if target not in card.targets:
target = random.choice(card.targets)
else:
log.info("%s cast spell %s don't have a legal target", source, card)
return
if card.requires_target() and not target:
if len(card.targets) > 0:
if target not in card.targets:
target = random.choice(card.targets)
else:
log.info("%s cast spell %s don't have a legal target", source, card)
return
card.target = target
card.zone = Zone.PLAY
log.info("%s cast spell %s target %s", source, card, target)
Expand All @@ -1648,43 +1654,6 @@ def do(self, source, card, targets):
source.game.queue_actions(source, [Deaths()])


class CastSpellTargetsEnemiesIfPossible(TargetedAction):
"""
Cast a spell target random targets enemies if possible
"""
CARD = CardArg()

def do(self, source, card):
target = None
player = source.controller
old_choice = player.choice
player.choice = None
if card.must_choose_one:
card = random.choice(card.choose_cards)
if card.requires_target():
targets = card.targets
if len(targets) > 0:
enemy_targets = list(filter(
lambda item: item.controller != source.controller, targets))
if len(enemy_targets) > 0:
target = random.choice(enemy_targets)
else:
target = random.choice(targets)
else:
log.info("%s cast spell %s don't have a legal target", source, card)
return
card.target = target
log.info("%s cast spell %s target %s", source, card, target)
source.game.queue_actions(source, [Battlecry(card, card.target)])
player = source.controller
while player.choice:
choice = random.choice(player.choice.cards)
log.info("Choosing card %r" % (choice))
player.choice.choose(choice)
player.choice = old_choice
source.game.queue_actions(source, [Deaths()])


class Evolve(TargetedAction):
"""
Transform your minions into random minions that cost (\a amount) more
Expand Down Expand Up @@ -1864,32 +1833,6 @@ def choose(self, card):
self.trigger_choice_callback()


class Upgrade(TargetedAction):
"""
Upgrade cards
"""
TARGET = ActionArg
AMOUNT = IntArg()

def do(self, source, target):
log.info("Upgrade %s counter to %s", target, target.upgrade_counter + 1)
target.upgrade_counter += 1
self.broadcast(source, EventListener.AFTER, target, target.upgrade_counter)


class Awaken(TargetedAction):
"""
Awaken a dormant minion
"""
TARGET = ActionArg()

def do(self, source, target):
log.info("%s is awaken", target)
target.turns_in_play = 0
if target.get_actions("awaken"):
source.game.trigger(target, target.get_actions("awaken"), event_args=None)


class GameStart(GameAction):
"""
Setup game
Expand Down
5 changes: 0 additions & 5 deletions fireplace/cards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ def merge(id, card, cardscript=None):
if hasattr(cardscript, "entourage"):
card.entourage = cardscript.entourage

if hasattr(cardscript, "dormant"):
card.dormant = cardscript.dormant
else:
card.dormant = 0

if hasattr(cardscript, "progress_total"):
card.scripts.progress_total = cardscript.progress_total
else:
Expand Down
8 changes: 1 addition & 7 deletions fireplace/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from hearthstone.enums import BlockType, CardType, PlayState, State, Step, Zone

from .actions import (
Attack, Awaken, BeginTurn, Death, EndTurn, EventListener, GameStart, Play
Attack, BeginTurn, Death, EndTurn, EventListener, GameStart, Play
)
from .card import THE_COIN
from .entity import Entity
Expand Down Expand Up @@ -376,12 +376,6 @@ def _begin_turn(self, player):
character.damaged_this_turn = 0
character.healed_this_turn = 0

for minion in player.field:
if minion.dormant:
minion.dormant -= 1
if not minion.dormant:
self.queue_actions(self, [Awaken(minion)])

player.draw()
self.manager.step(self.next_step, Step.MAIN_END)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_kobolds.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ def test_dragons_fury():
assert wisp.dead
assert not mech.dead
assert mech.health == 1


def test_unstable_evolution():
game = prepare_game()
game.player1.give(WISP).play()
game.player1.give("LOOT_504")
evolution = game.player1.hand[-1]
evolution.play(target=game.player1.field[0])
assert game.player1.field[0].cost == 1
1 change: 1 addition & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from full_game import test_full_game
from utils import *


Expand Down
59 changes: 59 additions & 0 deletions tests/test_troll.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,62 @@ def test_zuljin():
assert game.player1.temp_mana == 0
game.player1.give("TRL_065").play()
assert game.player1.temp_mana == 1


def test_sulthraze():
game = prepare_game()
wisps = [game.player1.give(WISP).play() for _ in range(4)]
game.end_turn()
game.player2.give("TRL_325").play()
for wisp in wisps:
assert game.player2.hero.can_attack()
game.player2.hero.attack(wisp)
assert not game.player2.hero.can_attack()


def test_summon_tiger():
game = prepare_game()
game.player1.give("TRL_309").play()
game.player1.give(FIREBALL).play(target=game.player2.hero)
tiger = game.player1.field[1]
assert tiger.cost == 4
assert tiger.atk == 4
assert tiger.health == 4
game.player1.give(SILENCE).play(target=tiger)
assert tiger.cost == 4
assert tiger.atk == 4
assert tiger.health == 4
game.end_turn()

game.player2.give("EX1_564").play(target=tiger)
copy_tiger = game.player2.field[0]
assert copy_tiger.cost == 4
assert copy_tiger.atk == 4
assert copy_tiger.health == 4


def test_mojomaster_zihi():
game = prepare_game()
zihi = game.player1.give("TRL_564").play()
assert game.player1.max_mana == 5
assert game.player2.max_mana == 5
assert game.player1.mana == 10 - zihi.cost
assert game.player2.mana == 5

game2 = prepare_game(game_class=Game)
for _ in range(5):
game2.player1.give(THE_COIN).play()
game2.player1.give("TRL_564").play()
assert game2.player1.max_mana == 5
assert game2.player2.max_mana == 5
assert game2.player1.mana == 0
assert game2.player2.mana == 0

game3 = prepare_game(game_class=Game)
for _ in range(10):
game3.player1.give(THE_COIN).play()
game3.player1.give("TRL_564").play()
assert game3.player1.max_mana == 5
assert game3.player2.max_mana == 5
assert game3.player1.mana == 10 - zihi.cost
assert game3.player2.mana == 0
8 changes: 8 additions & 0 deletions tests/test_wog.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,11 @@ def test_thing_from_below():
assert below.cost == below_cost - 2
below.play()
assert below.cost == below_cost


def test_faceless_shambler():
game = prepare_game()
wisp = game.player1.give(WISP).play()
faceless = game.player1.give("OG_174").play(target=wisp)
assert faceless.atk == wisp.atk
assert faceless.health == wisp.health

0 comments on commit 2c1000f

Please sign in to comment.