Compare commits

..

No commits in common. "8dd17014fbef7d2f66f8b693d59d197f4be02522" and "c3a9b42fa2443f83bc7a7050b8c371317d60bd5f" have entirely different histories.

2 changed files with 68 additions and 30 deletions

View File

@ -8,6 +8,7 @@ import { HydratedDocument, Types } from "mongoose";
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
import {
IChallengeProgress,
IConsumable,
IFlavourItem,
IMiscItem,
IMission,
@ -377,7 +378,7 @@ export const addItem = async (
{
ItemType: typeName,
ItemCount: quantity
} satisfies ITypeCount
} satisfies IConsumable
];
addConsumables(inventory, consumablesChanges);
return {
@ -1101,42 +1102,74 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
});
};
const applyArrayChanges = (arr: ITypeCount[], changes: ITypeCount[]): void => {
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;
}
export const addShipDecorations = (inventory: TInventoryDatabaseDocument, itemsArray: IConsumable[]): void => {
const { ShipDecorations } = inventory;
arr[itemIndex].ItemCount += change.ItemCount;
if (arr[itemIndex].ItemCount == 0) {
arr.splice(itemIndex, 1);
} else if (arr[itemIndex].ItemCount <= 0) {
logger.warn(`account now owns a negative amount of ${change.ItemType}`);
}
itemsArray.forEach(({ ItemCount, ItemType }) => {
const itemIndex = ShipDecorations.findIndex(miscItem => miscItem.ItemType === ItemType);
if (itemIndex !== -1) {
ShipDecorations[itemIndex].ItemCount += ItemCount;
} else {
ShipDecorations.push({ ItemCount, ItemType });
}
}
});
};
export const addShipDecorations = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
applyArrayChanges(inventory.ShipDecorations, itemsArray);
};
export const addConsumables = (inventory: TInventoryDatabaseDocument, itemsArray: IConsumable[]): void => {
const { Consumables } = inventory;
export const addConsumables = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
applyArrayChanges(inventory.Consumables, itemsArray);
itemsArray.forEach(({ ItemCount, ItemType }) => {
const itemIndex = Consumables.findIndex(i => i.ItemType === ItemType);
if (itemIndex !== -1) {
Consumables[itemIndex].ItemCount += ItemCount;
} else {
Consumables.push({ ItemCount, ItemType });
}
});
};
export const addCrewShipRawSalvage = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
applyArrayChanges(inventory.CrewShipRawSalvage, itemsArray);
const { CrewShipRawSalvage } = inventory;
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 => {
applyArrayChanges(inventory.CrewShipAmmo, itemsArray);
const { CrewShipAmmo } = inventory;
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 => {
applyArrayChanges(inventory.Recipes, itemsArray);
const { Recipes } = inventory;
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 => {

View File

@ -236,8 +236,8 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
FusionTreasures: IFusionTreasure[];
WebFlags: IWebFlags;
CompletedAlerts: string[];
Consumables: ITypeCount[];
LevelKeys: ITypeCount[];
Consumables: IConsumable[];
LevelKeys: IConsumable[];
TauntHistory?: ITaunt[];
StoryModeChoice: string;
PeriodicMissionCompletions: IPeriodicMissionCompletionDatabase[];
@ -265,7 +265,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
Drones: IDroneClient[];
StepSequencers: IStepSequencer[];
ActiveAvatarImageType: string;
ShipDecorations: ITypeCount[];
ShipDecorations: IConsumable[];
DiscoveredMarkers: IDiscoveredMarker[];
CompletedJobs: ICompletedJob[];
FocusAbility?: string;
@ -293,7 +293,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
Settings: ISettings;
PersonalTechProjects: IPersonalTechProject[];
PlayerSkills: IPlayerSkills;
CrewShipAmmo: ITypeCount[];
CrewShipAmmo: IConsumable[];
CrewShipSalvagedWeaponSkins: IUpgradeClient[];
CrewShipWeapons: ICrewShipWeaponClient[];
CrewShipSalvagedWeapons: IEquipmentClient[];
@ -303,7 +303,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
SubscribedToEmailsPersonalized: number;
InfestedFoundry?: IInfestedFoundryClient;
BlessingCooldown?: IMongoDate;
CrewShipRawSalvage: ITypeCount[];
CrewShipRawSalvage: IConsumable[];
CrewMembers: ICrewMember[];
LotusCustomization: ILotusCustomization;
UseAdultOperatorLoadout?: boolean;
@ -417,6 +417,11 @@ export interface ICompletedJob {
StageCompletions: number[];
}
export interface IConsumable {
ItemCount: number;
ItemType: string;
}
export interface ICrewMember {
ItemType: string;
NemesisFingerprint: number;
@ -886,7 +891,7 @@ export enum GettingSlotOrderInfo {
}
export interface IGiving {
RawUpgrades: ITypeCount[];
RawUpgrades: IConsumable[];
_SlotOrderInfo: GivingSlotOrderInfo[];
}
@ -919,7 +924,7 @@ export interface IPersonalTechProject {
State: number;
ReqCredits: number;
ItemType: string;
ReqItems: ITypeCount[];
ReqItems: IConsumable[];
CompletionDate?: IMongoDate;
ItemId: IOid;
ProductCategory?: string;