FIx premature exiting of loop

This commit is contained in:
Dev 2024-01-16 19:00:21 +00:00
parent 93edb3e074
commit 15be241dbf
2 changed files with 26 additions and 23 deletions

View File

@ -129,7 +129,7 @@ export class TradeController
} }
// Exit loop early if problem found // Exit loop early if problem found
if (output.warnings) if (output.warnings.length > 0)
{ {
return output; return output;
} }
@ -145,9 +145,8 @@ export class TradeController
* @param fleaOffer Offer being purchased * @param fleaOffer Offer being purchased
* @param requestOffer request data from client * @param requestOffer request data from client
* @param output Output to send back to client * @param output Output to send back to client
* @returns IItemEventRouterResponse
*/ */
protected buyTraderItemFromRagfair(sessionId: string, pmcData: IPmcData, fleaOffer: IRagfairOffer, requestOffer: IOfferRequest, output: IItemEventRouterResponse): IItemEventRouterResponse protected buyTraderItemFromRagfair(sessionId: string, pmcData: IPmcData, fleaOffer: IRagfairOffer, requestOffer: IOfferRequest, output: IItemEventRouterResponse): void
{ {
// Skip buying items when player doesn't have needed loyalty // Skip buying items when player doesn't have needed loyalty
if (this.playerLacksTraderLoyaltyLevelToBuyOffer(fleaOffer, pmcData)) if (this.playerLacksTraderLoyaltyLevelToBuyOffer(fleaOffer, pmcData))
@ -157,7 +156,9 @@ export class TradeController
} from trader: ${fleaOffer.user.id} as loyalty level too low, skipping` } from trader: ${fleaOffer.user.id} as loyalty level too low, skipping`
this.logger.debug(errorMessage); this.logger.debug(errorMessage);
return this.httpResponse.appendErrorToOutput(output, errorMessage, BackendErrorCodes.RAGFAIRUNAVAILABLE); this.httpResponse.appendErrorToOutput(output, errorMessage, BackendErrorCodes.RAGFAIRUNAVAILABLE);
return;
} }
const buyData: IProcessBuyTradeRequestData = { const buyData: IProcessBuyTradeRequestData = {
@ -171,8 +172,6 @@ export class TradeController
}; };
this.tradeHelper.buyItem(pmcData, buyData, sessionId, this.traderConfig.purchasesAreFoundInRaid, output); this.tradeHelper.buyItem(pmcData, buyData, sessionId, this.traderConfig.purchasesAreFoundInRaid, output);
return output;
} }
/** /**
@ -183,7 +182,7 @@ export class TradeController
* @param requestOffer Request data from client * @param requestOffer Request data from client
* @param output Output to send back to client * @param output Output to send back to client
*/ */
protected buyPmcItemFromRagfair(sessionId: string, pmcData: IPmcData, fleaOffer: IRagfairOffer, requestOffer: IOfferRequest, output: IItemEventRouterResponse): IItemEventRouterResponse protected buyPmcItemFromRagfair(sessionId: string, pmcData: IPmcData, fleaOffer: IRagfairOffer, requestOffer: IOfferRequest, output: IItemEventRouterResponse): void
{ {
const buyData: IProcessBuyTradeRequestData = { const buyData: IProcessBuyTradeRequestData = {
Action: "TradingConfirm", Action: "TradingConfirm",
@ -202,13 +201,11 @@ export class TradeController
this.tradeHelper.buyItem(pmcData, buyData, sessionId, this.ragfairConfig.dynamic.purchasesAreFoundInRaid, output); this.tradeHelper.buyItem(pmcData, buyData, sessionId, this.ragfairConfig.dynamic.purchasesAreFoundInRaid, output);
if (output.warnings.length > 0) if (output.warnings.length > 0)
{ {
return output; return;
} }
// Remove/lower stack count of item purchased from flea offer // Remove/lower stack count of item purchased from flea offer
this.ragfairServer.removeOfferStack(fleaOffer._id, requestOffer.count); this.ragfairServer.removeOfferStack(fleaOffer._id, requestOffer.count);
return output;
} }
/** /**

View File

@ -73,9 +73,8 @@ export class InventoryHelper
* @param request addItemDirect request * @param request addItemDirect request
* @param pmcData Player profile * @param pmcData Player profile
* @param output Client response object * @param output Client response object
* @returns IItemEventRouterResponse
*/ */
public addItemToStash(sessionId: string, request: IAddItemDirectRequest, pmcData: IPmcData, output: IItemEventRouterResponse): IItemEventRouterResponse public addItemToStash(sessionId: string, request: IAddItemDirectRequest, pmcData: IPmcData, output: IItemEventRouterResponse): void
{ {
const itemWithModsToAddClone = this.jsonUtil.clone(request.itemWithModsToAdd); const itemWithModsToAddClone = this.jsonUtil.clone(request.itemWithModsToAdd);
@ -84,7 +83,7 @@ export class InventoryHelper
const sortingTableFS2D = this.getSortingTableSlotMap(pmcData); const sortingTableFS2D = this.getSortingTableSlotMap(pmcData);
// Find empty slot in stash for item being added - adds 'location' + parentid + slotId properties to root item // Find empty slot in stash for item being added - adds 'location' + parentid + slotId properties to root item
const errorOutput = this.placeItemInInventory( this.placeItemInInventory(
stashFS2D, stashFS2D,
sortingTableFS2D, sortingTableFS2D,
itemWithModsToAddClone, itemWithModsToAddClone,
@ -92,10 +91,10 @@ export class InventoryHelper
request.useSortingTable, request.useSortingTable,
output, output,
); );
if (errorOutput) if (output.warnings.length > 0)
{ {
// Failed to place, error out // Failed to place, error out
return errorOutput; return;
} }
// Apply/remove FiR to item + mods // Apply/remove FiR to item + mods
@ -119,7 +118,9 @@ export class InventoryHelper
? err.message ? err.message
: this.localisationService.getText("http-unknown_error"); : this.localisationService.getText("http-unknown_error");
return this.httpResponse.appendErrorToOutput(output, message); this.httpResponse.appendErrorToOutput(output, message);
return;
} }
// Add item + mods to output and profile inventory // Add item + mods to output and profile inventory
@ -127,8 +128,6 @@ export class InventoryHelper
pmcData.Inventory.items.push(...itemWithModsToAddClone); pmcData.Inventory.items.push(...itemWithModsToAddClone);
this.logger.debug(`Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount} item: ${itemWithModsToAddClone[0]._tpl} with: ${itemWithModsToAddClone.length - 1} mods to inventory`); this.logger.debug(`Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount} item: ${itemWithModsToAddClone[0]._tpl} with: ${itemWithModsToAddClone.length - 1} mods to inventory`);
return output;
} }
/** /**
@ -505,7 +504,7 @@ export class InventoryHelper
itemWithChildren: Item[], itemWithChildren: Item[],
playerInventory: Inventory, playerInventory: Inventory,
useSortingTable: boolean, useSortingTable: boolean,
output: IItemEventRouterResponse): IItemEventRouterResponse output: IItemEventRouterResponse): void
{ {
// Get x/y size of item // Get x/y size of item
const rootItem = itemWithChildren[0]; const rootItem = itemWithChildren[0];
@ -539,10 +538,12 @@ export class InventoryHelper
: ""; : "";
this.logger.error(this.localisationService.getText("inventory-fill_container_failed", errorText)); this.logger.error(this.localisationService.getText("inventory-fill_container_failed", errorText));
return this.httpResponse.appendErrorToOutput( this.httpResponse.appendErrorToOutput(
output, output,
this.localisationService.getText("inventory-no_stash_space"), this.localisationService.getText("inventory-no_stash_space"),
); );
return;
} }
// Store details for object, incuding container item will be placed in // Store details for object, incuding container item will be placed in
rootItem.parentId = playerInventory.stash; rootItem.parentId = playerInventory.stash;
@ -584,10 +585,12 @@ export class InventoryHelper
const errorText = typeof err === "string" ? ` -> ${err}` : ""; const errorText = typeof err === "string" ? ` -> ${err}` : "";
this.logger.error(this.localisationService.getText("inventory-fill_container_failed", errorText)); this.logger.error(this.localisationService.getText("inventory-fill_container_failed", errorText));
return this.httpResponse.appendErrorToOutput( this.httpResponse.appendErrorToOutput(
output, output,
this.localisationService.getText("inventory-no_stash_space"), this.localisationService.getText("inventory-no_stash_space"),
); );
return;
} }
// Store details for object, incuding container item will be placed in // Store details for object, incuding container item will be placed in
@ -601,10 +604,12 @@ export class InventoryHelper
} }
else else
{ {
return this.httpResponse.appendErrorToOutput( this.httpResponse.appendErrorToOutput(
output, output,
this.localisationService.getText("inventory-no_stash_space"), this.localisationService.getText("inventory-no_stash_space"),
); );
return
} }
} }
@ -1107,7 +1112,8 @@ export class InventoryHelper
{ {
continue; continue;
} }
else if (childFoldable && rootFolded && childFolded)
if (childFoldable && rootFolded && childFolded)
{ {
continue; continue;
} }