Character service now only returns items that are equipped when getting the character list

Updated inventory items to match what the client is expecting (Header, Data)
This commit is contained in:
2025-06-24 14:07:01 -04:00
parent 69bbafa60a
commit 72949da095
2 changed files with 44 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ use crate::database::{
use serde::{Deserialize, Serialize};
use tonic::transport::Channel;
use crate::character_service::character_common::{Item, ItemHeader};
#[derive(Clone)]
pub struct CharacterDbClient {
@@ -16,20 +17,20 @@ struct Skill {
id: i32,
}
#[derive(Debug, Deserialize, Serialize)]
struct Item {
item_id: i32,
item_type: 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)]
// struct Item {
// item_id: i32,
// item_type: 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)]
struct Looks {
@@ -119,9 +120,11 @@ impl CharacterDbClient {
let inventory = vec![
Item {
item_id: 30,
item_type: 3,
is_created: 0,
header: Some(ItemHeader {
r#type: 3,
id: 30,
is_created: 0,
}),
gem_option: 0,
durability: 45.0,
life: 100.0,
@@ -132,9 +135,11 @@ impl CharacterDbClient {
slot: 3,
},
Item {
item_id: 1,
item_type: 8,
is_created: 0,
header: Some(ItemHeader {
r#type: 8,
id: 1,
is_created: 0,
}),
gem_option: 0,
durability: 45.0,
life: 100.0,
@@ -145,9 +150,11 @@ impl CharacterDbClient {
slot: 7,
},
Item {
item_id: hatid,
item_type: 2,
is_created: 0,
header: Some(ItemHeader {
r#type: 2,
id: hatid,
is_created: 0,
}),
gem_option: 0,
durability: 45.0,
life: 100.0,

View File

@@ -42,6 +42,19 @@ impl CharacterService for MyCharacterService {
let mut characters: Vec<Character> = vec![];
for character in character_list.characters {
let mut equipped_items: Vec<character_common::EquippedItem> = vec![];
let inventory: Vec<character_common::Item> = serde_json::from_str(&character.inventory).unwrap();
for item in inventory {
if item.slot < 12 {
equipped_items.push(character_common::EquippedItem {
item_id: item.header.unwrap().id,
socket: item.socket,
grade: item.grade,
gem_option: item.gem_option,
slot: item.slot,
});
}
}
characters.push(Character {
character_id: character.id.to_string(),
name: character.name,
@@ -49,7 +62,7 @@ impl CharacterService for MyCharacterService {
delete_time: character.deleted_at.parse().unwrap_or_default(),
stats: serde_json::from_str(&character.stats).unwrap(),
looks: serde_json::from_str(&character.looks).unwrap(),
items: serde_json::from_str(&character.inventory).unwrap(),
items: equipped_items,
})
}