1
0
Fork 0
spacetac/src/core/missions/MissionGenerator.ts

86 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-07-06 22:55:29 +00:00
module TS.SpaceTac {
const POOL_SHIP_NAMES = [
"Zert",
"Ob'tec",
"Paayk",
"Fen_amr",
"TempZst",
"croNt",
"Appn",
"Vertix",
"Opan-vel",
"Yz-aol",
"Arkant",
"PNX",
]
2017-07-06 22:55:29 +00:00
/**
* Random generator of secondary missions that can be taken from
*/
export class MissionGenerator {
universe: Universe
around: StarLocation
random: RandomGenerator
2017-07-10 20:40:22 +00:00
constructor(universe: Universe, around: StarLocation, random = RandomGenerator.global) {
2017-07-06 22:55:29 +00:00
this.universe = universe;
this.around = around;
this.random = random;
}
/**
* Generate a single mission
*/
generate(): Mission {
let generators = [
2017-07-10 20:40:22 +00:00
bound(this, "generateEscort"),
bound(this, "generateCleanLocation"),
2017-07-06 22:55:29 +00:00
];
let generator = this.random.choice(generators);
let result = generator();
// TODO Add reward
return result;
}
/**
* Generate a new ship
*/
2017-07-10 20:40:22 +00:00
private generateShip(level: number) {
let generator = new ShipGenerator(this.random);
2017-07-10 20:40:22 +00:00
let result = generator.generate(level, null, true);
result.name = `${this.random.choice(POOL_SHIP_NAMES)}-${this.random.randInt(10, 999)}`;
return result;
}
2017-07-06 22:55:29 +00:00
/**
* Generate an escort mission
*/
generateEscort(): Mission {
let mission = new Mission(this.universe);
2017-07-10 20:40:22 +00:00
let dest_star = this.random.choice(this.around.star.getNeighbors());
2017-07-06 22:55:29 +00:00
let destination = this.random.choice(dest_star.locations);
2017-07-10 20:40:22 +00:00
let ship = this.generateShip(dest_star.level);
2017-07-06 22:55:29 +00:00
mission.addPart(new MissionPartEscort(mission, destination, ship));
mission.title = `Escort a ship to a level ${dest_star.level} system`;
return mission;
}
2017-07-10 20:40:22 +00:00
/**
* Generate a clean location mission
*/
generateCleanLocation(): Mission {
let mission = new Mission(this.universe);
let dest_star = this.random.choice(this.around.star.getNeighbors().concat([this.around.star]));
let choices = dest_star.locations;
if (dest_star == this.around.star) {
choices = choices.filter(loc => loc != this.around);
}
let destination = this.random.choice(choices);
mission.addPart(new MissionPartCleanLocation(mission, destination));
mission.title = `Defeat a level ${destination.star.level} fleet in ${(dest_star == this.around.star) ? "this" : "a nearby"} system`;
return mission;
}
2017-07-06 22:55:29 +00:00
}
}