From dcbb5c1d5fda315f4b922799635547e837e9837a Mon Sep 17 00:00:00 2001 From: Jesse Date: Thu, 9 Jan 2025 21:25:53 +0100 Subject: [PATCH] Fix CI (#1056) - Removes a test for a class that was removed - Changes the command for type checking from `lint:types` to `type-check` --------- Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com> --- .github/workflows/run-types.yaml | 2 +- project/biome.jsonc | 9 ++- project/src/controllers/DialogueController.ts | 10 ++-- project/src/controllers/GameController.ts | 4 ++ project/src/controllers/HealthController.ts | 1 + project/src/controllers/HideoutController.ts | 1 + .../src/controllers/InventoryController.ts | 5 +- project/src/generators/BotWeaponGenerator.ts | 9 ++- project/src/generators/LootGenerator.ts | 4 +- .../src/generators/RagfairOfferGenerator.ts | 2 + .../RepeatableQuestRewardGenerator.ts | 10 ++-- .../src/generators/ScavCaseRewardGenerator.ts | 1 + project/src/helpers/HealthHelper.ts | 2 + project/src/helpers/HideoutHelper.ts | 5 ++ project/src/helpers/InRaidHelper.ts | 4 +- project/src/helpers/InventoryHelper.ts | 11 +++- project/src/helpers/ItemHelper.ts | 8 ++- project/src/helpers/QuestHelper.ts | 1 + .../models/eft/common/IEmptyRequestData.ts | 1 + .../IPlayerIncrementSkillLevelRequestData.ts | 23 -------- project/src/models/eft/profile/ISptProfile.ts | 3 + .../models/eft/ragfair/ISearchRequestData.ts | 4 +- .../services/BotEquipmentModPoolService.ts | 2 +- project/src/services/FenceService.ts | 9 ++- project/src/services/ItemFilterService.ts | 8 ++- project/src/services/MailSendService.ts | 3 + project/src/services/ProfileFixerService.ts | 50 ++++++++++------- project/src/services/RagfairOfferService.ts | 1 + project/src/services/RagfairTaxService.ts | 45 +++++++-------- .../ItemTplGenerator/ItemTplGenerator.ts | 12 ++-- .../utils/collections/queue/Queue.test.ts | 55 ------------------- 31 files changed, 150 insertions(+), 155 deletions(-) delete mode 100644 project/src/models/eft/player/IPlayerIncrementSkillLevelRequestData.ts delete mode 100644 project/tests/utils/collections/queue/Queue.test.ts diff --git a/.github/workflows/run-types.yaml b/.github/workflows/run-types.yaml index 9027b435..888a3c7c 100644 --- a/.github/workflows/run-types.yaml +++ b/.github/workflows/run-types.yaml @@ -38,5 +38,5 @@ jobs: working-directory: ./project - name: Run Type Check - run: npm run lint:types + run: npm run type-check working-directory: ./project diff --git a/project/biome.jsonc b/project/biome.jsonc index d3ab1259..427f6cbd 100644 --- a/project/biome.jsonc +++ b/project/biome.jsonc @@ -60,7 +60,14 @@ }, "overrides": [ { - "include": ["tests/*"] + "include": ["tests/*"], + "linter": { + "rules": { + "suspicious": { + "noExplicitAny": "off" + } + } + } } ] } diff --git a/project/src/controllers/DialogueController.ts b/project/src/controllers/DialogueController.ts index 5b663e50..e4a21561 100644 --- a/project/src/controllers/DialogueController.ts +++ b/project/src/controllers/DialogueController.ts @@ -83,10 +83,12 @@ export class DialogueController { // Add any friends the user has after the chatbots const profile = this.profileHelper.getFullProfile(sessionID); - for (const friendId of profile?.friends) { - const friendProfile = this.profileHelper.getChatRoomMemberFromSessionId(friendId); - if (friendProfile) { - friends.push(friendProfile); + if (profile?.friends) { + for (const friendId of profile.friends) { + const friendProfile = this.profileHelper.getChatRoomMemberFromSessionId(friendId); + if (friendProfile) { + friends.push(friendProfile); + } } } diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index 1047389a..76e8c526 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -256,6 +256,7 @@ export class GameController { // Hideout Improvement property changed name if ((fullProfile.characters.pmc.Hideout as any).Improvement) { fullProfile.characters.pmc.Hideout.Improvements = (fullProfile.characters.pmc.Hideout as any).Improvement; + // biome-ignore lint/performance/noDelete: Delete is fine here, as we're seeking to remove these entirely delete (fullProfile.characters.pmc.Hideout as any).Improvement; this.logger.warning(`Migration: Moved Hideout Improvement data to new property 'Improvements'`); } @@ -273,12 +274,14 @@ export class GameController { // Remove PMC 'ragfair' from trader list if (fullProfile.characters.pmc.TradersInfo.ragfair) { this.logger.warning("Migration: deleting: ragfair traderinfo object from PMC"); + // biome-ignore lint/performance/noDelete: Delete is fine here, as we're seeking to remove these entirely delete fullProfile.characters.pmc.TradersInfo.ragfair; } // Remove SCAV 'ragfair' from trader list if (fullProfile.characters.scav.TradersInfo.ragfair) { this.logger.warning("Migration: deleting: ragfair traderinfo object from PMC"); + // biome-ignore lint/performance/noDelete: Delete is fine here, as we're seeking to remove these entirely delete fullProfile.characters.scav.TradersInfo.ragfair; } @@ -561,6 +564,7 @@ export class GameController { protected checkForAndRemoveUndefinedDialogs(fullProfile: ISptProfile): void { const undefinedDialog = fullProfile.dialogues.undefined; if (undefinedDialog) { + // biome-ignore lint/performance/noDelete: Delete is fine here, as we're seeking to delete undefined dialogs. delete fullProfile.dialogues.undefined; } } diff --git a/project/src/controllers/HealthController.ts b/project/src/controllers/HealthController.ts index 61969477..6bd839af 100644 --- a/project/src/controllers/HealthController.ts +++ b/project/src/controllers/HealthController.ts @@ -250,6 +250,7 @@ export class HealthController { // Remove empty effect object if (Object.keys(pmcData.Health.BodyParts[bodyPartKey].Effects).length === 0) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the effect. delete pmcData.Health.BodyParts[bodyPartKey].Effects; } } diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index e0b8f3d3..f293503a 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -1229,6 +1229,7 @@ export class HideoutController { if (hasMildPain) { // Already has mild pain, remove mild and add severe + // biome-ignore lint/performance/noDelete: Deleting is fine here, we're removing the effect to replace it with another. delete pmcData.Health.BodyParts.Chest.Effects.MildMusclePain; pmcData.Health.BodyParts.Chest.Effects.SevereMusclePain = { diff --git a/project/src/controllers/InventoryController.ts b/project/src/controllers/InventoryController.ts index cbbf9b81..392a949c 100644 --- a/project/src/controllers/InventoryController.ts +++ b/project/src/controllers/InventoryController.ts @@ -282,7 +282,7 @@ export class InventoryController { // Remove FiR status from destination stack when source stack has no FiR but destination does if (!sourceItem.upd.SpawnedInSession && destinationItem.upd.SpawnedInSession) { - delete destinationItem.upd.SpawnedInSession; + destinationItem.upd.SpawnedInSession = false; } destinationItem.upd.StackObjectsCount += sourceItem.upd.StackObjectsCount; // Add source stackcount to destination @@ -408,6 +408,7 @@ export class InventoryController { if (request.to.location) { itemOne.location = request.to.location; } else { + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the location. delete itemOne.location; } @@ -416,6 +417,7 @@ export class InventoryController { if (request.to2.location) { itemTwo.location = request.to2.location; } else { + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the location. delete itemTwo.location; } @@ -721,6 +723,7 @@ export class InventoryController { if (change.location) { inventoryItem.location = change.location; } else { + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the location. delete inventoryItem.location; } } diff --git a/project/src/generators/BotWeaponGenerator.ts b/project/src/generators/BotWeaponGenerator.ts index 2ac057e3..6c8ea9a0 100644 --- a/project/src/generators/BotWeaponGenerator.ts +++ b/project/src/generators/BotWeaponGenerator.ts @@ -571,9 +571,12 @@ export class BotWeaponGenerator { } // Inner join the weapons allowed + passed in cartridge pool to get compatible cartridges - const compatibleCartridges = Object.keys(cartridgePoolForWeapon) - .filter((cartridge) => compatibleCartridgesInTemplate.includes(cartridge)) - .reduce((acc, key) => ({ ...acc, [key]: cartridgePoolForWeapon[key] }), {}); + const compatibleCartridges = {}; + for (const cartridge of Object.keys(cartridgePoolForWeapon)) { + if (compatibleCartridgesInTemplate.includes(cartridge)) { + compatibleCartridges[cartridge] = cartridgePoolForWeapon[cartridge]; + } + } if (!compatibleCartridges) { // No compatible cartridges, use default diff --git a/project/src/generators/LootGenerator.ts b/project/src/generators/LootGenerator.ts index 96d8de5e..1ce8677a 100644 --- a/project/src/generators/LootGenerator.ts +++ b/project/src/generators/LootGenerator.ts @@ -397,9 +397,9 @@ export class LootGenerator { const presetAndMods: IItem[] = this.itemHelper.replaceIDs(chosenPreset._items); this.itemHelper.remapRootItemId(presetAndMods); // Add chosen preset tpl to result array - presetAndMods.forEach((item) => { + for (const item of presetAndMods) { result.push(item); - }); + } if (itemLimitCount) { // Increment item count as item has been chosen and its inside itemLimitCount dictionary diff --git a/project/src/generators/RagfairOfferGenerator.ts b/project/src/generators/RagfairOfferGenerator.ts index 86e37062..4e8c8cad 100644 --- a/project/src/generators/RagfairOfferGenerator.ts +++ b/project/src/generators/RagfairOfferGenerator.ts @@ -403,7 +403,9 @@ export class RagfairOfferGenerator { this.itemHelper.reparentItemAndChildren(clonedAssort[0], clonedAssort); // Clear unnecessary properties + // biome-ignore lint/performance/noDelete: Deleting is fine here, we're getting rid of unecessary properties. delete clonedAssort[0].parentId; + // biome-ignore lint/performance/noDelete: Deleting is fine here, we're getting rid of unecessary properties. delete clonedAssort[0].slotId; assortSingleOfferProcesses.push( diff --git a/project/src/generators/RepeatableQuestRewardGenerator.ts b/project/src/generators/RepeatableQuestRewardGenerator.ts index ac667de3..22c6244d 100644 --- a/project/src/generators/RepeatableQuestRewardGenerator.ts +++ b/project/src/generators/RepeatableQuestRewardGenerator.ts @@ -309,20 +309,22 @@ export class RepeatableQuestRewardGenerator { itemsToReturn.push({ item: chosenItemFromPool, stackSize: rewardItemStackCount }); const itemCost = this.presetHelper.getDefaultPresetOrItemPrice(chosenItemFromPool._id); - itemRewardBudget -= rewardItemStackCount * itemCost; + const calculatedItemRewardBudget = itemRewardBudget - rewardItemStackCount * itemCost; this.logger.debug(`Added item: ${chosenItemFromPool._id} with price: ${rewardItemStackCount * itemCost}`); // If we still have budget narrow down possible items - if (itemRewardBudget > 0) { + if (calculatedItemRewardBudget > 0) { // Filter possible reward items to only items with a price below the remaining budget exhausableItemPool = new ExhaustableArray( - this.filterRewardPoolWithinBudget(itemPool, itemRewardBudget, 0), + this.filterRewardPoolWithinBudget(itemPool, calculatedItemRewardBudget, 0), this.randomUtil, this.cloner, ); if (!exhausableItemPool.hasValues()) { - this.logger.debug(`Reward pool empty with: ${itemRewardBudget} roubles of budget remaining`); + this.logger.debug( + `Reward pool empty with: ${calculatedItemRewardBudget} roubles of budget remaining`, + ); break; // No reward items left, exit } } diff --git a/project/src/generators/ScavCaseRewardGenerator.ts b/project/src/generators/ScavCaseRewardGenerator.ts index 180a27ec..9e0d8419 100644 --- a/project/src/generators/ScavCaseRewardGenerator.ts +++ b/project/src/generators/ScavCaseRewardGenerator.ts @@ -321,6 +321,7 @@ export class ScavCaseRewardGenerator { // Clean up upd object if it wasn't used if (!rootItem.upd) { + // biome-ignore lint/performance/noDelete: Delete is fine here, we're cleaning up this object without leaving an undefined. delete rootItem.upd; } diff --git a/project/src/helpers/HealthHelper.ts b/project/src/helpers/HealthHelper.ts index 7c23fff6..9be393f1 100644 --- a/project/src/helpers/HealthHelper.ts +++ b/project/src/helpers/HealthHelper.ts @@ -293,6 +293,7 @@ export class HealthHelper { for (const bodyPart in bodyPartsWithEffects) { // clear effects from profile bodyPart if (deleteExistingEffects) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the effect. delete pmcData.Health.BodyParts[bodyPart].Effects; } @@ -339,6 +340,7 @@ export class HealthHelper { // Delete empty property to prevent client bugs if (this.isEmpty(profileBodyPart.Effects)) { + // biome-ignore lint/performance/noDelete: Delete is fine here, we're removing an empty property to prevent game bugs. delete profileBodyPart.Effects; } } diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 8eb921ed..aca94f4c 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -180,8 +180,11 @@ export class HideoutHelper { break; case BonusType.TEXT_BONUS: // Delete values before they're added to profile + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the data. delete bonus.passive; + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the data. delete bonus.production; + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the data. delete bonus.visible; break; } @@ -781,6 +784,7 @@ export class HideoutHelper { } // Filter ran out / used up + // biome-ignore lint/performance/noDelete: Delete is fine here, as we're seeking to entirely delete the water filter. delete waterFilterArea.slots[i].item; // Update remaining resources to be subtracted filterDrainRate = Math.abs(resourceValue); @@ -919,6 +923,7 @@ export class HideoutHelper { break; // Break here to avoid updating all filters } + // biome-ignore lint/performance/noDelete: Delete is fine here, as we're seeking to entirely delete the air filter. delete airFilterArea.slots[i].item; // Update remaining resources to be subtracted filterDrainRate = Math.abs(resourceValue); diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index c4e6b67a..63a87059 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -118,7 +118,9 @@ export class InRaidHelper { }); for (const item of itemsToRemovePropertyFrom) { - delete item.upd.SpawnedInSession; + if (item.upd) { + item.upd.SpawnedInSession = false; + } } } diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index 93302d03..b3c059b0 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -177,10 +177,14 @@ export class InventoryHelper { // Ensure item has upd object this.itemHelper.addUpdObjectToItem(item); + if (!item.upd) { + item.upd = {}; + } + if (foundInRaid) { item.upd.SpawnedInSession = foundInRaid; } else { - delete item.upd.SpawnedInSession; + item.upd.SpawnedInSession = false; } } } @@ -191,14 +195,17 @@ export class InventoryHelper { */ protected removeTraderRagfairRelatedUpdProperties(upd: IUpd): void { if (upd.UnlimitedCount !== undefined) { + // biome-ignore lint/performance/noDelete: Delete is fine here since we're attempting to remove this fully here. delete upd.UnlimitedCount; } if (upd.BuyRestrictionCurrent !== undefined) { + // biome-ignore lint/performance/noDelete: Delete is fine here since we're attempting to remove this fully here. delete upd.BuyRestrictionCurrent; } if (upd.BuyRestrictionMax !== undefined) { + // biome-ignore lint/performance/noDelete: Delete is fine here since we're attempting to remove this fully here. delete upd.BuyRestrictionMax; } } @@ -997,6 +1004,7 @@ export class InventoryHelper { } else { // No location in request, delete it if (itemToMove.location) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the entire data property. delete itemToMove.location; } } @@ -1059,6 +1067,7 @@ export class InventoryHelper { } else { // Moved from slot with location to one without, clean up if (matchingInventoryItem.location) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the entire data property. delete matchingInventoryItem.location; } } diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index c56eb431..107e9e53 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1194,6 +1194,7 @@ export class ItemHelper { // In live no ammo box has the first cartridge item with a location if (location === 0) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the location. delete cartridgeItemToAdd.location; } @@ -1366,6 +1367,7 @@ export class ItemHelper { // Only one cartridge stack added, remove location property as its only used for 2 or more stacks if (location === 1) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the location. delete magazineWithChildCartridges[1].location; } } @@ -1706,6 +1708,7 @@ export class ItemHelper { if (!parentExists && item.parentId !== rootId && item.slotId !== "hideout") { item.parentId = rootId; item.slotId = "hideout"; + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the location. delete item.location; } } @@ -1800,7 +1803,10 @@ export class ItemHelper { */ public removeSpawnedInSessionPropertyFromItems(items: IItem[]): void { for (const item of items) { - delete item.upd.SpawnedInSession; + if (item.upd) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we're removing the entire property. + delete item.upd.SpawnedInSession; + } } } } diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index f378d8e5..40a380ab 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -253,6 +253,7 @@ export class QuestHelper { existingQuest.completedConditions = []; if (existingQuest.availableAfter) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the entire data property. delete existingQuest.availableAfter; } diff --git a/project/src/models/eft/common/IEmptyRequestData.ts b/project/src/models/eft/common/IEmptyRequestData.ts index 52a7b126..86455219 100644 --- a/project/src/models/eft/common/IEmptyRequestData.ts +++ b/project/src/models/eft/common/IEmptyRequestData.ts @@ -1 +1,2 @@ +// biome-ignore lint/complexity/noBannedTypes: Empty request is empty, this is fine. export type IEmptyRequestData = {}; diff --git a/project/src/models/eft/player/IPlayerIncrementSkillLevelRequestData.ts b/project/src/models/eft/player/IPlayerIncrementSkillLevelRequestData.ts deleted file mode 100644 index 4c5bbfcc..00000000 --- a/project/src/models/eft/player/IPlayerIncrementSkillLevelRequestData.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ISkills } from "@spt/models/eft/common/tables/IBotBase"; - -export interface IPlayerIncrementSkillLevelRequestData { - _id: string; - experience: number; - quests: any[]; - ragFairOffers: any[]; - builds: any[]; - items: Items; - production: Production; - skills: ISkills; - traderRelations: TraderRelations; -} - -export interface Items { - new: any[]; - change: any[]; - del: any[]; -} - -export type Production = {}; - -export type TraderRelations = {}; diff --git a/project/src/models/eft/profile/ISptProfile.ts b/project/src/models/eft/profile/ISptProfile.ts index 9bbf4516..da2b8183 100644 --- a/project/src/models/eft/profile/ISptProfile.ts +++ b/project/src/models/eft/profile/ISptProfile.ts @@ -227,10 +227,13 @@ export interface IEffects { RightLeg: IRightLeg; } +// biome-ignore lint/complexity/noBannedTypes: Not sure of typing on these for now. export type IHead = {}; +// biome-ignore lint/complexity/noBannedTypes: Not sure of typing on these for now. export type IChest = {}; +// biome-ignore lint/complexity/noBannedTypes: Not sure of typing on these for now. export type IStomach = {}; export interface ILeftArm { diff --git a/project/src/models/eft/ragfair/ISearchRequestData.ts b/project/src/models/eft/ragfair/ISearchRequestData.ts index ff3d22a2..046edf67 100644 --- a/project/src/models/eft/ragfair/ISearchRequestData.ts +++ b/project/src/models/eft/ragfair/ISearchRequestData.ts @@ -20,7 +20,7 @@ export interface ISearchRequestData { handbookId: string; linkedSearchId: string; neededSearchId: string; - buildItems: BuildItems; + buildItems: Record; buildCount: number; tm: number; reload: number; @@ -31,5 +31,3 @@ export enum OfferOwnerType { TRADEROWNERTYPE = 1, PLAYEROWNERTYPE = 2, } - -export type BuildItems = {}; diff --git a/project/src/services/BotEquipmentModPoolService.ts b/project/src/services/BotEquipmentModPoolService.ts index 95b8a129..fbf8a0ac 100644 --- a/project/src/services/BotEquipmentModPoolService.ts +++ b/project/src/services/BotEquipmentModPoolService.ts @@ -82,7 +82,7 @@ export class BotEquipmentModPoolService { // Check item added into array for slots, need to iterate over those const subItemDetails = this.itemHelper.getItem(itemToAdd)[1]; - const hasSubItemsToAdd = subItemDetails?._props?.Slots?.length ?? 0 > 0; + const hasSubItemsToAdd = (subItemDetails?._props?.Slots?.length ?? 0) > 0; if (hasSubItemsToAdd && !pool[subItemDetails._id]) { // Recursive call this.generatePool([subItemDetails], poolType); diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index d7dd0523..5e698a8a 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -165,6 +165,7 @@ export class FenceService { } // Clean up the items + // biome-ignore lint/performance/noDelete: Delete is fine here as we're getting rid of the items before updating. delete root.location; const createAssort: ICreateFenceAssortsResult = { sptItems: [], barter_scheme: {}, loyal_level_items: {} }; @@ -1115,6 +1116,8 @@ export class FenceService { continue; } + let armorWithMods = armorItemAndMods; + const modItemDbDetails = this.itemHelper.getItem(plateTpl)[1]; // Chance to remove plate @@ -1122,7 +1125,7 @@ export class FenceService { this.traderConfig.fence.chancePlateExistsInArmorPercent[modItemDbDetails._props?.armorClass ?? "3"]; if (!this.randomUtil.getChance100(plateExistsChance)) { // Remove plate from armor - armorItemAndMods = armorItemAndMods.filter( + armorWithMods = armorItemAndMods.filter( (item) => item.slotId.toLowerCase() !== plateSlot._name.toLowerCase(), ); @@ -1135,13 +1138,13 @@ export class FenceService { ); // Find items mod to apply dura changes to - const modItemToAdjust = armorItemAndMods.find( + const modItemToAdjust = armorWithMods.find( (mod) => mod.slotId.toLowerCase() === plateSlot._name.toLowerCase(), ); if (!modItemToAdjust) { this.logger.warning( - `Unable to randomise armor items ${armorItemAndMods[0]._tpl} ${plateSlot._name} slot as it cannot be found, skipping`, + `Unable to randomise armor items ${armorWithMods[0]._tpl} ${plateSlot._name} slot as it cannot be found, skipping`, ); continue; } diff --git a/project/src/services/ItemFilterService.ts b/project/src/services/ItemFilterService.ts index 35f0199c..125cb7ee 100644 --- a/project/src/services/ItemFilterService.ts +++ b/project/src/services/ItemFilterService.ts @@ -29,7 +29,9 @@ export class ItemFilterService { */ public isItemBlacklisted(tpl: string): boolean { if (this.itemBlacklistCache.size === 0) { - this.itemConfig.blacklist.forEach((item) => this.itemBlacklistCache.add(item)); + for (const item of this.itemConfig.blacklist) { + this.itemBlacklistCache.add(item); + } } return this.itemBlacklistCache.has(tpl); @@ -42,7 +44,9 @@ export class ItemFilterService { */ public isLootableItemBlacklisted(tpl: string): boolean { if (this.lootableItemBlacklistCache.size === 0) { - this.itemConfig.lootableItemBlacklist.forEach((item) => this.itemBlacklistCache.add(item)); + for (const item of this.itemConfig.lootableItemBlacklist) { + this.itemBlacklistCache.add(item); + } } return this.lootableItemBlacklistCache.has(tpl); diff --git a/project/src/services/MailSendService.ts b/project/src/services/MailSendService.ts index 4fba93ee..cddf662f 100644 --- a/project/src/services/MailSendService.ts +++ b/project/src/services/MailSendService.ts @@ -350,11 +350,13 @@ export class MailSendService { // Clean up empty system data if (!message.systemData) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the entire data property. delete message.systemData; } // Clean up empty template id if (!message.templateId) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the entire data property. delete message.templateId; } @@ -458,6 +460,7 @@ export class MailSendService { // Remove empty data property if no rewards if (itemsToSendToPlayer.data.length === 0) { + // biome-ignore lint/performance/noDelete: Delete is fine here as we're trying to remove the empty data property. delete itemsToSendToPlayer.data; } } diff --git a/project/src/services/ProfileFixerService.ts b/project/src/services/ProfileFixerService.ts index 6fb356a5..098bf473 100644 --- a/project/src/services/ProfileFixerService.ts +++ b/project/src/services/ProfileFixerService.ts @@ -83,25 +83,27 @@ export class ProfileFixerService { */ public checkForAndFixDialogueAttachments(fullProfile: ISptProfile): void { for (const traderDialogues of Object.values(fullProfile.dialogues)) { - for (const message of traderDialogues?.messages) { - // Skip any messages without attached items - if (!message.items?.data || !message.items?.stash) { - continue; - } + if (traderDialogues?.messages) { + for (const message of traderDialogues.messages) { + // Skip any messages without attached items + if (!message.items?.data || !message.items?.stash) { + continue; + } - // Skip any messages that don't have a stashId collision with the player's equipment ID - if (message.items?.stash !== fullProfile.characters?.pmc?.Inventory?.equipment) { - continue; - } + // Skip any messages that don't have a stashId collision with the player's equipment ID + if (message.items?.stash !== fullProfile.characters?.pmc?.Inventory?.equipment) { + continue; + } - // Otherwise we need to generate a new unique stash ID for this message's attachments - message.items.stash = this.hashUtil.generate(); - message.items.data = this.itemHelper.adoptOrphanedItems(message.items.stash, message.items.data); + // Otherwise we need to generate a new unique stash ID for this message's attachments + message.items.stash = this.hashUtil.generate(); + message.items.data = this.itemHelper.adoptOrphanedItems(message.items.stash, message.items.data); - // Because `adoptOrphanedItems` sets the slotId to `hideout`, we need to re-set it to `main` to work with mail - for (const item of message.items.data) { - if (item.slotId === "hideout") { - item.slotId = "main"; + // Because `adoptOrphanedItems` sets the slotId to `hideout`, we need to re-set it to `main` to work with mail + for (const item of message.items.data) { + if (item.slotId === "hideout") { + item.slotId = "main"; + } } } } @@ -325,15 +327,25 @@ export class ProfileFixerService { const productionRewards = quest.rewards.Started?.filter( (reward) => reward.type === QuestRewardType.PRODUCTIONS_SCHEME, ); - productionRewards?.forEach((reward) => this.verifyQuestProductionUnlock(pmcProfile, reward, quest)); + + if (productionRewards) { + for (const reward of productionRewards) { + this.verifyQuestProductionUnlock(pmcProfile, reward, quest); + } + } } // For successful quests, check for unlocks in the `Success` rewards - if (profileQuest.status == QuestStatus.Success) { + if (profileQuest.status === QuestStatus.Success) { const productionRewards = quest.rewards.Success?.filter( (reward) => reward.type === QuestRewardType.PRODUCTIONS_SCHEME, ); - productionRewards?.forEach((reward) => this.verifyQuestProductionUnlock(pmcProfile, reward, quest)); + + if (productionRewards) { + for (const reward of productionRewards) { + this.verifyQuestProductionUnlock(pmcProfile, reward, quest); + } + } } } diff --git a/project/src/services/RagfairOfferService.ts b/project/src/services/RagfairOfferService.ts index 27409da4..96432167 100644 --- a/project/src/services/RagfairOfferService.ts +++ b/project/src/services/RagfairOfferService.ts @@ -250,6 +250,7 @@ export class RagfairOfferService { if (firstOfferItem.upd.StackObjectsCount > firstOfferItem.upd.OriginalStackObjectsCount) { playerOffer.items[0].upd.StackObjectsCount = firstOfferItem.upd.OriginalStackObjectsCount; } + // biome-ignore lint/performance/noDelete: Delete is fine here as we entirely want to get rid of the data. delete playerOffer.items[0].upd.OriginalStackObjectsCount; // Remove player offer from flea this.ragfairOfferHandler.removeOffer(playerOffer); diff --git a/project/src/services/RagfairTaxService.ts b/project/src/services/RagfairTaxService.ts index 9371b74e..a8ee44b4 100644 --- a/project/src/services/RagfairTaxService.ts +++ b/project/src/services/RagfairTaxService.ts @@ -68,7 +68,7 @@ export class RagfairTaxService { const requirementsPrice = requirementsValue * (sellInOnePiece ? 1 : offerItemCount); const itemTaxMult = globals.config.RagFair.communityItemTax / 100.0; - const requirementTaxMult = globals!.config.RagFair.communityRequirementTax / 100.0; + const requirementTaxMult = globals.config.RagFair.communityRequirementTax / 100.0; let itemPriceMult = Math.log10(itemWorth / requirementsPrice); let requirementPriceMult = Math.log10(requirementsPrice / itemWorth); @@ -144,39 +144,34 @@ export class RagfairTaxService { } } - if ("Dogtag" in item.upd!) { - worth *= item.upd!.Dogtag!.Level; - } + const upd = item.upd ?? {}; - if ("Key" in item.upd! && (itemTemplate._props.MaximumNumberOfUsage ?? 0) > 0) { + if (upd.Dogtag) { + worth *= upd.Dogtag.Level; + } + if (upd.Key && (itemTemplate._props?.MaximumNumberOfUsage ?? 0) > 0) { worth = - (worth / itemTemplate._props.MaximumNumberOfUsage!) * - (itemTemplate._props.MaximumNumberOfUsage! - item.upd!.Key!.NumberOfUsages); + (worth / (itemTemplate._props?.MaximumNumberOfUsage ?? 1)) * + ((itemTemplate._props?.MaximumNumberOfUsage ?? 1) - upd.Key.NumberOfUsages); } - - if ("Resource" in item.upd! && itemTemplate._props.MaxResource! > 0) { - worth = worth * 0.1 + ((worth * 0.9) / itemTemplate._props.MaxResource!) * item.upd.Resource!.Value; + if (upd.Resource && (itemTemplate._props?.MaxResource ?? 0) > 0) { + worth = worth * 0.1 + ((worth * 0.9) / (itemTemplate._props?.MaxResource ?? 1)) * upd.Resource.Value; } - - if ("SideEffect" in item.upd! && itemTemplate._props.MaxResource! > 0) { - worth = worth * 0.1 + ((worth * 0.9) / itemTemplate._props.MaxResource!) * item.upd.SideEffect!.Value; + if (upd.SideEffect && (itemTemplate._props?.MaxResource ?? 0) > 0) { + worth = worth * 0.1 + ((worth * 0.9) / (itemTemplate._props?.MaxResource ?? 1)) * upd.SideEffect.Value; } - - if ("MedKit" in item.upd! && itemTemplate._props.MaxHpResource! > 0) { - worth = (worth / itemTemplate._props.MaxHpResource!) * item.upd.MedKit!.HpResource; + if (upd.MedKit && (itemTemplate._props?.MaxHpResource ?? 0) > 0) { + worth = (worth / (itemTemplate._props?.MaxHpResource ?? 1)) * upd.MedKit.HpResource; } - - if ("FoodDrink" in item.upd! && itemTemplate._props.MaxResource! > 0) { - worth = (worth / itemTemplate._props.MaxResource!) * item.upd.FoodDrink!.HpPercent; + if (upd.FoodDrink && (itemTemplate._props?.MaxResource ?? 0) > 0) { + worth = (worth / (itemTemplate._props?.MaxResource ?? 1)) * upd.FoodDrink.HpPercent; } - - if ("Repairable" in item.upd! && itemTemplate._props.armorClass > 0) { - const num2 = 0.01 * 0.0 ** item.upd.Repairable!.MaxDurability; + if (upd.Repairable && Number(itemTemplate._props?.armorClass ?? 0) > 0) { + const num2 = 0.01 * 0.0 ** upd.Repairable.MaxDurability; worth = - worth * (item.upd.Repairable!.MaxDurability / itemTemplate._props.Durability! - num2) - + worth * (upd.Repairable.MaxDurability / (itemTemplate._props?.Durability ?? 1) - num2) - Math.floor( - itemTemplate._props.RepairCost! * - (item.upd.Repairable!.MaxDurability - item.upd.Repairable!.Durability), + (itemTemplate._props?.RepairCost ?? 0) * (upd.Repairable.MaxDurability - upd.Repairable.Durability), ); } diff --git a/project/src/tools/ItemTplGenerator/ItemTplGenerator.ts b/project/src/tools/ItemTplGenerator/ItemTplGenerator.ts index 085d7759..6893d635 100644 --- a/project/src/tools/ItemTplGenerator/ItemTplGenerator.ts +++ b/project/src/tools/ItemTplGenerator/ItemTplGenerator.ts @@ -350,14 +350,16 @@ export class ItemTplGenerator { } private cleanCaliber(ammoCaliber: string): string { - ammoCaliber = ammoCaliber.replace("CALIBER", ""); - ammoCaliber = ammoCaliber.replace("PARA", ""); - ammoCaliber = ammoCaliber.replace("NATO", ""); + let ammoCaliberToClean = ammoCaliber; + + ammoCaliberToClean = ammoCaliberToClean.replace("CALIBER", ""); + ammoCaliberToClean = ammoCaliberToClean.replace("PARA", ""); + ammoCaliberToClean = ammoCaliberToClean.replace("NATO", ""); // Special case for 45ACP - ammoCaliber = ammoCaliber.replace("1143X23ACP", "45ACP"); + ammoCaliberToClean = ammoCaliberToClean.replace("1143X23ACP", "45ACP"); - return ammoCaliber; + return ammoCaliberToClean; } private getAmmoBoxPrefix(item: ITemplateItem): string { diff --git a/project/tests/utils/collections/queue/Queue.test.ts b/project/tests/utils/collections/queue/Queue.test.ts deleted file mode 100644 index 02688880..00000000 --- a/project/tests/utils/collections/queue/Queue.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -import "reflect-metadata"; -import { Queue } from "@spt/utils/collections/queue/Queue"; -import { describe, expect, it } from "vitest"; - -describe("LinkedList", () => { - describe("enqueue", () => { - const queue = new Queue(); - queue.enqueue(420); - queue.enqueue(69); - queue.enqueue(8008135); - queue.enqueue(1337); - - it("adds elements to the end of the queue", () => { - expect(queue.peek()).toEqual(420); - expect(queue.length).toEqual(4); - }); - }); - - describe("enqueueAll", () => { - const queue = new Queue(); - queue.enqueueAll([420, 69, 8008135, 1337]); - - it("iterates the array and adds each element to the end of the queue", () => { - expect(queue.peek()).toEqual(420); - expect(queue.length).toEqual(4); - }); - }); - - describe("dequeue", () => { - const queue = new Queue(); - queue.enqueueAll([420, 69, 8008135, 1337]); - - it("removes the first element and return it's value", () => { - expect(queue.dequeue()).toEqual(420); - expect(queue.peek()).toEqual(69); - expect(queue.length).toEqual(3); - - expect(queue.dequeue()).toEqual(69); - expect(queue.peek()).toEqual(8008135); - expect(queue.length).toEqual(2); - - expect(queue.dequeue()).toEqual(8008135); - expect(queue.peek()).toEqual(1337); - expect(queue.length).toEqual(1); - - expect(queue.dequeue()).toEqual(1337); - expect(queue.peek()).toEqual(undefined); - expect(queue.length).toEqual(0); - - expect(queue.dequeue()).toEqual(undefined); - expect(queue.peek()).toEqual(undefined); - expect(queue.length).toEqual(0); - }); - }); -});