Mission reward - blueprints
This commit is contained in:
parent
dcf21a8e76
commit
f9b87e44af
@ -9,7 +9,7 @@ import {
|
|||||||
import { RawUpgrade } from "@/src/types/inventoryTypes/inventoryTypes";
|
import { RawUpgrade } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
|
|
||||||
import missionsDropTable from "@/static/json/missions-drop-table.json";
|
import missionsDropTable from "@/static/json/missions-drop-table.json";
|
||||||
import { modNames, relicNames, miscNames, resourceNames, gearNames, craftNames } from "@/static/data/items";
|
import { modNames, relicNames, miscNames, resourceNames, gearNames, blueprintNames } from "@/static/data/items";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
**** INPUT ****
|
**** INPUT ****
|
||||||
@ -69,20 +69,15 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
|
|||||||
const MissionCredits = [missionCredits, missionCredits];
|
const MissionCredits = [missionCredits, missionCredits];
|
||||||
const CreditsBonus = [creditsBonus, creditsBonus];
|
const CreditsBonus = [creditsBonus, creditsBonus];
|
||||||
const TotalCredits = [totalCredits, totalCredits];
|
const TotalCredits = [totalCredits, totalCredits];
|
||||||
const FusionPoints =
|
const FusionPoints = (parsedData.FusionPoints || 0) + (InventoryChanges.FusionPoints || 0) || undefined;
|
||||||
parsedData.FusionPoints || InventoryChanges.FusionPoints
|
|
||||||
? (parsedData.FusionPoints || 0) + (InventoryChanges.FusionPoints || 0)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
// combine reward and loot
|
// combine reward and loot
|
||||||
parsedData.RegularCredits = totalCredits;
|
parsedData.RegularCredits = totalCredits;
|
||||||
if (FusionPoints) parsedData.FusionPoints = FusionPoints;
|
if (FusionPoints) parsedData.FusionPoints = FusionPoints;
|
||||||
if (InventoryChanges.RawUpgrades && !parsedData.RawUpgrades) parsedData.RawUpgrades = [];
|
inventoryFields.forEach((field: InventoryFieldType) => {
|
||||||
InventoryChanges.RawUpgrades?.forEach(i => parsedData.RawUpgrades!.push(i));
|
if (InventoryChanges[field] && !parsedData[field]) parsedData[field] = [];
|
||||||
if (InventoryChanges.MiscItems && !parsedData.MiscItems) parsedData.MiscItems = [];
|
InventoryChanges[field]?.forEach(i => parsedData[field]!.push(i));
|
||||||
InventoryChanges.MiscItems?.forEach(i => parsedData.MiscItems!.push(i));
|
});
|
||||||
if (InventoryChanges.Consumables && !parsedData.Consumables) parsedData.Consumables = [];
|
|
||||||
InventoryChanges.Consumables?.forEach(i => parsedData.Consumables!.push(i));
|
|
||||||
|
|
||||||
const Inventory = await missionInventoryUpdate(parsedData, id);
|
const Inventory = await missionInventoryUpdate(parsedData, id);
|
||||||
InventoryChanges.RawUpgrades?.forEach(
|
InventoryChanges.RawUpgrades?.forEach(
|
||||||
@ -115,6 +110,9 @@ 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
|
// need reverse engineer rewardSeed, otherwise ingame displayed rotation loot will be different than added to db
|
||||||
const getRewards = (
|
const getRewards = (
|
||||||
rewardInfo: IMissionInventoryUpdateRewardInfo | undefined
|
rewardInfo: IMissionInventoryUpdateRewardInfo | undefined
|
||||||
@ -151,7 +149,8 @@ const getRewards = (
|
|||||||
// { chance: 10.82, name: "Link Armor", rotation: "C" },
|
// { chance: 10.82, name: "Link Armor", rotation: "C" },
|
||||||
// // { chance: 10.82, name: "200 Endo", rotation: "C" },
|
// // { chance: 10.82, name: "200 Endo", rotation: "C" },
|
||||||
// { chance: 10.82, name: "2,000,000 Credits Cache", 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: "Health Restore (Large)", rotation: "C" },
|
||||||
|
// { chance: 7.69, name: "Vapor Specter Blueprint", rotation: "C" }
|
||||||
// ];
|
// ];
|
||||||
// console.log("Mission rewards:", testDrops);
|
// console.log("Mission rewards:", testDrops);
|
||||||
// return formatRewardsToInventoryType(testDrops);
|
// return formatRewardsToInventoryType(testDrops);
|
||||||
@ -200,21 +199,12 @@ const formatRewardsToInventoryType = (
|
|||||||
rewards.forEach(i => {
|
rewards.forEach(i => {
|
||||||
const mod = modNames[i.name];
|
const mod = modNames[i.name];
|
||||||
const gear = gearNames[i.name];
|
const gear = gearNames[i.name];
|
||||||
const craft = craftNames[i.name];
|
const blueprint = blueprintNames[i.name];
|
||||||
const misc = miscNames[i.name] || miscNames[i.name.replace(/\d+X\s*/, "")];
|
const misc = miscNames[i.name] || miscNames[i.name.replace(/\d+X\s*/, "")];
|
||||||
const resource = resourceNames[i.name] || resourceNames[i.name.replace(/\d+X\s*/, "")];
|
const resource = resourceNames[i.name] || resourceNames[i.name.replace(/\d+X\s*/, "")];
|
||||||
const relic =
|
const relic =
|
||||||
relicNames[i.name.replace("Relic", "Intact")] || relicNames[i.name.replace("Relic (Radiant)", "Radiant")];
|
relicNames[i.name.replace("Relic", "Intact")] || relicNames[i.name.replace("Relic (Radiant)", "Radiant")];
|
||||||
|
|
||||||
// console.log({
|
|
||||||
// mod,
|
|
||||||
// gear,
|
|
||||||
// misc,
|
|
||||||
// resource,
|
|
||||||
// relic,
|
|
||||||
// craft
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (mod) {
|
if (mod) {
|
||||||
addRewardResponse(InventoryChanges, MissionRewards, i.name, mod, "RawUpgrades");
|
addRewardResponse(InventoryChanges, MissionRewards, i.name, mod, "RawUpgrades");
|
||||||
} else if (gear) {
|
} else if (gear) {
|
||||||
@ -223,8 +213,8 @@ const formatRewardsToInventoryType = (
|
|||||||
addRewardResponse(InventoryChanges, MissionRewards, i.name, misc || resource, "MiscItems");
|
addRewardResponse(InventoryChanges, MissionRewards, i.name, misc || resource, "MiscItems");
|
||||||
} else if (relic) {
|
} else if (relic) {
|
||||||
addRewardResponse(InventoryChanges, MissionRewards, i.name, relic, "MiscItems");
|
addRewardResponse(InventoryChanges, MissionRewards, i.name, relic, "MiscItems");
|
||||||
} else if (craft) {
|
} else if (blueprint) {
|
||||||
/* craft */
|
addRewardResponse(InventoryChanges, MissionRewards, i.name, blueprint, "Recipes");
|
||||||
} else if (i.name.includes(" Endo")) {
|
} else if (i.name.includes(" Endo")) {
|
||||||
if (!InventoryChanges.FusionPoints) InventoryChanges.FusionPoints = 0;
|
if (!InventoryChanges.FusionPoints) InventoryChanges.FusionPoints = 0;
|
||||||
InventoryChanges.FusionPoints += getCountFromName(i.name);
|
InventoryChanges.FusionPoints += getCountFromName(i.name);
|
||||||
@ -247,7 +237,7 @@ const addRewardResponse = (
|
|||||||
MissionRewards: IMissionRewardResponse[],
|
MissionRewards: IMissionRewardResponse[],
|
||||||
ItemName: string,
|
ItemName: string,
|
||||||
ItemType: string,
|
ItemType: string,
|
||||||
InventoryCategory: "MiscItems" | "RawUpgrades" | "Consumables"
|
InventoryCategory: InventoryFieldType
|
||||||
) => {
|
) => {
|
||||||
if (!ItemType) return;
|
if (!ItemType) return;
|
||||||
if (!InventoryChanges[InventoryCategory]) InventoryChanges[InventoryCategory] = [];
|
if (!InventoryChanges[InventoryCategory]) InventoryChanges[InventoryCategory] = [];
|
||||||
@ -292,7 +282,7 @@ const _missionRewardsCheckAllNamings = () => {
|
|||||||
!relicNames[i.name.replace("Relic (Radiant)", "Radiant")]
|
!relicNames[i.name.replace("Relic (Radiant)", "Radiant")]
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.filter(i => !craftNames[i.name])
|
.filter(i => !blueprintNames[i.name])
|
||||||
.filter(i => !i.name.includes(" Endo"))
|
.filter(i => !i.name.includes(" Endo"))
|
||||||
.filter(i => !i.name.includes(" Credits Cache") && !i.name.includes("Return: "));
|
.filter(i => !i.name.includes(" Credits Cache") && !i.name.includes("Return: "));
|
||||||
console.log(tempRewards);
|
console.log(tempRewards);
|
||||||
|
@ -163,6 +163,21 @@ const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: Consu
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: Consumable[] | undefined) => {
|
||||||
|
const { Recipes } = inventory;
|
||||||
|
|
||||||
|
itemsArray?.forEach(({ ItemCount, ItemType }) => {
|
||||||
|
const itemIndex = Recipes.findIndex(i => i.ItemType === ItemType);
|
||||||
|
|
||||||
|
if (itemIndex !== -1) {
|
||||||
|
Recipes[itemIndex].ItemCount += ItemCount;
|
||||||
|
inventory.markModified(`Recipes.${itemIndex}.ItemCount`);
|
||||||
|
} else {
|
||||||
|
Recipes.push({ ItemCount, ItemType });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const addMods = (inventory: IInventoryDatabaseDocument, itemsArray: RawUpgrade[] | undefined) => {
|
const addMods = (inventory: IInventoryDatabaseDocument, itemsArray: RawUpgrade[] | undefined) => {
|
||||||
const { RawUpgrades } = inventory;
|
const { RawUpgrades } = inventory;
|
||||||
itemsArray?.forEach(({ ItemType, ItemCount }) => {
|
itemsArray?.forEach(({ ItemType, ItemCount }) => {
|
||||||
@ -196,7 +211,7 @@ const gearKeys = ["Suits", "Pistols", "LongGuns", "Melee"] as const;
|
|||||||
type GearKeysType = (typeof gearKeys)[number];
|
type GearKeysType = (typeof gearKeys)[number];
|
||||||
|
|
||||||
export const missionInventoryUpdate = async (data: IMissionInventoryUpdate, accountId: string) => {
|
export const missionInventoryUpdate = async (data: IMissionInventoryUpdate, accountId: string) => {
|
||||||
const { RawUpgrades, MiscItems, RegularCredits, ChallengeProgress, FusionPoints, Consumables } = data;
|
const { RawUpgrades, MiscItems, RegularCredits, ChallengeProgress, FusionPoints, Consumables, Recipes } = data;
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
|
|
||||||
// credits
|
// credits
|
||||||
@ -212,6 +227,7 @@ export const missionInventoryUpdate = async (data: IMissionInventoryUpdate, acco
|
|||||||
addMods(inventory, RawUpgrades);
|
addMods(inventory, RawUpgrades);
|
||||||
addMiscItems(inventory, MiscItems);
|
addMiscItems(inventory, MiscItems);
|
||||||
addConsumables(inventory, Consumables);
|
addConsumables(inventory, Consumables);
|
||||||
|
addRecipes(inventory, Recipes);
|
||||||
addChallenges(inventory, ChallengeProgress);
|
addChallenges(inventory, ChallengeProgress);
|
||||||
|
|
||||||
const changedInventory = await inventory.save();
|
const changedInventory = await inventory.save();
|
||||||
|
@ -69,6 +69,7 @@ export interface IMissionInventoryUpdate {
|
|||||||
RawUpgrades?: IMissionInventoryUpdateItem[];
|
RawUpgrades?: IMissionInventoryUpdateItem[];
|
||||||
MiscItems?: IMissionInventoryUpdateItem[];
|
MiscItems?: IMissionInventoryUpdateItem[];
|
||||||
Consumables?: IMissionInventoryUpdateItem[];
|
Consumables?: IMissionInventoryUpdateItem[];
|
||||||
|
Recipes?: IMissionInventoryUpdateItem[];
|
||||||
RegularCredits?: number;
|
RegularCredits?: number;
|
||||||
ChallengeProgress?: IMissionInventoryUpdateChallange[];
|
ChallengeProgress?: IMissionInventoryUpdateChallange[];
|
||||||
RewardInfo?: IMissionInventoryUpdateRewardInfo;
|
RewardInfo?: IMissionInventoryUpdateRewardInfo;
|
||||||
|
@ -19,7 +19,7 @@ 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, i) => {
|
||||||
acc[i.name!] = category !== "Mods" ? i.uniqueName! : i.uniqueName!.replace("'S", "'s");
|
acc[i.name!.replace("'S", "'s")] = i.uniqueName!;
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as ImportAssertions);
|
}, {} as ImportAssertions);
|
||||||
|
|
||||||
@ -52,3 +52,9 @@ export const craftNames: ImportAssertions = Object.fromEntries(
|
|||||||
.map(i => [i.drops![0].type, i.uniqueName])
|
.map(i => [i.drops![0].type, i.uniqueName])
|
||||||
);
|
);
|
||||||
craftNames["Forma Blueprint"] = "/Lotus/StoreItems/Types/Items/MiscItems/Forma";
|
craftNames["Forma Blueprint"] = "/Lotus/StoreItems/Types/Items/MiscItems/Forma";
|
||||||
|
|
||||||
|
export const blueprintNames: ImportAssertions = Object.fromEntries(
|
||||||
|
Object.keys(craftNames)
|
||||||
|
.filter(i => i.includes("Blueprint"))
|
||||||
|
.map(i => [i, craftNames[i]])
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user