From fbc68c7a26d2e5815e3f754598f16f915d575661 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 21 Jun 2021 17:08:55 +0000 Subject: [PATCH] handle selling photon tools and untekked weapon test --- src/ship/items/inventory.rs | 8 ++++--- tests/test_shops.rs | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index 7de42e9..4ff2992 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -3,7 +3,7 @@ use thiserror::Error; use libpso::character::character; use crate::entity::character::CharacterEntityId; use crate::entity::item::{ItemEntityId, ItemDetail, ItemEntity, ItemType, ItemLocation, InventoryEntity, InventoryItemEntity, EquippedEntity}; -use crate::entity::item::tool::Tool; +use crate::entity::item::tool::{Tool, ToolType}; use crate::entity::item::mag::Mag; use crate::entity::item::weapon::Weapon; use crate::ship::items::{ClientItemId, BankItem, BankItemHandle}; @@ -256,8 +256,10 @@ impl InventoryItem { Some((ArmorShopItem::unit_from_item(u).price() / 8) as u32) }, ItemDetail::Tool(t) => { - if t.is_rare_item() { // TODO: photon drop/sphere etc - return Some(10u32) + if !matches!(t.tool, ToolType::PhotonDrop | ToolType::PhotonSphere | ToolType::PhotonCrystal) { + if t.is_rare_item() { + return Some(10u32) + } } Some((ToolShopItem::tool_from_item(t).price() / 8) as u32) }, diff --git a/tests/test_shops.rs b/tests/test_shops.rs index 10a4df6..7cb06c2 100644 --- a/tests/test_shops.rs +++ b/tests/test_shops.rs @@ -627,3 +627,51 @@ async fn test_units_disappear_from_shop_when_bought() { }).unwrap(); }).unwrap(); } + +#[async_std::test] +async fn test_selling_untekked_weapon() { + let mut entity_gateway = InMemoryGateway::default(); + + let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + + let mut p1_inv = Vec::new(); + + p1_inv.push(entity_gateway.create_item( + item::NewItemEntity { + item: item::ItemDetail::Weapon( + item::weapon::Weapon { + weapon: item::weapon::WeaponType::Vulcan, + grind: 5, + special: Some(item::weapon::WeaponSpecial::Charge), + attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}), + Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), + Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], + tekked: false, + } + ), + location: item::ItemLocation::Inventory { + character_id: char1.id, + } + }).await.unwrap()); + + entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); + + let mut ship = Box::new(ShipServerState::builder() + .gateway(entity_gateway.clone()) + .build()); + + log_in_char(&mut ship, ClientId(1), "a1", "a").await; + join_lobby(&mut ship, ClientId(1)).await; + create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await; + + ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem { + client: 0, + target: 0, + item_id: 0x10000, + amount: 1, + })))).await.unwrap().for_each(drop); + + let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); + let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap(); + assert_eq!(c1.meseta, 1); +} \ No newline at end of file