From 449c41609300272f78aaf6406cac32ed8fa115b4 Mon Sep 17 00:00:00 2001 From: bgkillas Date: Sat, 16 Nov 2024 09:53:14 -0500 Subject: [PATCH] sync stains on enemys --- .../effect_data_sync/effect_data_sync.lua | 57 ++++++++++++------- quant.ew/files/system/enemy_sync.lua | 13 ++++- .../game_effect_sync/game_effect_sync.lua | 2 +- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/quant.ew/files/system/effect_data_sync/effect_data_sync.lua b/quant.ew/files/system/effect_data_sync/effect_data_sync.lua index 1ba8b105..a029f9cb 100644 --- a/quant.ew/files/system/effect_data_sync/effect_data_sync.lua +++ b/quant.ew/files/system/effect_data_sync/effect_data_sync.lua @@ -13,26 +13,7 @@ local rpc = net.new_rpc_namespace() local module = {} -function rpc.send_present_stains(present_stains) - local entity = ctx.rpc_player_data.entity - local effect_data = EntityGetFirstComponent(entity, "StatusEffectDataComponent") - if effect_data == nil or effect_data == 0 then - return - end - local current_stains = ComponentGetValue2(effect_data, "stain_effects") - - for index, is_present in ipairs(present_stains) do - if not is_present and current_stains[index+1] ~= nil and current_stains[index+1] >= 0.15 then - EntityRemoveStainStatusEffect(entity, effect_by_index[index]) - end - end -end - -function module.on_world_update() - if GameGetFrameNum() % 30 ~= 13 then - return - end - local entity = ctx.my_player.entity +function module.get_stains(entity) local effect_data = EntityGetFirstComponent(entity, "StatusEffectDataComponent") if effect_data == nil or effect_data == 0 then return @@ -42,9 +23,41 @@ function module.on_world_update() local present_stains = {} -- For some reason whatever value is at index 1 isn't used? for i=2, #stains do - table.insert(present_stains, stains[i] >= 0.15) + if stains[i] >= 0.15 then + present_stains[i] = true + end + end + return present_stains +end + +function module.sync_stains(present_stains, entity) + local effect_data = EntityGetFirstComponent(entity, "StatusEffectDataComponent") + if effect_data == nil or effect_data == 0 then + return + end + local current_stains = ComponentGetValue2(effect_data, "stain_effects") + + for i=2, #current_stains do + if current_stains[i] >= 0.15 and not present_stains[i] then + EntityRemoveStainStatusEffect(entity, effect_by_index[i - 1]) + end + end +end + +function rpc.send_present_stains(present_stains) + module.sync_stains(present_stains, ctx.rpc_player_data.entity) +end + + + +function module.on_world_update() + if GameGetFrameNum() % 15 ~= 8 then + return + end + local present = module.get_stains(ctx.my_player.entity) + if present ~= nil then + rpc.send_present_stains(present) end - rpc.send_present_stains(present_stains) end return module \ No newline at end of file diff --git a/quant.ew/files/system/enemy_sync.lua b/quant.ew/files/system/enemy_sync.lua index f868cb3a..107564e2 100644 --- a/quant.ew/files/system/enemy_sync.lua +++ b/quant.ew/files/system/enemy_sync.lua @@ -4,6 +4,7 @@ local net = dofile_once("mods/quant.ew/files/core/net.lua") local player_fns = dofile_once("mods/quant.ew/files/core/player_fns.lua") local item_sync = dofile_once("mods/quant.ew/files/system/item_sync.lua") local effect_sync = dofile_once("mods/quant.ew/files/system/game_effect_sync/game_effect_sync.lua") +local stain_sync = dofile_once("mods/quant.ew/files/system/effect_data_sync/effect_data_sync.lua") local np = require("noitapatcher") local ffi = require("ffi") @@ -350,7 +351,10 @@ function enemy_sync.host_upload_entities() local dont_cull = EntityHasTag(enemy_id, "worm") or EntityGetFirstComponent(enemy_id, "BossHealthBarComponent") ~= nil - table.insert(enemy_data_list, {filename, en_data, phys_info, phys_info_2, wand, effect_data, animation, dont_cull, death_triggers}) + local stains = stain_sync.get_stains(enemy_id) + + table.insert(enemy_data_list, {filename, en_data, phys_info, phys_info_2, wand, + effect_data, animation, dont_cull, death_triggers, stains}) ::continue:: end @@ -437,6 +441,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull) local en_data = enemy_info_raw[2] local dont_cull = enemy_info_raw[8] local death_triggers = enemy_info_raw[9] + local stains = enemy_info_raw[10] local remote_enemy_id = en_data.enemy_id local x, y = en_data.x, en_data.y if not force_no_cull and not dont_cull then @@ -630,6 +635,10 @@ local function sync_enemy(enemy_info_raw, force_no_cull) end end end + effect_sync.apply_effects(effects, enemy_id, true) + if stains ~= nil then + stain_sync.sync_stains(stains, enemy_id) + end end local inv = EntityGetFirstComponentIncludingDisabled(enemy_id, "Inventory2Component") @@ -669,8 +678,6 @@ local function sync_enemy(enemy_info_raw, force_no_cull) end end - effect_sync.apply_effects(effects, enemy_id, true) - for _, sprite in pairs(EntityGetComponent(enemy_id, "SpriteComponent", "ew_sprite") or {}) do ComponentSetValue2(sprite, "rect_animation", animation) ComponentSetValue2(sprite, "next_rect_animation", animation) diff --git a/quant.ew/files/system/game_effect_sync/game_effect_sync.lua b/quant.ew/files/system/game_effect_sync/game_effect_sync.lua index dccaa82d..411d9a2a 100644 --- a/quant.ew/files/system/game_effect_sync/game_effect_sync.lua +++ b/quant.ew/files/system/game_effect_sync/game_effect_sync.lua @@ -72,7 +72,7 @@ function effect_sync.get_sync_data(entity, perks) end function effect_sync.on_world_update() - if GameGetFrameNum() % 30 == 9 then + if GameGetFrameNum() % 15 == 9 then local sync_data = effect_sync.get_sync_data(ctx.my_player.entity, false) rpc.send_effects(sync_data, false) end