Skip to content

Commit

Permalink
Refactor Panache to use memory book since it's implemented in the com…
Browse files Browse the repository at this point in the history
…m mod differently from how we handle powers usually
  • Loading branch information
Typhi committed Jul 17, 2024
1 parent 2efc546 commit 136fc0f
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 16 deletions.
10 changes: 5 additions & 5 deletions rs/calculator/battle_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ def resolve_card_play(self, card: CardInterface, target_index: int):
if after_image_block > 0:
self.add_player_block(after_image_block)

if self.player.powers.get(PowerId.PANACHE):
self.player.powers[PowerId.PANACHE] -= 1
if self.player.powers.get(PowerId.PANACHE) == 0:
if self.get_memory_value(MemoryItem.PANACHE_DAMAGE):
self.add_memory_value(MemoryItem.PANACHE_COUNTER, -1)
if self.get_memory_value(MemoryItem.PANACHE_COUNTER) == 0:
for monster in self.monsters:
if monster.current_hp > 0:
monster.inflict_damage(self.player, 10, 1, vulnerable_modifier=1, is_attack=False)
self.player.powers[PowerId.PANACHE] = 5
monster.inflict_damage(self.player, self.get_memory_value(MemoryItem.PANACHE_DAMAGE), 1, vulnerable_modifier=1, is_attack=False)
self.add_memory_value(MemoryItem.PANACHE_COUNTER, 5)

