1
0
Fork 0
spacetac/src/core/LootTemplate.spec.ts

137 lines
5.8 KiB
TypeScript
Raw Normal View History

/// <reference path="effects/BaseEffect.ts" />
2017-09-24 22:23:22 +00:00
module TK.SpaceTac.Specs {
class FakeEffect extends BaseEffect {
fakevalue: number
constructor(val = 5) {
super("fake");
this.fakevalue = val;
}
}
2017-10-26 21:47:13 +00:00
testing("LootTemplate", test => {
test.case("generates equipment with correct information", check => {
let template = new LootTemplate(SlotType.Power, "Power Generator", "A great power generator !");
let result = template.generate(2, EquipmentQuality.PREMIUM);
2017-10-26 21:47:13 +00:00
check.equals(result.slot_type, SlotType.Power);
check.equals(result.code, "powergenerator");
check.equals(result.name, "Power Generator");
check.equals(result.price, 350);
check.equals(result.level, 2);
check.equals(result.quality, EquipmentQuality.COMMON);
check.equals(result.description, "A great power generator !");
template.addAttributeEffect("power_capacity", istep(10));
result = template.generate(1, EquipmentQuality.COMMON);
2017-10-26 21:47:13 +00:00
check.equals(result.quality, EquipmentQuality.COMMON);
check.equals(result.effects, [new AttributeEffect("power_capacity", 10)]);
result = template.generate(1, EquipmentQuality.PREMIUM);
2017-10-26 21:47:13 +00:00
check.equals(result.quality, EquipmentQuality.PREMIUM);
check.equals(result.effects, [new AttributeEffect("power_capacity", 13)]);
});
2017-10-26 21:47:13 +00:00
test.case("applies requirements on skills", check => {
let template = new LootTemplate(SlotType.Hull, "Hull");
2017-09-17 22:49:53 +00:00
template.setSkillsRequirements({ "skill_photons": istep(1), "skill_gravity": istep(2, istep(1)) });
let result = template.generate(1);
2017-10-26 21:47:13 +00:00
check.equals(result.requirements, {
2017-06-11 20:44:12 +00:00
"skill_photons": 1,
"skill_gravity": 2
});
2015-01-14 00:00:00 +00:00
result = template.generate(2);
2017-10-26 21:47:13 +00:00
check.equals(result.requirements, {
2017-06-11 20:44:12 +00:00
"skill_photons": 2,
"skill_gravity": 3
});
2015-01-14 00:00:00 +00:00
result = template.generate(10);
2017-10-26 21:47:13 +00:00
check.equals(result.requirements, {
2017-06-11 20:44:12 +00:00
"skill_photons": 10,
"skill_gravity": 47
});
2015-01-14 00:00:00 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("applies cooldown", check => {
2017-05-16 23:12:05 +00:00
let template = new LootTemplate(SlotType.Weapon, "Weapon");
template.setCooldown(istep(1), istep(2));
let result = template.generate(1);
2017-10-26 21:47:13 +00:00
check.equals(result.cooldown.overheat, 1);
check.equals(result.cooldown.cooling, 2);
2017-05-16 23:12:05 +00:00
result = template.generate(2);
2017-10-26 21:47:13 +00:00
check.equals(result.cooldown.overheat, 2);
check.equals(result.cooldown.cooling, 3);
2017-05-16 23:12:05 +00:00
result = template.generate(10);
2017-10-26 21:47:13 +00:00
check.equals(result.cooldown.overheat, 10);
check.equals(result.cooldown.cooling, 11);
2017-05-16 23:12:05 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("applies attributes permenant effects", check => {
let template = new LootTemplate(SlotType.Shield, "Shield");
template.addAttributeEffect("shield_capacity", irange(undefined, 50, 10));
2015-01-14 00:00:00 +00:00
let result = template.generate(1);
2017-10-26 21:47:13 +00:00
check.equals(result.effects, [new AttributeEffect("shield_capacity", 50)]);
2015-01-14 00:00:00 +00:00
result = template.generate(2);
2017-10-26 21:47:13 +00:00
check.equals(result.effects, [new AttributeEffect("shield_capacity", 60)]);
});
2015-01-14 00:00:00 +00:00
2017-10-26 21:47:13 +00:00
test.case("adds move actions", check => {
let template = new LootTemplate(SlotType.Engine, "Engine");
template.addMoveAction(irange(undefined, 100, 10), istep(50, irepeat(10)), irepeat(95));
2015-01-14 00:00:00 +00:00
let result = template.generate(1);
2017-10-26 21:47:13 +00:00
check.equals(result.action, new MoveAction(result, 100, 50, 95));
2015-01-14 00:00:00 +00:00
result = template.generate(2);
2017-10-26 21:47:13 +00:00
check.equals(result.action, new MoveAction(result, 110, 60, 95));
2015-01-14 00:00:00 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("adds fire actions", check => {
let template = new LootTemplate(SlotType.Weapon, "Weapon");
2017-10-03 16:11:30 +00:00
template.addTriggerAction(istep(1), [
new EffectTemplate(new FakeEffect(3), { "fakevalue": istep(8) })
2017-10-03 16:11:30 +00:00
], istep(100), istep(50), istep(10));
2017-02-09 22:21:39 +00:00
let result = template.generate(1);
2017-10-26 21:47:13 +00:00
check.equals(result.action, new TriggerAction(result, [new FakeEffect(8)], 1, 100, 50, 10));
2017-02-09 22:21:39 +00:00
result = template.generate(2);
2017-10-26 21:47:13 +00:00
check.equals(result.action, new TriggerAction(result, [new FakeEffect(9)], 2, 101, 51, 11));
2017-02-09 22:21:39 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("adds drone actions", check => {
let template = new LootTemplate(SlotType.Weapon, "Weapon");
template.addDroneAction(istep(1), istep(100), istep(2), istep(50), [
new EffectTemplate(new FakeEffect(3), { "fakevalue": istep(8) })
]);
2017-02-09 22:21:39 +00:00
let result = template.generate(1);
2017-10-26 21:47:13 +00:00
check.equals(result.action, new DeployDroneAction(result, 1, 100, 2, 50, [new FakeEffect(8)]));
result = template.generate(2);
2017-10-26 21:47:13 +00:00
check.equals(result.action, new DeployDroneAction(result, 2, 101, 3, 51, [new FakeEffect(9)]));
});
2017-10-26 21:47:13 +00:00
test.case("checks the presence of damaging effects", check => {
let template = new LootTemplate(SlotType.Weapon, "Weapon");
2017-10-26 21:47:13 +00:00
check.equals(template.hasDamageEffect(), false);
2017-09-17 22:49:53 +00:00
template.addAttributeEffect("maneuvrability", irepeat(1));
2017-10-26 21:47:13 +00:00
check.equals(template.hasDamageEffect(), false);
2017-10-03 16:11:30 +00:00
template.addTriggerAction(irepeat(1), [new EffectTemplate(new BaseEffect("test"), {})], irepeat(50), irepeat(50));
2017-10-26 21:47:13 +00:00
check.equals(template.hasDamageEffect(), false);
2017-10-03 16:11:30 +00:00
template.addTriggerAction(irepeat(1), [new EffectTemplate(new DamageEffect(20), {})], irepeat(50), irepeat(50));
2017-10-26 21:47:13 +00:00
check.equals(template.hasDamageEffect(), true);
});
2015-01-14 00:00:00 +00:00
});
}