- 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:
@@ -12,12 +12,15 @@ pub struct CharacterDbClient {
|
||||
struct Item {
|
||||
item_id: i32,
|
||||
item_type: i32,
|
||||
count: i32,
|
||||
durability: f32,
|
||||
slot: i32,
|
||||
is_created: i32,
|
||||
gem_option: i32,
|
||||
durability: f32,
|
||||
life: f32,
|
||||
socket: i8,
|
||||
is_appraised: i8,
|
||||
grade: u32,
|
||||
count: i32,
|
||||
slot: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
@@ -25,6 +28,7 @@ struct Looks {
|
||||
race: i32,
|
||||
face: i32,
|
||||
hair: i32,
|
||||
stone: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
@@ -33,6 +37,7 @@ struct Position {
|
||||
x: f64,
|
||||
y: f64,
|
||||
z: f64,
|
||||
spawn_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
@@ -48,7 +53,7 @@ struct Stats {
|
||||
hp: i32,
|
||||
max_mp: i32,
|
||||
mp: i32,
|
||||
xp: u32,
|
||||
xp: u64,
|
||||
level: u16,
|
||||
head_size: u8,
|
||||
body_size: u8,
|
||||
@@ -93,32 +98,41 @@ impl CharacterDbClient {
|
||||
Item {
|
||||
item_id: 30,
|
||||
item_type: 3,
|
||||
count: 1,
|
||||
slot: 3,
|
||||
durability: 45.0,
|
||||
is_created: 0,
|
||||
gem_option: 0,
|
||||
durability: 45.0,
|
||||
life: 100.0,
|
||||
socket: 0,
|
||||
grade: 0,
|
||||
is_appraised: 0,
|
||||
count: 1,
|
||||
slot: 3,
|
||||
},
|
||||
Item {
|
||||
item_id: 1,
|
||||
item_type: 8,
|
||||
count: 1,
|
||||
slot: 7,
|
||||
durability: 45.0,
|
||||
is_created: 0,
|
||||
gem_option: 0,
|
||||
durability: 45.0,
|
||||
life: 100.0,
|
||||
socket: 0,
|
||||
grade: 0,
|
||||
is_appraised: 0,
|
||||
count: 1,
|
||||
slot: 7,
|
||||
},
|
||||
Item {
|
||||
item_id: hatid,
|
||||
item_type: 2,
|
||||
count: 1,
|
||||
slot: 12,
|
||||
durability: 45.0,
|
||||
is_created: 0,
|
||||
gem_option: 0,
|
||||
durability: 45.0,
|
||||
life: 100.0,
|
||||
socket: 0,
|
||||
grade: 0,
|
||||
is_appraised: 0,
|
||||
count: 1,
|
||||
slot: 12,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -146,8 +160,8 @@ impl CharacterDbClient {
|
||||
pat_cooldown_time: 0,
|
||||
};
|
||||
|
||||
let looks = Looks {race, face, hair};
|
||||
let position = Position {map_id: 20, x: 5200.00, y: 5200.00, z: 1.0};
|
||||
let looks = Looks {race, face, hair, stone};
|
||||
let position = Position {map_id: 20, x: 5200.00, y: 5200.00, z: 1.0, spawn_id: 1};
|
||||
|
||||
let request = tonic::Request::new(CreateCharacterRequest {
|
||||
user_id: user_id.parse().unwrap(),
|
||||
|
||||
@@ -4,8 +4,8 @@ use tonic::{Request, Response, Status};
|
||||
use utils::null_string::NullTerminatedString;
|
||||
use crate::character_db_client::CharacterDbClient;
|
||||
use crate::character_service::character::character_service_server::CharacterService;
|
||||
use crate::character_service::character::{CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse, Empty, GetCharacterListRequest, GetCharacterListResponse, GetCharacterRequest};
|
||||
use crate::character_service::character_common::{Character, Looks, Stats};
|
||||
use crate::character_service::character::{CreateCharacterRequest, CreateCharacterResponse, DeleteCharacterRequest, DeleteCharacterResponse, Empty, GetCharacterListRequest, GetCharacterListResponse, GetCharacterRequest, GetCharacterResponse};
|
||||
use crate::character_service::character_common::{Character, CharacterFull, Looks, Stats};
|
||||
|
||||
pub mod character_common {
|
||||
tonic::include_proto!("character_common");
|
||||
@@ -71,9 +71,21 @@ impl CharacterService for MyCharacterService {
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
|
||||
async fn get_character(&self, request: Request<GetCharacterRequest>) -> Result<Response<Empty>, Status> {
|
||||
async fn get_character(&self, request: Request<GetCharacterRequest>) -> Result<Response<GetCharacterResponse>, Status> {
|
||||
let req = request.into_inner();
|
||||
debug!("{:?}", req);
|
||||
Ok(Response::new(Empty{}))
|
||||
let get_character_response = self.character_db_client.as_ref().clone().get_character(&req.user_id, &req.char_id).await.map_err(|_| Status::not_found("Character not found"))?;
|
||||
|
||||
let character = CharacterFull {
|
||||
character_id: get_character_response.id.to_string(),
|
||||
name: get_character_response.name.to_string(),
|
||||
position: serde_json::from_str(&get_character_response.position).unwrap(),
|
||||
looks: serde_json::from_str(&get_character_response.looks).unwrap(),
|
||||
stats: serde_json::from_str(&get_character_response.stats).unwrap(),
|
||||
items: serde_json::from_str(&get_character_response.inventory).unwrap(),
|
||||
};
|
||||
|
||||
let response = GetCharacterResponse { character: Some(character) };
|
||||
Ok(Response::new(response))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user