diff --git a/src/world/connection.rs b/src/world/connection.rs index 7a199e4..92257f4 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -296,6 +296,11 @@ impl ZoneConnection { self.send_segment(segment.clone()).await; } player.queued_segments.clear(); + + for task in &player.queued_tasks { + self.change_zone(task.zone_id).await; + } + player.queued_tasks.clear(); } pub async fn process_effects_list(&mut self) { diff --git a/src/world/lua.rs b/src/world/lua.rs index f4339bc..aacf935 100644 --- a/src/world/lua.rs +++ b/src/world/lua.rs @@ -11,11 +11,16 @@ use super::{ ipc::{ActorSetPos, EventPlay, ServerZoneIpcData, ServerZoneIpcSegment}, }; +pub struct ChangeTerritoryTask { + pub zone_id: u16, +} + #[derive(Default)] pub struct LuaPlayer { pub player_data: PlayerData, pub status_effects: StatusEffects, pub queued_segments: Vec>, + pub queued_tasks: Vec, } impl LuaPlayer { @@ -90,6 +95,10 @@ impl LuaPlayer { segment_type: SegmentType::Ipc { data: ipc }, }); } + + fn change_territory(&mut self, zone_id: u16) { + self.queued_tasks.push(ChangeTerritoryTask { zone_id }); + } } impl UserData for LuaPlayer { @@ -116,6 +125,10 @@ impl UserData for LuaPlayer { this.set_position(position); Ok(()) }); + methods.add_method_mut("change_territory", |_, this, zone_id: u16| { + this.change_territory(zone_id); + Ok(()) + }); } }