2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("ActiveMissions", test => {
|
|
|
|
test.case("starts the main story arc", check => {
|
2017-06-27 15:42:28 +00:00
|
|
|
let missions = new ActiveMissions();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.main, null);
|
2017-06-27 15:42:28 +00:00
|
|
|
|
|
|
|
let session = new GameSession();
|
|
|
|
session.startNewGame(true, false);
|
|
|
|
|
|
|
|
missions.startMainStory(session.universe, session.player.fleet);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.notequals(missions.main, null);
|
2017-06-27 15:42:28 +00:00
|
|
|
})
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("gets the current list of missions, and updates them", check => {
|
2017-06-27 15:42:28 +00:00
|
|
|
let missions = new ActiveMissions();
|
2017-06-29 17:25:38 +00:00
|
|
|
let universe = new Universe();
|
|
|
|
let fleet = new Fleet();
|
2017-06-27 15:42:28 +00:00
|
|
|
|
2017-06-29 17:25:38 +00:00
|
|
|
missions.main = new Mission(universe, fleet);
|
|
|
|
missions.main.addPart(new MissionPart(missions.main, "Do something"));
|
2017-06-27 15:42:28 +00:00
|
|
|
missions.secondary = [
|
2017-06-29 17:25:38 +00:00
|
|
|
new Mission(universe, fleet),
|
|
|
|
new Mission(universe, fleet)
|
2017-06-27 15:42:28 +00:00
|
|
|
];
|
2017-06-29 17:25:38 +00:00
|
|
|
missions.secondary[0].addPart(new MissionPart(missions.secondary[0], "Maybe do something"));
|
|
|
|
missions.secondary[1].addPart(new MissionPart(missions.secondary[1], "Surely do something"));
|
2017-06-27 15:42:28 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.getCurrent().map(mission => mission.current_part.title), [
|
2017-06-27 15:42:28 +00:00
|
|
|
"Do something",
|
|
|
|
"Maybe do something",
|
|
|
|
"Surely do something",
|
|
|
|
]);
|
|
|
|
|
2017-06-29 17:25:38 +00:00
|
|
|
missions.checkStatus();
|
2017-06-27 15:42:28 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.getCurrent().map(mission => mission.current_part.title), [
|
2017-06-27 15:42:28 +00:00
|
|
|
"Do something",
|
|
|
|
"Maybe do something",
|
|
|
|
"Surely do something",
|
|
|
|
]);
|
|
|
|
|
|
|
|
spyOn(missions.secondary[0].current_part, "checkCompleted").and.returnValue(true);
|
2017-06-29 17:25:38 +00:00
|
|
|
missions.checkStatus();
|
2017-06-27 15:42:28 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.getCurrent().map(mission => mission.current_part.title), [
|
2017-06-27 15:42:28 +00:00
|
|
|
"Do something",
|
|
|
|
"Surely do something",
|
|
|
|
]);
|
|
|
|
|
|
|
|
spyOn(missions.main.current_part, "checkCompleted").and.returnValue(true);
|
2017-06-29 17:25:38 +00:00
|
|
|
missions.checkStatus();
|
2017-06-27 15:42:28 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.getCurrent().map(mission => mission.current_part.title), [
|
2017-06-27 15:42:28 +00:00
|
|
|
"Surely do something",
|
|
|
|
]);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.main, null);
|
2017-06-27 15:42:28 +00:00
|
|
|
})
|
2017-07-09 21:18:05 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("builds a hash to help monitor status changes", check => {
|
2017-07-09 21:18:05 +00:00
|
|
|
let universe = new Universe();
|
|
|
|
universe.generate(4);
|
|
|
|
let fleet = new Fleet();
|
|
|
|
fleet.setLocation(universe.getStartLocation(), true);
|
|
|
|
|
|
|
|
let missions = new ActiveMissions();
|
|
|
|
let hash = missions.getHash();
|
|
|
|
function checkChanged(info: string, expected = true) {
|
|
|
|
let new_hash = missions.getHash();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.same(new_hash != hash, expected, info);
|
2017-07-09 21:18:05 +00:00
|
|
|
hash = new_hash;
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.getHash(), hash, "Stable after " + info);
|
2017-07-09 21:18:05 +00:00
|
|
|
}
|
|
|
|
checkChanged("Stable at init", false);
|
|
|
|
|
|
|
|
missions.startMainStory(universe, fleet);
|
|
|
|
checkChanged("Main story started");
|
|
|
|
|
|
|
|
let mission = new Mission(universe, fleet);
|
|
|
|
mission.addPart(new MissionPartConversation(mission, [new Ship()]));
|
|
|
|
mission.addPart(new MissionPartConversation(mission, [new Ship()]));
|
|
|
|
missions.addSecondary(mission, fleet);
|
|
|
|
checkChanged("Secondary mission accepted");
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(mission.getIndex(), 0);
|
2017-07-09 21:18:05 +00:00
|
|
|
missions.checkStatus();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(mission.getIndex(), 1);
|
2017-07-09 21:18:05 +00:00
|
|
|
checkChanged("First conversation ended");
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.secondary.length, 1);
|
2017-07-09 21:18:05 +00:00
|
|
|
missions.checkStatus();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(missions.secondary.length, 0);
|
2017-07-09 21:18:05 +00:00
|
|
|
checkChanged("Second conversation ended - mission removed");
|
|
|
|
|
|
|
|
nn(missions.main).current_part.forceComplete();
|
|
|
|
missions.checkStatus();
|
|
|
|
checkChanged("Main mission progress");
|
|
|
|
});
|
2017-06-27 15:42:28 +00:00
|
|
|
})
|
|
|
|
}
|