Skip to content

Commit

Permalink
Better handle cultist rewards not fitting the container (#979)
Browse files Browse the repository at this point in the history
Better handle rewards not fitting (they shouldn't just poof) by instead
trimming the rewards amount until they fit.

(cherry picked from commit 8d05bf0)
  • Loading branch information
chompDev authored and Chomp committed Dec 9, 2024
1 parent 2abf216 commit b4061b3
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions project/src/services/CircleOfCultistService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class CircleOfCultistService {
}
}

const rewards = hasDirectReward
let rewards = hasDirectReward
? this.getDirectRewards(sessionId, directRewardSettings, cultistCircleStashId)
: this.getRewardsWithinBudget(
this.getCultistCircleRewardPool(sessionId, pmcData, craftingInfo, this.hideoutConfig.cultistCircle),
Expand All @@ -138,27 +138,28 @@ export class CircleOfCultistService {

// Ensure rewards fit into container
const containerGrid = this.inventoryHelper.getContainerSlotMap(cultistStashDbItem[1]._id);
const canAddToContainer = this.inventoryHelper.canPlaceItemsInContainer(
this.cloner.clone(containerGrid), // MUST clone grid before passing in as function modifies grid
rewards,
);
let canAddToContainer = false;
while (!canAddToContainer && rewards.length > 0) {
canAddToContainer = this.inventoryHelper.canPlaceItemsInContainer(
this.cloner.clone(containerGrid), // MUST clone grid before passing in as function modifies grid
rewards,
);

if (canAddToContainer) {
for (const itemToAdd of rewards) {
this.inventoryHelper.placeItemInContainer(
containerGrid,
itemToAdd,
cultistCircleStashId,
CircleOfCultistService.circleOfCultistSlotId,
);
// Add item + mods to output and profile inventory
output.profileChanges[sessionId].items.new.push(...itemToAdd);
pmcData.Inventory.items.push(...itemToAdd);
if (canAddToContainer) {
for (const itemToAdd of rewards) {
this.inventoryHelper.placeItemInContainer(
containerGrid,
itemToAdd,
cultistCircleStashId,
CircleOfCultistService.circleOfCultistSlotId,
);
// Add item + mods to output and profile inventory
output.profileChanges[sessionId].items.new.push(...itemToAdd);
pmcData.Inventory.items.push(...itemToAdd);
}
} else {
rewards.pop();
}
} else {
this.logger.error(
`Unable to fit all: ${rewards.length} reward items into sacrifice grid, nothing will be returned (rewards so valuable cultists stole it)`,
);
}

return output;
Expand Down

0 comments on commit b4061b3

Please sign in to comment.