2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2015-01-13 00:00:00 +00:00
|
|
|
// Template used to generate a loot equipment
|
2017-02-07 18:54:53 +00:00
|
|
|
export class LootTemplate {
|
2015-01-13 00:00:00 +00:00
|
|
|
// Type of slot this equipment will fit in
|
|
|
|
slot: SlotType;
|
|
|
|
|
2015-02-23 00:00:00 +00:00
|
|
|
// Base name that will be given to generated equipment
|
2015-01-13 00:00:00 +00:00
|
|
|
name: string;
|
|
|
|
|
2017-02-07 19:15:21 +00:00
|
|
|
// Capability requirement ranges (indexed by attributes)
|
|
|
|
requirements: { [key: string]: IntegerRange };
|
2015-01-13 00:00:00 +00:00
|
|
|
|
|
|
|
// Distance to target
|
|
|
|
distance: Range;
|
|
|
|
|
|
|
|
// Effect area's radius
|
|
|
|
blast: Range;
|
|
|
|
|
2015-01-14 00:00:00 +00:00
|
|
|
// Duration, in number of turns
|
|
|
|
duration: IntegerRange;
|
2015-01-13 00:00:00 +00:00
|
|
|
|
2015-01-28 00:00:00 +00:00
|
|
|
// Permanent effects (when attached to an equipment slot)
|
2015-01-22 00:00:00 +00:00
|
|
|
permanent_effects: EffectTemplate[];
|
2015-01-13 00:00:00 +00:00
|
|
|
|
2015-01-28 00:00:00 +00:00
|
|
|
// Effects on target
|
|
|
|
target_effects: EffectTemplate[];
|
|
|
|
|
2015-01-13 00:00:00 +00:00
|
|
|
// Action Points usage
|
|
|
|
ap_usage: Range;
|
|
|
|
|
|
|
|
// Level requirement
|
2015-01-14 00:00:00 +00:00
|
|
|
min_level: IntegerRange;
|
2015-01-13 00:00:00 +00:00
|
|
|
|
|
|
|
// Create a loot template
|
|
|
|
constructor(slot: SlotType, name: string) {
|
|
|
|
this.slot = slot;
|
|
|
|
this.name = name;
|
2017-02-07 19:15:21 +00:00
|
|
|
this.requirements = {};
|
2015-01-13 00:00:00 +00:00
|
|
|
this.distance = new Range(0, 0);
|
|
|
|
this.blast = new Range(0, 0);
|
2015-01-14 00:00:00 +00:00
|
|
|
this.duration = new IntegerRange(0, 0);
|
2017-01-11 17:31:21 +00:00
|
|
|
this.ap_usage = new IntegerRange(0, 0);
|
2015-01-14 00:00:00 +00:00
|
|
|
this.min_level = new IntegerRange(0, 0);
|
2015-01-22 00:00:00 +00:00
|
|
|
this.permanent_effects = [];
|
2015-01-28 00:00:00 +00:00
|
|
|
this.target_effects = [];
|
2015-01-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-06 00:00:00 +00:00
|
|
|
// Set a capability requirement
|
2017-02-07 19:15:21 +00:00
|
|
|
addRequirement(capability: keyof ShipAttributes, min: number, max: number = null): void {
|
2015-02-06 00:00:00 +00:00
|
|
|
this.requirements[capability] = new IntegerRange(min, max);
|
|
|
|
}
|
|
|
|
|
2015-01-13 00:00:00 +00:00
|
|
|
// Generate a random equipment with this template
|
2015-01-14 00:00:00 +00:00
|
|
|
generate(random: RandomGenerator = null): Equipment {
|
|
|
|
random = random || new RandomGenerator();
|
2015-01-13 00:00:00 +00:00
|
|
|
var power = random.throw();
|
|
|
|
return this.generateFixed(power);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a fixed-power equipment with this template
|
|
|
|
generateFixed(power: number): Equipment {
|
|
|
|
var result = new Equipment();
|
|
|
|
|
|
|
|
result.slot = this.slot;
|
2015-02-23 00:00:00 +00:00
|
|
|
result.code = (this.name || "").toLowerCase().replace(/ /g, "");
|
2015-01-13 00:00:00 +00:00
|
|
|
result.name = this.name;
|
|
|
|
|
2015-01-14 00:00:00 +00:00
|
|
|
result.distance = this.distance.getProportional(power);
|
|
|
|
result.blast = this.blast.getProportional(power);
|
|
|
|
result.duration = this.duration.getProportional(power);
|
|
|
|
result.ap_usage = this.ap_usage.getProportional(power);
|
|
|
|
result.min_level = this.min_level.getProportional(power);
|
2015-01-13 00:00:00 +00:00
|
|
|
|
2015-01-16 00:00:00 +00:00
|
|
|
result.action = this.getActionForEquipment(result);
|
|
|
|
|
2017-02-07 19:15:21 +00:00
|
|
|
iteritems(this.requirements, (key: string, requirement: IntegerRange) => {
|
2015-02-06 00:00:00 +00:00
|
|
|
if (requirement) {
|
2017-02-07 19:15:21 +00:00
|
|
|
result.requirements[key] = requirement.getProportional(power);
|
2015-02-06 00:00:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
this.permanent_effects.forEach((eff_template: EffectTemplate) => {
|
|
|
|
result.permanent_effects.push(eff_template.generateFixed(power));
|
|
|
|
});
|
2015-01-28 00:00:00 +00:00
|
|
|
this.target_effects.forEach((eff_template: EffectTemplate) => {
|
|
|
|
result.target_effects.push(eff_template.generateFixed(power));
|
|
|
|
});
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2015-01-13 00:00:00 +00:00
|
|
|
return result;
|
|
|
|
}
|
2015-01-14 00:00:00 +00:00
|
|
|
|
|
|
|
// Find the power range that will result in the level range
|
|
|
|
getPowerRangeForLevel(level: IntegerRange): Range {
|
|
|
|
if (level.min > this.min_level.max || level.max < this.min_level.min) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
var min: number;
|
|
|
|
var max: number;
|
|
|
|
|
|
|
|
if (level.min <= this.min_level.min) {
|
|
|
|
min = 0.0;
|
|
|
|
} else {
|
|
|
|
min = this.min_level.getReverseProportional(level.min);
|
|
|
|
}
|
|
|
|
if (level.max >= this.min_level.max) {
|
|
|
|
max = 1.0;
|
|
|
|
} else {
|
2015-01-14 00:00:00 +00:00
|
|
|
max = this.min_level.getReverseProportional(level.max + 1);
|
2015-01-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Range(min, max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate an equipment that will have its level requirement in the given range
|
|
|
|
// May return null if level range is not compatible with the template
|
2015-02-13 00:00:00 +00:00
|
|
|
generateInLevelRange(level: IntegerRange, random: RandomGenerator = new RandomGenerator()): Equipment {
|
2015-01-14 00:00:00 +00:00
|
|
|
var random_range = this.getPowerRangeForLevel(level);
|
|
|
|
if (random_range) {
|
|
|
|
var power = random.throw() * (random_range.max - random_range.min) + random_range.min;
|
|
|
|
return this.generateFixed(power);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-01-16 00:00:00 +00:00
|
|
|
|
2017-02-09 22:21:39 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2015-01-22 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 22:21:39 +00:00
|
|
|
/**
|
|
|
|
* 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));
|
|
|
|
if (target) {
|
|
|
|
this.target_effects.push(template);
|
|
|
|
} else {
|
|
|
|
this.permanent_effects.push(template);
|
|
|
|
}
|
2017-02-07 00:08:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 22:21:39 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 22:21:39 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
2015-02-27 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-07 00:08:07 +00:00
|
|
|
/**
|
|
|
|
* Set the power consumption
|
|
|
|
*/
|
|
|
|
setPowerConsumption(minimal: number, maximal: number | null = null) {
|
|
|
|
this.ap_usage = new IntegerRange(minimal, maximal);
|
|
|
|
}
|
|
|
|
|
2015-01-16 00:00:00 +00:00
|
|
|
// Method to reimplement to assign an action to a generated equipment
|
|
|
|
protected getActionForEquipment(equipment: Equipment): BaseAction {
|
|
|
|
return null;
|
|
|
|
}
|
2015-01-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|