Mission rewards - type 1
This commit is contained in:
parent
4b03fd671c
commit
460d868715
@ -1,6 +1,9 @@
|
||||
import { RequestHandler } from "express";
|
||||
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 ****
|
||||
- [ ] crossPlaySetting
|
||||
@ -62,7 +65,7 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
|
||||
const CreditsBonus = [creditsBonus, creditsBonus]; // mission reward
|
||||
const TotalCredits = [totalCredits, totalCredits];
|
||||
|
||||
// TODO - get missions reward table
|
||||
console.log(getRewards(parsedData.RewardInfo));
|
||||
|
||||
res.json({
|
||||
// InventoryJson, // this part will reset game data and missions will be locked
|
||||
@ -86,4 +89,53 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
|
||||
- [ ] 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 };
|
||||
|
@ -50,6 +50,21 @@ interface MissionInventoryUpdateChallange {
|
||||
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 {
|
||||
rewardsMultiplier?: number;
|
||||
ActiveBoosters?: any[];
|
||||
@ -61,4 +76,5 @@ export interface MissionInventoryUpdate {
|
||||
MiscItems?: MissionInventoryUpdateItem[];
|
||||
RegularCredits?: number;
|
||||
ChallengeProgress?: MissionInventoryUpdateChallange[];
|
||||
RewardInfo?: MissionInventoryUpdateRewardInfo;
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -11,14 +11,18 @@
|
||||
rotation = undefined;
|
||||
} else if (element.children[0].getAttribute('colspan') == 2) {
|
||||
if (!lastItem.mission) {
|
||||
lastItem.mission = element.children[0].textContent;
|
||||
} else
|
||||
rotation = element.children[0].textContent;
|
||||
const mission = element.children[0].textContent;
|
||||
const formatedMission = mission.substring(0, mission.indexOf(' ('))
|
||||
lastItem.mission = formatedMission;
|
||||
} else{
|
||||
rotation = element.children[0].textContent.replace('Rotation ');
|
||||
}
|
||||
} else {
|
||||
if (!lastItem.rewards)
|
||||
lastItem.rewards = [];
|
||||
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 }) });
|
||||
}
|
||||
});
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user