diff --git a/character-service/src/character_service.rs b/character-service/src/character_service.rs index 90ff37d..d54b257 100644 --- a/character-service/src/character_service.rs +++ b/character-service/src/character_service.rs @@ -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(), diff --git a/database-service/src/characters.rs b/database-service/src/characters.rs index b9047f2..51abd39 100644 --- a/database-service/src/characters.rs +++ b/database-service/src/characters.rs @@ -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 { 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) diff --git a/database-service/src/grpc/character_service.rs b/database-service/src/grpc/character_service.rs index 32ad762..1096f5d 100644 --- a/database-service/src/grpc/character_service.rs +++ b/database-service/src/grpc/character_service.rs @@ -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(), diff --git a/packet-service/src/handlers/character.rs b/packet-service/src/handlers/character.rs index 3999861..354695a 100644 --- a/packet-service/src/handlers/character.rs +++ b/packet-service/src/handlers/character.rs @@ -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)?; diff --git a/proto/character_common.proto b/proto/character_common.proto index 44bdd27..fe7175d 100644 --- a/proto/character_common.proto +++ b/proto/character_common.proto @@ -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 } \ No newline at end of file diff --git a/proto/character_db_api.proto b/proto/character_db_api.proto index 3e28a30..611446d 100644 --- a/proto/character_db_api.proto +++ b/proto/character_db_api.proto @@ -3,61 +3,62 @@ syntax = "proto3"; package character_db_api; service CharacterDbService { - rpc GetCharacter (CharacterRequest) returns (Character); - rpc GetCharacterList (CharacterListRequest) returns (CharacterListResponse); - rpc CreateCharacter (CreateCharacterRequest) returns (CreateCharacterResponse); - rpc DeleteCharacter (DeleteCharacterRequest) returns (DeleteCharacterResponse); + rpc GetCharacter (CharacterRequest) returns (Character); + rpc GetCharacterList (CharacterListRequest) returns (CharacterListResponse); + rpc CreateCharacter (CreateCharacterRequest) returns (CreateCharacterResponse); + rpc DeleteCharacter (DeleteCharacterRequest) returns (DeleteCharacterResponse); } message CharacterRequest { - int32 user_id = 1; - int32 character_id = 2; + int32 user_id = 1; + int32 character_id = 2; } message CharacterListRequest { - int32 user_id = 1; + int32 user_id = 1; } message CharacterListResponse { - repeated Character characters = 1; + repeated Character characters = 1; } message CreateCharacterRequest { - int32 user_id = 1; - string name = 2; - string inventory = 3; // JSON serialized - string stats = 4; // JSON serialized - string looks = 5; // JSON serialized - string position = 6; // JSON serialized + int32 user_id = 1; + string name = 2; + string inventory = 3; // JSON serialized + string stats = 4; // JSON serialized + string looks = 5; // JSON serialized + string position = 6; // JSON serialized } message CreateCharacterResponse { - int32 result = 1; - int32 character_id = 2; + int32 result = 1; + int32 character_id = 2; } message DeleteCharacterRequest { - int32 user_id = 1; - int32 character_id = 2; - int32 delete_type = 3; + int32 user_id = 1; + int32 character_id = 2; + int32 delete_type = 3; } message DeleteCharacterResponse { - int64 remaining_time = 1; - string name = 2; + int64 remaining_time = 1; + string name = 2; } message Character { - int32 id = 1; - int32 user_id = 2; - string name = 3; - string inventory = 6; - string stats = 7; - string skills = 8; - string looks = 9; - string position = 10; - string created_at = 11; - string updated_at = 12; - string deleted_at = 13; - bool is_active = 14; + int32 id = 1; + int32 user_id = 2; + string name = 3; + int64 money = 4; + string inventory = 6; + string stats = 7; + string skills = 8; + string looks = 9; + string position = 10; + string created_at = 11; + string updated_at = 12; + string deleted_at = 13; + bool is_active = 14; } diff --git a/sql/schema.sql b/sql/schema.sql index 43f7198..539809c 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -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,