Mission rewards - type 1
This commit is contained in:
		
							parent
							
								
									4b03fd671c
								
							
						
					
					
						commit
						460d868715
					
				@ -1,6 +1,9 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { missionInventoryUpdate } from "@/src/services/inventoryService";
 | 
					import { missionInventoryUpdate } from "@/src/services/inventoryService";
 | 
				
			||||||
import { MissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
 | 
					import { MissionInventoryUpdate, MissionInventoryUpdateRewardInfo } from "@/src/types/missionInventoryUpdateType";
 | 
				
			||||||
 | 
					import missionNames from "@/static/data/mission-names.json";
 | 
				
			||||||
 | 
					import missionReward from "@/static/data/mission-rewards.json";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
**** INPUT ****
 | 
					**** INPUT ****
 | 
				
			||||||
- [ ]  crossPlaySetting
 | 
					- [ ]  crossPlaySetting
 | 
				
			||||||
@ -62,7 +65,7 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        const CreditsBonus = [creditsBonus, creditsBonus]; // mission reward
 | 
					        const CreditsBonus = [creditsBonus, creditsBonus]; // mission reward
 | 
				
			||||||
        const TotalCredits = [totalCredits, totalCredits];
 | 
					        const TotalCredits = [totalCredits, totalCredits];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // TODO - get missions reward table
 | 
					        console.log(getRewards(parsedData.RewardInfo));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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
 | 
				
			||||||
@ -86,4 +89,53 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
- [ ]  FusionPoints int
 | 
					- [ ]  FusionPoints int
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface MissionNames {
 | 
				
			||||||
 | 
					    [key: string]: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					const getRewards = (rewardInfo: MissionInventoryUpdateRewardInfo | undefined): Reward[] | undefined => {
 | 
				
			||||||
 | 
					    if (!rewardInfo) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const missionName = (missionNames as MissionNames)[rewardInfo.node];
 | 
				
			||||||
 | 
					    const rewards = missionReward.find(i => i.mission === missionName)?.rewards;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!rewards) return [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO - add Rotation logic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Separate guaranteed and chance drops
 | 
				
			||||||
 | 
					    const guaranteedDrops: Reward[] = [];
 | 
				
			||||||
 | 
					    const chanceDrops: Reward[] = [];
 | 
				
			||||||
 | 
					    for (const reward of rewards) {
 | 
				
			||||||
 | 
					        if (reward.chance === 100) guaranteedDrops.push(reward);
 | 
				
			||||||
 | 
					        else chanceDrops.push(reward);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const randomDrop = getRandomRewardByChance(chanceDrops);
 | 
				
			||||||
 | 
					    if (randomDrop) guaranteedDrops.push(randomDrop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return guaranteedDrops;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface Reward {
 | 
				
			||||||
 | 
					    name: string;
 | 
				
			||||||
 | 
					    chance: number;
 | 
				
			||||||
 | 
					    rotation?: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					const getRandomRewardByChance = (data: Reward[] | undefined): Reward | undefined => {
 | 
				
			||||||
 | 
					    if (!data || data.length == 0) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const totalChance = data.reduce((sum, item) => sum + item.chance, 0);
 | 
				
			||||||
 | 
					    const randomValue = Math.random() * totalChance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let cumulativeChance = 0;
 | 
				
			||||||
 | 
					    for (const item of data) {
 | 
				
			||||||
 | 
					        cumulativeChance += item.chance;
 | 
				
			||||||
 | 
					        if (randomValue <= cumulativeChance) {
 | 
				
			||||||
 | 
					            return item;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { missionInventoryUpdateController };
 | 
					export { missionInventoryUpdateController };
 | 
				
			||||||
 | 
				
			|||||||
@ -50,6 +50,21 @@ interface MissionInventoryUpdateChallange {
 | 
				
			|||||||
    Completed: any[];
 | 
					    Completed: any[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface MissionInventoryUpdateRewardInfo {
 | 
				
			||||||
 | 
					    node: string;
 | 
				
			||||||
 | 
					    rewardTier?: number;
 | 
				
			||||||
 | 
					    nightmareMode?: boolean;
 | 
				
			||||||
 | 
					    useVaultManifest?: boolean;
 | 
				
			||||||
 | 
					    EnemyCachesFound?: number;
 | 
				
			||||||
 | 
					    toxinOk?: boolean;
 | 
				
			||||||
 | 
					    lostTargetWave?: number;
 | 
				
			||||||
 | 
					    defenseTargetCount?: number;
 | 
				
			||||||
 | 
					    EOM_AFK?: number;
 | 
				
			||||||
 | 
					    rewardQualifications?: string;
 | 
				
			||||||
 | 
					    PurgatoryRewardQualifications?: string;
 | 
				
			||||||
 | 
					    rewardSeed?: number;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface MissionInventoryUpdate {
 | 
					export interface MissionInventoryUpdate {
 | 
				
			||||||
    rewardsMultiplier?: number;
 | 
					    rewardsMultiplier?: number;
 | 
				
			||||||
    ActiveBoosters?: any[];
 | 
					    ActiveBoosters?: any[];
 | 
				
			||||||
@ -61,4 +76,5 @@ export interface MissionInventoryUpdate {
 | 
				
			|||||||
    MiscItems?: MissionInventoryUpdateItem[];
 | 
					    MiscItems?: MissionInventoryUpdateItem[];
 | 
				
			||||||
    RegularCredits?: number;
 | 
					    RegularCredits?: number;
 | 
				
			||||||
    ChallengeProgress?: MissionInventoryUpdateChallange[];
 | 
					    ChallengeProgress?: MissionInventoryUpdateChallange[];
 | 
				
			||||||
 | 
					    RewardInfo?: MissionInventoryUpdateRewardInfo;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -11,14 +11,18 @@
 | 
				
			|||||||
            rotation = undefined;
 | 
					            rotation = undefined;
 | 
				
			||||||
        } else if (element.children[0].getAttribute('colspan') == 2) {
 | 
					        } else if (element.children[0].getAttribute('colspan') == 2) {
 | 
				
			||||||
            if (!lastItem.mission) {
 | 
					            if (!lastItem.mission) {
 | 
				
			||||||
                lastItem.mission = element.children[0].textContent;
 | 
					                const mission = element.children[0].textContent;
 | 
				
			||||||
            } else
 | 
					                const formatedMission = mission.substring(0, mission.indexOf(' ('))
 | 
				
			||||||
                rotation = element.children[0].textContent;
 | 
					                lastItem.mission = formatedMission;
 | 
				
			||||||
 | 
					            } else{
 | 
				
			||||||
 | 
					                rotation = element.children[0].textContent.replace('Rotation ');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            if (!lastItem.rewards)
 | 
					            if (!lastItem.rewards)
 | 
				
			||||||
                lastItem.rewards = [];
 | 
					                lastItem.rewards = [];
 | 
				
			||||||
            const name = element.children[0].textContent;
 | 
					            const name = element.children[0].textContent;
 | 
				
			||||||
            const chance = element.children[1].textContent;
 | 
					            const chance = parseFloat(element.children[1].textContent.match(/(\d+\.\d+)/)[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            lastItem.rewards.push({ chance, name, ...(rotation !== undefined && { rotation }) });
 | 
					            lastItem.rewards.push({ chance, name, ...(rotation !== undefined && { rotation }) });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user