- add: select character now actually sends the character data to the client
- add: character data response when a character is requested from the service
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::character::character_service_client::CharacterServiceClient;
|
||||
use crate::character::{CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse, Empty, GetCharacterListRequest, GetCharacterListResponse, GetCharacterRequest};
|
||||
use crate::character::{CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse, Empty, GetCharacterListRequest, GetCharacterListResponse, GetCharacterRequest, GetCharacterResponse};
|
||||
use tonic::transport::Channel;
|
||||
use utils::null_string::NullTerminatedString;
|
||||
|
||||
@@ -48,9 +48,10 @@ impl CharacterClient {
|
||||
Ok(response.into_inner())
|
||||
}
|
||||
|
||||
pub async fn get_character(&mut self, user_id: &str, char_id: u8) -> Result<Empty, Box<dyn std::error::Error + Send + Sync>> {
|
||||
pub async fn get_character(&mut self, user_id: &str, char_id: u8) -> Result<GetCharacterResponse, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let request = GetCharacterRequest {
|
||||
user_id: char_id.to_string(),
|
||||
user_id: user_id.to_string(),
|
||||
char_id: char_id.to_string(),
|
||||
};
|
||||
|
||||
let response = self.client.get_character(request).await?;
|
||||
|
||||
@@ -67,7 +67,7 @@ pub(crate) async fn handle_char_list_req(stream: &mut TcpStream, packet: Packet,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let character_info = CharInfo {
|
||||
name: NullTerminatedString(character.name),
|
||||
race: character.looks.unwrap().race as u8,
|
||||
@@ -153,6 +153,9 @@ pub(crate) async fn handle_delete_char_req(stream: &mut TcpStream, packet: Packe
|
||||
|
||||
pub(crate) async fn handle_select_char_req(stream: &mut TcpStream, packet: Packet, character_client: Arc<Mutex<CharacterClient>>, connection_service: Arc<ConnectionService>, connection_id: String) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
use crate::packets::srv_select_char_reply::*;
|
||||
use crate::packets::srv_inventory_data::*;
|
||||
use crate::packets::srv_quest_data::*;
|
||||
use crate::packets::srv_billing_message::*;
|
||||
use crate::types::{HotbarItem, StatusEffect};
|
||||
let request = CliSelectCharReq::decode(packet.payload.as_slice())?;
|
||||
debug!("{:?}", request);
|
||||
@@ -167,50 +170,88 @@ pub(crate) async fn handle_select_char_req(stream: &mut TcpStream, packet: Packe
|
||||
|
||||
let mut character_client = character_client.lock().await;
|
||||
let character_data = character_client.get_character(&user_id.to_string(), character_id_list[request.char_id as usize]).await?;
|
||||
|
||||
let character = character_data.character.unwrap_or_default();
|
||||
|
||||
let looks = character.looks.unwrap();
|
||||
let position = character.position.unwrap();
|
||||
let stats = character.stats.unwrap();
|
||||
let items = character.items;
|
||||
let mut equipped_item_list: [EquippedItem; (MAX_VISIBLE_ITEMS as usize)] = core::array::from_fn(|i| EquippedItem::default());
|
||||
let mut inventory: [srv_inventory_data::Item; (MAX_ITEMS as usize)] = core::array::from_fn(|i| srv_inventory_data::Item::default());
|
||||
|
||||
for item in items {
|
||||
if item.slot < 10 {
|
||||
let slot = convert_slot(item.slot) as usize;
|
||||
equipped_item_list[slot] = EquippedItem {
|
||||
id: item.item_id as u16,
|
||||
gem_opt: item.gem_option as u16,
|
||||
socket: item.socket as i8,
|
||||
grade: item.grade as u8,
|
||||
};
|
||||
}
|
||||
|
||||
inventory[item.slot as usize] = srv_inventory_data::Item {
|
||||
header: srv_inventory_data::Header {
|
||||
type_: item.item_type as u8,
|
||||
id: item.item_id as u16,
|
||||
is_created:item.is_created as u8,
|
||||
},
|
||||
data: srv_inventory_data::Data {
|
||||
gem_opt: item.gem_option as u16,
|
||||
life: item.life as u16,
|
||||
durability: item.durability as u8,
|
||||
has_socket: item.socket as u8,
|
||||
is_appraised: item.is_appraised as u8,
|
||||
refine: item.grade as u8,
|
||||
count: item.count as u32,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let mut effect_list: [StatusEffect; (MAX_STATUS_EFFECTS as usize)] = core::array::from_fn(|i| StatusEffect::default());
|
||||
let mut hotbar_list: [HotbarItem; (MAX_HOTBAR_ITEMS as usize)] = core::array::from_fn(|i| HotbarItem::default());
|
||||
let data = SrvSelectCharReply {
|
||||
race: 0,
|
||||
map: 0,
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
spawn: 0,
|
||||
body_face: 0,
|
||||
body_hair: 0,
|
||||
race: looks.race as u8,
|
||||
map: position.map_id as u16,
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
spawn: position.spawn_id as u16,
|
||||
body_face: looks.face as u32,
|
||||
body_hair: looks.hair as u32,
|
||||
equipped_items: equipped_item_list,
|
||||
stone: 0,
|
||||
face: 0,
|
||||
hair: 0,
|
||||
job: 0,
|
||||
stone: looks.stone as u8,
|
||||
face: looks.face as u8,
|
||||
hair: looks.hair as u8,
|
||||
job: stats.job as u16,
|
||||
faction_id: 0,
|
||||
faction_rank: 0,
|
||||
fame: 0,
|
||||
str: 0,
|
||||
dex: 0,
|
||||
int: 0,
|
||||
con: 0,
|
||||
charm: 0,
|
||||
sense: 0,
|
||||
hp: 0,
|
||||
mp: 0,
|
||||
xp: 0,
|
||||
level: 0,
|
||||
stat_points: 0,
|
||||
skill_points: 0,
|
||||
body_size: 0,
|
||||
head_size: 0,
|
||||
penalty_xp: 0,
|
||||
str: stats.str as u16,
|
||||
dex: stats.dex as u16,
|
||||
int: stats.int as u16,
|
||||
con: stats.con as u16,
|
||||
charm: stats.charm as u16,
|
||||
sense: stats.sense as u16,
|
||||
hp: stats.hp,
|
||||
mp: stats.mp,
|
||||
xp: stats.xp as u32,
|
||||
level: stats.level as u16,
|
||||
stat_points: stats.stat_points as u32,
|
||||
skill_points: stats.skill_points as u32,
|
||||
body_size: stats.body_size as u8,
|
||||
head_size: stats.head_size as u8,
|
||||
penalty_xp: stats.penalty_xp as u32,
|
||||
faction_fame: [0u16; 2],
|
||||
faction_points: [0u16; 10],
|
||||
guild_id: 0,
|
||||
guild_contribution: 0,
|
||||
guild_rank: 0,
|
||||
pk_flag: 0,
|
||||
stamina: 0,
|
||||
stamina: stats.stamina as u16,
|
||||
effects: effect_list,
|
||||
pat_hp: 0,
|
||||
pat_cooldown_time: 0,
|
||||
pat_hp: stats.pat_hp as u16,
|
||||
pat_cooldown_time: stats.pat_cooldown_time as u32,
|
||||
skills: [0u16; (MAX_SKILL_COUNT as usize)],
|
||||
hotbar: hotbar_list,
|
||||
tag: 0,
|
||||
@@ -218,5 +259,38 @@ pub(crate) async fn handle_select_char_req(stream: &mut TcpStream, packet: Packe
|
||||
};
|
||||
let response_packet = Packet::new(PacketType::PakwcSelectCharReply, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
|
||||
// here we build the inventory
|
||||
let data = SrvInventoryData {
|
||||
zuly: 0,
|
||||
items: inventory,
|
||||
};
|
||||
let response_packet = Packet::new(PacketType::PakwcInventoryData, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
|
||||
// Now we need to build the Quest data
|
||||
let mut quests: [srv_quest_data::Quest; (MAX_QUESTS as usize)] = core::array::from_fn(|i| srv_quest_data::Quest::default());
|
||||
let mut wishlist: [srv_quest_data::Item; (MAX_WISHLIST as usize)] = core::array::from_fn(|i| srv_quest_data::Item::default());
|
||||
|
||||
let data = SrvQuestData {
|
||||
episodes: [0; (MAX_CONDITIONS_EPISODE as usize)],
|
||||
jobs: [0; (MAX_CONDITIONS_JOB as usize)],
|
||||
planets: [0; (MAX_CONDITIONS_PLANET as usize)],
|
||||
unions: [0; (MAX_CONDITIONS_UNION as usize)],
|
||||
quests,
|
||||
switches: [0; (MAX_SWITCHES as usize)],
|
||||
wishlist,
|
||||
};
|
||||
let response_packet = Packet::new(PacketType::PakwcInventoryData, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
|
||||
// Send the billing message (we don't actually use this so we just send the defaults to allow)
|
||||
let data = SrvBillingMessage {
|
||||
function_type: 0x1001,
|
||||
pay_flag: 2,
|
||||
};
|
||||
let response_packet = Packet::new(PacketType::PakwcBillingMessage, &data)?;
|
||||
send_packet(stream, &response_packet).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user