mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Added effect sync module, but seems like it does the wrong thing.
This commit is contained in:
parent
a438dc1d9f
commit
00c6707b4f
6 changed files with 77 additions and 9 deletions
2
noita-proxy/Cargo.lock
generated
2
noita-proxy/Cargo.lock
generated
|
@ -1693,7 +1693,7 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
|
|||
|
||||
[[package]]
|
||||
name = "noita-proxy"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
dependencies = [
|
||||
"bitcode",
|
||||
"clipboard",
|
||||
|
|
|
@ -3,7 +3,7 @@ members = ["tangled"]
|
|||
|
||||
[package]
|
||||
name = "noita-proxy"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -2,6 +2,7 @@ local bitser = dofile_once("mods/quant.ew/files/lib/bitser.lua")
|
|||
local pollnet = dofile_once("mods/quant.ew/files/lib/pollnet.lua")
|
||||
local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
|
||||
local util = dofile_once("mods/quant.ew/files/src/util.lua")
|
||||
local player_fns = dofile_once("mods/quant.ew/files/src/player_fns.lua")
|
||||
|
||||
local reactor = pollnet.Reactor()
|
||||
|
||||
|
@ -40,8 +41,10 @@ local rpc_meta = {
|
|||
end)
|
||||
net_handling.mod[index] = function(peer_id, args)
|
||||
ctx.rpc_peer_id = peer_id
|
||||
ctx.rpc_player_data = player_fns.peer_get_player_data(peer_id)
|
||||
v(unpack(args))
|
||||
ctx.rpc_peer_id = nil
|
||||
ctx.rpc_player_data = nil
|
||||
end
|
||||
rpc_inner.opts = {}
|
||||
end,
|
||||
|
|
|
@ -443,6 +443,17 @@ function player_fns.respawn_if_necessary()
|
|||
end
|
||||
end
|
||||
|
||||
function player_fns.spread_max_health()
|
||||
if ctx.is_host then
|
||||
local _, max_hp = util.get_ent_health(ctx.my_player.entity)
|
||||
for peer_id, player_data in pairs(ctx.players) do
|
||||
if peer_id ~= ctx.my_id then
|
||||
util.set_ent_health(player_data.entity, {-1, max_hp})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function player_fns.is_inventory_open()
|
||||
local player_entity = ctx.players[ctx.my_id].entity
|
||||
local inventory_gui_comp = EntityGetFirstComponentIncludingDisabled(player_entity, "InventoryGuiComponent")
|
||||
|
|
52
quant.ew/files/src/sync/effect_sync.lua
Normal file
52
quant.ew/files/src/sync/effect_sync.lua
Normal file
|
@ -0,0 +1,52 @@
|
|||
local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
|
||||
local net = dofile_once("mods/quant.ew/files/src/net.lua")
|
||||
local np = require("noitapatcher")
|
||||
|
||||
local rpc = net.new_rcp_namespace()
|
||||
|
||||
local effect_sync = {}
|
||||
|
||||
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")
|
||||
-- GamePrint("eff "..name)
|
||||
table.insert(list, ent)
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function effect_sync.on_world_update()
|
||||
if GameGetFrameNum() % 30 ~= 9 then
|
||||
return
|
||||
end
|
||||
local my_player = ctx.my_player
|
||||
local effects = effect_sync.get_ent_effects(my_player.entity)
|
||||
local sync_data = {}
|
||||
for _, effect in ipairs(effects) do
|
||||
table.insert(sync_data, np.SerializeEntity(effect))
|
||||
end
|
||||
rpc.send_effects(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)
|
||||
local entity = ctx.rpc_player_data.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
|
||||
|
||||
return effect_sync
|
|
@ -18,8 +18,9 @@ local pretty = dofile_once("mods/quant.ew/files/lib/pretty_print.lua")
|
|||
local perk_fns = dofile_once("mods/quant.ew/files/src/perk_fns.lua")
|
||||
|
||||
local enemy_sync = ctx.dofile_and_add_hooks("mods/quant.ew/files/src/enemy_sync.lua")
|
||||
local world_sync = ctx.dofile_and_add_hooks("mods/quant.ew/files/src/world_sync.lua")
|
||||
local item_sync = ctx.dofile_and_add_hooks("mods/quant.ew/files/src/item_sync.lua")
|
||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/world_sync.lua")
|
||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/item_sync.lua")
|
||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/src/sync/effect_sync.lua")
|
||||
|
||||
local version = dofile_once("mods/quant.ew/files/version.lua") or "unknown (dev build)"
|
||||
|
||||
|
@ -159,7 +160,7 @@ function OnPlayerSpawned( player_entity ) -- This runs when player entity has be
|
|||
ComponentSetValue2(item_pick, "is_immune_to_kicks", true)
|
||||
|
||||
if ctx.debug then
|
||||
EntitySetTransform(player_entity, 0, 12600)
|
||||
-- EntitySetTransform(player_entity, 0, 12600)
|
||||
util.set_ent_health(player_entity, {1000, 1000})
|
||||
local wallet = EntityGetFirstComponentIncludingDisabled(player_entity, "WalletComponent")
|
||||
ComponentSetValue2(wallet, "money", 100000)
|
||||
|
@ -209,7 +210,10 @@ local function on_world_pre_update_inner()
|
|||
end
|
||||
end
|
||||
|
||||
player_fns.respawn_if_necessary()
|
||||
if GameGetFrameNum() % 120 == 0 then
|
||||
player_fns.respawn_if_necessary()
|
||||
player_fns.spread_max_health()
|
||||
end
|
||||
|
||||
if ctx.events.new_player_seen then
|
||||
local hp, max_hp = util.get_ent_health(my_player.entity)
|
||||
|
@ -281,7 +285,7 @@ local function on_world_pre_update_inner()
|
|||
else
|
||||
ctx.hook.on_world_update_client()
|
||||
end
|
||||
-- ctx.hook.world_update()
|
||||
ctx.hook.on_world_update()
|
||||
end
|
||||
|
||||
function OnWorldPreUpdate() -- This is called every time the game is about to start updating the world
|
||||
|
@ -305,8 +309,6 @@ function OnWorldPostUpdate() -- This is called every time the game has finished
|
|||
ctx.events = {}
|
||||
end
|
||||
|
||||
|
||||
|
||||
function register_localizations(translation_file, clear_count)
|
||||
|
||||
clear_count = clear_count or 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue