|
|
@ -182,7 +182,7 @@ impl EntityGateway for PostgresGateway { |
|
|
|
async fn create_character(&mut self, char: NewCharacterEntity) -> Result<CharacterEntity, GatewayError> {
|
|
|
|
let q = r#"insert into player_character
|
|
|
|
(user_account, slot, name, exp, class, section_id, costume, skin, face, head, hair, hair_r, hair_g, hair_b, prop_x, prop_y, techs,
|
|
|
|
config, infoboard, guildcard, power, mind, def, evade, luck, hp, tp, tech_menu, option_flags)
|
|
|
|
config, infoboard, guildcard, option_flags, power, mind, def, evade, luck, hp, tp, tech_menu, keyboard_config, gamepad_config)
|
|
|
|
values
|
|
|
|
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31)
|
|
|
|
returning *;"#;
|
|
|
@ -207,6 +207,7 @@ impl EntityGateway for PostgresGateway { |
|
|
|
.bind(&char.config.as_bytes().to_vec())
|
|
|
|
.bind(String::from_utf16_lossy(&char.info_board.board).trim_matches(char::from(0)))
|
|
|
|
.bind(char.guildcard.description)
|
|
|
|
.bind(char.option_flags as i32)
|
|
|
|
.bind(char.materials.power as i16)
|
|
|
|
.bind(char.materials.mind as i16)
|
|
|
|
.bind(char.materials.def as i16)
|
|
|
@ -215,7 +216,8 @@ impl EntityGateway for PostgresGateway { |
|
|
|
.bind(char.materials.hp as i16)
|
|
|
|
.bind(char.materials.tp as i16)
|
|
|
|
.bind(char.tech_menu.tech_menu.to_vec())
|
|
|
|
.bind(char.option_flags as i32)
|
|
|
|
.bind(char.keyboard_config.keyboard_config.to_vec())
|
|
|
|
.bind(char.gamepad_config.gamepad_config.to_vec())
|
|
|
|
.fetch_one(&self.pool).await?;
|
|
|
|
|
|
|
|
Ok(character.into())
|
|
|
@ -548,7 +550,7 @@ impl EntityGateway for PostgresGateway { |
|
|
|
}
|
|
|
|
|
|
|
|
async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, meseta: Meseta) -> Result<(), GatewayError> {
|
|
|
|
sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set items = $2")
|
|
|
|
sqlx::query("insert into character_meseta values ($1, $2) on conflict (pchar) do update set meseta = $2")
|
|
|
|
.bind(char_id.0)
|
|
|
|
.bind(meseta.0 as i32)
|
|
|
|
.execute(&self.pool)
|
|
|
@ -559,7 +561,7 @@ impl EntityGateway for PostgresGateway { |
|
|
|
async fn get_character_meseta(&mut self, char_id: &CharacterEntityId) -> Result<Meseta, GatewayError> {
|
|
|
|
#[derive(sqlx::FromRow)]
|
|
|
|
struct PgMeseta(i32);
|
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1"#)
|
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where pchar = $1"#)
|
|
|
|
.bind(char_id.0)
|
|
|
|
.fetch_one(&self.pool)
|
|
|
|
.await?;
|
|
|
@ -567,10 +569,10 @@ impl EntityGateway for PostgresGateway { |
|
|
|
}
|
|
|
|
|
|
|
|
async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> {
|
|
|
|
sqlx::query("insert into bank_meseta values ($1, $2, $3) on conflict (pchar, bank) do update set items = $2")
|
|
|
|
sqlx::query("insert into bank_meseta values ($1, $2, $3) on conflict (pchar, bank) do update set meseta = $3")
|
|
|
|
.bind(char_id.0)
|
|
|
|
.bind(meseta.0 as i32)
|
|
|
|
.bind(bank.0)
|
|
|
|
.bind(meseta.0 as i32)
|
|
|
|
.execute(&self.pool)
|
|
|
|
.await?;
|
|
|
|
Ok(())
|
|
|
@ -579,11 +581,21 @@ impl EntityGateway for PostgresGateway { |
|
|
|
async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result<Meseta, GatewayError> {
|
|
|
|
#[derive(sqlx::FromRow)]
|
|
|
|
struct PgMeseta(i32);
|
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1 and bank = $2"#)
|
|
|
|
let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from bank_meseta where pchar = $1 and bank = $2"#)
|
|
|
|
.bind(char_id.0)
|
|
|
|
.bind(bank.0)
|
|
|
|
.fetch_one(&self.pool)
|
|
|
|
.await?;
|
|
|
|
Ok(Meseta(meseta.0 as u32))
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn set_character_exp(&mut self, char_id: &CharacterEntityId, exp: u32) -> Result<(), GatewayError> {
|
|
|
|
let q = r#"update player_character set exp=$1 where id=$2;"#;
|
|
|
|
sqlx::query(q)
|
|
|
|
.bind(exp as i32)
|
|
|
|
.bind(char_id.0 as i32)
|
|
|
|
.execute(&self.pool)
|
|
|
|
.await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|