feat: argon crystal decay
This commit is contained in:
		
							parent
							
								
									2569e59cff
								
							
						
					
					
						commit
						449690cdac
					
				@ -14,7 +14,8 @@ import {
 | 
			
		||||
    ExportVirtuals
 | 
			
		||||
} from "warframe-public-export-plus";
 | 
			
		||||
import { applyCheatsToInfestedFoundry, handleSubsumeCompletion } from "./infestedFoundryController";
 | 
			
		||||
import { allDailyAffiliationKeys, createLibraryDailyTask } from "@/src/services/inventoryService";
 | 
			
		||||
import { addMiscItems, allDailyAffiliationKeys, createLibraryDailyTask } from "@/src/services/inventoryService";
 | 
			
		||||
import { logger } from "@/src/utils/logger";
 | 
			
		||||
 | 
			
		||||
export const inventoryController: RequestHandler = async (request, response) => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(request);
 | 
			
		||||
@ -35,6 +36,40 @@ export const inventoryController: RequestHandler = async (request, response) =>
 | 
			
		||||
 | 
			
		||||
        inventory.LibraryAvailableDailyTaskInfo = createLibraryDailyTask();
 | 
			
		||||
 | 
			
		||||
        if (inventory.NextRefill) {
 | 
			
		||||
            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) {
 | 
			
		||||
                const numArgonCrystals =
 | 
			
		||||
                    inventory.MiscItems.find(x => x.ItemType == "/Lotus/Types/Items/MiscItems/ArgonCrystal")
 | 
			
		||||
                        ?.ItemCount ?? 0;
 | 
			
		||||
                if (numArgonCrystals == 0) {
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                const numStableArgonCrystals =
 | 
			
		||||
                    inventory.FoundToday?.find(x => x.ItemType == "/Lotus/Types/Items/MiscItems/ArgonCrystal")
 | 
			
		||||
                        ?.ItemCount ?? 0;
 | 
			
		||||
                const numDecayingArgonCrystals = numArgonCrystals - numStableArgonCrystals;
 | 
			
		||||
                const numDecayingArgonCrystalsToRemove = Math.ceil(numDecayingArgonCrystals / 2);
 | 
			
		||||
                logger.debug(`ticking argon crystals for day ${i + 1} of ${daysPassed}`, {
 | 
			
		||||
                    numArgonCrystals,
 | 
			
		||||
                    numStableArgonCrystals,
 | 
			
		||||
                    numDecayingArgonCrystals,
 | 
			
		||||
                    numDecayingArgonCrystalsToRemove
 | 
			
		||||
                });
 | 
			
		||||
                // Remove half of owned decaying argon crystals
 | 
			
		||||
                addMiscItems(inventory, [
 | 
			
		||||
                    {
 | 
			
		||||
                        ItemType: "/Lotus/Types/Items/MiscItems/ArgonCrystal",
 | 
			
		||||
                        ItemCount: numDecayingArgonCrystalsToRemove * -1
 | 
			
		||||
                    }
 | 
			
		||||
                ]);
 | 
			
		||||
                // All stable argon crystals are now decaying
 | 
			
		||||
                inventory.FoundToday = undefined;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        inventory.NextRefill = new Date((Math.trunc(Date.now() / 86400000) + 1) * 86400000);
 | 
			
		||||
        await inventory.save();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -1161,7 +1161,8 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
 | 
			
		||||
        ChallengeProgress: [challengeProgressSchema],
 | 
			
		||||
 | 
			
		||||
        //Account Item like Ferrite,Form,Kuva etc
 | 
			
		||||
        MiscItems: [typeCountSchema],
 | 
			
		||||
        MiscItems: { type: [typeCountSchema], default: [] },
 | 
			
		||||
        FoundToday: { type: [typeCountSchema], default: undefined },
 | 
			
		||||
 | 
			
		||||
        //Non Upgrade Mods Example:I have 999 item WeaponElectricityDamageMod (only "ItemCount"+"ItemType")
 | 
			
		||||
        RawUpgrades: [RawUpgrades],
 | 
			
		||||
 | 
			
		||||
@ -1045,6 +1045,22 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MiscItems[itemIndex].ItemCount += ItemCount;
 | 
			
		||||
 | 
			
		||||
        if (ItemType == "/Lotus/Types/Items/MiscItems/ArgonCrystal") {
 | 
			
		||||
            inventory.FoundToday ??= [];
 | 
			
		||||
            let foundTodayIndex = inventory.FoundToday.findIndex(x => x.ItemType == ItemType);
 | 
			
		||||
            if (foundTodayIndex == -1) {
 | 
			
		||||
                foundTodayIndex = inventory.FoundToday.push({ ItemType, ItemCount: 0 }) - 1;
 | 
			
		||||
            }
 | 
			
		||||
            inventory.FoundToday[foundTodayIndex].ItemCount += ItemCount;
 | 
			
		||||
            if (inventory.FoundToday[foundTodayIndex].ItemCount <= 0) {
 | 
			
		||||
                inventory.FoundToday.splice(foundTodayIndex, 1);
 | 
			
		||||
            }
 | 
			
		||||
            if (inventory.FoundToday.length == 0) {
 | 
			
		||||
                inventory.FoundToday = undefined;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (MiscItems[itemIndex].ItemCount == 0) {
 | 
			
		||||
            MiscItems.splice(itemIndex, 1);
 | 
			
		||||
        } else if (MiscItems[itemIndex].ItemCount <= 0) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user