mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-12 21:30:43 -05:00
Moved reward fitting code into its own function, moved logic around
This commit is contained in:
parent
b4061b3e41
commit
be31f7248f
@ -124,7 +124,7 @@ export class CircleOfCultistService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rewards = hasDirectReward
|
const rewards = hasDirectReward
|
||||||
? this.getDirectRewards(sessionId, directRewardSettings, cultistCircleStashId)
|
? this.getDirectRewards(sessionId, directRewardSettings, cultistCircleStashId)
|
||||||
: this.getRewardsWithinBudget(
|
: this.getRewardsWithinBudget(
|
||||||
this.getCultistCircleRewardPool(sessionId, pmcData, craftingInfo, this.hideoutConfig.cultistCircle),
|
this.getCultistCircleRewardPool(sessionId, pmcData, craftingInfo, this.hideoutConfig.cultistCircle),
|
||||||
@ -138,6 +138,28 @@ export class CircleOfCultistService {
|
|||||||
|
|
||||||
// Ensure rewards fit into container
|
// Ensure rewards fit into container
|
||||||
const containerGrid = this.inventoryHelper.getContainerSlotMap(cultistStashDbItem[1]._id);
|
const containerGrid = this.inventoryHelper.getContainerSlotMap(cultistStashDbItem[1]._id);
|
||||||
|
this.addRewardsToCircleContainer(sessionId, pmcData, rewards, containerGrid, cultistCircleStashId, output);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to add all rewards to cultist circle, if they dont fit remove one and try again until they fit
|
||||||
|
* @param sessionId Session id
|
||||||
|
* @param pmcData Player profile
|
||||||
|
* @param rewards Rewards to send to player
|
||||||
|
* @param containerGrid Cultist grid to add rewards to
|
||||||
|
* @param cultistCircleStashId Stash id
|
||||||
|
* @param output Client output
|
||||||
|
*/
|
||||||
|
protected addRewardsToCircleContainer(
|
||||||
|
sessionId: string,
|
||||||
|
pmcData: IPmcData,
|
||||||
|
rewards: IItem[][],
|
||||||
|
containerGrid: number[][],
|
||||||
|
cultistCircleStashId: string,
|
||||||
|
output: IItemEventRouterResponse,
|
||||||
|
): void {
|
||||||
let canAddToContainer = false;
|
let canAddToContainer = false;
|
||||||
while (!canAddToContainer && rewards.length > 0) {
|
while (!canAddToContainer && rewards.length > 0) {
|
||||||
canAddToContainer = this.inventoryHelper.canPlaceItemsInContainer(
|
canAddToContainer = this.inventoryHelper.canPlaceItemsInContainer(
|
||||||
@ -145,24 +167,23 @@ export class CircleOfCultistService {
|
|||||||
rewards,
|
rewards,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (canAddToContainer) {
|
// Doesn't fit, remove one item
|
||||||
for (const itemToAdd of rewards) {
|
if (!canAddToContainer) {
|
||||||
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();
|
rewards.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user