From 88c3f4c5712b5a3ea9426234e42e72a1c5dfc2ab Mon Sep 17 00:00:00 2001 From: bgkillas Date: Tue, 19 Nov 2024 18:25:14 -0500 Subject: [PATCH] fix immortality and make items less easy to break --- quant.ew/files/core/inventory_helper.lua | 44 ++++++++++++------- quant.ew/files/system/item_sync.lua | 6 ++- .../system/potion_mimic/potion_mimic.lua | 4 ++ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/quant.ew/files/core/inventory_helper.lua b/quant.ew/files/core/inventory_helper.lua index 26df80ce..51d56a0a 100644 --- a/quant.ew/files/core/inventory_helper.lua +++ b/quant.ew/files/core/inventory_helper.lua @@ -213,6 +213,10 @@ function inventory_helper.get_item_data(player_data, fresh) if immortal ~= 0 then EntityRemoveComponent(item, immortal) end + local damage_component = EntityGetFirstComponentIncludingDisabled(item, "DamageModelComponent") + if damage_component and damage_component ~= 0 then + ComponentSetValue2(damage_component, "wait_for_kill_flag_on_death", false) + end SetRandomSeed(item + slot_x + item_x, slot_y + item_y) @@ -254,6 +258,16 @@ function inventory_helper.get_item_data(player_data, fresh) local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot") local item_x, item_y = EntityGetTransform(item) + local immortal = EntityGetFirstComponentIncludingDisabled(item, "LuaComponent", "ew_immortal") + if immortal ~= 0 then + EntityRemoveComponent(item, immortal) + end + local damage_component = EntityGetFirstComponentIncludingDisabled(item, "DamageModelComponent") + if damage_component and damage_component ~= 0 then + ComponentSetValue2(damage_component, "wait_for_kill_flag_on_death", false) + end + + SetRandomSeed(item + slot_x + item_x, slot_y + item_y) -- local item_id = entity.GetVariable(item, "arena_entity_id") @@ -261,23 +275,23 @@ function inventory_helper.get_item_data(player_data, fresh) -- GlobalsSetValue(tostring(item) .. "_item", tostring(k)) if(entity_is_wand(item))then table.insert(spellData, - { - data = inventory_helper.serialize_single_item(item), - -- id = item_id or (item + Random(1, 10000000)), - slot_x = slot_x, - slot_y = slot_y, - active = (mActiveItem == item), - is_wand = true - }) + { + data = inventory_helper.serialize_single_item(item), + -- id = item_id or (item + Random(1, 10000000)), + slot_x = slot_x, + slot_y = slot_y, + active = (mActiveItem == item), + is_wand = true + }) else table.insert(spellData, - { - data = inventory_helper.serialize_single_item(item), - -- id = item_id or (item + Random(1, 10000000)), - slot_x = slot_x, - slot_y = slot_y, - active = (mActiveItem == item) - }) + { + data = inventory_helper.serialize_single_item(item), + -- id = item_id or (item + Random(1, 10000000)), + slot_x = slot_x, + slot_y = slot_y, + active = (mActiveItem == item) + }) end end diff --git a/quant.ew/files/system/item_sync.lua b/quant.ew/files/system/item_sync.lua index c9205376..3ee2a796 100644 --- a/quant.ew/files/system/item_sync.lua +++ b/quant.ew/files/system/item_sync.lua @@ -499,7 +499,11 @@ function rpc.item_globalize(item_data) ComponentSetValue2(com, "value_int", GameGetFrameNum()) end end - EntityAddComponent2(item, "LuaComponent", {_tags="ew_immortal", script_damage_about_to_be_received = "mods/quant.ew/files/resource/cbs/immortal.lua"}) + local damage_component = EntityGetFirstComponentIncludingDisabled(item, "DamageModelComponent") + if damage_component and damage_component ~= 0 then + ComponentSetValue2(damage_component, "wait_for_kill_flag_on_death", true) + EntityAddComponent2(item, "LuaComponent", {_tags="ew_immortal", script_damage_about_to_be_received = "mods/quant.ew/files/resource/cbs/immortal.lua"}) + end if not is_my_item(item_data.gid) then local itemcom = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent") if ComponentGetValue2(itemcom, "play_hover_animation") then diff --git a/quant.ew/files/system/potion_mimic/potion_mimic.lua b/quant.ew/files/system/potion_mimic/potion_mimic.lua index 988a8ade..eb48ff40 100644 --- a/quant.ew/files/system/potion_mimic/potion_mimic.lua +++ b/quant.ew/files/system/potion_mimic/potion_mimic.lua @@ -22,6 +22,10 @@ function rpc.got_thrown(peer_id, vx, vy) if immortal == 0 then EntityAddComponent2(item, "LuaComponent", {_tags="ew_immortal", script_damage_about_to_be_received = "mods/quant.ew/files/resource/cbs/immortal.lua"}) end + local damage_component = EntityGetFirstComponentIncludingDisabled(item, "DamageModelComponent") + if damage_component and damage_component ~= 0 then + ComponentSetValue2(damage_component, "wait_for_kill_flag_on_death", true) + end end end