Skip to content

Commit 8d05bf0

Browse files
authored
Better handle cultist rewards not fitting the container (#979)
Better handle rewards not fitting (they shouldn't just poof) by instead trimming the rewards amount until they fit.
2 parents d5ce6c4 + 0527fc2 commit 8d05bf0

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

project/src/services/CircleOfCultistService.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class CircleOfCultistService {
124124
}
125125
}
126126

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

139139
// Ensure rewards fit into container
140140
const containerGrid = this.inventoryHelper.getContainerSlotMap(cultistStashDbItem[1]._id);
141-
const canAddToContainer = this.inventoryHelper.canPlaceItemsInContainer(
142-
this.cloner.clone(containerGrid), // MUST clone grid before passing in as function modifies grid
143-
rewards,
144-
);
141+
let canAddToContainer = false;
142+
while (!canAddToContainer && rewards.length > 0) {
143+
canAddToContainer = this.inventoryHelper.canPlaceItemsInContainer(
144+
this.cloner.clone(containerGrid), // MUST clone grid before passing in as function modifies grid
145+
rewards,
146+
);
145147

146-
if (canAddToContainer) {
147-
for (const itemToAdd of rewards) {
148-
this.inventoryHelper.placeItemInContainer(
149-
containerGrid,
150-
itemToAdd,
151-
cultistCircleStashId,
152-
CircleOfCultistService.circleOfCultistSlotId,
153-
);
154-
// Add item + mods to output and profile inventory
155-
output.profileChanges[sessionId].items.new.push(...itemToAdd);
156-
pmcData.Inventory.items.push(...itemToAdd);
148+
if (canAddToContainer) {
149+
for (const itemToAdd of rewards) {
150+
this.inventoryHelper.placeItemInContainer(
151+
containerGrid,
152+
itemToAdd,
153+
cultistCircleStashId,
154+
CircleOfCultistService.circleOfCultistSlotId,
155+
);
156+
// Add item + mods to output and profile inventory
157+
output.profileChanges[sessionId].items.new.push(...itemToAdd);
158+
pmcData.Inventory.items.push(...itemToAdd);
159+
}
160+
} else {
161+
rewards.pop();
157162
}
158-
} else {
159-
this.logger.error(
160-
`Unable to fit all: ${rewards.length} reward items into sacrifice grid, nothing will be returned (rewards so valuable cultists stole it)`,
161-
);
162163
}
163164

164165
return output;

0 commit comments

Comments
 (0)