Skip to content

Commit

Permalink
feat: infer tourists in the known starting deck list
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Aug 5, 2024
1 parent 601358e commit e42922f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
28 changes: 19 additions & 9 deletions hearthstone/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def register_entity(self, entity: Entity) -> None:
elif not self.setup_done:
self.initial_entities.append(entity)

# Update player.starting_hero for Maestra of the Masquerade
# Infer player class and card from "Maestra of the Masquerade" revealing herself
if (
entity.type == CardType.HERO and
entity.tags.get(GameTag.CREATOR_DBID) == MAESTRA_DISGUISE_DBF_ID
Expand All @@ -132,11 +132,22 @@ def register_entity(self, entity: Entity) -> None:
# one.
player.initial_hero_entity_id = entity.id

# At this point we know that Maestra must be in the starting of the player,
# because otherwise the reveal would not happen. Manually add it to the list
# of starting cards
# At this point we know that Maestra must be in the starting deck of the
# player, because otherwise the reveal would not happen. Manually add it to
# the list of starting cards
player._known_starting_card_ids.add("SW_050")

# Infer Tourists when they reveal themselves
if (
entity.tags.get(GameTag.ZONE) == Zone.REMOVEDFROMGAME and
entity.tags.get(GameTag.TOURIST) == 1
):
creator_id = entity.tags.get(GameTag.CREATOR)
creator = self.find_entity_by_id(creator_id) if creator_id else None
if creator and creator.card_id == "VAC_422e": # Tourist VFX Enchantment
player = entity.controller
player._known_starting_card_ids.add(entity.card_id)

def reset(self) -> None:
for entity in self.entities:
if entity is self:
Expand Down Expand Up @@ -214,15 +225,14 @@ def known_starting_deck_list(self) -> List[str]:
Blade) and well-known transforms (e.g. Spellstones, Unidentified Objects, Worgens)
so that the initial card id is included rather than the final card id.
"""
ret = list(self._known_starting_card_ids)

original_card_ids = [
get_original_card_id(entity.initial_card_id)
for entity in self.initial_deck if entity.initial_card_id
]
ret = ret + [card_id for card_id in original_card_ids if card_id not in ret]

return ret
return original_card_ids + [
card_id for card_id in self._known_starting_card_ids
if card_id not in original_card_ids
]

@property
def entities(self) -> Iterator[Entity]:
Expand Down
40 changes: 40 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,46 @@ def test_known_starting_deck_list_with_souleaters_scythe(self, game, player):

assert player.known_starting_deck_list == [WISP, SOULEATERS_SCYTHE]

def test_known_starting_deck_list_with_tourist(self, game, player):
HAMM = "VAC_340"
TOURIST_VFX_ENCHANTMENT = "VAC_422e"

tourist = Card(4, None)
tourist.tags.update({
GameTag.ZONE: Zone.DECK,
GameTag.CONTROLLER: player.player_id,
})
game.register_entity(tourist)

vfx = Card(5, None)
vfx.tags.update({
GameTag.ZONE: Zone.SETASIDE,
GameTag.CONTROLLER: player.player_id,
})
game.register_entity(vfx)
vfx.reveal(TOURIST_VFX_ENCHANTMENT, {
GameTag.CARDTYPE: CardType.ENCHANTMENT,
GameTag.ATTACHED: player.id,
GameTag.CREATOR: tourist.id,
})

# At some point we play an out-of-class card, and a fake tourist is shown
fake_tourist = Card(6, HAMM)
fake_tourist.tags.update({
GameTag.CONTROLLER: player.player_id,
GameTag.CREATOR: vfx.id,
GameTag.ZONE: Zone.REMOVEDFROMGAME,
GameTag.TOURIST: 1,
GameTag.DRUID_TOURIST: 1,
})
game.register_entity(fake_tourist)

assert player.known_starting_deck_list == [HAMM]

tourist.reveal(HAMM, {})

assert player.known_starting_deck_list == [HAMM]


class TestCard:
def test_card(self):
Expand Down

0 comments on commit e42922f

Please sign in to comment.