From 2aa8dae9b2eb18b0c971d459bd36ae22e96d6b30 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 14 May 2022 13:02:23 -0600 Subject: [PATCH] entitygateway stuff should take &BankName not BankName --- src/bin/main.rs | 7 +- src/entity/gateway/entitygateway.rs | 8 +-- src/entity/gateway/inmemory.rs | 12 ++-- src/entity/gateway/postgres/postgres.rs | 32 ++++----- src/login/character.rs | 2 +- src/ship/items/manager.rs | 8 +-- src/ship/items/state.rs | 2 +- tests/common.rs | 2 +- tests/test_bank.rs | 92 +++++++++++++------------ 9 files changed, 86 insertions(+), 79 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 3ce4ed7..f32d88e 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -69,14 +69,15 @@ fn main() { character.name = format!("Test Char {}", i*2); let character = entity_gateway.create_character(character).await.unwrap(); entity_gateway.set_character_meseta(&character.id, item::Meseta(999999)).await.unwrap(); - entity_gateway.set_bank_meseta(&character.id, item::BankName("".into()), item::Meseta(999999)).await.unwrap(); + let mut character = NewCharacterEntity::new(fake_user.id); + entity_gateway.set_bank_meseta(&character.id, &item::BankName("".into()), item::Meseta(999999)).await.unwrap(); let mut character = NewCharacterEntity::new(fake_user.id, 1); character.slot = 2; character.name = "ItemRefactor".into(); character.exp = 80000000; let character = entity_gateway.create_character(character).await.unwrap(); entity_gateway.set_character_meseta(&character.id, item::Meseta(999999)).await.unwrap(); - entity_gateway.set_bank_meseta(&character.id, item::BankName("".into()), item::Meseta(999999)).await.unwrap(); + entity_gateway.set_bank_meseta(&character.id, &item::BankName("".into()), item::Meseta(999999)).await.unwrap(); for _ in 0..3 { entity_gateway.create_item( @@ -347,7 +348,7 @@ fn main() { let inventory = item::InventoryEntity::new(vec![InventoryItemEntity::from(item0), item1.into(), item2_w.into(), item3.into(), item4.into(), item5_m.into(), item6.into(), item6_1.into(), item7_a.into(), item8_s.into(), item9_u0.into(), item10_u1.into(), item11_u2.into(), item12_u3.into(), item13.into(), item14.into(), monomates.into()]); entity_gateway.set_character_inventory(&character.id, &inventory).await.unwrap(); - entity_gateway.set_character_bank(&character.id, &item::BankEntity::default(), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&character.id, &item::BankEntity::default(), &item::BankName("".into())).await.unwrap(); } info!("[patch] starting server"); diff --git a/src/entity/gateway/entitygateway.rs b/src/entity/gateway/entitygateway.rs index a472973..8805b4f 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/src/entity/gateway/entitygateway.rs @@ -118,7 +118,7 @@ pub trait EntityGateway: Send + Sync { unimplemented!(); } - async fn get_character_bank(&mut self, _char_id: &CharacterEntityId, _bank_name: BankName) -> Result { + async fn get_character_bank(&mut self, _char_id: &CharacterEntityId, _bank_name: &BankName) -> Result { unimplemented!(); } @@ -126,7 +126,7 @@ pub trait EntityGateway: Send + Sync { unimplemented!(); } - async fn set_character_bank(&mut self, _char_id: &CharacterEntityId, _inventory: &BankEntity, _bank_name: BankName) -> Result<(), GatewayError> { + async fn set_character_bank(&mut self, _char_id: &CharacterEntityId, _inventory: &BankEntity, _bank_name: &BankName) -> Result<(), GatewayError> { unimplemented!(); } @@ -146,11 +146,11 @@ pub trait EntityGateway: Send + Sync { unimplemented!(); } - async fn get_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: BankName) -> Result { + async fn get_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: &BankName) -> Result { unimplemented!(); } - async fn set_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: BankName, _amount: Meseta) -> Result<(), GatewayError> { + async fn set_bank_meseta(&mut self, _char_id: &CharacterEntityId, _bank: &BankName, _amount: Meseta) -> Result<(), GatewayError> { unimplemented!(); } } diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index ca527e8..ec92a39 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -416,7 +416,7 @@ impl EntityGateway for InMemoryGateway { .unwrap_or_default()) } - async fn get_character_bank(&mut self, char_id: &CharacterEntityId, _bank_name: BankName) -> Result { + async fn get_character_bank(&mut self, char_id: &CharacterEntityId, _bank_name: &BankName) -> Result { let banks = self.banks.lock().unwrap(); Ok(banks .iter() @@ -432,7 +432,7 @@ impl EntityGateway for InMemoryGateway { } // TOOD: impl bank name - async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, _bank_name: BankName) -> Result<(), GatewayError> { + async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, _bank_name: &BankName) -> Result<(), GatewayError> { let mut banks = self.banks.lock().unwrap(); banks.insert(*char_id, bank.clone()); Ok(()) @@ -469,15 +469,15 @@ impl EntityGateway for InMemoryGateway { } } - async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> { + async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName, meseta: Meseta) -> Result<(), GatewayError> { let mut bank_meseta = self.bank_meseta.lock().unwrap(); - bank_meseta.insert((*char_id, bank), meseta); + bank_meseta.insert((*char_id, bank.clone()), meseta); Ok(()) } - async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result { + async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName) -> Result { let mut bank_meseta = self.bank_meseta.lock().unwrap(); - if let Some(meseta) = bank_meseta.get_mut(&(*char_id, bank)) { + if let Some(meseta) = bank_meseta.get_mut(&(*char_id, bank.clone())) { Ok(*meseta) } else { diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index b6f9cc9..266eab2 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -400,12 +400,12 @@ async fn get_character_inventory(conn: &mut sqlx::PgConnection, char_id: &Charac Ok(InventoryEntity::new(real_inventory)) } -async fn get_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank_name: BankName) -> Result +async fn get_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank_name: &BankName) -> Result { let mut t = conn.begin().await?; let bank = sqlx::query_as::<_, PgInventoryEntity>("select * from bank where pchar = $1 and name = $2") .bind(char_id.0) - .bind(bank_name.0) + .bind(bank_name.0.clone()) .fetch_one(&mut t).await?; // TODO: inefficient let mut real_bank = Vec::new(); @@ -461,7 +461,7 @@ async fn set_character_inventory(conn: &mut sqlx::PgConnection, char_id: &Charac Ok(()) } -async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: BankName) -> Result<(), GatewayError> +async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: &BankName) -> Result<(), GatewayError> { let bank = bank.items.iter() .map(|item| { @@ -479,7 +479,7 @@ async fn set_character_bank(conn: &mut sqlx::PgConnection, char_id: &CharacterEn sqlx::query("insert into bank (pchar, items, name) values ($1, $2, $3) on conflict (pchar, name) do update set items = $2") .bind(char_id.0) .bind(sqlx::types::Json(bank)) - .bind(bank_name.0) + .bind(bank_name.0.clone()) .execute(conn) .await?; Ok(()) @@ -534,24 +534,24 @@ async fn get_character_meseta(conn: &mut sqlx::PgConnection, char_id: &Character Ok(Meseta(meseta.0 as u32)) } -async fn set_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> +async fn set_bank_meseta(conn: &mut sqlx::PgConnection, 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") .bind(char_id.0) .bind(meseta.0 as i32) - .bind(bank.0) + .bind(bank.0.clone()) .execute(conn) .await?; Ok(()) } -async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: BankName) -> Result +async fn get_bank_meseta(conn: &mut sqlx::PgConnection, char_id: &CharacterEntityId, bank: &BankName) -> Result { #[derive(sqlx::FromRow)] struct PgMeseta(i32); let meseta = sqlx::query_as::<_, PgMeseta>(r#"select meseta from character_meseta where id = $1 and bank = $2"#) .bind(char_id.0) - .bind(bank.0) + .bind(bank.0.clone()) .fetch_one(conn) .await?; Ok(Meseta(meseta.0 as u32)) @@ -657,7 +657,7 @@ impl EntityGateway for PostgresGateway { get_character_inventory(&mut *self.pool.acquire().await?, char_id).await } - async fn get_character_bank(&mut self, char_id: &CharacterEntityId, bank_name: BankName) -> Result { + async fn get_character_bank(&mut self, char_id: &CharacterEntityId, bank_name: &BankName) -> Result { get_character_bank(&mut *self.pool.acquire().await?, char_id, bank_name).await } @@ -665,7 +665,7 @@ impl EntityGateway for PostgresGateway { set_character_inventory(&mut *self.pool.acquire().await?, char_id, inventory).await } - async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: BankName) -> Result<(), GatewayError> { + async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: &BankName) -> Result<(), GatewayError> { set_character_bank(&mut *self.pool.acquire().await?, char_id, bank, bank_name).await } @@ -685,11 +685,11 @@ impl EntityGateway for PostgresGateway { get_character_meseta(&mut *self.pool.acquire().await?, char_id).await } - async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> { + async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName, meseta: Meseta) -> Result<(), GatewayError> { set_bank_meseta(&mut *self.pool.acquire().await?, char_id, bank, meseta).await } - async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result { + async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName) -> Result { get_bank_meseta(&mut *self.pool.acquire().await?, char_id, bank).await } } @@ -773,7 +773,7 @@ impl<'c> EntityGateway for PostgresTransaction<'c> { get_character_inventory(&mut *self.pgtransaction, char_id).await } - async fn get_character_bank(&mut self, char_id: &CharacterEntityId, bank_name: BankName) -> Result { + async fn get_character_bank(&mut self, char_id: &CharacterEntityId, bank_name: &BankName) -> Result { get_character_bank(&mut *self.pgtransaction, char_id, bank_name).await } @@ -781,7 +781,7 @@ impl<'c> EntityGateway for PostgresTransaction<'c> { set_character_inventory(&mut *self.pgtransaction, char_id, inventory).await } - async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: BankName) -> Result<(), GatewayError> { + async fn set_character_bank(&mut self, char_id: &CharacterEntityId, bank: &BankEntity, bank_name: &BankName) -> Result<(), GatewayError> { set_character_bank(&mut *self.pgtransaction, char_id, bank, bank_name).await } @@ -801,11 +801,11 @@ impl<'c> EntityGateway for PostgresTransaction<'c> { get_character_meseta(&mut *self.pgtransaction, char_id).await } - async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName, meseta: Meseta) -> Result<(), GatewayError> { + async fn set_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName, meseta: Meseta) -> Result<(), GatewayError> { set_bank_meseta(&mut *self.pgtransaction, char_id, bank, meseta).await } - async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: BankName) -> Result { + async fn get_bank_meseta(&mut self, char_id: &CharacterEntityId, bank: &BankName) -> Result { get_bank_meseta(&mut *self.pgtransaction, char_id, bank).await } } diff --git a/src/login/character.rs b/src/login/character.rs index eb1cdb5..b530124 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -295,7 +295,7 @@ async fn new_character(entity_gateway: &mut EG, user: &UserAc InventoryItemEntity::Stacked(monomates), InventoryItemEntity::Stacked(monofluids)], }; entity_gateway.set_character_inventory(&character.id, &inventory).await?; - entity_gateway.set_character_bank(&character.id, &BankEntity::default(), BankName("".into())).await?; + entity_gateway.set_character_bank(&character.id, &BankEntity::default(), &BankName("".into())).await?; let equipped = EquippedEntity { weapon: Some(weapon.id), armor: Some(armor.id), diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index 1cd7d83..c5c7854 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -152,7 +152,7 @@ impl ItemManager { pub async fn load_character(&mut self, entity_gateway: &mut EG, character: &CharacterEntity) -> Result<(), anyhow::Error> { let inventory = entity_gateway.get_character_inventory(&character.id).await?; - let bank = entity_gateway.get_character_bank(&character.id, BankName("".into())).await?; + let bank = entity_gateway.get_character_bank(&character.id, &BankName("".into())).await?; let equipped = entity_gateway.get_character_equips(&character.id).await?; let inventory_items = inventory.items.into_iter() @@ -210,7 +210,7 @@ impl ItemManager { let character_bank = CharacterBank::new(bank_items); let character_meseta = entity_gateway.get_character_meseta(&character.id).await?; - let bank_meseta = entity_gateway.get_bank_meseta(&character.id, BankName("".into())).await?; + let bank_meseta = entity_gateway.get_bank_meseta(&character.id, &BankName("".into())).await?; self.character_inventory.insert(character.id, character_inventory); self.character_bank.insert(character.id, character_bank); @@ -630,7 +630,7 @@ impl ItemManager { let _bank_item = bank.deposit_item(item_to_deposit, amount).ok_or(ItemManagerError::Idunnoman)?; entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - entity_gateway.set_character_bank(&character.id, &bank.as_bank_entity(&character.id, &BankName("".into())), BankName("".into())).await?; + entity_gateway.set_character_bank(&character.id, &bank.as_bank_entity(&character.id, &BankName("".into())), &BankName("".into())).await?; Ok(()) } @@ -653,7 +653,7 @@ impl ItemManager { }; entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; - entity_gateway.set_character_bank(&character.id, &bank.as_bank_entity(&character.id, &BankName("".into())), BankName("".into())).await?; + entity_gateway.set_character_bank(&character.id, &bank.as_bank_entity(&character.id, &BankName("".into())), &BankName("".into())).await?; inventory.slot(inventory_item_slot).ok_or_else(|| ItemManagerError::Idunnoman.into()) } diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index a92bc4b..ec5b00c 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -723,7 +723,7 @@ impl ItemState { pub async fn load_character(&mut self, entity_gateway: &mut EG, character: &CharacterEntity) -> Result<(), ItemStateError> { let inventory = entity_gateway.get_character_inventory(&character.id).await?; - let bank = entity_gateway.get_character_bank(&character.id, BankName("".into())).await?; + let bank = entity_gateway.get_character_bank(&character.id, &BankName("".into())).await?; let equipped = entity_gateway.get_character_equips(&character.id).await?; let inventory_items = inventory.items.into_iter() diff --git a/tests/common.rs b/tests/common.rs index 0c6be23..ae4dc2a 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -29,7 +29,7 @@ pub async fn new_user_character(entity_gateway: &mut EG, user let new_character = NewCharacterEntity::new(user.id, kb_conf_preset); let character = entity_gateway.create_character(new_character).await.unwrap(); entity_gateway.set_character_meseta(&character.id, Meseta(0)).await.unwrap(); - entity_gateway.set_bank_meseta(&character.id, BankName("".into()), Meseta(0)).await.unwrap(); + entity_gateway.set_bank_meseta(&character.id, &BankName("".into()), Meseta(0)).await.unwrap(); (user, character) } diff --git a/tests/test_bank.rs b/tests/test_bank.rs index 1f80605..f7ade20 100644 --- a/tests/test_bank.rs +++ b/tests/test_bank.rs @@ -32,7 +32,7 @@ async fn test_bank_items_sent_in_character_login() { ), }).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -71,7 +71,7 @@ async fn test_request_bank_items() { }).await.unwrap()); } - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -115,7 +115,7 @@ async fn test_request_stacked_bank_items() { }).await.unwrap()); } - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -182,7 +182,7 @@ async fn test_request_bank_items_sorted() { }).await.unwrap(); let bank = vec![item::BankItemEntity::Individual(item1), vec![monomate].into(), item2.into()]; - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -275,7 +275,13 @@ async fn test_deposit_individual_item() { && player_no_longer_has_item.amount == 0 )); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); + assert_eq!(inventory_items.items.len(), 1); + inventory_items.items[0].with_individual(|item| { + assert_eq!(item.id, item::ItemEntityId(1)); + }).unwrap(); + + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_individual(|item| { assert_eq!(item.id, item::ItemEntityId(2)); @@ -335,7 +341,7 @@ async fn test_deposit_stacked_item() { && player_no_longer_has_item.amount == 3 )); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_stacked(|items| { assert_eq!(items.iter().map(|i| i.id).collect::>(), @@ -397,7 +403,7 @@ async fn test_deposit_partial_stacked_item() { )); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_stacked(|items| { assert_eq!(items.iter().map(|i| i.id).collect::>(), @@ -443,7 +449,7 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -477,7 +483,7 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() { && player_no_longer_has_item.amount == 2 )); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_stacked(|items| { assert_eq!(items.iter().map(|i| i.id).collect::>(), @@ -516,7 +522,7 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -543,7 +549,7 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() { assert!(packets.is_err()); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_stacked(|items| { assert_eq!(items.len(), 10); @@ -596,7 +602,7 @@ async fn test_deposit_individual_item_in_full_bank() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -623,7 +629,7 @@ async fn test_deposit_individual_item_in_full_bank() { assert!(packets.is_err()); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 200); let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); @@ -669,7 +675,7 @@ async fn test_deposit_stacked_item_in_full_bank() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(full_bank), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(full_bank), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -696,7 +702,7 @@ async fn test_deposit_stacked_item_in_full_bank() { assert!(packets.is_err()); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 200); let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); @@ -756,7 +762,7 @@ async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() { almost_full_bank.push(bank_monomates.into()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(almost_full_bank), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(almost_full_bank), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -781,7 +787,7 @@ async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() { unknown: 0, })))).await.unwrap().for_each(drop); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 200); bank_items.items[199].with_stacked(|items| { assert_eq!(items.len(), 4); @@ -822,7 +828,7 @@ async fn test_deposit_meseta() { })))).await.unwrap().for_each(drop); let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap(); - let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, item::BankName("".into())).await.unwrap(); + let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankName("".into())).await.unwrap(); assert!(c1_meseta.0 == 277); assert!(c1_bank_meseta.0 == 23); } @@ -833,7 +839,7 @@ async fn test_deposit_too_much_meseta() { let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap(); - entity_gateway.set_bank_meseta(&char1.id, item::BankName("".into()), item::Meseta(999980)).await.unwrap(); + entity_gateway.set_bank_meseta(&char1.id, &item::BankName("".into()), item::Meseta(999980)).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -859,7 +865,7 @@ async fn test_deposit_too_much_meseta() { })))).await.unwrap().for_each(drop); let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap(); - let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, item::BankName("".into())).await.unwrap(); + let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankName("".into())).await.unwrap(); assert!(c1_meseta.0 == 300); assert!(c1_bank_meseta.0 == 999980); } @@ -870,7 +876,7 @@ async fn test_deposit_meseta_when_bank_is_maxed() { let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(300)).await.unwrap(); - entity_gateway.set_bank_meseta(&char1.id, item::BankName("".into()), item::Meseta(999999)).await.unwrap(); + entity_gateway.set_bank_meseta(&char1.id, &item::BankName("".into()), item::Meseta(999999)).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -896,7 +902,7 @@ async fn test_deposit_meseta_when_bank_is_maxed() { })))).await.unwrap().for_each(drop); let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap(); - let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, item::BankName("".into())).await.unwrap(); + let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankName("".into())).await.unwrap(); assert!(c1_meseta.0 == 300); assert!(c1_bank_meseta.0 == 999999); } @@ -924,7 +930,7 @@ async fn test_withdraw_individual_item() { ), }).await.unwrap()); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -984,7 +990,7 @@ async fn test_withdraw_stacked_item() { }).await.unwrap()); } - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1043,7 +1049,7 @@ async fn test_withdraw_partial_stacked_item() { ), }).await.unwrap()); } - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1073,10 +1079,10 @@ async fn test_withdraw_partial_stacked_item() { assert!(packets.len() == 2); assert!(matches!(&packets[1], (ClientId(2), SendShipPacket::Message(Message {msg: GameMessage::CreateItem(create_item)})) - if create_item.item_id == 0x10002 + if create_item.item_id == 0x20002 )); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_stacked(|items| { assert_eq!(items.iter().map(|i| i.id).collect::>(), @@ -1121,7 +1127,7 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1154,7 +1160,7 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() { if create_item.item_id == 0x10000 )); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 0); let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); @@ -1196,7 +1202,7 @@ async fn test_withdraw_stacked_item_with_full_stack_in_inventory() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1223,7 +1229,7 @@ async fn test_withdraw_stacked_item_with_full_stack_in_inventory() { assert!(packets.is_err()); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_stacked(|items| { assert_eq!(items.iter().map(|i| i.id).collect::>(), @@ -1276,7 +1282,7 @@ async fn test_withdraw_individual_item_in_full_inventory() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1302,7 +1308,7 @@ async fn test_withdraw_individual_item_in_full_inventory() { })))).await; assert!(packets.is_err()); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); @@ -1345,7 +1351,7 @@ async fn test_withdraw_stacked_item_in_full_inventory() { } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankName("".into())).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1373,7 +1379,7 @@ async fn test_withdraw_stacked_item_in_full_inventory() { assert!(packets.is_err()); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert_eq!(bank_items.items.len(), 1); bank_items.items[0].with_stacked(|items| { assert_eq!(items.iter().map(|i| i.id).collect::>(), @@ -1401,7 +1407,7 @@ async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() { ), }).await.unwrap()); } - entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_item]), item::BankName("".into())).await.unwrap(); + entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_item]), &item::BankName("".into())).await.unwrap(); let mut items = Vec::new(); for _i in 0..29usize { @@ -1458,7 +1464,7 @@ async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() { unknown: 0, })))).await.unwrap().for_each(drop); - let bank_items = entity_gateway.get_character_bank(&char1.id, item::BankName("".into())).await.unwrap(); + let bank_items = entity_gateway.get_character_bank(&char1.id, &item::BankName("".into())).await.unwrap(); assert!(bank_items.items.len() == 0); let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); @@ -1476,7 +1482,7 @@ async fn test_withdraw_meseta() { let mut entity_gateway = InMemoryGateway::default(); let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; - entity_gateway.set_bank_meseta(&char1.id, item::BankName("".into()), item::Meseta(300)).await.unwrap(); + entity_gateway.set_bank_meseta(&char1.id, &item::BankName("".into()), item::Meseta(300)).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1502,7 +1508,7 @@ async fn test_withdraw_meseta() { })))).await.unwrap().for_each(drop); let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap(); - let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, item::BankName("".into())).await.unwrap(); + let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankName("".into())).await.unwrap(); assert!(c1_meseta.0 == 23); assert!(c1_bank_meseta.0 == 277); } @@ -1513,7 +1519,7 @@ async fn test_withdraw_too_much_meseta() { let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999980)).await.unwrap(); - entity_gateway.set_bank_meseta(&char1.id, item::BankName("".into()), item::Meseta(300)).await.unwrap(); + entity_gateway.set_bank_meseta(&char1.id, &item::BankName("".into()), item::Meseta(300)).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1539,7 +1545,7 @@ async fn test_withdraw_too_much_meseta() { })))).await.unwrap().for_each(drop); let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap(); - let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, item::BankName("".into())).await.unwrap(); + let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankName("".into())).await.unwrap(); assert!(c1_meseta.0 == 999980); assert!(c1_bank_meseta.0 == 300); } @@ -1550,7 +1556,7 @@ async fn test_withdraw_meseta_inventory_is_maxed() { let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); - entity_gateway.set_bank_meseta(&char1.id, item::BankName("".into()), item::Meseta(300)).await.unwrap(); + entity_gateway.set_bank_meseta(&char1.id, &item::BankName("".into()), item::Meseta(300)).await.unwrap(); let mut ship = Box::new(ShipServerState::builder() .gateway(entity_gateway.clone()) @@ -1576,7 +1582,7 @@ async fn test_withdraw_meseta_inventory_is_maxed() { })))).await.unwrap().for_each(drop); let c1_meseta = entity_gateway.get_character_meseta(&char1.id).await.unwrap(); - let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, item::BankName("".into())).await.unwrap(); + let c1_bank_meseta = entity_gateway.get_bank_meseta(&char1.id, &item::BankName("".into())).await.unwrap(); assert!(c1_meseta.0 == 999999); assert!(c1_bank_meseta.0 == 300); }