- 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 {
|
let character = CharacterFull {
|
||||||
character_id: get_character_response.id.to_string(),
|
character_id: get_character_response.id.to_string(),
|
||||||
name: get_character_response.name.to_string(),
|
name: get_character_response.name.to_string(),
|
||||||
|
money: get_character_response.money,
|
||||||
position: serde_json::from_str(&get_character_response.position).unwrap(),
|
position: serde_json::from_str(&get_character_response.position).unwrap(),
|
||||||
looks: serde_json::from_str(&get_character_response.looks).unwrap(),
|
looks: serde_json::from_str(&get_character_response.looks).unwrap(),
|
||||||
stats: serde_json::from_str(&get_character_response.stats).unwrap(),
|
stats: serde_json::from_str(&get_character_response.stats).unwrap(),
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub struct Character {
|
|||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub user_id: i32,
|
pub user_id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub money: i64,
|
||||||
pub inventory: serde_json::Value,
|
pub inventory: serde_json::Value,
|
||||||
pub stats: serde_json::Value,
|
pub stats: serde_json::Value,
|
||||||
pub skills: serde_json::Value,
|
pub skills: serde_json::Value,
|
||||||
@@ -48,7 +49,7 @@ impl CharacterRepository {
|
|||||||
|
|
||||||
// Fetch from database
|
// Fetch from database
|
||||||
let character = sqlx::query_as::<_, Character>(
|
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 \
|
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",
|
FROM characters WHERE id = $1 AND is_active = true",
|
||||||
)
|
)
|
||||||
@@ -77,11 +78,12 @@ impl CharacterRepository {
|
|||||||
) -> Result<i32, sqlx::Error> {
|
) -> 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 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(
|
let result = sqlx::query(
|
||||||
"INSERT INTO characters (user_id, name, inventory, stats, skills, looks, position, created_at, updated_at, is_active) \
|
"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, NOW(), NOW(), true) RETURNING id",
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW(), NOW(), true) RETURNING id",
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.bind(name)
|
.bind(name)
|
||||||
|
.bind(0)
|
||||||
.bind(inventory)
|
.bind(inventory)
|
||||||
.bind(stats)
|
.bind(stats)
|
||||||
.bind(default_skills)
|
.bind(default_skills)
|
||||||
@@ -153,7 +155,7 @@ impl CharacterRepository {
|
|||||||
|
|
||||||
// Fetch from database
|
// Fetch from database
|
||||||
let characters = sqlx::query_as::<_, Character>(
|
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)
|
.bind(user_id)
|
||||||
.fetch_all(&self.pool)
|
.fetch_all(&self.pool)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ impl CharacterDbService for MyDatabaseService {
|
|||||||
id: character.id,
|
id: character.id,
|
||||||
user_id: character.user_id,
|
user_id: character.user_id,
|
||||||
name: character.name,
|
name: character.name,
|
||||||
|
money: character.money,
|
||||||
inventory: character.inventory.to_string(),
|
inventory: character.inventory.to_string(),
|
||||||
stats: character.stats.to_string(),
|
stats: character.stats.to_string(),
|
||||||
skills: character.skills.to_string(),
|
skills: character.skills.to_string(),
|
||||||
@@ -67,6 +68,7 @@ impl CharacterDbService for MyDatabaseService {
|
|||||||
id: character.id,
|
id: character.id,
|
||||||
user_id: character.user_id,
|
user_id: character.user_id,
|
||||||
name: character.name,
|
name: character.name,
|
||||||
|
money: character.money,
|
||||||
inventory: character.inventory.to_string(),
|
inventory: character.inventory.to_string(),
|
||||||
stats: character.stats.to_string(),
|
stats: character.stats.to_string(),
|
||||||
skills: character.skills.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 character = character_data.character.unwrap_or_default();
|
||||||
|
|
||||||
let name = NullTerminatedString(character.name.clone());
|
let name = NullTerminatedString(character.name.clone());
|
||||||
|
let money = character.money;
|
||||||
let looks = character.looks.unwrap();
|
let looks = character.looks.unwrap();
|
||||||
let position = character.position.unwrap();
|
let position = character.position.unwrap();
|
||||||
let stats = character.stats.unwrap();
|
let stats = character.stats.unwrap();
|
||||||
@@ -376,7 +377,7 @@ pub(crate) async fn handle_select_char_req(
|
|||||||
|
|
||||||
// here we build the inventory
|
// here we build the inventory
|
||||||
let data = SrvInventoryData {
|
let data = SrvInventoryData {
|
||||||
zuly: 0,
|
zuly: money,
|
||||||
items: inventory,
|
items: inventory,
|
||||||
};
|
};
|
||||||
let response_packet = Packet::new(PacketType::PakwcInventoryData, &data)?;
|
let response_packet = Packet::new(PacketType::PakwcInventoryData, &data)?;
|
||||||
|
|||||||
@@ -79,9 +79,10 @@ message Character {
|
|||||||
message CharacterFull {
|
message CharacterFull {
|
||||||
string character_id = 1; // Unique ID for the character
|
string character_id = 1; // Unique ID for the character
|
||||||
string name = 2; // Name of the character
|
string name = 2; // Name of the character
|
||||||
Location position = 3; // Character's position
|
int64 money = 3;
|
||||||
Looks looks = 4; // Character's Looks
|
Location position = 4; // Character's position
|
||||||
Stats stats = 5; // Character's stats
|
Looks looks = 5; // Character's Looks
|
||||||
repeated Skill skills = 6; // Character's skills
|
Stats stats = 6; // Character's stats
|
||||||
repeated Item items = 7; // Character inventory
|
repeated Skill skills = 7; // Character's skills
|
||||||
|
repeated Item items = 8; // Character inventory
|
||||||
}
|
}
|
||||||
@@ -3,61 +3,62 @@ syntax = "proto3";
|
|||||||
package character_db_api;
|
package character_db_api;
|
||||||
|
|
||||||
service CharacterDbService {
|
service CharacterDbService {
|
||||||
rpc GetCharacter (CharacterRequest) returns (Character);
|
rpc GetCharacter (CharacterRequest) returns (Character);
|
||||||
rpc GetCharacterList (CharacterListRequest) returns (CharacterListResponse);
|
rpc GetCharacterList (CharacterListRequest) returns (CharacterListResponse);
|
||||||
rpc CreateCharacter (CreateCharacterRequest) returns (CreateCharacterResponse);
|
rpc CreateCharacter (CreateCharacterRequest) returns (CreateCharacterResponse);
|
||||||
rpc DeleteCharacter (DeleteCharacterRequest) returns (DeleteCharacterResponse);
|
rpc DeleteCharacter (DeleteCharacterRequest) returns (DeleteCharacterResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
message CharacterRequest {
|
message CharacterRequest {
|
||||||
int32 user_id = 1;
|
int32 user_id = 1;
|
||||||
int32 character_id = 2;
|
int32 character_id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CharacterListRequest {
|
message CharacterListRequest {
|
||||||
int32 user_id = 1;
|
int32 user_id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CharacterListResponse {
|
message CharacterListResponse {
|
||||||
repeated Character characters = 1;
|
repeated Character characters = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateCharacterRequest {
|
message CreateCharacterRequest {
|
||||||
int32 user_id = 1;
|
int32 user_id = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
string inventory = 3; // JSON serialized
|
string inventory = 3; // JSON serialized
|
||||||
string stats = 4; // JSON serialized
|
string stats = 4; // JSON serialized
|
||||||
string looks = 5; // JSON serialized
|
string looks = 5; // JSON serialized
|
||||||
string position = 6; // JSON serialized
|
string position = 6; // JSON serialized
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateCharacterResponse {
|
message CreateCharacterResponse {
|
||||||
int32 result = 1;
|
int32 result = 1;
|
||||||
int32 character_id = 2;
|
int32 character_id = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteCharacterRequest {
|
message DeleteCharacterRequest {
|
||||||
int32 user_id = 1;
|
int32 user_id = 1;
|
||||||
int32 character_id = 2;
|
int32 character_id = 2;
|
||||||
int32 delete_type = 3;
|
int32 delete_type = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteCharacterResponse {
|
message DeleteCharacterResponse {
|
||||||
int64 remaining_time = 1;
|
int64 remaining_time = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Character {
|
message Character {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
int32 user_id = 2;
|
int32 user_id = 2;
|
||||||
string name = 3;
|
string name = 3;
|
||||||
string inventory = 6;
|
int64 money = 4;
|
||||||
string stats = 7;
|
string inventory = 6;
|
||||||
string skills = 8;
|
string stats = 7;
|
||||||
string looks = 9;
|
string skills = 8;
|
||||||
string position = 10;
|
string looks = 9;
|
||||||
string created_at = 11;
|
string position = 10;
|
||||||
string updated_at = 12;
|
string created_at = 11;
|
||||||
string deleted_at = 13;
|
string updated_at = 12;
|
||||||
bool is_active = 14;
|
string deleted_at = 13;
|
||||||
|
bool is_active = 14;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ create table characters
|
|||||||
on delete cascade,
|
on delete cascade,
|
||||||
is_active boolean default true,
|
is_active boolean default true,
|
||||||
name varchar(50) not null,
|
name varchar(50) not null,
|
||||||
|
money bigint default 0,
|
||||||
inventory jsonb default '[]'::jsonb,
|
inventory jsonb default '[]'::jsonb,
|
||||||
stats jsonb default '{}'::jsonb,
|
stats jsonb default '{}'::jsonb,
|
||||||
skills jsonb default '[]'::jsonb,
|
skills jsonb default '[]'::jsonb,
|
||||||
|
|||||||
Reference in New Issue
Block a user