mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Sync at least some physycs stuff.
This commit is contained in:
parent
4b3b6543f7
commit
8d6e770e0b
4 changed files with 39 additions and 4 deletions
10
quant.ew/files/core/constants.lua
Normal file
10
quant.ew/files/core/constants.lua
Normal file
|
@ -0,0 +1,10 @@
|
|||
local module = {}
|
||||
|
||||
module.phys_sync_allowed = {
|
||||
["data/entities/props/physics_propane_tank.xml"] = true,
|
||||
["data/entities/props/physics_box_explosive.xml"] = true,
|
||||
["data/entities/props/physics_crate.xml.xml"] = true,
|
||||
["data/entities/props/physics_barrel_radioactive.xml"] = true,
|
||||
}
|
||||
|
||||
return module
|
|
@ -50,6 +50,10 @@ local function get_sync_entities()
|
|||
return not (EntityHasTag(ent, "ew_no_enemy_sync"))
|
||||
end)
|
||||
table_extend(entities, EntityGetWithTag("ew_enemy_sync_extra"))
|
||||
table_extend_filtered(entities, EntityGetWithTag("prop_physics"), function (ent)
|
||||
return constants.phys_sync_allowed[EntityGetFilename(ent)]
|
||||
end)
|
||||
|
||||
-- table_extend_filtered(entities, EntityGetWithTag("projectile"), function (ent)
|
||||
-- return not (EntityHasTag(ent, "ew_no_enemy_sync") or EntityHasTag(ent, "projectile_player"))
|
||||
-- end)
|
||||
|
@ -76,6 +80,16 @@ function enemy_sync.host_upload_entities()
|
|||
end
|
||||
local hp, max_hp, has_hp = util.get_ent_health(enemy_id)
|
||||
|
||||
local phys_info = nil
|
||||
|
||||
local phys_component = EntityGetFirstComponent(enemy_id, "PhysicsBody2Component")
|
||||
if phys_component ~= nil and phys_component ~= 0 then
|
||||
local initialized = ComponentGetValue2(phys_component, "mInitialized")
|
||||
if initialized then
|
||||
phys_info = {np.PhysBodyGetTransform(phys_component)}
|
||||
end
|
||||
end
|
||||
|
||||
if has_hp then
|
||||
util.ensure_component_present(enemy_id, "LuaComponent", "ew_death_notify", {
|
||||
script_death = "mods/quant.ew/files/resource/cbs/death_notify.lua"
|
||||
|
@ -89,7 +103,7 @@ function enemy_sync.host_upload_entities()
|
|||
-- -- local x, y, r =
|
||||
-- end
|
||||
|
||||
table.insert(enemy_data_list, {enemy_id, filename, x, y, vx, vy, hp, max_hp})
|
||||
table.insert(enemy_data_list, {enemy_id, filename, x, y, vx, vy, hp, max_hp, phys_info})
|
||||
::continue::
|
||||
end
|
||||
|
||||
|
@ -188,6 +202,7 @@ function rpc.handle_enemy_data(enemy_data)
|
|||
local vy = enemy_info_raw[6]
|
||||
local hp = enemy_info_raw[7]
|
||||
local max_hp = enemy_info_raw[8]
|
||||
local phys_info = enemy_info_raw[9]
|
||||
local has_died = filename == nil
|
||||
|
||||
local frame = GameGetFrameNum()
|
||||
|
@ -225,6 +240,15 @@ function rpc.handle_enemy_data(enemy_data)
|
|||
enemy_data.frame = frame
|
||||
local enemy_id = enemy_data.id
|
||||
|
||||
local phys_component = EntityGetFirstComponent(enemy_id, "PhysicsBody2Component")
|
||||
if phys_component ~= nil and phys_component ~= 0 and phys_info ~= nil then
|
||||
-- A physics body doesn't exist otherwise, causing a crash
|
||||
local initialized = ComponentGetValue2(phys_component, "mInitialized")
|
||||
if initialized then
|
||||
np.PhysBodySetTransform(phys_component, unpack(phys_info))
|
||||
end
|
||||
end
|
||||
|
||||
if not has_died then
|
||||
local character_data = EntityGetFirstComponentIncludingDisabled(enemy_id, "CharacterDataComponent")
|
||||
if character_data ~= nil then
|
||||
|
|
|
@ -48,7 +48,7 @@ np.CrossCallAdd("ew_spawn_hook_pre", function(ent_path, x, y)
|
|||
if is_sync_item(ent_path) then
|
||||
return false
|
||||
else
|
||||
return not module.entity_is_enemy(ent_path)
|
||||
return not module.entity_is_synced(ent_path)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -61,7 +61,7 @@ end)
|
|||
|
||||
local entity_is_enemy_cache = {}
|
||||
|
||||
function module.entity_is_enemy(ent_path)
|
||||
function module.entity_is_synced(ent_path)
|
||||
if entity_is_enemy_cache[ent_path] ~= nil then
|
||||
return entity_is_enemy_cache[ent_path]
|
||||
end
|
||||
|
@ -69,7 +69,7 @@ function module.entity_is_enemy(ent_path)
|
|||
print("Checking if this is an enemy: "..ent_path)
|
||||
|
||||
local ent = EntityLoad(ent_path) -- TODO: Just read xml maybe
|
||||
local res = EntityHasTag(ent, "enemy")
|
||||
local res = EntityHasTag(ent, "enemy") or constants.phys_sync_allowed[ent_path]
|
||||
EntityKill(ent)
|
||||
|
||||
entity_is_enemy_cache[ent_path] = res
|
||||
|
|
|
@ -14,6 +14,7 @@ player_fns = dofile_once("mods/quant.ew/files/core/player_fns.lua")
|
|||
net = dofile_once("mods/quant.ew/files/core/net.lua")
|
||||
util = dofile_once("mods/quant.ew/files/core/util.lua")
|
||||
inventory_helper = dofile_once("mods/quant.ew/files/core/inventory_helper.lua")
|
||||
constants = dofile_once("mods/quant.ew/files/core/constants.lua")
|
||||
|
||||
local pretty = dofile_once("mods/quant.ew/files/lib/pretty_print.lua")
|
||||
local perk_fns = dofile_once("mods/quant.ew/files/core/perk_fns.lua")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue