1
0
Fork 0

Added AP usage checking on weapons

This commit is contained in:
Michaël Lemaire 2015-01-28 01:00:00 +01:00 committed by Michaël Lemaire
parent ef1f0914b8
commit 4d29d2cbc2
2 changed files with 20 additions and 1 deletions

View file

@ -15,7 +15,7 @@ module SpaceTac.Game {
}
canBeUsed(battle: Battle, ship: Ship): boolean {
return ship.ap_current.current > 0;
return ship.ap_current.current >= this.equipment.ap_usage;
}
checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target {

View file

@ -34,6 +34,25 @@ module SpaceTac.Game.Specs {
expect(action.can_target_space).toBe(false);
});
it("can't fire without sufficient AP", function () {
var ship = new Ship();
ship.ap_current.set(3);
var weapon = new Equipments.AbstractWeapon("Super Fire Weapon", 50);
weapon.ap_usage = new Range(2);
var equipment = weapon.generateFixed(0);
expect(equipment.action.canBeUsed(null, ship)).toBe(true);
weapon.ap_usage = new Range(3);
equipment = weapon.generateFixed(0);
expect(equipment.action.canBeUsed(null, ship)).toBe(true);
weapon.ap_usage = new Range(4);
equipment = weapon.generateFixed(0);
expect(equipment.action.canBeUsed(null, ship)).toBe(false);
});
it("can't friendly fire", function () {
var fleet1 = new Fleet(new Player());
var fleet2 = new Fleet(new Player());