def __init__(self, card, count=1, add_to_deck=False): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) self.add_to_deck = add_to_deck self.count = count
class ReplaceHeroWithMinion(Action): # Used only for Jaraxxus currently def __init__(self, card): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) def act(self, actor, target, other=None): card = self.card.get_card(target, target.player, actor) target.player.game.selected_card = card hero = card.create_hero(target.player) hero.card = card target.player.trigger("minion_played", actor) hero.buffs = copy.deepcopy(actor.buffs) hero.health = actor.health target.replace(hero) if hero.health <= 0: hero.die(None) def __to_json__(self): return {'name': 'replace_hero_with_minion', 'card': self.card} def __from_json__(self, card): self.card = CardQuery.from_json(card) return self
class Transform(Action): def __init__(self, card): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) def act(self, actor, target, other=None): card = self.card.get_card(target, target.player, actor) target.player.game.selected_card = card if target.is_card(): target.replace(card) elif target.is_minion(): minion = card.create_minion(target.player) minion.card = card target.replace(minion) elif target.is_hero(): hero = card.create_hero(target.player) target.replace(hero) def __to_json__(self): return {'name': 'transform', 'card': self.card} def __from_json__(self, card): self.card = CardQuery.from_json(card) return self
class Transform(Action): def __init__(self, card): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) def act(self, actor, target, other=None): card = self.card.get_card(target, target.player, actor) target.player.game.selected_card = card if target.is_card(): target.replace(card) elif target.is_minion(): minion = card.create_minion(target.player) minion.card = card target.replace(minion) elif target.is_hero(): hero = card.create_hero(target.player) target.replace(hero) def __to_json__(self): return { 'name': 'transform', 'card': self.card } def __from_json__(self, card): self.card = CardQuery.from_json(card) return self
class ReplaceHeroWithMinion(Action): # Used only for Jaraxxus currently def __init__(self, card): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) def act(self, actor, target, other=None): card = self.card.get_card(target, target.player, actor) target.player.game.selected_card = card hero = card.create_hero(target.player) hero.card = card target.player.trigger("minion_played", actor) hero.buffs = copy.deepcopy(actor.buffs) hero.health = actor.health target.replace(hero) if hero.health <= 0: hero.die(None) def __to_json__(self): return { 'name': 'replace_hero_with_minion', 'card': self.card } def __from_json__(self, card): self.card = CardQuery.from_json(card) return self
class AddCard(Action): def __init__(self, card, count=1, add_to_deck=False): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) self.add_to_deck = add_to_deck self.count = count def act(self, actor, target, other=None): if self.add_to_deck: for i in range(self.count): card = self.card.get_card(target, target, actor) target.deck.put_back(card) target.game.selected_card = card else: for i in range(self.count): if len(target.hand) < 10: card = self.card.get_card(target, target, actor) target.game.selected_card = card if card: card = copy.copy(card) target.hand.append(card) card.attach(card, target) def __to_json__(self): if self.add_to_deck: return { 'name': 'add_card', 'card': self.card, 'count': self.count, 'add_to_deck': self.add_to_deck, } return { 'name': 'add_card', 'card': self.card, 'count': self.count } def __from_json__(self, card, count=1, add_to_deck=False): self.card = CardQuery.from_json(card) self.count = count self.add_to_deck = add_to_deck return self
class AddCard(Action): def __init__(self, card, count=1, add_to_deck=False): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) self.add_to_deck = add_to_deck self.count = count def act(self, actor, target, other=None): if self.add_to_deck: for i in range(self.count): card = self.card.get_card(target, target, actor) target.deck.put_back(card) target.game.selected_card = card else: for i in range(self.count): if len(target.hand) < 10: card = self.card.get_card(target, target, actor) target.game.selected_card = card if card: card = copy.copy(card) target.hand.append(card) card.attach(card, target) def __to_json__(self): if self.add_to_deck: return { 'name': 'add_card', 'card': self.card, 'count': self.count, 'add_to_deck': self.add_to_deck, } return {'name': 'add_card', 'card': self.card, 'count': self.count} def __from_json__(self, card, count=1, add_to_deck=False): self.card = CardQuery.from_json(card) self.count = count self.add_to_deck = add_to_deck return self
class Summon(Action): def __init__(self, card, count=1): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) self.count = count def act(self, actor, target, other=None): card = self.card.get_card(target, target, actor) target.game.selected_card = card if card is None: return if actor.is_minion() and actor.player is target: # When a minion is summoned around another minion, they alternate between left and right, # starting on the right if actor.removed: c = 0 else: c = 1 for summon in range(self.count): index = actor.index + (c % 2) card.summon(target, target.game, index) if not actor.removed: c += 1 else: for summon in range(self.count): card.summon(target, target.game, len(target.minions)) def __to_json__(self): if self.count > 1: return { 'name': 'summon', 'card': self.card, 'count': self.count } return { 'name': 'summon', 'card': self.card } def __from_json__(self, card, count=1): self.card = CardQuery.from_json(card) self.count = count return self
class Equip(Action): def __init__(self, weapon): if isinstance(weapon, CardQuery): self.weapon = weapon else: self.weapon = SpecificCard(weapon.ref_name) def act(self, actor, target, other=None): card = self.weapon.get_card(target, target, actor) target.game.selected_card = card weapon = card.create_weapon(target) weapon.card = card weapon.equip(target) def __to_json__(self): return {'name': 'equip', 'weapon': self.weapon} def __from_json__(self, weapon): self.weapon = CardQuery.from_json(weapon) return self
def from_json(query): from hearthbreaker.tags.card_source import SpecificCard, CardList, HandSource, \ DeckSource, CollectionSource, ObjectSource, LastCard, Same if isinstance(query, str): return SpecificCard.__from_json__(query) elif isinstance(query, list): return CardList.__from_json__(query) elif query['name'] == 'object': return ObjectSource.__from_json__(**query) elif query['name'] == 'hand': return HandSource.__from_json__(**query) elif query['name'] == 'deck': return DeckSource.__from_json__(**query) elif query['name'] == 'collection': return CollectionSource.__from_json__(**query) elif query['name'] == 'last_card': return LastCard() elif query['name'] == 'same': return Same() else: raise Exception(query['name'])
class Summon(Action): def __init__(self, card, count=1): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name) self.count = count def act(self, actor, target, other=None): card = self.card.get_card(target, target, actor) target.game.selected_card = card if card is None: return if actor.is_minion() and actor.player is target: # When a minion is summoned around another minion, they alternate between left and right, # starting on the right if actor.removed: c = 0 else: c = 1 for summon in range(self.count): index = actor.index + (c % 2) card.summon(target, target.game, index) if not actor.removed: c += 1 else: for summon in range(self.count): card.summon(target, target.game, len(target.minions)) def __to_json__(self): if self.count > 1: return {'name': 'summon', 'card': self.card, 'count': self.count} return {'name': 'summon', 'card': self.card} def __from_json__(self, card, count=1): self.card = CardQuery.from_json(card) self.count = count return self
class Equip(Action): def __init__(self, weapon): if isinstance(weapon, CardQuery): self.weapon = weapon else: self.weapon = SpecificCard(weapon.ref_name) def act(self, actor, target, other=None): card = self.weapon.get_card(target, target, actor) target.game.selected_card = card weapon = card.create_weapon(target) weapon.card = card weapon.equip(target) def __to_json__(self): return { 'name': 'equip', 'weapon': self.weapon } def __from_json__(self, weapon): self.weapon = CardQuery.from_json(weapon) return self
def __init__(self, weapon): if isinstance(weapon, CardQuery): self.weapon = weapon else: self.weapon = SpecificCard(weapon.ref_name)
def __init__(self, card): if isinstance(card, CardQuery): self.card = card else: self.card = SpecificCard(card.ref_name)