1
0
Fork 0

Added action listing from attached equipment

This commit is contained in:
Michaël Lemaire 2015-01-16 01:00:00 +01:00 committed by Michaël Lemaire
parent 03a0ab8e39
commit 7fae46b53e
7 changed files with 69 additions and 5 deletions

View file

@ -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'
});

View file

@ -23,5 +23,8 @@ module SpaceTac.Game {
// Level requirement
min_level: number;
// Action associated with this equipment
action: BaseAction;
}
}

View file

@ -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;
}
}
}

View file

@ -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

View file

@ -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 {

View file

@ -0,0 +1,18 @@
/// <reference path="../LootTemplate.ts"/>
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();
}
}
}

View file

@ -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");
});
});
}