1
0
Fork 0

Added the first weapon (Gatling Gun), using LootGenerator, LootTemplate and the slots system

This commit is contained in:
Michaël Lemaire 2015-01-14 01:00:00 +01:00 committed by Michaël Lemaire
parent 2a12a671a2
commit 0f45244a8e
7 changed files with 104 additions and 10 deletions

View file

@ -11,16 +11,24 @@ module SpaceTac.Game {
// Construct a basic loot generator
// The list of templates will be automatically populated
constructor() {
constructor(random: RandomGenerator = null) {
this.templates = [];
this.random = new RandomGenerator();
this.random = random || new RandomGenerator();
this.populate();
}
// Fill the list of templates
populate(): void {
var templates: LootTemplate[] = [];
for (var template_name in SpaceTac.Game.Equipments) {
if (template_name) {
var template_class = SpaceTac.Game.Equipments[template_name];
var template: LootTemplate = new template_class();
templates.push(template);
}
}
this.templates = templates;
}
// Generate a random equipment

View file

@ -93,7 +93,6 @@ module SpaceTac.Game {
random = random || new RandomGenerator();
var random_range = this.getPowerRangeForLevel(level);
console.log(level, random_range);
if (random_range) {
var power = random.throw() * (random_range.max - random_range.min) + random_range.min;
return this.generateFixed(power);

View file

@ -14,11 +14,24 @@ module SpaceTac.Game {
// Create a quick random player, with a fleet, for testing purposes
static newQuickRandom(name: String): Player {
var player = new Player();
var ship: Ship;
var ship_generator = new ShipGenerator();
new Ship(player.fleet, name + "'s First");
new Ship(player.fleet, name + "'s Second");
new Ship(player.fleet, name + "'s Third");
new Ship(player.fleet, name + "'s Fourth");
ship = ship_generator.generate(1);
ship.name = name + "'s First";
player.fleet.addShip(ship);
ship = ship_generator.generate(1);
ship.name = name + "'s Second";
player.fleet.addShip(ship);
ship = ship_generator.generate(1);
ship.name = name + "'s Third";
player.fleet.addShip(ship);
ship = ship_generator.generate(1);
ship.name = name + "'s Fourth";
player.fleet.addShip(ship);
return player;
}

View file

@ -47,7 +47,7 @@ module SpaceTac.Game {
slots: Slot[];
// Create a new ship inside a fleet
constructor(fleet: Fleet, name: string) {
constructor(fleet: Fleet = null, name: string = null) {
this.fleet = fleet;
this.name = name;
this.initiative_level = 1;
@ -131,5 +131,12 @@ module SpaceTac.Game {
this.setArenaPosition(this.arena_x + dx, this.arena_y + dy);
this.useActionPoints(cost);
}
// Add an empty equipment slot of the given type
addSlot(type: SlotType): Slot {
var result = new Slot(this, type);
this.slots.push(result);
return result;
}
}
}

View file

@ -0,0 +1,39 @@
module SpaceTac.Game {
"use strict";
// Generator of random ship
export class ShipGenerator {
// Random number generator used
random: RandomGenerator;
// Create a default ship generator
constructor(random: RandomGenerator = null) {
this.random = random || new RandomGenerator();
}
// Generate a ship of a given level
// The ship will not be named, nor will be a member of any fleet
generate(level: number): Ship {
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);
result.addSlot(SlotType.Power);
result.addSlot(SlotType.Shield);
result.addSlot(SlotType.Weapon);
// Fill equipment slots
result.slots.forEach((slot: Slot) => {
var equipment = loot.generate(new IntegerRange(level, level), slot.type);
slot.attach(equipment);
});
return result;
}
}
}

View file

@ -11,8 +11,20 @@ module SpaceTac.Game {
// Type of slot
type: SlotType;
// Currently attached equipment
// Currently attached equipment, null if none
attached: Equipment;
// Create an empty slot for a ship
constructor(ship: Ship, type: SlotType) {
this.ship = ship;
this.type = type;
this.attached = null;
}
// Attach an equipment in this slot
attach(equipment: Equipment): void {
this.attached = equipment;
}
}
}

View file

@ -0,0 +1,16 @@
/// <reference path="../LootTemplate.ts"/>
module SpaceTac.Game.Equipments {
"use strict";
// Equipment: Gatling Gun
export class GatlingGun extends LootTemplate {
constructor() {
super(SlotType.Weapon, "Gatling Gun");
this.distance = new Range(20, 30);
this.ap_usage = new Range(3, 4);
this.min_level = new IntegerRange(1, 3);
}
}
}