mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Brought back code for game effect sync (it's not enabled yet tho)
This commit is contained in:
parent
3ab095d60b
commit
7b211c2360
1 changed files with 69 additions and 0 deletions
69
quant.ew/files/system/game_effect_sync/game_effect_sync.lua
Normal file
69
quant.ew/files/system/game_effect_sync/game_effect_sync.lua
Normal file
|
@ -0,0 +1,69 @@
|
|||
-- This module syncs effects (like being on fire) from clients to everyone else.
|
||||
|
||||
local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
|
||||
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")
|
||||
|
||||
local rpc = net.new_rpc_namespace()
|
||||
|
||||
local effect_sync = {}
|
||||
|
||||
local IGNORE_EFFECTS = {
|
||||
POLYMORPH = true,
|
||||
POLYMORPH_RANDOM = true,
|
||||
POLYMORPH_CESSATION = true,
|
||||
POLYMORPH_UNSTABLE = true,
|
||||
}
|
||||
|
||||
function effect_sync.get_ent_effects(entity)
|
||||
local list = {}
|
||||
for _, ent in ipairs(EntityGetAllChildren(entity) or {}) do
|
||||
local com = EntityGetFirstComponentIncludingDisabled(ent, "GameEffectComponent")
|
||||
if com ~= nil then
|
||||
local name = ComponentGetValue2(com, "effect")
|
||||
if not IGNORE_EFFECTS[name] then
|
||||
table.insert(list, ent)
|
||||
end
|
||||
-- GamePrint("eff "..name)
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function effect_sync.on_world_update()
|
||||
if GameGetFrameNum() % 30 ~= 9 then
|
||||
return
|
||||
end
|
||||
local all_sync_data = {}
|
||||
|
||||
local effects = effect_sync.get_ent_effects(ctx.my_player.entity)
|
||||
local sync_data = {}
|
||||
for _, effect in ipairs(effects) do
|
||||
table.insert(sync_data, np.SerializeEntity(effect))
|
||||
end
|
||||
all_sync_data[ctx.my_id] = sync_data
|
||||
|
||||
rpc.send_effects(all_sync_data)
|
||||
end
|
||||
|
||||
function effect_sync.remove_all_effects(entity)
|
||||
local effects = effect_sync.get_ent_effects(entity)
|
||||
for _, effect in ipairs(effects) do
|
||||
EntityKill(effect)
|
||||
end
|
||||
end
|
||||
|
||||
function rpc.send_effects(effects_of_players)
|
||||
for peer_id, effects in pairs(effects_of_players) do
|
||||
local entity = player_fns.peer_get_player_data(peer_id).entity
|
||||
effect_sync.remove_all_effects(entity)
|
||||
for _, effect in ipairs(effects) do
|
||||
local ent = EntityCreateNew()
|
||||
np.DeserializeEntity(ent, effect)
|
||||
EntityAddChild(entity, ent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return effect_sync
|
Loading…
Add table
Add a link
Reference in a new issue