mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-19 22:36:49 +00:00
Begin wiring status effect Lua API
This commit is contained in:
parent
652beadaa4
commit
c5e04ba33f
3 changed files with 50 additions and 30 deletions
|
@ -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
|
||||
|
|
|
@ -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!");
|
||||
|
|
|
@ -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(())
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue