Centralise check for upd object / creation if it doesnt exist into one helper function inside ItemHelper
Some minor formatting updates
This commit is contained in:
parent
246f0d5030
commit
479898ecab
@ -79,10 +79,7 @@ export class HealthController
|
||||
}
|
||||
|
||||
// Ensure item has a upd object
|
||||
if (!healingItemToUse.upd)
|
||||
{
|
||||
healingItemToUse.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(healingItemToUse);
|
||||
|
||||
if (healingItemToUse.upd.MedKit)
|
||||
{
|
||||
|
@ -592,7 +592,9 @@ export class HideoutController
|
||||
const recipe = this.databaseServer.getTables().hideout.production.find((p) => p._id === body.recipeId);
|
||||
|
||||
// Find the actual amount of items we need to remove because body can send weird data
|
||||
const recipeRequirementsClone = this.jsonUtil.clone(recipe.requirements.filter((i) => i.type === "Item" || i.type === "Tool"));
|
||||
const recipeRequirementsClone = this.jsonUtil.clone(
|
||||
recipe.requirements.filter((i) => i.type === "Item" || i.type === "Tool"),
|
||||
);
|
||||
|
||||
const output = this.eventOutputHolder.getOutput(sessionID);
|
||||
const itemsToDelete = body.items.concat(body.tools);
|
||||
@ -833,10 +835,13 @@ export class HideoutController
|
||||
),
|
||||
);
|
||||
|
||||
this.httpResponse.appendErrorToOutput(output, this.localisationService.getText(
|
||||
"hideout-unable_to_find_production_in_profile_by_recipie_id",
|
||||
request.recipeId,
|
||||
));
|
||||
this.httpResponse.appendErrorToOutput(
|
||||
output,
|
||||
this.localisationService.getText(
|
||||
"hideout-unable_to_find_production_in_profile_by_recipie_id",
|
||||
request.recipeId,
|
||||
),
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -904,10 +909,7 @@ export class HideoutController
|
||||
{
|
||||
for (const reward of itemAndChildrenToSendToPlayer)
|
||||
{
|
||||
if (!reward[0].upd)
|
||||
{
|
||||
reward[0].upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(reward[0]);
|
||||
|
||||
reward[0].upd.RecodableComponent = { IsEncoded: true };
|
||||
}
|
||||
|
@ -463,10 +463,7 @@ export class InventoryController
|
||||
}
|
||||
|
||||
// Item may not have upd object
|
||||
if (!itemToFold.upd)
|
||||
{
|
||||
itemToFold.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(itemToFold);
|
||||
|
||||
itemToFold.upd.Foldable = { Folded: request.value };
|
||||
|
||||
@ -494,13 +491,10 @@ export class InventoryController
|
||||
const itemToToggle = playerData.Inventory.items.find((x) => x._id === body.item);
|
||||
if (itemToToggle)
|
||||
{
|
||||
if (!itemToToggle.upd)
|
||||
{
|
||||
this.logger.warning(
|
||||
this.localisationService.getText("inventory-item_to_toggle_missing_upd", itemToToggle._id),
|
||||
);
|
||||
itemToToggle.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(
|
||||
itemToToggle,
|
||||
this.localisationService.getText("inventory-item_to_toggle_missing_upd", itemToToggle._id),
|
||||
);
|
||||
|
||||
itemToToggle.upd.Togglable = { On: body.value };
|
||||
|
||||
|
@ -712,10 +712,8 @@ export class BotLootGenerator
|
||||
|
||||
const currencyWeight = currencyWeights[moneyItem._tpl];
|
||||
|
||||
if (!moneyItem.upd)
|
||||
{
|
||||
moneyItem.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(moneyItem);
|
||||
|
||||
moneyItem.upd.StackObjectsCount = Number.parseInt(this.weightedRandomHelper.getWeightedValue(currencyWeight));
|
||||
}
|
||||
|
||||
@ -734,10 +732,7 @@ export class BotLootGenerator
|
||||
Math.min(itemTemplate._props.StackMaxRandom, 60),
|
||||
);
|
||||
|
||||
if (!ammoItem.upd)
|
||||
{
|
||||
ammoItem.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(ammoItem);
|
||||
|
||||
ammoItem.upd.StackObjectsCount = randomSize;
|
||||
}
|
||||
|
@ -126,7 +126,6 @@ export class RagfairOfferGenerator
|
||||
|
||||
const itemsClone = this.jsonUtil.clone(items);
|
||||
|
||||
|
||||
// Add cartridges to offers for ammo boxes
|
||||
if (this.itemHelper.isOfBaseclass(itemsClone[0]._tpl, BaseClasses.AMMO_BOX))
|
||||
{
|
||||
@ -690,10 +689,7 @@ export class RagfairOfferGenerator
|
||||
);
|
||||
if (this.randomUtil.getChance100(25) && visorMod)
|
||||
{
|
||||
if (!visorMod.upd)
|
||||
{
|
||||
visorMod.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(visorMod);
|
||||
|
||||
visorMod.upd.FaceShield = { Hits: this.randomUtil.getInt(1, 3) };
|
||||
}
|
||||
@ -795,10 +791,7 @@ export class RagfairOfferGenerator
|
||||
const itemDbDetails = this.itemHelper.getItem(armorItem._tpl)[1];
|
||||
if ((parseInt(<string>itemDbDetails._props.armorClass)) > 1)
|
||||
{
|
||||
if (!armorItem.upd)
|
||||
{
|
||||
armorItem.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(armorItem);
|
||||
|
||||
const lowestMaxDurability = this.randomUtil.getFloat(maxMultiplier, 1)
|
||||
* itemDbDetails._props.MaxDurability;
|
||||
|
@ -110,10 +110,8 @@ export class HideoutHelper
|
||||
const toolItem = this.jsonUtil.clone(pmcData.Inventory.items.find((x) => x._id === tool.id));
|
||||
|
||||
// Make sure we only return as many as we took
|
||||
if (!toolItem.upd)
|
||||
{
|
||||
toolItem.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(toolItem);
|
||||
|
||||
toolItem.upd.StackObjectsCount = tool.count;
|
||||
|
||||
production.sptRequiredTools.push({
|
||||
|
@ -68,16 +68,13 @@ export class InRaidHelper
|
||||
*/
|
||||
public addUpdToMoneyFromRaid(items: Item[]): void
|
||||
{
|
||||
for (const item of items.filter((x) => this.paymentHelper.isMoneyTpl(x._tpl)))
|
||||
for (const moneyItem of items.filter((item) => this.paymentHelper.isMoneyTpl(item._tpl)))
|
||||
{
|
||||
if (!item.upd)
|
||||
{
|
||||
item.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(moneyItem);
|
||||
|
||||
if (!item.upd.StackObjectsCount)
|
||||
if (!moneyItem.upd.StackObjectsCount)
|
||||
{
|
||||
item.upd.StackObjectsCount = 1;
|
||||
moneyItem.upd.StackObjectsCount = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,10 +193,7 @@ export class InventoryHelper
|
||||
for (const item of itemWithChildren)
|
||||
{
|
||||
// Ensure item has upd object
|
||||
if (!item.upd)
|
||||
{
|
||||
item.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(item);
|
||||
|
||||
if (foundInRaid)
|
||||
{
|
||||
|
@ -1636,6 +1636,25 @@ export class ItemHelper
|
||||
}
|
||||
return itemsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a blank upd object to passed in item if it does not exist already
|
||||
* @param item item to add upd to
|
||||
* @param warningMessageWhenMissing text to write to log when upd object was not found
|
||||
* @returns True when upd object was added
|
||||
*/
|
||||
public addUpdObjectToItem(item: Item, warningMessageWhenMissing: string = null): boolean
|
||||
{
|
||||
if (!item.upd)
|
||||
{
|
||||
item.upd = {};
|
||||
this.logger.warning(warningMessageWhenMissing);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ItemHelper
|
||||
|
@ -278,33 +278,30 @@ export class QuestHelper
|
||||
}
|
||||
}
|
||||
|
||||
for (const item of questReward.items)
|
||||
for (const rewardItem of questReward.items)
|
||||
{
|
||||
if (!item.upd)
|
||||
{
|
||||
item.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(rewardItem);
|
||||
|
||||
// Reward items are granted Found in Raid status
|
||||
item.upd.SpawnedInSession = true;
|
||||
rewardItem.upd.SpawnedInSession = true;
|
||||
|
||||
// Is root item, fix stacks
|
||||
if (item._id === questReward.target)
|
||||
if (rewardItem._id === questReward.target)
|
||||
{ // Is base reward item
|
||||
if (
|
||||
(item.parentId !== undefined) && (item.parentId === "hideout") // Has parentId of hideout
|
||||
&& (item.upd !== undefined) && (item.upd.StackObjectsCount !== undefined) // Has upd with stackobject count
|
||||
&& (item.upd.StackObjectsCount > 1) // More than 1 item in stack
|
||||
(rewardItem.parentId !== undefined) && (rewardItem.parentId === "hideout") // Has parentId of hideout
|
||||
&& (rewardItem.upd !== undefined) && (rewardItem.upd.StackObjectsCount !== undefined) // Has upd with stackobject count
|
||||
&& (rewardItem.upd.StackObjectsCount > 1) // More than 1 item in stack
|
||||
)
|
||||
{
|
||||
item.upd.StackObjectsCount = 1;
|
||||
rewardItem.upd.StackObjectsCount = 1;
|
||||
}
|
||||
targets = this.itemHelper.splitStack(item);
|
||||
targets = this.itemHelper.splitStack(rewardItem);
|
||||
// splitStack created new ids for the new stacks. This would destroy the relation to possible children.
|
||||
// Instead, we reset the id to preserve relations and generate a new id in the downstream loop, where we are also reparenting if required
|
||||
for (const target of targets)
|
||||
{
|
||||
target._id = item._id;
|
||||
target._id = rewardItem._id;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -313,10 +310,10 @@ export class QuestHelper
|
||||
if (questReward.items[0].upd.SpawnedInSession)
|
||||
{
|
||||
// Propigate FiR status into child items
|
||||
item.upd.SpawnedInSession = questReward.items[0].upd.SpawnedInSession;
|
||||
rewardItem.upd.SpawnedInSession = questReward.items[0].upd.SpawnedInSession;
|
||||
}
|
||||
|
||||
mods.push(item);
|
||||
mods.push(rewardItem);
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,10 +360,8 @@ export class QuestHelper
|
||||
questReward.target = rootItem._id;
|
||||
|
||||
// Copy over stack count otherwise reward shows as missing in client
|
||||
if (!rootItem.upd)
|
||||
{
|
||||
rootItem.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(rootItem);
|
||||
|
||||
rootItem.upd.StackObjectsCount = originalRewardRootItem.upd.StackObjectsCount;
|
||||
|
||||
return;
|
||||
@ -609,10 +604,8 @@ export class QuestHelper
|
||||
if (newStackSize > 0)
|
||||
{
|
||||
const item = pmcData.Inventory.items[inventoryItemIndex];
|
||||
if (!item.upd)
|
||||
{
|
||||
item.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(item);
|
||||
|
||||
item.upd.StackObjectsCount = newStackSize;
|
||||
|
||||
this.addItemStackSizeChangeIntoEventResponse(output, sessionID, item);
|
||||
|
@ -917,10 +917,8 @@ export class FenceService
|
||||
const modItemToAdjust = armor.find((mod) =>
|
||||
mod.slotId.toLowerCase() === requiredSlot._name.toLowerCase()
|
||||
);
|
||||
if (!modItemToAdjust.upd)
|
||||
{
|
||||
modItemToAdjust.upd = {};
|
||||
}
|
||||
|
||||
this.itemHelper.addUpdObjectToItem(modItemToAdjust);
|
||||
|
||||
if (!modItemToAdjust.upd.Repairable)
|
||||
{
|
||||
@ -973,10 +971,7 @@ export class FenceService
|
||||
|
||||
// Find items mod to apply dura changes to
|
||||
const modItemToAdjust = armor.find((mod) => mod.slotId.toLowerCase() === plateSlot._name.toLowerCase());
|
||||
if (!modItemToAdjust.upd)
|
||||
{
|
||||
modItemToAdjust.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(modItemToAdjust);
|
||||
|
||||
if (!modItemToAdjust.upd.Repairable)
|
||||
{
|
||||
|
@ -346,44 +346,41 @@ export class InsuranceService
|
||||
): Item
|
||||
{
|
||||
// Get baseline item to return, clone pre raid item
|
||||
const itemToReturn: Item = this.jsonUtil.clone(preRaidItem);
|
||||
const itemToReturnClone: Item = this.jsonUtil.clone(preRaidItem);
|
||||
|
||||
// Add upd if it doesnt exist
|
||||
if (!itemToReturn.upd)
|
||||
{
|
||||
itemToReturn.upd = {};
|
||||
}
|
||||
this.itemHelper.addUpdObjectToItem(itemToReturnClone);
|
||||
|
||||
// Check for slotid values that need to be updated and adjust
|
||||
this.updateSlotIdValue(pmcData.Inventory.equipment, itemToReturn);
|
||||
this.updateSlotIdValue(pmcData.Inventory.equipment, itemToReturnClone);
|
||||
|
||||
// Remove location property
|
||||
if (itemToReturn.slotId === "hideout" && "location" in itemToReturn)
|
||||
if (itemToReturnClone.slotId === "hideout" && "location" in itemToReturnClone)
|
||||
{
|
||||
delete itemToReturn.location;
|
||||
delete itemToReturnClone.location;
|
||||
}
|
||||
|
||||
// Remove found in raid status when upd exists + SpawnedInSession value exists
|
||||
if ("upd" in itemToReturn && "SpawnedInSession" in itemToReturn.upd)
|
||||
if ("SpawnedInSession" in itemToReturnClone.upd)
|
||||
{
|
||||
itemToReturn.upd.SpawnedInSession = false;
|
||||
itemToReturnClone.upd.SpawnedInSession = false;
|
||||
}
|
||||
|
||||
// Client item has durability values, Ensure values persist into server data
|
||||
if (insuredItemFromClient?.durability)
|
||||
{
|
||||
// Item didnt have Repairable object pre-raid, add it
|
||||
if (!itemToReturn.upd.Repairable)
|
||||
if (!itemToReturnClone.upd.Repairable)
|
||||
{
|
||||
itemToReturn.upd.Repairable = {
|
||||
itemToReturnClone.upd.Repairable = {
|
||||
Durability: insuredItemFromClient.durability,
|
||||
MaxDurability: insuredItemFromClient.maxDurability,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
itemToReturn.upd.Repairable.Durability = insuredItemFromClient.durability;
|
||||
itemToReturn.upd.Repairable.MaxDurability = insuredItemFromClient.maxDurability;
|
||||
itemToReturnClone.upd.Repairable.Durability = insuredItemFromClient.durability;
|
||||
itemToReturnClone.upd.Repairable.MaxDurability = insuredItemFromClient.maxDurability;
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,17 +388,17 @@ export class InsuranceService
|
||||
if (insuredItemFromClient?.hits)
|
||||
{
|
||||
// Item didnt have faceshield object pre-raid, add it
|
||||
if (!itemToReturn.upd.FaceShield)
|
||||
if (!itemToReturnClone.upd.FaceShield)
|
||||
{
|
||||
itemToReturn.upd.FaceShield = { Hits: insuredItemFromClient.hits };
|
||||
itemToReturnClone.upd.FaceShield = { Hits: insuredItemFromClient.hits };
|
||||
}
|
||||
else
|
||||
{
|
||||
itemToReturn.upd.FaceShield.Hits = insuredItemFromClient.hits;
|
||||
itemToReturnClone.upd.FaceShield.Hits = insuredItemFromClient.hits;
|
||||
}
|
||||
}
|
||||
|
||||
return itemToReturn;
|
||||
return itemToReturnClone;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user