From 6fea0d22c2ca2ba68360e161bdcfa88c6b356690 Mon Sep 17 00:00:00 2001 From: IQuant Date: Sun, 30 Jun 2024 18:09:09 +0300 Subject: [PATCH] Make vampirism and extra health perks affect max health. --- docs/perks_that_dont_work_properly.md | 8 +++++++ quant.ew/files/src/net.lua | 9 ++++++++ quant.ew/files/src/perk_fns.lua | 9 +++++++- .../system/perk_patches/append/perk_list.lua | 22 +++++++++++++++++++ .../files/src/system/perk_patches/init.lua | 21 ++++++++++++++++++ quant.ew/init.lua | 1 + 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 docs/perks_that_dont_work_properly.md diff --git a/docs/perks_that_dont_work_properly.md b/docs/perks_that_dont_work_properly.md new file mode 100644 index 00000000..39140006 --- /dev/null +++ b/docs/perks_that_dont_work_properly.md @@ -0,0 +1,8 @@ + - ABILITY_ACTIONS_MATERIALIZED + - RESPAWN + - TELEKINESIS + - SAVING_GRACE + - INVISIBILITY (because stains aren't synced) + - CORDYCEPS + - HOMUNCULUS + \ No newline at end of file diff --git a/quant.ew/files/src/net.lua b/quant.ew/files/src/net.lua index fb21d487..992d6511 100644 --- a/quant.ew/files/src/net.lua +++ b/quant.ew/files/src/net.lua @@ -34,13 +34,22 @@ function rpc_base.opts_reliable() rpc_inner.opts.reliable = true end +-- Also call rpc on client who initiated it. +function rpc_base.opts_everywhere() + rpc_inner.opts.everywhere = true +end + local rpc_meta = { __newindex = function (t, k, v) table.insert(rpc_inner.rpcs, v) local index = #rpc_inner.rpcs local reliable = rpc_inner.opts.reliable == true + local everywhere = rpc_inner.opts.everywhere == true rawset(t, k, function(...) net.send(index, {...}, reliable) + if everywhere then + v(...) + end end) net_handling.mod[index] = function(peer_id, args) ctx.rpc_peer_id = peer_id diff --git a/quant.ew/files/src/perk_fns.lua b/quant.ew/files/src/perk_fns.lua index d6c4c332..9e5a1336 100644 --- a/quant.ew/files/src/perk_fns.lua +++ b/quant.ew/files/src/perk_fns.lua @@ -3,9 +3,16 @@ local util = dofile_once("mods/quant.ew/files/src/util.lua") local perk_fns = {} +-- Which perks we do not add to clients. local perks_to_ignore = { - GAMBLE = true, + GAMBLE = true, -- Tends to get readded, causing players to get a lot of random perks. + -- Doesn't make sense to duplicate those to clients. PERKS_LOTTERY = true, + REMOVE_FOG_OF_WAR = true, + MEGA_BEAM_STONE = true, + -- TODO: Needs extra work to work correctly + -- NO_MORE_SHUFFLE = true, + -- UNLIMITED_SPELLS = true, } function perk_fns.get_my_perks() diff --git a/quant.ew/files/src/system/perk_patches/append/perk_list.lua b/quant.ew/files/src/system/perk_patches/append/perk_list.lua index e69de29b..b261cc7a 100644 --- a/quant.ew/files/src/system/perk_patches/append/perk_list.lua +++ b/quant.ew/files/src/system/perk_patches/append/perk_list.lua @@ -0,0 +1,22 @@ +local function patch_perk(perk_id, fn, ignore_original_func) + local perk_data = get_perk_with_id(perk_list, perk_id) + local old_func = perk_data.func + perk_data.func = function(entity_perk_item, entity_who_picked, item_name, pickup_count) + if not ignore_original_func then + old_func(entity_perk_item, entity_who_picked, item_name, pickup_count) + end + fn(entity_perk_item, entity_who_picked, item_name, pickup_count) + end +end + +patch_perk("EXTRA_HP", function(entity_perk_item, entity_who_picked) + if EntityHasTag(entity_who_picked, "player_unit") then + CrossCall("ew_perks_modify_max_hp", 1.5, true) + end +end) + +patch_perk("VAMPIRISM", function(entity_perk_item, entity_who_picked) + if EntityHasTag(entity_who_picked, "player_unit") then + CrossCall("ew_perks_modify_max_hp", 0.75) + end +end, true) \ No newline at end of file diff --git a/quant.ew/files/src/system/perk_patches/init.lua b/quant.ew/files/src/system/perk_patches/init.lua index 65722eb9..fe6681ae 100644 --- a/quant.ew/files/src/system/perk_patches/init.lua +++ b/quant.ew/files/src/system/perk_patches/init.lua @@ -4,9 +4,30 @@ local net = dofile_once("mods/quant.ew/files/src/net.lua") local player_fns = dofile_once("mods/quant.ew/files/src/player_fns.lua") local np = require("noitapatcher") +local rpc = net.new_rpc_namespace() + local module = {} ModLuaFileAppend("data/scripts/perks/perk_list.lua", "mods/quant.ew/files/src/system/perk_patches/append/perk_list.lua") +rpc.opts_reliable() +rpc.opts_everywhere() +function rpc.modify_max_hp(percent_amount, do_heal) + if ctx.is_host then + local player_count = tonumber(GlobalsGetValue("ew_player_count", "1")) + local health = ctx.cap.health + local max_hp = health.max_health() + health.set_max_health(max_hp + max_hp / player_count * (percent_amount-1)) + if do_heal then + local hp = health.health() + health.set_health(hp + max_hp / player_count * (percent_amount-1)) + end + if health.health() > health.max_health() then + health.set_health(health.max_health()) + end + end +end + +np.CrossCallAdd("ew_perks_modify_max_hp", rpc.modify_max_hp) return module diff --git a/quant.ew/init.lua b/quant.ew/init.lua index 9f62b336..3e8244cd 100755 --- a/quant.ew/init.lua +++ b/quant.ew/init.lua @@ -52,6 +52,7 @@ local function load_modules() ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/heart_pickups/sync.lua") ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/spawn_hooks/init.lua") ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/proxy_info.lua") + ctx.dofile_and_add_hooks("mods/quant.ew/files/src/system/perk_patches/init.lua") end function OnProjectileFired(shooter_id, projectile_id, initial_rng, position_x, position_y, target_x, target_y, send_message,