Added the first weapon (Gatling Gun), using LootGenerator, LootTemplate and the slots system
This commit is contained in:
parent
2a12a671a2
commit
0f45244a8e
|
@ -11,16 +11,24 @@ module SpaceTac.Game {
|
||||||
|
|
||||||
// Construct a basic loot generator
|
// Construct a basic loot generator
|
||||||
// The list of templates will be automatically populated
|
// The list of templates will be automatically populated
|
||||||
constructor() {
|
constructor(random: RandomGenerator = null) {
|
||||||
this.templates = [];
|
this.templates = [];
|
||||||
this.random = new RandomGenerator();
|
this.random = random || new RandomGenerator();
|
||||||
|
|
||||||
this.populate();
|
this.populate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill the list of templates
|
// Fill the list of templates
|
||||||
populate(): void {
|
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
|
// Generate a random equipment
|
||||||
|
|
|
@ -93,7 +93,6 @@ module SpaceTac.Game {
|
||||||
random = random || new RandomGenerator();
|
random = random || new RandomGenerator();
|
||||||
|
|
||||||
var random_range = this.getPowerRangeForLevel(level);
|
var random_range = this.getPowerRangeForLevel(level);
|
||||||
console.log(level, random_range);
|
|
||||||
if (random_range) {
|
if (random_range) {
|
||||||
var power = random.throw() * (random_range.max - random_range.min) + random_range.min;
|
var power = random.throw() * (random_range.max - random_range.min) + random_range.min;
|
||||||
return this.generateFixed(power);
|
return this.generateFixed(power);
|
||||||
|
|
|
@ -14,11 +14,24 @@ module SpaceTac.Game {
|
||||||
// Create a quick random player, with a fleet, for testing purposes
|
// Create a quick random player, with a fleet, for testing purposes
|
||||||
static newQuickRandom(name: String): Player {
|
static newQuickRandom(name: String): Player {
|
||||||
var player = new Player();
|
var player = new Player();
|
||||||
|
var ship: Ship;
|
||||||
|
var ship_generator = new ShipGenerator();
|
||||||
|
|
||||||
new Ship(player.fleet, name + "'s First");
|
ship = ship_generator.generate(1);
|
||||||
new Ship(player.fleet, name + "'s Second");
|
ship.name = name + "'s First";
|
||||||
new Ship(player.fleet, name + "'s Third");
|
player.fleet.addShip(ship);
|
||||||
new Ship(player.fleet, name + "'s Fourth");
|
|
||||||
|
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;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ module SpaceTac.Game {
|
||||||
slots: Slot[];
|
slots: Slot[];
|
||||||
|
|
||||||
// Create a new ship inside a fleet
|
// Create a new ship inside a fleet
|
||||||
constructor(fleet: Fleet, name: string) {
|
constructor(fleet: Fleet = null, name: string = null) {
|
||||||
this.fleet = fleet;
|
this.fleet = fleet;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.initiative_level = 1;
|
this.initiative_level = 1;
|
||||||
|
@ -131,5 +131,12 @@ module SpaceTac.Game {
|
||||||
this.setArenaPosition(this.arena_x + dx, this.arena_y + dy);
|
this.setArenaPosition(this.arena_x + dx, this.arena_y + dy);
|
||||||
this.useActionPoints(cost);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
39
src/scripts/game/ShipGenerator.ts
Normal file
39
src/scripts/game/ShipGenerator.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,8 +11,20 @@ module SpaceTac.Game {
|
||||||
// Type of slot
|
// Type of slot
|
||||||
type: SlotType;
|
type: SlotType;
|
||||||
|
|
||||||
// Currently attached equipment
|
// Currently attached equipment, null if none
|
||||||
attached: Equipment;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
16
src/scripts/game/equipments/GatlingGun.ts
Normal file
16
src/scripts/game/equipments/GatlingGun.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue