1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-05-04 12:07:44 +00:00
kawari/src/world/event.rs
Joshua Goins 2bf9385079 Load the starting position from the LGB
It turns out (amazingly) that this data exists client-side, I guess because the
server and the client share the same planevent LGB file. So instead of
hardcoding the starting location in each city, it's now literally like retail*

* Except for the fact that we don't support rotation yet, and positions in pop
ranges are probably randomized too. But it's close!
2025-03-28 23:00:32 -04:00

53 lines
1.4 KiB
Rust

use mlua::{Function, Lua};
use crate::config::get_config;
use super::{LuaPlayer, Zone};
pub struct Event {
lua: Lua,
}
impl Event {
pub fn new(path: &str) -> Self {
let lua = Lua::new();
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!"))
.set_name("@".to_string() + &file_name)
.exec()
.unwrap();
Self { 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 func: Function = self.lua.globals().get("onEnterTerritory").unwrap();
func.call::<()>((player, zone)).unwrap();
Ok(())
})
.unwrap();
}
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 func: Function = self.lua.globals().get("onSceneFinished").unwrap();
func.call::<()>((player, scene)).unwrap();
Ok(())
})
.unwrap();
}
}