Browse Source

update exp tests with new map builder tech

pull/127/head
jake 2 years ago
parent
commit
220d3e7185
  1. 6
      src/ship/map/mod.rs
  2. 113
      tests/test_exp_gain.rs

6
src/ship/map/mod.rs

@ -1,8 +1,8 @@
pub mod area; pub mod area;
pub mod enemy; pub mod enemy;
mod object;
mod variant;
mod maps;
pub mod object;
pub mod variant;
pub mod maps;
// TODO: don't just forward everything to the module scope // TODO: don't just forward everything to the module scope
pub use area::*; pub use area::*;

113
tests/test_exp_gain.rs

@ -4,6 +4,10 @@ use elseware::common::leveltable::CharacterLevelTable;
use elseware::ship::ship::{ShipServerState, SendShipPacket, RecvShipPacket}; use elseware::ship::ship::{ShipServerState, SendShipPacket, RecvShipPacket};
use elseware::ship::monster::MonsterType; use elseware::ship::monster::MonsterType;
use elseware::ship::location::RoomId; use elseware::ship::location::RoomId;
use elseware::ship::map::variant::{MapVariant, MapVariantMode};
use elseware::ship::map::maps::Maps;
use elseware::ship::map::area::MapArea;
use elseware::ship::map::enemy::MapEnemy;
use libpso::packet::ship::*; use libpso::packet::ship::*;
use libpso::packet::messages::*; use libpso::packet::messages::*;
@ -20,35 +24,29 @@ async fn test_character_gains_exp() {
let mut ship = Box::new(ShipServerState::builder() let mut ship = Box::new(ShipServerState::builder()
.gateway(entity_gateway.clone()) .gateway(entity_gateway.clone())
.map_builder(Box::new(|_room_mode, _event| {
Maps::new(
vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
Vec::new(),
)
}))
.build()); .build());
log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await; join_lobby(&mut ship, ClientId(1)).await;
create_room(&mut ship, ClientId(1), "room", "").await; create_room(&mut ship, ClientId(1), "room", "").await;
let (enemy_id, exp) = {
//let room = ship.blocks.0[0].rooms.get(RoomId(0)).as_ref().unwrap();
ship.blocks.0[0].rooms.with(RoomId(0), |room| Box::pin(async move {
let (enemy_id, map_enemy) = (0..).filter_map(|i| {
room.maps.enemy_by_id(i).map(|enemy| {
(i, enemy)
}).ok()
}).next().unwrap();
let map_enemy_stats = room.monster_stats.get(&map_enemy.monster).unwrap();
(enemy_id, map_enemy_stats.exp)
})).await.unwrap()
};
ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp { ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
client: enemy_id as u8,
client: 0,
target: 16, target: 16,
enemy_id: enemy_id as u16,
enemy_id: 0,
client_id: 0, client_id: 0,
unused: 0, unused: 0,
last_hitter: 1, last_hitter: 1,
})))).await.unwrap(); })))).await.unwrap();
ship.clients.with(ClientId(1), |client| Box::pin(async move { ship.clients.with(ClientId(1), |client| Box::pin(async move {
assert!(exp == client.character.exp);
assert!(13 == client.character.exp);
})).await.unwrap(); })).await.unwrap();
} }
@ -62,23 +60,22 @@ async fn test_character_levels_up() {
let mut ship = Box::new(ShipServerState::builder() let mut ship = Box::new(ShipServerState::builder()
.gateway(entity_gateway.clone()) .gateway(entity_gateway.clone())
.map_builder(Box::new(|_room_mode, _event| {
Maps::new(
vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
Vec::new(),
)
}))
.build()); .build());
log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await; join_lobby(&mut ship, ClientId(1)).await;
create_room(&mut ship, ClientId(1), "room", "").await; create_room(&mut ship, ClientId(1), "room", "").await;
let enemy_id = ship.blocks.0[0].rooms.with(RoomId(0), |room| Box::pin(async move {
(0..).filter_map(|i| {
room.maps.enemy_by_id(i).map(|_| {
i
}).ok()
}).next().unwrap()
})).await.unwrap();
let levelup_pkt = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp { let levelup_pkt = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
client: enemy_id as u8,
client: 0 as u8,
target: 16, target: 16,
enemy_id: enemy_id as u16,
enemy_id: 0 as u16,
client_id: 0, client_id: 0,
unused: 0, unused: 0,
last_hitter: 1, last_hitter: 1,
@ -100,32 +97,22 @@ async fn test_character_levels_up_multiple_times() {
let mut ship = Box::new(ShipServerState::builder() let mut ship = Box::new(ShipServerState::builder()
.gateway(entity_gateway.clone()) .gateway(entity_gateway.clone())
.map_builder(Box::new(|_room_mode, _event| {
Maps::new(
vec![MapVariant::new(MapArea::DarkFalz, MapVariantMode::Online)],
vec![Some(MapEnemy::new(MonsterType::DarkFalz2, MapArea::DarkFalz))],
Vec::new(),
)
}))
.build()); .build());
log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await; join_lobby(&mut ship, ClientId(1)).await;
create_room(&mut ship, ClientId(1), "room", "").await; create_room(&mut ship, ClientId(1), "room", "").await;
let (enemy_id, exp) = {
ship.blocks.0[0].rooms.with(RoomId(0), |room| Box::pin(async move {
let (enemy_id, map_enemy) = (0..).filter_map(|i| {
room.maps.enemy_by_id(i).ok().and_then(|enemy| {
if enemy.monster == MonsterType::DarkFalz2 {
Some((i, enemy))
}
else {
None
}
})
}).next().unwrap();
let map_enemy_stats = room.monster_stats.get(&map_enemy.monster).unwrap();
(enemy_id, map_enemy_stats.exp)
})).await.unwrap()
};
let levelup_pkt = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp { let levelup_pkt = ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
client: enemy_id as u8,
client: 0 as u8,
target: 16, target: 16,
enemy_id: enemy_id as u16,
enemy_id: 0 as u16,
client_id: 0, client_id: 0,
unused: 0, unused: 0,
last_hitter: 1, last_hitter: 1,
@ -134,7 +121,7 @@ async fn test_character_levels_up_multiple_times() {
assert!(matches!(levelup_pkt[1].1, SendShipPacket::Message(Message {msg: GameMessage::PlayerLevelUp(PlayerLevelUp {lvl: 8, ..})}))); assert!(matches!(levelup_pkt[1].1, SendShipPacket::Message(Message {msg: GameMessage::PlayerLevelUp(PlayerLevelUp {lvl: 8, ..})})));
ship.clients.with(ClientId(1), |client| Box::pin(async move { ship.clients.with(ClientId(1), |client| Box::pin(async move {
assert!(exp == client.character.exp);
assert!(3000 == client.character.exp);
})).await.unwrap(); })).await.unwrap();
} }
@ -147,6 +134,13 @@ async fn test_one_character_gets_full_exp_and_other_attacker_gets_partial() {
let mut ship = Box::new(ShipServerState::builder() let mut ship = Box::new(ShipServerState::builder()
.gateway(entity_gateway.clone()) .gateway(entity_gateway.clone())
.map_builder(Box::new(|_room_mode, _event| {
Maps::new(
vec![MapVariant::new(MapArea::Forest2, MapVariantMode::Online)],
vec![Some(MapEnemy::new(MonsterType::Hildebear, MapArea::Forest2))],
Vec::new(),
)
}))
.build()); .build());
log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await; log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -157,43 +151,28 @@ async fn test_one_character_gets_full_exp_and_other_attacker_gets_partial() {
create_room(&mut ship, ClientId(1), "room", "").await; create_room(&mut ship, ClientId(1), "room", "").await;
join_room(&mut ship, ClientId(2), 0).await; join_room(&mut ship, ClientId(2), 0).await;
let (enemy_id, exp) = ship.blocks.0[0].rooms.with(RoomId(0), |room| Box::pin(async move {
let (enemy_id, map_enemy) = (0..).filter_map(|i| {
room.maps.enemy_by_id(i).ok().and_then(|enemy| {
if enemy.monster == MonsterType::DarkFalz2 {
Some((i, enemy))
}
else {
None
}
})
}).next().unwrap();
let map_enemy_stats = room.monster_stats.get(&map_enemy.monster).unwrap();
(enemy_id, map_enemy_stats.exp)
})).await.unwrap();
ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp { ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
client: enemy_id as u8,
client: 0,
target: 16, target: 16,
enemy_id: enemy_id as u16,
enemy_id: 0,
client_id: 0, client_id: 0,
unused: 0, unused: 0,
last_hitter: 1, last_hitter: 1,
})))).await.unwrap(); })))).await.unwrap();
ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp { ship.handle(ClientId(2), RecvShipPacket::Message(Message::new(GameMessage::RequestExp(RequestExp {
client: enemy_id as u8,
client: 0,
target: 16, target: 16,
enemy_id: enemy_id as u16,
enemy_id: 0,
client_id: 0, client_id: 0,
unused: 0, unused: 0,
last_hitter: 0, last_hitter: 0,
})))).await.unwrap(); })))).await.unwrap();
ship.clients.with(ClientId(1), |client| Box::pin(async move { ship.clients.with(ClientId(1), |client| Box::pin(async move {
assert!(client.character.exp == exp);
assert_eq!(client.character.exp, 13);
})).await.unwrap(); })).await.unwrap();
ship.clients.with(ClientId(2), |client| Box::pin(async move { ship.clients.with(ClientId(2), |client| Box::pin(async move {
assert!(client.character.exp == (exp as f32 * 0.8) as u32);
assert_eq!(client.character.exp, 10);
})).await.unwrap(); })).await.unwrap();
} }
Loading…
Cancel
Save