From 7d6721d47bf02b0ec98fb8e7e347f16d6ae3192b Mon Sep 17 00:00:00 2001 From: CWX Date: Sat, 6 Jul 2024 09:17:32 +0100 Subject: [PATCH] update comment for airdrop enum, allow airdrop loot to work --- project/src/callbacks/LocationCallbacks.ts | 2 +- project/src/controllers/LocationController.ts | 12 +-- project/src/controllers/MatchController.ts | 9 +- project/src/generators/LootGenerator.ts | 87 +++++++++++++++---- project/src/models/enums/AirdropType.ts | 10 +-- .../src/models/spt/services/LootRequest.ts | 2 + 6 files changed, 87 insertions(+), 35 deletions(-) diff --git a/project/src/callbacks/LocationCallbacks.ts b/project/src/callbacks/LocationCallbacks.ts index 77666cd7..cfbccffa 100644 --- a/project/src/callbacks/LocationCallbacks.ts +++ b/project/src/callbacks/LocationCallbacks.ts @@ -36,7 +36,7 @@ export class LocationCallbacks return this.httpResponse.getBody(this.locationController.get(sessionID, info)); } - /** Handle client/location/getAirdropLoot */ + /** Handle client/airdrop/loot */ public getAirdropLoot(url: string, info: IEmptyRequestData, sessionID: string): any { return this.httpResponse.getBody(this.locationController.getAirdropLoot()); diff --git a/project/src/controllers/LocationController.ts b/project/src/controllers/LocationController.ts index 25b0f7c1..f9826c98 100644 --- a/project/src/controllers/LocationController.ts +++ b/project/src/controllers/LocationController.ts @@ -11,7 +11,7 @@ import { IAirdropLootResult } from "@spt/models/eft/location/IAirdropLootResult" import { IGetLocationRequestData } from "@spt/models/eft/location/IGetLocationRequestData"; import { AirdropTypeEnum } from "@spt/models/enums/AirdropType"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; -import { IAirdropConfig } from "@spt/models/spt/config/IAirdropConfig"; +import { AirdropLoot, IAirdropConfig } from "@spt/models/spt/config/IAirdropConfig"; import { ILocationConfig } from "@spt/models/spt/config/ILocationConfig"; import { IRaidChanges } from "@spt/models/spt/location/IRaidChanges"; import { ILocations } from "@spt/models/spt/server/ILocations"; @@ -171,15 +171,14 @@ export class LocationController * Generates it randomly based on config/airdrop.json values * @returns Array of LootItem objects */ - public getAirdropLoot(): IAirdropLootResult + public getAirdropLoot(): any // TODO: need to fix { const airdropType = this.chooseAirdropType(); - this.logger.debug(`Chose ${airdropType} for airdrop loot`); const airdropConfig = this.getAirdropLootConfigByType(airdropType); - return { dropType: airdropType, loot: this.lootGenerator.createRandomLoot(airdropConfig) }; + return { icon: airdropType, container: this.lootGenerator.createRandomLoot(airdropConfig) }; } /** @@ -200,16 +199,17 @@ export class LocationController */ protected getAirdropLootConfigByType(airdropType: AirdropTypeEnum): LootRequest { - let lootSettingsByType = this.airdropConfig.loot[airdropType]; + let lootSettingsByType: AirdropLoot = this.airdropConfig.loot[airdropType]; if (!lootSettingsByType) { this.logger.error( this.localisationService.getText("location-unable_to_find_airdrop_drop_config_of_type", airdropType), ); - lootSettingsByType = this.airdropConfig.loot[AirdropTypeEnum.MIXED]; + lootSettingsByType = this.airdropConfig.loot[AirdropTypeEnum.COMMON]; } return { + airdropLoot: airdropType, weaponPresetCount: lootSettingsByType.weaponPresetCount, armorPresetCount: lootSettingsByType.armorPresetCount, itemCount: lootSettingsByType.itemCount, diff --git a/project/src/controllers/MatchController.ts b/project/src/controllers/MatchController.ts index 8e6ea31b..e9a77c40 100644 --- a/project/src/controllers/MatchController.ts +++ b/project/src/controllers/MatchController.ts @@ -228,13 +228,8 @@ export class MatchController const parentId = this.hashUtil.generate(); for (const item of loot) { - mailableLoot.push({ - _id: item.id, - _tpl: item.tpl, - slotId: "main", - parentId: parentId, - upd: { StackObjectsCount: item.stackCount, SpawnedInSession: true }, - }); + item.parentId = parentId; + mailableLoot.push(item); } // Send message from fence giving player reward generated above diff --git a/project/src/generators/LootGenerator.ts b/project/src/generators/LootGenerator.ts index dce16de2..d368d90b 100644 --- a/project/src/generators/LootGenerator.ts +++ b/project/src/generators/LootGenerator.ts @@ -17,6 +17,8 @@ import { LocalisationService } from "@spt/services/LocalisationService"; import { RagfairLinkedItemService } from "@spt/services/RagfairLinkedItemService"; import { HashUtil } from "@spt/utils/HashUtil"; import { RandomUtil } from "@spt/utils/RandomUtil"; +import { AirdropTypeEnum } from "@spt/models/enums/AirdropType"; +import { ItemTpl } from "@spt/models/enums/ItemTpl"; type ItemLimit = { current: number, max: number }; @@ -43,9 +45,41 @@ export class LootGenerator * @param options parameters to adjust how loot is generated * @returns An array of loot items */ - public createRandomLoot(options: LootRequest): LootItem[] + public createRandomLoot(options: LootRequest): Item[] { - const result: LootItem[] = []; + const result: Item[] = []; + let airdropContainerParentID = ""; + + if (options.airdropLoot) + { + airdropContainerParentID = this.hashUtil.generate(); + let airdropContainer = { + _id: airdropContainerParentID, + _tpl: "", + upd: { + SpawnedInSession: true, + StackObjectsCount: 1 + } + } + + switch (options.airdropLoot) { + case AirdropTypeEnum.MEDICAL: + airdropContainer._tpl = ItemTpl.LOOTCONTAINER_AIRDROP_MEDICAL_CRATE + break; + case AirdropTypeEnum.SUPPLY: + airdropContainer._tpl = ItemTpl.LOOTCONTAINER_AIRDROP_SUPPLY_CRATE + break; + case AirdropTypeEnum.WEAPON: + airdropContainer._tpl = ItemTpl.LOOTCONTAINER_AIRDROP_WEAPON_CRATE + break; + case AirdropTypeEnum.COMMON: + default: + airdropContainer._tpl = ItemTpl.LOOTCONTAINER_AIRDROP_COMMON_SUPPLY_CRATE + break; + } + + result.push(airdropContainer); + } const itemTypeCounts = this.initItemLimitCounter(options.itemLimits); @@ -86,10 +120,12 @@ export class LootGenerator // Choose one at random + add to results array const chosenSealedContainer = this.randomUtil.getArrayValue(sealedWeaponContainerPool); result.push({ - id: this.hashUtil.generate(), - tpl: chosenSealedContainer._id, - isPreset: false, - stackCount: 1, + _id: this.hashUtil.generate(), + _tpl: chosenSealedContainer._id, + upd: { + StackObjectsCount: 1, + SpawnedInSession: true + } }); } } @@ -185,6 +221,19 @@ export class LootGenerator } } + for (const item of result) { + if (item._id == airdropContainerParentID) + { + continue; + } + + if (!item.parentId) + { + item.parentId = airdropContainerParentID; + item.slotId = "main" + } + } + return result; } @@ -242,7 +291,7 @@ export class LootGenerator items: [string, ITemplateItem][], itemTypeCounts: Record, options: LootRequest, - result: LootItem[], + result: Item[], ): boolean { const randomItem = this.randomUtil.getArrayValue(items)[1]; @@ -259,20 +308,22 @@ export class LootGenerator return false; } - const newLootItem: LootItem = { - id: this.hashUtil.generate(), - tpl: randomItem._id, - isPreset: false, - stackCount: 1, + const newLootItem: Item = { + _id: this.hashUtil.generate(), + _tpl: randomItem._id, + upd: { + StackObjectsCount: 1, + SpawnedInSession: true + } }; // Special case - handle items that need a stackcount > 1 if (randomItem._props.StackMaxSize > 1) { - newLootItem.stackCount = this.getRandomisedStackCount(randomItem, options); + newLootItem.upd.StackObjectsCount = this.getRandomisedStackCount(randomItem, options); } - newLootItem.tpl = randomItem._id; + newLootItem._tpl = randomItem._id; result.push(newLootItem); if (itemLimitCount) @@ -317,7 +368,7 @@ export class LootGenerator presetPool: IPreset[], itemTypeCounts: Record, itemBlacklist: string[], - result: LootItem[], + result: Item[], ): boolean { // Choose random preset and get details from item db using encyclopedia value (encyclopedia === tplId) @@ -367,8 +418,12 @@ export class LootGenerator return false; } + const presetAndMods: Item[] = this.itemHelper.replaceIDs(chosenPreset._items); + this.itemHelper.remapRootItemId(presetAndMods); // Add chosen preset tpl to result array - result.push({ tpl: chosenPreset._items[0]._tpl, isPreset: true, stackCount: 1 }); + presetAndMods.forEach(item => { + result.push(item) + }); if (itemLimitCount) { diff --git a/project/src/models/enums/AirdropType.ts b/project/src/models/enums/AirdropType.ts index e1a54b67..916a3001 100644 --- a/project/src/models/enums/AirdropType.ts +++ b/project/src/models/enums/AirdropType.ts @@ -1,7 +1,7 @@ export enum AirdropTypeEnum { - MIXED = "mixed", - WEAPONARMOR = "weaponarmor", - FOODMEDICAL = "foodmedical", - BARTER = "barter", -} + COMMON = "common", + SUPPLY = "supply", + MEDICAL = "medical", + WEAPON = "weapon" +} \ No newline at end of file diff --git a/project/src/models/spt/services/LootRequest.ts b/project/src/models/spt/services/LootRequest.ts index 29a610f9..720d45aa 100644 --- a/project/src/models/spt/services/LootRequest.ts +++ b/project/src/models/spt/services/LootRequest.ts @@ -1,7 +1,9 @@ import { MinMax } from "@spt/models/common/MinMax"; +import { AirdropTypeEnum } from "@spt/models/enums/AirdropType"; export interface LootRequest { + airdropLoot?: AirdropTypeEnum weaponPresetCount: MinMax armorPresetCount: MinMax itemCount: MinMax