mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Item sync!
This commit is contained in:
parent
488a828a18
commit
c141e40b6b
4 changed files with 34 additions and 1 deletions
|
@ -10,6 +10,7 @@ ctx.init = function()
|
||||||
ctx.entity_by_remote_id = {}
|
ctx.entity_by_remote_id = {}
|
||||||
ctx.run_ended = false
|
ctx.run_ended = false
|
||||||
ctx.player_data_by_local_entity = {}
|
ctx.player_data_by_local_entity = {}
|
||||||
|
ctx.item_prevent_localize = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
return ctx
|
return ctx
|
|
@ -60,6 +60,10 @@ end
|
||||||
|
|
||||||
function item_sync.host_localize_item(gid, peer_id)
|
function item_sync.host_localize_item(gid, peer_id)
|
||||||
-- GamePrint("Localize "..g_id)
|
-- GamePrint("Localize "..g_id)
|
||||||
|
if ctx.item_prevent_localize[gid] then
|
||||||
|
GamePrint("Item localize for "..gid.." prevented")
|
||||||
|
end
|
||||||
|
ctx.item_prevent_localize[gid] = true
|
||||||
if peer_id ~= ctx.my_id then
|
if peer_id ~= ctx.my_id then
|
||||||
item_sync.remove_item_with_id(gid)
|
item_sync.remove_item_with_id(gid)
|
||||||
end
|
end
|
||||||
|
@ -80,6 +84,7 @@ function item_sync.make_item_global(item)
|
||||||
GamePrint(item_sync.get_global_item_id(item))
|
GamePrint(item_sync.get_global_item_id(item))
|
||||||
local item_data = inventory_helper.serialize_single_item(item)
|
local item_data = inventory_helper.serialize_single_item(item)
|
||||||
item_data.g_id = id
|
item_data.g_id = id
|
||||||
|
ctx.item_prevent_localize[id] = false
|
||||||
ctx.lib.net.send_make_global(item_data)
|
ctx.lib.net.send_make_global(item_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -109,6 +114,16 @@ function item_sync.host_upload_items(my_player)
|
||||||
end
|
end
|
||||||
|
|
||||||
function item_sync.client_tick(my_player)
|
function item_sync.client_tick(my_player)
|
||||||
|
if GameGetFrameNum() % 5 == 4 then
|
||||||
|
mark_in_inventory(my_player)
|
||||||
|
end
|
||||||
|
local thrown_item = get_global_ent("ew_thrown")
|
||||||
|
if thrown_item ~= nil then
|
||||||
|
GamePrint("Uploading item")
|
||||||
|
ctx.lib.net.send_item_upload(inventory_helper.serialize_single_item(thrown_item))
|
||||||
|
EntityKill(thrown_item)
|
||||||
|
end
|
||||||
|
|
||||||
local picked_item = get_global_ent("ew_picked")
|
local picked_item = get_global_ent("ew_picked")
|
||||||
if picked_item ~= nil and EntityHasTag(picked_item, "ew_global_item") then
|
if picked_item ~= nil and EntityHasTag(picked_item, "ew_global_item") then
|
||||||
GamePrint("Picked up "..picked_item)
|
GamePrint("Picked up "..picked_item)
|
||||||
|
@ -117,4 +132,11 @@ function item_sync.client_tick(my_player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function item_sync.upload(item_data)
|
||||||
|
local item = inventory_helper.deserialize_single_item(item_data)
|
||||||
|
EntityAddTag(item, "ew_global_item")
|
||||||
|
item_sync.ensure_notify_component(item)
|
||||||
|
item_sync.make_item_global(item)
|
||||||
|
end
|
||||||
|
|
||||||
return item_sync
|
return item_sync
|
|
@ -143,4 +143,8 @@ function net.send_localize_request(item_id)
|
||||||
net.send("item_localize_req", item_id, true)
|
net.send("item_localize_req", item_id, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function net.send_item_upload(item_data)
|
||||||
|
net.send("item_upload", item_data, true)
|
||||||
|
end
|
||||||
|
|
||||||
return net
|
return net
|
|
@ -177,9 +177,15 @@ function net_handling.mod.item_localize_req(peer_id, gid)
|
||||||
if not ctx.is_host then
|
if not ctx.is_host then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- TODO check for race condition from several clients
|
|
||||||
GamePrint("localize req "..peer_id.." gid "..gid)
|
GamePrint("localize req "..peer_id.." gid "..gid)
|
||||||
item_sync.host_localize_item(gid, peer_id)
|
item_sync.host_localize_item(gid, peer_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function net_handling.mod.item_upload(peer_id, item_data)
|
||||||
|
if not ctx.is_host then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
item_sync.upload(item_data)
|
||||||
|
end
|
||||||
|
|
||||||
return net_handling
|
return net_handling
|
Loading…
Add table
Add a link
Reference in a new issue