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-12-12 22:17:25 +00:00
check . equals ( ship . getName ( false ) , "Ship" ) ;
check . equals ( ship . getName ( true ) , "Level 1 Ship" ) ;
2017-07-31 18:17:43 +00:00
2018-03-06 14:39:48 +00:00
ship . model = new ShipModel ( "test" , "Hauler" ) ;
2017-12-12 22:17:25 +00:00
check . equals ( ship . getName ( false ) , "Hauler" ) ;
check . equals ( ship . getName ( true ) , "Level 1 Hauler" ) ;
2017-07-31 18:17:43 +00:00
2017-12-12 22:17:25 +00:00
ship . name = "Titan-W12" ;
check . equals ( ship . getName ( false ) , "Titan-W12" ) ;
check . equals ( ship . getName ( true ) , "Level 1 Titan-W12" ) ;
2017-07-31 18:17:43 +00:00
2017-12-12 22:17:25 +00:00
ship . level . forceLevel ( 3 ) ;
check . equals ( ship . getName ( false ) , "Titan-W12" ) ;
check . equals ( ship . getName ( true ) , "Level 3 Titan-W12" ) ;
2017-07-31 18:17:43 +00:00
} ) ;
2017-11-14 00:07:06 +00:00
test . case ( "moves in the arena" , check = > {
2017-08-17 17:51:22 +00:00
let ship = new Ship ( null , "Test" ) ;
let engine = TestTools . addEngine ( ship , 50 ) ;
2014-12-31 00:00:00 +00:00
2017-11-14 00:07:06 +00:00
check . equals ( ship . arena_x , 0 ) ;
check . equals ( ship . arena_y , 0 ) ;
2017-10-26 21:47:13 +00:00
check . equals ( ship . arena_angle , 0 ) ;
2015-01-26 00:00:00 +00:00
2017-11-14 00:07:06 +00:00
ship . setArenaFacingAngle ( 1.2 ) ;
ship . setArenaPosition ( 12 , 50 ) ;
2015-01-26 00:00:00 +00:00
2017-11-14 00:07:06 +00:00
check . equals ( ship . arena_x , 12 ) ;
check . equals ( ship . arena_y , 50 ) ;
check . nears ( ship . arena_angle , 1.2 ) ;
2017-05-16 23:12:05 +00:00
} ) ;
2018-02-08 15:16:03 +00:00
test . case ( "applies permanent effects of ship model on attributes" , check = > {
2018-03-06 14:39:48 +00:00
let model = new ShipModel ( ) ;
2018-02-08 15:16:03 +00:00
let ship = new Ship ( null , null , model ) ;
2015-01-22 00:00:00 +00:00
2018-02-08 15:16:03 +00:00
check . patch ( model , "getEffects" , ( ) = > [
new AttributeEffect ( "power_capacity" , 4 ) ,
new AttributeEffect ( "power_capacity" , 5 ) ,
] ) ;
2015-01-22 00:00:00 +00:00
ship . updateAttributes ( ) ;
2018-02-08 15:16:03 +00:00
check . equals ( ship . getAttribute ( "power_capacity" ) , 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-11-14 00:07:06 +00:00
TestTools . setAttribute ( ship , "hull_capacity" , 120 ) ;
TestTools . setAttribute ( ship , "shield_capacity" , 150 ) ;
2015-01-28 00:00:00 +00:00
2017-11-14 00:07:06 +00:00
check . equals ( ship . getValue ( "hull" ) , 0 ) ;
check . equals ( ship . getValue ( "shield" ) , 0 ) ;
2015-01-28 00:00:00 +00:00
ship . restoreHealth ( ) ;
2017-11-14 00:07:06 +00:00
check . equals ( ship . getValue ( "hull" ) , 120 ) ;
check . equals ( ship . getValue ( "shield" ) , 150 ) ;
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 ( ) ;
2017-11-14 00:07:06 +00:00
ship . setValue ( "hull" , 10 ) ;
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-11-14 00:07:06 +00:00
ship . setValue ( "power" , 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-11-14 00:07:06 +00:00
ship . setDead ( ) ;
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 ) , 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 ( "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 ( "restores as new at the end of battle" , check = > {
2017-05-10 17:16:57 +00:00
let ship = new Ship ( ) ;
2018-02-08 15:16:03 +00:00
TestTools . setShipModel ( ship , 10 , 20 , 5 ) ;
2017-11-14 00:07:06 +00:00
ship . setValue ( "hull" , 5 ) ;
ship . setValue ( "shield" , 15 ) ;
ship . setValue ( "power" , 2 ) ;
ship . active_effects . add ( new StickyEffect ( new AttributeLimitEffect ( "power_capacity" , 3 ) , 12 ) ) ;
2017-05-10 17:16:57 +00:00
ship . updateAttributes ( ) ;
2018-02-08 15:16:03 +00:00
let action1 = new BaseAction ( "action1" ) ;
ship . actions . addCustom ( action1 ) ;
let action2 = new ToggleAction ( "action2" ) ;
ship . actions . addCustom ( action2 ) ;
ship . actions . toggle ( action2 , true ) ;
let action3 = new ToggleAction ( "action3" ) ;
ship . actions . addCustom ( action3 ) ;
2017-05-10 17:16:57 +00:00
2017-11-14 00:07:06 +00:00
check . in ( "before" , check = > {
check . equals ( ship . getValue ( "hull" ) , 5 , "hull" ) ;
check . equals ( ship . getValue ( "shield" ) , 15 , "shield" ) ;
check . equals ( ship . getValue ( "power" ) , 2 , "power" ) ;
check . equals ( ship . active_effects . count ( ) , 1 , "effects count" ) ;
check . equals ( ship . getAttribute ( "power_capacity" ) , 3 , "power capacity" ) ;
2018-02-08 15:16:03 +00:00
check . equals ( ship . actions . isToggled ( action2 ) , true , "action 2 activation" ) ;
check . equals ( ship . actions . isToggled ( action3 ) , false , "action 3 activation" ) ;
2017-11-14 00:07:06 +00:00
} ) ;
ship . restoreInitialState ( ) ;
check . in ( "after" , check = > {
check . equals ( ship . getValue ( "hull" ) , 10 , "hull" ) ;
check . equals ( ship . getValue ( "shield" ) , 20 , "shield" ) ;
check . equals ( ship . getValue ( "power" ) , 5 , "power" ) ;
check . equals ( ship . active_effects . count ( ) , 0 , "effects count" ) ;
check . equals ( ship . getAttribute ( "power_capacity" ) , 5 , "power capacity" ) ;
2018-02-08 15:16:03 +00:00
check . equals ( ship . actions . isToggled ( action2 ) , false , "action 2 activation" ) ;
check . equals ( ship . actions . isToggled ( action3 ) , false , "action 3 activation" ) ;
2017-11-14 00:07:06 +00:00
} ) ;
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 ( ) ;
2018-06-13 18:17:46 +00:00
check . equals ( ship . getEffects ( ) , [ ] ) ;
2017-06-12 22:28:54 +00:00
2018-03-26 15:30:43 +00:00
let effect1 = new AttributeEffect ( "evasion" , 4 ) ;
2018-02-08 15:16:03 +00:00
check . patch ( ship . model , "getEffects" , ( ) = > [ effect1 ] ) ;
2018-06-13 18:17:46 +00:00
check . equals ( ship . getEffects ( ) , [ effect1 ] ) ;
2017-06-12 22:28:54 +00:00
2018-03-26 15:30:43 +00:00
let effect2 = new AttributeLimitEffect ( "evasion" , 2 ) ;
2017-11-14 00:07:06 +00:00
ship . active_effects . add ( new StickyEffect ( effect2 , 4 ) ) ;
2018-06-13 18:17:46 +00:00
check . equals ( ship . getEffects ( ) , [ effect1 , effect2 ] ) ;
2017-06-12 22:28:54 +00:00
} ) ;
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 ( ) ;
2018-03-26 15:30:43 +00:00
check . equals ( ship . getAttributeDescription ( "evasion" ) , "Damage points that may be evaded by maneuvering" ) ;
2018-02-08 15:16:03 +00:00
2018-03-06 14:39:48 +00:00
check . patch ( ship , "getUpgrades" , ( ) = > [
2018-03-26 15:30:43 +00:00
{ code : "Base" , effects : [ new AttributeEffect ( "evasion" , 3 ) ] } ,
{ code : "Up1" , effects : [ new AttributeEffect ( "shield_capacity" , 1 ) ] } ,
{ code : "Up2" , effects : [ new AttributeEffect ( "shield_capacity" , 1 ) , new AttributeEffect ( "evasion" , 1 ) ] }
2018-03-06 14:39:48 +00:00
] ) ;
2018-03-26 15:30:43 +00:00
check . equals ( ship . getAttributeDescription ( "evasion" ) , "Damage points that may be evaded by maneuvering\n\nBase: +3\nUp2: +1" ) ;
2018-02-08 15:16:03 +00:00
2018-03-26 15:30:43 +00:00
ship . active_effects . add ( new StickyEffect ( new AttributeLimitEffect ( "evasion" , 3 ) ) ) ;
check . equals ( ship . getAttributeDescription ( "evasion" ) , "Damage points that may be evaded by maneuvering\n\nBase: +3\nUp2: +1\nSticky effect: limit to 3" ) ;
2018-02-08 15:16:03 +00:00
ship . active_effects . remove ( ship . active_effects . list ( ) [ 0 ] ) ;
2018-03-26 15:30:43 +00:00
ship . active_effects . add ( new AttributeEffect ( "evasion" , - 1 ) ) ;
check . equals ( ship . getAttributeDescription ( "evasion" ) , "Damage points that may be evaded by maneuvering\n\nBase: +3\nUp2: +1\nActive effect: -1" ) ;
2017-07-12 23:18:20 +00:00
} ) ;
2017-11-29 23:56:22 +00:00
test . case ( "produces death diffs" , check = > {
let battle = TestTools . createBattle ( 1 ) ;
let ship = nn ( battle . playing_ship ) ;
check . equals ( ship . getDeathDiffs ( battle ) , [
new ShipValueDiff ( ship , "hull" , - 1 ) ,
new ShipDeathDiff ( battle , ship ) ,
] ) ;
2018-03-26 15:30:43 +00:00
let effect1 = ship . active_effects . add ( new AttributeEffect ( "shield_capacity" , 2 ) ) ;
let effect2 = ship . active_effects . add ( new StickyEffect ( new AttributeLimitEffect ( "evasion" , 1 ) ) ) ;
2018-02-08 15:16:03 +00:00
let action1 = ship . actions . addCustom ( new ToggleAction ( "weapon1" , { power : 3 } ) ) ;
let action2 = ship . actions . addCustom ( new ToggleAction ( "weapon2" , { power : 3 } ) ) ;
ship . actions . toggle ( action2 , true ) ;
2017-11-29 23:56:22 +00:00
check . equals ( ship . getDeathDiffs ( battle ) , [
new ShipEffectRemovedDiff ( ship , effect1 ) ,
2018-03-26 15:30:43 +00:00
new ShipAttributeDiff ( ship , "shield_capacity" , { } , { cumulative : 2 } ) ,
2017-11-29 23:56:22 +00:00
new ShipEffectRemovedDiff ( ship , effect2 ) ,
2018-03-26 15:30:43 +00:00
new ShipAttributeDiff ( ship , "evasion" , { } , { limit : 1 } ) ,
2018-02-08 15:16:03 +00:00
new ShipActionToggleDiff ( ship , action2 , false ) ,
2017-11-29 23:56:22 +00:00
new ShipValueDiff ( ship , "hull" , - 1 ) ,
new ShipDeathDiff ( battle , ship ) ,
] ) ;
} ) ;
2014-12-31 00:00:00 +00:00
} ) ;
2015-01-07 00:00:00 +00:00
}