1
0
Fork 0
spacetac/src/core/missions/MissionPartEscort.spec.ts

69 lines
2.6 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.Specs {
2017-10-26 21:47:13 +00:00
testing("MissionPartEscort", test => {
test.case("completes when the fleet is at location, with its escort", check => {
2017-07-02 18:21:04 +00:00
let destination = new StarLocation(new Star(null, 0, 0, "Atanax"));
destination.encounter_random = new SkewedRandomGenerator([0], true);
let universe = new Universe();
let fleet = new Fleet();
let ship = new Ship(null, "Zybux");
let part = new MissionPartEscort(new Mission(universe, fleet), destination, ship);
2017-10-26 21:47:13 +00:00
check.notcontains(fleet.ships, ship);
check.equals(part.title, "Escort Zybux to Atanax system");
check.same(part.checkCompleted(), false, "Init location");
2017-07-02 18:21:04 +00:00
part.onStarted();
2017-10-26 21:47:13 +00:00
check.contains(fleet.ships, ship);
2017-07-02 18:21:04 +00:00
fleet.setLocation(destination);
2017-10-26 21:47:13 +00:00
check.same(part.checkCompleted(), false, "Encounter not clear");
2017-07-02 18:21:04 +00:00
destination.clearEncounter();
2017-10-26 21:47:13 +00:00
check.same(part.checkCompleted(), true, "Encouter cleared");
2017-07-02 18:21:04 +00:00
fleet.setLocation(new StarLocation());
2017-10-26 21:47:13 +00:00
check.same(part.checkCompleted(), false, "Went to another system");
2017-07-02 18:21:04 +00:00
fleet.setLocation(destination);
2017-10-26 21:47:13 +00:00
check.same(part.checkCompleted(), true, "Back at destination");
check.contains(fleet.ships, ship);
2017-07-02 18:21:04 +00:00
part.onEnded();
2017-10-26 21:47:13 +00:00
check.notcontains(fleet.ships, ship);
2017-07-02 18:21:04 +00:00
})
2017-10-26 21:47:13 +00:00
test.case("sets the escorted ship as critical in battles", check => {
2017-07-02 18:21:04 +00:00
let universe = new Universe();
let fleet = new Fleet();
let ship1 = fleet.addShip();
let ship2 = fleet.addShip();
let ship = new Ship();
let destination = new StarLocation(new Star());
let part = new MissionPartEscort(new Mission(universe, fleet), destination, ship);
part.onStarted();
2017-10-26 21:47:13 +00:00
check.contains(fleet.ships, ship);
2017-07-02 18:21:04 +00:00
let enemy = new Fleet();
enemy.addShip();
let battle = new Battle(fleet, enemy);
battle.ships.list().forEach(ship => TestTools.setShipHP(ship, 10, 0));
2017-07-02 18:21:04 +00:00
battle.start();
battle.performChecks();
2017-10-26 21:47:13 +00:00
check.equals(battle.ended, false);
2017-07-02 18:21:04 +00:00
// if a fleet member dies, it is not over
ship1.setDead();
battle.performChecks();
2017-10-26 21:47:13 +00:00
check.equals(battle.ended, false);
2017-07-02 18:21:04 +00:00
// if the critical ship dies, it is defeat
ship.setDead();
battle.performChecks();
2017-10-26 21:47:13 +00:00
check.equals(battle.ended, true);
check.notsame(nn(battle.outcome).winner, fleet);
2017-07-02 18:21:04 +00:00
})
})
}