make broken wand consistent

This commit is contained in:
bgkillas 2025-02-19 17:37:37 -05:00
parent e6db6e0d33
commit db8c2aacaf
7 changed files with 167 additions and 39 deletions

View file

@ -668,8 +668,30 @@ pub unsafe extern "C" fn luaopen_ewext1(lua: *mut lua_State) -> c_int {
Ok(())
})?
}
add_lua_fn!(des_chest_opened);
fn des_broken_wand(lua: LuaState) -> eyre::Result<()> {
ExtState::with_global(|state| {
let x = lua.to_string(1)?.parse::<f64>()?;
let y = lua.to_string(2)?.parse::<f64>()?;
let mut temp = try_lock_netmanager()?;
let net = temp.as_mut().ok_or_eyre("Netmanager not available")?;
for peer in state.player_entity_map.left_values() {
if *peer != my_peer_id() {
net.send(&NoitaOutbound::RemoteMessage {
reliable: true,
destination: Destination::Peer(*peer),
message: shared::RemoteMessage::RemoteDes(RemoteDes::SpawnOnce(
WorldPos::from_f64(x, y),
SpawnOnce::BrokenWand,
)),
})?;
}
}
Ok(())
})?
}
add_lua_fn!(des_broken_wand);
}
println!("Initializing ewext - Ok");
1

View file

@ -209,6 +209,15 @@ impl EntitySync {
}
}
}
shared::SpawnOnce::BrokenWand => {
if let Some(ent) = noita_api::raw::entity_create_new(None)? {
ent.set_position(x as f32, y as f32, None)?;
ent.add_tag("broken_wand")?;
ent.add_lua_init_component::<LuaComponent>(
"data/scripts/buildings/forge_item_convert.lua",
)?;
}
}
}
self.spawn_once.remove(i);
i += 1;

View file

@ -0,0 +1,25 @@
dofile_once("data/scripts/lib/utilities.lua")
dofile("data/scripts/gun/gun_actions.lua")
local util = dofile_once("mods/quant.ew/files/resource/util_min.lua")
local entity_id = GetUpdatedEntityID()
local pos_x, pos_y = EntityGetTransform(entity_id)
-- abort if conversion already in progress
if #EntityGetInRadiusWithTag(pos_x, pos_y, 10, "forge_item_convert") > 0 then
return
end
for _, id in pairs(EntityGetInRadiusWithTag(pos_x, pos_y, 40, "forgeable")) do
-- make sure item is not carried in inventory or wand
if EntityGetRootEntity(id) == id then
-- start conversion
if util.do_i_own(id) then
EntityLoad("data/entities/buildings/forge_item_convert.xml", pos_x, pos_y)
else
EntityLoad("mods/quant.ew/files/system/forge/forge_item_convert.xml", pos_x, pos_y)
end
GamePlaySound("data/audio/Desktop/projectiles.snd", "projectiles/magic/create", pos_x, pos_y)
return
end
end

View file

@ -576,8 +576,8 @@ local function merge_xml(root, base_element, base_file)
if modifications then
merge_element(modifications, elem)
--[[if #elem.children > 0 then
merge_xml(root, base, elem)
end]]
merge_xml(root, base, elem)
end]]
else
table.insert(base_element.children, index, elem)
index = index + 1
@ -603,16 +603,16 @@ local function merge_xml(root, base_element, base_file)
end
--[[
TODO:
local to_remove = {}
for idx, elem in ipairs(parent.children) do
if elem.attr._remove_from_base == "1" then
table.insert(to_remove, 1, idx)
end
end
for _, idx in ipairs(to_remove) do
table.remove(parent.children, idx)
end
TODO:
local to_remove = {}
for idx, elem in ipairs(parent.children) do
if elem.attr._remove_from_base == "1" then
table.insert(to_remove, 1, idx)
end
end
for _, idx in ipairs(to_remove) do
table.remove(parent.children, idx)
end
]]
end
@ -750,14 +750,14 @@ end
---
---Example usage:
---```
--- elem:create_children(
--- { AbilityComponent = {
--- ui_name = "$item_jar_with_mat"
--- }},
--- { DamageModelComponent = {
--- hp = 2
--- }}
--- )
--- elem:create_children(
--- { AbilityComponent = {
--- ui_name = "$item_jar_with_mat"
--- }},
--- { DamageModelComponent = {
--- hp = 2
--- }}
--- )
---```
---@param ... table<str, table<str,any>> descriptions of child elements
---@return element self for chaining purposes
@ -864,7 +864,7 @@ end
---Use like:
---```lua
---for dmc in entity:each_of("DamageModelComponent") do
--- dmc:set("hp", 5)
--- dmc:set("hp", 5)
---end
---```
---@param element_name str
@ -902,7 +902,7 @@ end
---Iterate over each child of the xml element, use like:
---```lua
---for child in elem:each_child() do
--- print(child.name)
--- print(child.name)
---end
---```
---@return fun(): element?
@ -969,7 +969,7 @@ end
---Use like:
---```lua
---for content in nxml.edit_file("data/entities/animals/boss_centipede/boss_centipede.xml") do
--- content:first_of("DamageModelComponent"):set("hp", 2)
--- content:first_of("DamageModelComponent"):set("hp", 2)
---end
----- Kolmis file is edited once we exit the for loop.
---```

