Consume power before action starts
This commit is contained in:
parent
8b2a4ea026
commit
aa3af26790
|
@ -269,9 +269,18 @@ module TS.SpaceTac {
|
|||
}
|
||||
}
|
||||
|
||||
// Consumes action points
|
||||
useActionPoints(value: number): void {
|
||||
this.setValue("power", -value, true);
|
||||
/**
|
||||
* Consumes action points
|
||||
*
|
||||
* Return true if it was possible, false if there wasn't enough points.
|
||||
*/
|
||||
useActionPoints(value: number): boolean {
|
||||
if (this.getValue("power") >= value) {
|
||||
this.setValue("power", -value, true);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Call a method for each drone of the battlefield
|
||||
|
|
|
@ -100,23 +100,20 @@ module TS.SpaceTac {
|
|||
return false;
|
||||
}
|
||||
|
||||
var cost = this.getActionPointsUsage(battle, ship, target);
|
||||
if (this.customApply(battle, ship, target)) {
|
||||
if (cost > 0) {
|
||||
ship.useActionPoints(cost);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
let cost = this.getActionPointsUsage(battle, ship, target);
|
||||
if (!ship.useActionPoints(cost)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.customApply(battle, ship, target);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to reimplement to apply a action
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||
return false;
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ module TS.SpaceTac {
|
|||
return target;
|
||||
}
|
||||
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target) {
|
||||
let drone = new Drone(ship, this.equipment.code);
|
||||
drone.x = target.x;
|
||||
drone.y = target.y;
|
||||
|
@ -23,7 +23,6 @@ module TS.SpaceTac {
|
|||
drone.effects = this.equipment.target_effects;
|
||||
drone.duration = this.equipment.duration;
|
||||
battle.addDrone(drone);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@ module TS.SpaceTac {
|
|||
super("endturn", "End ship's turn", false);
|
||||
}
|
||||
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target) {
|
||||
ship.endTurn();
|
||||
battle.advanceToNextShip();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ module TS.SpaceTac {
|
|||
}
|
||||
}
|
||||
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target) {
|
||||
var affected: Ship[] = [];
|
||||
var blast = this.getBlastRadius(ship);
|
||||
|
||||
|
@ -58,8 +58,6 @@ module TS.SpaceTac {
|
|||
effect.applyOnShip(affship);
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,16 +65,16 @@ module TS.SpaceTac {
|
|||
|
||||
expect(battle.log.events.length).toBe(2);
|
||||
|
||||
expect(battle.log.events[0].code).toEqual("move");
|
||||
expect(battle.log.events[0].code).toEqual("value");
|
||||
expect(battle.log.events[0].ship).toBe(ship);
|
||||
expect(battle.log.events[0].target.ship).toBeNull();
|
||||
expect(battle.log.events[0].target.x).toBeCloseTo(3.535533, 0.00001);
|
||||
expect(battle.log.events[0].target.y).toBeCloseTo(3.535533, 0.00001);
|
||||
|
||||
expect(battle.log.events[1].code).toEqual("value");
|
||||
expect(battle.log.events[1].ship).toBe(ship);
|
||||
expect((<ValueChangeEvent>battle.log.events[1]).value).toEqual(
|
||||
expect((<ValueChangeEvent>battle.log.events[0]).value).toEqual(
|
||||
new ShipValue("power", 0, 20));
|
||||
|
||||
expect(battle.log.events[1].code).toEqual("move");
|
||||
expect(battle.log.events[1].ship).toBe(ship);
|
||||
expect(battle.log.events[1].target.ship).toBeNull();
|
||||
expect(battle.log.events[1].target.x).toBeCloseTo(3.535533, 0.00001);
|
||||
expect(battle.log.events[1].target.y).toBeCloseTo(3.535533, 0.00001);
|
||||
});
|
||||
|
||||
it("can't move too much near another ship", function () {
|
||||
|
|
|
@ -59,9 +59,8 @@ module TS.SpaceTac {
|
|||
return target;
|
||||
}
|
||||
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
|
||||
protected customApply(battle: Battle, ship: Ship, target: Target) {
|
||||
ship.moveTo(target.x, target.y);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,14 +239,14 @@ module TS.SpaceTac.Specs {
|
|||
|
||||
expect(battle.log.events.length).toBe(7);
|
||||
|
||||
expect(battle.log.events[0]).toEqual(new MoveEvent(ship1, 2, 0));
|
||||
expect(battle.log.events[1]).toEqual(new ValueChangeEvent(ship1, new ShipValue("power", 2, 10), -4));
|
||||
expect(battle.log.events[0]).toEqual(new ValueChangeEvent(ship1, new ShipValue("power", 2, 10), -4));
|
||||
expect(battle.log.events[1]).toEqual(new MoveEvent(ship1, 2, 0));
|
||||
|
||||
expect(battle.log.events[2]).toEqual(new FireEvent(ship1, weapon, Target.newFromShip(ship2)));
|
||||
expect(battle.log.events[3]).toEqual(new ValueChangeEvent(ship2, new ShipValue("shield", 0), -10));
|
||||
expect(battle.log.events[4]).toEqual(new ValueChangeEvent(ship2, new ShipValue("hull", 5), -10));
|
||||
expect(battle.log.events[5]).toEqual(new DamageEvent(ship2, 10, 10));
|
||||
expect(battle.log.events[6]).toEqual(new ValueChangeEvent(ship1, new ShipValue("power", 1, 10), -1));
|
||||
expect(battle.log.events[2]).toEqual(new ValueChangeEvent(ship1, new ShipValue("power", 1, 10), -1));
|
||||
expect(battle.log.events[3]).toEqual(new FireEvent(ship1, weapon, Target.newFromShip(ship2)));
|
||||
expect(battle.log.events[4]).toEqual(new ValueChangeEvent(ship2, new ShipValue("shield", 0), -10));
|
||||
expect(battle.log.events[5]).toEqual(new ValueChangeEvent(ship2, new ShipValue("hull", 5), -10));
|
||||
expect(battle.log.events[6]).toEqual(new DamageEvent(ship2, 10, 10));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ module TS.SpaceTac.Specs {
|
|||
|
||||
var ship = new Ship();
|
||||
var target = new Ship();
|
||||
TestTools.setShipAP(ship, 50);
|
||||
TestTools.setShipAP(target, 7, 2);
|
||||
spyOn(equipment.action, "canBeUsed").and.returnValue(true);
|
||||
|
||||
expect(target.values.power.get()).toBe(7);
|
||||
expect(target.sticky_effects).toEqual([]);
|
||||
|
|
Loading…
Reference in a new issue