2020-12-18 05:02:45 +00:00
use elseware ::common ::serverstate ::{ ClientId , ServerState } ;
use elseware ::entity ::gateway ::{ EntityGateway , InMemoryGateway } ;
use elseware ::entity ::item ;
use elseware ::ship ::ship ::{ ShipServerState , RecvShipPacket , SendShipPacket } ;
use libpso ::packet ::ship ::* ;
use libpso ::packet ::messages ::* ;
#[ path = " common.rs " ]
mod common ;
use common ::* ;
// unwrap presents
#[ async_std::test ]
async fn test_unwrap_weapon ( ) {
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 ::Weapon ( item ::weapon ::Weapon {
weapon : item ::weapon ::WeaponType ::Saber ,
special : Some ( item ::weapon ::WeaponSpecial ::Burning ) ,
grind : 5 ,
attrs : [ Some ( item ::weapon ::WeaponAttribute { attr : item ::weapon ::Attribute ::Machine , value : 20 } ) ,
Some ( item ::weapon ::WeaponAttribute { attr : item ::weapon ::Attribute ::Hit , value : 30 } ) ,
None ] ,
tekked : false ,
wrapping : Some ( item ::WrappingPaper ::Red_Green ) ,
} ) ,
location : item ::ItemLocation ::Inventory {
character_id : char1 . id ,
}
} ) . await . unwrap ( ) ;
2020-12-19 21:51:19 +00:00
assert! ( wrapped_item . item . as_client_bytes ( ) = = [ 0x00 , 0x01 , 0x00 , 0x05 , 0xDA , 0x05 , 0x03 , 0x14 , 0x05 , 0x1E , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ;
2020-12-18 05:02:45 +00:00
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 ::Weapon ( weapon ) = > {
assert! ( weapon . as_bytes ( ) = = [ 0x00 , 0x01 , 0x00 , 0x05 , 0x9A , 0x00 , 0x03 , 0x14 , 0x05 , 0x1E , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ;
} ,
_ = > panic! ( ) ,
}
} ) . unwrap ( ) ;
}
#[ async_std::test ]
2020-12-19 21:51:19 +00:00
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 : 3 u8 ,
evp : 2 u8 ,
slots : 4 u8 ,
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 ( ) ;
}
2020-12-18 05:02:45 +00:00
#[ async_std::test ]
2020-12-19 21:51:19 +00:00
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 : 2 u8 ,
evp : 3 u8 ,
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 ( ) ;
}
2020-12-18 05:02:45 +00:00
#[ async_std::test ]
2020-12-19 21:51:19 +00:00
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 ( ) ;
}
2020-12-18 05:02:45 +00:00
// mag cells are covered in test_mags.rs
#[ async_std::test ]
2020-12-19 21:51:19 +00:00
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 ( ) ;
}
2020-12-18 05:02:45 +00:00
2021-01-23 04:56:24 +00:00
// TODO: implement wrapping packet (message 0xD6) (gallons shop quest)
2020-12-18 05:02:45 +00:00
// wrap presents
#[ async_std::test ]
async fn test_wrap_weapon ( ) { }
#[ async_std::test ]
async fn test_wrap_armor ( ) { }
#[ async_std::test ]
async fn test_wrap_shield ( ) { }
#[ async_std::test ]
async fn test_wrap_unit ( ) { }
// mag cells are covered in test_mags.rs
#[ async_std::test ]
async fn test_wrap_mag ( ) { }
// item combinations?