forked from OpenWF/SpaceNinjaServer
		
	chore: get rid of instances of markModified (#908)
Closes #904 Reviewed-on: http://209.141.38.3/OpenWF/SpaceNinjaServer/pulls/908 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>
This commit is contained in:
		
							parent
							
								
									1c82b90033
								
							
						
					
					
						commit
						8175deb023
					
				@ -12,7 +12,7 @@ export const artifactsController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const { Upgrade, LevelDiff, Cost, FusionPointCost } = artifactsData;
 | 
			
		||||
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
    const { Upgrades, RawUpgrades } = inventory;
 | 
			
		||||
    const { Upgrades } = inventory;
 | 
			
		||||
    const { ItemType, UpgradeFingerprint, ItemId } = Upgrade;
 | 
			
		||||
 | 
			
		||||
    const safeUpgradeFingerprint = UpgradeFingerprint || '{"lvl":0}';
 | 
			
		||||
@ -32,13 +32,7 @@ export const artifactsController: RequestHandler = async (req, res) => {
 | 
			
		||||
                ItemType
 | 
			
		||||
            }) - 1;
 | 
			
		||||
 | 
			
		||||
        const rawItemIndex = RawUpgrades.findIndex(rawUpgrade => rawUpgrade.ItemType === ItemType);
 | 
			
		||||
        RawUpgrades[rawItemIndex].ItemCount--;
 | 
			
		||||
        if (RawUpgrades[rawItemIndex].ItemCount > 0) {
 | 
			
		||||
            inventory.markModified(`RawUpgrades.${rawItemIndex}.UpgradeFingerprint`);
 | 
			
		||||
        } else {
 | 
			
		||||
            RawUpgrades.splice(rawItemIndex, 1);
 | 
			
		||||
        }
 | 
			
		||||
        addMods(inventory, [{ ItemType, ItemCount: -1 }]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!config.infiniteCredits) {
 | 
			
		||||
 | 
			
		||||
@ -25,6 +25,7 @@ import {
 | 
			
		||||
    ISettings,
 | 
			
		||||
    IInfestedFoundryDatabase,
 | 
			
		||||
    IHelminthResource,
 | 
			
		||||
    IMissionDatabase,
 | 
			
		||||
    IConsumedSuit,
 | 
			
		||||
    IQuestStage,
 | 
			
		||||
    IQuestKeyDatabase,
 | 
			
		||||
@ -482,6 +483,15 @@ const helminthResourceSchema = new Schema<IHelminthResource>(
 | 
			
		||||
    { _id: false }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
const missionSchema = new Schema<IMissionDatabase>(
 | 
			
		||||
    {
 | 
			
		||||
        Tag: String,
 | 
			
		||||
        Completes: { type: Number, default: 0 },
 | 
			
		||||
        Tier: { type: Number, required: false }
 | 
			
		||||
    },
 | 
			
		||||
    { _id: false }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
const questProgressSchema = new Schema<IQuestStage>(
 | 
			
		||||
    {
 | 
			
		||||
        c: Number,
 | 
			
		||||
@ -1010,7 +1020,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
 | 
			
		||||
        CrewShipSalvagedWeapons: [Schema.Types.Mixed],
 | 
			
		||||
 | 
			
		||||
        //Complete Mission\Quests
 | 
			
		||||
        Missions: [Schema.Types.Mixed],
 | 
			
		||||
        Missions: [missionSchema],
 | 
			
		||||
        QuestKeys: [questKeysSchema],
 | 
			
		||||
        ActiveQuest: { type: String, default: "/Lotus/Types/Keys/VorsPrize/VorsPrizeQuestKeyChain" }, //TODO: check after mission starting gear
 | 
			
		||||
        //item like DojoKey or Boss missions key
 | 
			
		||||
 | 
			
		||||
@ -906,7 +906,6 @@ export const addShipDecorations = (
 | 
			
		||||
 | 
			
		||||
        if (itemIndex !== -1) {
 | 
			
		||||
            ShipDecorations[itemIndex].ItemCount += ItemCount;
 | 
			
		||||
            inventory.markModified(`ShipDecorations.${itemIndex}.ItemCount`);
 | 
			
		||||
        } else {
 | 
			
		||||
            ShipDecorations.push({ ItemCount, ItemType });
 | 
			
		||||
        }
 | 
			
		||||
@ -921,7 +920,6 @@ export const addConsumables = (inventory: TInventoryDatabaseDocument, itemsArray
 | 
			
		||||
 | 
			
		||||
        if (itemIndex !== -1) {
 | 
			
		||||
            Consumables[itemIndex].ItemCount += ItemCount;
 | 
			
		||||
            inventory.markModified(`Consumables.${itemIndex}.ItemCount`);
 | 
			
		||||
        } else {
 | 
			
		||||
            Consumables.push({ ItemCount, ItemType });
 | 
			
		||||
        }
 | 
			
		||||
@ -967,7 +965,6 @@ export const addRecipes = (inventory: TInventoryDatabaseDocument, itemsArray: IT
 | 
			
		||||
 | 
			
		||||
        if (itemIndex !== -1) {
 | 
			
		||||
            Recipes[itemIndex].ItemCount += ItemCount;
 | 
			
		||||
            inventory.markModified(`Recipes.${itemIndex}.ItemCount`);
 | 
			
		||||
        } else {
 | 
			
		||||
            Recipes.push({ ItemCount, ItemType });
 | 
			
		||||
        }
 | 
			
		||||
@ -1006,7 +1003,6 @@ export const addFusionTreasures = (
 | 
			
		||||
 | 
			
		||||
        if (itemIndex !== -1) {
 | 
			
		||||
            FusionTreasures[itemIndex].ItemCount += ItemCount;
 | 
			
		||||
            inventory.markModified(`FusionTreasures.${itemIndex}.ItemCount`);
 | 
			
		||||
        } else {
 | 
			
		||||
            FusionTreasures.push({ ItemCount, ItemType, Sockets });
 | 
			
		||||
        }
 | 
			
		||||
@ -1077,7 +1073,6 @@ export const addChallenges = (
 | 
			
		||||
 | 
			
		||||
        if (itemIndex !== -1) {
 | 
			
		||||
            category[itemIndex].Progress += Progress;
 | 
			
		||||
            inventory.markModified(`ChallengeProgress.${itemIndex}.ItemCount`);
 | 
			
		||||
        } else {
 | 
			
		||||
            category.push({ Name, Progress });
 | 
			
		||||
        }
 | 
			
		||||
@ -1090,7 +1085,6 @@ export const addMissionComplete = (inventory: TInventoryDatabaseDocument, { Tag,
 | 
			
		||||
 | 
			
		||||
    if (itemIndex !== -1) {
 | 
			
		||||
        Missions[itemIndex].Completes += Completes;
 | 
			
		||||
        inventory.markModified(`Missions.${itemIndex}.Completes`);
 | 
			
		||||
    } else {
 | 
			
		||||
        Missions.push({ Tag, Completes });
 | 
			
		||||
    }
 | 
			
		||||
@ -1106,7 +1100,6 @@ export const addBooster = (ItemType: string, time: number, inventory: TInventory
 | 
			
		||||
    if (itemIndex !== -1) {
 | 
			
		||||
        const existingBooster = Boosters[itemIndex];
 | 
			
		||||
        existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, currentTime) + time;
 | 
			
		||||
        inventory.markModified(`Boosters.${itemIndex}.ExpiryDate`);
 | 
			
		||||
    } else {
 | 
			
		||||
        Boosters.push({ ItemType, ExpiryDate: currentTime + time });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -753,10 +753,13 @@ export interface ILotusCustomization extends IItemConfig {
 | 
			
		||||
    Persona: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IMission {
 | 
			
		||||
export interface IMissionDatabase {
 | 
			
		||||
    Tag: string;
 | 
			
		||||
    Completes: number;
 | 
			
		||||
    Tier?: number;
 | 
			
		||||
    Tag: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IMission extends IMissionDatabase {
 | 
			
		||||
    RewardsCooldownTime?: IMongoDate;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user