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-04-25 23:27:42 +00:00
|
|
|
constructor(code: string, name: string, level: number, cargo: number, ...slots: SlotType[]) {
|
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;
|
2015-05-05 19:49:33 +00:00
|
|
|
this.slots = slots;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-04-25 23:27:42 +00:00
|
|
|
result.push(new ShipModel("scout", "Scout", 1, 2, SlotType.Hull, SlotType.Power, SlotType.Power, SlotType.Engine, SlotType.Weapon));
|
2015-05-05 19:49:33 +00:00
|
|
|
|
2017-05-14 20:07:33 +00:00
|
|
|
result.push(new ShipModel("breeze", "Breeze", 1, 0, SlotType.Hull, SlotType.Power, SlotType.Power, SlotType.Engine, SlotType.Engine, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("creeper", "Creeper", 1, 2, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("whirlwind", "Whirlwind", 1, 8, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("tomahawk", "Tomahawk", 1, 8, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("avenger", "Avenger", 1, 4, SlotType.Hull, SlotType.Shield, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("commodore", "Commodore", 1, 4, SlotType.Hull, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
2015-05-05 19:49:33 +00:00
|
|
|
SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
2017-05-14 20:07:33 +00:00
|
|
|
result.push(new ShipModel("falcon", "Falcon", 1, 2, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon, SlotType.Weapon, SlotType.Weapon));
|
2017-04-15 21:16:55 +00:00
|
|
|
|
2017-05-17 21:36:56 +00:00
|
|
|
result.push(new ShipModel("flea", "Flea", 1, 0, SlotType.Hull, SlotType.Power, SlotType.Power, SlotType.Engine, SlotType.Engine, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("jumper", "Jumper", 1, 2, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("rhino", "Rhino", 1, 16, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
|
|
|
SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("trapper", "Trapper", 1, 8, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
|
|
|
result.push(new ShipModel("xander", "Xander", 1, 8, SlotType.Hull, SlotType.Shield, SlotType.Power, SlotType.Engine,
|
|
|
|
SlotType.Weapon, SlotType.Weapon));
|
|
|
|
|
2015-05-05 19:49:33 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pick a random model in the default collection
|
|
|
|
static getRandomModel(level: Number, random: RandomGenerator = new RandomGenerator()): ShipModel {
|
|
|
|
var collection = this.getDefaultCollection();
|
|
|
|
collection = collection.filter((model: ShipModel) => {
|
|
|
|
return model.level <= level;
|
|
|
|
});
|
|
|
|
var result = random.choice(collection);
|
|
|
|
if (!result) {
|
|
|
|
console.error("Couldn't pick a random model for level " + level.toString());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|