2015-03-02 00:00:00 +00:00
|
|
|
/// <reference path="Serializable.ts"/>
|
|
|
|
|
2017-01-26 23:52:45 +00:00
|
|
|
module TS.SpaceTac.Game {
|
2015-01-13 00:00:00 +00:00
|
|
|
// Template used to generate a loot equipment
|
2015-03-02 00:00:00 +00:00
|
|
|
export class LootTemplate extends Serializable {
|
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;
|
|
|
|
|
2015-02-06 00:00:00 +00:00
|
|
|
// Capability requirement ranges (indexed by AttributeCode)
|
|
|
|
requirements: 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) {
|
2015-03-02 00:00:00 +00:00
|
|
|
super();
|
2015-01-13 00:00:00 +00:00
|
|
|
this.slot = slot;
|
|
|
|
this.name = name;
|
2015-02-06 00:00:00 +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
|
|
|
|
addRequirement(capability: AttributeCode, min: number, max: number = null): void {
|
|
|
|
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);
|
|
|
|
|
2015-02-06 00:00:00 +00:00
|
|
|
this.requirements.forEach((requirement: IntegerRange, index: AttributeCode) => {
|
|
|
|
if (requirement) {
|
|
|
|
result.requirements.push(new Attribute(index, requirement.getProportional(power)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// Convenience function to add a permanent attribute effect on equipment
|
|
|
|
addPermanentAttributeValueEffect(code: AttributeCode, min: number, max: number = null): void {
|
|
|
|
var template = new EffectTemplate(new AttributeValueEffect(code, 0));
|
2017-01-11 17:31:21 +00:00
|
|
|
template.addModifier("value", new IntegerRange(min, max));
|
2015-01-22 00:00:00 +00:00
|
|
|
this.permanent_effects.push(template);
|
|
|
|
}
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// Convenience function to add a permanent attribute max effect on equipment
|
|
|
|
addPermanentAttributeMaxEffect(code: AttributeCode, min: number, max: number = null): void {
|
|
|
|
var template = new EffectTemplate(new AttributeMaxEffect(code, 0));
|
2017-01-11 17:31:21 +00:00
|
|
|
template.addModifier("value", new IntegerRange(min, max));
|
2015-01-22 00:00:00 +00:00
|
|
|
this.permanent_effects.push(template);
|
|
|
|
}
|
|
|
|
|
2017-02-07 00:08:07 +00:00
|
|
|
// Convenience function to add an offset effect on attribute value
|
|
|
|
addAttributeAddEffect(code: AttributeCode, min: number, max: number | null = null): void {
|
|
|
|
let template = new EffectTemplate(new AttributeAddEffect(code, 0));
|
|
|
|
template.addModifier("value", new IntegerRange(min, max));
|
|
|
|
this.target_effects.push(template);
|
|
|
|
}
|
|
|
|
|
2015-01-28 00:00:00 +00:00
|
|
|
// Convenience function to add a "damage on target" effect
|
|
|
|
addDamageOnTargetEffect(min: number, max: number = null): void {
|
|
|
|
var template = new EffectTemplate(new DamageEffect(0));
|
2017-01-11 17:31:21 +00:00
|
|
|
template.addModifier("value", new IntegerRange(min, max));
|
2015-01-28 00:00:00 +00:00
|
|
|
this.target_effects.push(template);
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:00:00 +00:00
|
|
|
// Convenience function to add a sticking effect on target
|
2017-01-24 00:14:04 +00:00
|
|
|
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 {
|
|
|
|
var template = new EffectTemplate(new StickyEffect(effect, 0, on_stick, on_turn_start));
|
2017-01-11 17:31:21 +00:00
|
|
|
template.addModifier("value", new IntegerRange(min_value, max_value));
|
2015-04-22 20:03:59 +00:00
|
|
|
template.addModifier("duration", new IntegerRange(min_duration, max_duration));
|
2015-02-27 00:00:00 +00:00
|
|
|
this.target_effects.push(template);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|