From 5cc4ff01c5cd4c822c9e57bad3aec16e14af6fc9 Mon Sep 17 00:00:00 2001 From: bgkillas Date: Wed, 13 Nov 2024 18:54:28 -0500 Subject: [PATCH] use new ephemerial for enemys and players, fix polymorphing enemys looking weird --- quant.ew/files/core/player_fns.lua | 6 +++ quant.ew/files/core/util.lua | 11 ++++-- quant.ew/files/resource/append/action_fix.lua | 3 -- quant.ew/files/system/enemy_sync.lua | 37 +++++-------------- .../files/system/ewext_init/ewext_init.lua | 6 ++- .../game_effect_sync/game_effect_sync.lua | 11 ++++++ 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/quant.ew/files/core/player_fns.lua b/quant.ew/files/core/player_fns.lua index eea414eb..5e8a0322 100644 --- a/quant.ew/files/core/player_fns.lua +++ b/quant.ew/files/core/player_fns.lua @@ -491,6 +491,9 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata) end print("Spawning player for "..peer_id) local new = EntityLoad("mods/quant.ew/files/system/player/tmp/" .. peer_id .. "_base.xml", x, y) + if new ~= nil then + ewext.make_ephemerial(new) + end local inv_full = EntityCreateNew("inventory_full") EntityAddChild(new, inv_full) LoadGameEffectEntityTo(new, "mods/quant.ew/files/system/spectate/no_tinker.xml") @@ -539,6 +542,9 @@ function player_fns.spawn_player_for(peer_id, x, y, existing_playerdata) end function player_fns.replace_player_entity(new_entity, player_data) + if new_entity ~= nil then + ewext.make_ephemerial(new_entity) + end if new_entity ~= nil then local old_entity = player_data.entity player_data.entity = new_entity diff --git a/quant.ew/files/core/util.lua b/quant.ew/files/core/util.lua index ee8b6a6e..7d23273c 100644 --- a/quant.ew/files/core/util.lua +++ b/quant.ew/files/core/util.lua @@ -183,11 +183,14 @@ end) -- Load an entity that doesn't get saved. function util.load_ephemerial(path, x, y) - local entity = EntityCreateNew() - EntityAddTag(entity, "ew_synced_entity") - EntitySetTransform(entity, x, y) + --local entity = EntityCreateNew() + --EntityAddTag(entity, "ew_synced_entity") + --EntitySetTransform(entity, x, y) local ent_2 = EntityLoad(path, x, y) - EntityAddChild(entity, ent_2) + --EntityAddChild(entity, ent_2) + if ent_2 ~= nil then + ewext.make_ephemerial(ent_2) + end return ent_2 end diff --git a/quant.ew/files/resource/append/action_fix.lua b/quant.ew/files/resource/append/action_fix.lua index a39f7e34..76ad3a79 100644 --- a/quant.ew/files/resource/append/action_fix.lua +++ b/quant.ew/files/resource/append/action_fix.lua @@ -42,8 +42,5 @@ local orig = GetUpdatedEntityID function GetUpdatedEntityID() local ent = EntityGetRootEntity(orig()) - if EntityHasTag(ent, "ew_synced_entity") then - ent = (EntityGetAllChildren(ent) or {0})[1] - end return ent end \ 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 87be76d9..0e2bc524 100644 --- a/quant.ew/files/system/enemy_sync.lua +++ b/quant.ew/files/system/enemy_sync.lua @@ -63,6 +63,8 @@ local PhysDataNoMotion = util.make_type({ u8 = {"r"} }) +local frame = 0 + local enemy_sync = {} local unsynced_enemys = {} @@ -96,10 +98,10 @@ np.CrossCallAdd("ew_es_death_notify", function(enemy_id, responsible_id) end) local function kill(entity) - local parent = EntityGetParent(entity) - if parent ~= nil then - EntityKill(parent) - end + --local parent = EntityGetParent(entity) + --if parent ~= nil then + -- EntityKill(parent) + --end EntityKill(entity) end @@ -401,26 +403,15 @@ function enemy_sync.client_cleanup() local filename = EntityGetFilename(enemy_id) print("Despawning persisted "..enemy_id.." "..filename) kill(enemy_id) - else - local cull = EntityGetFirstComponentIncludingDisabled(enemy_id, "VariableStorageComponent", "ew_cull") - if cull ~= nil and ComponentGetValue2(cull, "value_int") + 120 < GameGetFrameNum() then - kill(enemy_id) - end end end - local frame = GameGetFrameNum() for remote_id, enemy_data in pairs(ctx.entity_by_remote_id) do - if frame - enemy_data.frame > 60*2 then + if frame > enemy_data.frame then --print("Despawning stale "..remote_id.." "..enemy_data.id) kill(enemy_data.id) ctx.entity_by_remote_id[remote_id] = nil end end - for _, ent in ipairs(EntityGetWithTag("ew_synced_entity") or {}) do - if #(EntityGetAllChildren(ent) or {}) == 0 then - EntityKill(ent) - end - end end function enemy_sync.on_world_update_host() @@ -440,7 +431,7 @@ function enemy_sync.on_world_update_host() end function enemy_sync.on_world_update_client() - if GameGetFrameNum() % 20 == 1 then + if GameGetFrameNum() % 10 == 1 then enemy_sync.client_cleanup() end if GameGetFrameNum() % (60*60) == 1 then @@ -527,9 +518,6 @@ local function sync_enemy(enemy_info_raw, force_no_cull) EntityRemoveComponent(enemy_id, com) end end - if not dont_cull then - EntityAddComponent2(enemy_id, "VariableStorageComponent", {_tags="ew_cull", value_int = GameGetFrameNum()}) - end EntityAddComponent2(enemy_id, "LuaComponent", {_tags="ew_immortal", script_damage_about_to_be_received = "mods/quant.ew/files/resource/cbs/immortal.lua"}) local damage_component = EntityGetFirstComponentIncludingDisabled(enemy_id, "DamageModelComponent") if damage_component and damage_component ~= 0 then @@ -570,10 +558,6 @@ local function sync_enemy(enemy_info_raw, force_no_cull) enemy_data_new.frame = frame local enemy_id = enemy_data_new.id - if not dont_cull then - ComponentSetValue2(EntityGetFirstComponentIncludingDisabled(enemy_id, "VariableStorageComponent", "ew_cull"), "value_int", GameGetFrameNum()) - end - for i, phys_component in ipairs(EntityGetComponent(enemy_id, "PhysicsBodyComponent") or {}) do local phys_info = phys_infos[i] if phys_component ~= nil and phys_component ~= 0 and phys_info ~= nil then @@ -605,10 +589,6 @@ local function sync_enemy(enemy_info_raw, force_no_cull) else EntitySetTransform(enemy_id, x, y) end - local root = EntityGetRootEntity(enemy_id) - if root ~= nil and EntityHasTag(root, "ew_synced_entity") then - EntitySetTransform(root, x, y) - end local worm = EntityGetFirstComponentIncludingDisabled(enemy_id, "WormAIComponent") or EntityGetFirstComponentIncludingDisabled(enemy_id, "BossDragonComponent") if worm ~= nil and ffi.typeof(en_data) == EnemyDataWorm then @@ -768,6 +748,7 @@ function rpc.handle_death_data(death_data) end function rpc.handle_enemy_data(enemy_data) + frame = GameGetFrameNum() for _, enemy_info_raw in ipairs(enemy_data) do sync_enemy(enemy_info_raw, false) end diff --git a/quant.ew/files/system/ewext_init/ewext_init.lua b/quant.ew/files/system/ewext_init/ewext_init.lua index af1f415b..d57dd3f9 100644 --- a/quant.ew/files/system/ewext_init/ewext_init.lua +++ b/quant.ew/files/system/ewext_init/ewext_init.lua @@ -22,7 +22,9 @@ local function oh_another_world_state(entity) print("Another world state: "..entity) GamePrint("Another World State Entity detected") GamePrint("Do a 'mods > restart with enabled mods' to avoid a crash") - ewext.make_ephemerial(entity) + if entity ~= nil then + ewext.make_ephemerial(entity) + end end function module.on_local_player_spawn() @@ -44,4 +46,4 @@ function module.on_world_update() end end -return module +return module \ No newline at end of file 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 35b7883b..dccaa82d 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 @@ -12,6 +12,13 @@ local IGNORE_EFFECTS = { NO_WAND_EDITING = true, } +local REMOVE_EFFECTS = { + POLYMORPH = true, + POLYMORPH_RANDOM = true, + POLYMORPH_CESSATION = true, + POLYMORPH_UNSTABLE = true, +} + function effect_sync.get_ent_effects(entity, perks) local filename = EntityGetFilename(entity) local list = {} @@ -25,6 +32,10 @@ function effect_sync.get_ent_effects(entity, perks) local name = ComponentGetValue2(com, "effect") if not IGNORE_EFFECTS[name] and filename ~= EntityGetFilename(ent) and (not EntityHasTag(ent, "perk_entity") or perks) then table.insert(list, ent) + elseif REMOVE_EFFECTS[name] + and ctx.my_player.entity ~= entity + and (ctx.my_id ~= ctx.host_id or player_fns.get_player_data_by_local_entity_id(entity) ~= nil) then + EntityKill(ent) end end end