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-03 21:25:54 +04:00
|
|
|
import {
|
|
|
|
MissionInventoryUpdate,
|
|
|
|
MissionInventoryUpdateRewardInfo,
|
|
|
|
MissionRewardResponse,
|
|
|
|
Reward
|
|
|
|
} from "@/src/types/missionInventoryUpdateType";
|
|
|
|
import { RawUpgrade } from "@/src/types/inventoryTypes/inventoryTypes";
|
2023-09-02 01:56:08 +04:00
|
|
|
|
|
|
|
import missionsDropTable from "@/static/json/missions-drop-table.json";
|
2023-09-03 21:25:54 +04:00
|
|
|
import {
|
|
|
|
modNames,
|
|
|
|
relicNames,
|
|
|
|
skinNames,
|
|
|
|
miscNames,
|
|
|
|
resourceNames,
|
|
|
|
gearNames,
|
|
|
|
arcaneNames,
|
|
|
|
craftNames
|
|
|
|
} from "@/static/data/items";
|
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-09-03 12:22:27 +04:00
|
|
|
|
|
|
|
const { InventoryChanges, MissionRewards } = getRewards(parsedData.RewardInfo);
|
2023-08-31 15:39:35 +04:00
|
|
|
|
|
|
|
const missionCredits = parsedData.RegularCredits || 0;
|
2023-09-03 12:22:27 +04:00
|
|
|
const creditsBonus = InventoryChanges.RegularCredits || 1000;
|
2023-08-31 15:39:35 +04:00
|
|
|
const totalCredits = missionCredits + creditsBonus;
|
|
|
|
|
2023-09-03 12:22:27 +04:00
|
|
|
const MissionCredits = [missionCredits, missionCredits];
|
|
|
|
const CreditsBonus = [creditsBonus, creditsBonus];
|
2023-08-31 15:39:35 +04:00
|
|
|
const TotalCredits = [totalCredits, totalCredits];
|
2023-09-03 12:22:27 +04:00
|
|
|
const FusionPoints =
|
|
|
|
parsedData.FusionPoints || InventoryChanges.FusionPoints
|
|
|
|
? (parsedData.FusionPoints || 0) + (InventoryChanges.FusionPoints || 0)
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
);
|
2023-09-02 22:47:57 +04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2023-09-03 12:22:27 +04:00
|
|
|
const InventoryJson = JSON.stringify(Inventory);
|
2023-08-31 15:39:35 +04:00
|
|
|
res.json({
|
|
|
|
// InventoryJson, // this part will reset game data and missions will be locked
|
|
|
|
TotalCredits,
|
|
|
|
CreditsBonus,
|
2023-09-03 12:22:27 +04:00
|
|
|
MissionCredits,
|
|
|
|
MissionRewards,
|
|
|
|
InventoryChanges,
|
|
|
|
...(FusionPoints !== undefined && { FusionPoints })
|
2023-08-31 15:39:35 +04:00
|
|
|
});
|
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
|
2023-09-03 12:22:27 +04:00
|
|
|
- [x] MissionRewards
|
2023-08-31 15:39:35 +04:00
|
|
|
- [x] TotalCredits
|
|
|
|
- [x] CreditsBonus
|
|
|
|
- [x] MissionCredits
|
2023-09-03 12:22:27 +04:00
|
|
|
- [x] InventoryChanges
|
|
|
|
- [x] FusionPoints
|
2023-08-31 15:39:35 +04:00
|
|
|
*/
|
|
|
|
|
2023-09-03 12:22:27 +04:00
|
|
|
const getRewards = (
|
|
|
|
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
|
|
|
|
// },
|
2023-09-01 15:38:41 +04:00
|
|
|
|
2023-09-03 21:25:54 +04:00
|
|
|
const rewards = (missionsDropTable as { [key: string]: Reward[] })[rewardInfo.node];
|
2023-09-01 15:38:41 +04:00
|
|
|
|
2023-09-03 12:22:27 +04:00
|
|
|
if (!rewards) return { InventoryChanges: {}, MissionRewards: [] };
|
2023-09-01 15:38:41 +04:00
|
|
|
|
|
|
|
// 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-03 12:22:27 +04:00
|
|
|
console.log("Mission rewards:", guaranteedDrops);
|
|
|
|
|
2023-09-02 01:56:08 +04:00
|
|
|
return formatRewardsToInventoryType(guaranteedDrops);
|
2023-09-01 15:38:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
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-03 12:22:27 +04:00
|
|
|
const formatRewardsToInventoryType = (
|
|
|
|
rewards: Reward[]
|
|
|
|
): { InventoryChanges: MissionInventoryUpdate; MissionRewards: MissionRewardResponse[] } => {
|
|
|
|
const InventoryChanges: MissionInventoryUpdate = {};
|
|
|
|
const MissionRewards: MissionRewardResponse[] = [];
|
|
|
|
rewards.forEach(i => {
|
2023-09-03 21:25:54 +04:00
|
|
|
const mod = modNames[i.name];
|
|
|
|
const skin = skinNames[i.name];
|
|
|
|
const gear = gearNames[i.name];
|
|
|
|
const arcane = arcaneNames[i.name];
|
|
|
|
const craft = craftNames[i.name];
|
|
|
|
const misc = miscNames[i.name] || miscNames[i.name.replace(/\d+X\s*/, "")];
|
|
|
|
const resource = resourceNames[i.name] || resourceNames[i.name.replace(/\d+X\s*/, "")];
|
2023-09-02 01:56:08 +04:00
|
|
|
const relic =
|
2023-09-03 21:25:54 +04:00
|
|
|
relicNames[i.name.replace("Relic", "Exceptional")] ||
|
|
|
|
relicNames[i.name.replace("Relic (Radiant)", "Radiant")];
|
2023-09-02 01:56:08 +04:00
|
|
|
|
|
|
|
if (mod) {
|
2023-09-03 12:22:27 +04:00
|
|
|
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"
|
|
|
|
});
|
2023-09-02 01:56:08 +04:00
|
|
|
} else if (skin) {
|
2023-09-03 12:22:27 +04:00
|
|
|
/* skin */
|
2023-09-02 01:56:08 +04:00
|
|
|
} else if (gear) {
|
2023-09-03 12:22:27 +04:00
|
|
|
/* gear */
|
2023-09-02 01:56:08 +04:00
|
|
|
} else if (arcane) {
|
2023-09-03 12:22:27 +04:00
|
|
|
/* arcane */
|
2023-09-02 01:56:08 +04:00
|
|
|
} else if (craft) {
|
2023-09-03 12:22:27 +04:00
|
|
|
/* craft */
|
|
|
|
} else if (misc || resource) {
|
|
|
|
if (!InventoryChanges.MiscItems) InventoryChanges.MiscItems = [];
|
|
|
|
const ItemType = misc || resource;
|
|
|
|
const ItemCount = parseInt(i.name) || 1;
|
|
|
|
InventoryChanges.MiscItems.push({ ItemType, ItemCount });
|
2023-09-02 01:56:08 +04:00
|
|
|
} else if (relic) {
|
2023-09-03 12:22:27 +04:00
|
|
|
/* relic */
|
2023-09-02 01:56:08 +04:00
|
|
|
} else if (i.name.includes(" Endo")) {
|
2023-09-03 12:22:27 +04:00
|
|
|
InventoryChanges.FusionPoints = parseInt(i.name);
|
2023-09-02 01:56:08 +04:00
|
|
|
} else if (i.name.includes(" Credits Cache") || i.name.includes("Return: ")) {
|
2023-09-03 12:22:27 +04:00
|
|
|
InventoryChanges.RegularCredits = parseInt(i.name.replace(/ Credits Cache|Return: |,/g, ""));
|
2023-09-02 01:56:08 +04:00
|
|
|
}
|
|
|
|
});
|
2023-09-03 12:22:27 +04:00
|
|
|
return { InventoryChanges, MissionRewards };
|
2023-09-02 01:56:08 +04:00
|
|
|
};
|
|
|
|
|
2023-09-03 21:25:54 +04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
const _missionRewardsCheckAllNamings = () => {
|
|
|
|
let tempRewards: Reward[] = [];
|
|
|
|
Object.values(missionsDropTable as { [key: string]: Reward[] }).forEach(i => {
|
|
|
|
i.forEach(j => {
|
|
|
|
tempRewards.push(j);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
tempRewards = tempRewards
|
|
|
|
.filter(i => !modNames[i.name])
|
|
|
|
|
|
|
|
.filter(i => !skinNames[i.name])
|
|
|
|
.filter(i => !miscNames[i.name])
|
|
|
|
.filter(i => !miscNames[i.name.replace(/\d+X\s*/, "")])
|
|
|
|
.filter(i => !resourceNames[i.name])
|
|
|
|
.filter(i => !resourceNames[i.name.replace(/\d+X\s*/, "")])
|
|
|
|
.filter(i => !gearNames[i.name])
|
|
|
|
.filter(i => !arcaneNames[i.name])
|
|
|
|
.filter(i => !craftNames[i.name])
|
|
|
|
.filter(i => {
|
|
|
|
// return true;
|
|
|
|
// return !relicNames[i.name.replace("Relic", "Exceptional")];
|
|
|
|
// console.log(i.name.replace("Relic", "Exceptional"));
|
|
|
|
return (
|
|
|
|
!relicNames[i.name.replace("Relic", "Exceptional")] &&
|
|
|
|
!relicNames[i.name.replace("Relic (Radiant)", "Radiant")]
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.filter(i => !i.name.includes(" Endo"))
|
|
|
|
.filter(i => !i.name.includes(" Credits Cache") && !i.name.includes("Return: "));
|
|
|
|
console.log(tempRewards);
|
|
|
|
};
|
|
|
|
// _missionRewardsCheckAllNamings();
|
|
|
|
|
2023-06-01 17:08:05 -07:00
|
|
|
export { missionInventoryUpdateController };
|