Start the kolmi fight properly if any player picks up the sampo.

This commit is contained in:
IQuant 2024-07-14 14:57:00 +03:00
parent 6e4230c9c7
commit af90ebb0d8
5 changed files with 71 additions and 10 deletions

View file

@ -26,6 +26,7 @@ Used by:
Functions:
- `globalize(entity_id, instantly: bool)`
- `register_pickup_handler(fn(local_item_id))`
Provided by:
- item_sync system

View file

@ -15,20 +15,24 @@ function module.on_local_player_spawn(my_player)
-- EntitySetTransform(player_entity, 512*3+10, 512*3+10)
EntitySetTransform(player_entity, 3400, 13040)
-- util.load_ephemerial("mods/quant.ew/files/entities/client.xml", 512*3+20, 512*3+10)
-- EntityLoad("mods/quant.ew/files/entities/client.xml", 512*3+20, 512*3+10)
util.set_ent_health(player_entity, {1000, 1000})
ctx.cap.health.set_max_health(1000)
ctx.cap.health.set_health(1000)
-- util.set_ent_health(player_entity, {1000, 1000})
local wallet = EntityGetFirstComponentIncludingDisabled(player_entity, "WalletComponent")
ComponentSetValue2(wallet, "money", 100000)
-- GameSetCameraFree(true)
dofile_once("data/scripts/perks/perk.lua")
local x, y = EntityGetFirstHitboxCenter(player_entity)
perk_spawn(x, y, "LASER_AIM", true)
perk_spawn(x-50, y, "GLASS_CANNON", true)
perk_spawn(x-25, y, "EDIT_WANDS_EVERYWHERE", true)
EntityLoad("data/entities/items/pickup/heart.xml", x-75, y-20)
-- dofile_once("data/scripts/perks/perk.lua")
-- local x, y = EntityGetFirstHitboxCenter(player_entity)
-- perk_spawn(x, y, "LASER_AIM", true)
-- perk_spawn(x-50, y, "GLASS_CANNON", true)
-- perk_spawn(x-25, y, "EDIT_WANDS_EVERYWHERE", true)
-- EntityLoad("data/entities/items/pickup/heart.xml", x-75, y-20)
end

View file

@ -11,6 +11,7 @@ local rpc = net.new_rpc_namespace()
local item_sync = {}
local pending_remove = {}
local pickup_handlers = {}
function item_sync.ensure_notify_component(ent)
local notify = EntityGetFirstComponentIncludingDisabled(ent, "LuaComponent", "ew_notify_component")
@ -55,6 +56,16 @@ function item_sync.remove_item_with_id(gid)
table.insert(pending_remove, gid)
end
function item_sync.find_by_gid(gid)
local global_items = EntityGetWithTag("ew_global_item")
for _, item in ipairs(global_items) do
local i_gid = item_sync.get_global_item_id(item)
if i_gid == gid then
return item
end
end
end
function item_sync.remove_item_with_id_now(gid)
local global_items = EntityGetWithTag("ew_global_item")
for _, item in ipairs(global_items) do
@ -66,7 +77,6 @@ function item_sync.remove_item_with_id_now(gid)
end
function item_sync.host_localize_item(gid, peer_id)
GamePrint("Will localize")
if ctx.item_prevent_localize[gid] then
GamePrint("Item localize for "..gid.." prevented")
end
@ -77,7 +87,12 @@ function item_sync.host_localize_item(gid, peer_id)
return
end
local item_ent_id = item_sync.find_by_gid(gid)
if item_ent_id ~= nil then
for _, handler in ipairs(pickup_handlers) do
handler(item_ent_id)
end
end
if peer_id ~= ctx.my_id then
item_sync.remove_item_with_id(gid)
end
@ -94,6 +109,7 @@ function item_sync.make_item_global(item, instant)
GamePrint("Thrown item vanished before we could send it")
return
end
item_sync.ensure_notify_component(item)
local gid_component = EntityGetFirstComponentIncludingDisabled(item, "VariableStorageComponent", "ew_global_item_id")
local gid = ComponentGetValue2(gid_component, "value_string")
if gid_component == nil then
@ -198,6 +214,12 @@ end
rpc.opts_reliable()
function rpc.item_localize(l_peer_id, item_id)
local item_ent_id = item_sync.find_by_gid(item_id)
if item_ent_id ~= nil then
for _, handler in ipairs(pickup_handlers) do
handler(item_ent_id)
end
end
if l_peer_id ~= ctx.my_id then
item_sync.remove_item_with_id(item_id)
end
@ -212,7 +234,10 @@ function rpc.item_localize_req(gid)
end
ctx.cap.item_sync = {
globalize = item_sync.make_item_global
globalize = item_sync.make_item_global,
register_pickup_handler = function(handler)
table.insert(pickup_handlers, handler)
end
}
return item_sync

View file

@ -0,0 +1,6 @@
local old_spawn_items = spawn_items
function spawn_items(x, y)
old_spawn_items(x, y)
CrossCall("ew_sampo_spawned")
end

View file

@ -4,10 +4,35 @@ 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")
ModLuaFileAppend("data/scripts/biomes/boss_arena.lua", "mods/quant.ew/files/src/system/kolmi/append/boss_arena.lua")
local rpc = net.new_rpc_namespace()
local module = {}
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)
ctx.cap.item_sync.register_pickup_handler(function(item_id)
if ctx.is_host and EntityHasTag(item_id, "this_is_sampo") then
dofile("data/entities/animals/boss_centipede/sampo_pickup.lua")
item_pickup(item_id)
end
end)
return module