Browse Source

more tests for unwrapping equips

presents
andy 3 years ago
parent
commit
b29bb473d5
  1. 198
      tests/test_item_modifiers.rs

198
tests/test_item_modifiers.rs

@ -34,7 +34,7 @@ async fn test_unwrap_weapon() {
}
}).await.unwrap();
println!("created item: {:?}", wrapped_item);
assert!(wrapped_item.item.as_client_bytes() == [0x00,0x01,0x00,0x05,0xDA,0x05,0x03,0x14,0x05,0x1E,0x00,0x00,0x00,0x00,0x00,0x00]);
let mut inventory = Vec::<item::ItemEntity>::new();
inventory.push(wrapped_item.into());
@ -67,17 +67,205 @@ async fn test_unwrap_weapon() {
}
#[async_std::test]
async fn test_unwrap_armor() {}
async fn test_unwrap_armor() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let wrapped_item = entity_gateway.create_item(
item::NewItemEntity {
item: item::ItemDetail::Armor(item::armor::Armor {
armor: item::armor::ArmorType::PerfectFrame,
dfp: 3u8,
evp: 2u8,
slots: 4u8,
wrapping: Some(item::WrappingPaper::Red_Green), // 5
}),
location: item::ItemLocation::Inventory{
character_id: char1.id,
}
}).await.unwrap();
// slots should be untouched when wrapped regardless of wrapping paper colour
assert!(wrapped_item.item.as_client_bytes() == [0x01,0x01,0x10,0x00,0x40,0x04,0x03,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
let mut inventory = Vec::<item::ItemEntity>::new();
inventory.push(wrapped_item.into());
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).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(&mut ship, ClientId(1), "room", "").await;
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
client: 0,
target: 0,
item_id: 0x10000,
})))).await.unwrap().for_each(drop);
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
inventory_items.items[0].with_individual(|item| {
match &item.item {
item::ItemDetail::Armor(armor) => {
assert!(armor.as_bytes() == [0x01,0x01,0x10,0x00,0x00,0x04,0x03,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
},
_ => panic!(),
}
}).unwrap();
}
#[async_std::test]
async fn test_unwrap_shield() {}
async fn test_unwrap_shield() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let wrapped_item = entity_gateway.create_item(
item::NewItemEntity {
item: item::ItemDetail::Shield(item::shield::Shield {
shield: item::shield::ShieldType::CoreShield,
dfp: 2u8,
evp: 3u8,
wrapping: Some(item::WrappingPaper::Red_Green), // 5
}),
location: item::ItemLocation::Inventory{
character_id: char1.id,
}
}).await.unwrap();
assert!(wrapped_item.item.as_client_bytes() == [0x01,0x02,0x02,0x00,0x40,0x05,0x02,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
let mut inventory = Vec::<item::ItemEntity>::new();
inventory.push(wrapped_item.into());
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).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(&mut ship, ClientId(1), "room", "").await;
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
client: 0,
target: 0,
item_id: 0x10000,
})))).await.unwrap().for_each(drop);
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
inventory_items.items[0].with_individual(|item| {
match &item.item {
item::ItemDetail::Shield(shield) => {
assert!(shield.as_bytes() == [0x01,0x02,0x02,0x00,0x00,0x00,0x02,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
},
_ => panic!(),
}
}).unwrap();
}
#[async_std::test]
async fn test_unwrap_unit() {}
async fn test_unwrap_unit() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let wrapped_item = entity_gateway.create_item(
item::NewItemEntity {
item: item::ItemDetail::Unit(item::unit::Unit {
unit: item::unit::UnitType::KnightPower,
modifier: Some(item::unit::UnitModifier::MinusMinus),
wrapping: Some(item::WrappingPaper::Red_Green), // 5
}),
location: item::ItemLocation::Inventory{
character_id: char1.id,
}
}).await.unwrap();
assert!(wrapped_item.item.as_client_bytes() == [0x01,0x03,0x00,0x00,0x40,0x05,0xFE,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
let mut inventory = Vec::<item::ItemEntity>::new();
inventory.push(wrapped_item.into());
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).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(&mut ship, ClientId(1), "room", "").await;
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
client: 0,
target: 0,
item_id: 0x10000,
})))).await.unwrap().for_each(drop);
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
inventory_items.items[0].with_individual(|item| {
match &item.item {
item::ItemDetail::Unit(unit) => {
assert!(unit.as_bytes() == [0x01,0x03,0x00,0x00,0x00,0x00,0xFE,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]);
},
_ => panic!(),
}
}).unwrap();
}
// mag cells are covered in test_mags.rs
#[async_std::test]
async fn test_unwrap_mag() {}
async fn test_unwrap_mag() {
let mut entity_gateway = InMemoryGateway::new();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let wrapped_item = entity_gateway.create_item(
item::NewItemEntity {
item: item::ItemDetail::Mag(item::mag::Mag::wrapped_baby_mag(12)), //turquoise
location: item::ItemLocation::Inventory{
character_id: char1.id,
}
}).await.unwrap();
assert!(wrapped_item.item.as_client_bytes() == [0x02,0x00,0x00,0x00,0xF4,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x40,0x0C]); // item maker is wrong?
let mut inventory = Vec::<item::ItemEntity>::new();
inventory.push(wrapped_item.into());
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).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(&mut ship, ClientId(1), "room", "").await;
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem {
client: 0,
target: 0,
item_id: 0x10000,
})))).await.unwrap().for_each(drop);
let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
inventory_items.items[0].with_individual(|item| {
match &item.item {
item::ItemDetail::Mag(mag) => {
assert!(mag.as_bytes() == [0x02,0x00,0x00,0x00,0xF4,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x0C]);
},
_ => panic!(),
}
}).unwrap();
}
// TODO: implement wrapping packet (gallons shop quest)
// wrap presents

Loading…
Cancel
Save