Sync orbs from host to clients

This commit is contained in:
IQuant 2024-08-21 14:25:12 +03:00
parent a363efdfa9
commit a4d71769bf
3 changed files with 53 additions and 0 deletions

View file

@ -94,6 +94,8 @@ function module.on_world_update_post()
tp_button("Meat realm", 7328, 9263)
tp_button("Kivi", 7427, -4960)
tp_button("Null altar", 14000, 7500)
tp_button("Orb 0", 765.510, -1075.003)
tp_button("Orb 7", 4262.749, 887.997)
end
if imgui.CollapsingHeader("Game effects") then
show_game_effects()

View file

@ -0,0 +1,50 @@
local rpc = net.new_rpc_namespace()
local module = {}
local function orbs_found_this_run()
local wsc = EntityGetFirstComponent(GameGetWorldStateEntity(), "WorldStateComponent")
return ComponentGetValue2(wsc, "orbs_found_thisrun")
end
function rpc.update_orbs(found_orbs)
local found_local = orbs_found_this_run()
for _, orb in ipairs(found_orbs) do
if table.contains(found_local, orb) then
goto continue
end
local orb_ent = EntityCreateNew()
EntityAddComponent2(orb_ent, "ItemComponent", {
enable_orb_hacks = true,
auto_pickup = true,
})
EntityAddComponent2(orb_ent, "OrbComponent", {
orb_id = orb,
})
local x, y = EntityGetTransform(ctx.my_player.entity)
EntitySetTransform(orb_ent, x, y)
::continue::
end
end
local function send_orbs()
GamePrint("sending orbs")
rpc.update_orbs(orbs_found_this_run())
end
local last_orb_count = 0
function module.on_world_update_host()
if last_orb_count ~= GameGetOrbCountThisRun() then
last_orb_count = GameGetOrbCountThisRun()
send_orbs()
end
end
function module.on_should_send_updates()
if ctx.is_host then
send_orbs()
end
end
return module

View file

@ -92,6 +92,7 @@ local function load_modules()
ctx.load_system("extra_genomes")
ctx.load_system("amulet_sync")
ctx.load_system("game_effect_sync")
ctx.load_system("orb_sync")
-- ctx.load_system("effect_data_sync")
end