mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 01:50:44 -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,7 +167,12 @@ export class CircleOfCultistService {
|
|||||||
rewards,
|
rewards,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (canAddToContainer) {
|
// Doesn't fit, remove one item
|
||||||
|
if (!canAddToContainer) {
|
||||||
|
rewards.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const itemToAdd of rewards) {
|
for (const itemToAdd of rewards) {
|
||||||
this.inventoryHelper.placeItemInContainer(
|
this.inventoryHelper.placeItemInContainer(
|
||||||
containerGrid,
|
containerGrid,
|
||||||
@ -157,12 +184,6 @@ export class CircleOfCultistService {
|
|||||||
output.profileChanges[sessionId].items.new.push(...itemToAdd);
|
output.profileChanges[sessionId].items.new.push(...itemToAdd);
|
||||||
pmcData.Inventory.items.push(...itemToAdd);
|
pmcData.Inventory.items.push(...itemToAdd);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
rewards.pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user