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
|
// Ensure item has a upd object
|
||||||
if (!healingItemToUse.upd)
|
this.itemHelper.addUpdObjectToItem(healingItemToUse);
|
||||||
{
|
|
||||||
healingItemToUse.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (healingItemToUse.upd.MedKit)
|
if (healingItemToUse.upd.MedKit)
|
||||||
{
|
{
|
||||||
|
@ -592,7 +592,9 @@ export class HideoutController
|
|||||||
const recipe = this.databaseServer.getTables().hideout.production.find((p) => p._id === body.recipeId);
|
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
|
// 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 output = this.eventOutputHolder.getOutput(sessionID);
|
||||||
const itemsToDelete = body.items.concat(body.tools);
|
const itemsToDelete = body.items.concat(body.tools);
|
||||||
@ -833,10 +835,13 @@ export class HideoutController
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.httpResponse.appendErrorToOutput(output, this.localisationService.getText(
|
this.httpResponse.appendErrorToOutput(
|
||||||
"hideout-unable_to_find_production_in_profile_by_recipie_id",
|
output,
|
||||||
request.recipeId,
|
this.localisationService.getText(
|
||||||
));
|
"hideout-unable_to_find_production_in_profile_by_recipie_id",
|
||||||
|
request.recipeId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -904,10 +909,7 @@ export class HideoutController
|
|||||||
{
|
{
|
||||||
for (const reward of itemAndChildrenToSendToPlayer)
|
for (const reward of itemAndChildrenToSendToPlayer)
|
||||||
{
|
{
|
||||||
if (!reward[0].upd)
|
this.itemHelper.addUpdObjectToItem(reward[0]);
|
||||||
{
|
|
||||||
reward[0].upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
reward[0].upd.RecodableComponent = { IsEncoded: true };
|
reward[0].upd.RecodableComponent = { IsEncoded: true };
|
||||||
}
|
}
|
||||||
|
@ -463,10 +463,7 @@ export class InventoryController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Item may not have upd object
|
// Item may not have upd object
|
||||||
if (!itemToFold.upd)
|
this.itemHelper.addUpdObjectToItem(itemToFold);
|
||||||
{
|
|
||||||
itemToFold.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
itemToFold.upd.Foldable = { Folded: request.value };
|
itemToFold.upd.Foldable = { Folded: request.value };
|
||||||
|
|
||||||
@ -494,13 +491,10 @@ export class InventoryController
|
|||||||
const itemToToggle = playerData.Inventory.items.find((x) => x._id === body.item);
|
const itemToToggle = playerData.Inventory.items.find((x) => x._id === body.item);
|
||||||
if (itemToToggle)
|
if (itemToToggle)
|
||||||
{
|
{
|
||||||
if (!itemToToggle.upd)
|
this.itemHelper.addUpdObjectToItem(
|
||||||
{
|
itemToToggle,
|
||||||
this.logger.warning(
|
this.localisationService.getText("inventory-item_to_toggle_missing_upd", itemToToggle._id),
|
||||||
this.localisationService.getText("inventory-item_to_toggle_missing_upd", itemToToggle._id),
|
);
|
||||||
);
|
|
||||||
itemToToggle.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
itemToToggle.upd.Togglable = { On: body.value };
|
itemToToggle.upd.Togglable = { On: body.value };
|
||||||
|
|
||||||
|
@ -712,10 +712,8 @@ export class BotLootGenerator
|
|||||||
|
|
||||||
const currencyWeight = currencyWeights[moneyItem._tpl];
|
const currencyWeight = currencyWeights[moneyItem._tpl];
|
||||||
|
|
||||||
if (!moneyItem.upd)
|
this.itemHelper.addUpdObjectToItem(moneyItem);
|
||||||
{
|
|
||||||
moneyItem.upd = {};
|
|
||||||
}
|
|
||||||
moneyItem.upd.StackObjectsCount = Number.parseInt(this.weightedRandomHelper.getWeightedValue(currencyWeight));
|
moneyItem.upd.StackObjectsCount = Number.parseInt(this.weightedRandomHelper.getWeightedValue(currencyWeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,10 +732,7 @@ export class BotLootGenerator
|
|||||||
Math.min(itemTemplate._props.StackMaxRandom, 60),
|
Math.min(itemTemplate._props.StackMaxRandom, 60),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!ammoItem.upd)
|
this.itemHelper.addUpdObjectToItem(ammoItem);
|
||||||
{
|
|
||||||
ammoItem.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
ammoItem.upd.StackObjectsCount = randomSize;
|
ammoItem.upd.StackObjectsCount = randomSize;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,6 @@ export class RagfairOfferGenerator
|
|||||||
|
|
||||||
const itemsClone = this.jsonUtil.clone(items);
|
const itemsClone = this.jsonUtil.clone(items);
|
||||||
|
|
||||||
|
|
||||||
// Add cartridges to offers for ammo boxes
|
// Add cartridges to offers for ammo boxes
|
||||||
if (this.itemHelper.isOfBaseclass(itemsClone[0]._tpl, BaseClasses.AMMO_BOX))
|
if (this.itemHelper.isOfBaseclass(itemsClone[0]._tpl, BaseClasses.AMMO_BOX))
|
||||||
{
|
{
|
||||||
@ -690,10 +689,7 @@ export class RagfairOfferGenerator
|
|||||||
);
|
);
|
||||||
if (this.randomUtil.getChance100(25) && visorMod)
|
if (this.randomUtil.getChance100(25) && visorMod)
|
||||||
{
|
{
|
||||||
if (!visorMod.upd)
|
this.itemHelper.addUpdObjectToItem(visorMod);
|
||||||
{
|
|
||||||
visorMod.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
visorMod.upd.FaceShield = { Hits: this.randomUtil.getInt(1, 3) };
|
visorMod.upd.FaceShield = { Hits: this.randomUtil.getInt(1, 3) };
|
||||||
}
|
}
|
||||||
@ -795,10 +791,7 @@ export class RagfairOfferGenerator
|
|||||||
const itemDbDetails = this.itemHelper.getItem(armorItem._tpl)[1];
|
const itemDbDetails = this.itemHelper.getItem(armorItem._tpl)[1];
|
||||||
if ((parseInt(<string>itemDbDetails._props.armorClass)) > 1)
|
if ((parseInt(<string>itemDbDetails._props.armorClass)) > 1)
|
||||||
{
|
{
|
||||||
if (!armorItem.upd)
|
this.itemHelper.addUpdObjectToItem(armorItem);
|
||||||
{
|
|
||||||
armorItem.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const lowestMaxDurability = this.randomUtil.getFloat(maxMultiplier, 1)
|
const lowestMaxDurability = this.randomUtil.getFloat(maxMultiplier, 1)
|
||||||
* itemDbDetails._props.MaxDurability;
|
* itemDbDetails._props.MaxDurability;
|
||||||
|
@ -110,10 +110,8 @@ export class HideoutHelper
|
|||||||
const toolItem = this.jsonUtil.clone(pmcData.Inventory.items.find((x) => x._id === tool.id));
|
const toolItem = this.jsonUtil.clone(pmcData.Inventory.items.find((x) => x._id === tool.id));
|
||||||
|
|
||||||
// Make sure we only return as many as we took
|
// Make sure we only return as many as we took
|
||||||
if (!toolItem.upd)
|
this.itemHelper.addUpdObjectToItem(toolItem);
|
||||||
{
|
|
||||||
toolItem.upd = {};
|
|
||||||
}
|
|
||||||
toolItem.upd.StackObjectsCount = tool.count;
|
toolItem.upd.StackObjectsCount = tool.count;
|
||||||
|
|
||||||
production.sptRequiredTools.push({
|
production.sptRequiredTools.push({
|
||||||
|
@ -68,16 +68,13 @@ export class InRaidHelper
|
|||||||
*/
|
*/
|
||||||
public addUpdToMoneyFromRaid(items: Item[]): void
|
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)
|
this.itemHelper.addUpdObjectToItem(moneyItem);
|
||||||
{
|
|
||||||
item.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
for (const item of itemWithChildren)
|
||||||
{
|
{
|
||||||
// Ensure item has upd object
|
// Ensure item has upd object
|
||||||
if (!item.upd)
|
this.itemHelper.addUpdObjectToItem(item);
|
||||||
{
|
|
||||||
item.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundInRaid)
|
if (foundInRaid)
|
||||||
{
|
{
|
||||||
|
@ -1636,6 +1636,25 @@ export class ItemHelper
|
|||||||
}
|
}
|
||||||
return itemsMap;
|
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
|
namespace ItemHelper
|
||||||
|
@ -278,33 +278,30 @@ export class QuestHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const item of questReward.items)
|
for (const rewardItem of questReward.items)
|
||||||
{
|
{
|
||||||
if (!item.upd)
|
this.itemHelper.addUpdObjectToItem(rewardItem);
|
||||||
{
|
|
||||||
item.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reward items are granted Found in Raid status
|
// Reward items are granted Found in Raid status
|
||||||
item.upd.SpawnedInSession = true;
|
rewardItem.upd.SpawnedInSession = true;
|
||||||
|
|
||||||
// Is root item, fix stacks
|
// Is root item, fix stacks
|
||||||
if (item._id === questReward.target)
|
if (rewardItem._id === questReward.target)
|
||||||
{ // Is base reward item
|
{ // Is base reward item
|
||||||
if (
|
if (
|
||||||
(item.parentId !== undefined) && (item.parentId === "hideout") // Has parentId of hideout
|
(rewardItem.parentId !== undefined) && (rewardItem.parentId === "hideout") // Has parentId of hideout
|
||||||
&& (item.upd !== undefined) && (item.upd.StackObjectsCount !== undefined) // Has upd with stackobject count
|
&& (rewardItem.upd !== undefined) && (rewardItem.upd.StackObjectsCount !== undefined) // Has upd with stackobject count
|
||||||
&& (item.upd.StackObjectsCount > 1) // More than 1 item in stack
|
&& (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.
|
// 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
|
// 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)
|
for (const target of targets)
|
||||||
{
|
{
|
||||||
target._id = item._id;
|
target._id = rewardItem._id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -313,10 +310,10 @@ export class QuestHelper
|
|||||||
if (questReward.items[0].upd.SpawnedInSession)
|
if (questReward.items[0].upd.SpawnedInSession)
|
||||||
{
|
{
|
||||||
// Propigate FiR status into child items
|
// 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;
|
questReward.target = rootItem._id;
|
||||||
|
|
||||||
// Copy over stack count otherwise reward shows as missing in client
|
// Copy over stack count otherwise reward shows as missing in client
|
||||||
if (!rootItem.upd)
|
this.itemHelper.addUpdObjectToItem(rootItem);
|
||||||
{
|
|
||||||
rootItem.upd = {};
|
|
||||||
}
|
|
||||||
rootItem.upd.StackObjectsCount = originalRewardRootItem.upd.StackObjectsCount;
|
rootItem.upd.StackObjectsCount = originalRewardRootItem.upd.StackObjectsCount;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -609,10 +604,8 @@ export class QuestHelper
|
|||||||
if (newStackSize > 0)
|
if (newStackSize > 0)
|
||||||
{
|
{
|
||||||
const item = pmcData.Inventory.items[inventoryItemIndex];
|
const item = pmcData.Inventory.items[inventoryItemIndex];
|
||||||
if (!item.upd)
|
this.itemHelper.addUpdObjectToItem(item);
|
||||||
{
|
|
||||||
item.upd = {};
|
|
||||||
}
|
|
||||||
item.upd.StackObjectsCount = newStackSize;
|
item.upd.StackObjectsCount = newStackSize;
|
||||||
|
|
||||||
this.addItemStackSizeChangeIntoEventResponse(output, sessionID, item);
|
this.addItemStackSizeChangeIntoEventResponse(output, sessionID, item);
|
||||||
|
@ -917,10 +917,8 @@ export class FenceService
|
|||||||
const modItemToAdjust = armor.find((mod) =>
|
const modItemToAdjust = armor.find((mod) =>
|
||||||
mod.slotId.toLowerCase() === requiredSlot._name.toLowerCase()
|
mod.slotId.toLowerCase() === requiredSlot._name.toLowerCase()
|
||||||
);
|
);
|
||||||
if (!modItemToAdjust.upd)
|
|
||||||
{
|
this.itemHelper.addUpdObjectToItem(modItemToAdjust);
|
||||||
modItemToAdjust.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!modItemToAdjust.upd.Repairable)
|
if (!modItemToAdjust.upd.Repairable)
|
||||||
{
|
{
|
||||||
@ -973,10 +971,7 @@ export class FenceService
|
|||||||
|
|
||||||
// Find items mod to apply dura changes to
|
// Find items mod to apply dura changes to
|
||||||
const modItemToAdjust = armor.find((mod) => mod.slotId.toLowerCase() === plateSlot._name.toLowerCase());
|
const modItemToAdjust = armor.find((mod) => mod.slotId.toLowerCase() === plateSlot._name.toLowerCase());
|
||||||
if (!modItemToAdjust.upd)
|
this.itemHelper.addUpdObjectToItem(modItemToAdjust);
|
||||||
{
|
|
||||||
modItemToAdjust.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!modItemToAdjust.upd.Repairable)
|
if (!modItemToAdjust.upd.Repairable)
|
||||||
{
|
{
|
||||||
|
@ -346,44 +346,41 @@ export class InsuranceService
|
|||||||
): Item
|
): Item
|
||||||
{
|
{
|
||||||
// Get baseline item to return, clone pre raid 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
|
// Add upd if it doesnt exist
|
||||||
if (!itemToReturn.upd)
|
this.itemHelper.addUpdObjectToItem(itemToReturnClone);
|
||||||
{
|
|
||||||
itemToReturn.upd = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for slotid values that need to be updated and adjust
|
// 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
|
// 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
|
// 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
|
// Client item has durability values, Ensure values persist into server data
|
||||||
if (insuredItemFromClient?.durability)
|
if (insuredItemFromClient?.durability)
|
||||||
{
|
{
|
||||||
// Item didnt have Repairable object pre-raid, add it
|
// 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,
|
Durability: insuredItemFromClient.durability,
|
||||||
MaxDurability: insuredItemFromClient.maxDurability,
|
MaxDurability: insuredItemFromClient.maxDurability,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemToReturn.upd.Repairable.Durability = insuredItemFromClient.durability;
|
itemToReturnClone.upd.Repairable.Durability = insuredItemFromClient.durability;
|
||||||
itemToReturn.upd.Repairable.MaxDurability = insuredItemFromClient.maxDurability;
|
itemToReturnClone.upd.Repairable.MaxDurability = insuredItemFromClient.maxDurability;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,17 +388,17 @@ export class InsuranceService
|
|||||||
if (insuredItemFromClient?.hits)
|
if (insuredItemFromClient?.hits)
|
||||||
{
|
{
|
||||||
// Item didnt have faceshield object pre-raid, add it
|
// 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
|
else
|
||||||
{
|
{
|
||||||
itemToReturn.upd.FaceShield.Hits = insuredItemFromClient.hits;
|
itemToReturnClone.upd.FaceShield.Hits = insuredItemFromClient.hits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemToReturn;
|
return itemToReturnClone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user