From c5e04ba33f56f494002bee3429e3b2291173b660 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 27 Mar 2025 23:32:36 -0400 Subject: [PATCH] Begin wiring status effect Lua API --- resources/scripts/test.lua | 5 +++++ src/bin/kawari-world.rs | 42 ++++++++++++-------------------------- src/world/connection.rs | 33 +++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/resources/scripts/test.lua b/resources/scripts/test.lua index 213a2cf..f2d23a0 100644 --- a/resources/scripts/test.lua +++ b/resources/scripts/test.lua @@ -2,3 +2,8 @@ function onBeginLogin(player) -- send a welcome message player:send_message("Welcome to Kawari!") end + +function doAction(player) + -- give sprint + player:give_status_effect(50, 5.0) +end diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index c1fa1b3..c30d97d 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -722,36 +722,20 @@ async fn main() { println!("Found action: {:#?}", action_row); - // send new status list - { - let ipc = ServerZoneIpcSegment { - op_code: ServerZoneIpcType::StatusEffectList, - timestamp: timestamp_secs(), - data: ServerZoneIpcData::StatusEffectList( - kawari::world::ipc::StatusEffectList { - statues: [StatusEffect { - effect_id: 50, - param: 0, - duration: 50.0, - source_actor_id: connection - .player_data - .actor_id, - }; - 30], - ..Default::default() - }, - ), - ..Default::default() - }; + let lua = lua.lock().unwrap(); + lua.scope(|scope| { + let connection_data = scope + .create_userdata_ref_mut(&mut lua_player) + .unwrap(); - connection - .send_segment(PacketSegment { - source_actor: connection.player_data.actor_id, - target_actor: connection.player_data.actor_id, - segment_type: SegmentType::Ipc { data: ipc }, - }) - .await; - } + let func: Function = + lua.globals().get("doAction").unwrap(); + + func.call::<()>(connection_data).unwrap(); + + Ok(()) + }) + .unwrap(); } ClientZoneIpcData::Unk16 { .. } => { tracing::info!("Recieved Unk16!"); diff --git a/src/world/connection.rs b/src/world/connection.rs index 1046fee..08355dc 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -14,7 +14,8 @@ use super::{ Inventory, Item, Zone, ipc::{ ActorSetPos, ClientZoneIpcSegment, ContainerInfo, ContainerType, InitZone, ItemInfo, - ServerZoneIpcData, ServerZoneIpcSegment, UpdateClassInfo, WeatherChange, + ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect, StatusEffectList, UpdateClassInfo, + WeatherChange, }, }; @@ -299,6 +300,29 @@ impl LuaPlayer { segment_type: SegmentType::Ipc { data: ipc }, }); } + + fn give_status_effect(&mut self, effect_id: u16, duration: f32) { + let ipc = ServerZoneIpcSegment { + op_code: ServerZoneIpcType::StatusEffectList, + timestamp: timestamp_secs(), + data: ServerZoneIpcData::StatusEffectList(StatusEffectList { + statues: [StatusEffect { + effect_id, + param: 0, + duration, + source_actor_id: self.player_data.actor_id, + }; 30], + ..Default::default() + }), + ..Default::default() + }; + + self.queue_segment(PacketSegment { + source_actor: self.player_data.actor_id, + target_actor: self.player_data.actor_id, + segment_type: SegmentType::Ipc { data: ipc }, + }); + } } impl UserData for LuaPlayer { @@ -307,5 +331,12 @@ impl UserData for LuaPlayer { this.send_message(&message); Ok(()) }); + methods.add_method_mut( + "give_status_effect", + |_, this, (effect_id, duration): (u16, f32)| { + this.give_status_effect(effect_id, duration); + Ok(()) + }, + ); } }