- update: default skills are set by the character service, not the database service
This commit is contained in:
@@ -12,6 +12,11 @@ pub struct CharacterDbClient {
|
|||||||
client: CharacterDbServiceClient<Channel>,
|
client: CharacterDbServiceClient<Channel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
struct Skill {
|
||||||
|
id: i32,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
struct Item {
|
struct Item {
|
||||||
item_id: i32,
|
item_id: i32,
|
||||||
@@ -155,6 +160,24 @@ impl CharacterDbClient {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let skills = vec![
|
||||||
|
Skill { id: 11 },
|
||||||
|
Skill { id: 12 },
|
||||||
|
Skill { id: 16 },
|
||||||
|
Skill { id: 19 },
|
||||||
|
Skill { id: 20 },
|
||||||
|
Skill { id: 21 },
|
||||||
|
Skill { id: 26 },
|
||||||
|
Skill { id: 41 },
|
||||||
|
Skill { id: 42 },
|
||||||
|
Skill { id: 43 },
|
||||||
|
Skill { id: 46 },
|
||||||
|
Skill { id: 47 },
|
||||||
|
Skill { id: 48 },
|
||||||
|
Skill { id: 49 },
|
||||||
|
Skill { id: 60 },
|
||||||
|
];
|
||||||
|
|
||||||
let stats = Stats {
|
let stats = Stats {
|
||||||
job: 0,
|
job: 0,
|
||||||
str: 10,
|
str: 10,
|
||||||
@@ -197,6 +220,7 @@ impl CharacterDbClient {
|
|||||||
user_id: user_id.parse().unwrap(),
|
user_id: user_id.parse().unwrap(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
inventory: serde_json::to_value(inventory)?.to_string(),
|
inventory: serde_json::to_value(inventory)?.to_string(),
|
||||||
|
skills: serde_json::to_value(skills)?.to_string(),
|
||||||
stats: serde_json::to_value(stats)?.to_string(),
|
stats: serde_json::to_value(stats)?.to_string(),
|
||||||
looks: serde_json::to_value(looks)?.to_string(),
|
looks: serde_json::to_value(looks)?.to_string(),
|
||||||
position: serde_json::to_value(position)?.to_string(),
|
position: serde_json::to_value(position)?.to_string(),
|
||||||
|
|||||||
@@ -72,21 +72,20 @@ impl CharacterRepository {
|
|||||||
user_id: i32,
|
user_id: i32,
|
||||||
name: &str,
|
name: &str,
|
||||||
inventory: serde_json::Value,
|
inventory: serde_json::Value,
|
||||||
|
skills: serde_json::Value,
|
||||||
stats: serde_json::Value,
|
stats: serde_json::Value,
|
||||||
looks: serde_json::Value,
|
looks: serde_json::Value,
|
||||||
position: serde_json::Value,
|
position: serde_json::Value,
|
||||||
) -> 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 result = sqlx::query(
|
let result = sqlx::query(
|
||||||
"INSERT INTO characters (user_id, name, money, inventory, stats, skills, looks, position, created_at, updated_at, is_active) \
|
"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, $8, NOW(), NOW(), true) RETURNING id",
|
VALUES ($1, $2, $3, $4, $5, $6, $7, 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(skills)
|
||||||
.bind(looks)
|
.bind(looks)
|
||||||
.bind(position)
|
.bind(position)
|
||||||
.fetch_one(&self.pool)
|
.fetch_one(&self.pool)
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ impl CharacterDbService for MyDatabaseService {
|
|||||||
req.user_id,
|
req.user_id,
|
||||||
&req.name,
|
&req.name,
|
||||||
serde_json::from_str(&req.inventory).unwrap_or_default(),
|
serde_json::from_str(&req.inventory).unwrap_or_default(),
|
||||||
|
serde_json::from_str(&req.skills).unwrap_or_default(),
|
||||||
serde_json::from_str(&req.stats).unwrap_or_default(),
|
serde_json::from_str(&req.stats).unwrap_or_default(),
|
||||||
serde_json::from_str(&req.looks).unwrap_or_default(),
|
serde_json::from_str(&req.looks).unwrap_or_default(),
|
||||||
serde_json::from_str(&req.position).unwrap_or_default(),
|
serde_json::from_str(&req.position).unwrap_or_default(),
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ 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 skills = 4; // JSON serialized
|
||||||
string looks = 5; // JSON serialized
|
string stats = 5; // JSON serialized
|
||||||
string position = 6; // JSON serialized
|
string looks = 6; // JSON serialized
|
||||||
|
string position = 7; // JSON serialized
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateCharacterResponse {
|
message CreateCharacterResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user