mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
Fix spellstate desync if a certain trick is used.
This commit is contained in:
parent
a8da17a520
commit
5ec82e2102
2 changed files with 34 additions and 7 deletions
|
@ -65,11 +65,29 @@ function net_handling.mod.perks(peer_id, perk_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function reset_cast_state_if_has_any_other_item(player_data)
|
||||||
|
local inventory2Comp = EntityGetFirstComponentIncludingDisabled(player_data.entity, "Inventory2Component")
|
||||||
|
local mActiveItem = ComponentGetValue2(inventory2Comp, "mActiveItem")
|
||||||
|
|
||||||
|
for k, item in ipairs(inventory_helper.get_inventory_items(player_data, "inventory_quick") or {}) do
|
||||||
|
if item ~= mActiveItem then
|
||||||
|
np.SetActiveHeldEntity(player_data.entity, item)
|
||||||
|
np.SetActiveHeldEntity(player_data.entity, mActiveItem)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function net_handling.mod.fire(peer_id, fire_data)
|
function net_handling.mod.fire(peer_id, fire_data)
|
||||||
local rng = fire_data[1]
|
local rng = fire_data[1]
|
||||||
local message = fire_data[2]
|
local message = fire_data[2]
|
||||||
local player_data = player_fns.peer_get_player_data(peer_id)
|
local player_data = player_fns.peer_get_player_data(peer_id)
|
||||||
local entity = player_data.entity
|
local entity = player_data.entity
|
||||||
|
|
||||||
|
local switched_now = fire_data.switched_now == true
|
||||||
|
if switched_now then
|
||||||
|
reset_cast_state_if_has_any_other_item(player_data)
|
||||||
|
end
|
||||||
|
|
||||||
GlobalsSetValue("ew_shooter_rng_" .. tostring(peer_id), tostring(message.special_seed))
|
GlobalsSetValue("ew_shooter_rng_" .. tostring(peer_id), tostring(message.special_seed))
|
||||||
|
|
||||||
|
|
|
@ -191,11 +191,15 @@ local function on_world_pre_update_inner()
|
||||||
end
|
end
|
||||||
|
|
||||||
if ctx.events.new_player_just_connected or ctx.events.inventory_maybe_just_changed or (GameGetFrameNum() % 5 == 0 and inventory_helper.has_inventory_changed(ctx.my_player)) then
|
if ctx.events.new_player_just_connected or ctx.events.inventory_maybe_just_changed or (GameGetFrameNum() % 5 == 0 and inventory_helper.has_inventory_changed(ctx.my_player)) then
|
||||||
local inventory_state = player_fns.serialize_items(ctx.my_player)
|
async(function()
|
||||||
if inventory_state ~= nil then
|
-- Wait 1 frame because apperently it takes some time for an item to get properly "registered" in an inventory?
|
||||||
-- GamePrint("Sending updated inventory")
|
wait(1)
|
||||||
net.send_player_inventory(inventory_state)
|
local inventory_state = player_fns.serialize_items(ctx.my_player)
|
||||||
end
|
if inventory_state ~= nil then
|
||||||
|
-- GamePrint("Sending updated inventory")
|
||||||
|
net.send_player_inventory(inventory_state)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Perk sync
|
-- Perk sync
|
||||||
|
@ -225,8 +229,6 @@ end
|
||||||
local function on_world_post_update_inner()
|
local function on_world_post_update_inner()
|
||||||
if ctx.my_player == nil then return end
|
if ctx.my_player == nil then return end
|
||||||
|
|
||||||
-- local px, py = EntityGetTransform(my_player.entity)
|
|
||||||
-- GameSetCameraPos(px, py)
|
|
||||||
if not ctx.run_ended then
|
if not ctx.run_ended then
|
||||||
ctx.hook.on_world_update_post()
|
ctx.hook.on_world_update_post()
|
||||||
end
|
end
|
||||||
|
@ -234,9 +236,16 @@ local function on_world_post_update_inner()
|
||||||
local times_wand_fired = tonumber(GlobalsGetValue("ew_wand_fired", "0"))
|
local times_wand_fired = tonumber(GlobalsGetValue("ew_wand_fired", "0"))
|
||||||
GlobalsSetValue("ew_wand_fired", "0")
|
GlobalsSetValue("ew_wand_fired", "0")
|
||||||
if times_wand_fired > 0 then
|
if times_wand_fired > 0 then
|
||||||
|
local inventory_component = EntityGetFirstComponentIncludingDisabled(ctx.my_player.entity, "Inventory2Component")
|
||||||
|
local last_switch = ComponentGetValue2(inventory_component, "mLastItemSwitchFrame")
|
||||||
|
local switched_now = last_switch == GameGetFrameNum()
|
||||||
|
|
||||||
local special_seed = tonumber(GlobalsGetValue("ew_player_rng", "0"))
|
local special_seed = tonumber(GlobalsGetValue("ew_player_rng", "0"))
|
||||||
local fire_data = player_fns.make_fire_data(special_seed, ctx.my_player)
|
local fire_data = player_fns.make_fire_data(special_seed, ctx.my_player)
|
||||||
if fire_data ~= nil then
|
if fire_data ~= nil then
|
||||||
|
if switched_now then
|
||||||
|
fire_data.switched_now = true
|
||||||
|
end
|
||||||
net.send_fire(fire_data)
|
net.send_fire(fire_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue