mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
dont have Results where not needed
This commit is contained in:
parent
618cf08439
commit
06e2f7e2ea
3 changed files with 192 additions and 217 deletions
|
@ -1430,7 +1430,7 @@ impl EntityManager {
|
|||
Ok(())
|
||||
}
|
||||
pub fn check_all_phys_init(&mut self) -> eyre::Result<bool> {
|
||||
for phys_c in self.iter_mut_all_components_of_type::<PhysicsBody2Component>()? {
|
||||
for phys_c in self.iter_mut_all_components_of_type::<PhysicsBody2Component>() {
|
||||
if !phys_c.phys_init && !PhysicsBody2Component::from(phys_c.id).m_initialized()? {
|
||||
return Ok(false);
|
||||
} else {
|
||||
|
@ -1439,40 +1439,33 @@ impl EntityManager {
|
|||
}
|
||||
Ok(true)
|
||||
}
|
||||
pub fn try_get_first_component<C: Component>(
|
||||
&self,
|
||||
tag: ComponentTag,
|
||||
) -> eyre::Result<Option<C>> {
|
||||
let coms = &self.current_data.components
|
||||
[const { CachedComponent::from_component::<C>() as usize }];
|
||||
Ok(coms
|
||||
pub fn try_get_first_component<C: Component>(&self, tag: ComponentTag) -> Option<C> {
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter()
|
||||
.find(|c| c.enabled && (tag == ComponentTag::None || c.tags.get(tag as u16)))
|
||||
.map(|com| C::from(com.id)))
|
||||
.map(|com| C::from(com.id))
|
||||
}
|
||||
pub fn try_get_first_component_including_disabled<C: Component>(
|
||||
&self,
|
||||
tag: ComponentTag,
|
||||
) -> eyre::Result<Option<C>> {
|
||||
) -> Option<C> {
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter()
|
||||
.find(|c| tag == ComponentTag::None || c.tags.get(tag as u16))
|
||||
.map(|c| C::from(c.id))
|
||||
}
|
||||
pub fn get_first_component<C: Component>(&self, tag: ComponentTag) -> eyre::Result<C> {
|
||||
if let Some(coms) = self.current_data.components
|
||||
[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter()
|
||||
.find(|c| tag == ComponentTag::None || c.tags.get(tag as u16))
|
||||
.find(|c| c.enabled && (tag == ComponentTag::None || c.tags.get(tag as u16)))
|
||||
.map(|com| C::from(com.id))
|
||||
{
|
||||
Ok(Some(C::from(coms.id)))
|
||||
Ok(coms)
|
||||
} else {
|
||||
Ok(None)
|
||||
Err(eyre!("no comp found"))
|
||||
}
|
||||
}
|
||||
pub fn get_first_component<C: Component>(&self, tag: ComponentTag) -> eyre::Result<C> {
|
||||
let coms = &self.current_data.components
|
||||
[const { CachedComponent::from_component::<C>() as usize }];
|
||||
Ok(coms
|
||||
.iter()
|
||||
.find(|c| c.enabled && (tag == ComponentTag::None || c.tags.get(tag as u16)))
|
||||
.map(|com| C::from(com.id))
|
||||
.unwrap())
|
||||
}
|
||||
pub fn get_first_component_including_disabled<C: Component>(
|
||||
&self,
|
||||
tag: ComponentTag,
|
||||
|
@ -1509,33 +1502,27 @@ impl EntityManager {
|
|||
pub fn iter_all_components_of_type<C: Component>(
|
||||
&self,
|
||||
tag: ComponentTag,
|
||||
) -> eyre::Result<impl Iterator<Item = C>> {
|
||||
Ok(
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter()
|
||||
.filter(move |c| c.enabled && (tag == ComponentTag::None || c.tags.get(tag as u16)))
|
||||
.map(|c| C::from(c.id)),
|
||||
)
|
||||
) -> impl Iterator<Item = C> {
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter()
|
||||
.filter(move |c| c.enabled && (tag == ComponentTag::None || c.tags.get(tag as u16)))
|
||||
.map(|c| C::from(c.id))
|
||||
}
|
||||
fn iter_mut_all_components_of_type<C: Component>(
|
||||
&mut self,
|
||||
) -> eyre::Result<impl Iterator<Item = &mut ComponentData>> {
|
||||
Ok(
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter_mut()
|
||||
.filter(|c| c.enabled),
|
||||
)
|
||||
) -> impl Iterator<Item = &mut ComponentData> {
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter_mut()
|
||||
.filter(|c| c.enabled)
|
||||
}
|
||||
pub fn iter_all_components_of_type_including_disabled<C: Component>(
|
||||
&self,
|
||||
tag: ComponentTag,
|
||||
) -> eyre::Result<impl Iterator<Item = C>> {
|
||||
Ok(
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter()
|
||||
.filter(move |c| tag == ComponentTag::None || c.tags.get(tag as u16))
|
||||
.map(|c| C::from(c.id)),
|
||||
)
|
||||
) -> impl Iterator<Item = C> {
|
||||
self.current_data.components[const { CachedComponent::from_component::<C>() as usize }]
|
||||
.iter()
|
||||
.filter(move |c| tag == ComponentTag::None || c.tags.get(tag as u16))
|
||||
.map(|c| C::from(c.id))
|
||||
}
|
||||
fn iter_all_components_of_type_including_disabled_raw<C: Component>(
|
||||
&self,
|
||||
|
|
|
@ -565,7 +565,7 @@ impl Module for EntitySync {
|
|||
{
|
||||
if let Some(cost) = self
|
||||
.entity_manager
|
||||
.try_get_first_component::<ItemCostComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<ItemCostComponent>(ComponentTag::None)
|
||||
{
|
||||
if cost.stealable()? {
|
||||
cost.set_stealable(false)?;
|
||||
|
@ -576,7 +576,7 @@ impl Module for EntitySync {
|
|||
}
|
||||
if let Some(vel) = self
|
||||
.entity_manager
|
||||
.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
vel.set_gravity_y(0.0)?;
|
||||
vel.set_air_friction(10.0)?;
|
||||
|
|
|
@ -303,7 +303,7 @@ impl LocalDiffModelTracker {
|
|||
|
||||
let (x, y, r, sx, sy) = entity.transform()?;
|
||||
let should_send_position = if let Some(com) =
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)
|
||||
{
|
||||
!com.play_hover_animation()?
|
||||
} else {
|
||||
|
@ -315,7 +315,7 @@ impl LocalDiffModelTracker {
|
|||
}
|
||||
|
||||
let should_send_rotation = if let Some(com) =
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)
|
||||
{
|
||||
!com.play_spinning_animation()? || com.play_hover_animation()?
|
||||
} else {
|
||||
|
@ -327,7 +327,7 @@ impl LocalDiffModelTracker {
|
|||
}
|
||||
|
||||
if let Some(inv) = entity_manager
|
||||
.try_get_first_component_including_disabled::<Inventory2Component>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<Inventory2Component>(ComponentTag::None)
|
||||
{
|
||||
if let Some(wand) = inv.m_actual_active_item()? {
|
||||
if info.wand.is_none() {
|
||||
|
@ -365,7 +365,7 @@ impl LocalDiffModelTracker {
|
|||
&& entity_manager
|
||||
.try_get_first_component::<BossHealthBarComponent>(
|
||||
const { ComponentTag::from_str("disabled_at_start") },
|
||||
)?
|
||||
)
|
||||
.is_some())
|
||||
|| entity_manager
|
||||
.get_var(const { VarName::from_str("active") })
|
||||
|
@ -375,7 +375,7 @@ impl LocalDiffModelTracker {
|
|||
&& entity_manager
|
||||
.try_get_first_component::<LuaComponent>(
|
||||
const { ComponentTag::from_str("disabled") },
|
||||
)?
|
||||
)
|
||||
.is_some());
|
||||
|
||||
info.limbs = entity
|
||||
|
@ -390,26 +390,26 @@ impl LocalDiffModelTracker {
|
|||
.collect();
|
||||
|
||||
if let Some(worm) =
|
||||
entity_manager.try_get_first_component::<BossDragonComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<BossDragonComponent>(ComponentTag::None)
|
||||
{
|
||||
(info.vx, info.vy) = worm.m_target_vec()?;
|
||||
} else if let Some(worm) =
|
||||
entity_manager.try_get_first_component::<WormComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<WormComponent>(ComponentTag::None)
|
||||
{
|
||||
(info.vx, info.vy) = worm.m_target_vec()?;
|
||||
} else if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<CharacterDataComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<CharacterDataComponent>(ComponentTag::None)
|
||||
{
|
||||
(info.vx, info.vy) = vel.m_velocity()?;
|
||||
} else if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
(info.vx, info.vy) = vel.m_velocity()?;
|
||||
}
|
||||
|
||||
if entity_manager.has_tag(const { CachedTag::from_tag("card_action") }) {
|
||||
if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
let (cx, cy) = entity_manager.camera_pos();
|
||||
if ((cx - x) as f32).powi(2) + ((cy - y) as f32).powi(2) > 512.0 * 512.0 {
|
||||
|
@ -423,7 +423,7 @@ impl LocalDiffModelTracker {
|
|||
}
|
||||
|
||||
if let Some(damage) =
|
||||
entity_manager.try_get_first_component::<DamageModelComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<DamageModelComponent>(ComponentTag::None)
|
||||
{
|
||||
let hp = damage.hp()?;
|
||||
info.hp = hp as f32;
|
||||
|
@ -434,7 +434,7 @@ impl LocalDiffModelTracker {
|
|||
}
|
||||
|
||||
if let Some(item_cost) =
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)
|
||||
{
|
||||
info.cost = item_cost.cost()?;
|
||||
} else if entity_manager.has_tag(const { CachedTag::from_tag("boss_wizard") }) {
|
||||
|
@ -520,75 +520,65 @@ impl LocalDiffModelTracker {
|
|||
|
||||
let mut any = false;
|
||||
for ai in entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<AIAttackComponent>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
.iter_all_components_of_type_including_disabled::<AIAttackComponent>(ComponentTag::None)
|
||||
{
|
||||
any = any || ai.attack_ranged_aim_rotation_enabled()?;
|
||||
}
|
||||
for ai in entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<AnimalAIComponent>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
.iter_all_components_of_type_including_disabled::<AnimalAIComponent>(ComponentTag::None)
|
||||
{
|
||||
any = any || ai.attack_ranged_aim_rotation_enabled()?;
|
||||
}
|
||||
if any {
|
||||
if let Some(ai) = entity_manager
|
||||
.try_get_first_component_including_disabled::<AnimalAIComponent>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
.try_get_first_component_including_disabled::<AnimalAIComponent>(ComponentTag::None)
|
||||
{
|
||||
info.ai_state = ai.ai_state()?;
|
||||
info.ai_rotation = ai.m_ranged_attack_current_aim_angle()?;
|
||||
}
|
||||
} else {
|
||||
let mut files = std::mem::take(&mut entity_manager.files);
|
||||
if let Ok(sprites) =
|
||||
entity_manager.iter_all_components_of_type::<SpriteComponent>(ComponentTag::None)
|
||||
let sprites =
|
||||
entity_manager.iter_all_components_of_type::<SpriteComponent>(ComponentTag::None);
|
||||
info.facing_direction = (sx.is_sign_positive(), sy.is_sign_positive());
|
||||
info.animations = sprites
|
||||
.filter_map(|sprite| {
|
||||
let file = sprite.image_file().ok()?;
|
||||
if file.ends_with(".xml") {
|
||||
let text = noita_api::get_file(&mut files, file).ok()?;
|
||||
let animation = sprite.rect_animation().unwrap_or("".into());
|
||||
Some(
|
||||
text.iter()
|
||||
.position(|name| name == &animation)
|
||||
.unwrap_or(usize::MAX) as u16,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if let Some(ai) =
|
||||
entity_manager.try_get_first_component::<AnimalAIComponent>(ComponentTag::None)
|
||||
{
|
||||
info.facing_direction = (sx.is_sign_positive(), sy.is_sign_positive());
|
||||
info.animations = sprites
|
||||
.filter_map(|sprite| {
|
||||
let file = sprite.image_file().ok()?;
|
||||
if file.ends_with(".xml") {
|
||||
let text = noita_api::get_file(&mut files, file).ok()?;
|
||||
let animation = sprite.rect_animation().unwrap_or("".into());
|
||||
Some(
|
||||
text.iter()
|
||||
.position(|name| name == &animation)
|
||||
.unwrap_or(usize::MAX) as u16,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if let Some(ai) = entity_manager
|
||||
.try_get_first_component::<AnimalAIComponent>(ComponentTag::None)?
|
||||
{
|
||||
if ai.attack_ranged_use_laser_sight()? && !ai.is_static_turret()? {
|
||||
info.laser = if let Some(target) = ai.m_greatest_prey()? {
|
||||
if ![15, 16].contains(&ai.ai_state()?) {
|
||||
Target::None
|
||||
} else if let Some(peer) = ctx.player_map.get_by_right(&target) {
|
||||
Target::Peer(*peer)
|
||||
} else if let Some(var) = target.get_var("ew_gid_lid") {
|
||||
if var.value_bool()? {
|
||||
Target::Gid(Gid(var.value_string()?.parse::<u64>()?))
|
||||
} else {
|
||||
Target::None
|
||||
}
|
||||
if ai.attack_ranged_use_laser_sight()? && !ai.is_static_turret()? {
|
||||
info.laser = if let Some(target) = ai.m_greatest_prey()? {
|
||||
if ![15, 16].contains(&ai.ai_state()?) {
|
||||
Target::None
|
||||
} else if let Some(peer) = ctx.player_map.get_by_right(&target) {
|
||||
Target::Peer(*peer)
|
||||
} else if let Some(var) = target.get_var("ew_gid_lid") {
|
||||
if var.value_bool()? {
|
||||
Target::Gid(Gid(var.value_string()?.parse::<u64>()?))
|
||||
} else {
|
||||
Target::None
|
||||
}
|
||||
} else {
|
||||
Target::None
|
||||
}
|
||||
} else {
|
||||
Target::None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info.animations.clear()
|
||||
}
|
||||
entity_manager.files = files;
|
||||
}
|
||||
|
@ -596,7 +586,7 @@ impl LocalDiffModelTracker {
|
|||
info.synced_var = entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<VariableStorageComponent>(
|
||||
const { ComponentTag::from_str("ew_synced_var") },
|
||||
)?
|
||||
)
|
||||
.filter_map(|a| {
|
||||
Some((
|
||||
a.name().ok()?.to_string(),
|
||||
|
@ -648,8 +638,8 @@ impl LocalDiffModelTracker {
|
|||
if let Some(var) = entity_manager.get_var(const { VarName::from_str("ew_was_stealable") }) {
|
||||
let n = var.value_int()?;
|
||||
if n == 1 {
|
||||
if let Some(cost) = entity_manager
|
||||
.try_get_first_component::<ItemCostComponent>(ComponentTag::None)?
|
||||
if let Some(cost) =
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)
|
||||
{
|
||||
let (cx, cy) = entity_manager.camera_pos();
|
||||
if ((cx - x) as f32).powi(2) + ((cy - y) as f32).powi(2) < 256.0 * 256.0 {
|
||||
|
@ -657,24 +647,24 @@ impl LocalDiffModelTracker {
|
|||
entity_manager.remove_component(var)?;
|
||||
}
|
||||
}
|
||||
if let Some(vel) = entity_manager
|
||||
.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
vel.set_gravity_y(400.0)?;
|
||||
vel.set_air_friction(0.55)?;
|
||||
}
|
||||
} else if n == 0 {
|
||||
var.set_value_int(48)?;
|
||||
if let Some(vel) = entity_manager
|
||||
.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
vel.set_gravity_y(0.0)?;
|
||||
vel.set_air_friction(10.0)?;
|
||||
}
|
||||
} else {
|
||||
var.set_value_int(n - 1)?;
|
||||
if let Some(vel) = entity_manager
|
||||
.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
vel.set_gravity_y(0.0)?;
|
||||
vel.set_air_friction(10.0)?;
|
||||
|
@ -843,16 +833,16 @@ impl LocalDiffModel {
|
|||
|| (entity.is_alive() && entity_manager.check_all_phys_init()? && entity.get_physics_body_ids().unwrap_or_default()
|
||||
.len()
|
||||
== entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<PhysicsBodyComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type_including_disabled::<PhysicsBodyComponent>(ComponentTag::None)
|
||||
.count()
|
||||
+ entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<PhysicsBody2Component>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
)
|
||||
.count());
|
||||
entity_manager.add_tag(const { CachedTag::from_tag(DES_TAG) })?;
|
||||
if let Some(ghost) = entity_manager
|
||||
.try_get_first_component_including_disabled::<GhostComponent>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<GhostComponent>(ComponentTag::None)
|
||||
{
|
||||
ghost.set_target_tag("".into())?;
|
||||
}
|
||||
|
@ -863,7 +853,7 @@ impl LocalDiffModel {
|
|||
|
||||
if entity_manager.has_tag(const { CachedTag::from_tag("card_action") }) {
|
||||
if let Some(cost) =
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)
|
||||
{
|
||||
if cost.stealable()? {
|
||||
cost.set_stealable(false)?;
|
||||
|
@ -900,7 +890,7 @@ impl LocalDiffModel {
|
|||
|
||||
if entity_manager.has_tag(const { CachedTag::from_tag("card_action") }) {
|
||||
if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
vel.set_gravity_y(0.0)?;
|
||||
vel.set_air_friction(10.0)?;
|
||||
|
@ -908,10 +898,10 @@ impl LocalDiffModel {
|
|||
}
|
||||
|
||||
if entity_manager
|
||||
.try_get_first_component::<BossDragonComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<BossDragonComponent>(ComponentTag::None)
|
||||
.is_some()
|
||||
&& entity_manager
|
||||
.try_get_first_component::<StreamingKeepAliveComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<StreamingKeepAliveComponent>(ComponentTag::None)
|
||||
.is_none()
|
||||
{
|
||||
entity_manager.add_component::<StreamingKeepAliveComponent>()?;
|
||||
|
@ -920,10 +910,10 @@ impl LocalDiffModel {
|
|||
let is_global = entity_manager
|
||||
.try_get_first_component_including_disabled::<BossHealthBarComponent>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
)
|
||||
.is_some()
|
||||
|| entity_manager
|
||||
.try_get_first_component::<StreamingKeepAliveComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<StreamingKeepAliveComponent>(ComponentTag::None)
|
||||
.is_some();
|
||||
|
||||
if is_global {
|
||||
|
@ -931,16 +921,16 @@ impl LocalDiffModel {
|
|||
}
|
||||
|
||||
let drops_gold = (entity_manager
|
||||
.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)
|
||||
.any(|lua| {
|
||||
lua.script_death().ok() == Some("data/scripts/items/drop_money.lua".into())
|
||||
})
|
||||
&& entity_manager
|
||||
.iter_all_components_of_type::<VariableStorageComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type::<VariableStorageComponent>(ComponentTag::None)
|
||||
.all(|var| !var.has_tag("no_gold_drop")))
|
||||
|| (entity_manager.has_tag(const { CachedTag::from_tag("boss_dragon") })
|
||||
&& entity_manager
|
||||
.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)
|
||||
.any(|lua| {
|
||||
lua.script_death().ok()
|
||||
== Some("data/scripts/animals/boss_dragon_death.lua".into())
|
||||
|
@ -1094,8 +1084,9 @@ impl LocalDiffModel {
|
|||
sun(entity_manager, entity_data.counter)?;
|
||||
if entity_data.hp != -1.0 {
|
||||
if let Some(damage) = entity_manager
|
||||
.try_get_first_component::<DamageModelComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<DamageModelComponent>(ComponentTag::None)
|
||||
{
|
||||
noita_api::print(format!("a {:?} {:?}", entity, damage.0));
|
||||
if entity_data.hp > damage.max_hp_cap()? as f32 {
|
||||
damage.set_max_hp_cap(entity_data.hp as f64)?;
|
||||
}
|
||||
|
@ -1107,7 +1098,7 @@ impl LocalDiffModel {
|
|||
}
|
||||
if !entity_data.drops_gold {
|
||||
let n = entity_manager
|
||||
.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)
|
||||
.find(|lua| {
|
||||
lua.script_death().ok() == Some("data/scripts/items/drop_money.lua".into())
|
||||
});
|
||||
|
@ -1689,7 +1680,7 @@ impl RemoteDiffModel {
|
|||
for lua in entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<LuaComponent>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
)
|
||||
{
|
||||
if [
|
||||
"data/entities/animals/boss_centipede/boss_centipede_before_fight.lua",
|
||||
|
@ -1755,7 +1746,7 @@ impl RemoteDiffModel {
|
|||
&& entity_manager.has_tag(const { CachedTag::from_tag("boss_centipede") }))
|
||||
{
|
||||
let should_send_position = if let Some(com) =
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)
|
||||
{
|
||||
!com.play_hover_animation()?
|
||||
} else {
|
||||
|
@ -1763,7 +1754,7 @@ impl RemoteDiffModel {
|
|||
};
|
||||
|
||||
let should_send_rotation = if let Some(com) =
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemComponent>(ComponentTag::None)
|
||||
{
|
||||
!com.play_spinning_animation()? || com.play_hover_animation()?
|
||||
} else {
|
||||
|
@ -1782,26 +1773,27 @@ impl RemoteDiffModel {
|
|||
entity.set_position(x, y, Some(entity_info.r as f64))?;
|
||||
}
|
||||
if let Some(worm) =
|
||||
entity_manager.try_get_first_component::<BossDragonComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<BossDragonComponent>(ComponentTag::None)
|
||||
{
|
||||
worm.set_m_target_vec((vx, vy))?;
|
||||
} else if let Some(worm) =
|
||||
entity_manager.try_get_first_component::<WormComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<WormComponent>(ComponentTag::None)
|
||||
{
|
||||
worm.set_m_target_vec((vx, vy))?;
|
||||
} else if let Some(vel) = entity_manager
|
||||
.try_get_first_component::<CharacterDataComponent>(ComponentTag::None)?
|
||||
} else if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<CharacterDataComponent>(ComponentTag::None)
|
||||
{
|
||||
vel.set_m_velocity((vx, vy))?;
|
||||
} else if let Some(vel) =
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<VelocityComponent>(ComponentTag::None)
|
||||
{
|
||||
vel.set_m_velocity((vx, vy))?;
|
||||
}
|
||||
}
|
||||
if let Some(damage) =
|
||||
entity_manager.try_get_first_component::<DamageModelComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<DamageModelComponent>(ComponentTag::None)
|
||||
{
|
||||
noita_api::print(format!("b {:?} {:?}", entity, damage.0));
|
||||
if entity_info.hp > damage.max_hp()? as f32 {
|
||||
damage.set_max_hp(entity_info.hp as f64)?
|
||||
}
|
||||
|
@ -1861,7 +1853,7 @@ impl RemoteDiffModel {
|
|||
}
|
||||
|
||||
if let Some(cost) =
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)
|
||||
{
|
||||
cost.set_cost(entity_info.cost)?;
|
||||
if entity_info.cost == 0 {
|
||||
|
@ -1889,7 +1881,7 @@ impl RemoteDiffModel {
|
|||
if var.value_int()? == 0 {
|
||||
var.set_value_int(4)?;
|
||||
entity_manager
|
||||
.iter_all_components_of_type::<SpriteComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type::<SpriteComponent>(ComponentTag::None)
|
||||
.for_each(|s| {
|
||||
let _ = s.set_rect_animation("roll".into());
|
||||
})
|
||||
|
@ -1906,49 +1898,47 @@ impl RemoteDiffModel {
|
|||
entity.set_current_stains(entity_info.current_stains)?;
|
||||
}
|
||||
if let Some(ai) = entity_manager
|
||||
.try_get_first_component_including_disabled::<AnimalAIComponent>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<AnimalAIComponent>(ComponentTag::None)
|
||||
{
|
||||
ai.set_ai_state(entity_info.ai_state)?;
|
||||
ai.set_m_ranged_attack_current_aim_angle(entity_info.ai_rotation)?;
|
||||
} else {
|
||||
let mut files = std::mem::take(&mut entity_manager.files);
|
||||
if let Ok(sprites) =
|
||||
entity_manager.iter_all_components_of_type::<SpriteComponent>(ComponentTag::None)
|
||||
let sprites =
|
||||
entity_manager.iter_all_components_of_type::<SpriteComponent>(ComponentTag::None);
|
||||
for (sprite, animation) in sprites
|
||||
.filter(|sprite| {
|
||||
sprite
|
||||
.image_file()
|
||||
.map(|c| c.ends_with(".xml"))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.zip(entity_info.animations.iter())
|
||||
{
|
||||
for (sprite, animation) in sprites
|
||||
.filter(|sprite| {
|
||||
sprite
|
||||
.image_file()
|
||||
.map(|c| c.ends_with(".xml"))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.zip(entity_info.animations.iter())
|
||||
{
|
||||
sprite.set_special_scale_x(if entity_info.facing_direction.0 {
|
||||
1.0
|
||||
} else {
|
||||
-1.0
|
||||
})?;
|
||||
sprite.set_special_scale_y(if entity_info.facing_direction.1 {
|
||||
1.0
|
||||
} else {
|
||||
-1.0
|
||||
})?;
|
||||
if *animation == u16::MAX {
|
||||
continue;
|
||||
}
|
||||
let file = sprite.image_file()?;
|
||||
let text = noita_api::get_file(&mut files, file)?;
|
||||
if let Some(ani) = text.get(*animation as usize) {
|
||||
sprite.set_rect_animation(ani.into())?;
|
||||
sprite.set_next_rect_animation(ani.into())?;
|
||||
}
|
||||
sprite.set_special_scale_x(if entity_info.facing_direction.0 {
|
||||
1.0
|
||||
} else {
|
||||
-1.0
|
||||
})?;
|
||||
sprite.set_special_scale_y(if entity_info.facing_direction.1 {
|
||||
1.0
|
||||
} else {
|
||||
-1.0
|
||||
})?;
|
||||
if *animation == u16::MAX {
|
||||
continue;
|
||||
}
|
||||
let file = sprite.image_file()?;
|
||||
let text = noita_api::get_file(&mut files, file)?;
|
||||
if let Some(ani) = text.get(*animation as usize) {
|
||||
sprite.set_rect_animation(ani.into())?;
|
||||
sprite.set_next_rect_animation(ani.into())?;
|
||||
}
|
||||
}
|
||||
entity_manager.files = files;
|
||||
}
|
||||
let laser =
|
||||
entity_manager.try_get_first_component::<LaserEmitterComponent>(ComponentTag::None)?;
|
||||
entity_manager.try_get_first_component::<LaserEmitterComponent>(ComponentTag::None);
|
||||
if entity_info.laser != Target::None {
|
||||
let laser = if let Some(laser) = laser {
|
||||
laser
|
||||
|
@ -2016,7 +2006,7 @@ impl RemoteDiffModel {
|
|||
{
|
||||
let should_send_position = if let Some(com) =
|
||||
entity_manager
|
||||
.try_get_first_component::<ItemComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<ItemComponent>(ComponentTag::None)
|
||||
{
|
||||
!com.play_hover_animation()?
|
||||
} else {
|
||||
|
@ -2024,7 +2014,7 @@ impl RemoteDiffModel {
|
|||
};
|
||||
let should_send_rotation = if let Some(com) =
|
||||
entity_manager
|
||||
.try_get_first_component::<ItemComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<ItemComponent>(ComponentTag::None)
|
||||
{
|
||||
!com.play_spinning_animation()? || com.play_hover_animation()?
|
||||
} else {
|
||||
|
@ -2108,7 +2098,7 @@ impl RemoteDiffModel {
|
|||
};
|
||||
entity_manager.set_current_entity(entity)?;
|
||||
if let Some(explosion) = entity_manager
|
||||
.try_get_first_component::<ExplodeOnDamageComponent>(ComponentTag::None)?
|
||||
.try_get_first_component::<ExplodeOnDamageComponent>(ComponentTag::None)
|
||||
{
|
||||
explosion.set_explode_on_death_percent(1.0)?;
|
||||
}
|
||||
|
@ -2118,8 +2108,8 @@ impl RemoteDiffModel {
|
|||
{
|
||||
inv.children(None).for_each(|e| e.kill())
|
||||
}
|
||||
if let Some(damage) = entity_manager
|
||||
.try_get_first_component::<DamageModelComponent>(ComponentTag::None)?
|
||||
if let Some(damage) =
|
||||
entity_manager.try_get_first_component::<DamageModelComponent>(ComponentTag::None)
|
||||
{
|
||||
entity_manager.remove_ent(&entity);
|
||||
entity
|
||||
|
@ -2225,14 +2215,14 @@ pub fn init_remote_entity(
|
|||
entity_manager.remove_all_components_of_type::<LifetimeComponent>(ComponentTag::None)?;
|
||||
let mut any = false;
|
||||
for ai in entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<AIAttackComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type_including_disabled::<AIAttackComponent>(ComponentTag::None)
|
||||
{
|
||||
any = any || ai.attack_ranged_aim_rotation_enabled()?;
|
||||
ai.set_attack_ranged_entity_count_max(0)?;
|
||||
ai.set_attack_ranged_entity_count_min(0)?;
|
||||
}
|
||||
for ai in entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<AnimalAIComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type_including_disabled::<AnimalAIComponent>(ComponentTag::None)
|
||||
{
|
||||
any = any || ai.attack_ranged_aim_rotation_enabled()?;
|
||||
ai.set_attack_ranged_entity_count_max(0)?;
|
||||
|
@ -2249,25 +2239,26 @@ pub fn init_remote_entity(
|
|||
entity_manager.remove_all_components_of_type::<AIAttackComponent>(ComponentTag::None)?;
|
||||
for sprite in entity_manager.iter_all_components_of_type::<SpriteComponent>(
|
||||
const { ComponentTag::from_str("character") },
|
||||
)? {
|
||||
) {
|
||||
sprite.remove_tag("character")?;
|
||||
sprite.set_has_special_scale(true)?;
|
||||
}
|
||||
}
|
||||
entity_manager
|
||||
.try_get_first_component_including_disabled::<WormComponent>(ComponentTag::None)?
|
||||
.iter()
|
||||
.for_each(|w| w.set_bite_damage(0.0).unwrap_or(()));
|
||||
entity_manager
|
||||
.try_get_first_component_including_disabled::<BossDragonComponent>(ComponentTag::None)?
|
||||
.iter()
|
||||
.for_each(|w| w.set_bite_damage(0.0).unwrap_or(()));
|
||||
|
||||
if let Some(w) = entity_manager
|
||||
.try_get_first_component_including_disabled::<WormComponent>(ComponentTag::None)
|
||||
{
|
||||
w.set_bite_damage(0.0)?;
|
||||
}
|
||||
if let Some(w) = entity_manager
|
||||
.try_get_first_component_including_disabled::<BossDragonComponent>(ComponentTag::None)
|
||||
{
|
||||
w.set_bite_damage(0.0)?;
|
||||
}
|
||||
entity_manager.add_tag(const { CachedTag::from_tag(DES_TAG) })?;
|
||||
entity_manager.add_tag(const { CachedTag::from_tag("polymorphable_NOT") })?;
|
||||
if lid.is_some() {
|
||||
if let Some(damage) =
|
||||
entity_manager.try_get_first_component::<DamageModelComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<DamageModelComponent>(ComponentTag::None)
|
||||
{
|
||||
damage.set_wait_for_kill_flag_on_death(true)?;
|
||||
damage.set_physics_objects_damage(false)?;
|
||||
|
@ -2275,13 +2266,13 @@ pub fn init_remote_entity(
|
|||
}
|
||||
|
||||
for pb2 in
|
||||
entity_manager.iter_all_components_of_type::<PhysicsBody2Component>(ComponentTag::None)?
|
||||
entity_manager.iter_all_components_of_type::<PhysicsBody2Component>(ComponentTag::None)
|
||||
{
|
||||
pb2.set_destroy_body_if_entity_destroyed(true)?;
|
||||
}
|
||||
|
||||
for expl in entity_manager
|
||||
.iter_all_components_of_type::<ExplodeOnDamageComponent>(ComponentTag::None)?
|
||||
for expl in
|
||||
entity_manager.iter_all_components_of_type::<ExplodeOnDamageComponent>(ComponentTag::None)
|
||||
{
|
||||
expl.set_explode_on_damage_percent(0.0)?;
|
||||
expl.set_explode_on_death_percent(0.0)?;
|
||||
|
@ -2289,14 +2280,14 @@ pub fn init_remote_entity(
|
|||
}
|
||||
|
||||
if let Some(itemc) =
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)?
|
||||
entity_manager.try_get_first_component::<ItemCostComponent>(ComponentTag::None)
|
||||
{
|
||||
itemc.set_stealable(false)?;
|
||||
}
|
||||
|
||||
let mut to_remove = Vec::new();
|
||||
for lua in entity_manager
|
||||
.iter_all_components_of_type_including_disabled::<LuaComponent>(ComponentTag::None)?
|
||||
.iter_all_components_of_type_including_disabled::<LuaComponent>(ComponentTag::None)
|
||||
{
|
||||
if (!drops_gold
|
||||
&& lua.script_death().ok() == Some("data/scripts/items/drop_money.lua".into()))
|
||||
|
@ -2363,19 +2354,19 @@ pub fn init_remote_entity(
|
|||
lua.set_execute_every_n_frame(-1)?;
|
||||
}
|
||||
if let Some(life) = entity_manager
|
||||
.try_get_first_component_including_disabled::<LifetimeComponent>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<LifetimeComponent>(ComponentTag::None)
|
||||
{
|
||||
life.set_lifetime(i32::MAX)?;
|
||||
}
|
||||
if let Some(pickup) = entity_manager
|
||||
.try_get_first_component_including_disabled::<ItemPickUpperComponent>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<ItemPickUpperComponent>(ComponentTag::None)
|
||||
{
|
||||
pickup.set_drop_items_on_death(false)?;
|
||||
pickup.set_only_pick_this_entity(Some(EntityID(NonZero::new(1).unwrap())))?;
|
||||
}
|
||||
|
||||
if let Some(ghost) = entity_manager
|
||||
.try_get_first_component_including_disabled::<GhostComponent>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<GhostComponent>(ComponentTag::None)
|
||||
{
|
||||
ghost.set_die_if_no_home(false)?;
|
||||
}
|
||||
|
@ -2384,7 +2375,7 @@ pub fn init_remote_entity(
|
|||
if let Some(explosion) = entity_manager
|
||||
.try_get_first_component_including_disabled::<ExplodeOnDamageComponent>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
)
|
||||
{
|
||||
explosion.object_set_value::<Cow<'_, str>>(
|
||||
"config_explosion",
|
||||
|
@ -2412,12 +2403,10 @@ pub fn init_remote_entity(
|
|||
}
|
||||
|
||||
if entity_manager
|
||||
.try_get_first_component_including_disabled::<PhysicsBodyComponent>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<PhysicsBodyComponent>(ComponentTag::None)
|
||||
.is_none()
|
||||
&& entity_manager
|
||||
.try_get_first_component_including_disabled::<PhysicsBody2Component>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
.try_get_first_component_including_disabled::<PhysicsBody2Component>(ComponentTag::None)
|
||||
.is_none()
|
||||
{
|
||||
ephemerial(entity.0.get() as u32)?
|
||||
|
@ -2465,7 +2454,7 @@ fn spawn_entity_by_data(
|
|||
entity_manager.set_current_entity(ent)?;
|
||||
let mut to_remove = Vec::new();
|
||||
for lua in
|
||||
entity_manager.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)?
|
||||
entity_manager.iter_all_components_of_type::<LuaComponent>(ComponentTag::None)
|
||||
{
|
||||
if ["data/scripts/props/suspended_container_physics_objects.lua"]
|
||||
.contains(&&*lua.script_source_file()?)
|
||||
|
@ -2504,18 +2493,19 @@ fn with_entity_scripts<T>(
|
|||
entity: &mut EntityManager,
|
||||
f: impl FnOnce(LuaComponent) -> eyre::Result<T>,
|
||||
) -> eyre::Result<T> {
|
||||
let component = entity
|
||||
.try_get_first_component(const { ComponentTag::from_str(DES_SCRIPTS_TAG) })
|
||||
.transpose()
|
||||
.unwrap_or_else(|| {
|
||||
let component = entity.add_component::<LuaComponent>()?;
|
||||
component.add_tag(DES_SCRIPTS_TAG)?;
|
||||
component.add_tag("enabled_in_inventory")?;
|
||||
component.add_tag("enabled_in_world")?;
|
||||
component.add_tag("enabled_in_hand")?;
|
||||
component.add_tag("ew_remove_on_send")?;
|
||||
Ok(component)
|
||||
})?;
|
||||
let component = if let Some(c) =
|
||||
entity.try_get_first_component(const { ComponentTag::from_str(DES_SCRIPTS_TAG) })
|
||||
{
|
||||
c
|
||||
} else {
|
||||
let component = entity.add_component::<LuaComponent>()?;
|
||||
component.add_tag(DES_SCRIPTS_TAG)?;
|
||||
component.add_tag("enabled_in_inventory")?;
|
||||
component.add_tag("enabled_in_world")?;
|
||||
component.add_tag("enabled_in_hand")?;
|
||||
component.add_tag("ew_remove_on_send")?;
|
||||
component
|
||||
};
|
||||
f(component)
|
||||
}
|
||||
|
||||
|
@ -2559,10 +2549,7 @@ fn safe_entitykill(entity: &mut EntityManager) {
|
|||
let is_wand =
|
||||
entity.try_get_first_component_including_disabled::<AbilityComponent>(ComponentTag::None);
|
||||
if is_wand
|
||||
.map(|a| {
|
||||
a.map(|b| b.use_gun_script().unwrap_or(false))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.map(|b| b.use_gun_script().unwrap_or(false))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
let _ = _safe_wandkill(entity);
|
||||
|
@ -2588,7 +2575,7 @@ fn give_wand(
|
|||
entity_manager: &mut EntityManager,
|
||||
) -> eyre::Result<()> {
|
||||
let inv = if let Some(inv) = entity_manager
|
||||
.try_get_first_component_including_disabled::<Inventory2Component>(ComponentTag::None)?
|
||||
.try_get_first_component_including_disabled::<Inventory2Component>(ComponentTag::None)
|
||||
{
|
||||
inv
|
||||
} else {
|
||||
|
@ -2637,7 +2624,7 @@ fn give_wand(
|
|||
if let Some(pickup) = entity_manager
|
||||
.try_get_first_component_including_disabled::<ItemPickUpperComponent>(
|
||||
ComponentTag::None,
|
||||
)?
|
||||
)
|
||||
{
|
||||
pickup.set_only_pick_this_entity(Some(wand))?;
|
||||
}
|
||||
|
@ -2705,6 +2692,7 @@ fn mom(entity: &mut EntityManager, counter: u8, cost: Option<i32>) -> eyre::Resu
|
|||
} else if let Ok(damage) =
|
||||
ent.get_first_component::<DamageModelComponent>(None)
|
||||
{
|
||||
noita_api::print(format!("c {:?} {:?}", entity.entity(), damage.0));
|
||||
damage.set_wait_for_kill_flag_on_death(true)?;
|
||||
damage.set_hp(damage.max_hp()?)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue