Added retreat after defeat
This commit is contained in:
parent
ca7be2e416
commit
b916230002
1
TODO
1
TODO
|
@ -4,7 +4,6 @@
|
|||
* Character sheet: add levelling up (spending of available points)
|
||||
* Character sheet: disable interaction during battle (except for loot screen)
|
||||
* Add battle statistics and/or critics in outcome dialog
|
||||
* Add battle reverting in defeat outcome dialog
|
||||
* Ensure that tweens and particle emitters get destroyed once animation is done (or view changes)
|
||||
* Highlight ships that will be included as target of current action
|
||||
* Controls: Do not focus on ship while targetting for area effects (dissociate hover and target)
|
||||
|
|
|
@ -129,12 +129,9 @@ module TS.SpaceTac {
|
|||
}
|
||||
|
||||
// Ends a battle and sets the outcome
|
||||
endBattle(winner: Fleet | null, log = true, loot = true) {
|
||||
endBattle(winner: Fleet | null, log = true) {
|
||||
this.ended = true;
|
||||
this.outcome = new BattleOutcome(winner);
|
||||
if (loot && winner) {
|
||||
this.outcome.createLoot(this);
|
||||
}
|
||||
if (log && this.log) {
|
||||
this.log.add(new EndBattleEvent(this.outcome));
|
||||
}
|
||||
|
|
|
@ -10,10 +10,11 @@ module TS.SpaceTac {
|
|||
ships: Ship[];
|
||||
|
||||
// Current fleet location
|
||||
location: StarLocation | null;
|
||||
location: StarLocation | null = null;
|
||||
previous_location: StarLocation | null = null;
|
||||
|
||||
// Current battle in which the fleet is engaged (null if not fighting)
|
||||
battle: Battle | null;
|
||||
battle: Battle | null = null;
|
||||
|
||||
// Amount of credits available
|
||||
credits = 0;
|
||||
|
@ -22,8 +23,6 @@ module TS.SpaceTac {
|
|||
constructor(player = new Player()) {
|
||||
this.player = player;
|
||||
this.ships = [];
|
||||
this.location = null;
|
||||
this.battle = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,6 +35,7 @@ module TS.SpaceTac {
|
|||
return false;
|
||||
}
|
||||
|
||||
this.previous_location = this.location;
|
||||
this.location = location;
|
||||
this.player.setVisited(this.location);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ module TS.SpaceTac.Specs {
|
|||
var battle = nn(session.getBattle());
|
||||
battle.advanceToNextShip();
|
||||
// TODO Make some fixed moves (AI?)
|
||||
battle.endBattle(battle.fleets[0], true, false);
|
||||
battle.endBattle(battle.fleets[0]);
|
||||
}
|
||||
|
||||
it("serializes to a string", () => {
|
||||
|
|
|
@ -36,5 +36,38 @@ module TS.SpaceTac {
|
|||
|
||||
checkVisited(true, true, true, true, true, false);
|
||||
});
|
||||
|
||||
it("reverts battle", function () {
|
||||
let player = new Player();
|
||||
let star = new Star();
|
||||
let loc1 = new StarLocation(star);
|
||||
loc1.encounter_gen = true;
|
||||
loc1.encounter = null;
|
||||
let loc2 = new StarLocation(star);
|
||||
loc2.encounter_gen = false;
|
||||
loc2.encounter = null;
|
||||
loc2.encounter_random = new SkewedRandomGenerator([0], true);
|
||||
|
||||
player.fleet.setLocation(loc1);
|
||||
expect(player.getBattle()).toBeNull();
|
||||
expect(player.fleet.location).toBe(loc1);
|
||||
|
||||
player.fleet.setLocation(loc2);
|
||||
expect(player.getBattle()).not.toBeNull();
|
||||
expect(player.fleet.location).toBe(loc2);
|
||||
expect(player.hasVisitedLocation(loc2)).toBe(true);
|
||||
let enemy = loc2.encounter;
|
||||
|
||||
player.revertBattle();
|
||||
expect(player.getBattle()).toBeNull();
|
||||
expect(player.fleet.location).toBe(loc1);
|
||||
expect(player.hasVisitedLocation(loc2)).toBe(true);
|
||||
|
||||
player.fleet.setLocation(loc2);
|
||||
expect(player.getBattle()).not.toBeNull();
|
||||
expect(player.fleet.location).toBe(loc2);
|
||||
expect(player.hasVisitedLocation(loc2)).toBe(true);
|
||||
expect(nn(player.getBattle()).fleets[1]).toBe(enemy);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -70,10 +70,24 @@ module TS.SpaceTac {
|
|||
this.fleet.setBattle(battle);
|
||||
}
|
||||
|
||||
// Exit the current battle unconditionally, if any
|
||||
// This does not apply retreat penalties, or battle outcome, only unbind the battle from current session
|
||||
/**
|
||||
* Exit the current battle unconditionally, if any
|
||||
*
|
||||
* This does not apply retreat penalties, or battle outcome, only unbind the battle from current session
|
||||
*/
|
||||
exitBattle(): void {
|
||||
this.setBattle(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert current battle, and put the player's fleet to its previous location, as if the battle never happened
|
||||
*/
|
||||
revertBattle(): void {
|
||||
this.exitBattle();
|
||||
|
||||
if (this.fleet.previous_location) {
|
||||
this.fleet.setLocation(this.fleet.previous_location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,6 +292,7 @@ module TS.SpaceTac {
|
|||
|
||||
// Method called at the start of battle
|
||||
startBattle() {
|
||||
this.alive = true;
|
||||
this.updateAttributes();
|
||||
this.restoreHealth();
|
||||
this.initializeActionPoints();
|
||||
|
|
|
@ -3,8 +3,8 @@ module TS.SpaceTac.Specs {
|
|||
it("removes generated encounters that lose", function () {
|
||||
var location = new StarLocation(undefined, StarLocationType.PLANET, 0, 0);
|
||||
var fleet = new Fleet();
|
||||
var random = new SkewedRandomGenerator([0]);
|
||||
var battle = location.enterLocation(fleet, random);
|
||||
location.encounter_random = new SkewedRandomGenerator([0]);
|
||||
var battle = location.enterLocation(fleet);
|
||||
|
||||
expect(location.encounter).not.toBeNull();
|
||||
expect(battle).not.toBeNull();
|
||||
|
@ -17,8 +17,8 @@ module TS.SpaceTac.Specs {
|
|||
it("leaves generated encounters that win", function () {
|
||||
var location = new StarLocation(undefined, StarLocationType.PLANET, 0, 0);
|
||||
var fleet = new Fleet();
|
||||
var random = new SkewedRandomGenerator([0]);
|
||||
var battle = location.enterLocation(fleet, random);
|
||||
location.encounter_random = new SkewedRandomGenerator([0]);
|
||||
var battle = location.enterLocation(fleet);
|
||||
|
||||
expect(location.encounter).not.toBeNull();
|
||||
expect(battle).not.toBeNull();
|
||||
|
|
|
@ -27,8 +27,9 @@ module TS.SpaceTac {
|
|||
jump_dest: StarLocation | null;
|
||||
|
||||
// Enemy encounter
|
||||
encounter: Fleet | null;
|
||||
encounter_gen: boolean;
|
||||
encounter: Fleet | null = null;
|
||||
encounter_gen = false;
|
||||
encounter_random = RandomGenerator.global;
|
||||
|
||||
constructor(star = new Star(), type: StarLocationType = StarLocationType.PLANET, x: number = 0, y: number = 0) {
|
||||
this.star = star;
|
||||
|
@ -38,9 +39,6 @@ module TS.SpaceTac {
|
|||
this.universe_x = this.star.x + this.x;
|
||||
this.universe_y = this.star.y + this.y;
|
||||
this.jump_dest = null;
|
||||
|
||||
this.encounter = null;
|
||||
this.encounter_gen = false;
|
||||
}
|
||||
|
||||
// Set the jump destination of a WARP location
|
||||
|
@ -52,13 +50,13 @@ module TS.SpaceTac {
|
|||
|
||||
// Call this when first probing a location to generate the possible encounter
|
||||
// Returns the encountered fleet, null if no encounter happens
|
||||
tryGenerateEncounter(random = RandomGenerator.global): Fleet | null {
|
||||
tryGenerateEncounter(): Fleet | null {
|
||||
if (!this.encounter_gen) {
|
||||
this.encounter_gen = true;
|
||||
|
||||
if (random.random() < 0.8) {
|
||||
var fleet_generator = new FleetGenerator(random);
|
||||
var ship_count = random.randInt(1, 5);
|
||||
if (this.encounter_random.random() < 0.8) {
|
||||
var fleet_generator = new FleetGenerator(this.encounter_random);
|
||||
var ship_count = this.encounter_random.randInt(1, 5);
|
||||
this.encounter = fleet_generator.generate(this.star.level, undefined, ship_count);
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +67,8 @@ module TS.SpaceTac {
|
|||
// Call this when entering a location to generate the possible encounter
|
||||
// *fleet* is the player fleet, entering the location
|
||||
// Returns the engaged battle, null if no encounter happens
|
||||
enterLocation(fleet: Fleet, random = RandomGenerator.global): Battle | null {
|
||||
var encounter = this.tryGenerateEncounter(random);
|
||||
enterLocation(fleet: Fleet): Battle | null {
|
||||
var encounter = this.tryGenerateEncounter();
|
||||
if (encounter) {
|
||||
var battle = new Battle(fleet, encounter);
|
||||
battle.log.subscribe((event: BaseLogEvent) => {
|
||||
|
|
|
@ -233,6 +233,11 @@ module TS.SpaceTac.UI {
|
|||
if (this.battle.ended) {
|
||||
this.setInteractionEnabled(false);
|
||||
|
||||
if (this.battle.outcome.winner == this.player.fleet) {
|
||||
// In case of victory, generate loot
|
||||
this.battle.outcome.createLoot(this.battle);
|
||||
}
|
||||
|
||||
let dialog = new OutcomeDialog(this, this.player, this.battle.outcome);
|
||||
dialog.position.set(this.getMidWidth() - dialog.width / 2, this.getMidHeight() - dialog.height / 2);
|
||||
this.outcome_layer.addChild(dialog);
|
||||
|
@ -248,5 +253,13 @@ module TS.SpaceTac.UI {
|
|||
this.player.exitBattle();
|
||||
this.game.state.start('router');
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert the battle, and go back to map
|
||||
*/
|
||||
revertBattle() {
|
||||
this.player.revertBattle();
|
||||
this.game.state.start('router');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ module TS.SpaceTac.UI {
|
|||
} else {
|
||||
this.addChild(new Phaser.Button(this.game, 344, 842, "battle-outcome-button-revert", () => {
|
||||
// Revert just before battle
|
||||
// TODO
|
||||
parent.revertBattle();
|
||||
}));
|
||||
this.addChild(new Phaser.Button(this.game, 766, 842, "battle-outcome-button-menu", () => {
|
||||
// Quit the game, and go back to menu
|
||||
|
|
Loading…
Reference in a new issue