faithful cleanup of UsedDailyDeals
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (pull_request) Successful in 56s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (pull_request) Successful in 56s
				
			This commit is contained in:
		
							parent
							
								
									a75f7e0a5b
								
							
						
					
					
						commit
						cff01898b7
					
				@ -24,6 +24,8 @@ import { IPersonalRoomsClient } from "@/src/types/personalRoomsTypes";
 | 
				
			|||||||
import { Ship } from "@/src/models/shipModel";
 | 
					import { Ship } from "@/src/models/shipModel";
 | 
				
			||||||
import { toLegacyOid, toOid, version_compare } from "@/src/helpers/inventoryHelpers";
 | 
					import { toLegacyOid, toOid, version_compare } from "@/src/helpers/inventoryHelpers";
 | 
				
			||||||
import { Inbox } from "@/src/models/inboxModel";
 | 
					import { Inbox } from "@/src/models/inboxModel";
 | 
				
			||||||
 | 
					import { unixTimesInMs } from "@/src/constants/timeConstants";
 | 
				
			||||||
 | 
					import { DailyDeal } from "@/src/models/worldStateModel";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const inventoryController: RequestHandler = async (request, response) => {
 | 
					export const inventoryController: RequestHandler = async (request, response) => {
 | 
				
			||||||
    const account = await getAccountForRequest(request);
 | 
					    const account = await getAccountForRequest(request);
 | 
				
			||||||
@ -37,6 +39,8 @@ export const inventoryController: RequestHandler = async (request, response) =>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Handle daily reset
 | 
					    // Handle daily reset
 | 
				
			||||||
    if (!inventory.NextRefill || Date.now() >= inventory.NextRefill.getTime()) {
 | 
					    if (!inventory.NextRefill || Date.now() >= inventory.NextRefill.getTime()) {
 | 
				
			||||||
 | 
					        const today = Math.trunc(Date.now() / 86400000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const key of allDailyAffiliationKeys) {
 | 
					        for (const key of allDailyAffiliationKeys) {
 | 
				
			||||||
            inventory[key] = 16000 + inventory.PlayerLevel * 500;
 | 
					            inventory[key] = 16000 + inventory.PlayerLevel * 500;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -47,12 +51,12 @@ export const inventoryController: RequestHandler = async (request, response) =>
 | 
				
			|||||||
        inventory.LibraryAvailableDailyTaskInfo = createLibraryDailyTask();
 | 
					        inventory.LibraryAvailableDailyTaskInfo = createLibraryDailyTask();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (inventory.NextRefill) {
 | 
					        if (inventory.NextRefill) {
 | 
				
			||||||
 | 
					            const lastLoginDay = Math.trunc(inventory.NextRefill.getTime() / 86400000) - 1;
 | 
				
			||||||
 | 
					            const daysPassed = today - lastLoginDay;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (config.noArgonCrystalDecay) {
 | 
					            if (config.noArgonCrystalDecay) {
 | 
				
			||||||
                inventory.FoundToday = undefined;
 | 
					                inventory.FoundToday = undefined;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                const lastLoginDay = Math.trunc(inventory.NextRefill.getTime() / 86400000) - 1;
 | 
					 | 
				
			||||||
                const today = Math.trunc(Date.now() / 86400000);
 | 
					 | 
				
			||||||
                const daysPassed = today - lastLoginDay;
 | 
					 | 
				
			||||||
                for (let i = 0; i != daysPassed; ++i) {
 | 
					                for (let i = 0; i != daysPassed; ++i) {
 | 
				
			||||||
                    const numArgonCrystals =
 | 
					                    const numArgonCrystals =
 | 
				
			||||||
                        inventory.MiscItems.find(x => x.ItemType == "/Lotus/Types/Items/MiscItems/ArgonCrystal")
 | 
					                        inventory.MiscItems.find(x => x.ItemType == "/Lotus/Types/Items/MiscItems/ArgonCrystal")
 | 
				
			||||||
@ -84,11 +88,29 @@ export const inventoryController: RequestHandler = async (request, response) =>
 | 
				
			|||||||
                    inventory.FoundToday = undefined;
 | 
					                    inventory.FoundToday = undefined;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (inventory.UsedDailyDeals.length != 0) {
 | 
				
			||||||
 | 
					                if (daysPassed == 1) {
 | 
				
			||||||
 | 
					                    const todayAt0Utc = today * 86400000;
 | 
				
			||||||
 | 
					                    const darvoIndex = Math.trunc((todayAt0Utc - 25200000) / (26 * unixTimesInMs.hour));
 | 
				
			||||||
 | 
					                    const darvoStart = darvoIndex * (26 * unixTimesInMs.hour) + 25200000;
 | 
				
			||||||
 | 
					                    const darvoOid =
 | 
				
			||||||
 | 
					                        ((darvoStart / 1000) & 0xffffffff).toString(16).padStart(8, "0") + "adc51a72f7324d95";
 | 
				
			||||||
 | 
					                    const deal = await DailyDeal.findById(darvoOid);
 | 
				
			||||||
 | 
					                    if (deal) {
 | 
				
			||||||
 | 
					                        inventory.UsedDailyDeals = inventory.UsedDailyDeals.filter(x => x == deal.StoreItem); // keep only the deal that came into this new day with us
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        inventory.UsedDailyDeals = [];
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    inventory.UsedDailyDeals = [];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cleanupInventory(inventory);
 | 
					        cleanupInventory(inventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        inventory.NextRefill = new Date((Math.trunc(Date.now() / 86400000) + 1) * 86400000);
 | 
					        inventory.NextRefill = new Date((today + 1) * 86400000); // tomorrow at 0 UTC
 | 
				
			||||||
        //await inventory.save();
 | 
					        //await inventory.save();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,6 @@ const dailyDealSchema = new Schema<IDailyDealDatabase>({
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dailyDealSchema.index({ StoreItem: 1 }, { unique: true });
 | 
					dailyDealSchema.index({ StoreItem: 1 }, { unique: true });
 | 
				
			||||||
dailyDealSchema.index({ Expiry: 1 }, { expireAfterSeconds: 0 });
 | 
					dailyDealSchema.index({ Expiry: 1 }, { expireAfterSeconds: 86400 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const DailyDeal = model<IDailyDealDatabase>("DailyDeal", dailyDealSchema);
 | 
					export const DailyDeal = model<IDailyDealDatabase>("DailyDeal", dailyDealSchema);
 | 
				
			||||||
 | 
				
			|||||||
@ -1566,6 +1566,7 @@ export const populateFissures = async (worldState: IWorldState): Promise<void> =
 | 
				
			|||||||
export const populateDailyDeal = async (worldState: IWorldState): Promise<void> => {
 | 
					export const populateDailyDeal = async (worldState: IWorldState): Promise<void> => {
 | 
				
			||||||
    const dailyDeals = await DailyDeal.find({});
 | 
					    const dailyDeals = await DailyDeal.find({});
 | 
				
			||||||
    for (const dailyDeal of dailyDeals) {
 | 
					    for (const dailyDeal of dailyDeals) {
 | 
				
			||||||
 | 
					        if (dailyDeal.Expiry.getTime() > Date.now()) {
 | 
				
			||||||
            worldState.DailyDeals.push({
 | 
					            worldState.DailyDeals.push({
 | 
				
			||||||
                StoreItem: dailyDeal.StoreItem,
 | 
					                StoreItem: dailyDeal.StoreItem,
 | 
				
			||||||
                Activation: toMongoDate(dailyDeal.Activation),
 | 
					                Activation: toMongoDate(dailyDeal.Activation),
 | 
				
			||||||
@ -1577,6 +1578,7 @@ export const populateDailyDeal = async (worldState: IWorldState): Promise<void>
 | 
				
			|||||||
                AmountSold: dailyDeal.AmountSold
 | 
					                AmountSold: dailyDeal.AmountSold
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const idToBountyCycle = (id: string): number => {
 | 
					export const idToBountyCycle = (id: string): number => {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user