Added capabilities to ships, and matching requirements in equipment
This commit is contained in:
parent
2c73a62893
commit
f6a7c0b8d9
|
@ -21,6 +21,24 @@ module SpaceTac.Game {
|
|||
// Starting action points in a battle
|
||||
AP_Initial,
|
||||
|
||||
// Capability level in materials
|
||||
Cap_Material,
|
||||
|
||||
// Capability level in energy
|
||||
Cap_Energy,
|
||||
|
||||
// Capability level in electronics
|
||||
Cap_Electronics,
|
||||
|
||||
// Capability level in human things
|
||||
Cap_Human,
|
||||
|
||||
// Capability level in time manipulation
|
||||
Cap_Time,
|
||||
|
||||
// Capability level in gravity manipulation
|
||||
Cap_Gravity,
|
||||
|
||||
// Miscellaneous attribute
|
||||
Misc
|
||||
}
|
||||
|
@ -39,7 +57,7 @@ module SpaceTac.Game {
|
|||
current: number;
|
||||
|
||||
// Create an attribute
|
||||
constructor(code: AttributeCode = AttributeCode.Misc, maximal: number = null, current: number = 0) {
|
||||
constructor(code: AttributeCode = AttributeCode.Misc, current: number = 0, maximal: number = null) {
|
||||
this.code = code;
|
||||
this.maximal = maximal;
|
||||
this.current = current;
|
||||
|
|
|
@ -24,10 +24,13 @@ module SpaceTac.Game {
|
|||
// Level requirement
|
||||
min_level: number;
|
||||
|
||||
// Minimal attribute to be able to equip this equipment
|
||||
requirements: Attribute[];
|
||||
|
||||
// Action associated with this equipment
|
||||
action: BaseAction;
|
||||
|
||||
// Permanent effects
|
||||
// Permanent effects on the ship that equips the equipment
|
||||
permanent_effects: BaseEffect[];
|
||||
|
||||
// Effects on target
|
||||
|
@ -35,8 +38,21 @@ module SpaceTac.Game {
|
|||
|
||||
// Basic constructor
|
||||
constructor() {
|
||||
this.requirements = [];
|
||||
this.permanent_effects = [];
|
||||
this.target_effects = [];
|
||||
}
|
||||
|
||||
// Returns true if the equipment can be equipped on a ship
|
||||
// This checks *requirements* against the ship capabilities
|
||||
canBeEquipped(ship: Ship): boolean {
|
||||
var able = true;
|
||||
this.requirements.forEach((cap: Attribute) => {
|
||||
if (ship.attributes.getValue(cap.code) < cap.current) {
|
||||
able = false;
|
||||
}
|
||||
});
|
||||
return able;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,8 @@ module SpaceTac.Game {
|
|||
// Base name, lower cased
|
||||
name: string;
|
||||
|
||||
// Ability requirement ranges
|
||||
|
||||
// Targetting flags
|
||||
// Capability requirement ranges (indexed by AttributeCode)
|
||||
requirements: IntegerRange[];
|
||||
|
||||
// Distance to target
|
||||
distance: Range;
|
||||
|
@ -38,6 +37,7 @@ module SpaceTac.Game {
|
|||
constructor(slot: SlotType, name: string) {
|
||||
this.slot = slot;
|
||||
this.name = name;
|
||||
this.requirements = [];
|
||||
this.distance = new Range(0, 0);
|
||||
this.blast = new Range(0, 0);
|
||||
this.duration = new IntegerRange(0, 0);
|
||||
|
@ -47,6 +47,11 @@ module SpaceTac.Game {
|
|||
this.target_effects = [];
|
||||
}
|
||||
|
||||
// Set a capability requirement
|
||||
addRequirement(capability: AttributeCode, min: number, max: number = null): void {
|
||||
this.requirements[capability] = new IntegerRange(min, max);
|
||||
}
|
||||
|
||||
// Generate a random equipment with this template
|
||||
generate(random: RandomGenerator = null): Equipment {
|
||||
random = random || new RandomGenerator();
|
||||
|
@ -69,6 +74,12 @@ module SpaceTac.Game {
|
|||
|
||||
result.action = this.getActionForEquipment(result);
|
||||
|
||||
this.requirements.forEach((requirement: IntegerRange, index: AttributeCode) => {
|
||||
if (requirement) {
|
||||
result.requirements.push(new Attribute(index, requirement.getProportional(power)));
|
||||
}
|
||||
});
|
||||
|
||||
this.permanent_effects.forEach((eff_template: EffectTemplate) => {
|
||||
result.permanent_effects.push(eff_template.generateFixed(power));
|
||||
});
|
||||
|
|
|
@ -40,6 +40,14 @@ module SpaceTac.Game {
|
|||
// Number of shield points (a shield can absorb some damage to protect the hull)
|
||||
shield: Attribute;
|
||||
|
||||
// Capabilities level
|
||||
cap_material: Attribute;
|
||||
cap_energy: Attribute;
|
||||
cap_electronics: Attribute;
|
||||
cap_human: Attribute;
|
||||
cap_time: Attribute;
|
||||
cap_gravity: Attribute;
|
||||
|
||||
// List of slots, able to contain equipment
|
||||
slots: Slot[];
|
||||
|
||||
|
@ -59,6 +67,12 @@ module SpaceTac.Game {
|
|||
this.ap_recover = this.newAttribute(AttributeCode.AP_Recovery);
|
||||
this.hull = this.newAttribute(AttributeCode.Hull);
|
||||
this.shield = this.newAttribute(AttributeCode.Shield);
|
||||
this.cap_material = this.newAttribute(AttributeCode.Cap_Material);
|
||||
this.cap_energy = this.newAttribute(AttributeCode.Cap_Energy);
|
||||
this.cap_electronics = this.newAttribute(AttributeCode.Cap_Electronics);
|
||||
this.cap_human = this.newAttribute(AttributeCode.Cap_Human);
|
||||
this.cap_time = this.newAttribute(AttributeCode.Cap_Time);
|
||||
this.cap_gravity = this.newAttribute(AttributeCode.Cap_Gravity);
|
||||
this.slots = [];
|
||||
|
||||
this.arena_x = 0;
|
||||
|
@ -223,7 +237,7 @@ module SpaceTac.Game {
|
|||
this.addBattleEvent(new DamageEvent(this, hull, shield));
|
||||
}
|
||||
|
||||
if (this.hull.current == 0) {
|
||||
if (this.hull.current === 0) {
|
||||
// Ship is dead
|
||||
this.alive = false;
|
||||
if (log) {
|
||||
|
|
|
@ -30,10 +30,12 @@ module SpaceTac.Game {
|
|||
|
||||
// Attach an equipment in this slot
|
||||
attach(equipment: Equipment): void {
|
||||
this.attached = equipment;
|
||||
if (this.type === equipment.slot && equipment.canBeEquipped(this.ship)) {
|
||||
this.attached = equipment;
|
||||
|
||||
if (this.ship) {
|
||||
this.ship.updateAttributes();
|
||||
if (this.ship) {
|
||||
this.ship.updateAttributes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,18 @@ module SpaceTac.Game {
|
|||
AttributeCode.AP,
|
||||
AttributeCode.AP_Recovery,
|
||||
AttributeCode.AP_Initial,
|
||||
AttributeCode.Cap_Material,
|
||||
AttributeCode.Cap_Energy,
|
||||
AttributeCode.Cap_Electronics,
|
||||
AttributeCode.Cap_Human,
|
||||
AttributeCode.Cap_Time,
|
||||
AttributeCode.Cap_Gravity,
|
||||
AttributeCode.Misc
|
||||
]);
|
||||
});
|
||||
|
||||
it("applies minimal and maximal value", function () {
|
||||
var attr = new Attribute(AttributeCode.Misc, 100, 50);
|
||||
var attr = new Attribute(AttributeCode.Misc, 50, 100);
|
||||
expect(attr.current).toBe(50);
|
||||
|
||||
attr.add(8);
|
||||
|
@ -61,7 +67,7 @@ module SpaceTac.Game {
|
|||
|
||||
it("tells if value changed", function () {
|
||||
var result: boolean;
|
||||
var attr = new Attribute(AttributeCode.Misc, 100, 50);
|
||||
var attr = new Attribute(AttributeCode.Misc, 50, 100);
|
||||
expect(attr.current).toBe(50);
|
||||
|
||||
result = attr.set(51);
|
||||
|
|
39
src/scripts/game/specs/Equipment.spec.ts
Normal file
39
src/scripts/game/specs/Equipment.spec.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
/// <reference path="../../definitions/jasmine.d.ts"/>
|
||||
|
||||
module SpaceTac.Game.Specs {
|
||||
"use strict";
|
||||
|
||||
describe("Equipment", () => {
|
||||
it("checks capabilities requirements", () => {
|
||||
var equipment = new Equipment();
|
||||
var ship = new Ship();
|
||||
|
||||
expect(equipment.canBeEquipped(ship)).toBe(true);
|
||||
|
||||
equipment.requirements.push(new Attribute(AttributeCode.Cap_Time, 2));
|
||||
|
||||
expect(equipment.canBeEquipped(ship)).toBe(false);
|
||||
|
||||
ship.cap_time.set(1);
|
||||
|
||||
expect(equipment.canBeEquipped(ship)).toBe(false);
|
||||
|
||||
ship.cap_time.set(2);
|
||||
|
||||
expect(equipment.canBeEquipped(ship)).toBe(true);
|
||||
|
||||
ship.cap_time.set(3);
|
||||
|
||||
expect(equipment.canBeEquipped(ship)).toBe(true);
|
||||
|
||||
// Second requirement
|
||||
equipment.requirements.push(new Attribute(AttributeCode.Cap_Material, 3));
|
||||
|
||||
expect(equipment.canBeEquipped(ship)).toBe(false);
|
||||
|
||||
ship.cap_material.set(4);
|
||||
|
||||
expect(equipment.canBeEquipped(ship)).toBe(true);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -12,6 +12,8 @@ module SpaceTac.Game.Specs {
|
|||
template.duration = new IntegerRange(1, 2);
|
||||
template.ap_usage = new Range(4, 12);
|
||||
template.min_level = new IntegerRange(5, 9);
|
||||
template.addRequirement(AttributeCode.Cap_Energy, 2, 8);
|
||||
template.addRequirement(AttributeCode.Cap_Human, 5);
|
||||
|
||||
var equipment = template.generateFixed(0.0);
|
||||
|
||||
|
@ -22,6 +24,9 @@ module SpaceTac.Game.Specs {
|
|||
expect(equipment.duration).toEqual(1);
|
||||
expect(equipment.ap_usage).toEqual(4);
|
||||
expect(equipment.min_level).toEqual(5);
|
||||
expect(equipment.requirements.length).toBe(2);
|
||||
expect(equipment.requirements[0]).toEqual(new Attribute(AttributeCode.Cap_Energy, 2));
|
||||
expect(equipment.requirements[1]).toEqual(new Attribute(AttributeCode.Cap_Human, 5));
|
||||
|
||||
equipment = template.generateFixed(1.0);
|
||||
|
||||
|
@ -32,6 +37,9 @@ module SpaceTac.Game.Specs {
|
|||
expect(equipment.duration).toEqual(2);
|
||||
expect(equipment.ap_usage).toEqual(12);
|
||||
expect(equipment.min_level).toEqual(9);
|
||||
expect(equipment.requirements.length).toBe(2);
|
||||
expect(equipment.requirements[0]).toEqual(new Attribute(AttributeCode.Cap_Energy, 8));
|
||||
expect(equipment.requirements[1]).toEqual(new Attribute(AttributeCode.Cap_Human, 5));
|
||||
|
||||
equipment = template.generateFixed(0.5);
|
||||
|
||||
|
@ -42,6 +50,9 @@ module SpaceTac.Game.Specs {
|
|||
expect(equipment.duration).toEqual(2);
|
||||
expect(equipment.ap_usage).toEqual(8);
|
||||
expect(equipment.min_level).toEqual(7);
|
||||
expect(equipment.requirements.length).toBe(2);
|
||||
expect(equipment.requirements[0]).toEqual(new Attribute(AttributeCode.Cap_Energy, 5));
|
||||
expect(equipment.requirements[1]).toEqual(new Attribute(AttributeCode.Cap_Human, 5));
|
||||
});
|
||||
|
||||
it("restricts power range to stay in a level range", () => {
|
||||
|
|
|
@ -73,7 +73,7 @@ module SpaceTac.Game {
|
|||
expect(battle.log.events[1].code).toEqual("attr");
|
||||
expect(battle.log.events[1].ship).toBe(ship);
|
||||
expect((<AttributeChangeEvent>battle.log.events[1]).attribute).toEqual(
|
||||
new Attribute(AttributeCode.AP, 20, 0));
|
||||
new Attribute(AttributeCode.AP, 0, 20));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ module SpaceTac.Game {
|
|||
|
||||
slot = ship.addSlot(SlotType.Engine);
|
||||
equipment = new Equipment();
|
||||
equipment.slot = slot.type;
|
||||
equipment.action = new MoveAction(equipment);
|
||||
slot.attach(equipment);
|
||||
|
||||
|
@ -67,11 +68,13 @@ module SpaceTac.Game {
|
|||
|
||||
slot = ship.addSlot(SlotType.Power);
|
||||
equipment = new Equipment();
|
||||
equipment.slot = slot.type;
|
||||
equipment.permanent_effects.push(new AttributeMaxEffect(AttributeCode.AP, 4));
|
||||
slot.attach(equipment);
|
||||
|
||||
slot = ship.addSlot(SlotType.Power);
|
||||
equipment = new Equipment();
|
||||
equipment.slot = slot.type;
|
||||
equipment.permanent_effects.push(new AttributeMaxEffect(AttributeCode.AP, 5));
|
||||
slot.attach(equipment);
|
||||
|
||||
|
@ -120,7 +123,7 @@ module SpaceTac.Game {
|
|||
expect(battle.log.events.length).toBe(0);
|
||||
});
|
||||
|
||||
it("sets and logs death state", function (){
|
||||
it("sets and logs death state", function () {
|
||||
var fleet = new Fleet();
|
||||
var battle = new Battle(fleet);
|
||||
var ship = new Ship(fleet);
|
||||
|
|
42
src/scripts/game/specs/Slot.spec.ts
Normal file
42
src/scripts/game/specs/Slot.spec.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
/// <reference path="../../definitions/jasmine.d.ts"/>
|
||||
|
||||
module SpaceTac.Game.Specs {
|
||||
"use strict";
|
||||
|
||||
describe("Slot", () => {
|
||||
it("checks equipment type", () => {
|
||||
var ship = new Ship();
|
||||
var slot = ship.addSlot(SlotType.Engine);
|
||||
|
||||
var equipment = new Equipment();
|
||||
equipment.slot = SlotType.Weapon;
|
||||
|
||||
expect(slot.attached).toBeNull();
|
||||
slot.attach(equipment);
|
||||
expect(slot.attached).toBeNull();
|
||||
|
||||
equipment.slot = SlotType.Engine;
|
||||
|
||||
slot.attach(equipment);
|
||||
expect(slot.attached).toBe(equipment);
|
||||
});
|
||||
|
||||
it("checks equipment capabilities", () => {
|
||||
var ship = new Ship();
|
||||
var slot = ship.addSlot(SlotType.Shield);
|
||||
|
||||
var equipment = new Equipment();
|
||||
equipment.slot = SlotType.Shield;
|
||||
equipment.requirements.push(new Attribute(AttributeCode.Cap_Gravity, 5));
|
||||
|
||||
expect(slot.attached).toBeNull();
|
||||
slot.attach(equipment);
|
||||
expect(slot.attached).toBeNull();
|
||||
|
||||
ship.cap_gravity.set(6);
|
||||
|
||||
slot.attach(equipment);
|
||||
expect(slot.attached).toBe(equipment);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue