noita_entangled_worlds/quant.ew/files/system/kolmi/kolmi.lua

139 lines
5.1 KiB
Lua
Raw Normal View History

2024-08-07 17:11:55 +03:00
local util = dofile_once("mods/quant.ew/files/core/util.lua")
local ctx = dofile_once("mods/quant.ew/files/core/ctx.lua")
local net = dofile_once("mods/quant.ew/files/core/net.lua")
2024-07-14 12:19:26 +03:00
local np = require("noitapatcher")
2024-07-16 15:45:01 +03:00
dofile_once("data/scripts/lib/coroutines.lua")
2024-08-07 17:11:55 +03:00
ModLuaFileAppend("data/scripts/biomes/boss_arena.lua", "mods/quant.ew/files/system/kolmi/append/boss_arena.lua")
ModLuaFileAppend("data/entities/animals/boss_centipede/boss_centipede_update.lua", "mods/quant.ew/files/system/kolmi/append/boss_update.lua")
2024-07-16 12:48:40 +03:00
util.replace_text_in("data/entities/animals/boss_centipede/boss_centipede_before_fight.lua",
[[local player_nearby = false]], [[local player_nearby = #EntityGetInRadiusWithTag(x, y, 128, "ew_peer") > 0]])
2024-07-14 12:19:26 +03:00
local rpc = net.new_rpc_namespace()
local module = {}
2024-07-15 21:27:15 +03:00
rpc.opts_reliable()
2024-07-15 19:32:42 +03:00
function rpc.spawn_portal(x, y)
EntityLoad( "data/entities/buildings/teleport_ending_victory_delay.xml", x, y )
end
2024-07-14 12:19:26 +03:00
2024-07-16 13:34:39 +03:00
local function animate_sprite( current_name, next_name )
local kolmi = EntityGetClosestWithTag(0, 0, "boss_centipede")
if kolmi ~= nil and kolmi ~= 0 then
GamePlayAnimation( kolmi, current_name, 0, next_name, 0 )
end
end
rpc.opts_reliable()
function rpc.kolmi_anim(current_name, next_name, is_aggro)
if not is_aggro then
animate_sprite( current_name, next_name )
else
-- aggro overrides animations
animate_sprite( "aggro", "aggro" )
end
end
2024-07-16 15:45:01 +03:00
local function switch_shield(entity_id, is_on)
local children = EntityGetAllChildren(entity_id)
if children == nil then return end
for _,v in ipairs(children) do
if EntityGetName(v) == "shield_entity" then
if is_on then
EntitySetComponentsWithTagEnabled( v, "shield", true )
-- muzzle flash
local x, y = EntityGetTransform(entity_id)
EntityLoad( "data/entities/particles/muzzle_flashes/muzzle_flash_circular_large_pink_reverse.xml", x, y)
GameEntityPlaySound( v, "activate" )
return true
else
EntitySetComponentsWithTagEnabled( v, "shield", false )
-- muzzle flash
local x, y = EntityGetTransform(entity_id)
EntityLoad( "data/entities/particles/muzzle_flashes/muzzle_flash_circular_large_pink.xml", x, y)
GameEntityPlaySound( v, "deactivate" )
return true
end
end
end
end
rpc.opts_reliable()
function rpc.kolmi_shield(is_on, orbcount)
local kolmi = EntityGetClosestWithTag(0, 0, "boss_centipede")
if kolmi == nil or kolmi == 0 then
return
end
2024-07-16 15:45:01 +03:00
if switch_shield(kolmi, is_on) then
return
end
-- No shield?
local pos_x, pos_y = EntityGetTransform(kolmi)
if orbcount == 0 then
EntityAddChild(kolmi, EntityLoad("data/entities/animals/boss_centipede/boss_centipede_shield_weak.xml", pos_x, pos_y))
else
EntityAddChild(kolmi, EntityLoad("data/entities/animals/boss_centipede/boss_centipede_shield_strong.xml", pos_x, pos_y))
end
switch_shield(kolmi, is_on)
end
2024-07-16 16:13:06 +03:00
rpc.opts_reliable()
function rpc.init_boss(orbcount)
local kolmi = EntityGetClosestWithTag(0, 0, "boss_centipede")
if kolmi == nil or kolmi == 0 then
return
end
local lua_components = EntityGetComponentIncludingDisabled(kolmi, "LuaComponent") or {}
for _, c in ipairs(lua_components) do
EntityRemoveComponent(kolmi, c)
end
EntitySetComponentsWithTagEnabled(kolmi, "enabled_at_start", false)
EntitySetComponentsWithTagEnabled(kolmi, "disabled_at_start", true)
end
np.CrossCallAdd("ew_sampo_spawned", function()
local sampo_ent = EntityGetClosestWithTag(0, 0, "this_is_sampo")
if sampo_ent == nil or sampo_ent == 0 then
-- In case sampo wasn't actually spawned.
return
end
if ctx.is_host then
-- First lua component is the one that has pickup script.
local pickup_component = EntityGetFirstComponentIncludingDisabled(sampo_ent, "LuaComponent")
-- Remove it as to not handle pickup twice.
EntityRemoveComponent(sampo_ent, pickup_component)
ctx.cap.item_sync.globalize(sampo_ent)
else
EntityKill(sampo_ent)
end
end)
2024-07-15 21:27:15 +03:00
np.CrossCallAdd("ew_kolmi_spawn_portal", rpc.spawn_portal)
2024-07-15 19:32:42 +03:00
2024-07-16 13:34:39 +03:00
np.CrossCallAdd("ew_kolmi_anim", rpc.kolmi_anim)
2024-07-16 15:45:01 +03:00
np.CrossCallAdd("ew_kolmi_shield", rpc.kolmi_shield)
ctx.cap.item_sync.register_pickup_handler(function(item_id)
if ctx.is_host and EntityHasTag(item_id, "this_is_sampo") then
-- Check if it's the first time we pick it up to avoid that sound on later pickups.
if not GameHasFlagRun("ew_sampo_picked") then
GameAddFlagRun("ew_sampo_picked")
dofile("data/entities/animals/boss_centipede/sampo_pickup.lua")
item_pickup(item_id)
2024-07-16 15:45:01 +03:00
async(function()
wait(10) -- Wait a bit for enemy sync to do it's thing.
local newgame_n = tonumber( SessionNumbersGetValue("NEW_GAME_PLUS_COUNT") )
local orbcount = GameGetOrbCountThisRun() + newgame_n
rpc.kolmi_shield(true, orbcount)
2024-07-16 16:13:06 +03:00
rpc.init_boss(orbcount)
2024-07-16 15:45:01 +03:00
end)
end
end
end)
2024-07-14 12:19:26 +03:00
return module