if self.player.powers.get(PowerId.HEATSINK) and card.type == CardType.POWER:
self.draw_cards(self.player.powers.get(PowerId.HEATSINK))
Expand Down
6 changes: 6 additions & 0 deletions rs/calculator/card_effect_custom_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,9 @@ def lesson_learned_post_hook(state: BattleStateInterface, effect: CardEffectsInt
state.monsters[target_index].powers.get(PowerId.MINION) and not \
life_link_more_alive:
state.add_memory_value(MemoryItem.KILLED_WITH_LESSON_LEARNED, 1)


def panache_post_hook(state: BattleStateInterface, effect: CardEffectsInterface, card: CardInterface,
target_index: int = -1):
power_amount = 10 if not card.upgrade else 14
state.add_memory_value(MemoryItem.PANACHE_DAMAGE, power_amount)
3 changes: 2 additions & 1 deletion rs/calculator/card_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def get_card_effects(card: CardInterface, player: PlayerInterface, draw_pile: Li
if card.id == CardId.MAYHEM:
return [CardEffects(target=TargetType.SELF, applies_powers={PowerId.MAYHEM: 1})]
if card.id == CardId.PANACHE:
return [CardEffects(target=TargetType.SELF, applies_powers={PowerId.PANACHE: 5})]
return [CardEffects(target=TargetType.SELF, applies_powers={PowerId.PANACHE_INTERNAL: 1},
post_hooks=[panache_post_hook])]
if card.id == CardId.SADISTIC_NATURE:
return [CardEffects(target=TargetType.SELF, applies_powers={PowerId.SADISTIC: 5 if not card.upgrade else 7})]

Expand Down
3 changes: 2 additions & 1 deletion rs/calculator/enums/power_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class PowerId(Enum):
NO_DRAW = 'no draw'
NOXIOUS_FUMES = 'noxious fumes'
OMEGA = 'omegapower'
PANACHE = 'panache'
PANACHE = 'panache' # See below
PANACHE_INTERNAL = 'internal_use_panache' # Just for comparator purposes. Panache is handled by memory book.
# We currently have damage provided by triggering the Panache power hardcoded to 10.
# It's the first power we've run into that has multiple values associated with it.
PEN_NIB_POWER_IRRELEVANT = 'pen nib' # Covered by Pen Nib relic counting
Expand Down
2 changes: 2 additions & 0 deletions rs/calculator/interfaces/memory_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class MemoryItem(Enum):
LAST_KNOWN_TURN = auto()
MANTRA_THIS_BATTLE = auto()
NECRONOMICON_READY = auto()
PANACHE_COUNTER = auto()
PANACHE_DAMAGE = auto()
KILLED_WITH_LESSON_LEARNED = auto()
LIGHTNING_THIS_BATTLE = auto()
SAVE_INTERNAL_MANTRA = auto()
Expand Down
2 changes: 1 addition & 1 deletion rs/common/comparators/common_general_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
PowerId.NIRVANA,
PowerId.NOXIOUS_FUMES,
PowerId.OMEGA,
PowerId.PANACHE,
PowerId.PANACHE_INTERNAL,
PowerId.PHANTASMAL,
PowerId.PLATED_ARMOR,
PowerId.REPAIR,
Expand Down
2 changes: 2 additions & 0 deletions rs/machine/the_bots_memory_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def set_new_battle_state(self):

self.memory_general[MemoryItem.LIGHTNING_THIS_BATTLE] = 0
self.memory_general[MemoryItem.MANTRA_THIS_BATTLE] = 0
self.memory_general[MemoryItem.PANACHE_DAMAGE] = 0
self.memory_general[MemoryItem.SAVE_INTERNAL_MANTRA] = 0
self.memory_general[MemoryItem.STANCE] = StanceType.NO_STANCE
self.memory_general[MemoryItem.TYPE_LAST_PLAYED] = 0
Expand All @@ -52,6 +53,7 @@ def set_new_turn_state(self):
self.memory_general[MemoryItem.ORANGE_PELLETS_ATTACK] = 0
self.memory_general[MemoryItem.ORANGE_PELLETS_SKILL] = 0
self.memory_general[MemoryItem.ORANGE_PELLETS_POWER] = 0
self.memory_general[MemoryItem.PANACHE_COUNTER] = 5

def initialize_memory_by_card(self, card_id: CardId):
reset_schedule = {}
Expand Down
12 changes: 11 additions & 1 deletion tests/calculator/test_calculator_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,17 @@ def test_panache(self):
state = self.given_state(CardId.PANACHE)
play = self.when_playing_the_first_card(state)
self.see_player_spent_energy(play, 0)
self.see_player_has_power(play, PowerId.PANACHE, 5)
self.assertEqual(5, play.state.get_memory_value(MemoryItem.PANACHE_COUNTER))
self.assertEqual(10, play.state.get_memory_value(MemoryItem.PANACHE_DAMAGE))
self.see_player_has_power(play, PowerId.PANACHE_INTERNAL, 1)

def test_panache_upgraded(self):
state = self.given_state(CardId.PANACHE, upgrade=1)
state.hand.append(get_card(CardId.PANACHE))
play = self.when_making_the_most_plays(state)
self.see_player_spent_energy(play, 0)
self.assertEqual(4, play.state.get_memory_value(MemoryItem.PANACHE_COUNTER))
self.assertEqual(24, play.state.get_memory_value(MemoryItem.PANACHE_DAMAGE))

def test_sadistic_nature(self):
state = self.given_state(CardId.SADISTIC_NATURE)
Expand Down
22 changes: 15 additions & 7 deletions tests/calculator/test_calculator_powers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from rs.calculator.enums.orb_id import OrbId
from rs.calculator.enums.power_id import PowerId
from rs.calculator.enums.relic_id import RelicId
from rs.calculator.interfaces.memory_items import MemoryItem


class CalculatorPowersTest(CalculatorTestFixture):
Expand Down Expand Up @@ -825,19 +826,26 @@ def test_juggernaut_does_not_damage_when_0_block_gained(self):
self.see_enemy_lost_hp(play, 0)
self.see_random_damage_dealt(play, 0)

def test_panache_decrements(self):
def test_panache_counter_decrements(self):
state = self.given_state(CardId.DEFEND_R)
state.player.powers[PowerId.PANACHE] = 5
state.add_memory_value(MemoryItem.PANACHE_DAMAGE, 10)
play = self.when_playing_the_first_card(state)
self.see_enemy_lost_hp(play, 0)
self.see_player_has_power(play, PowerId.PANACHE, 4)
self.assertEqual(4, play.state.get_memory_value(MemoryItem.PANACHE_COUNTER))

def test_panache_triggers(self):
def test_panache_counter_decrements_only_when_panache_damage_present(self):
state = self.given_state(CardId.DEFEND_R)
state.player.powers[PowerId.PANACHE] = 1
play = self.when_playing_the_first_card(state)
self.see_enemy_lost_hp(play, 10)
self.see_player_has_power(play, PowerId.PANACHE, 5)
self.see_enemy_lost_hp(play, 0)
self.assertEqual(5, play.state.get_memory_value(MemoryItem.PANACHE_COUNTER))

def test_panache_triggers_and_resets_when_counter_0(self):
state = self.given_state(CardId.DEFEND_R)
state.memory_general[MemoryItem.PANACHE_COUNTER] = 1
state.add_memory_value(MemoryItem.PANACHE_DAMAGE, 22)
play = self.when_playing_the_first_card(state)
self.see_enemy_lost_hp(play, 22)
self.assertEqual(5, play.state.get_memory_value(MemoryItem.PANACHE_COUNTER))

def test_sadistic_triggers(self):
state = self.given_state(CardId.BLIND, player_powers={PowerId.SADISTIC: 5})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,21 @@ def test_memory_of_mantra_gained_is_reset_when_leaving_battle(self):
mb.memory_general[MemoryItem.MANTRA_THIS_BATTLE] = 3
new_state = load_resource_state('card_reward/card_reward_take.json', memory_book=mb)
self.assertEqual(0, new_state.memory_general[MemoryItem.MANTRA_THIS_BATTLE])

def test_memory_of_panache_counter_is_cleared_per_turn(self):
mb = TheBotsMemoryBook.new_default(last_known_turn=1)
mb.memory_general[MemoryItem.PANACHE_COUNTER] = 2
new_state = load_resource_state('battles/memory/basic_turn_2.json', memory_book=mb)
self.assertEqual(5, new_state.memory_general[MemoryItem.PANACHE_COUNTER])

def test_memory_of_panache_damage_is_saved_across_turn(self):
mb = TheBotsMemoryBook.new_default(last_known_turn=1)
mb.memory_general[MemoryItem.PANACHE_DAMAGE] = 10
new_state = load_resource_state('battles/memory/basic_turn_2.json', memory_book=mb)
self.assertEqual(10, new_state.memory_general[MemoryItem.PANACHE_DAMAGE])

def test_memory_of_panache_damage_is_reset_when_leaving_battle(self):
mb = TheBotsMemoryBook.new_default(last_known_turn=1)
mb.memory_general[MemoryItem.PANACHE_DAMAGE] = 10
new_state = load_resource_state('card_reward/card_reward_take.json', memory_book=mb)
self.assertEqual(0, new_state.memory_general[MemoryItem.PANACHE_DAMAGE])

0 comments on commit 136fc0f

Please sign in to comment.