mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
WIP inventory sync
This commit is contained in:
parent
2df43137c9
commit
6fccc6bfd6
3 changed files with 1508 additions and 20 deletions
1385
files/lib/EZWand.lua
Normal file
1385
files/lib/EZWand.lua
Normal file
File diff suppressed because it is too large
Load diff
119
files/src/inventory_helper.lua
Normal file
119
files/src/inventory_helper.lua
Normal file
|
@ -0,0 +1,119 @@
|
|||
local inventory_helper = {}
|
||||
|
||||
local function entity_is_wand(entity_id)
|
||||
local ability_component = EntityGetFirstComponentIncludingDisabled(entity_id, "AbilityComponent")
|
||||
if ability_component == nil then return false end
|
||||
return ComponentGetValue2(ability_component, "use_gun_script") == true
|
||||
end
|
||||
|
||||
function inventory_helper.get_inventory_items(player_data, inventory_name)
|
||||
local player = player_data.entity
|
||||
if(not player)then
|
||||
return {}
|
||||
end
|
||||
local inventory = nil
|
||||
|
||||
local player_child_entities = EntityGetAllChildren( player )
|
||||
if ( player_child_entities ~= nil ) then
|
||||
for i,child_entity in ipairs( player_child_entities ) do
|
||||
local child_entity_name = EntityGetName( child_entity )
|
||||
|
||||
if ( child_entity_name == inventory_name ) then
|
||||
inventory = child_entity
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if(inventory == nil)then
|
||||
return {}
|
||||
end
|
||||
|
||||
local items = {}
|
||||
for i, v in ipairs(EntityGetAllChildren(inventory) or {}) do
|
||||
local item_component = EntityGetFirstComponentIncludingDisabled(v, "ItemComponent")
|
||||
if(item_component)then
|
||||
table.insert(items, v)
|
||||
end
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
function inventory_helper.get_item_data(player_data, fresh)
|
||||
fresh = fresh or false
|
||||
|
||||
local player = player_data.entity
|
||||
local inventory2Comp = EntityGetFirstComponentIncludingDisabled(player, "Inventory2Component")
|
||||
local mActiveItem = ComponentGetValue2(inventory2Comp, "mActiveItem")
|
||||
local wandData = {}
|
||||
local spellData = {}
|
||||
for k, item in ipairs(inventory_helper.get_inventory_items(player_data, "inventory_quick") or {}) do
|
||||
local item_comp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent")
|
||||
local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot")
|
||||
local item_x, item_y = EntityGetTransform(item)
|
||||
|
||||
SetRandomSeed(item + slot_x + item_x, slot_y + item_y)
|
||||
|
||||
-- local item_id = entity.GetVariable(item, "arena_entity_id")
|
||||
|
||||
GlobalsSetValue(tostring(item) .. "_item", tostring(k))
|
||||
if(entity_is_wand(item))then
|
||||
local wand = EZWand(item)
|
||||
table.insert(wandData,
|
||||
{
|
||||
data = wand:Serialize(not fresh, not fresh),
|
||||
id = item_id or (item + Random(1, 10000000)),
|
||||
slot_x = slot_x,
|
||||
slot_y = slot_y,
|
||||
active = (mActiveItem == item),
|
||||
is_wand = true
|
||||
})
|
||||
else
|
||||
table.insert(wandData,
|
||||
{
|
||||
data = np.SerializeEntity(item),
|
||||
id = item_id or (item + Random(1, 10000000)),
|
||||
slot_x = slot_x,
|
||||
slot_y = slot_y,
|
||||
active = (mActiveItem == item)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
for k, item in ipairs(inventory_helper.get_inventory_items(player_data, "inventory_full") or {}) do
|
||||
local item_comp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent")
|
||||
local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot")
|
||||
local item_x, item_y = EntityGetTransform(item)
|
||||
|
||||
SetRandomSeed(item + slot_x + item_x, slot_y + item_y)
|
||||
|
||||
-- local item_id = entity.GetVariable(item, "arena_entity_id")
|
||||
|
||||
GlobalsSetValue(tostring(item) .. "_item", tostring(k))
|
||||
if(entity_is_wand(item))then
|
||||
local wand = EZWand(item)
|
||||
table.insert(spellData,
|
||||
{
|
||||
data = wand:Serialize(not fresh, not fresh),
|
||||
-- id = item_id or (item + Random(1, 10000000)),
|
||||
slot_x = slot_x,
|
||||
slot_y = slot_y,
|
||||
active = (mActiveItem == item),
|
||||
is_wand = true
|
||||
})
|
||||
else
|
||||
table.insert(spellData,
|
||||
{
|
||||
data = np.SerializeEntity(item),
|
||||
-- id = item_id or (item + Random(1, 10000000)),
|
||||
slot_x = slot_x,
|
||||
slot_y = slot_y,
|
||||
active = (mActiveItem == item)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return wandData, spellData
|
||||
end
|
||||
|
||||
return inventory_helper
|
|
@ -1,4 +1,5 @@
|
|||
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 ffi = require("ffi")
|
||||
|
||||
|
@ -369,38 +370,21 @@ function player_fns.deserialize_position(message, player_data)
|
|||
EntityApplyTransform(entity, message.x, message.y)
|
||||
end
|
||||
|
||||
|
||||
function player_fns.serialize_items(player_data)
|
||||
local playerEnt = player_data.entity
|
||||
|
||||
local item_data, spell_data = player_helper.GetItemData()
|
||||
local item_data, spell_data = inventory_helper.GetItemData()
|
||||
if(item_data ~= nil)then
|
||||
local data = { item_data, force, GameHasFlagRun( "arena_unlimited_spells" ) }
|
||||
|
||||
|
||||
if (user ~= nil) then
|
||||
table.insert(data, spell_data)
|
||||
steamutils.sendToPlayer("item_update", data, user, true)
|
||||
else
|
||||
if(to_spectators)then
|
||||
table.insert(data, spell_data)
|
||||
steamutils.send("item_update", data, steamutils.messageTypes.Spectators, lobby, true, true)
|
||||
else
|
||||
steamutils.send("item_update", data, steamutils.messageTypes.OtherPlayers, lobby, true, true)
|
||||
end
|
||||
end
|
||||
else
|
||||
if (user ~= nil) then
|
||||
table.insert(data, spell_data)
|
||||
steamutils.sendToPlayer("item_update", {}, user, true)
|
||||
else
|
||||
if(to_spectators)then
|
||||
table.insert(data, spell_data)
|
||||
steamutils.send("item_update", {}, steamutils.messageTypes.Spectators, lobby, true, true)
|
||||
else
|
||||
steamutils.send("item_update", {}, steamutils.messageTypes.OtherPlayers, lobby, true, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function player_fns.peer_has_player(peer_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue