Browse Source

handle selling photon tools and untekked weapon test

pull/47/head
andy 4 years ago
parent
commit
fbc68c7a26
  1. 8
      src/ship/items/inventory.rs
  2. 48
      tests/test_shops.rs

8
src/ship/items/inventory.rs

@ -3,7 +3,7 @@ use thiserror::Error;
use libpso::character::character; use libpso::character::character;
use crate::entity::character::CharacterEntityId; use crate::entity::character::CharacterEntityId;
use crate::entity::item::{ItemEntityId, ItemDetail, ItemEntity, ItemType, ItemLocation, InventoryEntity, InventoryItemEntity, EquippedEntity}; 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::mag::Mag;
use crate::entity::item::weapon::Weapon; use crate::entity::item::weapon::Weapon;
use crate::ship::items::{ClientItemId, BankItem, BankItemHandle}; use crate::ship::items::{ClientItemId, BankItem, BankItemHandle};
@ -256,8 +256,10 @@ impl InventoryItem {
Some((ArmorShopItem::unit_from_item(u).price() / 8) as u32) Some((ArmorShopItem::unit_from_item(u).price() / 8) as u32)
}, },
ItemDetail::Tool(t) => { 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) Some((ToolShopItem::tool_from_item(t).price() / 8) as u32)
}, },

48
tests/test_shops.rs

@ -627,3 +627,51 @@ async fn test_units_disappear_from_shop_when_bought() {
}).unwrap(); }).unwrap();
}).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);
}
Loading…
Cancel
Save