fix: 'account now owns a negative amount' not showing when it had 0 (#877)
This commit is contained in:
		
							parent
							
								
									50c280cf01
								
							
						
					
					
						commit
						9de87f0959
					
				@ -819,19 +819,20 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
 | 
				
			|||||||
    const { MiscItems } = inventory;
 | 
					    const { MiscItems } = inventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
					    itemsArray?.forEach(({ ItemCount, ItemType }) => {
 | 
				
			||||||
        const itemIndex = MiscItems.findIndex(miscItem => miscItem.ItemType === ItemType);
 | 
					        if (ItemCount == 0) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (itemIndex !== -1) {
 | 
					        let itemIndex = MiscItems.findIndex(x => x.ItemType === ItemType);
 | 
				
			||||||
            MiscItems[itemIndex].ItemCount += ItemCount;
 | 
					        if (itemIndex == -1) {
 | 
				
			||||||
            if (MiscItems[itemIndex].ItemCount <= 0) {
 | 
					            itemIndex = MiscItems.push({ ItemType, ItemCount: 0 }) - 1;
 | 
				
			||||||
                if (MiscItems[itemIndex].ItemCount == 0) {
 | 
					        }
 | 
				
			||||||
                    MiscItems.splice(itemIndex, 1);
 | 
					
 | 
				
			||||||
                } else {
 | 
					        MiscItems[itemIndex].ItemCount += ItemCount;
 | 
				
			||||||
                    logger.warn(`account now owns a negative amount of ${ItemType}`);
 | 
					        if (MiscItems[itemIndex].ItemCount == 0) {
 | 
				
			||||||
                }
 | 
					            MiscItems.splice(itemIndex, 1);
 | 
				
			||||||
            }
 | 
					        } else if (MiscItems[itemIndex].ItemCount <= 0) {
 | 
				
			||||||
        } else {
 | 
					            logger.warn(`account now owns a negative amount of ${ItemType}`);
 | 
				
			||||||
            MiscItems.push({ ItemCount, ItemType });
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -886,20 +887,22 @@ export const addRecipes = (inventory: TInventoryDatabaseDocument, itemsArray: IT
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawUpgrade[] | undefined): void => {
 | 
					export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawUpgrade[] | undefined): void => {
 | 
				
			||||||
    const { RawUpgrades } = inventory;
 | 
					    const { RawUpgrades } = inventory;
 | 
				
			||||||
    itemsArray?.forEach(({ ItemType, ItemCount }) => {
 | 
					 | 
				
			||||||
        const itemIndex = RawUpgrades.findIndex(i => i.ItemType === ItemType);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (itemIndex !== -1) {
 | 
					    itemsArray?.forEach(({ ItemType, ItemCount }) => {
 | 
				
			||||||
            RawUpgrades[itemIndex].ItemCount += ItemCount;
 | 
					        if (ItemCount == 0) {
 | 
				
			||||||
            if (RawUpgrades[itemIndex].ItemCount <= 0) {
 | 
					            return;
 | 
				
			||||||
                if (RawUpgrades[itemIndex].ItemCount == 0) {
 | 
					        }
 | 
				
			||||||
                    RawUpgrades.splice(itemIndex, 1);
 | 
					
 | 
				
			||||||
                } else {
 | 
					        let itemIndex = RawUpgrades.findIndex(x => x.ItemType === ItemType);
 | 
				
			||||||
                    logger.warn(`account now owns a negative amount of ${ItemType}`);
 | 
					        if (itemIndex == -1) {
 | 
				
			||||||
                }
 | 
					            itemIndex = RawUpgrades.push({ ItemType, ItemCount: 0 }) - 1;
 | 
				
			||||||
            }
 | 
					        }
 | 
				
			||||||
        } else {
 | 
					
 | 
				
			||||||
            RawUpgrades.push({ ItemCount, ItemType });
 | 
					        RawUpgrades[itemIndex].ItemCount += ItemCount;
 | 
				
			||||||
 | 
					        if (RawUpgrades[itemIndex].ItemCount == 0) {
 | 
				
			||||||
 | 
					            RawUpgrades.splice(itemIndex, 1);
 | 
				
			||||||
 | 
					        } else if (RawUpgrades[itemIndex].ItemCount <= 0) {
 | 
				
			||||||
 | 
					            logger.warn(`account now owns a negative amount of ${ItemType}`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user