From ccaf515649e4ec3b20711377fb1a41b77182a219 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 12 Jan 2024 21:52:26 +0100 Subject: [PATCH] feat: 3 new items --- assets/scripts/_test.lua | 21 +++++++ assets/scripts/definitions/card.lua | 1 + assets/scripts/definitions/status_effect.lua | 2 +- assets/scripts/equipment/flash_bang.lua | 4 +- assets/scripts/equipment/flash_shield.lua | 62 ++++++++++++++++++++ assets/scripts/equipment/stim_pack.lua | 20 +++++++ assets/scripts/events/act_0/enemies.lua | 11 +++- 7 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 assets/scripts/equipment/flash_shield.lua create mode 100644 assets/scripts/equipment/stim_pack.lua diff --git a/assets/scripts/_test.lua b/assets/scripts/_test.lua index 6b97839..950c23d 100644 --- a/assets/scripts/_test.lua +++ b/assets/scripts/_test.lua @@ -53,6 +53,27 @@ function assert_cast_damage(id, dmg) end end +function assert_cast_heal(id, heal) + local cards = get_cards(PLAYER_ID) + + if not cards[1] then + return "Card not in hand" + end + + local card = get_card_instance(cards[1]) + if card.type_id ~= id then + return "Card has wrong type: " .. card.type_id + end + + deal_damage(PLAYER_ID, PLAYER_ID, 5, true) + local hp_before = get_actor(PLAYER_ID).hp + cast_card(cards[1], PLAYER_ID) + + if get_actor(PLAYER_ID).hp ~= hp_before + heal then + return "Expected " .. tostring(hp_before + heal) .. " health, got " .. get_actor(PLAYER_ID).hp + end +end + ---assert_status_effect_count asserts that the player has a certain number of status effects, returning an error message if not ---@param count number ---@return string|nil diff --git a/assets/scripts/definitions/card.lua b/assets/scripts/definitions/card.lua index 0d43fff..59e9d62 100644 --- a/assets/scripts/definitions/card.lua +++ b/assets/scripts/definitions/card.lua @@ -17,6 +17,7 @@ ---@field point_cost number ---@field max_level number ---@field does_exhaust? boolean +---@field does_consume? boolean ---@field need_target boolean ---@field price number ---@field callbacks callbacks diff --git a/assets/scripts/definitions/status_effect.lua b/assets/scripts/definitions/status_effect.lua index e306973..b69983a 100644 --- a/assets/scripts/definitions/status_effect.lua +++ b/assets/scripts/definitions/status_effect.lua @@ -13,7 +13,7 @@ ---@field id? type_id ---@field name string ---@field description string ----@field state fun(ctx:status_effect_state_ctx):nil +---@field state? fun(ctx:status_effect_state_ctx):nil ---@field look string ---@field foreground string ---@field order? number diff --git a/assets/scripts/equipment/flash_bang.lua b/assets/scripts/equipment/flash_bang.lua index c5ea1b1..8d00050 100644 --- a/assets/scripts/equipment/flash_bang.lua +++ b/assets/scripts/equipment/flash_bang.lua @@ -17,8 +17,8 @@ register_card("FLASH_BANG", { }) register_status_effect("FLASH_BANG", { - name = l("cards.FLASH_BANG.name", "Blinded"), - description = l("cards.FLASH_BANG.description", "Causing " .. highlight("25%") .. " less damage."), + name = l("status_effects.FLASH_BANG.name", "Blinded"), + description = l("status_effects.FLASH_BANG.description", "Causing " .. highlight("25%") .. " less damage."), look = "FL", foreground = COLOR_PURPLE, state = function(ctx) return nil end, diff --git a/assets/scripts/equipment/flash_shield.lua b/assets/scripts/equipment/flash_shield.lua new file mode 100644 index 0000000..713a55e --- /dev/null +++ b/assets/scripts/equipment/flash_shield.lua @@ -0,0 +1,62 @@ +register_card("FLASH_SHIELD", { + name = l("cards.FLASH_SHIELD.name", "Flash Shield"), + description = string.format( + l("cards.FLASH_SHIELD.description","%s\n\nDeploy a temporary shield. %s the next attack."), + highlight("One-Time"), highlight("Negates") + ), + tags = { "DEF" }, + max_level = 0, + color = COLOR_BLUE, + need_target = false, + does_consume = true, + point_cost = 0, + price = 180, + callbacks = { + on_cast = function(ctx) + give_status_effect("FLASH_SHIELD", ctx.caster, 1 + ctx.level) + return nil + end + } +}) + +register_status_effect("FLASH_SHIELD", { + name = l("status_effects.FLASH_SHIELD.name", "Flash Shield"), + description = l("status_effects.FLASH_SHIELD.description", "Negates the next attack."), + look = "Fsh", + foreground = COLOR_BLUE, + can_stack = false, + decay = DECAY_ALL, + rounds = 1, + order = 100, + callbacks = { + on_damage_calc = function(ctx) + if ctx.simulated then + return ctx.damage + end + + if ctx.target == ctx.owner then + add_status_effect_stacks(ctx.guid, -1) + return 0 + end + return ctx.damage + end, + }, + test = function() + return assert_chain({ + function() return assert_status_effect_count(1) end, + function() return assert_status_effect("FLASH_SHIELD", 1) end, + function () + local dummy = add_actor_by_enemy("DUMMY") + local damage = deal_damage(dummy, PLAYER_ID, 100) + 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/assets/scripts/equipment/stim_pack.lua b/assets/scripts/equipment/stim_pack.lua new file mode 100644 index 0000000..7ccec59 --- /dev/null +++ b/assets/scripts/equipment/stim_pack.lua @@ -0,0 +1,20 @@ +register_card("STIM_PACK", { + name = l("cards.STIM_PACK.name", "Stim Pack"), + description = l("cards.STIM_PACK.description", highlight("One-Time") .. "\n\nRestores " .. highlight(5) .. " HP."), + tags = { "HEAL" }, + max_level = 0, + color = COLOR_BLUE, + need_target = false, + does_consume = true, + point_cost = 0, + price = -1, + callbacks = { + on_cast = function(ctx) + heal(ctx.caster, ctx.caster, 5) + return nil + end + }, + test = function () + return assert_cast_heal("STIM_PACK", 5) + end +}) \ No newline at end of file diff --git a/assets/scripts/events/act_0/enemies.lua b/assets/scripts/events/act_0/enemies.lua index 611a731..42c65c7 100644 --- a/assets/scripts/events/act_0/enemies.lua +++ b/assets/scripts/events/act_0/enemies.lua @@ -1,7 +1,10 @@ register_event("RUST_MITE", { name = "Tasty metals...", description = [[ - You come across a strange being. It seems to be eating the metal from the walls. It looks at you and after a few seconds it rushes towards you. It seems to be hostile. + You are walking through the facility hoping to find a way out. After a few turns you hear a strange noise. You look around and come across a strange being. + It seems to be eating the metal from the walls. It looks at you and after a few seconds it rushes towards you. + + **It seems to be hostile!** ]], tags = {"ACT_0"}, choices = { @@ -18,7 +21,11 @@ register_event("RUST_MITE", { register_event("CLEAN_BOT", { name = "Corpse. Clean. Engage.", description = [[ - You come across a strange robot. It seems to be cleaning up the area. It looks at you and says "Corpse. Clean. Engage.". You're not sure what it means, but it doesn't seem to be friendly. + While exploring the facility you hear a strange noise. Suddenly a strange robot appears from one of the corridors. + It seems to be cleaning up the area, but it's not working properly anymore and you can see small sparks coming out of it. + It looks at you and says "Corpse. Clean. Engage.". + + **You're not sure what it means, but it doesn't seem to be friendly!** ]], tags = {"ACT_0"}, choices = {