Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/engine/effects/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,23 @@ def if_in_wrath_extra_block(ctx: EffectContext) -> None:
ctx.gain_block(extra)


@effect_simple("if_calm_draw_3_else_calm")
@effect_simple("if_calm_draw_else_calm")
def if_calm_draw_else_calm(ctx: EffectContext) -> None:
"""If in Calm draw 3, else enter Calm (Inner Peace)."""
"""If in Calm draw 3/4, else enter Calm (Inner Peace)."""
if ctx.stance == "Calm":
amount = 4 if ctx.is_upgraded else 3
ctx.draw_cards(amount)
else:
ctx.change_stance("Calm")


# Alias for backwards compatibility
@effect_simple("if_calm_draw_3_else_calm")
def _if_calm_draw_else_calm_alias(ctx: EffectContext) -> None:
"""Alias for if_calm_draw_else_calm."""
if_calm_draw_else_calm(ctx)


@effect_simple("if_wrath_gain_mantra_else_wrath")
def if_wrath_gain_mantra_else_wrath(ctx: EffectContext) -> None:
"""If in Wrath gain mantra, else enter Wrath (Indignation)."""
Expand Down Expand Up @@ -1152,7 +1159,7 @@ def hand_of_greed_effect(ctx: EffectContext) -> None:
"EmptyMind": ["draw_cards", "exit_stance"],
"Evaluate": ["add_insight_to_draw"],
"Halt": ["if_in_wrath_extra_block_6"],
"InnerPeace": ["if_calm_draw_3_else_calm"],
"InnerPeace": ["if_calm_draw_else_calm"],
"PathToVictory": ["apply_mark", "trigger_all_marks"], # Pressure Points
"Protect": [], # Just block + retain
"ThirdEye": ["scry"],
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/effects/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ def _handle_conditional_last_card(self, ctx: EffectContext, card: Card, result:
"if_enemy_attacking_enter_calm": lambda s, c, cd, r: c.change_stance("Calm") if c.is_enemy_attacking() else None,

# Calm/Wrath conditionals
"if_calm_draw_3_else_calm": lambda s, c, cd, r: c.draw_cards(4 if c.is_upgraded else 3) if c.stance == "Calm" else c.change_stance("Calm"),
"if_calm_draw_else_calm": lambda s, c, cd, r: c.draw_cards(4 if c.is_upgraded else 3) if c.stance == "Calm" else c.change_stance("Calm"),
"if_calm_draw_3_else_calm": lambda s, c, cd, r: c.draw_cards(4 if c.is_upgraded else 3) if c.stance == "Calm" else c.change_stance("Calm"), # Alias
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated lambda logic for alias instead of delegation

Low Severity

The if_calm_draw_3_else_calm alias duplicates the entire lambda logic instead of referencing the canonical if_calm_draw_else_calm handler. In cards.py, the alias correctly delegates to the main function, but here the logic is copy-pasted. Consider using _EFFECT_HANDLERS.get("if_calm_draw_else_calm") or a shared reference.

Fix in Cursor Fix in Web

"if_wrath_gain_mantra_else_wrath": lambda s, c, cd, r: c.gain_mantra(5 if c.is_upgraded else 3) if c.stance == "Wrath" else c.change_stance("Wrath"),

# Damage effects
Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

import pytest
import sys
import os

# Ensure project root is in path
sys.path.insert(0, '/Users/jackswitzer/Desktop/SlayTheSpireRL')
# Ensure project root is in path (use the directory containing this conftest.py)
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, _PROJECT_ROOT)

from packages.engine.state.combat import (
CombatState, EntityState, EnemyCombatState,
Expand Down
32 changes: 29 additions & 3 deletions tests/test_watcher_card_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
"""

import pytest
import sys
sys.path.insert(0, '/Users/jackswitzer/Desktop/SlayTheSpireRL')

from packages.engine.state.combat import CombatState, EntityState, EnemyCombatState
from packages.engine.effects.registry import EffectContext, execute_effect
from packages.engine.effects import cards as card_effects
from packages.engine.effects import cards as card_effects # noqa: F401 - imports to register effects
from packages.engine.content.cards import get_card, CardType


Expand Down Expand Up @@ -205,6 +203,34 @@ def test_inner_peace_not_in_calm_enters_calm(self, ctx_basic):
execute_effect("if_calm_draw_3_else_calm", ctx_basic)
assert ctx_basic.stance == "Calm"

def test_inner_peace_canonical_effect_in_calm(self, ctx_basic):
"""Inner Peace canonical effect (if_calm_draw_else_calm) draws 3 in Calm."""
ctx_basic.state.stance = "Calm"
ctx_basic.is_upgraded = False
initial_hand = len(ctx_basic.hand)
execute_effect("if_calm_draw_else_calm", ctx_basic)
assert len(ctx_basic.hand) == initial_hand + 3

def test_inner_peace_canonical_effect_not_in_calm(self, ctx_basic):
"""Inner Peace canonical effect enters Calm from Neutral."""
ctx_basic.state.stance = "Neutral"
execute_effect("if_calm_draw_else_calm", ctx_basic)
assert ctx_basic.stance == "Calm"

def test_inner_peace_upgraded_draws_4(self, ctx_basic):
"""Inner Peace upgraded draws 4 cards in Calm."""
ctx_basic.state.stance = "Calm"
ctx_basic.is_upgraded = True
initial_hand = len(ctx_basic.hand)
execute_effect("if_calm_draw_else_calm", ctx_basic)
assert len(ctx_basic.hand) == initial_hand + 4

def test_inner_peace_from_wrath_enters_calm(self, ctx_basic):
"""Inner Peace from Wrath stance enters Calm."""
ctx_basic.state.stance = "Wrath"
execute_effect("if_calm_draw_else_calm", ctx_basic)
assert ctx_basic.stance == "Calm"

def test_indignation_in_wrath_gains_mantra(self, ctx_basic):
"""Indignation in Wrath gains 3 mantra."""
ctx_basic.state.stance = "Wrath"
Expand Down