Handle adding booster in addItem
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (pull_request) Successful in 1m13s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (pull_request) Successful in 1m13s
				
			This commit is contained in:
		
							parent
							
								
									60236a1154
								
							
						
					
					
						commit
						4910de959a
					
				@ -819,6 +819,9 @@ export const addItem = async (
 | 
				
			|||||||
                        return addMotorcycle(inventory, typeName);
 | 
					                        return addMotorcycle(inventory, typeName);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
 | 
					                case "Boosters":
 | 
				
			||||||
 | 
					                    // e.g. RadioLegionIntermission2Syndicate Level 14
 | 
				
			||||||
 | 
					                    return addBooster(typeName, quantity * 24 * 60 * 60, inventory); // assume each quantity is 1 day
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            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 currentTime = Math.floor(Date.now() / 1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const { Boosters } = inventory;
 | 
					    const { Boosters } = inventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const itemIndex = Boosters.findIndex(booster => booster.ItemType === ItemType);
 | 
					    const item = Boosters.find(booster => booster.ItemType === ItemType);
 | 
				
			||||||
 | 
					    if (item) {
 | 
				
			||||||
    if (itemIndex !== -1) {
 | 
					        item.ExpiryDate = Math.max(item.ExpiryDate, currentTime) + time;
 | 
				
			||||||
        const existingBooster = Boosters[itemIndex];
 | 
					        combineInventoryChanges(inventoryChanges, {
 | 
				
			||||||
        existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, currentTime) + time;
 | 
					            Boosters: [
 | 
				
			||||||
    } else {
 | 
					                {
 | 
				
			||||||
        Boosters.push({ ItemType, ExpiryDate: currentTime + time });
 | 
					                    ItemType,
 | 
				
			||||||
 | 
					                    ExpiryDate: item.ExpiryDate
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        const toAdditem = { ItemType, ExpiryDate: currentTime + time };
 | 
				
			||||||
 | 
					        Boosters.push(toAdditem);
 | 
				
			||||||
 | 
					        combineInventoryChanges(inventoryChanges, { Boosters: [toAdditem] });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return inventoryChanges;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const updateSyndicate = (
 | 
					export const updateSyndicate = (
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user