From db877938ac87e00cee196a959e9ddd65a2661657 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 18 Apr 2025 01:38:47 -0400 Subject: [PATCH] Attempt to remove actors when killed This doesn't work on the test monster yet - I don't know why, but this is what it's supposed to do. --- src/bin/kawari-world.rs | 21 +++++++++++++-------- src/world/connection.rs | 4 +++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index ae71480..bd443c8 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -120,10 +120,6 @@ async fn main_loop(mut recv: Receiver) -> Result<(), std::io::Error> { for (id, handle) in &mut data.clients { let id = *id; - if id == from_id { - continue; - } - let msg = FromServer::ActorDespawn(actor_id); if handle.send(msg).is_err() { @@ -717,14 +713,11 @@ async fn client_loop( for effect in &effects_builder.effects { match effect.kind { EffectKind::Damage => { - actor.hp = effect.value as u32; + actor.hp = actor.hp.saturating_sub(effect.value as u32); } _ => todo!() } } - - let actor = *actor; - //connection.update_hp_mp(actor.id, actor.hp, 10000).await; } let ipc = ServerZoneIpcSegment { @@ -752,6 +745,18 @@ async fn client_loop( segment_type: SegmentType::Ipc { data: ipc }, }) .await; + + if let Some(actor) = + connection.get_actor(request.target.object_id) + { + if actor.hp == 0 { + tracing::info!("Despawning {} because they died!", actor.id.0); + // if the actor died, despawn them + connection.handle + .send(ToServer::ActorDespawned(connection.id, actor.id.0)) + .await; + } + } } } ClientZoneIpcData::Unk16 { .. } => { diff --git a/src/world/connection.rs b/src/world/connection.rs index b94f454..3808ceb 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -343,6 +343,8 @@ impl ZoneConnection { pub async fn remove_actor(&mut self, actor_id: u32) { if let Some(actor) = self.get_actor(ObjectId(actor_id)).cloned() { + tracing::info!("Removing actor {actor_id} {}!", actor.spawn_index); + let ipc = ServerZoneIpcSegment { unk1: 20, unk2: 0, @@ -754,7 +756,7 @@ impl ZoneConnection { self.actors.iter_mut().find(|actor| actor.id == id) } - pub fn get_actor(&mut self, id: ObjectId) -> Option<&Actor> { + pub fn get_actor(&self, id: ObjectId) -> Option<&Actor> { self.actors.iter().find(|actor| actor.id == id) }