Browse Source

test with toomanyunwraps()

kill_counters
andy 3 years ago
parent
commit
e075de3259
  1. 86
      tests/test_unseal_items.rs

86
tests/test_unseal_items.rs

@ -147,13 +147,89 @@ async fn test_all_equipped_kill_counters_increase_per_kill() {
assert!(w.item.as_client_bytes()[11] == u.item.as_client_bytes()[11]);
}
// #[async_std::test]
// async fn test_non_equipped_kill_counter_does_not_increase() {
// let mut entity_gateway = InMemoryGateway::default();
#[async_std::test]
async fn test_non_equipped_kill_counter_does_not_increase() {
let mut entity_gateway = InMemoryGateway::default();
// let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
// }
let mut ship = Box::new(ShipServerState::builder()
.gateway(entity_gateway.clone())
.build());
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::SealedJSword,
grind: 0,
special: None,
attrs: [None,
None,
None,],
tekked: true,
kills: Some(0),
}
),
}).await.unwrap());
p1_inv.push(entity_gateway.create_item(
item::NewItemEntity {
item: item::ItemDetail::Unit(
item::unit::Unit {
unit: item::unit::UnitType::Limiter,
modifier: None,
kills: Some(0),
}
),
}).await.unwrap());
let equipped = item::EquippedEntity {
weapon: Some(p1_inv[0].id),
armor: None,
shield: None,
unit: [None; 4],
mag: None,
};
entity_gateway.set_character_equips(&char1.id, &equipped).await.unwrap();
entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap();
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;
let enemy_id = {
let room = ship.blocks.0[0].rooms[0].as_ref().unwrap();
let enemy_id = (0..).filter_map(|i| {
room.maps.enemy_by_id(i).ok().and_then(|enemy| {
if enemy.monster == MonsterType::Booma {
Some(i)
}
else {
None
}
})
}).next().unwrap();
enemy_id
};
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::KillMonster(KillMonster{
client: enemy_id as u8,
target: 16,
map_area: 1,
data: [8,0],
})))).await.unwrap().for_each(drop);
let equipped_items = entity_gateway.get_character_equips(&char1.id).await.unwrap();
let inventory = entity_gateway.get_character_inventory(&char1.id).await.unwrap();
let w = inventory.items.iter().find(|x| x.individual().unwrap().id == equipped_items.weapon.unwrap()).unwrap().individual().unwrap();
let u = inventory.items.iter().find(|x| x.individual().unwrap().id == item::ItemEntityId(2)).unwrap().individual().unwrap();
assert!(w.item.as_client_bytes()[11] == 1);
assert!(u.item.as_client_bytes()[11] == 0);
}
// #[async_std::test]
// async fn test_kill_counter_increase_only_for_final_hit() { // don't share kills among players

Loading…
Cancel
Save