mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Kinda sync current item? Only works in one direction for some reason
This commit is contained in:
parent
9e8c108b5d
commit
70e6f1efa9
5 changed files with 78 additions and 8 deletions
|
@ -83,10 +83,11 @@ function net.send(key, value, reliable) -- TODO reliability
|
||||||
net.sock:send_binary(encoded_msg)
|
net.sock:send_binary(encoded_msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function net.send_player_update(input_data, pos_data)
|
function net.send_player_update(input_data, pos_data, current_slot)
|
||||||
net.send("player", {
|
net.send("player", {
|
||||||
inp = input_data,
|
i = input_data,
|
||||||
pos = pos_data,
|
p = pos_data,
|
||||||
|
s = current_slot,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,9 @@ function net_handling.proxy.peer_id(_, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function net_handling.mod.player(peer_id, value)
|
function net_handling.mod.player(peer_id, value)
|
||||||
local input_data = value.inp
|
local input_data = value.i
|
||||||
local pos_data = value.pos
|
local pos_data = value.p
|
||||||
|
local slot_data = value.s
|
||||||
-- GamePrint("Player update for "..peer_id.." "..pos_data.x.." "..pos_data.y)
|
-- GamePrint("Player update for "..peer_id.." "..pos_data.x.." "..pos_data.y)
|
||||||
if not player_fns.peer_has_player(peer_id) then
|
if not player_fns.peer_has_player(peer_id) then
|
||||||
player_fns.spawn_player_for(peer_id, pos_data.x, pos_data.y)
|
player_fns.spawn_player_for(peer_id, pos_data.x, pos_data.y)
|
||||||
|
@ -28,6 +29,9 @@ function net_handling.mod.player(peer_id, value)
|
||||||
local player_data = player_fns.peer_get_player_data(peer_id)
|
local player_data = player_fns.peer_get_player_data(peer_id)
|
||||||
player_fns.deserialize_inputs(input_data, player_data)
|
player_fns.deserialize_inputs(input_data, player_data)
|
||||||
player_fns.deserialize_position(pos_data, player_data)
|
player_fns.deserialize_position(pos_data, player_data)
|
||||||
|
if slot_data ~= nil then
|
||||||
|
player_fns.set_current_slot(slot_data, player_data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function net_handling.mod.inventory(peer_id, inventory_state)
|
function net_handling.mod.inventory(peer_id, inventory_state)
|
||||||
|
|
|
@ -2,6 +2,7 @@ local ctx = dofile_once("mods/quant.ew/files/src/ctx.lua")
|
||||||
local inventory_helper = dofile_once("mods/quant.ew/files/src/inventory_helper.lua")
|
local inventory_helper = dofile_once("mods/quant.ew/files/src/inventory_helper.lua")
|
||||||
|
|
||||||
local ffi = require("ffi")
|
local ffi = require("ffi")
|
||||||
|
local np = require("noitapatcher")
|
||||||
|
|
||||||
ffi.cdef([[
|
ffi.cdef([[
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
|
@ -402,5 +403,67 @@ function player_fns.is_inventory_open()
|
||||||
return ComponentGetValue2(inventory_gui_comp, "mActive")
|
return ComponentGetValue2(inventory_gui_comp, "mActive")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_active_held_item(player_entity)
|
||||||
|
local inventory2Comp = EntityGetFirstComponentIncludingDisabled(player_entity, "Inventory2Component")
|
||||||
|
local mActiveItem = ComponentGetValue2(inventory2Comp, "mActiveItem")
|
||||||
|
return mActiveItem
|
||||||
|
end
|
||||||
|
|
||||||
|
function player_fns.get_current_slot(player_data)
|
||||||
|
local held_item = get_active_held_item(player_data.entity)
|
||||||
|
if (held_item ~= nil and held_item ~= 0) then
|
||||||
|
local item_comp = EntityGetFirstComponentIncludingDisabled(held_item, "ItemComponent")
|
||||||
|
|
||||||
|
-- the hell??
|
||||||
|
if(item_comp == nil)then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot")
|
||||||
|
local ability_comp = EntityGetFirstComponentIncludingDisabled(held_item, "AbilityComponent")
|
||||||
|
|
||||||
|
local is_wand = false
|
||||||
|
if(ability_comp and ComponentGetValue2(ability_comp, "use_gun_script"))then
|
||||||
|
is_wand = true
|
||||||
|
end
|
||||||
|
return {is_wand, slot_x, slot_y}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function player_fns.set_current_slot(slot_data, player_data)
|
||||||
|
local is_wand, slot_x, slot_y = slot_data[1], slot_data[2], slot_data[3]
|
||||||
|
-- GamePrint("Switching item to slot: " .. tostring(slot_x) .. ", " .. tostring(slot_y))
|
||||||
|
if (player_data.entity and EntityGetIsAlive(player_data.entity)) then
|
||||||
|
local items = GameGetAllInventoryItems(player_data.entity) or {}
|
||||||
|
for i, item in ipairs(items) do
|
||||||
|
-- check id
|
||||||
|
local itemComp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent")
|
||||||
|
if itemComp ~= nil then
|
||||||
|
local item_slot_x, item_slot_y = ComponentGetValue2(itemComp, "inventory_slot")
|
||||||
|
|
||||||
|
local ability_comp = EntityGetFirstComponentIncludingDisabled(item, "AbilityComponent")
|
||||||
|
|
||||||
|
local item_is_wand = false
|
||||||
|
if(ability_comp and ComponentGetValue2(ability_comp, "use_gun_script"))then
|
||||||
|
item_is_wand = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if (item_slot_x == slot_x and item_slot_y == slot_y and item_is_wand == is_wand) then
|
||||||
|
local inventory2Comp = EntityGetFirstComponentIncludingDisabled(
|
||||||
|
player_data.entity, "Inventory2Component")
|
||||||
|
local mActiveItem = ComponentGetValue2(inventory2Comp, "mActiveItem")
|
||||||
|
|
||||||
|
if (mActiveItem ~= item) then
|
||||||
|
np.SetActiveHeldEntity(player_data.entity, item, false, false)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print("something in inventory that is not an item")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
print("Players initialized")
|
print("Players initialized")
|
||||||
return player_fns
|
return player_fns
|
3
init.lua
3
init.lua
|
@ -86,7 +86,8 @@ function OnWorldPreUpdate() -- This is called every time the game is about to st
|
||||||
if GameGetFrameNum() % 2 == 0 then
|
if GameGetFrameNum() % 2 == 0 then
|
||||||
local input_data = player_fns.serialize_inputs(my_player)
|
local input_data = player_fns.serialize_inputs(my_player)
|
||||||
local pos_data = player_fns.serialize_position(my_player)
|
local pos_data = player_fns.serialize_position(my_player)
|
||||||
net.send_player_update(input_data, pos_data)
|
local current_slot = player_fns.get_current_slot(my_player)
|
||||||
|
net.send_player_update(input_data, pos_data, current_slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
if GameGetFrameNum() % 120 == 0 then
|
if GameGetFrameNum() % 120 == 0 then
|
||||||
|
|
5
todo.txt
5
todo.txt
|
@ -8,7 +8,8 @@
|
||||||
- Синхронизация противников
|
- Синхронизация противников
|
||||||
- Перекидывание предметов
|
- Перекидывание предметов
|
||||||
- Синхронизация мира
|
- Синхронизация мира
|
||||||
- Фикс наведения на клиентов
|
? Фикс наведения на клиентов
|
||||||
- Проверка окончания игры
|
- Проверка окончания игры
|
||||||
- Удаление лишних клиентов при загрузке игры
|
- Удаление лишних клиентов при загрузке игры
|
||||||
- Синхронизация противников
|
- fungal shift-ы
|
||||||
|
- test tangled better
|
Loading…
Add table
Add a link
Reference in a new issue