remove ITypeCount array entries at ItemCount 0
All checks were successful
Build / build (20) (push) Successful in 43s
Build / build (18) (push) Successful in 1m10s
Build / build (22) (push) Successful in 1m10s
Build / build (18) (pull_request) Successful in 43s
Build / build (20) (pull_request) Successful in 1m6s
Build / build (22) (pull_request) Successful in 1m9s
All checks were successful
Build / build (20) (push) Successful in 43s
Build / build (18) (push) Successful in 1m10s
Build / build (22) (push) Successful in 1m10s
Build / build (18) (pull_request) Successful in 43s
Build / build (20) (pull_request) Successful in 1m6s
Build / build (22) (pull_request) Successful in 1m9s
This commit is contained in:
parent
d16bf5a308
commit
8dd17014fb
@ -1101,74 +1101,42 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addShipDecorations = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
const applyArrayChanges = (arr: ITypeCount[], changes: ITypeCount[]): void => {
|
||||||
const { ShipDecorations } = inventory;
|
for (const change of changes) {
|
||||||
|
if (change.ItemCount != 0) {
|
||||||
itemsArray.forEach(({ ItemCount, ItemType }) => {
|
let itemIndex = arr.findIndex(x => x.ItemType === change.ItemType);
|
||||||
const itemIndex = ShipDecorations.findIndex(miscItem => miscItem.ItemType === ItemType);
|
if (itemIndex == -1) {
|
||||||
|
itemIndex = arr.push({ ItemType: change.ItemType, ItemCount: 0 }) - 1;
|
||||||
if (itemIndex !== -1) {
|
|
||||||
ShipDecorations[itemIndex].ItemCount += ItemCount;
|
|
||||||
} else {
|
|
||||||
ShipDecorations.push({ ItemCount, ItemType });
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const addShipDecorations = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
||||||
|
applyArrayChanges(inventory.ShipDecorations, itemsArray);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addConsumables = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
export const addConsumables = (inventory: TInventoryDatabaseDocument, itemsArray: ITypeCount[]): void => {
|
||||||
const { Consumables } = inventory;
|
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 => {
|
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 => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user