Better error handling in server
This commit is contained in:
@@ -40,10 +40,14 @@ class UIFixes implements IPreSptLoadMod {
|
|||||||
original.call(inRaidHelper, pmcData, sessionId);
|
original.call(inRaidHelper, pmcData, sessionId);
|
||||||
|
|
||||||
// Restore the quickbinds for items that still exist
|
// Restore the quickbinds for items that still exist
|
||||||
for (const index in fastPanel) {
|
try {
|
||||||
if (pmcData.Inventory.items.find(i => i._id == fastPanel[index])) {
|
for (const index in fastPanel) {
|
||||||
pmcData.Inventory.fastPanel[index] = fastPanel[index];
|
if (pmcData.Inventory.items.find(i => i._id == fastPanel[index])) {
|
||||||
|
pmcData.Inventory.fastPanel[index] = fastPanel[index];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`UIFixes failed to restore quickbinds\n ${error}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -61,14 +65,20 @@ class UIFixes implements IPreSptLoadMod {
|
|||||||
const result = original.call(hideoutHelper, pmcData, body, sessionID);
|
const result = original.call(hideoutHelper, pmcData, body, sessionID);
|
||||||
|
|
||||||
// The items haven't been deleted yet, augment the list with their parentId
|
// The items haven't been deleted yet, augment the list with their parentId
|
||||||
const bodyAsSingle = body as IHideoutSingleProductionStartRequestData;
|
try {
|
||||||
if (bodyAsSingle && bodyAsSingle.tools?.length > 0) {
|
const bodyAsSingle = body as IHideoutSingleProductionStartRequestData;
|
||||||
const requestTools = bodyAsSingle.tools;
|
if (bodyAsSingle && bodyAsSingle.tools?.length > 0) {
|
||||||
const tools = pmcData.Hideout.Production[body.recipeId].sptRequiredTools;
|
const requestTools = bodyAsSingle.tools;
|
||||||
for (let i = 0; i < tools.length; i++) {
|
const tools = pmcData.Hideout.Production[body.recipeId].sptRequiredTools;
|
||||||
const originalTool = pmcData.Inventory.items.find(x => x._id === requestTools[i].id);
|
for (let i = 0; i < tools.length; i++) {
|
||||||
tools[i]["uifixes.returnTo"] = [originalTool.parentId, originalTool.slotId];
|
const originalTool = pmcData.Inventory.items.find(
|
||||||
|
x => x._id === requestTools[i].id
|
||||||
|
);
|
||||||
|
tools[i]["uifixes.returnTo"] = [originalTool.parentId, originalTool.slotId];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`UIFixes failed to save tool origin\n ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -89,51 +99,59 @@ class UIFixes implements IPreSptLoadMod {
|
|||||||
// If a tool marked with uifixes is there, try to return it to its original container
|
// If a tool marked with uifixes is there, try to return it to its original container
|
||||||
const tool = itemWithModsToAddClone[0];
|
const tool = itemWithModsToAddClone[0];
|
||||||
if (tool["uifixes.returnTo"]) {
|
if (tool["uifixes.returnTo"]) {
|
||||||
const [containerId, slotId] = tool["uifixes.returnTo"];
|
try {
|
||||||
|
const [containerId, slotId] = tool["uifixes.returnTo"];
|
||||||
|
|
||||||
const container = pmcData.Inventory.items.find(x => x._id === containerId);
|
const container = pmcData.Inventory.items.find(x => x._id === containerId);
|
||||||
if (container) {
|
if (container) {
|
||||||
const containerTemplate = itemHelper.getItem(container._tpl)[1];
|
const [foundTemplate, containerTemplate] = itemHelper.getItem(container._tpl);
|
||||||
const containerFS2D = inventoryHelper.getContainerMap(
|
if (foundTemplate && containerTemplate) {
|
||||||
containerTemplate._props.Grids[0]._props.cellsH,
|
const containerFS2D = inventoryHelper.getContainerMap(
|
||||||
containerTemplate._props.Grids[0]._props.cellsV,
|
containerTemplate._props.Grids[0]._props.cellsH,
|
||||||
pmcData.Inventory.items,
|
containerTemplate._props.Grids[0]._props.cellsV,
|
||||||
containerId
|
pmcData.Inventory.items,
|
||||||
);
|
containerId
|
||||||
|
);
|
||||||
|
|
||||||
// will change the array so clone it
|
// will change the array so clone it
|
||||||
if (
|
if (
|
||||||
inventoryHelper.canPlaceItemInContainer(
|
inventoryHelper.canPlaceItemInContainer(
|
||||||
cloner.clone(containerFS2D),
|
cloner.clone(containerFS2D),
|
||||||
itemWithModsToAddClone
|
itemWithModsToAddClone
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// At this point everything should succeed
|
// At this point everything should succeed
|
||||||
inventoryHelper.placeItemInContainer(
|
inventoryHelper.placeItemInContainer(
|
||||||
containerFS2D,
|
containerFS2D,
|
||||||
itemWithModsToAddClone,
|
itemWithModsToAddClone,
|
||||||
containerId,
|
containerId,
|
||||||
slotId
|
slotId
|
||||||
);
|
);
|
||||||
|
|
||||||
// protected function, bypass typescript
|
// protected function, bypass typescript
|
||||||
inventoryHelper["setFindInRaidStatusForItem"](
|
inventoryHelper["setFindInRaidStatusForItem"](
|
||||||
itemWithModsToAddClone,
|
itemWithModsToAddClone,
|
||||||
request.foundInRaid
|
request.foundInRaid
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add item + mods to output and profile inventory
|
// Add item + mods to output and profile inventory
|
||||||
output.profileChanges[sessionId].items.new.push(...itemWithModsToAddClone);
|
output.profileChanges[sessionId].items.new.push(...itemWithModsToAddClone);
|
||||||
pmcData.Inventory.items.push(...itemWithModsToAddClone);
|
pmcData.Inventory.items.push(...itemWithModsToAddClone);
|
||||||
|
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount ?? 1} item: ${
|
`Added ${itemWithModsToAddClone[0].upd?.StackObjectsCount ?? 1} item: ${
|
||||||
itemWithModsToAddClone[0]._tpl
|
itemWithModsToAddClone[0]._tpl
|
||||||
} with: ${itemWithModsToAddClone.length - 1} mods to ${containerId}`
|
} with: ${itemWithModsToAddClone.length - 1} mods to ${containerId}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`UIFixes failed to put a tool back, it will be returned to your stash as normal.\n ${error}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user