Test coverage on core
This commit is contained in:
parent
b7a02e2b37
commit
53bbe510d2
|
@ -13,5 +13,40 @@ module TS.SpaceTac {
|
|||
fleet.ships[2].level = 7;
|
||||
expect(fleet.getLevel()).toEqual(4);
|
||||
});
|
||||
|
||||
it("changes location, only using jumps to travel between systems", function () {
|
||||
let fleet = new Fleet();
|
||||
let system1 = new Star();
|
||||
let system2 = new Star();
|
||||
let jump1 = new StarLocation(system1, StarLocationType.WARP);
|
||||
let jump2 = new StarLocation(system2, StarLocationType.WARP);
|
||||
jump1.setJumpDestination(jump2);
|
||||
jump2.setJumpDestination(jump1);
|
||||
let other1 = new StarLocation(system1, StarLocationType.PLANET);
|
||||
|
||||
let result = fleet.setLocation(other1);
|
||||
expect(result).toBe(true);
|
||||
expect(fleet.location).toBe(other1);
|
||||
|
||||
result = fleet.setLocation(jump2);
|
||||
expect(result).toBe(false);
|
||||
expect(fleet.location).toBe(other1);
|
||||
|
||||
result = fleet.setLocation(jump1);
|
||||
expect(result).toBe(true);
|
||||
expect(fleet.location).toBe(jump1);
|
||||
|
||||
result = fleet.setLocation(jump2);
|
||||
expect(result).toBe(true);
|
||||
expect(fleet.location).toBe(jump2);
|
||||
|
||||
result = fleet.setLocation(other1);
|
||||
expect(result).toBe(false);
|
||||
expect(fleet.location).toBe(jump2);
|
||||
|
||||
result = fleet.setLocation(jump1);
|
||||
expect(result).toBe(true);
|
||||
expect(fleet.location).toBe(jump1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
module TS.SpaceTac {
|
||||
// A fleet of ships
|
||||
/**
|
||||
* A fleet of ships, all belonging to the same player
|
||||
*/
|
||||
export class Fleet {
|
||||
// Fleet owner
|
||||
player: Player;
|
||||
|
@ -21,8 +23,16 @@ module TS.SpaceTac {
|
|||
this.battle = null;
|
||||
}
|
||||
|
||||
// Set the current location of the fleet
|
||||
setLocation(location: StarLocation): void {
|
||||
/**
|
||||
* Set the current location of the fleet
|
||||
*
|
||||
* Returns true on success
|
||||
*/
|
||||
setLocation(location: StarLocation, force = false): boolean {
|
||||
if (!force && this.location && location.star != this.location.star && (this.location.type != StarLocationType.WARP || this.location.jump_dest != location)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.location = location;
|
||||
this.player.setVisited(this.location);
|
||||
|
||||
|
@ -31,6 +41,8 @@ module TS.SpaceTac {
|
|||
if (battle) {
|
||||
this.player.setBattle(battle);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add a ship in this fleet
|
||||
|
@ -70,15 +82,5 @@ module TS.SpaceTac {
|
|||
});
|
||||
return (count > 0);
|
||||
}
|
||||
|
||||
// Use the current warp location to make a jump to another star
|
||||
jump(): boolean {
|
||||
if (this.location && this.location.type === StarLocationType.WARP && this.location.jump_dest) {
|
||||
this.player.fleet.setLocation(this.player.fleet.location.jump_dest);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,15 +94,30 @@ module TS.SpaceTac.Specs {
|
|||
expect(result.max).toBeCloseTo(0.5, 0.000001);
|
||||
});
|
||||
|
||||
it("adds damage on target effects", () => {
|
||||
var template = new LootTemplate(SlotType.Weapon, "Bulletator");
|
||||
template.addDamageOnTargetEffect(80, 120);
|
||||
it("adds modulated effects", () => {
|
||||
let template = new LootTemplate(SlotType.Weapon, "Bulletator");
|
||||
template.addEffect(new DamageEffect(), 5, 10, true);
|
||||
|
||||
var result = template.generateFixed(0.5);
|
||||
expect(result.target_effects.length).toBe(1);
|
||||
var effect = <DamageEffect>result.target_effects[0];
|
||||
expect(effect.code).toEqual("damage");
|
||||
expect(effect.value).toEqual(100);
|
||||
expect(template.generateFixed(0).target_effects).toEqual([new DamageEffect(5)]);
|
||||
expect(template.generateFixed(1).target_effects).toEqual([new DamageEffect(10)]);
|
||||
|
||||
template.addEffect(new AttributeEffect("initiative"), 1, 2, false);
|
||||
|
||||
expect(template.generateFixed(0).permanent_effects).toEqual([new AttributeEffect("initiative", 1)]);
|
||||
expect(template.generateFixed(1).permanent_effects).toEqual([new AttributeEffect("initiative", 2)]);
|
||||
});
|
||||
|
||||
it("adds modulated sticky effects", () => {
|
||||
let template = new LootTemplate(SlotType.Weapon, "Bulletator");
|
||||
template.addStickyEffect(new DamageEffect(), 5, 10, 1, 2, true, false, true);
|
||||
|
||||
expect(template.generateFixed(0).target_effects).toEqual([new StickyEffect(new DamageEffect(5), 1, true, false)]);
|
||||
expect(template.generateFixed(1).target_effects).toEqual([new StickyEffect(new DamageEffect(10), 2, true, false)]);
|
||||
|
||||
template.addStickyEffect(new AttributeLimitEffect("power_recovery"), 1, 2, 1, null, false, true, false);
|
||||
|
||||
expect(template.generateFixed(0).permanent_effects).toEqual([new StickyEffect(new AttributeLimitEffect("power_recovery", 1), 1, false, true)]);
|
||||
expect(template.generateFixed(1).permanent_effects).toEqual([new StickyEffect(new AttributeLimitEffect("power_recovery", 2), 1, false, true)]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -124,41 +124,50 @@ module TS.SpaceTac {
|
|||
}
|
||||
}
|
||||
|
||||
// Convenience function to add an attribute effect on equipment
|
||||
addAttributeEffect(code: keyof ShipAttributes, min: number, max: number = null): void {
|
||||
var template = new EffectTemplate(new AttributeEffect(code, 0));
|
||||
template.addModifier("value", new IntegerRange(min, max));
|
||||
this.permanent_effects.push(template);
|
||||
/**
|
||||
* Convenience function to add a modulated effect to the equipment
|
||||
*/
|
||||
addEffect(effect: BaseEffect, min_value: number, max_value: number = null, target = true) {
|
||||
var template = new EffectTemplate(effect);
|
||||
template.addModifier("value", new IntegerRange(min_value, max_value));
|
||||
if (target) {
|
||||
this.target_effects.push(template);
|
||||
} else {
|
||||
this.permanent_effects.push(template);
|
||||
}
|
||||
}
|
||||
|
||||
// Convenience function to add a permanent attribute limit effect on equipment
|
||||
addAttributeLimitEffect(code: keyof ShipAttributes, min: number, max: number = null): void {
|
||||
var template = new EffectTemplate(new AttributeLimitEffect(code, 0));
|
||||
template.addModifier("value", new IntegerRange(min, max));
|
||||
this.permanent_effects.push(template);
|
||||
}
|
||||
|
||||
// Convenience function to add a value effect on equipment
|
||||
addValueEffectOnTarget(code: keyof ShipValues, min: number, max: number = null): void {
|
||||
var template = new EffectTemplate(new ValueEffect(code, 0));
|
||||
template.addModifier("value", new IntegerRange(min, max));
|
||||
this.target_effects.push(template);
|
||||
}
|
||||
|
||||
// Convenience function to add a "damage on target" effect
|
||||
addDamageOnTargetEffect(min: number, max: number = null): void {
|
||||
var template = new EffectTemplate(new DamageEffect(0));
|
||||
template.addModifier("value", new IntegerRange(min, max));
|
||||
this.target_effects.push(template);
|
||||
}
|
||||
|
||||
// Convenience function to add a sticking effect on target
|
||||
addSticky(effect: BaseEffect, min_value: number, max_value: number = null,
|
||||
min_duration: number = 1, max_duration: number = null, on_stick = false, on_turn_start = false): void {
|
||||
/**
|
||||
* Convenience function to add a modulated sticky effect to the equipment
|
||||
*/
|
||||
addStickyEffect(effect: BaseEffect, min_value: number, max_value: number = null, min_duration: number = 1,
|
||||
max_duration: number = null, on_stick = false, on_turn_start = false, target = true): void {
|
||||
var template = new EffectTemplate(new StickyEffect(effect, 0, on_stick, on_turn_start));
|
||||
template.addModifier("value", new IntegerRange(min_value, max_value));
|
||||
template.addModifier("duration", new IntegerRange(min_duration, max_duration));
|
||||
this.target_effects.push(template);
|
||||
if (target) {
|
||||
this.target_effects.push(template);
|
||||
} else {
|
||||
this.permanent_effects.push(template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to add damage on target, immediate or over time
|
||||
*/
|
||||
addDamage(min_value: number, max_value: number | null = null, min_duration: number | null = null, max_duration: number | null = null) {
|
||||
if (min_duration != null) {
|
||||
this.addStickyEffect(new DamageEffect(), min_value, max_value, min_duration, max_duration, true, false, true);
|
||||
} else {
|
||||
this.addEffect(new DamageEffect(), min_value, max_value, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to add an attribute on the ship that equips the loot
|
||||
*/
|
||||
increaseAttribute(attribute: keyof ShipAttributes, min_value: number, max_value: number | null = null) {
|
||||
this.addEffect(new AttributeEffect(attribute), min_value, max_value, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -157,17 +157,6 @@ module TS.SpaceTac {
|
|||
return result;
|
||||
}
|
||||
|
||||
// Find an unbound warp location to bind, null if none found
|
||||
findUnboundWarp(): StarLocation {
|
||||
var result: StarLocation = null;
|
||||
this.locations.forEach((location: StarLocation) => {
|
||||
if (location.type === StarLocationType.WARP && !location.jump_dest) {
|
||||
result = location;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check if a location is far enough from all other ones
|
||||
private checkMinDistance(loc: StarLocation, others: StarLocation[]): boolean {
|
||||
return others.every((iloc: StarLocation): boolean => {
|
||||
|
|
|
@ -23,6 +23,12 @@ module TS.SpaceTac.Specs {
|
|||
expect(t1.getDistanceTo(t2)).toBeCloseTo(Math.sqrt(2), 0.00001);
|
||||
});
|
||||
|
||||
it("gets angle to another target", () => {
|
||||
var t1 = Target.newFromLocation(2, 3);
|
||||
var t2 = Target.newFromLocation(4, 5);
|
||||
expect(t1.getAngleTo(t2)).toBeCloseTo(Math.PI / 4, 0.0000001);
|
||||
});
|
||||
|
||||
it("checks if a target is in range of another", () => {
|
||||
var t1 = Target.newFromLocation(5, 4);
|
||||
expect(t1.isInRange(7, 3, 2)).toBe(false);
|
||||
|
|
|
@ -13,7 +13,7 @@ module TS.SpaceTac {
|
|||
// Base value
|
||||
value: number;
|
||||
|
||||
constructor(attrcode: keyof ShipAttributes, value: number) {
|
||||
constructor(attrcode: keyof ShipAttributes, value = 0) {
|
||||
super("attr");
|
||||
|
||||
this.attrcode = attrcode;
|
||||
|
|
|
@ -10,7 +10,7 @@ module TS.SpaceTac {
|
|||
// Base damage points
|
||||
value: number;
|
||||
|
||||
constructor(value: number) {
|
||||
constructor(value: number = 0) {
|
||||
super("damage");
|
||||
|
||||
this.value = value;
|
||||
|
|
|
@ -13,7 +13,7 @@ module TS.SpaceTac {
|
|||
// Value to add (or subtract if negative)
|
||||
value: number;
|
||||
|
||||
constructor(valuetype: keyof ShipValues, value: number) {
|
||||
constructor(valuetype: keyof ShipValues, value: number = 0) {
|
||||
super("value");
|
||||
|
||||
this.valuetype = valuetype;
|
||||
|
|
|
@ -17,7 +17,7 @@ module TS.SpaceTac.Equipments {
|
|||
template.setDeployDistance(100, 200);
|
||||
template.setEffectRadius(50, 100);
|
||||
template.setLifetime(2, 3);
|
||||
template.addDamageOnTargetEffect(20, 30);
|
||||
template.addDamage(20, 30);
|
||||
template.setPowerConsumption(3, 5);
|
||||
|
||||
let equipment = template.generateFixed(0);
|
||||
|
|
|
@ -12,7 +12,7 @@ module TS.SpaceTac.Equipments {
|
|||
this.can_target_space = false;
|
||||
|
||||
if (min_damage > 0 || (max_damage != null && max_damage > 0)) {
|
||||
this.addDamageOnTargetEffect(min_damage, max_damage);
|
||||
this.addDamage(min_damage, max_damage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ module TS.SpaceTac.Equipments {
|
|||
|
||||
this.min_level = new IntegerRange(1, 3);
|
||||
|
||||
this.addAttributeEffect("shield_capacity", 100, 200);
|
||||
this.increaseAttribute("shield_capacity", 100, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ module TS.SpaceTac.Equipments {
|
|||
|
||||
this.min_level = new IntegerRange(1, 1);
|
||||
|
||||
this.addAttributeEffect("initiative", 1);
|
||||
this.addAttributeEffect("power_capacity", 8);
|
||||
this.addAttributeEffect("power_initial", 5);
|
||||
this.addAttributeEffect("power_recovery", 4);
|
||||
this.increaseAttribute("initiative", 1);
|
||||
this.increaseAttribute("power_capacity", 8);
|
||||
this.increaseAttribute("power_initial", 5);
|
||||
this.increaseAttribute("power_recovery", 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ module TS.SpaceTac.Equipments {
|
|||
this.distance = new Range(100, 100);
|
||||
this.ap_usage = new IntegerRange(1);
|
||||
|
||||
this.addAttributeEffect("initiative", 1);
|
||||
this.increaseAttribute("initiative", 1);
|
||||
}
|
||||
|
||||
protected getActionForEquipment(equipment: Equipment): BaseAction {
|
||||
|
|
|
@ -7,7 +7,7 @@ module TS.SpaceTac.Equipments {
|
|||
|
||||
this.min_level = new IntegerRange(1, 3);
|
||||
|
||||
this.addAttributeEffect("hull_capacity", 100, 200);
|
||||
this.increaseAttribute("hull_capacity", 100, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ module TS.SpaceTac.Equipments {
|
|||
this.ap_usage = new IntegerRange(4, 5);
|
||||
this.min_level = new IntegerRange(1, 3);
|
||||
|
||||
this.addSticky(new AttributeLimitEffect("power_capacity"), 4, 3, 1, 2, true);
|
||||
this.addStickyEffect(new AttributeLimitEffect("power_capacity"), 4, 3, 1, 2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ module TS.SpaceTac.Equipments {
|
|||
this.setEffectRadius(40, 80);
|
||||
this.setPowerConsumption(4, 5);
|
||||
|
||||
this.addValueEffectOnTarget("hull", 10, 20);
|
||||
this.addEffect(new ValueEffect("hull"), 10, 20);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue