2017-11-14 00:07:06 +00:00
|
|
|
/// <reference path="../common/RObject.ts" />
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-11-14 00:07:06 +00:00
|
|
|
/**
|
|
|
|
* One player (human or IA)
|
|
|
|
*/
|
|
|
|
export class Player extends RObject {
|
2017-04-25 23:27:42 +00:00
|
|
|
// Player's name
|
2017-06-27 15:42:28 +00:00
|
|
|
name: string
|
2017-04-25 23:27:42 +00:00
|
|
|
|
2018-01-16 00:08:24 +00:00
|
|
|
// Bound fleet
|
2017-06-27 15:42:28 +00:00
|
|
|
fleet: Fleet
|
2014-12-29 00:00:00 +00:00
|
|
|
|
2017-06-27 15:42:28 +00:00
|
|
|
// Active missions
|
|
|
|
missions = new ActiveMissions()
|
2015-03-19 00:00:00 +00:00
|
|
|
|
2014-12-29 00:00:00 +00:00
|
|
|
// Create a player, with an empty fleet
|
2018-01-16 00:08:24 +00:00
|
|
|
constructor(name = "Player", fleet?: Fleet) {
|
2017-11-14 00:07:06 +00:00
|
|
|
super();
|
|
|
|
|
2017-04-25 23:27:42 +00:00
|
|
|
this.name = name;
|
2018-01-16 00:08:24 +00:00
|
|
|
this.fleet = fleet || new Fleet(this);
|
|
|
|
|
|
|
|
this.fleet.setPlayer(this);
|
2014-12-29 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a quick random player, with a fleet, for testing purposes
|
2017-05-02 22:49:35 +00:00
|
|
|
static newQuickRandom(name: string, level = 1, shipcount = 4, upgrade = false): Player {
|
2018-01-16 00:08:24 +00:00
|
|
|
let player = new Player(name);
|
2017-04-25 23:27:42 +00:00
|
|
|
let generator = new FleetGenerator();
|
2017-05-02 22:49:35 +00:00
|
|
|
player.fleet = generator.generate(level, player, shipcount, upgrade);
|
2014-12-29 00:00:00 +00:00
|
|
|
return player;
|
|
|
|
}
|
2015-03-19 00:00:00 +00:00
|
|
|
|
2017-01-29 18:34:38 +00:00
|
|
|
/**
|
2018-01-16 00:08:24 +00:00
|
|
|
* Get a cheats object
|
2017-01-29 18:34:38 +00:00
|
|
|
*/
|
2018-01-16 00:08:24 +00:00
|
|
|
getCheats(): BattleCheats | null {
|
|
|
|
let battle = this.getBattle();
|
|
|
|
if (battle) {
|
|
|
|
return new BattleCheats(battle, this);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2015-03-19 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 18:34:38 +00:00
|
|
|
/**
|
2018-01-16 00:08:24 +00:00
|
|
|
* Return true if the player has visited at least one location in a given system.
|
2017-01-29 18:34:38 +00:00
|
|
|
*/
|
2018-01-16 00:08:24 +00:00
|
|
|
hasVisitedSystem(system: Star): boolean {
|
|
|
|
return intersection(this.fleet.visited, system.locations.map(loc => loc.id)).length > 0;
|
2017-01-29 18:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-16 00:08:24 +00:00
|
|
|
* Return true if the player has visited a given star location.
|
2017-01-29 18:34:38 +00:00
|
|
|
*/
|
2018-01-16 00:08:24 +00:00
|
|
|
hasVisitedLocation(location: StarLocation): boolean {
|
|
|
|
return contains(this.fleet.visited, location.id);
|
2015-03-19 00:00:00 +00:00
|
|
|
}
|
2015-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
// Get currently played battle, null when none is in progress
|
2017-03-09 17:11:00 +00:00
|
|
|
getBattle(): Battle | null {
|
2015-04-07 00:00:00 +00:00
|
|
|
return this.fleet.battle;
|
|
|
|
}
|
2017-03-09 17:11:00 +00:00
|
|
|
setBattle(battle: Battle | null): void {
|
2015-04-07 00:00:00 +00:00
|
|
|
this.fleet.setBattle(battle);
|
2017-06-29 17:25:38 +00:00
|
|
|
this.missions.checkStatus();
|
2015-04-07 00:00:00 +00:00
|
|
|
}
|
2014-12-29 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|