2025-08-25 13:37:14 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  type  {  TInventoryDatabaseDocument  }  from  "../models/inventoryModels/inventoryModel.ts" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  type  {  IVoidTearParticipantInfo  }  from  "../types/requestTypes.ts" ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-24 21:41:20 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  type  {  TRarity  }  from  "warframe-public-export-plus" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  {  ExportRelics ,  ExportRewards  }  from  "warframe-public-export-plus" ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-25 13:37:14 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								import  type  {  IRngResult  }  from  "../services/rngService.ts" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  {  getRandomWeightedReward  }  from  "../services/rngService.ts" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  {  logger  }  from  "../utils/logger.ts" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  {  addMiscItems ,  combineInventoryChanges  }  from  "../services/inventoryService.ts" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  {  handleStoreItemAcquisition  }  from  "../services/purchaseService.ts" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  type  {  IInventoryChanges  }  from  "../types/purchaseTypes.ts" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  {  config  }  from  "../services/configService.ts" ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								export  const  crackRelic  =  async  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    inventory : TInventoryDatabaseDocument , 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-09 07:43:30 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    participant : IVoidTearParticipantInfo , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    inventoryChanges : IInventoryChanges  =  { } 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-26 15:42:13 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								) :  Promise < IRngResult >  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    const  relic  =  ExportRelics [ participant . VoidProjection ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-02 14:17:14 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    let  weights  =  refinementToWeights [ relic . quality ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-28 05:50:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( relic . quality  ==  "VPQ_SILVER"  &&  inventory . exceptionalRelicsAlwaysGiveBronzeReward )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-02 14:17:14 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        weights  =  {  COMMON : 1 ,  UNCOMMON : 0 ,  RARE : 0 ,  LEGENDARY : 0  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-28 05:50:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  if  ( relic . quality  ==  "VPQ_GOLD"  &&  inventory . flawlessRelicsAlwaysGiveSilverReward )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-02 14:17:14 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        weights  =  {  COMMON : 0 ,  UNCOMMON : 1 ,  RARE : 0 ,  LEGENDARY : 0  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-28 05:50:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }  else  if  ( relic . quality  ==  "VPQ_PLATINUM"  &&  inventory . radiantRelicsAlwaysGiveGoldReward )  { 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-02 14:17:14 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        weights  =  {  COMMON : 0 ,  UNCOMMON : 0 ,  RARE : 1 ,  LEGENDARY : 0  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    logger . debug ( ` opening a relic of quality  ${ relic . quality } ; rarity weights are ` ,  weights ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-08 20:49:46 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    let  reward  =  getRandomWeightedReward ( 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        ExportRewards [ relic . rewardManifest ] [ 0 ]  as  {  type :  string ;  itemCount : number ;  rarity : TRarity  } [ ] ,  // rarity is nullable in PE+ typings, but always present for relics
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        weights 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    ) ! ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-08 20:49:46 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( config . relicRewardItemCountMultiplier  !==  undefined  &&  ( config . relicRewardItemCountMultiplier  ? ?  1 )  !=  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        reward  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            . . . reward , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            itemCount : reward.itemCount  *  config . relicRewardItemCountMultiplier 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    logger . debug ( ` relic rolled ` ,  reward ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    participant . Reward  =  reward . type ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Remove relic
 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-09 07:43:30 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    const  miscItemChanges  =  [ 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ItemType : participant.VoidProjection , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ItemCount :  - 1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-09 07:43:30 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    addMiscItems ( inventory ,  miscItemChanges ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    combineInventoryChanges ( inventoryChanges ,  {  MiscItems : miscItemChanges  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Give reward
 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-09 07:43:30 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    combineInventoryChanges ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        inventoryChanges , 
							 
						 
					
						
							
								
									
										
										
										
											2025-07-08 20:49:46 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        ( await  handleStoreItemAcquisition ( reward . type ,  inventory ,  reward . itemCount ) ) . InventoryChanges 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-09 07:43:30 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-26 15:42:13 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  reward ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-02-25 04:38:47 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								const  refinementToWeights  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    VPQ_BRONZE :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        COMMON : 0.76 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        UNCOMMON : 0.22 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        RARE : 0.02 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        LEGENDARY : 0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    VPQ_SILVER :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        COMMON : 0.7 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        UNCOMMON : 0.26 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        RARE : 0.04 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        LEGENDARY : 0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    VPQ_GOLD :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        COMMON : 0.6 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        UNCOMMON : 0.34 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        RARE : 0.06 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        LEGENDARY : 0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    VPQ_PLATINUM :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        COMMON : 0.5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        UNCOMMON : 0.4 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        RARE : 0.1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        LEGENDARY : 0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ;