1
0
Fork 0

Moved level from fleet to ships

Now, generated 'lucky' loots are from the dead ship level, not the winner one (more logical that way)
This commit is contained in:
Michaël Lemaire 2015-03-12 01:00:00 +01:00
parent 488b059913
commit fcf696f7c1
5 changed files with 47 additions and 10 deletions

View file

@ -42,7 +42,7 @@ module SpaceTac.Game {
var luck = random.throw();
if (luck > 0.9) {
// Salvage a supposedly transported item
var transported = this.generateLootItem(random);
var transported = this.generateLootItem(random, ship.level);
if (transported) {
this.loot.push(transported);
}
@ -66,10 +66,10 @@ module SpaceTac.Game {
}
// 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 {
// The equipment will be in the dead ship range
generateLootItem(random: RandomGenerator, base_level: number): Equipment {
var generator = this.getLootGenerator(random);
var level = new IntegerRange(this.winner.level - 1, this.winner.level + 1);
var level = new IntegerRange(base_level - 1, base_level + 1);
return generator.generate(level);
}
}

View file

@ -14,14 +14,10 @@ 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) {
super();
this.level = 1;
this.player = player || new Player();
this.ships = [];
this.battle = null;
@ -40,6 +36,20 @@ module SpaceTac.Game {
this.battle = battle;
}
// Get the average level of this fleet
getLevel(): number {
if (this.ships.length === 0) {
return 0;
}
var sum = 0;
this.ships.forEach((ship: Ship) => {
sum += ship.level;
});
var avg = sum / this.ships.length;
return Math.round(avg);
}
// Check if the fleet still has living ships
isAlive(): boolean {
var count = 0;

View file

@ -8,6 +8,9 @@ module SpaceTac.Game {
// Fleet this ship is a member of
fleet: Fleet;
// Level of this ship
level: number;
// Name of the ship
name: string;
@ -62,6 +65,7 @@ module SpaceTac.Game {
this.attributes = new AttributeCollection();
this.fleet = fleet || new Fleet();
this.level = 1;
this.name = name;
this.alive = true;
this.initiative = this.newAttribute(AttributeCode.Initiative);

View file

@ -6,7 +6,6 @@ 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));
@ -16,6 +15,9 @@ module SpaceTac.Game.Specs {
fleet2.addShip(new Ship(fleet2));
fleet2.addShip(new Ship(fleet2));
fleet2.ships[2].level = 5;
fleet2.ships[3].level = 5;
fleet1.ships[0].setDead();
fleet1.ships[0].addSlot(SlotType.Armor).attach(new Equipment(SlotType.Armor));
fleet1.ships[1].setDead();
@ -44,7 +46,7 @@ module SpaceTac.Game.Specs {
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, // - lower end of level range (dead ship 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

View file

@ -0,0 +1,21 @@
/// <reference path="../../definitions/jasmine.d.ts"/>
module SpaceTac.Game {
"use strict";
describe("Fleet", function () {
it("get average level", function () {
var fleet = new Fleet();
expect(fleet.getLevel()).toEqual(0);
fleet.addShip(new Ship());
fleet.addShip(new Ship());
fleet.addShip(new Ship());
fleet.ships[0].level = 2;
fleet.ships[1].level = 4;
fleet.ships[2].level = 7;
expect(fleet.getLevel()).toEqual(4);
});
});
}