Added looting of enemy ships after battle
This commit is contained in:
parent
8354f03cfb
commit
2239d1e06d
|
@ -37,14 +37,36 @@ module SpaceTac.Game {
|
|||
} else {
|
||||
var luck = random.throw();
|
||||
if (luck > 0.9) {
|
||||
// TODO Salvage a supposedly transported item
|
||||
// Salvage a supposedly transported item
|
||||
var transported = this.generateLootItem(random);
|
||||
if (transported) {
|
||||
this.loot.push(transported);
|
||||
}
|
||||
} else if (luck > 0.5) {
|
||||
// TODO Salvage an equipped item
|
||||
// Salvage one equipped item
|
||||
var token = ship.getRandomEquipment(random);
|
||||
if (token) {
|
||||
token.detach();
|
||||
this.loot.push(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Create a loot generator for lucky loots
|
||||
getLootGenerator(random: RandomGenerator): LootGenerator {
|
||||
return new LootGenerator(random);
|
||||
}
|
||||
|
||||
// Generate a special loot item for the winner fleet
|
||||
// The equipment will be in the winner range (because its a lucky loot!)
|
||||
generateLootItem(random: RandomGenerator): Equipment {
|
||||
var generator = this.getLootGenerator(random);
|
||||
var level = new IntegerRange(this.winner.level - 1, this.winner.level + 1);
|
||||
return generator.generate(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,12 @@ module SpaceTac.Game {
|
|||
// Current battle in which the fleet is engaged (null if not fighting)
|
||||
battle: Battle;
|
||||
|
||||
// Current level of the fleet
|
||||
level: number;
|
||||
|
||||
// Create a fleet, bound to a player
|
||||
constructor(player: Player = null) {
|
||||
this.level = 1;
|
||||
this.player = player || new Player();
|
||||
this.ships = [];
|
||||
this.battle = null;
|
||||
|
|
|
@ -11,11 +11,13 @@ module SpaceTac.Game {
|
|||
|
||||
// Construct a basic loot generator
|
||||
// The list of templates will be automatically populated
|
||||
constructor(random: RandomGenerator = null) {
|
||||
constructor(random: RandomGenerator = new RandomGenerator(), populate: boolean = true) {
|
||||
this.templates = [];
|
||||
this.random = random || new RandomGenerator();
|
||||
this.random = random;
|
||||
|
||||
this.populate();
|
||||
if (populate) {
|
||||
this.populate();
|
||||
}
|
||||
}
|
||||
|
||||
// Fill the list of templates
|
||||
|
|
|
@ -115,9 +115,7 @@ module SpaceTac.Game {
|
|||
|
||||
// Generate an equipment that will have its level requirement in the given range
|
||||
// May return null if level range is not compatible with the template
|
||||
generateInLevelRange(level: IntegerRange, random: RandomGenerator = null): Equipment {
|
||||
random = random || new RandomGenerator();
|
||||
|
||||
generateInLevelRange(level: IntegerRange, random: RandomGenerator = new RandomGenerator()): Equipment {
|
||||
var random_range = this.getPowerRangeForLevel(level);
|
||||
if (random_range) {
|
||||
var power = random.throw() * (random_range.max - random_range.min) + random_range.min;
|
||||
|
|
|
@ -11,6 +11,11 @@ module SpaceTac.Game {
|
|||
|
||||
// Create a range of values
|
||||
constructor(min: number, max: number = null) {
|
||||
this.set(min, max);
|
||||
}
|
||||
|
||||
// Change the range
|
||||
set(min: number, max: number = null) {
|
||||
this.min = min;
|
||||
if (max === null) {
|
||||
this.max = this.min;
|
||||
|
|
|
@ -9,9 +9,6 @@ module SpaceTac.Game {
|
|||
// Name of the ship
|
||||
name: string;
|
||||
|
||||
// Current level
|
||||
level: number;
|
||||
|
||||
// Flag indicating if the ship is alive
|
||||
alive: boolean;
|
||||
|
||||
|
|
|
@ -17,9 +17,6 @@ module SpaceTac.Game {
|
|||
var result = new Ship();
|
||||
var loot = new LootGenerator(this.random);
|
||||
|
||||
// Set basic info
|
||||
result.level = level;
|
||||
|
||||
// Add equipment slots
|
||||
result.addSlot(SlotType.Armor);
|
||||
result.addSlot(SlotType.Engine);
|
||||
|
|
|
@ -5,7 +5,7 @@ module SpaceTac.Game.Equipments {
|
|||
|
||||
export class BasicForceField extends LootTemplate {
|
||||
constructor() {
|
||||
super(SlotType.Shield, "BasicForceField");
|
||||
super(SlotType.Shield, "Basic Force Field");
|
||||
|
||||
this.min_level = new IntegerRange(1, 3);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ module SpaceTac.Game.Specs {
|
|||
describe("BattleOutcome", () => {
|
||||
it("generates loot from dead ships, for the winner to take", () => {
|
||||
var fleet1 = new Fleet();
|
||||
fleet1.level = 5;
|
||||
fleet1.addShip(new Ship(fleet1));
|
||||
fleet1.addShip(new Ship(fleet1));
|
||||
fleet1.addShip(new Ship(fleet1));
|
||||
|
@ -13,6 +14,7 @@ module SpaceTac.Game.Specs {
|
|||
fleet2.addShip(new Ship(fleet2));
|
||||
fleet2.addShip(new Ship(fleet2));
|
||||
fleet2.addShip(new Ship(fleet2));
|
||||
fleet2.addShip(new Ship(fleet2));
|
||||
|
||||
fleet1.ships[0].setDead();
|
||||
fleet1.ships[0].addSlot(SlotType.Armor).attach(new Equipment(SlotType.Armor));
|
||||
|
@ -22,8 +24,13 @@ module SpaceTac.Game.Specs {
|
|||
fleet1.ships[1].addSlot(SlotType.Engine).attach(new Equipment(SlotType.Engine, "1.1.3"));
|
||||
fleet1.ships[1].addSlot(SlotType.Engine).attach(new Equipment(SlotType.Engine, "1.1.4"));
|
||||
fleet2.ships[0].setDead();
|
||||
fleet2.ships[0].addSlot(SlotType.Weapon).attach(new Equipment(SlotType.Weapon, "2.0.1"));
|
||||
fleet2.ships[1].setDead();
|
||||
fleet2.ships[1].addSlot(SlotType.Weapon).attach(new Equipment(SlotType.Weapon, "2.1.1"));
|
||||
fleet2.ships[2].setDead();
|
||||
fleet2.ships[2].addSlot(SlotType.Weapon).attach(new Equipment(SlotType.Weapon, "2.2.1"));
|
||||
fleet2.ships[3].setDead();
|
||||
fleet2.ships[3].addSlot(SlotType.Weapon).attach(new Equipment(SlotType.Weapon, "2.3.1"));
|
||||
|
||||
var battle = new Battle(fleet1, fleet2);
|
||||
var outcome = new BattleOutcome(fleet1);
|
||||
|
@ -32,13 +39,37 @@ module SpaceTac.Game.Specs {
|
|||
0, // leave first ship alone
|
||||
0.45, // take 2 equipments from the 4 of second ship
|
||||
1, // - take last equipment
|
||||
0 // - take first equipment
|
||||
0, // - take first equipment
|
||||
0.6, // standard loot on first ship of second fleet
|
||||
0, // - take first equipment
|
||||
0.4, // no loot on second ship
|
||||
0.95, // lucky loot on third ship
|
||||
0, // - lower end of level range (winner has 5, so range is 4-6)
|
||||
0, // - take first generated equipment (there is only one anyway)
|
||||
0.96, // lucky loot on fourth ship
|
||||
1 // - higher end of level range
|
||||
);
|
||||
|
||||
// Force lucky finds with one template
|
||||
var looter = new LootGenerator(random, false);
|
||||
var template = new LootTemplate(SlotType.Power, "Nuclear Reactor");
|
||||
template.min_level.set(3, 7);
|
||||
template.distance.set(0, 5);
|
||||
looter.templates = [template];
|
||||
spyOn(outcome, "getLootGenerator").and.returnValue(looter);
|
||||
|
||||
outcome.createLoot(battle, random);
|
||||
|
||||
expect(outcome.loot.length).toBe(2);
|
||||
expect(outcome.loot.length).toBe(5);
|
||||
expect(outcome.loot[0].name).toBe("1.1.4");
|
||||
expect(outcome.loot[1].name).toBe("1.1.1");
|
||||
expect(outcome.loot[2].name).toBe("2.0.1");
|
||||
expect(outcome.loot[3].name).toBe("Nuclear Reactor");
|
||||
expect(outcome.loot[3].min_level).toBe(4);
|
||||
expect(outcome.loot[3].distance).toEqual(1);
|
||||
expect(outcome.loot[4].name).toBe("Nuclear Reactor");
|
||||
expect(outcome.loot[4].min_level).toBe(6);
|
||||
expect(outcome.loot[4].distance).toBeCloseTo(4, 0.000001);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue