203 lines
7.1 KiB
TypeScript
203 lines
7.1 KiB
TypeScript
|
import "reflect-metadata";
|
||
|
|
||
|
import { RepairHelper } from "@spt-aki/helpers/RepairHelper";
|
||
|
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
||
|
import { ITemplateItem } from "@spt-aki/models/eft/common/tables/ITemplateItem";
|
||
|
import { TestHelper } from "./common/TestHelper";
|
||
|
|
||
|
const testHelper = new TestHelper();
|
||
|
|
||
|
const logger = testHelper.getTestLogger();
|
||
|
|
||
|
const jsonUtil = testHelper.getTestJsonUtil();
|
||
|
const randomUtil = testHelper.getTestRandomUtil();
|
||
|
const configServer = testHelper.getTestConfigServer();
|
||
|
|
||
|
const databaseServer = testHelper.getTestDatabaseServer();
|
||
|
|
||
|
describe("BotHelper", () =>
|
||
|
{
|
||
|
let helper: RepairHelper;
|
||
|
beforeEach(() =>
|
||
|
{
|
||
|
helper = new RepairHelper(
|
||
|
logger,
|
||
|
jsonUtil,
|
||
|
randomUtil,
|
||
|
databaseServer,
|
||
|
configServer);
|
||
|
});
|
||
|
|
||
|
it("RepairHelper type check", () =>
|
||
|
{
|
||
|
expect(helper).toBeInstanceOf(RepairHelper);
|
||
|
});
|
||
|
|
||
|
it("updateItemDurability() repairkit with slick armor with max dura degredation", () =>
|
||
|
{
|
||
|
const slickTpl = "5e4abb5086f77406975c9342";
|
||
|
const itemToRepair: Item = {
|
||
|
_id: "12345",
|
||
|
_tpl: slickTpl,
|
||
|
upd: {
|
||
|
Repairable: {
|
||
|
Durability: 60,
|
||
|
MaxDurability: 80
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[slickTpl];
|
||
|
const isArmor = true;
|
||
|
const useRepairKit = true;
|
||
|
const useDegridation = true;
|
||
|
|
||
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 5, useRepairKit, 1, useDegridation);
|
||
|
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(80);
|
||
|
});
|
||
|
|
||
|
it("updateItemDurability() trader with slick armor with max dura degredation - partial repair", () =>
|
||
|
{
|
||
|
const slickTpl = "5e4abb5086f77406975c9342";
|
||
|
const itemToRepair: Item = {
|
||
|
_id: "12345",
|
||
|
_tpl: slickTpl,
|
||
|
upd: {
|
||
|
Repairable: {
|
||
|
Durability: 60,
|
||
|
MaxDurability: 80
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[slickTpl];
|
||
|
const isArmor = true;
|
||
|
const useRepairKit = false;
|
||
|
const useDegridation = true;
|
||
|
|
||
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 5, useRepairKit, 1.2, useDegridation);
|
||
|
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(80);
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeGreaterThan(60);
|
||
|
});
|
||
|
|
||
|
it("updateItemDurability() trader with slick armor, no dura degredation", () =>
|
||
|
{
|
||
|
const slickTpl = "5e4abb5086f77406975c9342";
|
||
|
const itemToRepair: Item = {
|
||
|
_id: "12345",
|
||
|
_tpl: slickTpl,
|
||
|
upd: {
|
||
|
Repairable: {
|
||
|
Durability: 60,
|
||
|
MaxDurability: 80
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[slickTpl];
|
||
|
const isArmor = true;
|
||
|
const useRepairKit = false;
|
||
|
const useDegridation = false;
|
||
|
|
||
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 20, useRepairKit, 1.2, useDegridation);
|
||
|
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBe(80);
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
|
||
|
});
|
||
|
|
||
|
it("updateItemDurability() repairkit with g36 with max dura degredation - Full repair", () =>
|
||
|
{
|
||
|
const itemCurrentDura = 68;
|
||
|
const itemCurrentMaxDura = 100;
|
||
|
const duraDifference = itemCurrentMaxDura - itemCurrentDura;
|
||
|
const g36Tpl = "623063e994fc3f7b302a9696";
|
||
|
const itemToRepair: Item = {
|
||
|
_id: "12345",
|
||
|
_tpl: g36Tpl,
|
||
|
upd: {
|
||
|
Repairable: {
|
||
|
Durability: itemCurrentDura,
|
||
|
MaxDurability: itemCurrentMaxDura
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[g36Tpl];
|
||
|
const isArmor = false;
|
||
|
const useRepairKit = true;
|
||
|
const useDegridation = true;
|
||
|
|
||
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, duraDifference, useRepairKit, 1, useDegridation);
|
||
|
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(100);
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
|
||
|
});
|
||
|
|
||
|
it("updateItemDurability() trader with g36 with max dura degredation - Full repair", () =>
|
||
|
{
|
||
|
const itemCurrentDura = 68;
|
||
|
const itemCurrentMaxDura = 100;
|
||
|
const duraDifference = itemCurrentMaxDura - itemCurrentDura;
|
||
|
const g36Tpl = "623063e994fc3f7b302a9696";
|
||
|
const itemToRepair: Item = {
|
||
|
_id: "12345",
|
||
|
_tpl: g36Tpl,
|
||
|
upd: {
|
||
|
Repairable: {
|
||
|
Durability: itemCurrentDura,
|
||
|
MaxDurability: itemCurrentMaxDura
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[g36Tpl];
|
||
|
const isArmor = false;
|
||
|
const useRepairKit = false;
|
||
|
const useDegridation = true;
|
||
|
|
||
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, duraDifference, useRepairKit, 1.2, useDegridation);
|
||
|
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(100);
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
|
||
|
});
|
||
|
|
||
|
it("updateItemDurability() faceshield broken use repairkit with max dura degredation", () =>
|
||
|
{
|
||
|
const twExfilBallisticFaceShieldTpl = "5e00cdd986f7747473332240";
|
||
|
const itemToRepair: Item = {
|
||
|
_id: "12345",
|
||
|
_tpl: twExfilBallisticFaceShieldTpl,
|
||
|
upd: {
|
||
|
Repairable: {
|
||
|
Durability: 30,
|
||
|
MaxDurability: 45
|
||
|
},
|
||
|
FaceShield: {
|
||
|
Hits: 2
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const itemToRepairDetails = <ITemplateItem>databaseServer.getTables().templates?.items[twExfilBallisticFaceShieldTpl];
|
||
|
const isArmor = true;
|
||
|
const useRepairKit = true;
|
||
|
const useDegridation = true;
|
||
|
|
||
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 5, useRepairKit, 1, useDegridation);
|
||
|
|
||
|
expect(itemToRepair.upd?.FaceShield?.Hits).toBe(0);
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(45);
|
||
|
expect(itemToRepair.upd?.Repairable?.Durability).toBe(itemToRepair.upd?.Repairable?.MaxDurability);
|
||
|
});
|
||
|
|
||
|
it("isWeaponTemplate() g36 weapon", () =>
|
||
|
{
|
||
|
const result = helper.isWeaponTemplate("623063e994fc3f7b302a9696");
|
||
|
|
||
|
expect(result).toBe(true);
|
||
|
});
|
||
|
|
||
|
it("isWeaponTemplate() slick armor", () =>
|
||
|
{
|
||
|
const result = helper.isWeaponTemplate("5e4abb5086f77406975c9342");
|
||
|
|
||
|
expect(result).toBe(false);
|
||
|
});
|
||
|
});
|