1
0
Fork 0
spacetac/src/core/Shop.ts

51 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac {
2017-03-23 18:58:09 +00:00
/**
* A shop is a place to buy/sell equipments
*/
export class Shop {
2017-05-10 15:29:10 +00:00
// Average level of equipment
private level: number
// Random generator
private random: RandomGenerator
2017-07-06 22:55:29 +00:00
// Available missions
private missions: Mission[] = []
constructor(level = 1) {
2017-05-10 15:29:10 +00:00
this.level = level;
this.random = new RandomGenerator();
2017-03-23 18:58:09 +00:00
}
2017-07-06 22:55:29 +00:00
/**
* Get a list of available secondary missions
*/
getMissions(around: StarLocation, max_count = 3): Mission[] {
while (this.missions.length < max_count) {
2017-07-10 20:40:22 +00:00
let generator = new MissionGenerator(around.star.universe, around, this.random);
2017-07-06 22:55:29 +00:00
let mission = generator.generate();
this.missions.push(mission);
}
return this.missions;
}
/**
* Assign a mission to a fleet
*
* Returns true on success
*/
acceptMission(mission: Mission, player: Player): boolean {
if (contains(this.missions, mission)) {
if (player.missions.addSecondary(mission, player.fleet)) {
remove(this.missions, mission);
return true;
} else {
return false;
}
2017-07-06 22:55:29 +00:00
} else {
return false;
}
}
2017-03-23 18:58:09 +00:00
}
}