2023-08-30 22:56:50 +04:00
|
|
|
import { RequestHandler } from "express";
|
2023-08-30 07:51:56 +04:00
|
|
|
import { missionInventoryUpdate } from "@/src/services/inventoryService";
|
2023-09-01 15:38:41 +04:00
|
|
|
import { MissionInventoryUpdate, MissionInventoryUpdateRewardInfo } from "@/src/types/missionInventoryUpdateType";
|
2023-09-02 01:56:08 +04:00
|
|
|
|
|
|
|
import missionsDropTable from "@/static/json/missions-drop-table.json";
|
|
|
|
import missionNames from "@/static/json/mission-names.json";
|
|
|
|
import modNames from "@/static/json/mod-names.json";
|
|
|
|
import relicNames from "@/static/json/relic-names.json";
|
|
|
|
import skinNames from "@/static/json/skin-names.json";
|
|
|
|
import miscNames from "@/static/json/misc-names.json";
|
|
|
|
import resourceNames from "@/static/json/resource-names.json";
|
|
|
|
import gearNames from "@/static/json/gear-names.json";
|
|
|
|
import arcaneNames from "@/static/json/arcane-names.json";
|
|
|
|
import craftNames from "@/static/json/craft-names.json";
|
2023-09-01 15:38:41 +04:00
|
|
|
|
2023-08-30 05:42:50 +04:00
|
|
|
/*
|
2023-08-31 15:39:35 +04:00
|
|
|
**** INPUT ****
|
2023-08-30 05:42:50 +04:00
|
|
|
- [ ] crossPlaySetting
|
|
|
|
- [ ] rewardsMultiplier
|
|
|
|
- [ ] ActiveBoosters
|
2023-08-30 07:51:56 +04:00
|
|
|
- [x] LongGuns
|
|
|
|
- [x] Pistols
|
|
|
|
- [x] Suits
|
|
|
|
- [x] Melee
|
2023-08-30 05:42:50 +04:00
|
|
|
- [x] RawUpgrades
|
|
|
|
- [x] MiscItems
|
2023-08-30 08:14:59 +04:00
|
|
|
- [x] RegularCredits
|
2023-08-30 05:42:50 +04:00
|
|
|
- [ ] RandomUpgradesIdentified
|
|
|
|
- [ ] MissionFailed
|
|
|
|
- [ ] MissionStatus
|
|
|
|
- [ ] CurrentLoadOutIds
|
|
|
|
- [ ] AliveTime
|
|
|
|
- [ ] MissionTime
|
|
|
|
- [ ] Missions
|
|
|
|
- [ ] CompletedAlerts
|
|
|
|
- [ ] LastRegionPlayed
|
|
|
|
- [ ] GameModeId
|
|
|
|
- [ ] hosts
|
2023-08-30 23:50:52 +04:00
|
|
|
- [x] ChallengeProgress
|
2023-08-30 05:42:50 +04:00
|
|
|
- [ ] SeasonChallengeHistory
|
|
|
|
- [ ] PS
|
|
|
|
- [ ] ActiveDojoColorResearch
|
|
|
|
- [ ] RewardInfo
|
|
|
|
- [ ] ReceivedCeremonyMsg
|
|
|
|
- [ ] LastCeremonyResetDate
|
|
|
|
- [ ] MissionPTS
|
|
|
|
- [ ] RepHash
|
|
|
|
- [ ] EndOfMatchUpload
|
|
|
|
- [ ] ObjectiveReached
|
|
|
|
- [ ] FpsAvg
|
|
|
|
- [ ] FpsMin
|
|
|
|
- [ ] FpsMax
|
|
|
|
- [ ] FpsSamples
|
|
|
|
*/
|
2023-08-30 17:32:08 +04:00
|
|
|
|
2023-08-30 22:56:50 +04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
|
|
const missionInventoryUpdateController: RequestHandler = async (req, res) => {
|
2023-08-30 20:14:06 +04:00
|
|
|
const [data] = String(req.body).split("\n");
|
2023-08-30 05:42:50 +04:00
|
|
|
const id = req.query.accountId as string;
|
2023-08-30 17:32:08 +04:00
|
|
|
|
|
|
|
// TODO - salt check
|
|
|
|
|
|
|
|
try {
|
2023-08-30 20:14:06 +04:00
|
|
|
const parsedData = JSON.parse(data) as MissionInventoryUpdate;
|
|
|
|
if (typeof parsedData !== "object" || parsedData === null) throw new Error("Invalid data format");
|
2023-08-31 15:39:35 +04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
const InventoryJson = JSON.stringify(await missionInventoryUpdate(parsedData, id));
|
|
|
|
|
|
|
|
const missionCredits = parsedData.RegularCredits || 0;
|
|
|
|
const creditsBonus = 0;
|
|
|
|
const totalCredits = missionCredits + creditsBonus;
|
|
|
|
|
|
|
|
const MissionCredits = [missionCredits, missionCredits]; // collected credits
|
|
|
|
const CreditsBonus = [creditsBonus, creditsBonus]; // mission reward
|
|
|
|
const TotalCredits = [totalCredits, totalCredits];
|
|
|
|
|
2023-09-01 15:38:41 +04:00
|
|
|
console.log(getRewards(parsedData.RewardInfo));
|
2023-08-31 15:39:35 +04:00
|
|
|
|
|
|
|
res.json({
|
|
|
|
// InventoryJson, // this part will reset game data and missions will be locked
|
|
|
|
TotalCredits,
|
|
|
|
CreditsBonus,
|
|
|
|
MissionCredits
|
|
|
|
});
|
2023-08-30 17:32:08 +04:00
|
|
|
} catch (err) {
|
2023-08-30 20:14:06 +04:00
|
|
|
console.error("Error parsing JSON data:", err);
|
2023-08-30 17:32:08 +04:00
|
|
|
}
|
2023-06-01 17:08:05 -07:00
|
|
|
};
|
|
|
|
|
2023-08-31 15:39:35 +04:00
|
|
|
/*
|
|
|
|
**** OUTPUT ****
|
|
|
|
- [x] InventoryJson
|
|
|
|
- [ ] MissionRewards
|
|
|
|
- [x] TotalCredits
|
|
|
|
- [x] CreditsBonus
|
|
|
|
- [x] MissionCredits
|
|
|
|
- [ ] InventoryChanges
|
2023-08-31 22:20:55 +04:00
|
|
|
- [ ] FusionPoints int
|
2023-08-31 15:39:35 +04:00
|
|
|
*/
|
|
|
|
|
2023-09-02 01:56:08 +04:00
|
|
|
interface StringDictionary {
|
2023-09-01 15:38:41 +04:00
|
|
|
[key: string]: string;
|
|
|
|
}
|
2023-09-02 01:56:08 +04:00
|
|
|
const getRewards = (rewardInfo: MissionInventoryUpdateRewardInfo | undefined) => {
|
2023-09-01 15:38:41 +04:00
|
|
|
if (!rewardInfo) return;
|
|
|
|
|
2023-09-02 01:56:08 +04:00
|
|
|
const missionName = (missionNames as StringDictionary)[rewardInfo.node];
|
|
|
|
const rewards = missionsDropTable.find(i => i.mission === missionName)?.rewards;
|
2023-09-01 15:38:41 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-09-02 01:56:08 +04:00
|
|
|
return formatRewardsToInventoryType(guaranteedDrops);
|
2023-09-01 15:38:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2023-09-02 01:56:08 +04:00
|
|
|
const formatRewardsToInventoryType = (rewards: Reward[]) => {
|
|
|
|
return rewards.map(i => {
|
|
|
|
const mod = (modNames as StringDictionary)[i.name];
|
|
|
|
const skin = (skinNames as StringDictionary)[i.name];
|
|
|
|
const gear = (gearNames as StringDictionary)[i.name];
|
|
|
|
const arcane = (arcaneNames as StringDictionary)[i.name];
|
|
|
|
const craft = (craftNames as StringDictionary)[i.name];
|
|
|
|
const misc =
|
|
|
|
(miscNames as StringDictionary)[i.name] || (miscNames as StringDictionary)[i.name.replace(/\d+X\s*/, "")];
|
|
|
|
const resource =
|
|
|
|
(resourceNames as StringDictionary)[i.name] ||
|
|
|
|
(resourceNames as StringDictionary)[i.name.replace(/\d+X\s*/, "")];
|
|
|
|
const relic =
|
|
|
|
(relicNames as StringDictionary)[i.name.replace("Relic", "Exceptional")] ||
|
|
|
|
(relicNames as StringDictionary)[i.name.replace("Relic (Radiant)", "Radiant")];
|
|
|
|
|
|
|
|
let ItemType: string = mod;
|
|
|
|
const ItemCount = 1;
|
|
|
|
|
|
|
|
if (mod) {
|
|
|
|
ItemType = mod;
|
|
|
|
} else if (skin) {
|
|
|
|
ItemType = skin;
|
|
|
|
} else if (gear) {
|
|
|
|
ItemType = gear;
|
|
|
|
} else if (arcane) {
|
|
|
|
ItemType = arcane;
|
|
|
|
} else if (craft) {
|
|
|
|
ItemType = craft;
|
|
|
|
} else if (misc) {
|
|
|
|
ItemType = misc;
|
|
|
|
} else if (resource) {
|
|
|
|
ItemType = resource;
|
|
|
|
} else if (relic) {
|
|
|
|
ItemType = relic;
|
|
|
|
} else if (i.name.includes(" Endo")) {
|
|
|
|
/* endo */
|
|
|
|
} else if (i.name.includes(" Credits Cache") || i.name.includes("Return: ")) {
|
|
|
|
/* credits */
|
|
|
|
}
|
|
|
|
return { ItemType, ItemCount };
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-06-01 17:08:05 -07:00
|
|
|
export { missionInventoryUpdateController };
|