MissionInventoryUpdate(not completed), Mod upgrade, Booster purchase #49
@ -12,6 +12,7 @@ import resourceNames from "@/static/json/resource-names.json";
 | 
				
			|||||||
import gearNames from "@/static/json/gear-names.json";
 | 
					import gearNames from "@/static/json/gear-names.json";
 | 
				
			||||||
import arcaneNames from "@/static/json/arcane-names.json";
 | 
					import arcaneNames from "@/static/json/arcane-names.json";
 | 
				
			||||||
import craftNames from "@/static/json/craft-names.json";
 | 
					import craftNames from "@/static/json/craft-names.json";
 | 
				
			||||||
 | 
					import { RawUpgrade } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
**** INPUT ****
 | 
					**** INPUT ****
 | 
				
			||||||
@ -63,25 +64,43 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    try {
 | 
					    try {
 | 
				
			||||||
        const parsedData = JSON.parse(data) as MissionInventoryUpdate;
 | 
					        const parsedData = JSON.parse(data) as MissionInventoryUpdate;
 | 
				
			||||||
        if (typeof parsedData !== "object" || parsedData === null) throw new Error("Invalid data format");
 | 
					        if (typeof parsedData !== "object" || parsedData === null) throw new Error("Invalid data format");
 | 
				
			||||||
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
					
 | 
				
			||||||
 | 
					        const { InventoryChanges, MissionRewards } = getRewards(parsedData.RewardInfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const missionCredits = parsedData.RegularCredits || 0;
 | 
					        const missionCredits = parsedData.RegularCredits || 0;
 | 
				
			||||||
        const creditsBonus = 0;
 | 
					        const creditsBonus = InventoryChanges.RegularCredits || 1000;
 | 
				
			||||||
        const totalCredits = missionCredits + creditsBonus;
 | 
					        const totalCredits = missionCredits + creditsBonus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const MissionCredits = [missionCredits, missionCredits]; // collected credits
 | 
					        const MissionCredits = [missionCredits, missionCredits];
 | 
				
			||||||
        const CreditsBonus = [creditsBonus, creditsBonus]; // mission reward
 | 
					        const CreditsBonus = [creditsBonus, creditsBonus];
 | 
				
			||||||
        const TotalCredits = [totalCredits, totalCredits];
 | 
					        const TotalCredits = [totalCredits, totalCredits];
 | 
				
			||||||
 | 
					        const FusionPoints =
 | 
				
			||||||
 | 
					            parsedData.FusionPoints || InventoryChanges.FusionPoints
 | 
				
			||||||
 | 
					                ? (parsedData.FusionPoints || 0) + (InventoryChanges.FusionPoints || 0)
 | 
				
			||||||
 | 
					                : undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        console.log(getRewards(parsedData.RewardInfo));
 | 
					        // combine reward and loot
 | 
				
			||||||
 | 
					        parsedData.RegularCredits = totalCredits;
 | 
				
			||||||
 | 
					        if (FusionPoints) parsedData.FusionPoints = FusionPoints;
 | 
				
			||||||
 | 
					        if (InventoryChanges.RawUpgrades && !parsedData.RawUpgrades) parsedData.RawUpgrades = [];
 | 
				
			||||||
 | 
					        InventoryChanges.RawUpgrades?.forEach(i => parsedData.RawUpgrades!.push(i));
 | 
				
			||||||
 | 
					        if (InventoryChanges.MiscItems && !parsedData.MiscItems) parsedData.RawUpgrades = [];
 | 
				
			||||||
 | 
					        InventoryChanges.MiscItems?.forEach(i => parsedData.MiscItems!.push(i));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const Inventory = await missionInventoryUpdate(parsedData, id);
 | 
				
			||||||
 | 
					        InventoryChanges.RawUpgrades?.forEach(
 | 
				
			||||||
 | 
					            (i: RawUpgrade) => (i.LastAdded = Inventory.RawUpgrades.find(j => j.ItemType === i.ItemType)?.LastAdded)
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
					        // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | 
				
			||||||
        const InventoryJson = JSON.stringify(await missionInventoryUpdate(parsedData, id));
 | 
					        const InventoryJson = JSON.stringify(Inventory);
 | 
				
			||||||
        res.json({
 | 
					        res.json({
 | 
				
			||||||
            // InventoryJson, // this part will reset game data and missions will be locked
 | 
					            // InventoryJson, // this part will reset game data and missions will be locked
 | 
				
			||||||
            TotalCredits,
 | 
					            TotalCredits,
 | 
				
			||||||
            CreditsBonus,
 | 
					            CreditsBonus,
 | 
				
			||||||
            MissionCredits
 | 
					            MissionCredits,
 | 
				
			||||||
 | 
					            MissionRewards,
 | 
				
			||||||
 | 
					            InventoryChanges,
 | 
				
			||||||
 | 
					            ...(FusionPoints !== undefined && { FusionPoints })
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    } catch (err) {
 | 
					    } catch (err) {
 | 
				
			||||||
        console.error("Error parsing JSON data:", err);
 | 
					        console.error("Error parsing JSON data:", err);
 | 
				
			||||||
@ -91,26 +110,44 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
**** OUTPUT ****
 | 
					**** OUTPUT ****
 | 
				
			||||||
- [x]  InventoryJson
 | 
					- [x]  InventoryJson
 | 
				
			||||||
- [ ]  MissionRewards
 | 
					- [x]  MissionRewards
 | 
				
			||||||
- [x]  TotalCredits
 | 
					- [x]  TotalCredits
 | 
				
			||||||
- [x]  CreditsBonus
 | 
					- [x]  CreditsBonus
 | 
				
			||||||
- [x]  MissionCredits
 | 
					- [x]  MissionCredits
 | 
				
			||||||
- [ ]  InventoryChanges
 | 
					- [x]  InventoryChanges
 | 
				
			||||||
- [ ]  FusionPoints int
 | 
					- [x]  FusionPoints
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface StringDictionary {
 | 
					interface StringDictionary {
 | 
				
			||||||
    [key: string]: string;
 | 
					    [key: string]: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
const getRewards = (rewardInfo: MissionInventoryUpdateRewardInfo | undefined) => {
 | 
					const getRewards = (
 | 
				
			||||||
    if (!rewardInfo) return;
 | 
					    rewardInfo: MissionInventoryUpdateRewardInfo | undefined
 | 
				
			||||||
 | 
					): { InventoryChanges: MissionInventoryUpdate; MissionRewards: MissionRewardResponse[] } => {
 | 
				
			||||||
 | 
					    if (!rewardInfo) return { InventoryChanges: {}, MissionRewards: [] };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO - add Rotation logic
 | 
				
			||||||
 | 
					    // no data for rotation, need reverse engineer rewardSeed, otherwise ingame displayed rotation loot will be different than added to db
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // "RewardInfo": {
 | 
				
			||||||
 | 
					    //     "node": "SolNode39",
 | 
				
			||||||
 | 
					    //     "rewardTier": 1,
 | 
				
			||||||
 | 
					    //     "nightmareMode": false,
 | 
				
			||||||
 | 
					    //     "useVaultManifest": false,
 | 
				
			||||||
 | 
					    //     "EnemyCachesFound": 0,
 | 
				
			||||||
 | 
					    //     "toxinOk": true,
 | 
				
			||||||
 | 
					    //     "lostTargetWave": 0,
 | 
				
			||||||
 | 
					    //     "defenseTargetCount": 1,
 | 
				
			||||||
 | 
					    //     "EOM_AFK": 0,
 | 
				
			||||||
 | 
					    //     "rewardQualifications": "11",
 | 
				
			||||||
 | 
					    //     "PurgatoryRewardQualifications": "",
 | 
				
			||||||
 | 
					    //     "rewardSeed": -5604904486637266000
 | 
				
			||||||
 | 
					    // },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const missionName = (missionNames as StringDictionary)[rewardInfo.node];
 | 
					    const missionName = (missionNames as StringDictionary)[rewardInfo.node];
 | 
				
			||||||
    const rewards = missionsDropTable.find(i => i.mission === missionName)?.rewards;
 | 
					    const rewards = missionsDropTable.find(i => i.mission === missionName)?.rewards;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!rewards) return [];
 | 
					    if (!rewards) return { InventoryChanges: {}, MissionRewards: [] };
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // TODO - add Rotation logic
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Separate guaranteed and chance drops
 | 
					    // Separate guaranteed and chance drops
 | 
				
			||||||
    const guaranteedDrops: Reward[] = [];
 | 
					    const guaranteedDrops: Reward[] = [];
 | 
				
			||||||
@ -123,6 +160,8 @@ const getRewards = (rewardInfo: MissionInventoryUpdateRewardInfo | undefined) =>
 | 
				
			|||||||
    const randomDrop = getRandomRewardByChance(chanceDrops);
 | 
					    const randomDrop = getRandomRewardByChance(chanceDrops);
 | 
				
			||||||
    if (randomDrop) guaranteedDrops.push(randomDrop);
 | 
					    if (randomDrop) guaranteedDrops.push(randomDrop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    console.log("Mission rewards:", guaranteedDrops);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return formatRewardsToInventoryType(guaranteedDrops);
 | 
					    return formatRewardsToInventoryType(guaranteedDrops);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -148,8 +187,20 @@ const getRandomRewardByChance = (data: Reward[] | undefined): Reward | undefined
 | 
				
			|||||||
    return;
 | 
					    return;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const formatRewardsToInventoryType = (rewards: Reward[]) => {
 | 
					interface MissionRewardResponse {
 | 
				
			||||||
    return rewards.map(i => {
 | 
					    StoreItem?: string;
 | 
				
			||||||
 | 
					    TypeName: string;
 | 
				
			||||||
 | 
					    UpgradeLevel: number;
 | 
				
			||||||
 | 
					    ItemCount: number;
 | 
				
			||||||
 | 
					    TweetText: string;
 | 
				
			||||||
 | 
					    ProductCategory: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					const formatRewardsToInventoryType = (
 | 
				
			||||||
 | 
					    rewards: Reward[]
 | 
				
			||||||
 | 
					): { InventoryChanges: MissionInventoryUpdate; MissionRewards: MissionRewardResponse[] } => {
 | 
				
			||||||
 | 
					    const InventoryChanges: MissionInventoryUpdate = {};
 | 
				
			||||||
 | 
					    const MissionRewards: MissionRewardResponse[] = [];
 | 
				
			||||||
 | 
					    rewards.forEach(i => {
 | 
				
			||||||
        const mod = (modNames as StringDictionary)[i.name];
 | 
					        const mod = (modNames as StringDictionary)[i.name];
 | 
				
			||||||
        const skin = (skinNames as StringDictionary)[i.name];
 | 
					        const skin = (skinNames as StringDictionary)[i.name];
 | 
				
			||||||
        const gear = (gearNames as StringDictionary)[i.name];
 | 
					        const gear = (gearNames as StringDictionary)[i.name];
 | 
				
			||||||
@ -164,32 +215,39 @@ const formatRewardsToInventoryType = (rewards: Reward[]) => {
 | 
				
			|||||||
            (relicNames as StringDictionary)[i.name.replace("Relic", "Exceptional")] ||
 | 
					            (relicNames as StringDictionary)[i.name.replace("Relic", "Exceptional")] ||
 | 
				
			||||||
            (relicNames as StringDictionary)[i.name.replace("Relic (Radiant)", "Radiant")];
 | 
					            (relicNames as StringDictionary)[i.name.replace("Relic (Radiant)", "Radiant")];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let ItemType: string = mod;
 | 
					 | 
				
			||||||
        const ItemCount = 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (mod) {
 | 
					        if (mod) {
 | 
				
			||||||
            ItemType = mod;
 | 
					            if (!InventoryChanges.RawUpgrades) InventoryChanges.RawUpgrades = [];
 | 
				
			||||||
 | 
					            InventoryChanges.RawUpgrades.push({ ItemType: mod, ItemCount: 1 });
 | 
				
			||||||
 | 
					            MissionRewards.push({
 | 
				
			||||||
 | 
					                StoreItem: mod.replace("/Lotus/", "/Lotus/StoreItems/"),
 | 
				
			||||||
 | 
					                TypeName: mod,
 | 
				
			||||||
 | 
					                UpgradeLevel: 0,
 | 
				
			||||||
 | 
					                ItemCount: 1,
 | 
				
			||||||
 | 
					                TweetText: `${i.name} (Mod)`,
 | 
				
			||||||
 | 
					                ProductCategory: "Upgrades"
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        } else if (skin) {
 | 
					        } else if (skin) {
 | 
				
			||||||
            ItemType = skin;
 | 
					            /* skin */
 | 
				
			||||||
        } else if (gear) {
 | 
					        } else if (gear) {
 | 
				
			||||||
            ItemType = gear;
 | 
					            /* gear */
 | 
				
			||||||
        } else if (arcane) {
 | 
					        } else if (arcane) {
 | 
				
			||||||
            ItemType = arcane;
 | 
					            /* arcane */
 | 
				
			||||||
        } else if (craft) {
 | 
					        } else if (craft) {
 | 
				
			||||||
            ItemType = craft;
 | 
					            /* craft */
 | 
				
			||||||
        } else if (misc) {
 | 
					        } else if (misc || resource) {
 | 
				
			||||||
            ItemType = misc;
 | 
					            if (!InventoryChanges.MiscItems) InventoryChanges.MiscItems = [];
 | 
				
			||||||
        } else if (resource) {
 | 
					            const ItemType = misc || resource;
 | 
				
			||||||
            ItemType = resource;
 | 
					            const ItemCount = parseInt(i.name) || 1;
 | 
				
			||||||
 | 
					            InventoryChanges.MiscItems.push({ ItemType, ItemCount });
 | 
				
			||||||
        } else if (relic) {
 | 
					        } else if (relic) {
 | 
				
			||||||
            ItemType = relic;
 | 
					            /* relic */
 | 
				
			||||||
        } else if (i.name.includes(" Endo")) {
 | 
					        } else if (i.name.includes(" Endo")) {
 | 
				
			||||||
            /* endo */
 | 
					            InventoryChanges.FusionPoints = parseInt(i.name);
 | 
				
			||||||
        } else if (i.name.includes(" Credits Cache") || i.name.includes("Return: ")) {
 | 
					        } else if (i.name.includes(" Credits Cache") || i.name.includes("Return: ")) {
 | 
				
			||||||
            /* credits */
 | 
					            InventoryChanges.RegularCredits = parseInt(i.name.replace(/ Credits Cache|Return: |,/g, ""));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return { ItemType, ItemCount };
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					    return { InventoryChanges, MissionRewards };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { missionInventoryUpdateController };
 | 
					export { missionInventoryUpdateController };
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,4 @@
 | 
				
			|||||||
| 
						
							
	
	
	
	
	
	
	
	 | 
				|||||||
 | 
					/* eslint-disable @typescript-eslint/no-explicit-any */
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
interface MongooseId {
 | 
					interface MongooseId {
 | 
				
			||||||
    $oid: string;
 | 
					    $oid: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -37,13 +38,6 @@ export interface MissionInventoryUpdateItem {
 | 
				
			|||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
    ItemType: string;
 | 
					    ItemType: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface MissionInventoryUpdateCard extends MissionInventoryUpdateItem {
 | 
					 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
    ItemId: MongooseId;
 | 
					 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
    UpgradeFingerprint: string;
 | 
					 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
    PendingRerollFingerprint: string;
 | 
					 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
    LastAdded: MongooseId;
 | 
					 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
}
 | 
					 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
 | 
					 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
interface MissionInventoryUpdateChallange {
 | 
					interface MissionInventoryUpdateChallange {
 | 
				
			||||||
    Name: string;
 | 
					    Name: string;
 | 
				
			||||||
    Progress: number;
 | 
					    Progress: number;
 | 
				
			||||||
@ -72,9 +66,10 @@ export interface MissionInventoryUpdate {
 | 
				
			|||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
    Pistols?: MissionInventoryUpdateGear[];
 | 
					    Pistols?: MissionInventoryUpdateGear[];
 | 
				
			||||||
    Suits?: MissionInventoryUpdateGear[];
 | 
					    Suits?: MissionInventoryUpdateGear[];
 | 
				
			||||||
    Melee?: MissionInventoryUpdateGear[];
 | 
					    Melee?: MissionInventoryUpdateGear[];
 | 
				
			||||||
    RawUpgrades?: MissionInventoryUpdateCard[];
 | 
					    RawUpgrades?: MissionInventoryUpdateItem[];
 | 
				
			||||||
| 
							
								
									
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
					|||||||
    MiscItems?: MissionInventoryUpdateItem[];
 | 
					    MiscItems?: MissionInventoryUpdateItem[];
 | 
				
			||||||
    RegularCredits?: number;
 | 
					    RegularCredits?: number;
 | 
				
			||||||
    ChallengeProgress?: MissionInventoryUpdateChallange[];
 | 
					    ChallengeProgress?: MissionInventoryUpdateChallange[];
 | 
				
			||||||
    RewardInfo?: MissionInventoryUpdateRewardInfo;
 | 
					    RewardInfo?: MissionInventoryUpdateRewardInfo;
 | 
				
			||||||
 | 
					    FusionPoints?: number;
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 instead of this use /types/commonTypes Oid type instead of this use /types/commonTypes Oid type 
			
			
		 | 
				|||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	
instead of this use /types/commonTypes Oid type
instead of this use /types/commonTypes Oid type