2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2015-02-13 00:00:00 +00:00
|
|
|
// Result of an ended battle
|
2017-02-07 18:54:53 +00:00
|
|
|
export class BattleOutcome {
|
2015-02-13 00:00:00 +00:00
|
|
|
// Indicates if the battle is a draw (no winner)
|
|
|
|
draw: boolean;
|
|
|
|
|
|
|
|
// Victorious fleet
|
2017-03-09 17:11:00 +00:00
|
|
|
winner: Fleet | null;
|
2015-02-13 00:00:00 +00:00
|
|
|
|
|
|
|
// Retrievable loot
|
|
|
|
loot: Equipment[];
|
|
|
|
|
2017-03-09 17:11:00 +00:00
|
|
|
constructor(winner: Fleet | null) {
|
2015-02-13 00:00:00 +00:00
|
|
|
this.winner = winner;
|
|
|
|
this.draw = winner ? false : true;
|
|
|
|
this.loot = [];
|
|
|
|
}
|
|
|
|
|
2017-03-14 17:48:04 +00:00
|
|
|
/**
|
|
|
|
* Fill loot from defeated fleet
|
|
|
|
*/
|
|
|
|
createLoot(battle: Battle, random = RandomGenerator.global): void {
|
2015-02-13 00:00:00 +00:00
|
|
|
this.loot = [];
|
|
|
|
|
2017-03-14 17:48:04 +00:00
|
|
|
battle.fleets.forEach(fleet => {
|
|
|
|
if (this.winner && this.winner.player != fleet.player) {
|
|
|
|
fleet.ships.forEach(ship => {
|
|
|
|
var luck = random.random();
|
|
|
|
if (luck > 0.9) {
|
|
|
|
// Salvage a supposedly transported item
|
2017-03-17 00:07:00 +00:00
|
|
|
var transported = this.generateLootItem(random, ship.level.get());
|
2017-03-14 17:48:04 +00:00
|
|
|
if (transported) {
|
|
|
|
this.loot.push(transported);
|
|
|
|
}
|
|
|
|
} else if (luck > 0.5) {
|
|
|
|
// Salvage one equipped item
|
|
|
|
var token = ship.getRandomEquipment(random);
|
|
|
|
if (token) {
|
|
|
|
token.detach();
|
|
|
|
this.loot.push(token);
|
2015-02-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-14 17:48:04 +00:00
|
|
|
});
|
|
|
|
}
|
2015-02-13 00:00:00 +00:00
|
|
|
});
|
|
|
|
}
|
2015-02-13 00:00:00 +00:00
|
|
|
|
|
|
|
// Create a loot generator for lucky loots
|
|
|
|
getLootGenerator(random: RandomGenerator): LootGenerator {
|
|
|
|
return new LootGenerator(random);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a special loot item for the winner fleet
|
2015-03-12 00:00:00 +00:00
|
|
|
// The equipment will be in the dead ship range
|
2017-03-09 17:11:00 +00:00
|
|
|
generateLootItem(random: RandomGenerator, base_level: number): Equipment | null {
|
2015-02-13 00:00:00 +00:00
|
|
|
var generator = this.getLootGenerator(random);
|
2017-04-18 19:51:23 +00:00
|
|
|
var level = random.randInt(Math.max(base_level - 1, 1), base_level + 1);
|
2015-02-13 00:00:00 +00:00
|
|
|
return generator.generate(level);
|
|
|
|
}
|
2015-02-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|