Grant initial AP at start of battle, and recover when turn ends
This commit is contained in:
parent
cfaeb8da7a
commit
356486c6ce
|
@ -112,7 +112,7 @@ module SpaceTac.Game {
|
|||
expect(battle.playing_ship_index).toBe(2);
|
||||
});
|
||||
|
||||
it("calls startTurn on ships, with first turn indicator", function () {
|
||||
it("calls startTurn on ships", function () {
|
||||
var fleet1 = new Fleet(null);
|
||||
var fleet2 = new Fleet(null);
|
||||
|
||||
|
@ -131,16 +131,16 @@ module SpaceTac.Game {
|
|||
battle.throwInitiative(gen);
|
||||
|
||||
battle.advanceToNextShip();
|
||||
expect(ship1.startTurn).toHaveBeenCalledWith(true);
|
||||
expect(ship1.startTurn).toHaveBeenCalledWith();
|
||||
|
||||
battle.advanceToNextShip();
|
||||
expect(ship2.startTurn).toHaveBeenCalledWith(true);
|
||||
expect(ship2.startTurn).toHaveBeenCalledWith();
|
||||
|
||||
battle.advanceToNextShip();
|
||||
expect(ship3.startTurn).toHaveBeenCalledWith(true);
|
||||
expect(ship3.startTurn).toHaveBeenCalledWith();
|
||||
|
||||
battle.advanceToNextShip();
|
||||
expect(ship1.startTurn).toHaveBeenCalledWith(false);
|
||||
expect(ship1.startTurn).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it("detects victory condition and logs a final EndBattleEvent", function () {
|
||||
|
|
|
@ -191,7 +191,7 @@ module SpaceTac.Game {
|
|||
}
|
||||
|
||||
if (this.playing_ship) {
|
||||
this.playing_ship.startTurn(this.first_turn);
|
||||
this.playing_ship.startTurn();
|
||||
|
||||
if (!this.playing_ship.isAbleToPlay()) {
|
||||
// If the ship is not able to play, wait a little, then advance to the next one
|
||||
|
@ -217,8 +217,7 @@ module SpaceTac.Game {
|
|||
this.placeShips();
|
||||
this.throwInitiative();
|
||||
this.play_order.forEach((ship: Ship) => {
|
||||
ship.updateAttributes();
|
||||
ship.restoreHealth();
|
||||
ship.startBattle();
|
||||
});
|
||||
this.advanceToNextShip();
|
||||
}
|
||||
|
|
|
@ -235,5 +235,22 @@ module SpaceTac.Game.Specs {
|
|||
expect(picked).not.toBeNull();
|
||||
expect(picked).toBe(ship.slots[2].attached);
|
||||
});
|
||||
|
||||
it("recover action points at end of turn", function () {
|
||||
var ship = new Ship();
|
||||
|
||||
var power_core_template = new Equipments.BasicPowerCore();
|
||||
ship.addSlot(SlotType.Power).attach(power_core_template.generateFixed(0));
|
||||
|
||||
expect(ship.ap_current.current).toBe(0);
|
||||
ship.initializeActionPoints();
|
||||
expect(ship.ap_current.current).toBe(5);
|
||||
ship.ap_current.set(2);
|
||||
expect(ship.ap_current.current).toBe(2);
|
||||
ship.endTurn();
|
||||
expect(ship.ap_current.current).toBe(6);
|
||||
ship.endTurn();
|
||||
expect(ship.ap_current.current).toBe(8);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ module SpaceTac.Game {
|
|||
}
|
||||
|
||||
// Recover action points
|
||||
// This should be called once at the start of a turn
|
||||
// This should be called once at the end of a turn
|
||||
// If no value is provided, the current attribute ap_recovery will be used
|
||||
recoverActionPoints(value: number = null): void {
|
||||
if (value === null) {
|
||||
|
@ -213,18 +213,18 @@ module SpaceTac.Game {
|
|||
this.setAttribute(this.ap_current, -value, true);
|
||||
}
|
||||
|
||||
// Method called at the start of battle
|
||||
startBattle() {
|
||||
this.updateAttributes();
|
||||
this.restoreHealth();
|
||||
this.initializeActionPoints();
|
||||
}
|
||||
|
||||
// Method called at the start of this ship turn
|
||||
startTurn(first: boolean = false): void {
|
||||
startTurn(): void {
|
||||
// Recompute attributes
|
||||
this.updateAttributes();
|
||||
|
||||
// Manage action points
|
||||
if (first) {
|
||||
this.initializeActionPoints();
|
||||
} else {
|
||||
this.recoverActionPoints();
|
||||
}
|
||||
|
||||
// Apply sticky effects
|
||||
this.temporary_effects.forEach((effect: TemporaryEffect) => {
|
||||
effect.singleApply(this, false);
|
||||
|
@ -233,6 +233,9 @@ module SpaceTac.Game {
|
|||
|
||||
// Method called at the end of this ship turn
|
||||
endTurn(): void {
|
||||
// Recover action points for next turn
|
||||
this.recoverActionPoints();
|
||||
|
||||
// Decrement sticky effects duration
|
||||
this.temporary_effects = this.temporary_effects.filter((effect: TemporaryEffect): boolean => {
|
||||
if (effect.duration <= 1) {
|
||||
|
|
|
@ -29,17 +29,11 @@ module SpaceTac.Game.Specs {
|
|||
new AttributeLimitEffect(AttributeCode.AP, 1, 4)
|
||||
]);
|
||||
|
||||
// Attribute vanishes before the end of turn, so AP recovery happens
|
||||
target.endTurn();
|
||||
expect(target.ap_current.current).toBe(4);
|
||||
expect(target.temporary_effects).toEqual([]);
|
||||
|
||||
// Attribute vanishes before the start of next turn, so AP recovery happens
|
||||
target.startTurn();
|
||||
|
||||
expect(target.ap_current.current).toBe(6);
|
||||
expect(target.temporary_effects).toEqual([]);
|
||||
|
||||
target.endTurn();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue