fix some errors, fix potion mimic on reconnects

This commit is contained in:
bgkillas 2024-11-16 23:07:10 -05:00
parent 3efee1293b
commit 93eb43bd60
3 changed files with 46 additions and 13 deletions

View file

@ -230,14 +230,17 @@ function inventory_helper.get_item_data(player_data, fresh)
active = (mActiveItem == item) active = (mActiveItem == item)
}) })
else else
local peer_id = player_fns.get_player_data_by_local_entity_id(item).peer_id local data = player_fns.get_player_data_by_local_entity_id(item)
table.insert(wandData, if data ~= nil then
{ local peer_id = data.peer_id
peer_id = peer_id, table.insert(wandData,
slot_x = slot_x, {
slot_y = slot_y, peer_id = peer_id,
active = (mActiveItem == item) slot_x = slot_x,
}) slot_y = slot_y,
active = (mActiveItem == item)
})
end
end end
end end
@ -289,6 +292,7 @@ local function pickup_item(entity, item)
EntityRemoveFromParent(item) EntityRemoveFromParent(item)
end end
EntityAddChild( child, item) EntityAddChild( child, item)
break
end end
end end
end end
@ -424,8 +428,10 @@ function inventory_helper.has_inventory_changed(player_data)
end end
for _, item in ipairs(GameGetAllInventoryItems(player_data.entity) or {}) do for _, item in ipairs(GameGetAllInventoryItems(player_data.entity) or {}) do
local item_comp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent") local item_comp = EntityGetFirstComponentIncludingDisabled(item, "ItemComponent")
local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot") if item_comp ~= nil then
inventory_hash = (inventory_hash*19 + (item % 65000 + slot_x + slot_y)) % (math.pow(2, 20) - 1) local slot_x, slot_y = ComponentGetValue2(item_comp, "inventory_slot")
inventory_hash = (inventory_hash*19 + (item % 65000 + slot_x + slot_y)) % (math.pow(2, 20) - 1)
end
end end
player_data.prev_inventory_hash = inventory_hash player_data.prev_inventory_hash = inventory_hash
return inventory_hash ~= prev_inventory return inventory_hash ~= prev_inventory

View file

@ -274,7 +274,7 @@ function enemy_sync.host_upload_entities()
} }
elseif EntityHasTag(enemy_id, "boss_wizard") then elseif EntityHasTag(enemy_id, "boss_wizard") then
local orbs = {false, false, false, false, false, false, false, false} local orbs = {false, false, false, false, false, false, false, false}
for _, child in pairs(EntityGetAllChildren(enemy_id) or {}) do for _, child in ipairs(EntityGetAllChildren(enemy_id) or {}) do
local var = EntityGetFirstComponentIncludingDisabled(child, "VariableStorageComponent") local var = EntityGetFirstComponentIncludingDisabled(child, "VariableStorageComponent")
if EntityHasTag(child, "touchmagic_immunity") and var ~= nil then if EntityHasTag(child, "touchmagic_immunity") and var ~= nil then
local n = ComponentGetValue2(var, "value_int") local n = ComponentGetValue2(var, "value_int")
@ -627,7 +627,7 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
end end
if ffi.typeof(en_data) == EnemyDataMom then if ffi.typeof(en_data) == EnemyDataMom then
local orbs = en_data.orbs local orbs = en_data.orbs
for _, child in pairs(EntityGetAllChildren(enemy_id) or {}) do for _, child in ipairs(EntityGetAllChildren(enemy_id) or {}) do
local var = EntityGetFirstComponentIncludingDisabled(child, "VariableStorageComponent") local var = EntityGetFirstComponentIncludingDisabled(child, "VariableStorageComponent")
local damage_component = EntityGetFirstComponentIncludingDisabled(child, "DamageModelComponent") local damage_component = EntityGetFirstComponentIncludingDisabled(child, "DamageModelComponent")
if EntityHasTag(child, "touchmagic_immunity") and var ~= nil then if EntityHasTag(child, "touchmagic_immunity") and var ~= nil then

View file

@ -33,6 +33,29 @@ np.CrossCallAdd("ew_potion_mimic_pickup", function()
end end
end) end)
function rpc.ensure_held(peer_id)
if peer_id == ctx.my_player.peer_id then
local ent = ctx.my_player.entity
local inv
for _, child in ipairs(EntityGetAllChildren(ent) or {}) do
if EntityGetName( child ) == "inventory_quick" then
inv = child
break
end
end
local has_player = false
for _, child in ipairs(EntityGetAllChildren(inv) or {}) do
local player = player_fns.get_player_data_by_local_entity_id(child)
if player ~= nil and player.peer_id == ctx.rpc_player_data.peer_id then
has_player = true
end
end
if not has_player then
EntityAddChild(inv, ctx.rpc_player_data.entity)
end
end
end
function potion.on_world_update() function potion.on_world_update()
if EntityHasTag(ctx.my_player.entity, "mimic_potion") then if EntityHasTag(ctx.my_player.entity, "mimic_potion") then
local effect local effect
@ -47,8 +70,12 @@ function potion.on_world_update()
end end
end end
end end
local root = EntityGetRootEntity(ctx.my_player.entity)
if effect ~= nil then if effect ~= nil then
EntitySetComponentIsEnabled(ctx.my_player.entity, effect, EntityGetParent(ctx.my_player.entity) == 0) EntitySetComponentIsEnabled(ctx.my_player.entity, effect, root == ctx.my_player.entity)
end
if GameGetFrameNum() % 60 == 53 and root ~= ctx.my_player.entity then
rpc.ensure_held(player_fns.get_player_data_by_local_entity_id(root).peer_id)
end end
end end
--if InputIsKeyJustDown(16) then --when "m" is pressed --if InputIsKeyJustDown(16) then --when "m" is pressed