mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-30 11:47:45 +00:00
parent
6b0487f30f
commit
a6e270d5e3
2 changed files with 61 additions and 37 deletions
|
@ -573,15 +573,21 @@ async fn client_loop(
|
|||
} else {
|
||||
tracing::info!("Unknown command {command_name}");
|
||||
|
||||
let mut call_func = || {
|
||||
lua.scope(|scope| {
|
||||
let connection_data = scope
|
||||
.create_userdata_ref_mut(&mut lua_player)
|
||||
.unwrap();
|
||||
.create_userdata_ref_mut(&mut lua_player)?;;
|
||||
let func: Function =
|
||||
lua.globals().get("onUnknownCommandError").unwrap();
|
||||
func.call::<()>((command_name, connection_data)).unwrap();
|
||||
lua.globals().get("onUnknownCommandError")?;
|
||||
func.call::<()>((command_name, connection_data))?;
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
})
|
||||
};
|
||||
|
||||
if let Err(err) = call_func() {
|
||||
tracing::warn!("Lua error in Global.lua: {:?}", err);
|
||||
handled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ use crate::{common::ObjectTypeId, config::get_config};
|
|||
use super::{LuaPlayer, Zone};
|
||||
|
||||
pub struct Event {
|
||||
file_name: String,
|
||||
lua: Lua,
|
||||
}
|
||||
|
||||
|
@ -14,70 +15,87 @@ impl Event {
|
|||
|
||||
let config = get_config();
|
||||
let file_name = format!("{}/{}", &config.world.scripts_location, path);
|
||||
lua.load(std::fs::read(&file_name).expect("Failed to locate scripts directory!"))
|
||||
|
||||
if let Err(err) = lua
|
||||
.load(std::fs::read(&file_name).expect("Failed to locate scripts directory!"))
|
||||
.set_name("@".to_string() + &file_name)
|
||||
.exec()
|
||||
.unwrap();
|
||||
{
|
||||
tracing::warn!("Syntax error in {}: {:?}", file_name, err);
|
||||
return Self { file_name, lua };
|
||||
}
|
||||
|
||||
lua.globals().set("EVENT_ID", id).unwrap();
|
||||
|
||||
Self { lua }
|
||||
Self { file_name, lua }
|
||||
}
|
||||
|
||||
pub fn enter_territory(&mut self, player: &mut LuaPlayer, zone: &Zone) {
|
||||
self.lua
|
||||
.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player).unwrap();
|
||||
let zone = scope.create_userdata_ref(zone).unwrap();
|
||||
let mut run_script = || {
|
||||
self.lua.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player)?;
|
||||
let zone = scope.create_userdata_ref(zone)?;
|
||||
|
||||
let func: Function = self.lua.globals().get("onEnterTerritory").unwrap();
|
||||
let func: Function = self.lua.globals().get("onEnterTerritory")?;
|
||||
|
||||
func.call::<()>((player, zone)).unwrap();
|
||||
func.call::<()>((player, zone))?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
if let Err(err) = run_script() {
|
||||
tracing::warn!("Syntax error in {}: {:?}", self.file_name, err);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scene_finished(&mut self, player: &mut LuaPlayer, scene: u16) {
|
||||
self.lua
|
||||
.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player).unwrap();
|
||||
let mut run_script = || {
|
||||
self.lua.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player)?;
|
||||
|
||||
let func: Function = self.lua.globals().get("onSceneFinished").unwrap();
|
||||
let func: Function = self.lua.globals().get("onSceneFinished")?;
|
||||
|
||||
func.call::<()>((player, scene)).unwrap();
|
||||
func.call::<()>((player, scene))?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
if let Err(err) = run_script() {
|
||||
tracing::warn!("Syntax error in {}: {:?}", self.file_name, err);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn talk(&mut self, target_id: ObjectTypeId, player: &mut LuaPlayer) {
|
||||
self.lua
|
||||
.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player).unwrap();
|
||||
let mut run_script = || {
|
||||
self.lua.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player)?;
|
||||
|
||||
let func: Function = self.lua.globals().get("onTalk").unwrap();
|
||||
let func: Function = self.lua.globals().get("onTalk")?;
|
||||
|
||||
func.call::<()>((target_id, player)).unwrap();
|
||||
func.call::<()>((target_id, player))?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
if let Err(err) = run_script() {
|
||||
tracing::warn!("Syntax error in {}: {:?}", self.file_name, err);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn finish(&mut self, scene: u16, results: &[u32], player: &mut LuaPlayer) {
|
||||
self.lua
|
||||
.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player).unwrap();
|
||||
let mut run_script = || {
|
||||
self.lua.scope(|scope| {
|
||||
let player = scope.create_userdata_ref_mut(player)?;
|
||||
|
||||
let func: Function = self.lua.globals().get("onReturn").unwrap();
|
||||
let func: Function = self.lua.globals().get("onReturn")?;
|
||||
|
||||
func.call::<()>((scene, results, player)).unwrap();
|
||||
func.call::<()>((scene, results, player))?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
};
|
||||
if let Err(err) = run_script() {
|
||||
tracing::warn!("Syntax error in {}: {:?}", self.file_name, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue