2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.Specs {
|
2015-02-13 00:00:00 +00:00
|
|
|
describe("BattleOutcome", () => {
|
|
|
|
it("generates loot from dead ships, for the winner to take", () => {
|
|
|
|
var fleet1 = new Fleet();
|
|
|
|
fleet1.addShip(new Ship(fleet1));
|
|
|
|
fleet1.addShip(new Ship(fleet1));
|
|
|
|
fleet1.addShip(new Ship(fleet1));
|
|
|
|
var fleet2 = new Fleet();
|
|
|
|
fleet2.addShip(new Ship(fleet2));
|
|
|
|
fleet2.addShip(new Ship(fleet2));
|
|
|
|
fleet2.addShip(new Ship(fleet2));
|
2015-02-13 00:00:00 +00:00
|
|
|
fleet2.addShip(new Ship(fleet2));
|
2015-02-13 00:00:00 +00:00
|
|
|
|
2015-03-12 00:00:00 +00:00
|
|
|
fleet2.ships[2].level = 5;
|
|
|
|
fleet2.ships[3].level = 5;
|
|
|
|
|
2015-02-13 00:00:00 +00:00
|
|
|
fleet1.ships[0].setDead();
|
2017-03-05 14:12:08 +00:00
|
|
|
fleet1.ships[0].addSlot(SlotType.Hull).attach(new Equipment(SlotType.Hull));
|
2015-02-13 00:00:00 +00:00
|
|
|
fleet1.ships[1].setDead();
|
|
|
|
fleet1.ships[1].addSlot(SlotType.Engine).attach(new Equipment(SlotType.Engine, "1.1.1"));
|
|
|
|
fleet1.ships[1].addSlot(SlotType.Engine).attach(new Equipment(SlotType.Engine, "1.1.2"));
|
|
|
|
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();
|
2015-02-13 00:00:00 +00:00
|
|
|
fleet2.ships[0].addSlot(SlotType.Weapon).attach(new Equipment(SlotType.Weapon, "2.0.1"));
|
2015-02-13 00:00:00 +00:00
|
|
|
fleet2.ships[1].setDead();
|
2015-02-13 00:00:00 +00:00
|
|
|
fleet2.ships[1].addSlot(SlotType.Weapon).attach(new Equipment(SlotType.Weapon, "2.1.1"));
|
2015-02-13 00:00:00 +00:00
|
|
|
fleet2.ships[2].setDead();
|
2015-02-13 00:00:00 +00:00
|
|
|
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"));
|
2015-02-13 00:00:00 +00:00
|
|
|
|
|
|
|
var battle = new Battle(fleet1, fleet2);
|
|
|
|
var outcome = new BattleOutcome(fleet1);
|
|
|
|
|
2017-02-26 17:44:15 +00:00
|
|
|
var random = new SkewedRandomGenerator([
|
2015-02-13 00:00:00 +00:00
|
|
|
0, // leave first ship alone
|
|
|
|
0.45, // take 2 equipments from the 4 of second ship
|
2017-02-26 17:44:15 +00:00
|
|
|
0.999, // - take last equipment
|
2015-02-13 00:00:00 +00:00
|
|
|
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
|
2015-03-12 00:00:00 +00:00
|
|
|
0, // - lower end of level range (dead ship has 5, so range is 4-6)
|
2015-02-13 00:00:00 +00:00
|
|
|
0, // - take first generated equipment (there is only one anyway)
|
|
|
|
0.96, // lucky loot on fourth ship
|
2017-02-26 17:44:15 +00:00
|
|
|
0.999 // - higher end of level range
|
|
|
|
]);
|
2015-02-13 00:00:00 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2015-02-13 00:00:00 +00:00
|
|
|
outcome.createLoot(battle, random);
|
|
|
|
|
2015-02-13 00:00:00 +00:00
|
|
|
expect(outcome.loot.length).toBe(5);
|
2015-02-13 00:00:00 +00:00
|
|
|
expect(outcome.loot[0].name).toBe("1.1.4");
|
|
|
|
expect(outcome.loot[1].name).toBe("1.1.1");
|
2015-02-13 00:00:00 +00:00
|
|
|
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);
|
2015-02-13 00:00:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|