mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 15:13:16 +00:00
- Fix bugs/inconsistencies related to spectator shields.
This commit is contained in:
parent
491f29948a
commit
b51e4db750
3 changed files with 57 additions and 22 deletions
|
@ -9,4 +9,5 @@
|
|||
- `ctx.hook.on_client_spawned(peer_id, new_playerdata)`
|
||||
- `ctx.hook.on_should_send_updates()` - called either when we connect, or somebody else connects (and sends "welcome" message)
|
||||
- `ctx.hook.on_draw_debug_window(imgui)`
|
||||
|
||||
- `ctx.hook.on_local_player_polymorphed(currently_polymorphed)`
|
||||
- `ctx.hook.on_client_polymorphed(peer_id, player_data)`
|
||||
|
|
|
@ -22,6 +22,7 @@ local function entity_changed()
|
|||
rpc.change_entity(nil)
|
||||
wandfinder.set_wands_after_poly()
|
||||
end
|
||||
ctx.hook.on_local_player_polymorphed(currently_polymorphed)
|
||||
end
|
||||
|
||||
function module.on_local_player_spawn()
|
||||
|
@ -131,6 +132,7 @@ function rpc.change_entity(seri_ent)
|
|||
EntityKill(ctx.rpc_player_data.entity)
|
||||
player_fns.replace_player_entity(ent, ctx.rpc_player_data)
|
||||
ctx.rpc_player_data.currently_polymorphed = true
|
||||
ctx.hook.on_client_polymorphed(ctx.rpc_peer_id, ctx.rpc_player_data)
|
||||
else
|
||||
if ctx.rpc_player_data.currently_polymorphed then
|
||||
EntityKill(ctx.rpc_player_data.entity)
|
||||
|
|
|
@ -2,24 +2,14 @@ local rpc = net.new_rpc_namespace()
|
|||
|
||||
local shield_entities = {}
|
||||
|
||||
local function create_shield_for(spectator_peer_id, target_entity)
|
||||
local ent = EntityLoad("mods/quant.ew/files/system/spectator_helps/shield_base.xml")
|
||||
EntityAddChild(target_entity, ent)
|
||||
shield_entities[spectator_peer_id] = ent
|
||||
|
||||
-- EntityAddComponent2(ent, "EnergyShieldComponent", {})
|
||||
local function delete_shields()
|
||||
for _, child in ipairs(EntityGetAllChildren(ctx.my_player.entity) or {}) do
|
||||
if EntityGetName(child) == "spectator_shield" then
|
||||
EntityKill(child)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local spectating_which = rpc:create_var("spectating_which", function(new_value)
|
||||
if shield_entities[ctx.rpc_peer_id] ~= nil then
|
||||
EntityKill(shield_entities[ctx.rpc_peer_id])
|
||||
shield_entities[ctx.rpc_peer_id] = nil
|
||||
end
|
||||
if ctx.rpc_peer_id ~= new_value and new_value ~= nil then
|
||||
create_shield_for(ctx.rpc_peer_id, player_fns.peer_get_player_data(new_value).entity)
|
||||
end
|
||||
end)
|
||||
|
||||
local shield_angle = rpc:create_var("shield_angle", function(new_value)
|
||||
local shield_ent = shield_entities[ctx.rpc_peer_id]
|
||||
if shield_ent ~= nil then
|
||||
|
@ -28,6 +18,39 @@ local shield_angle = rpc:create_var("shield_angle", function(new_value)
|
|||
end
|
||||
end)
|
||||
|
||||
local function create_shield_for(spectator_peer_id, target_entity)
|
||||
local ent = EntityLoad("mods/quant.ew/files/system/spectator_helps/shield_base.xml")
|
||||
EntityAddChild(target_entity, ent)
|
||||
shield_entities[spectator_peer_id] = ent
|
||||
if shield_angle.values[spectator_peer_id] ~= nil then
|
||||
local x, y = EntityGetTransform(ent)
|
||||
EntitySetTransform(ent, x, y, shield_angle.values[spectator_peer_id])
|
||||
end
|
||||
end
|
||||
|
||||
local function maybe_clean_existing_shield(spectator_peer_id)
|
||||
if shield_entities[spectator_peer_id] ~= nil then
|
||||
EntityKill(shield_entities[spectator_peer_id])
|
||||
shield_entities[spectator_peer_id] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local spectating_which = rpc:create_var("spectating_which", function(new_value)
|
||||
maybe_clean_existing_shield(ctx.rpc_peer_id)
|
||||
if ctx.rpc_peer_id ~= new_value and new_value ~= nil then
|
||||
create_shield_for(ctx.rpc_peer_id, player_fns.peer_get_player_data(new_value).entity)
|
||||
end
|
||||
end)
|
||||
|
||||
local function recreate_shields_of(updated_peer_id)
|
||||
for peer_id, target_peer_id in pairs(spectating_which.values) do
|
||||
if target_peer_id == updated_peer_id then
|
||||
maybe_clean_existing_shield(peer_id)
|
||||
create_shield_for(peer_id, player_fns.peer_get_player_data(target_peer_id).entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local module = {}
|
||||
|
||||
local function is_acceptable_help_target(spectating_over)
|
||||
|
@ -43,6 +66,11 @@ local function is_acceptable_help_target(spectating_over)
|
|||
return true
|
||||
end
|
||||
|
||||
function module.on_local_player_polymorphed(_currently_polymorphed)
|
||||
delete_shields()
|
||||
recreate_shields_of(ctx.my_id)
|
||||
end
|
||||
|
||||
function module.on_world_update()
|
||||
local notplayer_active = GameHasFlagRun("ew_flag_notplayer_active")
|
||||
if notplayer_active and ctx.spectating_over_peer_id ~= nil and is_acceptable_help_target(ctx.spectating_over_peer_id) then
|
||||
|
@ -61,11 +89,15 @@ end
|
|||
|
||||
function module.on_local_player_spawn()
|
||||
-- Cleanup after restarts
|
||||
for _, child in ipairs(EntityGetAllChildren(ctx.my_player.entity) or {}) do
|
||||
if EntityGetName(child) == "spectator_shield" then
|
||||
EntityKill(child)
|
||||
end
|
||||
end
|
||||
delete_shields()
|
||||
end
|
||||
|
||||
function module.on_client_polymorphed(peer_id, _player_data)
|
||||
recreate_shields_of(peer_id)
|
||||
end
|
||||
|
||||
function module.on_client_spawned(peer_id, _new_playerdata)
|
||||
recreate_shields_of(peer_id)
|
||||
end
|
||||
|
||||
return module
|
Loading…
Add table
Add a link
Reference in a new issue