1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-20 06:37:45 +00:00

Add script for Fast Blade action

This adds the necessary infrastructure to add actions that deal damage to
enemies, and tests this through the new effects builder exposed through Lua.
This commit is contained in:
Joshua Goins 2025-03-30 09:29:36 -04:00
parent d8627c646e
commit e8581cdaba
6 changed files with 64 additions and 13 deletions

View file

@ -4,3 +4,4 @@ function onBeginLogin(player)
end
registerAction(3, "actions/Sprint.lua")
registerAction(9, "actions/FastBlade.lua")

View file

@ -0,0 +1,6 @@
function doAction(player)
effects = EffectsBuilder()
effects:damage(20)
return effects
end

View file

@ -1,4 +1,9 @@
function doAction(player)
effects = EffectsBuilder()
-- TODO: go through effectsbuilder
-- give sprint
player:give_status_effect(50, 5.0)
return effects
end

View file

@ -27,7 +27,7 @@ use kawari::world::{
SocialList,
},
};
use kawari::world::{LuaPlayer, PlayerData, StatusEffects, WorldDatabase};
use kawari::world::{EffectsBuilder, LuaPlayer, PlayerData, StatusEffects, WorldDatabase};
use mlua::{Function, Lua};
use physis::common::{Language, Platform};
use physis::gamedata::GameData;
@ -71,6 +71,13 @@ async fn main() {
.set("registerAction", register_action_func)
.unwrap();
let effectsbuilder_constructor = lua
.create_function(|_, ()| Ok(EffectsBuilder::default()))
.unwrap();
lua.globals()
.set("EffectsBuilder", effectsbuilder_constructor)
.unwrap();
let file_name = format!("{}/Global.lua", &config.world.scripts_location);
lua.load(std::fs::read(&file_name).expect("Failed to locate scripts directory!"))
.set_name("@".to_string() + &file_name)
@ -778,6 +785,8 @@ async fn main() {
.await;
}
let mut effects_builder = None;
// run action script
{
let lua = lua.lock().unwrap();
@ -807,7 +816,12 @@ async fn main() {
let func: Function =
lua.globals().get("doAction").unwrap();
func.call::<()>(connection_data).unwrap();
effects_builder = Some(
func.call::<EffectsBuilder>(
connection_data,
)
.unwrap(),
);
Ok(())
})
@ -816,14 +830,10 @@ async fn main() {
}
// tell them the action results
{
if let Some(effects_builder) = effects_builder {
let mut effects = [ActionEffect::default(); 8];
effects[0] = ActionEffect {
action_type: 3,
value: 22,
param1: 133,
..Default::default()
};
effects[..effects_builder.effects.len()]
.copy_from_slice(&effects_builder.effects);
let ipc = ServerZoneIpcSegment {
op_code: ServerZoneIpcType::ActionResult,
@ -843,7 +853,8 @@ async fn main() {
rotation: connection.player_data.rotation,
action_animation_id: 31,
flag: 1,
effect_count: 1,
effect_count: effects_builder.effects.len()
as u8,
effects,
..Default::default()
},

View file

@ -1,4 +1,4 @@
use mlua::{FromLua, Lua, UserData, UserDataMethods, Value};
use mlua::{FromLua, Lua, MetaMethod, UserData, UserDataMethods, Value};
use crate::{
common::{ObjectId, ObjectTypeId, Position, timestamp_secs},
@ -8,7 +8,7 @@ use crate::{
use super::{
PlayerData, StatusEffects, Zone,
ipc::{ActorSetPos, EventPlay, ServerZoneIpcData, ServerZoneIpcSegment},
ipc::{ActionEffect, ActorSetPos, EventPlay, ServerZoneIpcData, ServerZoneIpcSegment},
};
pub struct ChangeTerritoryTask {
@ -161,3 +161,31 @@ impl UserData for Zone {
);
}
}
#[derive(Clone, Debug, Default)]
pub struct EffectsBuilder {
pub effects: Vec<ActionEffect>,
}
impl UserData for EffectsBuilder {
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
methods.add_method_mut("damage", |_, this, amount: u16| {
this.effects.push(ActionEffect {
action_type: 3,
value: amount,
param1: 133,
..Default::default()
});
Ok(())
});
}
}
impl FromLua for EffectsBuilder {
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
match value {
Value::UserData(ud) => Ok(ud.borrow::<Self>()?.clone()),
_ => unreachable!(),
}
}
}

View file

@ -16,7 +16,7 @@ mod inventory;
pub use inventory::{EquippedContainer, Inventory, Item};
mod lua;
pub use lua::LuaPlayer;
pub use lua::{EffectsBuilder, LuaPlayer};
mod event;
pub use event::Event;