diff --git a/gulpfile.js b/gulpfile.js index 574fd66..4cd35c3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -41,7 +41,7 @@ gulp.task('copy', function () { var tsProject = ts.createProject({ declarationFiles: true, noExternalResolve: true, - noImplicitAny: true, + noImplicitAny: false, // Handled by tslint sortOutput: true, sourceRoot: '../scripts' }); diff --git a/src/scripts/game/Equipment.ts b/src/scripts/game/Equipment.ts index ad63766..ba0fd07 100644 --- a/src/scripts/game/Equipment.ts +++ b/src/scripts/game/Equipment.ts @@ -23,5 +23,8 @@ module SpaceTac.Game { // Level requirement min_level: number; + + // Action associated with this equipment + action: BaseAction; } } diff --git a/src/scripts/game/LootTemplate.ts b/src/scripts/game/LootTemplate.ts index fb3e1fb..f68159c 100644 --- a/src/scripts/game/LootTemplate.ts +++ b/src/scripts/game/LootTemplate.ts @@ -61,6 +61,8 @@ module SpaceTac.Game { result.ap_usage = this.ap_usage.getProportional(power); result.min_level = this.min_level.getProportional(power); + result.action = this.getActionForEquipment(result); + return result; } @@ -100,5 +102,10 @@ module SpaceTac.Game { return null; } } + + // Method to reimplement to assign an action to a generated equipment + protected getActionForEquipment(equipment: Equipment): BaseAction { + return null; + } } } diff --git a/src/scripts/game/Ship.ts b/src/scripts/game/Ship.ts index 05afde0..f0283b4 100644 --- a/src/scripts/game/Ship.ts +++ b/src/scripts/game/Ship.ts @@ -90,11 +90,19 @@ module SpaceTac.Game { } // Get the list of actions available - // This list does not filter out actions unavailable due to insufficient AP, it justs filter out + // This list does not filter out actions unavailable due to insufficient AP, it only filters out // actions that are not allowed/available at all on the ship getAvailableActions(): BaseAction[] { - // TODO - return [new MoveAction(), new EndTurnAction()]; + var actions: BaseAction[] = []; + + this.slots.forEach((slot: Slot) => { + if (slot.attached && slot.attached.action) { + actions.push(slot.attached.action); + } + }); + + actions.push(new EndTurnAction()); + return actions; } // Consumes action points diff --git a/src/scripts/game/Slot.ts b/src/scripts/game/Slot.ts index 2462c28..7c53aa8 100644 --- a/src/scripts/game/Slot.ts +++ b/src/scripts/game/Slot.ts @@ -1,7 +1,14 @@ module SpaceTac.Game { "use strict"; - export enum SlotType {Armor, Shield, Engine, Power, Weapon, } + // Types of slots + export enum SlotType { + Armor, + Shield, + Engine, + Power, + Weapon + } // Slot to attach an equipment to a ship export class Slot { diff --git a/src/scripts/game/equipments/ConventionalEngine.ts b/src/scripts/game/equipments/ConventionalEngine.ts new file mode 100644 index 0000000..f527f16 --- /dev/null +++ b/src/scripts/game/equipments/ConventionalEngine.ts @@ -0,0 +1,18 @@ +/// + +module SpaceTac.Game.Equipments { + "use strict"; + + // Equipment: Conventional Engine + export class ConventionalEngine extends LootTemplate { + constructor() { + super(SlotType.Engine, "Conventional Engine"); + + this.min_level = new IntegerRange(1, 1); + } + + protected getActionForEquipment(equipment: Equipment): BaseAction { + return new MoveAction(); + } + } +} diff --git a/src/scripts/game/specs/Ship.spec.ts b/src/scripts/game/specs/Ship.spec.ts index 2125c59..eee45be 100644 --- a/src/scripts/game/specs/Ship.spec.ts +++ b/src/scripts/game/specs/Ship.spec.ts @@ -34,5 +34,26 @@ module SpaceTac.Game { expect(ship.arena_x).toBeCloseTo(52.333333, 0.00001); expect(ship.arena_y).toEqual(50); }); + + it("lists available actions from attached equipment", function () { + var ship = new Ship(null, "Test"); + var actions: BaseAction[]; + var slot: Slot; + var equipment: Equipment; + + actions = ship.getAvailableActions(); + expect(actions.length).toBe(1); + expect(actions[0].code).toEqual("endturn"); + + slot = ship.addSlot(SlotType.Engine); + equipment = new Equipment(); + equipment.action = new MoveAction(); + slot.attach(equipment); + + actions = ship.getAvailableActions(); + expect(actions.length).toBe(2); + expect(actions[0].code).toEqual("move"); + expect(actions[1].code).toEqual("endturn"); + }); }); }