Handle adding booster in addItem #2146
@ -819,6 +819,9 @@ export const addItem = async (
 | 
			
		||||
                        return addMotorcycle(inventory, typeName);
 | 
			
		||||
                    }
 | 
			
		||||
                    break;
 | 
			
		||||
                case "Boosters":
 | 
			
		||||
                    // e.g. RadioLegionIntermission2Syndicate Level 14
 | 
			
		||||
                    return addBooster(typeName, quantity * 24 * 60 * 60, inventory); // assume each quantity is 1 day
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
@ -1796,19 +1799,33 @@ export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag,
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const addBooster = (ItemType: string, time: number, inventory: TInventoryDatabaseDocument): void => {
 | 
			
		||||
export const addBooster = (
 | 
			
		||||
    ItemType: string,
 | 
			
		||||
    time: number,
 | 
			
		||||
    inventory: TInventoryDatabaseDocument,
 | 
			
		||||
    inventoryChanges: IInventoryChanges = {}
 | 
			
		||||
): IInventoryChanges => {
 | 
			
		||||
    const currentTime = Math.floor(Date.now() / 1000);
 | 
			
		||||
 | 
			
		||||
    const { Boosters } = inventory;
 | 
			
		||||
 | 
			
		||||
    const itemIndex = Boosters.findIndex(booster => booster.ItemType === ItemType);
 | 
			
		||||
 | 
			
		||||
    if (itemIndex !== -1) {
 | 
			
		||||
        const existingBooster = Boosters[itemIndex];
 | 
			
		||||
        existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, currentTime) + time;
 | 
			
		||||
    const item = Boosters.find(booster => booster.ItemType === ItemType);
 | 
			
		||||
    if (item) {
 | 
			
		||||
        item.ExpiryDate = Math.max(item.ExpiryDate, currentTime) + time;
 | 
			
		||||
        combineInventoryChanges(inventoryChanges, {
 | 
			
		||||
            Boosters: [
 | 
			
		||||
                {
 | 
			
		||||
                    ItemType,
 | 
			
		||||
                    ExpiryDate: item.ExpiryDate
 | 
			
		||||
                }
 | 
			
		||||
            ]
 | 
			
		||||
        });
 | 
			
		||||
    } else {
 | 
			
		||||
        Boosters.push({ ItemType, ExpiryDate: currentTime + time });
 | 
			
		||||
        const toAdditem = { ItemType, ExpiryDate: currentTime + time };
 | 
			
		||||
        Boosters.push(toAdditem);
 | 
			
		||||
        combineInventoryChanges(inventoryChanges, { Boosters: [toAdditem] });
 | 
			
		||||
    }
 | 
			
		||||
    return inventoryChanges;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const updateSyndicate = (
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user