1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-19 22:36:49 +00:00

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.
This commit is contained in:
Joshua Goins 2025-04-18 01:38:47 -04:00
parent 3d9bbf8719
commit db877938ac
2 changed files with 16 additions and 9 deletions

View file

@ -120,10 +120,6 @@ async fn main_loop(mut recv: Receiver<ToServer>) -> 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 { .. } => {

View file

@ -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)
}