View file

@ -6,6 +6,34 @@ ModLuaFileAppend("data/scripts/buildings/chest_light.lua", "mods/quant.ew/files/
ModLuaFileAppend("data/scripts/buildings/chest_dark.lua", "mods/quant.ew/files/resource/cbs/chest_sync.lua")
ModLuaFileAppend("data/biome_impl/static_tile/chest_darkness.lua", "mods/quant.ew/files/resource/cbs/chest_sync.lua")
ModLuaFileAppend("data/scripts/buildings/forge_item_convert.lua", "mods/quant.ew/files/system/forge/append.lua")
util.prepend(
"data/scripts/buildings/forge_item_convert.lua",
"local converted = false",
"local converted = false\n"
.. 'local util = dofile_once("mods/quant.ew/files/resource/util_min.lua")\n'
.. "local kill = EntityKill\n"
.. "local function EntityKill(ent)\n"
.. 'if EntityHasTag(ent, "broken_wand") then\n'
.. "local x, y = EntityGetTransform(ent)\n"
.. 'CrossCall("ew_broken_wand", ent, x, y)\n'
.. "end\n"
.. "return kill(ent)\n"
.. "end\n"
.. "local first = false\n"
.. "local rt = EntityGetRootEntity\n"
.. "local function EntityGetRootEntity(ent)\n"
.. "if util.do_i_own(ent) then\n"
.. "return rt(ent)\n"
.. "else\n"
.. "if rt(ent) == ent then\n"
.. "converted = true\n"
.. "end\n"
.. "return 0\n"
.. "end\n"
.. "end"
)
local nxml = dofile_once("mods/quant.ew/files/lib/nxml.lua")
local thrown = {}
@ -14,6 +42,8 @@ local dead = {}
local chest = {}
local broken_wands = {}
local gid_chest = {}
-- Add extra entities to entity sync
@ -35,6 +65,19 @@ for filename, _ in pairs(constants.phys_sync_allowed) do
end]]
end
util.add_cross_call("ew_broken_wand", function(ent, x, y)
local gid
for _, v in ipairs(EntityGetComponent(ent, "VariableStorageComponent") or {}) do
if ComponentGetValue2(v, "name") == "ew_gid_lid" then
gid = v
break
end
end
if gid ~= nil then
table.insert(broken_wands, { x, y })
end
end)
util.add_cross_call("ew_thrown", function(thrown_item)
if
thrown_item ~= nil
@ -95,8 +138,10 @@ end]]
function mod.on_world_update()
local c_thrown = thrown
local c_chest = chest
local wands = broken_wands
thrown = {}
chest = {}
broken_wands = {}
for _, ent in ipairs(c_thrown) do
if EntityGetIsAlive(ent) then
ewext.des_item_thrown(ent)
@ -105,27 +150,15 @@ function mod.on_world_update()
for _, data in ipairs(c_chest) do
ewext.des_chest_opened(data[1], data[2], data[3], data[4], data[5], data[6])
end
for _, data in ipairs(wands) do
ewext.des_broken_wand(data[1], data[2])
end
end
function mod.on_world_update_post()
local c_dead = dead
dead = {}
for _, data in ipairs(c_dead) do
--[[print(
"resp_entity",
type(data[1]),
data[1],
type(data[2]),
bool_to_truefalse(data[2]),
type(data[3]),
data[3],
type(data[4]),
data[4],
type(data[5]),
data[5],
type(data[6]),
data[6]
)]]
ewext.des_death_notify(data[1], data[2], data[3], data[4], data[5], data[6])
end
end

View file

@ -0,0 +1,38 @@
<Entity tags="forge_item_convert">
<!-- buildup -->
<ParticleEmitterComponent
_tags="buildup_particles"
emitted_material_name="spark_purple"
gravity.y="0.0"
lifetime_min="0.8"
lifetime_max="5.5"
count_min="20"
count_max="40"
render_on_grid="1"
fade_based_on_lifetime="1"
area_circle_radius.min="0"
area_circle_radius.max="0"
cosmetic_force_create="0"
airflow_force="1.1"
airflow_time="1.01"
airflow_scale="0.05"
emission_interval_min_frames="1"
emission_interval_max_frames="1"
emit_cosmetic_particles="1"
image_animation_file="data/particles/image_emitters/circle_reverse_64.png"
image_animation_speed="3.5"
image_animation_loop="0"
is_emitting="1" >
</ParticleEmitterComponent>
<LifetimeComponent
lifetime="81"
>
</LifetimeComponent>
<AudioComponent
file="data/audio/Desktop/projectiles.snd"
event_root="player_projectiles/crumbling_earth">
</AudioComponent>
</Entity>

View file

@ -29,6 +29,7 @@ pub struct ModMessage {
pub enum SpawnOnce {
Enemy(String, bool, Option<PeerId>),
Chest(String, f32, f32),
BrokenWand,
}
#[derive(Debug, Encode, Decode, Clone)]