Added a ship model system
This commit is contained in:
parent
dcbfbca891
commit
301bce75e0
1
TODO
1
TODO
|
@ -3,4 +3,3 @@
|
||||||
* Add retreat from battle
|
* Add retreat from battle
|
||||||
* Refactor the tooltip system to use it more
|
* Refactor the tooltip system to use it more
|
||||||
* Flash ship icons that receive damage
|
* Flash ship icons that receive damage
|
||||||
* Add a ship model system
|
|
|
@ -14,6 +14,9 @@ module SpaceTac.Game {
|
||||||
// Name of the ship
|
// Name of the ship
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
// Code of the ShipModel used to create it
|
||||||
|
model: string;
|
||||||
|
|
||||||
// Flag indicating if the ship is alive
|
// Flag indicating if the ship is alive
|
||||||
alive: boolean;
|
alive: boolean;
|
||||||
|
|
||||||
|
@ -67,6 +70,7 @@ module SpaceTac.Game {
|
||||||
this.fleet = fleet || new Fleet();
|
this.fleet = fleet || new Fleet();
|
||||||
this.level = 1;
|
this.level = 1;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.model = "default";
|
||||||
this.alive = true;
|
this.alive = true;
|
||||||
this.initiative = this.newAttribute(AttributeCode.Initiative);
|
this.initiative = this.newAttribute(AttributeCode.Initiative);
|
||||||
this.initiative.setMaximal(1);
|
this.initiative.setMaximal(1);
|
||||||
|
|
|
@ -13,16 +13,20 @@ module SpaceTac.Game {
|
||||||
|
|
||||||
// Generate a ship of a given level
|
// Generate a ship of a given level
|
||||||
// The ship will not be named, nor will be a member of any fleet
|
// The ship will not be named, nor will be a member of any fleet
|
||||||
generate(level: number): Ship {
|
generate(level: number, model: ShipModel = null): Ship {
|
||||||
var result = new Ship();
|
var result = new Ship();
|
||||||
var loot = new LootGenerator(this.random);
|
var loot = new LootGenerator(this.random);
|
||||||
|
|
||||||
// Add equipment slots
|
if (!model) {
|
||||||
result.addSlot(SlotType.Armor);
|
// Get a random model
|
||||||
result.addSlot(SlotType.Engine);
|
model = ShipModel.getRandomModel(level, this.random);
|
||||||
result.addSlot(SlotType.Power);
|
}
|
||||||
result.addSlot(SlotType.Shield);
|
|
||||||
result.addSlot(SlotType.Weapon);
|
// Apply model
|
||||||
|
result.model = model.code;
|
||||||
|
model.slots.forEach((slot: SlotType) => {
|
||||||
|
result.addSlot(slot);
|
||||||
|
});
|
||||||
|
|
||||||
// Fill equipment slots
|
// Fill equipment slots
|
||||||
result.slots.forEach((slot: Slot) => {
|
result.slots.forEach((slot: Slot) => {
|
||||||
|
|
48
src/app/game/ShipModel.ts
Normal file
48
src/app/game/ShipModel.ts
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
module SpaceTac.Game {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// A model of ship
|
||||||
|
// It defines the ship looks, and available slots for equipment
|
||||||
|
export class ShipModel {
|
||||||
|
// Code to identify the model
|
||||||
|
code: string;
|
||||||
|
|
||||||
|
// Minimal level to use this model
|
||||||
|
level: number;
|
||||||
|
|
||||||
|
// Available slots
|
||||||
|
slots: SlotType[];
|
||||||
|
|
||||||
|
constructor(code: string, level: number, ...slots: SlotType[]) {
|
||||||
|
this.code = code;
|
||||||
|
this.level = level;
|
||||||
|
this.slots = slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the default ship model collection available in-game
|
||||||
|
static getDefaultCollection(): ShipModel[] {
|
||||||
|
// TODO Store in cache
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
result.push(new ShipModel("scout", 1, SlotType.Armor, SlotType.Engine, SlotType.Power, SlotType.Weapon));
|
||||||
|
|
||||||
|
result.push(new ShipModel("whirlwind", 1, SlotType.Armor, SlotType.Engine, SlotType.Power, SlotType.Shield,
|
||||||
|
SlotType.Weapon, SlotType.Weapon));
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/// <reference path="../../definitions/jasmine.d.ts"/>
|
/// <reference path="../../definitions/jasmine.d.ts"/>
|
||||||
|
|
||||||
module SpaceTac.Game {
|
module SpaceTac.Game.Specs {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("Ship", function () {
|
describe("Ship", function () {
|
||||||
|
|
18
src/app/game/specs/ShipGenerator.spec.ts
Normal file
18
src/app/game/specs/ShipGenerator.spec.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/// <reference path="../../definitions/jasmine.d.ts"/>
|
||||||
|
|
||||||
|
module SpaceTac.Game.Specs {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("ShipGenerator", function () {
|
||||||
|
it("can use ship model", function () {
|
||||||
|
var gen = new ShipGenerator();
|
||||||
|
var model = new ShipModel("test", 1, SlotType.Shield, SlotType.Weapon, SlotType.Weapon);
|
||||||
|
var ship = gen.generate(1, model);
|
||||||
|
expect(ship.model).toBe("test");
|
||||||
|
expect(ship.slots.length).toBe(3);
|
||||||
|
expect(ship.slots[0].type).toBe(SlotType.Shield);
|
||||||
|
expect(ship.slots[1].type).toBe(SlotType.Weapon);
|
||||||
|
expect(ship.slots[2].type).toBe(SlotType.Weapon);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ module SpaceTac.View {
|
||||||
super(battleview.game);
|
super(battleview.game);
|
||||||
|
|
||||||
// Add ship sprite
|
// Add ship sprite
|
||||||
this.sprite = new Phaser.Button(battleview.game, 0, 0, "ship-scout-sprite");
|
this.sprite = new Phaser.Button(battleview.game, 0, 0, "ship-" + ship.model + "-sprite");
|
||||||
this.sprite.rotation = ship.arena_angle;
|
this.sprite.rotation = ship.arena_angle;
|
||||||
this.sprite.anchor.set(0.5, 0.5);
|
this.sprite.anchor.set(0.5, 0.5);
|
||||||
this.addChild(this.sprite);
|
this.addChild(this.sprite);
|
||||||
|
|
|
@ -41,7 +41,7 @@ module SpaceTac.View {
|
||||||
this.layer_base = new Phaser.Image(this.game, 0, 0, "battle-shiplist-base", 0);
|
this.layer_base = new Phaser.Image(this.game, 0, 0, "battle-shiplist-base", 0);
|
||||||
this.addChild(this.layer_base);
|
this.addChild(this.layer_base);
|
||||||
|
|
||||||
this.layer_portrait = new Phaser.Image(this.game, 30, 30, "ship-scout-portrait", 0);
|
this.layer_portrait = new Phaser.Image(this.game, 30, 30, "ship-" + ship.model + "-portrait", 0);
|
||||||
this.layer_portrait.anchor.set(0.5, 0.5);
|
this.layer_portrait.anchor.set(0.5, 0.5);
|
||||||
this.layer_portrait.scale.set(0.19, 0.19);
|
this.layer_portrait.scale.set(0.19, 0.19);
|
||||||
this.addChild(this.layer_portrait);
|
this.addChild(this.layer_portrait);
|
||||||
|
|
Loading…
Reference in a new issue