2023-03-03 16:23:46 +01:00
|
|
|
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";
|
2023-03-03 18:53:28 +01:00
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
|
|
|
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
2023-03-03 16:23:46 +01:00
|
|
|
import { TestHelper } from "./common/TestHelper";
|
|
|
|
|
2023-03-03 18:53:28 +01:00
|
|
|
let testHelper: TestHelper;
|
|
|
|
let logger: ILogger;
|
|
|
|
let jsonUtil: JsonUtil;
|
|
|
|
let randomUtil: RandomUtil;
|
|
|
|
let configServer: ConfigServer;
|
|
|
|
let databaseServer: DatabaseServer;
|
|
|
|
let helper: RepairHelper;
|
|
|
|
|
|
|
|
describe("BotHelper", () => {
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
testHelper = await TestHelper.fetchTestHelper();
|
|
|
|
logger = testHelper.getTestLogger();
|
|
|
|
jsonUtil = testHelper.getTestJsonUtil();
|
|
|
|
randomUtil = testHelper.getTestRandomUtil();
|
|
|
|
configServer = testHelper.getTestConfigServer();
|
|
|
|
databaseServer = testHelper.getTestDatabaseServer();
|
|
|
|
})
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-03-03 16:23:46 +01:00
|
|
|
helper = new RepairHelper(
|
|
|
|
logger,
|
|
|
|
jsonUtil,
|
|
|
|
randomUtil,
|
|
|
|
databaseServer,
|
|
|
|
configServer);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("RepairHelper type check", () =>
|
|
|
|
{
|
|
|
|
expect(helper).toBeInstanceOf(RepairHelper);
|
|
|
|
});
|
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
it("updateItemDurability() repairkit with slick armor with max dura degradation", () =>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
it("updateItemDurability() trader with slick armor with max dura degradation - partial repair", () =>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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);
|
2023-03-07 01:06:59 +01:00
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThanOrEqual(itemToRepair.upd?.Repairable?.MaxDurability);
|
2023-03-03 16:23:46 +01:00
|
|
|
});
|
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
it("updateItemDurability() trader with slick armor, no dura degradation", () =>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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;
|
2023-03-07 01:06:59 +01:00
|
|
|
const useDegradation = false;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 20, useRepairKit, 1.2, useDegradation);
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBe(80);
|
2023-03-07 01:06:59 +01:00
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThanOrEqual(itemToRepair.upd?.Repairable?.MaxDurability);
|
2023-03-03 16:23:46 +01:00
|
|
|
});
|
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
it("updateItemDurability() repairkit with g36 with max dura degradation - Full repair", () =>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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;
|
2023-03-07 01:06:59 +01:00
|
|
|
const useDegradation = true;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, duraDifference, useRepairKit, 1, useDegradation);
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(100);
|
2023-03-07 01:06:59 +01:00
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThanOrEqual(itemToRepair.upd?.Repairable?.MaxDurability);
|
2023-03-03 16:23:46 +01:00
|
|
|
});
|
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
it("updateItemDurability() trader with g36 with max dura degradation - Full repair", () =>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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;
|
2023-03-07 01:06:59 +01:00
|
|
|
const useDegradation = true;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, duraDifference, useRepairKit, 1.2, useDegradation);
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(100);
|
2023-03-07 01:06:59 +01:00
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThanOrEqual(itemToRepair.upd?.Repairable?.MaxDurability);
|
2023-03-03 16:23:46 +01:00
|
|
|
});
|
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
it("updateItemDurability() faceshield broken use repairkit with max dura degradation", () =>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
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;
|
2023-03-07 01:06:59 +01:00
|
|
|
const useDegradation = true;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2023-03-07 01:06:59 +01:00
|
|
|
helper.updateItemDurability(itemToRepair, itemToRepairDetails, isArmor, 5, useRepairKit, 1, useDegradation);
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
expect(itemToRepair.upd?.FaceShield?.Hits).toBe(0);
|
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThan(45);
|
2023-03-07 01:06:59 +01:00
|
|
|
expect(itemToRepair.upd?.Repairable?.Durability).toBeLessThanOrEqual(itemToRepair.upd?.Repairable?.MaxDurability);
|
2023-03-03 16:23:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|