From 681bc6a3b8e5479b91293fe86e76eee29e1aaec5 Mon Sep 17 00:00:00 2001 From: bgkillas Date: Sat, 2 Nov 2024 18:37:16 -0400 Subject: [PATCH] fix enemys not dropping right stuff generally, specifically pyramid boss --- quant.ew/files/system/end_fight/end_fight.lua | 2 +- quant.ew/files/system/enemy_sync.lua | 43 ++- .../patch_dragon_boss/dragon_boss_extra.xml | 299 ------------------ .../patch_dragon_boss/dragonspot_script.lua | 4 +- 4 files changed, 30 insertions(+), 318 deletions(-) delete mode 100644 quant.ew/files/system/patch_dragon_boss/dragon_boss_extra.xml diff --git a/quant.ew/files/system/end_fight/end_fight.lua b/quant.ew/files/system/end_fight/end_fight.lua index cadedbe8..ea65c8a6 100644 --- a/quant.ew/files/system/end_fight/end_fight.lua +++ b/quant.ew/files/system/end_fight/end_fight.lua @@ -100,7 +100,7 @@ function rpc.try_kill(x, y) end end end) - GamePrintImportant(ctx.rpc_player_data.name .. " has won") + GamePrintImportant(ctx.rpc_player_data.name .. " wins") end local function remove_fire(entity) diff --git a/quant.ew/files/system/enemy_sync.lua b/quant.ew/files/system/enemy_sync.lua index b484726f..1c980938 100644 --- a/quant.ew/files/system/enemy_sync.lua +++ b/quant.ew/files/system/enemy_sync.lua @@ -12,33 +12,29 @@ local rpc = net.new_rpc_namespace() local EnemyData = util.make_type({ u32 = {"enemy_id"}, f32 = {"x", "y", "vx", "vy"}, - bool = {"drop_gold"}, }) -- Variant of EnemyData for when we don't have any motion (or no VelocityComponent). local EnemyDataNoMotion = util.make_type({ u32 = {"enemy_id"}, f32 = {"x", "y"}, - bool = {"drop_gold"} }) local EnemyDataWorm = util.make_type({ u32 = {"enemy_id"}, f32 = {"x", "y", "vx", "vy", "tx", "ty"}, - bool = {"drop_gold"} }) local EnemyDataKolmi = util.make_type({ u32 = {"enemy_id"}, f32 = {"x", "y", "vx", "vy"}, - bool = {"enabled", "drop_gold"}, + bool = {"enabled"}, }) local EnemyDataFish = util.make_type({ u32 = {"enemy_id"}, f32 = {"x", "y", "vx", "vy"}, u8 = {"r"}, - bool = {"drop_gold"}, }) --local EnemyDataSniper = util.make_type({ @@ -269,10 +265,11 @@ function enemy_sync.host_upload_entities() -- -- local x, y, r = -- end - local drop_gold = false + local death_triggers = {} for _, com in ipairs(EntityGetComponent(enemy_id, "LuaComponent") or {}) do - if ComponentGetValue2(com, "script_death") == "data/scripts/items/drop_money.lua" then - drop_gold = true + local script = ComponentGetValue2(com, "script_death") + if script ~= nil and script ~= "" then + table.insert(death_triggers, constants.interned_filename_to_index[script] or script) end end local en_data @@ -285,7 +282,6 @@ function enemy_sync.host_upload_entities() vx = vx, vy = vy, enabled = EntityGetFirstComponent(enemy_id, "BossHealthBarComponent", "disabled_at_start") ~= nil, - drop_gold = drop_gold } elseif worm ~= nil then local tx, ty = ComponentGetValue2(worm, "mRandomTarget") @@ -297,14 +293,12 @@ function enemy_sync.host_upload_entities() vy = vy, tx = tx, ty = ty, - drop_gold = drop_gold } elseif math.abs(vx) < 0.01 and math.abs(vy) < 0.01 then en_data = EnemyDataNoMotion { enemy_id = enemy_id, x = x, y = y, - drop_gold = drop_gold } elseif EntityGetFirstComponentIncludingDisabled(enemy_id, "AdvancedFishAIComponent") ~= nil then en_data = EnemyDataFish { @@ -314,7 +308,6 @@ function enemy_sync.host_upload_entities() vx = vx, vy = vy, r = math.floor((rot % FULL_TURN) / FULL_TURN * 255), - drop_gold = drop_gold } else en_data = EnemyData { @@ -323,7 +316,6 @@ function enemy_sync.host_upload_entities() y = y, vx = vx, vy = vy, - drop_gold = drop_gold } end @@ -352,7 +344,7 @@ 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, not_ephemerial, phys_info, phys_info_2, has_wand, effect_data, animation, dont_cull}) + table.insert(enemy_data_list, {filename, en_data, not_ephemerial, phys_info, phys_info_2, has_wand, effect_data, animation, dont_cull, death_triggers}) ::continue:: end @@ -454,6 +446,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull) local en_data = enemy_info_raw[2] local dont_cull = enemy_info_raw[9] + local death_triggers = 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 @@ -617,13 +610,29 @@ local function sync_enemy(enemy_info_raw, force_no_cull) EntitySetComponentsWithTagEnabled(enemy_id, "enabled_at_start", false) EntitySetComponentsWithTagEnabled(enemy_id, "disabled_at_start", true) end - end - if not en_data.drop_gold then + + local indexed = {} for _, com in ipairs(EntityGetComponent(enemy_id, "LuaComponent") or {}) do - if ComponentGetValue2(com, "script_death") == "data/scripts/items/drop_money.lua" then + local script = ComponentGetValue2(com, "script_death") + local has = false + for _, inx in ipairs(death_triggers) do + local script2 = constants.interned_index_to_filename[inx] or inx + if script == script2 then + has = true + indexed[script] = true + end + end + if not has then ComponentSetValue2(com, "script_death", "") end end + for _, inx in ipairs(death_triggers) do + local script = constants.interned_index_to_filename[inx] or inx + if indexed[script] == nil then + EntityAddComponent(enemy_id, "LuaComponent", { script_death = script, + execute_every_n_frame = "-1"}) + end + end end local inv = EntityGetFirstComponentIncludingDisabled(enemy_id, "Inventory2Component") diff --git a/quant.ew/files/system/patch_dragon_boss/dragon_boss_extra.xml b/quant.ew/files/system/patch_dragon_boss/dragon_boss_extra.xml deleted file mode 100644 index eca8b695..00000000 --- a/quant.ew/files/system/patch_dragon_boss/dragon_boss_extra.xml +++ /dev/null @@ -1,299 +0,0 @@ - - - <_Transform - position.x="0" - position.y="0" - rotation="0" - scale.x="1" - scale.y="1" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/quant.ew/files/system/patch_dragon_boss/dragonspot_script.lua b/quant.ew/files/system/patch_dragon_boss/dragonspot_script.lua index af2fa1e4..3bce382e 100644 --- a/quant.ew/files/system/patch_dragon_boss/dragonspot_script.lua +++ b/quant.ew/files/system/patch_dragon_boss/dragonspot_script.lua @@ -5,7 +5,9 @@ function collision_trigger() local entity_id = GetUpdatedEntityID() local pos_x, pos_y = EntityGetTransform( entity_id ) if GameHasFlagRun("ew_flag_this_is_host") then - EntityLoad( "mods/quant.ew/files/system/patch_dragon_boss/dragon_boss_extra.xml", pos_x, pos_y ) + local eid = EntityLoad( "data/entities/animals/boss_dragon.xml", pos_x, pos_y ) + EntityAddComponent(eid, "LuaComponent", { script_death = "data/scripts/animals/boss_dragon_death.lua", + execute_every_n_frame = "-1"}) end EntityLoad( "data/entities/particles/image_emitters/magical_symbol_fast.xml", pos_x, pos_y )