diff --git a/assets/scripts/artifacts/deflector_shield.lua b/assets/scripts/artifacts/deflector_shield.lua index 94ad35c..6403716 100644 --- a/assets/scripts/artifacts/deflector_shield.lua +++ b/assets/scripts/artifacts/deflector_shield.lua @@ -13,6 +13,9 @@ register_artifact("DEFLECTOR_SHIELD", { }, test = function() add_actor_by_enemy("DUMMY") - return assert_chain({ assert_status_effect_count(1), assert_status_effect("BLOCK", 8) }) + return assert_chain({ + function () return assert_status_effect_count(1) end, + function () return assert_status_effect("BLOCK", 8) end + }) end }); diff --git a/assets/scripts/cards/shield_bash.lua b/assets/scripts/cards/shield_bash.lua index 7ff07bd..838c0a6 100644 --- a/assets/scripts/cards/shield_bash.lua +++ b/assets/scripts/cards/shield_bash.lua @@ -19,15 +19,15 @@ register_card("SHIELD_BASH", { end }, test = function() - dummy = add_actor_by_enemy("DUMMY") - cards = get_cards(PLAYER_ID) + local dummy = add_actor_by_enemy("DUMMY") + local cards = get_cards(PLAYER_ID) -- Check if the card is in the player's hand if not cards[1] then return "Card not in hand" end - card = get_card_instance(cards[1]) + local card = get_card_instance(cards[1]) if card.type_id ~= "SHIELD_BASH" then return "Card has wrong type: " .. card.type_id end @@ -35,9 +35,12 @@ register_card("SHIELD_BASH", { cast_card(cards[1], dummy) if get_actor(dummy).hp ~= 96 then - return "Expected 96 health, got " .. get_actor_health(dummy) + return "Expected 96 health, got " .. get_actor(dummy).hp end - return assert_chain({ assert_status_effect_count(1), assert_status_effect("BLOCK", 4) }) + return assert_chain({ + function () assert_status_effect_count(1) end, + function () assert_status_effect("BLOCK", 4) end + }) end }) diff --git a/assets/scripts/status_effects/block.lua b/assets/scripts/status_effects/block.lua index d77ef71..5c7b2f8 100644 --- a/assets/scripts/status_effects/block.lua +++ b/assets/scripts/status_effects/block.lua @@ -18,5 +18,23 @@ register_status_effect("BLOCK", { end return ctx.damage end - } + }, + test = function() + return assert_chain({ + function() return assert_status_effect_count(1) end, + function() return assert_status_effect("BLOCK", 1) end, + function () + local dummy = add_actor_by_enemy("DUMMY") + local damage = deal_damage(dummy, PLAYER_ID, 1) + if damage ~= 0 then + return "Expected 0 damage, got " .. damage + end + + damage = deal_damage(dummy, PLAYER_ID, 2) + if damage ~= 2 then + return "Expected 2 damage, got " .. damage + end + end + }) + end }) diff --git a/cmd/internal/tester/main.go b/cmd/internal/tester/main.go index 41dc5eb..0c832cb 100644 --- a/cmd/internal/tester/main.go +++ b/cmd/internal/tester/main.go @@ -111,8 +111,8 @@ func main() { for _, statusEffect := range resources.StatusEffects { if statusEffect.Test != nil { setupClean(session) - session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1) setupFight(session) + session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1) res, err := statusEffect.Test.Call() if err != nil { diff --git a/cmd/internal/tester/main_test.go b/cmd/internal/tester/main_test.go index 2e5710b..8f4c520 100644 --- a/cmd/internal/tester/main_test.go +++ b/cmd/internal/tester/main_test.go @@ -66,8 +66,8 @@ func TestGame(t *testing.T) { for _, statusEffect := range resources.StatusEffects { if statusEffect.Test != nil { setupClean(session) - session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1) setupFight(session) + session.GiveStatusEffect(statusEffect.ID, game.PlayerActorID, 1) t.Run(fmt.Sprintf("StatusEffect:%s", statusEffect.ID), func(t *testing.T) { res, err := statusEffect.Test.Call()