mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
fix shops, fix enemys with wands maybe, fix some more item dupes, dont tether between PW since everyone should be able to get there
This commit is contained in:
parent
161e71fefc
commit
9b87a6cba5
3 changed files with 62 additions and 16 deletions
|
@ -49,6 +49,10 @@ local HpData = util.make_type({
|
|||
f32 = {"hp", "max_hp"}
|
||||
})
|
||||
|
||||
local should_wait = {}
|
||||
|
||||
local first = true
|
||||
|
||||
local FULL_TURN = math.pi * 2
|
||||
|
||||
local frame = 0
|
||||
|
@ -268,6 +272,9 @@ function enemy_sync.host_upload_entities()
|
|||
item_sync.make_item_global(item)
|
||||
else
|
||||
wand = item_sync.get_global_item_id(item)
|
||||
if not item_sync.is_my_item(wand) then
|
||||
EntityAddTag(item, "ew_client_item")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -290,7 +297,8 @@ function enemy_sync.host_upload_entities()
|
|||
::continue::
|
||||
end
|
||||
|
||||
rpc.handle_enemy_data(enemy_data_list)
|
||||
rpc.handle_enemy_data(enemy_data_list, first)
|
||||
first = false
|
||||
if #dead_entities > 0 then
|
||||
rpc.handle_death_data(dead_entities)
|
||||
end
|
||||
|
@ -576,7 +584,9 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
|
|||
if gid ~= nil and (item == nil or item == 0 or not EntityGetIsAlive(item)) then
|
||||
local wand = item_sync.find_by_gid(gid)
|
||||
if wand ~= nil then
|
||||
EntityAddTag(wand, "ew_client_item")
|
||||
if not item_sync.is_my_item(gid) then
|
||||
EntityAddTag(wand, "ew_client_item")
|
||||
end
|
||||
local found = false
|
||||
for _, child in ipairs(EntityGetAllChildren(enemy_id) or {}) do
|
||||
if EntityGetName(child) == "inventory_quick" then
|
||||
|
@ -601,7 +611,10 @@ local function sync_enemy(enemy_info_raw, force_no_cull)
|
|||
EntitySetComponentsWithTagEnabled(wand, "enabled_in_inventory", false)
|
||||
np.SetActiveHeldEntity(enemy_id, wand, false, false)
|
||||
else
|
||||
item_sync.rpc.request_send_again(gid)
|
||||
if should_wait[gid] == nil or should_wait[gid] < GameGetFrameNum() then
|
||||
item_sync.rpc.request_send_again(gid)
|
||||
should_wait[gid] = GameGetFrameNum() + 15
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -671,7 +684,10 @@ function rpc.handle_death_data(death_data)
|
|||
end
|
||||
end
|
||||
|
||||
function rpc.handle_enemy_data(enemy_data)
|
||||
function rpc.handle_enemy_data(enemy_data, first)
|
||||
if first then
|
||||
ctx.entity_by_remote_id = {}
|
||||
end
|
||||
frame = GameGetFrameNum()
|
||||
for _, enemy_info_raw in ipairs(enemy_data) do
|
||||
sync_enemy(enemy_info_raw, false)
|
||||
|
|
|
@ -61,7 +61,10 @@ util.add_cross_call("ew_item_death_notify", function(enemy_id, responsible_id)
|
|||
else
|
||||
responsible = responsible_id
|
||||
end
|
||||
table.insert(dead_entities, {item_sync.get_global_item_id(enemy_id), responsible})
|
||||
local gid = item_sync.get_global_item_id(enemy_id)
|
||||
if gid ~= nil then
|
||||
table.insert(dead_entities, {gid, responsible})
|
||||
end
|
||||
end)
|
||||
|
||||
function item_sync.ensure_notify_component(ent)
|
||||
|
@ -125,12 +128,14 @@ function item_sync.find_by_gid(gid)
|
|||
local candidate
|
||||
for _, item in ipairs(EntityGetWithTag("ew_global_item") or {}) do
|
||||
local i_gid = item_sync.get_global_item_id(item)
|
||||
find_by_gid_cache[i_gid] = item
|
||||
if i_gid == gid then
|
||||
if is_item_on_ground(item) then
|
||||
return item
|
||||
else
|
||||
candidate = item
|
||||
if i_gid ~= nil then
|
||||
find_by_gid_cache[i_gid] = item
|
||||
if i_gid == gid then
|
||||
if is_item_on_ground(item) then
|
||||
return item
|
||||
else
|
||||
candidate = item
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -260,6 +265,10 @@ local function is_my_item(gid)
|
|||
return string.sub(gid, 1, 16) == ctx.my_id
|
||||
end
|
||||
|
||||
function item_sync.is_my_item(gid)
|
||||
is_my_item(gid)
|
||||
end
|
||||
|
||||
function item_sync.take_authority(gid)
|
||||
if not is_my_item(gid) then
|
||||
local new_id = allocate_global_id()
|
||||
|
@ -272,6 +281,15 @@ rpc.opts_reliable()
|
|||
function rpc.give_authority_to(gid, new_id)
|
||||
local item = item_sync.find_by_gid(gid)
|
||||
find_by_gid_cache[gid] = nil
|
||||
if table.contains(pending_remove, gid) then
|
||||
for i, id in ipairs(pending_remove) do
|
||||
if id == gid then
|
||||
table.remove(pending_remove, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
table.insert(pending_remove, new_id)
|
||||
end
|
||||
if item ~= nil then
|
||||
find_by_gid_cache[new_id] = item
|
||||
local var = EntityGetFirstComponentIncludingDisabled(item, "VariableStorageComponent", "ew_global_item_id")
|
||||
|
@ -424,7 +442,9 @@ function item_sync.on_world_update_host()
|
|||
local picked_item = get_global_ent("ew_picked")
|
||||
if picked_item ~= nil and EntityHasTag(picked_item, "ew_global_item") then
|
||||
local gid = item_sync.get_global_item_id(picked_item)
|
||||
item_sync.host_localize_item(gid, ctx.my_id)
|
||||
if gid ~= nil then
|
||||
item_sync.host_localize_item(gid, ctx.my_id)
|
||||
end
|
||||
end
|
||||
remove_client_items_from_world()
|
||||
end
|
||||
|
@ -435,14 +455,16 @@ function item_sync.on_world_update_client()
|
|||
mark_in_inventory(my_player)
|
||||
end
|
||||
local thrown_item = get_global_ent("ew_thrown")
|
||||
if thrown_item ~= nil then
|
||||
if thrown_item ~= nil and is_my_item(item_sync.get_global_item_id(thrown_item)) then
|
||||
item_sync.make_item_global(thrown_item)
|
||||
end
|
||||
|
||||
local picked_item = get_global_ent("ew_picked")
|
||||
if picked_item ~= nil and EntityHasTag(picked_item, "ew_global_item") then
|
||||
local gid = item_sync.get_global_item_id(picked_item)
|
||||
rpc.item_localize_req(gid)
|
||||
if gid ~= nil then
|
||||
rpc.item_localize_req(gid)
|
||||
end
|
||||
end
|
||||
remove_client_items_from_world()
|
||||
end
|
||||
|
@ -495,8 +517,10 @@ function item_sync.on_should_send_updates()
|
|||
if is_item_on_ground(item) and not EntityHasTag(item, "mimic_potion") then
|
||||
local item_data = inventory_helper.serialize_single_item(item)
|
||||
local gid = item_sync.get_global_item_id(item)
|
||||
item_data.gid = gid
|
||||
table.insert(item_list, item_data)
|
||||
if gid ~= nil then
|
||||
item_data.gid = gid
|
||||
table.insert(item_list, item_data)
|
||||
end
|
||||
end
|
||||
end
|
||||
rpc.initial_items(item_list)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
dofile_once("data/scripts/lib/utilities.lua")
|
||||
local ctx = dofile_once("mods/quant.ew/files/core/ctx.lua")
|
||||
local player_fns = dofile_once("mods/quant.ew/files/core/player_fns.lua")
|
||||
local rpc = net.new_rpc_namespace()
|
||||
|
@ -252,6 +253,11 @@ function module.on_world_update()
|
|||
end
|
||||
return
|
||||
end
|
||||
local host_pw = check_parallel_pos(x1)
|
||||
local my_pw = check_parallel_pos(x2)
|
||||
if host_pw ~= my_pw then
|
||||
return
|
||||
end
|
||||
local dx = x1-x2
|
||||
local dy = y1-y2
|
||||
local dist_sq = dx*dx + dy*dy
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue