- add: money is now sent with the character data sent to the client
This commit is contained in:
@@ -124,6 +124,7 @@ impl CharacterService for MyCharacterService {
|
||||
let character = CharacterFull {
|
||||
character_id: get_character_response.id.to_string(),
|
||||
name: get_character_response.name.to_string(),
|
||||
money: get_character_response.money,
|
||||
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(),
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct Character {
|
||||
pub id: i32,
|
||||
pub user_id: i32,
|
||||
pub name: String,
|
||||
pub money: i64,
|
||||
pub inventory: serde_json::Value,
|
||||
pub stats: serde_json::Value,
|
||||
pub skills: serde_json::Value,
|
||||
@@ -48,7 +49,7 @@ impl CharacterRepository {
|
||||
|
||||
// Fetch from database
|
||||
let character = sqlx::query_as::<_, Character>(
|
||||
"SELECT id, user_id, name, inventory, stats, skills, looks, position, \
|
||||
"SELECT id, user_id, name, money, inventory, stats, skills, looks, position, \
|
||||
created_at, updated_at, extract(epoch from (deleted_at - now()))::BIGINT as deleted_at, is_active \
|
||||
FROM characters WHERE id = $1 AND is_active = true",
|
||||
)
|
||||
@@ -77,11 +78,12 @@ impl CharacterRepository {
|
||||
) -> Result<i32, sqlx::Error> {
|
||||
let default_skills = "[{\"id\": 11, \"level\": 1}, {\"id\": 12, \"level\": 1}, {\"id\": 16, \"level\": 1}, {\"id\": 19, \"level\": 1}, {\"id\": 20, \"level\": 1}, {\"id\": 21, \"level\": 1}, {\"id\": 26, \"level\": 1}, {\"id\": 41, \"level\": 1}, {\"id\": 42, \"level\": 1}, {\"id\": 43, \"level\": 1}, {\"id\": 46, \"level\": 1}, {\"id\": 47, \"level\": 1}, {\"id\": 48, \"level\": 1}, {\"id\": 49, \"level\": 1}, {\"id\": 50, \"level\": 1}]";
|
||||
let result = sqlx::query(
|
||||
"INSERT INTO characters (user_id, name, inventory, stats, skills, looks, position, created_at, updated_at, is_active) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, NOW(), NOW(), true) RETURNING id",
|
||||
"INSERT INTO characters (user_id, name, money, inventory, stats, skills, looks, position, created_at, updated_at, is_active) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW(), NOW(), true) RETURNING id",
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(name)
|
||||
.bind(0)
|
||||
.bind(inventory)
|
||||
.bind(stats)
|
||||
.bind(default_skills)
|
||||
@@ -153,7 +155,7 @@ impl CharacterRepository {
|
||||
|
||||
// Fetch from database
|
||||
let characters = sqlx::query_as::<_, Character>(
|
||||
"SELECT id, user_id, name, inventory, stats, skills, looks, position, created_at, updated_at, extract(epoch from (deleted_at - now()))::BIGINT as deleted_at, is_active FROM characters WHERE user_id = $1 AND is_active = true",
|
||||
"SELECT id, user_id, name, money, inventory, stats, skills, looks, position, created_at, updated_at, extract(epoch from (deleted_at - now()))::BIGINT as deleted_at, is_active FROM characters WHERE user_id = $1 AND is_active = true",
|
||||
)
|
||||
.bind(user_id)
|
||||
.fetch_all(&self.pool)
|
||||
|
||||
@@ -30,6 +30,7 @@ impl CharacterDbService for MyDatabaseService {
|
||||
id: character.id,
|
||||
user_id: character.user_id,
|
||||
name: character.name,
|
||||
money: character.money,
|
||||
inventory: character.inventory.to_string(),
|
||||
stats: character.stats.to_string(),
|
||||
skills: character.skills.to_string(),
|
||||
@@ -67,6 +68,7 @@ impl CharacterDbService for MyDatabaseService {
|
||||
id: character.id,
|
||||
user_id: character.user_id,
|
||||
name: character.name,
|
||||
money: character.money,
|
||||
inventory: character.inventory.to_string(),
|
||||
stats: character.stats.to_string(),
|
||||
skills: character.skills.to_string(),
|
||||
|
||||
@@ -274,6 +274,7 @@ pub(crate) async fn handle_select_char_req(
|
||||
let character = character_data.character.unwrap_or_default();
|
||||
|
||||
let name = NullTerminatedString(character.name.clone());
|
||||
let money = character.money;
|
||||
let looks = character.looks.unwrap();
|
||||
let position = character.position.unwrap();
|
||||
let stats = character.stats.unwrap();
|
||||
@@ -376,7 +377,7 @@ pub(crate) async fn handle_select_char_req(
|
||||
|
||||
// here we build the inventory
|
||||
let data = SrvInventoryData {
|
||||
zuly: 0,
|
||||
zuly: money,
|
||||
items: inventory,
|
||||
};
|
||||
let response_packet = Packet::new(PacketType::PakwcInventoryData, &data)?;
|
||||
|
||||
@@ -79,9 +79,10 @@ message Character {
|
||||
message CharacterFull {
|
||||
string character_id = 1; // Unique ID for the character
|
||||
string name = 2; // Name of the character
|
||||
Location position = 3; // Character's position
|
||||
Looks looks = 4; // Character's Looks
|
||||
Stats stats = 5; // Character's stats
|
||||
repeated Skill skills = 6; // Character's skills
|
||||
repeated Item items = 7; // Character inventory
|
||||
int64 money = 3;
|
||||
Location position = 4; // Character's position
|
||||
Looks looks = 5; // Character's Looks
|
||||
Stats stats = 6; // Character's stats
|
||||
repeated Skill skills = 7; // Character's skills
|
||||
repeated Item items = 8; // Character inventory
|
||||
}
|
||||
@@ -51,6 +51,7 @@ message Character {
|
||||
int32 id = 1;
|
||||
int32 user_id = 2;
|
||||
string name = 3;
|
||||
int64 money = 4;
|
||||
string inventory = 6;
|
||||
string stats = 7;
|
||||
string skills = 8;
|
||||
|
||||
@@ -39,6 +39,7 @@ create table characters
|
||||
on delete cascade,
|
||||
is_active boolean default true,
|
||||
name varchar(50) not null,
|
||||
money bigint default 0,
|
||||
inventory jsonb default '[]'::jsonb,
|
||||
stats jsonb default '{}'::jsonb,
|
||||
skills jsonb default '[]'::jsonb,
|
||||
|
||||
Reference in New Issue
Block a user