mirror of
https://github.com/redstrate/Kawari.git
synced 2025-06-21 07:27:45 +00:00
Refactor portions of lua.rs to reduce boilerplate
-Create common methods create_segment_self and create_segment_target. These reduce the amount of copy-paste boilerplate code since the IPC queueing stuff basically never changes as far as I can tell. Now we simply specify the opcode and the data that goes with it, and off we go. Create_segment_self retains the current behaviour of using the player's actor id as both the source and target, and create_segment_target allows us to change the source and target in case commands are written that require one or the other to be different (Sending targeted players to other coords/zones? Bringing a player to the GM/source user? Several possibilities.).
This commit is contained in:
parent
9567c8f38e
commit
749b499db6
1 changed files with 34 additions and 41 deletions
|
@ -38,25 +38,36 @@ impl LuaPlayer {
|
|||
self.queued_segments.push(segment);
|
||||
}
|
||||
|
||||
fn send_message(&mut self, message: &str) {
|
||||
fn create_segment_target(&mut self, op_code: ServerZoneIpcType, data: ServerZoneIpcData, source_actor: u32, target_actor: u32) {
|
||||
let ipc = ServerZoneIpcSegment {
|
||||
op_code: ServerZoneIpcType::ServerChatMessage,
|
||||
op_code,
|
||||
timestamp: timestamp_secs(),
|
||||
data: ServerZoneIpcData::ServerChatMessage {
|
||||
message: message.to_string(),
|
||||
unk: 0,
|
||||
},
|
||||
data,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
self.queue_segment(PacketSegment {
|
||||
source_actor: self.player_data.actor_id,
|
||||
target_actor: self.player_data.actor_id,
|
||||
source_actor,
|
||||
target_actor,
|
||||
segment_type: SegmentType::Ipc,
|
||||
data: SegmentData::Ipc { data: ipc },
|
||||
});
|
||||
}
|
||||
|
||||
fn create_segment_self(&mut self, op_code: ServerZoneIpcType, data: ServerZoneIpcData) {
|
||||
self.create_segment_target(op_code, data, self.player_data.actor_id, self.player_data.actor_id);
|
||||
}
|
||||
|
||||
fn send_message(&mut self, message: &str) {
|
||||
let op_code = ServerZoneIpcType::ServerChatMessage;
|
||||
let data = ServerZoneIpcData::ServerChatMessage {
|
||||
message: message.to_string(),
|
||||
unk: 0,
|
||||
};
|
||||
|
||||
self.create_segment_self(op_code, data);
|
||||
}
|
||||
|
||||
fn give_status_effect(&mut self, effect_id: u16, duration: f32) {
|
||||
self.status_effects.add(effect_id, duration);
|
||||
}
|
||||
|
@ -69,46 +80,28 @@ impl LuaPlayer {
|
|||
scene_flags: u32,
|
||||
param: u8,
|
||||
) {
|
||||
let ipc = ServerZoneIpcSegment {
|
||||
op_code: ServerZoneIpcType::EventScene,
|
||||
timestamp: timestamp_secs(),
|
||||
data: ServerZoneIpcData::EventScene(EventScene {
|
||||
let op_code = ServerZoneIpcType::EventScene;
|
||||
let data = ServerZoneIpcData::EventScene(EventScene {
|
||||
actor_id: target,
|
||||
event_id,
|
||||
scene,
|
||||
scene_flags,
|
||||
unk2: param,
|
||||
..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: SegmentData::Ipc { data: ipc },
|
||||
});
|
||||
|
||||
self.create_segment_self(op_code, data);
|
||||
}
|
||||
|
||||
fn set_position(&mut self, position: Position, rotation: f32) {
|
||||
let ipc = ServerZoneIpcSegment {
|
||||
op_code: ServerZoneIpcType::Warp,
|
||||
timestamp: timestamp_secs(),
|
||||
data: ServerZoneIpcData::Warp(Warp {
|
||||
let op_code = ServerZoneIpcType::Warp;
|
||||
let data = ServerZoneIpcData::Warp(Warp {
|
||||
dir: write_quantized_rotation(&rotation),
|
||||
position,
|
||||
..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: SegmentData::Ipc { data: ipc },
|
||||
});
|
||||
|
||||
self.create_segment_self(op_code, data);
|
||||
}
|
||||
|
||||
fn change_territory(&mut self, zone_id: u16) {
|
||||
|
|
Loading…
Add table
Reference in a new issue