2017-09-24 22:23:22 +00:00
module TK.SpaceTac.Specs {
2017-10-26 21:47:13 +00:00
testing ( "Ship" , test = > {
test . case ( "creates a full name" , check = > {
2017-07-31 18:17:43 +00:00
let ship = new Ship ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getFullName ( false ) , "Level 1 unnamed" ) ;
2017-07-31 18:17:43 +00:00
ship . name = "Titan" ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getFullName ( false ) , "Level 1 Titan" ) ;
2017-07-31 18:17:43 +00:00
ship . level . forceLevel ( 3 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getFullName ( false ) , "Level 3 Titan" ) ;
2017-07-31 18:17:43 +00:00
ship . fleet . player . name = "Emperor" ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getFullName ( true ) , "Emperor's Level 3 Titan" ) ;
2017-07-31 18:17:43 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "moves and computes facing angle" , check = > {
2017-08-17 17:51:22 +00:00
let ship = new Ship ( null , "Test" ) ;
let engine = TestTools . addEngine ( ship , 50 ) ;
2015-01-29 00:00:00 +00:00
ship . setArenaFacingAngle ( 0 ) ;
2014-12-31 00:00:00 +00:00
ship . setArenaPosition ( 50 , 50 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . arena_x , 50 ) ;
check . equals ( ship . arena_y , 50 ) ;
check . equals ( ship . arena_angle , 0 ) ;
2014-12-31 00:00:00 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 51 , 50 , engine ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . arena_x , 51 ) ;
check . equals ( ship . arena_y , 50 ) ;
check . equals ( ship . arena_angle , 0 ) ;
2015-01-26 00:00:00 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 50 , 50 , engine ) ;
2017-10-26 21:47:13 +00:00
check . nears ( ship . arena_angle , 3.14159265 , 5 ) ;
2015-01-26 00:00:00 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 51 , 51 , engine ) ;
2017-10-26 21:47:13 +00:00
check . nears ( ship . arena_angle , 0.785398 , 5 ) ;
2015-01-26 00:00:00 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 51 , 52 , engine ) ;
2017-10-26 21:47:13 +00:00
check . nears ( ship . arena_angle , 1.5707963 , 5 ) ;
2015-01-26 00:00:00 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 52 , 52 , engine ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . arena_x , 52 ) ;
check . equals ( ship . arena_y , 52 ) ;
check . equals ( ship . arena_angle , 0 ) ;
2015-01-26 00:00:00 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 52 , 50 , engine ) ;
2017-10-26 21:47:13 +00:00
check . nears ( ship . arena_angle , - 1.5707963 , 5 ) ;
2015-01-26 00:00:00 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 50 , 50 , engine ) ;
2017-10-26 21:47:13 +00:00
check . nears ( ship . arena_angle , 3.14159265 , 5 ) ;
2017-05-25 23:09:29 +00:00
let battle = new Battle ( ) ;
battle . fleets [ 0 ] . addShip ( ship ) ;
2017-10-26 21:47:13 +00:00
check . equals ( battle . log . events , [ ] ) ;
2017-05-25 23:09:29 +00:00
2017-08-17 17:51:22 +00:00
ship . moveTo ( 70 , 50 , engine ) ;
2017-10-26 21:47:13 +00:00
check . equals ( battle . log . events , [ new MoveEvent ( ship , new ArenaLocationAngle ( 50 , 50 , Math . PI ) , new ArenaLocationAngle ( 70 , 50 , 0 ) , engine ) ] ) ;
2017-06-07 17:09:06 +00:00
2017-08-17 17:51:22 +00:00
battle . log . clear ( ) ;
2017-06-07 17:09:06 +00:00
ship . rotate ( 2.1 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( battle . log . events , [
2017-06-07 17:09:06 +00:00
new MoveEvent ( ship , new ArenaLocationAngle ( 70 , 50 , 0 ) , new ArenaLocationAngle ( 70 , 50 , 2.1 ) )
] ) ;
2017-08-17 17:51:22 +00:00
battle . log . clear ( ) ;
ship . moveTo ( 0 , 0 , null ) ;
2017-10-26 21:47:13 +00:00
check . equals ( battle . log . events , [
2017-08-17 17:51:22 +00:00
new MoveEvent ( ship , new ArenaLocationAngle ( 70 , 50 , 2.1 ) , new ArenaLocationAngle ( 0 , 0 , 2.1 ) )
] ) ;
2015-01-26 00:00:00 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "applies equipment cooldown" , check = > {
2017-05-16 23:12:05 +00:00
let ship = new Ship ( ) ;
let equipment = new Equipment ( SlotType . Weapon ) ;
2017-05-22 16:29:04 +00:00
equipment . cooldown . configure ( 1 , 2 ) ;
2017-05-16 23:12:05 +00:00
ship . addSlot ( SlotType . Weapon ) . attach ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . same ( equipment . cooldown . canUse ( ) , true , "1" ) ;
2017-05-16 23:12:05 +00:00
equipment . cooldown . use ( ) ;
2017-10-26 21:47:13 +00:00
check . same ( equipment . cooldown . canUse ( ) , false , "2" ) ;
2017-05-16 23:12:05 +00:00
ship . startBattle ( ) ;
2017-10-26 21:47:13 +00:00
check . same ( equipment . cooldown . canUse ( ) , true , "3" ) ;
2017-05-16 23:12:05 +00:00
ship . startTurn ( ) ;
equipment . cooldown . use ( ) ;
2017-10-26 21:47:13 +00:00
check . same ( equipment . cooldown . canUse ( ) , false , "4" ) ;
2017-05-16 23:12:05 +00:00
ship . endTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . same ( equipment . cooldown . canUse ( ) , false , "5" ) ;
2017-05-16 23:12:05 +00:00
ship . startTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . same ( equipment . cooldown . canUse ( ) , false , "6" ) ;
2017-05-16 23:12:05 +00:00
ship . endTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . same ( equipment . cooldown . canUse ( ) , true , "7" ) ;
2017-05-16 23:12:05 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "lists available actions from attached equipment" , check = > {
2015-01-16 00:00:00 +00:00
var ship = new Ship ( null , "Test" ) ;
var actions : BaseAction [ ] ;
var slot : Slot ;
var equipment : Equipment ;
actions = ship . getAvailableActions ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( actions . length , 1 ) ;
check . equals ( actions [ 0 ] . code , "endturn" ) ;
2015-01-16 00:00:00 +00:00
slot = ship . addSlot ( SlotType . Engine ) ;
2017-09-17 23:12:51 +00:00
equipment = new Equipment ( slot . type ) ;
2015-01-28 00:00:00 +00:00
equipment . action = new MoveAction ( equipment ) ;
2015-01-16 00:00:00 +00:00
slot . attach ( equipment ) ;
2017-03-09 18:43:24 +00:00
slot = ship . addSlot ( SlotType . Weapon ) ;
2017-09-17 23:12:51 +00:00
equipment = new Equipment ( slot . type ) ;
slot . attach ( equipment ) ;
slot = ship . addSlot ( SlotType . Power ) ;
equipment = new Equipment ( slot . type ) ;
2017-10-03 16:11:30 +00:00
equipment . action = new TriggerAction ( equipment ) ;
2017-03-09 18:43:24 +00:00
slot . attach ( equipment ) ;
2015-01-16 00:00:00 +00:00
actions = ship . getAvailableActions ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( actions . length , 3 ) ;
check . equals ( actions [ 0 ] . code , "move" ) ;
check . equals ( actions [ 1 ] . code , "fire-equipment" ) ;
check . equals ( actions [ 2 ] . code , "endturn" ) ;
2015-01-16 00:00:00 +00:00
} ) ;
2015-01-22 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "applies permanent effects of equipments on attributes" , check = > {
2015-01-22 00:00:00 +00:00
var ship = new Ship ( null , "Test" ) ;
var slot : Slot ;
var equipment : Equipment ;
slot = ship . addSlot ( SlotType . Power ) ;
equipment = new Equipment ( ) ;
2017-04-18 19:51:23 +00:00
equipment . slot_type = slot . type ;
equipment . effects . push ( new AttributeEffect ( "power_capacity" , 4 ) ) ;
2015-01-22 00:00:00 +00:00
slot . attach ( equipment ) ;
slot = ship . addSlot ( SlotType . Power ) ;
equipment = new Equipment ( ) ;
2017-04-18 19:51:23 +00:00
equipment . slot_type = slot . type ;
equipment . effects . push ( new AttributeEffect ( "power_capacity" , 5 ) ) ;
2015-01-22 00:00:00 +00:00
slot . attach ( equipment ) ;
ship . updateAttributes ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . attributes . power_capacity . get ( ) , 9 ) ;
2015-01-22 00:00:00 +00:00
} ) ;
2015-01-28 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "repairs hull and recharges shield" , check = > {
2015-01-28 00:00:00 +00:00
var ship = new Ship ( null , "Test" ) ;
2017-02-07 19:15:21 +00:00
ship . setAttribute ( "hull_capacity" , 120 ) ;
ship . setAttribute ( "shield_capacity" , 150 ) ;
2015-01-28 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . hull . get ( ) , 0 ) ;
check . equals ( ship . values . shield . get ( ) , 0 ) ;
2015-01-28 00:00:00 +00:00
ship . restoreHealth ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . hull . get ( ) , 120 ) ;
check . equals ( ship . values . shield . get ( ) , 150 ) ;
2015-01-28 00:00:00 +00:00
} ) ;
2015-02-03 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "applies and logs hull and shield damage" , check = > {
2015-02-03 00:00:00 +00:00
var fleet = new Fleet ( ) ;
var battle = new Battle ( fleet ) ;
var ship = new Ship ( fleet ) ;
2017-04-24 17:59:16 +00:00
TestTools . setShipHP ( ship , 150 , 400 ) ;
2015-02-03 00:00:00 +00:00
ship . restoreHealth ( ) ;
battle . log . clear ( ) ;
ship . addDamage ( 10 , 20 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . hull . get ( ) , 140 ) ;
check . equals ( ship . values . shield . get ( ) , 380 ) ;
check . equals ( battle . log . events . length , 3 ) ;
check . equals ( battle . log . events [ 0 ] , new ValueChangeEvent ( ship , ship . values . shield , - 20 ) ) ;
check . equals ( battle . log . events [ 1 ] , new ValueChangeEvent ( ship , ship . values . hull , - 10 ) ) ;
check . equals ( battle . log . events [ 2 ] , new DamageEvent ( ship , 10 , 20 ) ) ;
2015-02-03 00:00:00 +00:00
battle . log . clear ( ) ;
ship . addDamage ( 15 , 25 , false ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . hull . get ( ) , 125 ) ;
check . equals ( ship . values . shield . get ( ) , 355 ) ;
check . equals ( battle . log . events . length , 0 ) ;
2017-04-24 17:59:16 +00:00
ship . addDamage ( 125 , 355 , false ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . hull . get ( ) , 0 ) ;
check . equals ( ship . values . shield . get ( ) , 0 ) ;
check . equals ( ship . alive , false ) ;
2015-02-03 00:00:00 +00:00
} ) ;
2015-02-06 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "sets and logs sticky effects" , check = > {
2015-02-27 00:00:00 +00:00
var ship = new Ship ( ) ;
var battle = new Battle ( ship . fleet ) ;
2017-01-24 00:14:04 +00:00
ship . addStickyEffect ( new StickyEffect ( new BaseEffect ( "test" ) , 2 , false , true ) ) ;
2015-02-27 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( ship . sticky_effects , [ new StickyEffect ( new BaseEffect ( "test" ) , 2 , false , true ) ] ) ;
check . equals ( battle . log . events , [
2017-06-13 22:01:39 +00:00
new ActiveEffectsEvent ( ship , [ ] , [ new StickyEffect ( new BaseEffect ( "test" ) , 2 , false , true ) ] )
2015-02-27 00:00:00 +00:00
] ) ;
2017-01-20 00:02:18 +00:00
ship . startTurn ( ) ;
2015-02-27 00:00:00 +00:00
battle . log . clear ( ) ;
ship . endTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . sticky_effects , [ new StickyEffect ( new BaseEffect ( "test" ) , 1 , false , true ) ] ) ;
check . equals ( battle . log . events , [
2017-06-13 22:01:39 +00:00
new ActiveEffectsEvent ( ship , [ ] , [ new StickyEffect ( new BaseEffect ( "test" ) , 1 , false , true ) ] )
2015-02-27 00:00:00 +00:00
] ) ;
2017-01-20 00:02:18 +00:00
ship . startTurn ( ) ;
2015-02-27 00:00:00 +00:00
battle . log . clear ( ) ;
ship . endTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . sticky_effects , [ ] ) ;
check . equals ( battle . log . events , [
2017-06-13 22:01:39 +00:00
new ActiveEffectsEvent ( ship , [ ] , [ new StickyEffect ( new BaseEffect ( "test" ) , 0 , false , true ) ] ) ,
new ActiveEffectsEvent ( ship , [ ] , [ ] )
2015-02-27 00:00:00 +00:00
] ) ;
2017-01-20 00:02:18 +00:00
ship . startTurn ( ) ;
2015-02-27 00:00:00 +00:00
battle . log . clear ( ) ;
ship . endTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . sticky_effects , [ ] ) ;
check . equals ( battle . log . events , [ ] ) ;
2015-02-27 00:00:00 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "resets toggle actions at the start of turn" , check = > {
2017-06-13 22:01:39 +00:00
let ship = new Ship ( ) ;
let equ = ship . addSlot ( SlotType . Weapon ) . attach ( new Equipment ( SlotType . Weapon ) ) ;
let action = equ . action = new ToggleAction ( equ , 0 , 10 , [ new AttributeEffect ( "power_capacity" , 1 ) ] ) ;
2017-10-26 21:47:13 +00:00
check . equals ( action . activated , false ) ;
2017-06-13 22:01:39 +00:00
let battle = new Battle ( ship . fleet ) ;
2017-10-25 22:45:53 +00:00
TestTools . setShipPlaying ( battle , ship ) ;
2017-06-13 22:01:39 +00:00
ship . startTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( action . activated , false ) ;
2017-06-13 22:01:39 +00:00
2017-09-19 15:09:06 +00:00
let result = action . apply ( ship ) ;
2017-10-26 21:47:13 +00:00
check . same ( result , true , "Could not be applied" ) ;
check . equals ( action . activated , true ) ;
2017-06-13 22:01:39 +00:00
ship . endTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( action . activated , true ) ;
2017-06-13 22:01:39 +00:00
ship . startTurn ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( action . activated , false ) ;
2017-06-13 22:01:39 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( battle . log . events , [
2017-09-19 15:09:06 +00:00
new ActionAppliedEvent ( ship , action , Target . newFromShip ( ship ) , 0 ) ,
2017-06-13 22:01:39 +00:00
new ToggleEvent ( ship , action , true ) ,
new ActiveEffectsEvent ( ship , [ ] , [ ] , [ new AttributeEffect ( "power_capacity" , 1 ) ] ) ,
new ValueChangeEvent ( ship , new ShipAttribute ( "power capacity" , 1 ) , 1 ) ,
2017-09-19 15:09:06 +00:00
new ActionAppliedEvent ( ship , action , Target . newFromShip ( ship ) , 0 ) ,
2017-06-13 22:01:39 +00:00
new ToggleEvent ( ship , action , false ) ,
new ActiveEffectsEvent ( ship , [ ] , [ ] , [ ] ) ,
new ValueChangeEvent ( ship , new ShipAttribute ( "power capacity" , 0 ) , - 1 ) ,
] ) ;
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "updates area effects when the ship moves" , check = > {
2017-06-13 22:01:39 +00:00
let battle = new Battle ( ) ;
let ship1 = battle . fleets [ 0 ] . addShip ( ) ;
let ship2 = battle . fleets [ 0 ] . addShip ( ) ;
ship2 . setArenaPosition ( 10 , 0 ) ;
let ship3 = battle . fleets [ 0 ] . addShip ( ) ;
ship3 . setArenaPosition ( 20 , 0 ) ;
let shield = ship1 . addSlot ( SlotType . Shield ) . attach ( new Equipment ( SlotType . Shield ) ) ;
shield . action = new ToggleAction ( shield , 0 , 15 , [ new AttributeEffect ( "shield_capacity" , 5 ) ] ) ;
2017-10-25 22:45:53 +00:00
TestTools . setShipPlaying ( battle , ship1 ) ;
2017-09-19 15:09:06 +00:00
shield . action . apply ( ship1 ) ;
2017-06-13 22:01:39 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( ship1 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship2 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship3 . getAttribute ( "shield_capacity" ) , 0 ) ;
2017-06-13 22:01:39 +00:00
ship1 . moveTo ( 15 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship1 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship2 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship3 . getAttribute ( "shield_capacity" ) , 5 ) ;
2017-06-13 22:01:39 +00:00
ship1 . moveTo ( 30 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship1 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship2 . getAttribute ( "shield_capacity" ) , 0 ) ;
check . equals ( ship3 . getAttribute ( "shield_capacity" ) , 5 ) ;
2017-06-13 22:01:39 +00:00
ship1 . moveTo ( 50 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship1 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship2 . getAttribute ( "shield_capacity" ) , 0 ) ;
check . equals ( ship3 . getAttribute ( "shield_capacity" ) , 0 ) ;
2017-06-13 22:01:39 +00:00
ship2 . moveTo ( 40 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship1 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship2 . getAttribute ( "shield_capacity" ) , 5 ) ;
check . equals ( ship3 . getAttribute ( "shield_capacity" ) , 0 ) ;
2017-06-13 22:01:39 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "sets and logs death state" , check = > {
2015-02-06 00:00:00 +00:00
var fleet = new Fleet ( ) ;
var battle = new Battle ( fleet ) ;
var ship = new Ship ( fleet ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . alive , true ) ;
2015-02-06 00:00:00 +00:00
2017-02-07 19:15:21 +00:00
ship . values . hull . set ( 10 ) ;
2015-02-06 00:00:00 +00:00
battle . log . clear ( ) ;
ship . addDamage ( 5 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . alive , true ) ;
check . equals ( battle . log . events . length , 2 ) ;
check . equals ( battle . log . events [ 0 ] . code , "value" ) ;
check . equals ( battle . log . events [ 1 ] . code , "damage" ) ;
2015-02-06 00:00:00 +00:00
battle . log . clear ( ) ;
ship . addDamage ( 5 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . alive , false ) ;
check . equals ( battle . log . events . length , 3 ) ;
check . equals ( battle . log . events [ 0 ] . code , "value" ) ;
check . equals ( battle . log . events [ 1 ] . code , "damage" ) ;
check . equals ( battle . log . events [ 2 ] . code , "death" ) ;
2015-02-06 00:00:00 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "checks if a ship is able to play" , check = > {
2017-10-25 22:45:53 +00:00
let battle = new Battle ( ) ;
let ship = battle . fleets [ 0 ] . addShip ( ) ;
2015-02-06 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( ship . isAbleToPlay ( ) , false ) ;
check . equals ( ship . isAbleToPlay ( false ) , true ) ;
2015-02-06 00:00:00 +00:00
2017-02-07 19:15:21 +00:00
ship . values . power . set ( 5 ) ;
2015-02-06 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( ship . isAbleToPlay ( ) , true ) ;
check . equals ( ship . isAbleToPlay ( false ) , true ) ;
2015-02-06 00:00:00 +00:00
2017-02-07 19:15:21 +00:00
ship . values . hull . set ( 10 ) ;
2015-02-06 00:00:00 +00:00
ship . addDamage ( 8 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . isAbleToPlay ( ) , true ) ;
check . equals ( ship . isAbleToPlay ( false ) , true ) ;
2015-02-06 00:00:00 +00:00
ship . addDamage ( 8 , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . isAbleToPlay ( ) , false ) ;
check . equals ( ship . isAbleToPlay ( false ) , false ) ;
2015-02-06 00:00:00 +00:00
} ) ;
2015-02-13 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "counts attached equipment" , check = > {
2015-02-13 00:00:00 +00:00
var ship = new Ship ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getEquipmentCount ( ) , 0 ) ;
2015-02-13 00:00:00 +00:00
2017-03-05 14:12:08 +00:00
ship . addSlot ( SlotType . Hull ) . attach ( new Equipment ( SlotType . Hull ) ) ;
2015-02-13 00:00:00 +00:00
ship . addSlot ( SlotType . Shield ) ;
ship . addSlot ( SlotType . Weapon ) . attach ( new Equipment ( SlotType . Weapon ) ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getEquipmentCount ( ) , 2 ) ;
2015-02-13 00:00:00 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "can pick a random attached equipment" , check = > {
2015-02-13 00:00:00 +00:00
var ship = new Ship ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getRandomEquipment ( ) , null ) ;
2015-02-13 00:00:00 +00:00
2017-03-05 14:12:08 +00:00
ship . addSlot ( SlotType . Hull ) . attach ( new Equipment ( SlotType . Hull ) ) ;
2015-02-13 00:00:00 +00:00
ship . addSlot ( SlotType . Shield ) ;
ship . addSlot ( SlotType . Weapon ) . attach ( new Equipment ( SlotType . Weapon ) ) ;
2017-02-26 17:44:15 +00:00
var random = new SkewedRandomGenerator ( [ 0.2 ] ) ;
2015-02-13 00:00:00 +00:00
var picked = ship . getRandomEquipment ( random ) ;
2017-10-26 21:47:13 +00:00
check . notequals ( picked , null ) ;
check . same ( picked , ship . slots [ 0 ] . attached ) ;
2015-02-13 00:00:00 +00:00
2017-02-26 17:44:15 +00:00
random = new SkewedRandomGenerator ( [ 0.999999 ] ) ;
2015-02-13 00:00:00 +00:00
picked = ship . getRandomEquipment ( random ) ;
2017-10-26 21:47:13 +00:00
check . notequals ( picked , null ) ;
check . same ( picked , ship . slots [ 2 ] . attached ) ;
2015-02-13 00:00:00 +00:00
} ) ;
2017-01-12 00:36:34 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "recover action points at end of turn" , check = > {
2017-01-12 00:36:34 +00:00
var ship = new Ship ( ) ;
2017-04-18 19:51:23 +00:00
let power_generator = new Equipment ( SlotType . Power ) ;
power_generator . effects = [
new AttributeEffect ( "power_capacity" , 8 ) ,
2017-06-11 20:44:12 +00:00
new AttributeEffect ( "power_generation" , 3 ) ,
2017-04-18 19:51:23 +00:00
]
ship . addSlot ( SlotType . Power ) . attach ( power_generator ) ;
2017-01-12 00:36:34 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . power . get ( ) , 0 ) ;
2017-01-12 00:36:34 +00:00
ship . initializeActionPoints ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . power . get ( ) , 8 ) ;
2017-02-16 00:17:09 +00:00
ship . values . power . set ( 3 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . power . get ( ) , 3 ) ;
2017-01-20 00:02:18 +00:00
ship . recoverActionPoints ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . power . get ( ) , 6 ) ;
2017-01-20 00:02:18 +00:00
ship . recoverActionPoints ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . values . power . get ( ) , 8 ) ;
2017-01-12 00:36:34 +00:00
} ) ;
2017-02-06 21:46:55 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "checks if a ship is inside a given circle" , check = > {
2017-02-06 21:46:55 +00:00
let ship = new Ship ( ) ;
ship . arena_x = 5 ;
ship . arena_y = 8 ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . isInCircle ( 5 , 8 , 0 ) , true ) ;
check . equals ( ship . isInCircle ( 5 , 8 , 1 ) , true ) ;
check . equals ( ship . isInCircle ( 5 , 7 , 1 ) , true ) ;
check . equals ( ship . isInCircle ( 6 , 9 , 1.7 ) , true ) ;
check . equals ( ship . isInCircle ( 5 , 8.1 , 0 ) , false ) ;
check . equals ( ship . isInCircle ( 5 , 7 , 0.9 ) , false ) ;
check . equals ( ship . isInCircle ( 12 , - 4 , 5 ) , false ) ;
2017-02-06 21:46:55 +00:00
} ) ;
2017-02-08 00:47:18 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "stores items in cargo space" , check = > {
2017-03-05 23:29:02 +00:00
let ship = new Ship ( ) ;
let equipment1 = new Equipment ( ) ;
let equipment2 = new Equipment ( ) ;
let result = ship . addCargo ( equipment1 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , false ) ;
check . equals ( ship . cargo , [ ] ) ;
check . equals ( ship . getFreeCargoSpace ( ) , 0 ) ;
2017-03-05 23:29:02 +00:00
ship . setCargoSpace ( 1 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getFreeCargoSpace ( ) , 1 ) ;
2017-03-05 23:29:02 +00:00
result = ship . addCargo ( equipment1 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , true ) ;
check . equals ( ship . cargo , [ equipment1 ] ) ;
check . equals ( ship . getFreeCargoSpace ( ) , 0 ) ;
2017-03-05 23:29:02 +00:00
result = ship . addCargo ( equipment1 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , false ) ;
check . equals ( ship . cargo , [ equipment1 ] ) ;
2017-03-05 23:29:02 +00:00
result = ship . addCargo ( equipment2 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , false ) ;
check . equals ( ship . cargo , [ equipment1 ] ) ;
2017-03-05 23:29:02 +00:00
ship . setCargoSpace ( 2 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getFreeCargoSpace ( ) , 1 ) ;
2017-03-05 23:29:02 +00:00
result = ship . addCargo ( equipment2 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , true ) ;
check . equals ( ship . cargo , [ equipment1 , equipment2 ] ) ;
check . equals ( ship . getFreeCargoSpace ( ) , 0 ) ;
2017-03-05 23:29:02 +00:00
ship . setCargoSpace ( 1 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . cargo , [ equipment1 ] ) ;
check . equals ( ship . getFreeCargoSpace ( ) , 0 ) ;
2017-03-05 23:29:02 +00:00
ship . setCargoSpace ( 2 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . cargo , [ equipment1 ] ) ;
check . equals ( ship . getFreeCargoSpace ( ) , 1 ) ;
2017-03-05 23:29:02 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "equips items from cargo" , check = > {
2017-03-05 23:29:02 +00:00
let ship = new Ship ( ) ;
let equipment = new Equipment ( SlotType . Weapon ) ;
let slot = ship . addSlot ( SlotType . Weapon ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . listEquipment ( ) , [ ] ) ;
2017-03-05 23:29:02 +00:00
let result = ship . equip ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , false ) ;
check . equals ( ship . listEquipment ( ) , [ ] ) ;
2017-03-05 23:29:02 +00:00
ship . setCargoSpace ( 1 ) ;
ship . addCargo ( equipment ) ;
result = ship . equip ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , true ) ;
check . equals ( ship . listEquipment ( SlotType . Weapon ) , [ equipment ] ) ;
check . equals ( equipment . attached_to , slot ) ;
2017-03-05 23:29:02 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "removes equipped items" , check = > {
2017-03-05 23:29:02 +00:00
let ship = new Ship ( ) ;
let equipment = new Equipment ( SlotType . Weapon ) ;
let slot = ship . addSlot ( SlotType . Weapon ) ;
slot . attach ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . listEquipment ( ) , [ equipment ] ) ;
check . same ( slot . attached , equipment ) ;
check . same ( equipment . attached_to , slot ) ;
2017-03-05 23:29:02 +00:00
let result = ship . unequip ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , false ) ;
check . equals ( ship . listEquipment ( ) , [ equipment ] ) ;
check . equals ( ship . cargo , [ ] ) ;
2017-03-05 23:29:02 +00:00
ship . setCargoSpace ( 10 ) ;
result = ship . unequip ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , true ) ;
check . equals ( ship . listEquipment ( ) , [ ] ) ;
check . equals ( ship . cargo , [ equipment ] ) ;
check . equals ( slot . attached , null ) ;
check . equals ( equipment . attached_to , null ) ;
2017-03-05 23:29:02 +00:00
result = ship . unequip ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . equals ( result , false ) ;
check . equals ( ship . listEquipment ( ) , [ ] ) ;
check . equals ( ship . cargo , [ equipment ] ) ;
2017-03-05 23:29:02 +00:00
} ) ;
2017-03-17 00:07:00 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "checks equipment requirements" , check = > {
2017-04-25 18:24:43 +00:00
let ship = new Ship ( ) ;
let equipment = new Equipment ( SlotType . Hull ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . canEquip ( equipment ) , null ) ;
2017-04-25 18:24:43 +00:00
ship . addSlot ( SlotType . Engine ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . canEquip ( equipment ) , null ) ;
2017-04-25 18:24:43 +00:00
let slot = ship . addSlot ( SlotType . Hull ) ;
2017-10-26 21:47:13 +00:00
check . same ( ship . canEquip ( equipment ) , slot ) ;
2017-04-25 18:24:43 +00:00
2017-06-11 20:44:12 +00:00
equipment . requirements [ "skill_photons" ] = 2 ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . canEquip ( equipment ) , null ) ;
2017-04-25 18:24:43 +00:00
2017-06-11 20:44:12 +00:00
ship . upgradeSkill ( "skill_photons" ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . canEquip ( equipment ) , null ) ;
2017-04-25 18:24:43 +00:00
2017-06-11 20:44:12 +00:00
ship . upgradeSkill ( "skill_photons" ) ;
2017-10-26 21:47:13 +00:00
check . same ( ship . canEquip ( equipment ) , slot ) ;
2017-04-25 18:24:43 +00:00
slot . attach ( new Equipment ( SlotType . Hull ) ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . canEquip ( equipment ) , null ) ;
2017-04-25 18:24:43 +00:00
} ) ;
2017-10-26 21:47:13 +00:00
test . case ( "allow skills upgrading from current level" , check = > {
2017-03-17 00:07:00 +00:00
let ship = new Ship ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . level . get ( ) , 1 ) ;
check . equals ( ship . getAvailableUpgradePoints ( ) , 10 ) ;
2017-03-17 00:07:00 +00:00
ship . level . forceLevel ( 2 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . level . get ( ) , 2 ) ;
check . equals ( ship . getAvailableUpgradePoints ( ) , 15 ) ;
2017-03-17 00:07:00 +00:00
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttribute ( "skill_photons" ) , 0 ) ;
2017-06-11 20:44:12 +00:00
ship . upgradeSkill ( "skill_photons" ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttribute ( "skill_photons" ) , 1 ) ;
2017-03-17 00:07:00 +00:00
range ( 50 ) . forEach ( ( ) = > ship . upgradeSkill ( "skill_gravity" ) ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttribute ( "skill_photons" ) , 1 ) ;
check . equals ( ship . getAttribute ( "skill_gravity" ) , 14 ) ;
check . equals ( ship . getAvailableUpgradePoints ( ) , 0 ) ;
2017-03-17 00:07:00 +00:00
ship . updateAttributes ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttribute ( "skill_photons" ) , 1 ) ;
check . equals ( ship . getAttribute ( "skill_gravity" ) , 14 ) ;
2017-03-17 00:07:00 +00:00
} ) ;
2017-05-10 17:16:57 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "restores as new at the end of battle" , check = > {
2017-05-10 17:16:57 +00:00
let ship = new Ship ( ) ;
TestTools . setShipHP ( ship , 10 , 20 ) ;
TestTools . setShipAP ( ship , 5 , 0 ) ;
ship . addDamage ( 5 , 5 ) ;
ship . addStickyEffect ( new StickyEffect ( new DamageEffect ( 10 ) , 8 ) ) ;
ship . addStickyEffect ( new StickyEffect ( new AttributeLimitEffect ( "power_capacity" , 3 ) , 12 ) ) ;
ship . updateAttributes ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getValue ( "hull" ) , 5 ) ;
check . equals ( ship . getValue ( "shield" ) , 15 ) ;
check . equals ( ship . getValue ( "power" ) , 3 ) ;
check . equals ( ship . sticky_effects . length , 2 ) ;
check . equals ( ship . getAttribute ( "power_capacity" ) , 3 ) ;
2017-05-10 17:16:57 +00:00
ship . endBattle ( 1 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getValue ( "hull" ) , 10 ) ;
check . equals ( ship . getValue ( "shield" ) , 20 ) ;
check . equals ( ship . getValue ( "power" ) , 5 ) ;
check . equals ( ship . sticky_effects . length , 0 ) ;
check . equals ( ship . getAttribute ( "power_capacity" ) , 5 ) ;
2017-05-10 17:16:57 +00:00
} ) ;
2017-06-12 22:28:54 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "lists active effects" , check = > {
2017-06-12 22:28:54 +00:00
let ship = new Ship ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( imaterialize ( ship . ieffects ( ) ) , [ ] ) ;
2017-06-12 22:28:54 +00:00
let equipment = ship . addSlot ( SlotType . Engine ) . attach ( new Equipment ( SlotType . Engine ) ) ;
2017-10-26 21:47:13 +00:00
check . equals ( imaterialize ( ship . ieffects ( ) ) , [ ] ) ;
2017-06-12 22:28:54 +00:00
equipment . effects . push ( new AttributeEffect ( "precision" , 4 ) ) ;
2017-10-26 21:47:13 +00:00
check . equals ( imaterialize ( ship . ieffects ( ) ) , [
2017-06-12 22:28:54 +00:00
new AttributeEffect ( "precision" , 4 )
] ) ;
ship . addStickyEffect ( new StickyEffect ( new AttributeLimitEffect ( "precision" , 2 ) , 4 ) ) ;
2017-10-26 21:47:13 +00:00
check . equals ( imaterialize ( ship . ieffects ( ) ) , [
2017-06-12 22:28:54 +00:00
new AttributeEffect ( "precision" , 4 ) ,
new AttributeLimitEffect ( "precision" , 2 )
] ) ;
} ) ;
2017-07-12 23:18:20 +00:00
2017-10-26 21:47:13 +00:00
test . case ( "gets a textual description of an attribute" , check = > {
2017-07-12 23:18:20 +00:00
let ship = new Ship ( ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttributeDescription ( "skill_photons" ) , "Forces of light, and electromagnetic radiation" ) ;
2017-07-12 23:18:20 +00:00
let equipment = new Equipment ( SlotType . Engine ) ;
equipment . effects = [ new AttributeEffect ( "skill_photons" , 4 ) ] ;
equipment . name = "Photonic engine" ;
ship . addSlot ( SlotType . Engine ) . attach ( equipment ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttribute ( "skill_photons" ) , 4 ) ;
check . equals ( ship . getAttributeDescription ( "skill_photons" ) , "Forces of light, and electromagnetic radiation\n\nPhotonic engine Mk1: +4" ) ;
2017-07-12 23:18:20 +00:00
ship . level . forceLevelUp ( ) ;
ship . upgradeSkill ( "skill_photons" ) ;
ship . upgradeSkill ( "skill_photons" ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttributeDescription ( "skill_photons" ) , "Forces of light, and electromagnetic radiation\n\nLevelled up: +2\nPhotonic engine Mk1: +4" ) ;
2017-07-12 23:18:20 +00:00
ship . addStickyEffect ( new StickyEffect ( new AttributeLimitEffect ( "skill_photons" , 3 ) ) ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . getAttributeDescription ( "skill_photons" ) , "Forces of light, and electromagnetic radiation\n\nLevelled up: +2\nPhotonic engine Mk1: +4\n???: limit to 3" ) ;
2017-07-12 23:18:20 +00:00
} ) ;
2014-12-31 00:00:00 +00:00
} ) ;
2015-01-07 00:00:00 +00:00
}