2024-05-02 20:24:27 +03:00
|
|
|
local player_fns = dofile_once("mods/quant.ew/files/src/player_fns.lua")
|
|
|
|
|
local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
|
2024-05-10 22:17:45 +03:00
|
|
|
local util = dofile_once("mods/quant.ew/files/src/util.lua")
|
2024-05-08 20:33:41 +03:00
|
|
|
local enemy_sync = dofile_once("mods/quant.ew/files/src/enemy_sync.lua")
|
2024-05-10 18:47:01 +03:00
|
|
|
local world_sync = dofile_once("mods/quant.ew/files/src/world_sync.lua")
|
2024-05-07 23:46:15 +03:00
|
|
|
local perk_fns = dofile_once("mods/quant.ew/files/src/perk_fns.lua")
|
2024-05-02 20:24:27 +03:00
|
|
|
|
|
|
|
|
local net_handling = {
|
|
|
|
|
proxy = {},
|
|
|
|
|
mod = {},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function net_handling.proxy.seed(_, value)
|
|
|
|
|
local seed = tonumber(value)
|
|
|
|
|
if seed ~= nil then
|
|
|
|
|
SetWorldSeed(seed)
|
|
|
|
|
SetRandomSeed(seed, 141)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function net_handling.proxy.peer_id(_, value)
|
|
|
|
|
ctx.my_id = tonumber(value)
|
2024-05-10 23:43:32 +03:00
|
|
|
ctx.is_host = ctx.my_id == ctx.host_id
|
2024-05-02 20:24:27 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function net_handling.mod.player(peer_id, value)
|
2024-05-05 23:49:10 +03:00
|
|
|
local input_data = value.i
|
|
|
|
|
local pos_data = value.p
|
|
|
|
|
local slot_data = value.s
|
2024-05-02 20:24:27 +03:00
|
|
|
-- GamePrint("Player update for "..peer_id.." "..pos_data.x.." "..pos_data.y)
|
|
|
|
|
if not player_fns.peer_has_player(peer_id) then
|
|
|
|
|
player_fns.spawn_player_for(peer_id, pos_data.x, pos_data.y)
|
|
|
|
|
end
|
|
|
|
|
local player_data = player_fns.peer_get_player_data(peer_id)
|
2024-05-10 22:17:45 +03:00
|
|
|
if input_data ~= nil then
|
|
|
|
|
player_fns.deserialize_inputs(input_data, player_data)
|
|
|
|
|
end
|
|
|
|
|
if pos_data ~= nil then
|
|
|
|
|
player_fns.deserialize_position(pos_data, player_data)
|
|
|
|
|
end
|
2024-05-05 23:49:10 +03:00
|
|
|
if slot_data ~= nil then
|
|
|
|
|
player_fns.set_current_slot(slot_data, player_data)
|
|
|
|
|
end
|
2024-05-02 20:24:27 +03:00
|
|
|
end
|
|
|
|
|
|
2024-05-03 23:38:40 +03:00
|
|
|
function net_handling.mod.inventory(peer_id, inventory_state)
|
|
|
|
|
if not player_fns.peer_has_player(peer_id) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local player_data = player_fns.peer_get_player_data(peer_id)
|
|
|
|
|
player_fns.deserialize_items(inventory_state, player_data)
|
2024-05-10 20:22:38 +03:00
|
|
|
-- GamePrint("synced inventory")
|
2024-05-07 23:46:15 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function net_handling.mod.perks(peer_id, perk_data)
|
|
|
|
|
if not player_fns.peer_has_player(peer_id) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
local player_data = player_fns.peer_get_player_data(peer_id)
|
|
|
|
|
perk_fns.update_perks(perk_data, player_data)
|
2024-05-03 23:38:40 +03:00
|
|
|
end
|
|
|
|
|
|
2024-05-08 20:33:41 +03:00
|
|
|
function net_handling.mod.enemy(peer_id, enemy_data)
|
|
|
|
|
if peer_id == ctx.host_id then
|
|
|
|
|
enemy_sync.handle_enemy_data(enemy_data)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-10 18:47:01 +03:00
|
|
|
function net_handling.mod.world(peer_id, world_data)
|
|
|
|
|
if peer_id == ctx.host_id then
|
|
|
|
|
world_sync.handle_world_data(world_data)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-10 22:17:45 +03:00
|
|
|
function net_handling.mod.host_player(peer_id, player_infos)
|
|
|
|
|
if peer_id ~= ctx.host_id then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
for id, player_data in pairs(ctx.players) do
|
|
|
|
|
if player_infos[id] ~= nil then
|
|
|
|
|
local info = player_infos[id]
|
|
|
|
|
util.set_ent_health(player_data.entity, {info[1], info[2]})
|
2024-05-10 23:43:32 +03:00
|
|
|
util.set_ent_air(player_data.entity, {info[3], info[4]})
|
2024-05-10 22:17:45 +03:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-02 20:24:27 +03:00
|
|
|
return net_handling
|