Skip to content

Commit

Permalink
Added system to insert items into bot storage areas during seasonal e…
Browse files Browse the repository at this point in the history
…vents - Used to add Christmas items to scavs
  • Loading branch information
Chomp committed Dec 18, 2024
1 parent fae9657 commit 7caec6e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
22 changes: 22 additions & 0 deletions project/assets/configs/seasonalevents.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@
}
}
},
"eventLoot": {
"christmas": {
"assault": {
"Pockets": {
"5df8a6a186f77412640e2e80": 3000,
"5df8a72c86f77412640e2e83": 3000,
"5df8a77486f77412672a1e3f": 3000
},
"Backpack": {
"5df8a6a186f77412640e2e80": 3000,
"5df8a72c86f77412640e2e83": 3000,
"5df8a77486f77412672a1e3f": 3000,
"63a8970d7108f713591149f5": 250
},
"TacticalVest": {
"5df8a6a186f77412640e2e80": 3000,
"5df8a72c86f77412640e2e83": 3000,
"5df8a77486f77412672a1e3f": 3000
}
}
}
},
"eventBotMapping": {
"peacefullZryachiyEvent": "bossZryachiy",
"sectactPriestEvent": "sectantPriest",
Expand Down
2 changes: 2 additions & 0 deletions project/src/models/spt/config/ISeasonalEventConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface ISeasonalEventConfig extends IBaseConfig {
enableSeasonalEventDetection: boolean;
/** event / botType / equipSlot / itemid */
eventGear: Record<string, Record<string, Record<string, Record<string, number>>>>;
/** event / bot type / equipSlot / itemid */
eventLoot: Record<string, Record<string, Record<string, Record<string, number>>>>;
events: ISeasonalEvent[];
eventBotMapping: Record<string, string>;
eventBossSpawns: Record<string, Record<string, IBossLocationSpawn[]>>;
Expand Down
49 changes: 46 additions & 3 deletions project/src/services/SeasonalEventService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ export class SeasonalEventService {
return this.seasonalEventConfig.eventGear[eventType.toLowerCase()];
}

/**
* Get a dictionary of loot changes to apply to bots for a specific event e.g. Christmas/Halloween
* @param eventName Name of event to get gear changes for
* @returns bots with loot changes
*/
protected getEventBotLoot(eventType: SeasonalEventType): Record<string, Record<string, Record<string, number>>> {
return this.seasonalEventConfig.eventLoot[eventType.toLowerCase()];
}

/**
* Get the dates each seasonal event starts and ends at
* @returns Record with event name + start/end date
Expand Down Expand Up @@ -385,6 +394,7 @@ export class SeasonalEventService {
globalConfig.EventType = globalConfig.EventType.filter((x) => x !== "None");
globalConfig.EventType.push("Christmas");
this.addEventGearToBots(event.type);
this.addEventLootToBots(event.type);
if (event.settings?.enableSanta) {
this.addGifterBotToMaps();
this.addLootItemsToGifterDropItemsList();
Expand All @@ -398,6 +408,7 @@ export class SeasonalEventService {
this.addLootItemsToGifterDropItemsList();
this.addEventGearToBots(SeasonalEventType.HALLOWEEN);
this.addEventGearToBots(SeasonalEventType.CHRISTMAS);
this.addEventLootToBots(SeasonalEventType.CHRISTMAS);
this.addEventBossesToMaps(SeasonalEventType.HALLOWEEN);
this.enableHalloweenSummonEvent();
this.addPumpkinsToScavBackpacks();
Expand Down Expand Up @@ -663,23 +674,55 @@ export class SeasonalEventService {
}

// Iterate over each equipment slot change
const gearAmendments = botGearChanges[bot];
for (const equipmentSlot in gearAmendments) {
const gearAmendmentsBySlot = botGearChanges[bot];
for (const equipmentSlot in gearAmendmentsBySlot) {
// Adjust slots spawn chance to be at least 75%
botToUpdate.chances.equipment[equipmentSlot] = Math.max(
botToUpdate.chances.equipment[equipmentSlot],
75,
);

// Grab gear to add and loop over it
const itemsToAdd = gearAmendments[equipmentSlot];
const itemsToAdd = gearAmendmentsBySlot[equipmentSlot];
for (const itemTplIdToAdd in itemsToAdd) {
botToUpdate.inventory.equipment[equipmentSlot][itemTplIdToAdd] = itemsToAdd[itemTplIdToAdd];
}
}
}
}

/**
* Read in data from seasonalEvents.json and add found loot items to bots
* @param eventName Name of the event to read loot in from config
*/
protected addEventLootToBots(eventType: SeasonalEventType): void {
const botLootChanges = this.getEventBotLoot(eventType);
if (!botLootChanges) {
this.logger.warning(this.localisationService.getText("gameevent-no_gear_data", eventType));

return;
}

// Iterate over bots with changes to apply
for (const bot in botLootChanges) {
const botToUpdate = this.databaseService.getBots().types[bot.toLowerCase()];
if (!botToUpdate) {
this.logger.warning(this.localisationService.getText("gameevent-bot_not_found", bot));
continue;
}

// Iterate over each loot slot change
const lootAmendmentsBySlot = botLootChanges[bot];
for (const slotKey in lootAmendmentsBySlot) {
// Grab loot to add and loop over it
const itemTplsToAdd = lootAmendmentsBySlot[slotKey];
for (const tpl in itemTplsToAdd) {
botToUpdate.inventory.items[slotKey][tpl] = itemTplsToAdd[tpl];
}
}
}
}

/**
* Add pumpkin loot boxes to scavs
*/
Expand Down

0 comments on commit 7caec6e

Please sign in to comment.