chore: remove consumables, recipes, etc. from array when their ItemCount becomes 0 (#1216)
Reviewed-on: #1216
This commit is contained in:
parent
6d12d90877
commit
1d091e3c4c
@ -8,7 +8,6 @@ import { HydratedDocument, Types } from "mongoose";
|
|||||||
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
|
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
|
||||||
import {
|
import {
|
||||||
IChallengeProgress,
|
IChallengeProgress,
|
||||||
IConsumable,
|
|
||||||
IFlavourItem,
|
IFlavourItem,
|
||||||
IMiscItem,
|
IMiscItem,
|
||||||
IMission,
|
IMission,
|
||||||
@ -378,7 +377,7 @@ export const addItem = async (
|
|||||||
{
|
{
|
||||||
ItemType: typeName,
|
ItemType: typeName,
|
||||||
ItemCount: quantity
|
ItemCount: quantity
|
||||||
} satisfies IConsumable
|
} satisfies ITypeCount
|
||||||
];
|
];
|
||||||
addConsumables(inventory, consumablesChanges);
|
addConsumables(inventory, consumablesChanges);
|
||||||
return {
|
return {
|
||||||
@ -1102,74 +1101,42 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addShipDecorations = (inventory: TInventoryDatabaseDocument, itemsArray: IConsumable[]): void => {
|
const applyArrayChanges = (arr: ITypeCount[], changes: ITypeCount[]): void => {
|
||||||
const { ShipDecorations } = inventory;
|
for (const change of changes) {
|
||||||
|
if (change.ItemCount != 0) {
|
||||||
|
let itemIndex = arr.findIndex(x => x.ItemType === change.ItemType);
|
||||||
|
if (itemIndex == -1) {
|
||||||
|
itemIndex = arr.push({ ItemType: change.ItemType, ItemCount: 0 }) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
itemsArray.forEach(({ ItemCount, ItemType }) => {
|
arr[itemIndex].ItemCount += change.ItemCount;
|
||||||
const itemIndex = ShipDecorations.findIndex(miscItem => miscItem.ItemType === ItemType);
|
if (arr[itemIndex].ItemCount == 0) {
|
||||||
|
arr.splice(itemIndex, 1);
|
||||||
if (itemIndex !== -1) {
|
} else if (arr[itemIndex].ItemCount <= 0) {
|
||||||
ShipDecorations[itemIndex].ItemCount += ItemCount;
|
logger.warn(`account now owns a negative amount of ${change.ItemType}`);
|
||||||
} else {
|
}
|
||||||
ShipDecorations.push({ ItemCount, ItemType });
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addConsumables = (inventory: TInventoryDatabaseDocument, itemsArray: IConsumable[]): void => {
|
export const addShipDecorations = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
||||||
const { Consumables } = inventory;
|
applyArrayChanges(inventory.ShipDecorations, itemsArray);
|
||||||
|
};
|
||||||
|
|
||||||
itemsArray.forEach(({ ItemCount, ItemType }) => {
|
export const addConsumables = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
||||||
const itemIndex = Consumables.findIndex(i => i.ItemType === ItemType);
|
applyArrayChanges(inventory.Consumables, itemsArray);
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
|
||||||
Consumables[itemIndex].ItemCount += ItemCount;
|
|
||||||
} else {
|
|
||||||
Consumables.push({ ItemCount, ItemType });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addCrewShipRawSalvage = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
export const addCrewShipRawSalvage = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
||||||
const { CrewShipRawSalvage } = inventory;
|
applyArrayChanges(inventory.CrewShipRawSalvage, itemsArray);
|
||||||
|
|
||||||
itemsArray.forEach(({ ItemCount, ItemType }) => {
|
|
||||||
const itemIndex = CrewShipRawSalvage.findIndex(i => i.ItemType === ItemType);
|
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
|
||||||
CrewShipRawSalvage[itemIndex].ItemCount += ItemCount;
|
|
||||||
} else {
|
|
||||||
CrewShipRawSalvage.push({ ItemCount, ItemType });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addCrewShipAmmo = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
export const addCrewShipAmmo = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
||||||
const { CrewShipAmmo } = inventory;
|
applyArrayChanges(inventory.CrewShipAmmo, itemsArray);
|
||||||
|
|
||||||
itemsArray.forEach(({ ItemCount, ItemType }) => {
|
|
||||||
const itemIndex = CrewShipAmmo.findIndex(i => i.ItemType === ItemType);
|
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
|
||||||
CrewShipAmmo[itemIndex].ItemCount += ItemCount;
|
|
||||||
} else {
|
|
||||||
CrewShipAmmo.push({ ItemCount, ItemType });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addRecipes = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
export const addRecipes = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
||||||
const { Recipes } = inventory;
|
applyArrayChanges(inventory.Recipes, itemsArray);
|
||||||
|
|
||||||
itemsArray.forEach(({ ItemCount, ItemType }) => {
|
|
||||||
const itemIndex = Recipes.findIndex(i => i.ItemType === ItemType);
|
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
|
||||||
Recipes[itemIndex].ItemCount += ItemCount;
|
|
||||||
} else {
|
|
||||||
Recipes.push({ ItemCount, ItemType });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawUpgrade[]): void => {
|
export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawUpgrade[]): void => {
|
||||||
|
@ -236,8 +236,8 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
|
|||||||
FusionTreasures: IFusionTreasure[];
|
FusionTreasures: IFusionTreasure[];
|
||||||
WebFlags: IWebFlags;
|
WebFlags: IWebFlags;
|
||||||
CompletedAlerts: string[];
|
CompletedAlerts: string[];
|
||||||
Consumables: IConsumable[];
|
Consumables: ITypeCount[];
|
||||||
LevelKeys: IConsumable[];
|
LevelKeys: ITypeCount[];
|
||||||
TauntHistory?: ITaunt[];
|
TauntHistory?: ITaunt[];
|
||||||
StoryModeChoice: string;
|
StoryModeChoice: string;
|
||||||
PeriodicMissionCompletions: IPeriodicMissionCompletionDatabase[];
|
PeriodicMissionCompletions: IPeriodicMissionCompletionDatabase[];
|
||||||
@ -265,7 +265,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
|
|||||||
Drones: IDroneClient[];
|
Drones: IDroneClient[];
|
||||||
StepSequencers: IStepSequencer[];
|
StepSequencers: IStepSequencer[];
|
||||||
ActiveAvatarImageType: string;
|
ActiveAvatarImageType: string;
|
||||||
ShipDecorations: IConsumable[];
|
ShipDecorations: ITypeCount[];
|
||||||
DiscoveredMarkers: IDiscoveredMarker[];
|
DiscoveredMarkers: IDiscoveredMarker[];
|
||||||
CompletedJobs: ICompletedJob[];
|
CompletedJobs: ICompletedJob[];
|
||||||
FocusAbility?: string;
|
FocusAbility?: string;
|
||||||
@ -293,7 +293,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
|
|||||||
Settings: ISettings;
|
Settings: ISettings;
|
||||||
PersonalTechProjects: IPersonalTechProject[];
|
PersonalTechProjects: IPersonalTechProject[];
|
||||||
PlayerSkills: IPlayerSkills;
|
PlayerSkills: IPlayerSkills;
|
||||||
CrewShipAmmo: IConsumable[];
|
CrewShipAmmo: ITypeCount[];
|
||||||
CrewShipSalvagedWeaponSkins: IUpgradeClient[];
|
CrewShipSalvagedWeaponSkins: IUpgradeClient[];
|
||||||
CrewShipWeapons: ICrewShipWeaponClient[];
|
CrewShipWeapons: ICrewShipWeaponClient[];
|
||||||
CrewShipSalvagedWeapons: IEquipmentClient[];
|
CrewShipSalvagedWeapons: IEquipmentClient[];
|
||||||
@ -303,7 +303,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
|
|||||||
SubscribedToEmailsPersonalized: number;
|
SubscribedToEmailsPersonalized: number;
|
||||||
InfestedFoundry?: IInfestedFoundryClient;
|
InfestedFoundry?: IInfestedFoundryClient;
|
||||||
BlessingCooldown?: IMongoDate;
|
BlessingCooldown?: IMongoDate;
|
||||||
CrewShipRawSalvage: IConsumable[];
|
CrewShipRawSalvage: ITypeCount[];
|
||||||
CrewMembers: ICrewMember[];
|
CrewMembers: ICrewMember[];
|
||||||
LotusCustomization: ILotusCustomization;
|
LotusCustomization: ILotusCustomization;
|
||||||
UseAdultOperatorLoadout?: boolean;
|
UseAdultOperatorLoadout?: boolean;
|
||||||
@ -417,11 +417,6 @@ export interface ICompletedJob {
|
|||||||
StageCompletions: number[];
|
StageCompletions: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IConsumable {
|
|
||||||
ItemCount: number;
|
|
||||||
ItemType: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ICrewMember {
|
export interface ICrewMember {
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
NemesisFingerprint: number;
|
NemesisFingerprint: number;
|
||||||
@ -891,7 +886,7 @@ export enum GettingSlotOrderInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IGiving {
|
export interface IGiving {
|
||||||
RawUpgrades: IConsumable[];
|
RawUpgrades: ITypeCount[];
|
||||||
_SlotOrderInfo: GivingSlotOrderInfo[];
|
_SlotOrderInfo: GivingSlotOrderInfo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,7 +919,7 @@ export interface IPersonalTechProject {
|
|||||||
State: number;
|
State: number;
|
||||||
ReqCredits: number;
|
ReqCredits: number;
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
ReqItems: IConsumable[];
|
ReqItems: ITypeCount[];
|
||||||
CompletionDate?: IMongoDate;
|
CompletionDate?: IMongoDate;
|
||||||
ItemId: IOid;
|
ItemId: IOid;
|
||||||
ProductCategory?: string;
|
ProductCategory?: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user