Mission reward - fixes
This commit is contained in:
parent
2d4b139e0e
commit
4cc2c801b4
@ -1,15 +1,7 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { missionInventoryUpdate } from "@/src/services/inventoryService";
|
import { missionInventoryUpdate } from "@/src/services/inventoryService";
|
||||||
import {
|
import { combineRewardAndLootInventory, getRewards } from "@/src/services/missionInventoryUpdateService ";
|
||||||
IMissionInventoryUpdate,
|
import { IMissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
|
||||||
IMissionInventoryUpdateRewardInfo,
|
|
||||||
IMissionRewardResponse,
|
|
||||||
IReward
|
|
||||||
} from "@/src/types/missionInventoryUpdateType";
|
|
||||||
import { IRawUpgrade } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
||||||
|
|
||||||
import missionsDropTable from "@/static/json/missions-drop-table.json";
|
|
||||||
import { modNames, relicNames, miscNames, resourceNames, gearNames, blueprintNames } from "@/static/data/items";
|
|
||||||
/*
|
/*
|
||||||
**** INPUT ****
|
**** INPUT ****
|
||||||
- [ ] crossPlaySetting
|
- [ ] crossPlaySetting
|
||||||
@ -37,7 +29,7 @@ import { modNames, relicNames, miscNames, resourceNames, gearNames, blueprintNam
|
|||||||
- [ ] SeasonChallengeHistory
|
- [ ] SeasonChallengeHistory
|
||||||
- [ ] PS (Passive anti-cheat data which includes your username, module list, process list, and system name.)
|
- [ ] PS (Passive anti-cheat data which includes your username, module list, process list, and system name.)
|
||||||
- [ ] ActiveDojoColorResearch
|
- [ ] ActiveDojoColorResearch
|
||||||
- [ ] RewardInfo
|
- [x] RewardInfo
|
||||||
- [ ] ReceivedCeremonyMsg
|
- [ ] ReceivedCeremonyMsg
|
||||||
- [ ] LastCeremonyResetDate
|
- [ ] LastCeremonyResetDate
|
||||||
- [ ] MissionPTS (Used to validate the mission/alive time above.)
|
- [ ] MissionPTS (Used to validate the mission/alive time above.)
|
||||||
@ -56,41 +48,25 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
|
|||||||
const id = req.query.accountId as string;
|
const id = req.query.accountId as string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(data) as IMissionInventoryUpdate;
|
const lootInventory = JSON.parse(data) as IMissionInventoryUpdate;
|
||||||
if (typeof parsedData !== "object" || parsedData === null) throw new Error("Invalid data format");
|
if (typeof lootInventory !== "object" || lootInventory === null) {
|
||||||
|
throw new Error("Invalid data format");
|
||||||
|
}
|
||||||
|
|
||||||
const { InventoryChanges, MissionRewards } = getRewards(parsedData.RewardInfo);
|
const { InventoryChanges, MissionRewards } = getRewards(lootInventory.RewardInfo);
|
||||||
|
|
||||||
const missionCredits = parsedData.RegularCredits || 0;
|
const { combinedInventoryChanges, TotalCredits, CreditsBonus, MissionCredits, FusionPoints } =
|
||||||
const creditsBonus = InventoryChanges.RegularCredits || 1000;
|
combineRewardAndLootInventory(InventoryChanges, lootInventory);
|
||||||
const totalCredits = missionCredits + creditsBonus;
|
|
||||||
|
|
||||||
const MissionCredits = [missionCredits, missionCredits];
|
|
||||||
const CreditsBonus = [creditsBonus, creditsBonus];
|
|
||||||
const TotalCredits = [totalCredits, totalCredits];
|
|
||||||
const FusionPoints = (parsedData.FusionPoints || 0) + (InventoryChanges.FusionPoints || 0) || undefined;
|
|
||||||
|
|
||||||
// combine reward and loot
|
|
||||||
parsedData.RegularCredits = totalCredits;
|
|
||||||
if (FusionPoints) parsedData.FusionPoints = FusionPoints;
|
|
||||||
inventoryFields.forEach((field: InventoryFieldType) => {
|
|
||||||
if (InventoryChanges[field] && !parsedData[field]) parsedData[field] = [];
|
|
||||||
InventoryChanges[field]?.forEach(i => parsedData[field]!.push(i));
|
|
||||||
});
|
|
||||||
|
|
||||||
const Inventory = await missionInventoryUpdate(parsedData, id);
|
|
||||||
InventoryChanges.RawUpgrades?.forEach(
|
|
||||||
(i: IRawUpgrade) => (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(Inventory);
|
const InventoryJson = JSON.stringify(await missionInventoryUpdate(combinedInventoryChanges, id));
|
||||||
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
|
||||||
|
MissionRewards,
|
||||||
|
InventoryChanges,
|
||||||
TotalCredits,
|
TotalCredits,
|
||||||
CreditsBonus,
|
CreditsBonus,
|
||||||
MissionCredits,
|
MissionCredits,
|
||||||
MissionRewards,
|
|
||||||
InventoryChanges,
|
|
||||||
...(FusionPoints !== undefined && { FusionPoints })
|
...(FusionPoints !== undefined && { FusionPoints })
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -109,193 +85,4 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
|
|||||||
- [x] FusionPoints
|
- [x] FusionPoints
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const inventoryFields = ["RawUpgrades", "MiscItems", "Consumables", "Recipes"] as const;
|
|
||||||
type InventoryFieldType = (typeof inventoryFields)[number];
|
|
||||||
|
|
||||||
// need reverse engineer rewardSeed, otherwise ingame displayed rotation loot will be different than added to db
|
|
||||||
const getRewards = (
|
|
||||||
rewardInfo: IMissionInventoryUpdateRewardInfo | undefined
|
|
||||||
): { InventoryChanges: IMissionInventoryUpdate; MissionRewards: IMissionRewardResponse[] } => {
|
|
||||||
if (!rewardInfo) return { InventoryChanges: {}, MissionRewards: [] };
|
|
||||||
|
|
||||||
const rewards = (missionsDropTable as { [key: string]: IReward[] })[rewardInfo.node];
|
|
||||||
if (!rewards) return { InventoryChanges: {}, MissionRewards: [] };
|
|
||||||
|
|
||||||
const rotationCount = rewardInfo.rewardQualifications?.length || 0;
|
|
||||||
const rotations = getRotations(rotationCount);
|
|
||||||
const drops: IReward[] = [];
|
|
||||||
for (const rotation of rotations) {
|
|
||||||
const rotationRewards = rewards.filter(i => i.rotation === rotation);
|
|
||||||
|
|
||||||
// Separate guaranteed and chance drops
|
|
||||||
const guaranteedDrops: IReward[] = [];
|
|
||||||
const chanceDrops: IReward[] = [];
|
|
||||||
for (const reward of rotationRewards) {
|
|
||||||
if (reward.chance === 100) guaranteedDrops.push(reward);
|
|
||||||
else chanceDrops.push(reward);
|
|
||||||
}
|
|
||||||
|
|
||||||
const randomDrop = getRandomRewardByChance(chanceDrops);
|
|
||||||
if (randomDrop) guaranteedDrops.push(randomDrop);
|
|
||||||
|
|
||||||
drops.push(...guaranteedDrops);
|
|
||||||
}
|
|
||||||
|
|
||||||
// const testDrops = [
|
|
||||||
// { chance: 7.69, name: "Lith W3 Relic", rotation: "B" },
|
|
||||||
// { chance: 7.69, name: "Lith W3 Relic", rotation: "B" },
|
|
||||||
// { chance: 10.82, name: "2X Orokin Cell", rotation: "C" },
|
|
||||||
// { chance: 10.82, name: "Link Armor", rotation: "C" },
|
|
||||||
// { chance: 10.82, name: "200 Endo", rotation: "C" },
|
|
||||||
// { chance: 10.82, name: "2,000,000 Credits Cache", rotation: "C" },
|
|
||||||
// { chance: 7.69, name: "Health Restore (Large)", rotation: "C" },
|
|
||||||
// { chance: 7.69, name: "Vapor Specter Blueprint", rotation: "C" }
|
|
||||||
// ];
|
|
||||||
// console.log("Mission rewards:", testDrops);
|
|
||||||
// return formatRewardsToInventoryType(testDrops);
|
|
||||||
|
|
||||||
console.log("Mission rewards:", drops);
|
|
||||||
return formatRewardsToInventoryType(drops);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getRotations = (rotationCount: number): (string | undefined)[] => {
|
|
||||||
if (rotationCount === 0) return [undefined];
|
|
||||||
|
|
||||||
const rotations = ["A", "B", "C"];
|
|
||||||
let rotationIndex = 0;
|
|
||||||
const rotatedValues = [];
|
|
||||||
|
|
||||||
for (let i = 1; i <= rotationCount; i++) {
|
|
||||||
rotatedValues.push(rotations[rotationIndex]);
|
|
||||||
rotationIndex = (rotationIndex + 1) % 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rotatedValues;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getRandomRewardByChance = (data: IReward[] | undefined): IReward | 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatRewardsToInventoryType = (
|
|
||||||
rewards: IReward[]
|
|
||||||
): { InventoryChanges: IMissionInventoryUpdate; MissionRewards: IMissionRewardResponse[] } => {
|
|
||||||
const InventoryChanges: IMissionInventoryUpdate = {};
|
|
||||||
const MissionRewards: IMissionRewardResponse[] = [];
|
|
||||||
for (const reward of rewards) {
|
|
||||||
if (itemCheck(InventoryChanges, MissionRewards, reward.name)) continue;
|
|
||||||
|
|
||||||
if (reward.name.includes(" Endo")) {
|
|
||||||
if (!InventoryChanges.FusionPoints) InventoryChanges.FusionPoints = 0;
|
|
||||||
InventoryChanges.FusionPoints += getCountFromName(reward.name);
|
|
||||||
} else if (reward.name.includes(" Credits Cache") || reward.name.includes("Return: ")) {
|
|
||||||
if (!InventoryChanges.RegularCredits) InventoryChanges.RegularCredits = 0;
|
|
||||||
InventoryChanges.RegularCredits += getCountFromName(reward.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { InventoryChanges, MissionRewards };
|
|
||||||
};
|
|
||||||
|
|
||||||
const itemCheck = (
|
|
||||||
InventoryChanges: IMissionInventoryUpdate,
|
|
||||||
MissionRewards: IMissionRewardResponse[],
|
|
||||||
name: string
|
|
||||||
) => {
|
|
||||||
const rewardCheck = {
|
|
||||||
RawUpgrades: modNames[name],
|
|
||||||
Consumables: gearNames[name],
|
|
||||||
MiscItems:
|
|
||||||
miscNames[name] ||
|
|
||||||
miscNames[name.replace(/\d+X\s*/, "")] ||
|
|
||||||
resourceNames[name] ||
|
|
||||||
resourceNames[name.replace(/\d+X\s*/, "")] ||
|
|
||||||
relicNames[name.replace("Relic", "Intact")] ||
|
|
||||||
relicNames[name.replace("Relic (Radiant)", "Radiant")],
|
|
||||||
Recipes: blueprintNames[name]
|
|
||||||
};
|
|
||||||
for (const key of Object.keys(rewardCheck) as InventoryFieldType[]) {
|
|
||||||
if (rewardCheck[key]) {
|
|
||||||
addRewardResponse(InventoryChanges, MissionRewards, name, rewardCheck[key]!, key);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCountFromName = (name: string) => {
|
|
||||||
const regex = /(^(?:\d{1,3}(?:,\d{3})*(?:\.\d+)?)(\s|X))|(\s(?:\d{1,3}(?:,\d{3})*(?:\.\d+)?)$)/;
|
|
||||||
const countMatches = name.match(regex);
|
|
||||||
return countMatches ? parseInt(countMatches[0].replace(/,/g, ""), 10) : 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
const addRewardResponse = (
|
|
||||||
InventoryChanges: IMissionInventoryUpdate,
|
|
||||||
MissionRewards: IMissionRewardResponse[],
|
|
||||||
ItemName: string,
|
|
||||||
ItemType: string,
|
|
||||||
InventoryCategory: InventoryFieldType
|
|
||||||
) => {
|
|
||||||
if (!ItemType) return;
|
|
||||||
if (!InventoryChanges[InventoryCategory]) InventoryChanges[InventoryCategory] = [];
|
|
||||||
const ItemCount = getCountFromName(ItemName);
|
|
||||||
const TweetText = `${ItemName}`;
|
|
||||||
|
|
||||||
const existReward = InventoryChanges[InventoryCategory]!.find(j => j.ItemType === ItemType);
|
|
||||||
if (existReward) {
|
|
||||||
existReward.ItemCount += ItemCount;
|
|
||||||
const missionReward = MissionRewards.find(j => j.TypeName === ItemType);
|
|
||||||
if (missionReward) missionReward.ItemCount += ItemCount;
|
|
||||||
} else {
|
|
||||||
InventoryChanges[InventoryCategory]!.push({ ItemType, ItemCount });
|
|
||||||
MissionRewards.push({
|
|
||||||
ItemCount,
|
|
||||||
TweetText,
|
|
||||||
ProductCategory: InventoryCategory,
|
|
||||||
StoreItem: ItemType.replace("/Lotus/", "/Lotus/StoreItems/"),
|
|
||||||
TypeName: ItemType
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const _missionRewardsCheckAllNamings = () => {
|
|
||||||
let tempRewards: IReward[] = [];
|
|
||||||
Object.values(missionsDropTable as { [key: string]: IReward[] }).forEach(i => {
|
|
||||||
i.forEach(j => {
|
|
||||||
tempRewards.push(j);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
tempRewards = tempRewards
|
|
||||||
.filter(i => !modNames[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 => {
|
|
||||||
return (
|
|
||||||
!relicNames[i.name.replace("Relic", "Intact")] &&
|
|
||||||
!relicNames[i.name.replace("Relic (Radiant)", "Radiant")]
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.filter(i => !blueprintNames[i.name])
|
|
||||||
.filter(i => !i.name.includes(" Endo"))
|
|
||||||
.filter(i => !i.name.includes(" Credits Cache") && !i.name.includes("Return: "));
|
|
||||||
console.log(tempRewards);
|
|
||||||
};
|
|
||||||
// _missionRewardsCheckAllNamings();
|
|
||||||
|
|
||||||
export { missionInventoryUpdateController };
|
export { missionInventoryUpdateController };
|
||||||
|
@ -145,7 +145,7 @@ const addGearExpByCategory = (
|
|||||||
const category = inventory[categoryName];
|
const category = inventory[categoryName];
|
||||||
|
|
||||||
gearArray?.forEach(({ ItemId, XP }) => {
|
gearArray?.forEach(({ ItemId, XP }) => {
|
||||||
const itemIndex = category.findIndex(i => i._id?.equals(ItemId.$oid));
|
const itemIndex = category.findIndex(item => item._id?.equals(ItemId.$oid));
|
||||||
const item = category[itemIndex];
|
const item = category[itemIndex];
|
||||||
|
|
||||||
if (itemIndex !== -1 && item.XP != undefined) {
|
if (itemIndex !== -1 && item.XP != undefined) {
|
||||||
@ -159,7 +159,7 @@ const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray: IMiscIt
|
|||||||
const { MiscItems } = inventory;
|
const { MiscItems } = inventory;
|
||||||
|
|
||||||
itemsArray?.forEach(({ ItemCount, ItemType }) => {
|
itemsArray?.forEach(({ ItemCount, ItemType }) => {
|
||||||
const itemIndex = MiscItems.findIndex(i => i.ItemType === ItemType);
|
const itemIndex = MiscItems.findIndex(miscItem => miscItem.ItemType === ItemType);
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
if (itemIndex !== -1) {
|
||||||
MiscItems[itemIndex].ItemCount += ItemCount;
|
MiscItems[itemIndex].ItemCount += ItemCount;
|
||||||
@ -262,7 +262,7 @@ export const addBooster = async (ItemType: string, time: number, accountId: stri
|
|||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const { Boosters } = inventory;
|
const { Boosters } = inventory;
|
||||||
|
|
||||||
const itemIndex = Boosters.findIndex(i => i.ItemType === ItemType);
|
const itemIndex = Boosters.findIndex(booster => booster.ItemType === ItemType);
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
if (itemIndex !== -1) {
|
||||||
const existingBooster = Boosters[itemIndex];
|
const existingBooster = Boosters[itemIndex];
|
||||||
@ -295,7 +295,7 @@ export const upgradeMod = async (
|
|||||||
parsedUpgradeFingerprint.lvl += LevelDiff;
|
parsedUpgradeFingerprint.lvl += LevelDiff;
|
||||||
const stringifiedUpgradeFingerprint = JSON.stringify(parsedUpgradeFingerprint);
|
const stringifiedUpgradeFingerprint = JSON.stringify(parsedUpgradeFingerprint);
|
||||||
|
|
||||||
let itemIndex = Upgrades.findIndex(i => i._id?.equals(ItemId!.$oid));
|
let itemIndex = Upgrades.findIndex(upgrade => upgrade._id?.equals(ItemId!.$oid));
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
if (itemIndex !== -1) {
|
||||||
Upgrades[itemIndex].UpgradeFingerprint = stringifiedUpgradeFingerprint;
|
Upgrades[itemIndex].UpgradeFingerprint = stringifiedUpgradeFingerprint;
|
||||||
@ -307,7 +307,7 @@ export const upgradeMod = async (
|
|||||||
ItemType
|
ItemType
|
||||||
}) - 1;
|
}) - 1;
|
||||||
|
|
||||||
const rawItemIndex = RawUpgrades.findIndex(i => i.ItemType === ItemType);
|
const rawItemIndex = RawUpgrades.findIndex(rawUpgrade => rawUpgrade.ItemType === ItemType);
|
||||||
RawUpgrades[rawItemIndex].ItemCount--;
|
RawUpgrades[rawItemIndex].ItemCount--;
|
||||||
if (RawUpgrades[rawItemIndex].ItemCount > 0) {
|
if (RawUpgrades[rawItemIndex].ItemCount > 0) {
|
||||||
inventory.markModified(`RawUpgrades.${rawItemIndex}.UpgradeFingerprint`);
|
inventory.markModified(`RawUpgrades.${rawItemIndex}.UpgradeFingerprint`);
|
||||||
|
249
src/services/missionInventoryUpdateService .ts
Normal file
249
src/services/missionInventoryUpdateService .ts
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
import {
|
||||||
|
IMissionInventoryUpdate,
|
||||||
|
IMissionInventoryUpdateRewardInfo,
|
||||||
|
IMissionRewardResponse,
|
||||||
|
IReward,
|
||||||
|
IInventoryFieldType,
|
||||||
|
inventoryFields
|
||||||
|
} from "@/src/types/missionInventoryUpdateType";
|
||||||
|
|
||||||
|
import missionsDropTable from "@/static/json/missions-drop-table.json";
|
||||||
|
import { modNames, relicNames, miscNames, resourceNames, gearNames, blueprintNames } from "@/static/data/items";
|
||||||
|
|
||||||
|
// need reverse engineer rewardSeed, otherwise ingame displayed rotation reward will be different than added to db or displayed on mission end
|
||||||
|
const getRewards = (
|
||||||
|
rewardInfo: IMissionInventoryUpdateRewardInfo | undefined
|
||||||
|
): { InventoryChanges: IMissionInventoryUpdate; MissionRewards: IMissionRewardResponse[] } => {
|
||||||
|
if (!rewardInfo) {
|
||||||
|
return { InventoryChanges: {}, MissionRewards: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const rewards = (missionsDropTable as { [key: string]: IReward[] })[rewardInfo.node];
|
||||||
|
if (!rewards) {
|
||||||
|
return { InventoryChanges: {}, MissionRewards: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const rotationCount = rewardInfo.rewardQualifications?.length || 0;
|
||||||
|
const rotations = getRotations(rotationCount);
|
||||||
|
const drops: IReward[] = [];
|
||||||
|
for (const rotation of rotations) {
|
||||||
|
const rotationRewards = rewards.filter(reward => reward.rotation === rotation);
|
||||||
|
|
||||||
|
// Separate guaranteed and chance drops
|
||||||
|
const guaranteedDrops: IReward[] = [];
|
||||||
|
const chanceDrops: IReward[] = [];
|
||||||
|
for (const reward of rotationRewards) {
|
||||||
|
if (reward.chance === 100) {
|
||||||
|
guaranteedDrops.push(reward);
|
||||||
|
} else {
|
||||||
|
chanceDrops.push(reward);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const randomDrop = getRandomRewardByChance(chanceDrops);
|
||||||
|
if (randomDrop) {
|
||||||
|
guaranteedDrops.push(randomDrop);
|
||||||
|
}
|
||||||
|
|
||||||
|
drops.push(...guaranteedDrops);
|
||||||
|
}
|
||||||
|
|
||||||
|
// const testDrops = [
|
||||||
|
// { chance: 7.69, name: "Lith W3 Relic", rotation: "B" },
|
||||||
|
// { chance: 7.69, name: "Lith W3 Relic", rotation: "B" },
|
||||||
|
// { chance: 10.82, name: "2X Orokin Cell", rotation: "C" },
|
||||||
|
// { chance: 10.82, name: "Arrow Mutation", rotation: "C" },
|
||||||
|
// { chance: 10.82, name: "200 Endo", rotation: "C" },
|
||||||
|
// { chance: 10.82, name: "2,000,000 Credits Cache", rotation: "C" },
|
||||||
|
// { chance: 7.69, name: "Health Restore (Large)", rotation: "C" },
|
||||||
|
// { chance: 7.69, name: "Vapor Specter Blueprint", rotation: "C" }
|
||||||
|
// ];
|
||||||
|
// console.log("Mission rewards:", testDrops);
|
||||||
|
// return formatRewardsToInventoryType(testDrops);
|
||||||
|
|
||||||
|
console.log("Mission rewards:", drops);
|
||||||
|
return formatRewardsToInventoryType(drops);
|
||||||
|
};
|
||||||
|
|
||||||
|
const combineRewardAndLootInventory = (
|
||||||
|
rewardInventory: IMissionInventoryUpdate,
|
||||||
|
lootInventory: IMissionInventoryUpdate
|
||||||
|
) => {
|
||||||
|
const missionCredits = lootInventory.RegularCredits || 0;
|
||||||
|
const creditsBonus = rewardInventory.RegularCredits || 0;
|
||||||
|
const totalCredits = missionCredits + creditsBonus;
|
||||||
|
const FusionPoints = (lootInventory.FusionPoints || 0) + (rewardInventory.FusionPoints || 0) || undefined;
|
||||||
|
|
||||||
|
lootInventory.RegularCredits = totalCredits;
|
||||||
|
if (FusionPoints) {
|
||||||
|
lootInventory.FusionPoints = FusionPoints;
|
||||||
|
}
|
||||||
|
inventoryFields.forEach((field: IInventoryFieldType) => {
|
||||||
|
if (rewardInventory[field] && !lootInventory[field]) {
|
||||||
|
lootInventory[field] = [];
|
||||||
|
}
|
||||||
|
rewardInventory[field]?.forEach(item => lootInventory[field]!.push(item));
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
combinedInventoryChanges: lootInventory,
|
||||||
|
TotalCredits: [totalCredits, totalCredits],
|
||||||
|
CreditsBonus: [creditsBonus, creditsBonus],
|
||||||
|
MissionCredits: [missionCredits, missionCredits],
|
||||||
|
...(FusionPoints !== undefined && { FusionPoints })
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getRotations = (rotationCount: number): (string | undefined)[] => {
|
||||||
|
if (rotationCount === 0) return [undefined];
|
||||||
|
|
||||||
|
const rotationPattern = ["A", "A", "B", "C"];
|
||||||
|
let rotationIndex = 0;
|
||||||
|
const rotatedValues = [];
|
||||||
|
|
||||||
|
for (let i = 1; i <= rotationCount; i++) {
|
||||||
|
rotatedValues.push(rotationPattern[rotationIndex]);
|
||||||
|
rotationIndex = (rotationIndex + 1) % 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rotatedValues;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getRandomRewardByChance = (data: IReward[] | undefined): IReward | 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatRewardsToInventoryType = (
|
||||||
|
rewards: IReward[]
|
||||||
|
): { InventoryChanges: IMissionInventoryUpdate; MissionRewards: IMissionRewardResponse[] } => {
|
||||||
|
const InventoryChanges: IMissionInventoryUpdate = {};
|
||||||
|
const MissionRewards: IMissionRewardResponse[] = [];
|
||||||
|
for (const reward of rewards) {
|
||||||
|
if (itemCheck(InventoryChanges, MissionRewards, reward.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reward.name.includes(" Endo")) {
|
||||||
|
if (!InventoryChanges.FusionPoints) {
|
||||||
|
InventoryChanges.FusionPoints = 0;
|
||||||
|
}
|
||||||
|
InventoryChanges.FusionPoints += getCountFromName(reward.name);
|
||||||
|
} else if (reward.name.includes(" Credits Cache") || reward.name.includes("Return: ")) {
|
||||||
|
if (!InventoryChanges.RegularCredits) {
|
||||||
|
InventoryChanges.RegularCredits = 0;
|
||||||
|
}
|
||||||
|
InventoryChanges.RegularCredits += getCountFromName(reward.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { InventoryChanges, MissionRewards };
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemCheck = (
|
||||||
|
InventoryChanges: IMissionInventoryUpdate,
|
||||||
|
MissionRewards: IMissionRewardResponse[],
|
||||||
|
name: string
|
||||||
|
) => {
|
||||||
|
const rewardCheck = {
|
||||||
|
RawUpgrades: modNames[name],
|
||||||
|
Consumables: gearNames[name],
|
||||||
|
MiscItems:
|
||||||
|
miscNames[name] ||
|
||||||
|
miscNames[name.replace(/\d+X\s*/, "")] ||
|
||||||
|
resourceNames[name] ||
|
||||||
|
resourceNames[name.replace(/\d+X\s*/, "")] ||
|
||||||
|
relicNames[name.replace("Relic", "Intact")] ||
|
||||||
|
relicNames[name.replace("Relic (Radiant)", "Radiant")],
|
||||||
|
Recipes: blueprintNames[name]
|
||||||
|
};
|
||||||
|
for (const key of Object.keys(rewardCheck) as IInventoryFieldType[]) {
|
||||||
|
if (rewardCheck[key]) {
|
||||||
|
addRewardResponse(InventoryChanges, MissionRewards, name, rewardCheck[key]!, key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCountFromName = (name: string) => {
|
||||||
|
const regex = /(^(?:\d{1,3}(?:,\d{3})*(?:\.\d+)?)(\s|X))|(\s(?:\d{1,3}(?:,\d{3})*(?:\.\d+)?)$)/;
|
||||||
|
const countMatches = name.match(regex);
|
||||||
|
return countMatches ? parseInt(countMatches[0].replace(/,/g, ""), 10) : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
const addRewardResponse = (
|
||||||
|
InventoryChanges: IMissionInventoryUpdate,
|
||||||
|
MissionRewards: IMissionRewardResponse[],
|
||||||
|
ItemName: string,
|
||||||
|
ItemType: string,
|
||||||
|
InventoryCategory: IInventoryFieldType
|
||||||
|
) => {
|
||||||
|
if (!ItemType) return;
|
||||||
|
|
||||||
|
if (!InventoryChanges[InventoryCategory]) {
|
||||||
|
InventoryChanges[InventoryCategory] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ItemCount = getCountFromName(ItemName);
|
||||||
|
const TweetText = `${ItemName}`;
|
||||||
|
|
||||||
|
const existReward = InventoryChanges[InventoryCategory]!.find(item => item.ItemType === ItemType);
|
||||||
|
if (existReward) {
|
||||||
|
existReward.ItemCount += ItemCount;
|
||||||
|
const missionReward = MissionRewards.find(missionReward => missionReward.TypeName === ItemType);
|
||||||
|
if (missionReward) {
|
||||||
|
missionReward.ItemCount += ItemCount;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
InventoryChanges[InventoryCategory]!.push({ ItemType, ItemCount });
|
||||||
|
MissionRewards.push({
|
||||||
|
ItemCount,
|
||||||
|
TweetText,
|
||||||
|
ProductCategory: InventoryCategory,
|
||||||
|
StoreItem: ItemType.replace("/Lotus/", "/Lotus/StoreItems/"),
|
||||||
|
TypeName: ItemType
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const _missionRewardsCheckAllNamings = () => {
|
||||||
|
let tempRewards: IReward[] = [];
|
||||||
|
Object.values(missionsDropTable as { [key: string]: IReward[] }).forEach(rewards => {
|
||||||
|
rewards.forEach(reward => {
|
||||||
|
tempRewards.push(reward);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
tempRewards = tempRewards
|
||||||
|
.filter(reward => !modNames[reward.name])
|
||||||
|
.filter(reward => !miscNames[reward.name])
|
||||||
|
.filter(reward => !miscNames[reward.name.replace(/\d+X\s*/, "")])
|
||||||
|
.filter(reward => !resourceNames[reward.name])
|
||||||
|
.filter(reward => !resourceNames[reward.name.replace(/\d+X\s*/, "")])
|
||||||
|
.filter(reward => !gearNames[reward.name])
|
||||||
|
.filter(reward => {
|
||||||
|
return (
|
||||||
|
!relicNames[reward.name.replace("Relic", "Intact")] &&
|
||||||
|
!relicNames[reward.name.replace("Relic (Radiant)", "Radiant")]
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.filter(reward => !blueprintNames[reward.name])
|
||||||
|
.filter(reward => !reward.name.includes(" Endo"))
|
||||||
|
.filter(reward => !reward.name.includes(" Credits Cache") && !reward.name.includes("Return: "));
|
||||||
|
console.log(tempRewards);
|
||||||
|
};
|
||||||
|
// _missionRewardsCheckAllNamings();
|
||||||
|
|
||||||
|
export { getRewards, combineRewardAndLootInventory };
|
@ -2,6 +2,8 @@
|
|||||||
import { IOid } from "./commonTypes";
|
import { IOid } from "./commonTypes";
|
||||||
import { IDate } from "./inventoryTypes/inventoryTypes";
|
import { IDate } from "./inventoryTypes/inventoryTypes";
|
||||||
|
|
||||||
|
export const inventoryFields = ["RawUpgrades", "MiscItems", "Consumables", "Recipes"] as const;
|
||||||
|
export type IInventoryFieldType = (typeof inventoryFields)[number];
|
||||||
export interface IMissionInventoryUpdateGear {
|
export interface IMissionInventoryUpdateGear {
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
ItemName: string;
|
ItemName: string;
|
||||||
|
@ -18,8 +18,8 @@ export const items: MinItem[] = new Items({ category: ["All"] }).map(item => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const getNamesObj = (category: Category) =>
|
const getNamesObj = (category: Category) =>
|
||||||
new Items({ category: [category] }).reduce((acc, i) => {
|
new Items({ category: [category] }).reduce((acc, item) => {
|
||||||
acc[i.name!.replace("'S", "'s")] = i.uniqueName!;
|
acc[item.name!.replace("'S", "'s")] = item.uniqueName!;
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as ImportAssertions);
|
}, {} as ImportAssertions);
|
||||||
|
|
||||||
@ -47,14 +47,14 @@ export const craftNames: ImportAssertions = Object.fromEntries(
|
|||||||
]
|
]
|
||||||
}) as Warframe[]
|
}) as Warframe[]
|
||||||
)
|
)
|
||||||
.flatMap(j => j.components || [])
|
.flatMap(item => item.components || [])
|
||||||
.filter(i => i.drops && i.drops[0])
|
.filter(item => item.drops && item.drops[0])
|
||||||
.map(i => [i.drops![0].type, i.uniqueName])
|
.map(item => [item.drops![0].type, item.uniqueName])
|
||||||
);
|
);
|
||||||
craftNames["Forma Blueprint"] = "/Lotus/StoreItems/Types/Items/MiscItems/Forma";
|
craftNames["Forma Blueprint"] = "/Lotus/Types/Recipes/Components/FormaBlueprint";
|
||||||
|
|
||||||
export const blueprintNames: ImportAssertions = Object.fromEntries(
|
export const blueprintNames: ImportAssertions = Object.fromEntries(
|
||||||
Object.keys(craftNames)
|
Object.keys(craftNames)
|
||||||
.filter(i => i.includes("Blueprint"))
|
.filter(name => name.includes("Blueprint"))
|
||||||
.map(i => [i, craftNames[i]])
|
.map(name => [name, craftNames[name]])
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user