2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2015-05-05 19:49:33 +00:00
|
|
|
// A model of ship
|
|
|
|
// It defines the ship looks, and available slots for equipment
|
|
|
|
export class ShipModel {
|
|
|
|
// Code to identify the model
|
|
|
|
code: string;
|
|
|
|
|
2017-04-25 23:27:42 +00:00
|
|
|
// Human-readable model name
|
|
|
|
name: string;
|
|
|
|
|
2015-05-05 19:49:33 +00:00
|
|
|
// Minimal level to use this model
|
|
|
|
level: number;
|
|
|
|
|
2017-03-05 17:48:13 +00:00
|
|
|
// Cargo space
|
|
|
|
cargo: number;
|
|
|
|
|
2015-05-05 19:49:33 +00:00
|
|
|
// Available slots
|
|
|
|
slots: SlotType[];
|
|
|
|
|
2017-05-23 16:43:05 +00:00
|
|
|
constructor(code: string, name: string, level = 1, cargo = 6, default_slots = true, weapon_slots = 2) {
|
2015-05-05 19:49:33 +00:00
|
|
|
this.code = code;
|
2017-04-25 23:27:42 +00:00
|
|
|
this.name = name;
|
2015-05-05 19:49:33 +00:00
|
|
|
this.level = level;
|
2017-03-05 17:48:13 +00:00
|
|
|
this.cargo = cargo;
|
2017-05-23 16:43:05 +00:00
|
|
|
this.slots = default_slots ? [SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine] : [];
|
|
|
|
range(weapon_slots).forEach(() => this.slots.push(SlotType.Weapon));
|
2015-05-05 19:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default ship model collection available in-game
|
|
|
|
static getDefaultCollection(): ShipModel[] {
|
|
|
|
// TODO Store in cache
|
2017-03-09 17:11:00 +00:00
|
|
|
var result: ShipModel[] = [];
|
2015-05-05 19:49:33 +00:00
|
|
|
|
2017-05-23 16:43:05 +00:00
|
|
|
result.push(new ShipModel("scout", "Scout"));
|
|
|
|
result.push(new ShipModel("breeze", "Breeze"));
|
|
|
|
result.push(new ShipModel("creeper", "Creeper"));
|
|
|
|
result.push(new ShipModel("whirlwind", "Whirlwind"));
|
|
|
|
result.push(new ShipModel("tomahawk", "Tomahawk"));
|
|
|
|
result.push(new ShipModel("avenger", "Avenger"));
|
|
|
|
result.push(new ShipModel("commodore", "Commodore"));
|
|
|
|
result.push(new ShipModel("falcon", "Falcon"));
|
|
|
|
result.push(new ShipModel("flea", "Flea"));
|
|
|
|
result.push(new ShipModel("jumper", "Jumper"));
|
|
|
|
result.push(new ShipModel("rhino", "Rhino"));
|
|
|
|
result.push(new ShipModel("trapper", "Trapper"));
|
|
|
|
result.push(new ShipModel("xander", "Xander"));
|
2017-05-17 21:36:56 +00:00
|
|
|
|
2015-05-05 19:49:33 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-07-09 21:18:05 +00:00
|
|
|
/**
|
|
|
|
* Pick a random model in the default collection
|
|
|
|
*/
|
|
|
|
static getRandomModel(level?: number, random: RandomGenerator = new RandomGenerator()): ShipModel {
|
|
|
|
let collection = this.getDefaultCollection();
|
|
|
|
if (level) {
|
|
|
|
collection = collection.filter(model => model.level <= level);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collection.length == 0) {
|
|
|
|
console.error("Couldn't pick a random model");
|
|
|
|
return new ShipModel("undefined", "Undefined");
|
|
|
|
} else {
|
|
|
|
return random.choice(collection);
|
2015-05-05 19:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|