use NextRefill to handle daily reset
This commit is contained in:
		
							parent
							
								
									2f59b3d775
								
							
						
					
					
						commit
						2569e59cff
					
				@ -1,5 +1,5 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { getAccountForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
					import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
import { config } from "@/src/services/configService";
 | 
					import { config } from "@/src/services/configService";
 | 
				
			||||||
import allDialogue from "@/static/fixed_responses/allDialogue.json";
 | 
					import allDialogue from "@/static/fixed_responses/allDialogue.json";
 | 
				
			||||||
@ -17,9 +17,9 @@ import { applyCheatsToInfestedFoundry, handleSubsumeCompletion } from "./infeste
 | 
				
			|||||||
import { allDailyAffiliationKeys, createLibraryDailyTask } from "@/src/services/inventoryService";
 | 
					import { allDailyAffiliationKeys, createLibraryDailyTask } from "@/src/services/inventoryService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const inventoryController: RequestHandler = async (request, response) => {
 | 
					export const inventoryController: RequestHandler = async (request, response) => {
 | 
				
			||||||
    const account = await getAccountForRequest(request);
 | 
					    const accountId = await getAccountIdForRequest(request);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() });
 | 
					    const inventory = await Inventory.findOne({ accountOwnerId: accountId });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!inventory) {
 | 
					    if (!inventory) {
 | 
				
			||||||
        response.status(400).json({ error: "inventory was undefined" });
 | 
					        response.status(400).json({ error: "inventory was undefined" });
 | 
				
			||||||
@ -27,11 +27,7 @@ export const inventoryController: RequestHandler = async (request, response) =>
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Handle daily reset
 | 
					    // Handle daily reset
 | 
				
			||||||
    const today: number = Math.trunc(new Date().getTime() / 86400000);
 | 
					    if (!inventory.NextRefill || Date.now() >= inventory.NextRefill.getTime()) {
 | 
				
			||||||
    if (account.LastLoginDay != today) {
 | 
					 | 
				
			||||||
        account.LastLoginDay = today;
 | 
					 | 
				
			||||||
        await account.save();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (const key of allDailyAffiliationKeys) {
 | 
					        for (const key of allDailyAffiliationKeys) {
 | 
				
			||||||
            inventory[key] = 16000 + inventory.PlayerLevel * 500;
 | 
					            inventory[key] = 16000 + inventory.PlayerLevel * 500;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -39,6 +35,7 @@ export const inventoryController: RequestHandler = async (request, response) =>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        inventory.LibraryAvailableDailyTaskInfo = createLibraryDailyTask();
 | 
					        inventory.LibraryAvailableDailyTaskInfo = createLibraryDailyTask();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        inventory.NextRefill = new Date((Math.trunc(Date.now() / 86400000) + 1) * 86400000);
 | 
				
			||||||
        await inventory.save();
 | 
					        await inventory.save();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -219,9 +216,6 @@ export const getInventoryResponse = async (
 | 
				
			|||||||
        applyCheatsToInfestedFoundry(inventoryResponse.InfestedFoundry);
 | 
					        applyCheatsToInfestedFoundry(inventoryResponse.InfestedFoundry);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Fix for #380
 | 
					 | 
				
			||||||
    inventoryResponse.NextRefill = { $date: { $numberLong: "9999999999999" } };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // This determines if the "void fissures" tab is shown in navigation.
 | 
					    // This determines if the "void fissures" tab is shown in navigation.
 | 
				
			||||||
    inventoryResponse.HasOwnedVoidProjectionsPreviously = true;
 | 
					    inventoryResponse.HasOwnedVoidProjectionsPreviously = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1360,7 +1360,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
 | 
				
			|||||||
        //https://warframe.fandom.com/wiki/Helminth
 | 
					        //https://warframe.fandom.com/wiki/Helminth
 | 
				
			||||||
        InfestedFoundry: infestedFoundrySchema,
 | 
					        InfestedFoundry: infestedFoundrySchema,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        NextRefill: Schema.Types.Mixed, // Date, convert to IMongoDate
 | 
					        NextRefill: { type: Date, default: undefined },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Purchase this new permanent skin from the Lotus customization options in Personal Quarters located in your Orbiter.
 | 
					        //Purchase this new permanent skin from the Lotus customization options in Personal Quarters located in your Orbiter.
 | 
				
			||||||
        //https://warframe.fandom.com/wiki/Lotus#The_New_War
 | 
					        //https://warframe.fandom.com/wiki/Lotus#The_New_War
 | 
				
			||||||
@ -1435,6 +1435,9 @@ inventorySchema.set("toJSON", {
 | 
				
			|||||||
        if (inventoryDatabase.BlessingCooldown) {
 | 
					        if (inventoryDatabase.BlessingCooldown) {
 | 
				
			||||||
            inventoryResponse.BlessingCooldown = toMongoDate(inventoryDatabase.BlessingCooldown);
 | 
					            inventoryResponse.BlessingCooldown = toMongoDate(inventoryDatabase.BlessingCooldown);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (inventoryDatabase.NextRefill) {
 | 
				
			||||||
 | 
					            inventoryResponse.NextRefill = toMongoDate(inventoryDatabase.NextRefill);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -21,7 +21,6 @@ const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
 | 
				
			|||||||
        TrackedSettings: { type: [String], default: [] },
 | 
					        TrackedSettings: { type: [String], default: [] },
 | 
				
			||||||
        Nonce: { type: Number, default: 0 },
 | 
					        Nonce: { type: Number, default: 0 },
 | 
				
			||||||
        Dropped: Boolean,
 | 
					        Dropped: Boolean,
 | 
				
			||||||
        LastLoginDay: { type: Number },
 | 
					 | 
				
			||||||
        LatestEventMessageDate: { type: Date, default: 0 }
 | 
					        LatestEventMessageDate: { type: Date, default: 0 }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    opts
 | 
					    opts
 | 
				
			||||||
 | 
				
			|||||||
@ -42,6 +42,7 @@ export interface IInventoryDatabase
 | 
				
			|||||||
            | "PendingCoupon"
 | 
					            | "PendingCoupon"
 | 
				
			||||||
            | "Drones"
 | 
					            | "Drones"
 | 
				
			||||||
            | "RecentVendorPurchases"
 | 
					            | "RecentVendorPurchases"
 | 
				
			||||||
 | 
					            | "NextRefill"
 | 
				
			||||||
            | TEquipmentKey
 | 
					            | TEquipmentKey
 | 
				
			||||||
        >,
 | 
					        >,
 | 
				
			||||||
        InventoryDatabaseEquipment {
 | 
					        InventoryDatabaseEquipment {
 | 
				
			||||||
@ -69,6 +70,7 @@ export interface IInventoryDatabase
 | 
				
			|||||||
    PendingCoupon?: IPendingCouponDatabase;
 | 
					    PendingCoupon?: IPendingCouponDatabase;
 | 
				
			||||||
    Drones: IDroneDatabase[];
 | 
					    Drones: IDroneDatabase[];
 | 
				
			||||||
    RecentVendorPurchases?: IRecentVendorPurchaseDatabase[];
 | 
					    RecentVendorPurchases?: IRecentVendorPurchaseDatabase[];
 | 
				
			||||||
 | 
					    NextRefill?: Date;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IQuestKeyDatabase {
 | 
					export interface IQuestKeyDatabase {
 | 
				
			||||||
@ -307,7 +309,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
 | 
				
			|||||||
    UseAdultOperatorLoadout?: boolean;
 | 
					    UseAdultOperatorLoadout?: boolean;
 | 
				
			||||||
    NemesisAbandonedRewards: string[];
 | 
					    NemesisAbandonedRewards: string[];
 | 
				
			||||||
    LastInventorySync: IOid;
 | 
					    LastInventorySync: IOid;
 | 
				
			||||||
    NextRefill: IMongoDate; // Next time argon crystals will have a decay tick
 | 
					    NextRefill?: IMongoDate;
 | 
				
			||||||
    FoundToday?: IMiscItem[]; // for Argon Crystals
 | 
					    FoundToday?: IMiscItem[]; // for Argon Crystals
 | 
				
			||||||
    CustomMarkers?: ICustomMarkers[];
 | 
					    CustomMarkers?: ICustomMarkers[];
 | 
				
			||||||
    ActiveLandscapeTraps: any[];
 | 
					    ActiveLandscapeTraps: any[];
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,6 @@ export interface IDatabaseAccount extends IAccountAndLoginResponseCommons {
 | 
				
			|||||||
    email: string;
 | 
					    email: string;
 | 
				
			||||||
    password: string;
 | 
					    password: string;
 | 
				
			||||||
    Dropped?: boolean;
 | 
					    Dropped?: boolean;
 | 
				
			||||||
    LastLoginDay?: number;
 | 
					 | 
				
			||||||
    LatestEventMessageDate: Date;
 | 
					    LatestEventMessageDate: Date;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user