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

79 lines
2.2 KiB
TypeScript
Raw Normal View History

/// <reference path="../common/RObject.ts" />
2017-09-24 22:23:22 +00:00
module TK.SpaceTac {
/**
* One player (human or IA)
*/
export class Player extends RObject {
// Player's name
name: string
// Bound fleet
fleet: Fleet
2014-12-29 00:00:00 +00:00
// Active missions
missions = new ActiveMissions()
2014-12-29 00:00:00 +00:00
// Create a player, with an empty fleet
constructor(name = "Player", fleet?: Fleet) {
super();
this.name = name;
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
static newQuickRandom(name: string, level = 1, shipcount = 4, upgrade = false): Player {
let player = new Player(name);
let generator = new FleetGenerator();
player.fleet = generator.generate(level, player, shipcount, upgrade);
2014-12-29 00:00:00 +00:00
return player;
}
/**
* Set the fleet for this player
*/
setFleet(fleet: Fleet): void {
this.fleet = fleet;
fleet.setPlayer(this);
}
2017-01-29 18:34:38 +00:00
/**
* Get a cheats object
2017-01-29 18:34:38 +00:00
*/
getCheats(): BattleCheats | null {
let battle = this.getBattle();
if (battle) {
return new BattleCheats(battle, this);
} else {
return null;
}
}
2017-01-29 18:34:38 +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
*/
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
}
/**
* Return true if the player has visited a given star location.
2017-01-29 18:34:38 +00:00
*/
hasVisitedLocation(location: StarLocation): boolean {
return contains(this.fleet.visited, location.id);
}
// Get currently played battle, null when none is in progress
2017-03-09 17:11:00 +00:00
getBattle(): Battle | null {
return this.fleet.battle;
}
2017-03-09 17:11:00 +00:00
setBattle(battle: Battle | null): void {
this.fleet.setBattle(battle);
2017-06-29 17:25:38 +00:00
this.missions.checkStatus();
}
2014-12-29 00:00:00 +00:00
}
2015-01-07 00:00:00 +00:00
}