From 6ed0d838d28580ae28d1ba2d29ed28b5d67bf7e6 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 14 Oct 2021 00:16:22 -0600 Subject: [PATCH] add gateway function set_character_meseta --- src/entity/gateway/entitygateway.rs | 4 ++++ src/entity/gateway/inmemory.rs | 8 ++++++++ src/entity/gateway/postgres/postgres.rs | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/src/entity/gateway/entitygateway.rs b/src/entity/gateway/entitygateway.rs index 261aadc..27cc5d5 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/src/entity/gateway/entitygateway.rs @@ -115,4 +115,8 @@ pub trait EntityGateway: Send + Sync + Clone { async fn set_character_equips(&mut self, _char_id: &CharacterEntityId, _equips: &EquippedEntity) -> Result<(), GatewayError> { unimplemented!(); } + + async fn set_character_meseta(&mut self, _char_id: &CharacterEntityId, amount: usize) -> Result<(), GatewayError> { + unimplemented!(); + } } diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index d80dca7..4a95b52 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -318,4 +318,12 @@ impl EntityGateway for InMemoryGateway { equips.insert(*char_id, equipped.clone()); Ok(()) } + + async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, amount: usize) -> Result<(), GatewayError> { + let mut characters = self.characters.lock().unwrap(); + if let Some(char) = characters.get_mut(&char_id) { + char.meseta = amount as u32; + } + Ok(()) + } } diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 53609cf..4f872c4 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -597,4 +597,13 @@ impl EntityGateway for PostgresGateway { .await?; Ok(()) } + + async fn set_character_meseta(&mut self, char_id: &CharacterEntityId, amount: usize) -> Result<(), GatewayError> { + sqlx::query(r#"update player_character set meseta=$2 where id = $1"#) + .bind(char_id.0) + .bind(amount as i32) + .execute(&self.pool) + .await?; + Ok(()) + } }