forked from OpenWF/SpaceNinjaServer
MissionInventoryUpdate(not completed), Mod upgrade, Booster purchase (#49)
Co-authored-by: OrdisPrime <134585663+OrdisPrime@users.noreply.github.com> Co-authored-by: Ângelo Tadeucci <angelo_tadeucci@hotmail.com.br>
This commit is contained in:
parent
a931863249
commit
01cfecd9d2
@ -8,4 +8,4 @@
|
||||
"skipTutorial": true,
|
||||
"testMission": true,
|
||||
"testQuestKey": true
|
||||
}
|
||||
}
|
23
src/controllers/api/artifactsController.ts
Normal file
23
src/controllers/api/artifactsController.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { upgradeMod } from "@/src/services/inventoryService";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
const artifactsController: RequestHandler = async (req, res) => {
|
||||
const [data] = String(req.body).split("\n");
|
||||
const id = req.query.accountId as string;
|
||||
|
||||
// TODO - salt check
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const parsedData = JSON.parse(data);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
const upgradeModId = await upgradeMod(parsedData, id);
|
||||
res.send(upgradeModId);
|
||||
} catch (err) {
|
||||
console.error("Error parsing JSON data:", err);
|
||||
}
|
||||
};
|
||||
|
||||
export { artifactsController };
|
@ -1,7 +1,9 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { missionInventoryUpdate } from "@/src/services/inventoryService";
|
||||
import { combineRewardAndLootInventory, getRewards } from "@/src/services/missionInventoryUpdateService ";
|
||||
import { IMissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType";
|
||||
/*
|
||||
**** INPUT ****
|
||||
- [ ] crossPlaySetting
|
||||
- [ ] rewardsMultiplier
|
||||
- [ ] ActiveBoosters
|
||||
@ -27,7 +29,7 @@ import { IMissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType"
|
||||
- [ ] SeasonChallengeHistory
|
||||
- [ ] PS (Passive anti-cheat data which includes your username, module list, process list, and system name.)
|
||||
- [ ] ActiveDojoColorResearch
|
||||
- [ ] RewardInfo
|
||||
- [x] RewardInfo
|
||||
- [ ] ReceivedCeremonyMsg
|
||||
- [ ] LastCeremonyResetDate
|
||||
- [ ] MissionPTS (Used to validate the mission/alive time above.)
|
||||
@ -42,20 +44,45 @@ import { IMissionInventoryUpdate } from "@/src/types/missionInventoryUpdateType"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
const missionInventoryUpdateController: RequestHandler = async (req, res) => {
|
||||
const [data] = String(req.body).split("\n");
|
||||
const id = req.query.accountId as string;
|
||||
|
||||
const [data] = String(req.body).split("\n");
|
||||
|
||||
try {
|
||||
const parsedData = JSON.parse(data) as IMissionInventoryUpdate;
|
||||
if (typeof parsedData !== "object") throw new Error("Invalid data format");
|
||||
await missionInventoryUpdate(parsedData, id);
|
||||
const lootInventory = JSON.parse(data) as IMissionInventoryUpdate;
|
||||
if (typeof lootInventory !== "object" || lootInventory === null) {
|
||||
throw new Error("Invalid data format");
|
||||
}
|
||||
|
||||
const { InventoryChanges, MissionRewards } = getRewards(lootInventory.RewardInfo);
|
||||
|
||||
const { combinedInventoryChanges, TotalCredits, CreditsBonus, MissionCredits, FusionPoints } =
|
||||
combineRewardAndLootInventory(InventoryChanges, lootInventory);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const InventoryJson = JSON.stringify(await missionInventoryUpdate(combinedInventoryChanges, id));
|
||||
res.json({
|
||||
// InventoryJson, // this part will reset game data and missions will be locked
|
||||
MissionRewards,
|
||||
InventoryChanges,
|
||||
TotalCredits,
|
||||
CreditsBonus,
|
||||
MissionCredits,
|
||||
...(FusionPoints !== undefined && { FusionPoints })
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error parsing JSON data:", err);
|
||||
}
|
||||
|
||||
// TODO - Return the updated inventory the way the game does it.
|
||||
res.json({});
|
||||
};
|
||||
|
||||
/*
|
||||
**** OUTPUT ****
|
||||
- [x] InventoryJson
|
||||
- [x] MissionRewards
|
||||
- [x] TotalCredits
|
||||
- [x] CreditsBonus
|
||||
- [x] MissionCredits
|
||||
- [x] InventoryChanges
|
||||
- [x] FusionPoints
|
||||
*/
|
||||
|
||||
export { missionInventoryUpdateController };
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
IBooster
|
||||
} from "../types/inventoryTypes/inventoryTypes";
|
||||
import { IOid } from "../types/commonTypes";
|
||||
import { ISuitDatabase, ISuitDocument } from "@/src/types/inventoryTypes/SuitTypes";
|
||||
import { ISuitDatabase } from "@/src/types/inventoryTypes/SuitTypes";
|
||||
import { IWeaponDatabase } from "@/src/types/inventoryTypes/weaponTypes";
|
||||
|
||||
const abilityOverrideSchema = new Schema({
|
||||
@ -77,6 +77,34 @@ const BoosterSchema = new Schema({
|
||||
ItemType: String
|
||||
});
|
||||
|
||||
const RawUpgrades = new Schema({
|
||||
ItemType: String,
|
||||
ItemCount: Number
|
||||
});
|
||||
|
||||
RawUpgrades.set("toJSON", {
|
||||
transform(_document, returnedObject) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||
returnedObject.LastAdded = { $oid: returnedObject._id.toString() } satisfies IOid;
|
||||
delete returnedObject._id;
|
||||
delete returnedObject.__v;
|
||||
}
|
||||
});
|
||||
|
||||
const Upgrade = new Schema({
|
||||
UpgradeFingerprint: String,
|
||||
ItemType: String
|
||||
});
|
||||
|
||||
Upgrade.set("toJSON", {
|
||||
transform(_document, returnedObject) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||
returnedObject.ItemId = { $oid: returnedObject._id.toString() } satisfies IOid;
|
||||
delete returnedObject._id;
|
||||
delete returnedObject.__v;
|
||||
}
|
||||
});
|
||||
|
||||
WeaponSchema.set("toJSON", {
|
||||
transform(_document, returnedObject) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
||||
@ -187,7 +215,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>({
|
||||
MiscItems: [Schema.Types.Mixed],
|
||||
ChallengesFixVersion: Number,
|
||||
ChallengeProgress: [Schema.Types.Mixed],
|
||||
RawUpgrades: [Schema.Types.Mixed],
|
||||
RawUpgrades: [RawUpgrades],
|
||||
ReceivedStartingGear: Boolean,
|
||||
Suits: [suitSchema],
|
||||
LongGuns: [WeaponSchema],
|
||||
@ -209,7 +237,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>({
|
||||
PendingRecipes: [Schema.Types.Mixed],
|
||||
TrainingDate: Schema.Types.Mixed,
|
||||
PlayerLevel: Number,
|
||||
Upgrades: [Schema.Types.Mixed],
|
||||
Upgrades: [Upgrade],
|
||||
EquippedGear: [String],
|
||||
DeathMarks: [String],
|
||||
FusionTreasures: [Schema.Types.Mixed],
|
||||
@ -350,7 +378,7 @@ type InventoryDocumentProps = {
|
||||
Boosters: Types.DocumentArray<IBooster>;
|
||||
};
|
||||
|
||||
type InventoryModelType = Model<IInventoryDatabase, {}, InventoryDocumentProps>;
|
||||
type InventoryModelType = Model<IInventoryDatabase, object, InventoryDocumentProps>;
|
||||
|
||||
const Inventory = model<IInventoryDatabase, InventoryModelType>("Inventory", inventorySchema);
|
||||
|
||||
|
@ -29,6 +29,7 @@ import { updateSessionGetController, updateSessionPostController } from "@/src/c
|
||||
import { viewController } from "@/src/controllers/api/viewController";
|
||||
import { joinSessionController } from "@/src/controllers/api/joinSessionController";
|
||||
import { saveLoadoutController } from "@/src/controllers/api/saveLoadout";
|
||||
import { artifactsController } from "../controllers/api/artifactsController";
|
||||
|
||||
import express from "express";
|
||||
|
||||
@ -58,6 +59,7 @@ apiRouter.get("/deleteSession.php", deleteSessionController);
|
||||
apiRouter.get("/logout.php", logoutController);
|
||||
|
||||
// post
|
||||
apiRouter.post("/artifacts.php", artifactsController);
|
||||
apiRouter.post("/findSessions.php", findSessionsController);
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
apiRouter.post("/purchase.php", purchaseController);
|
||||
|
@ -7,15 +7,14 @@ import { SlotType } from "@/src/types/purchaseTypes";
|
||||
import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
|
||||
import {
|
||||
IChallengeProgress,
|
||||
IConsumable,
|
||||
ICrewShipSalvagedWeaponSkin,
|
||||
IFlavourItem,
|
||||
IInventoryDatabaseDocument
|
||||
IInventoryDatabaseDocument,
|
||||
IMiscItem,
|
||||
IRawUpgrade
|
||||
} from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import {
|
||||
IMissionInventoryUpdate,
|
||||
IMissionInventoryUpdateCard,
|
||||
IMissionInventoryUpdateGear,
|
||||
IMissionInventoryUpdateItem
|
||||
} from "../types/missionInventoryUpdateType";
|
||||
import { IMissionInventoryUpdate, IMissionInventoryUpdateGear } from "../types/missionInventoryUpdateType";
|
||||
import { IGenericUpdate } from "../types/genericUpdate";
|
||||
|
||||
const createInventory = async (accountOwnerId: Types.ObjectId) => {
|
||||
@ -146,7 +145,7 @@ const addGearExpByCategory = (
|
||||
const category = inventory[categoryName];
|
||||
|
||||
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];
|
||||
|
||||
if (itemIndex !== -1 && item.XP != undefined) {
|
||||
@ -156,21 +155,61 @@ const addGearExpByCategory = (
|
||||
});
|
||||
};
|
||||
|
||||
const addItemsByCategory = (
|
||||
inventory: IInventoryDatabaseDocument,
|
||||
itemsArray: (IMissionInventoryUpdateItem | IMissionInventoryUpdateCard)[] | undefined,
|
||||
categoryName: "RawUpgrades" | "MiscItems"
|
||||
) => {
|
||||
const category = inventory[categoryName];
|
||||
const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray: IMiscItem[] | undefined) => {
|
||||
const { MiscItems } = inventory;
|
||||
|
||||
itemsArray?.forEach(({ ItemCount, ItemType }) => {
|
||||
const itemIndex = category.findIndex(i => i.ItemType === ItemType);
|
||||
const itemIndex = MiscItems.findIndex(miscItem => miscItem.ItemType === ItemType);
|
||||
|
||||
if (itemIndex !== -1) {
|
||||
category[itemIndex].ItemCount += ItemCount;
|
||||
inventory.markModified(`${categoryName}.${itemIndex}.ItemCount`);
|
||||
MiscItems[itemIndex].ItemCount += ItemCount;
|
||||
inventory.markModified(`MiscItems.${itemIndex}.ItemCount`);
|
||||
} else {
|
||||
category.push({ ItemCount, ItemType });
|
||||
MiscItems.push({ ItemCount, ItemType });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
|
||||
const { Consumables } = inventory;
|
||||
|
||||
itemsArray?.forEach(({ ItemCount, ItemType }) => {
|
||||
const itemIndex = Consumables.findIndex(i => i.ItemType === ItemType);
|
||||
|
||||
if (itemIndex !== -1) {
|
||||
Consumables[itemIndex].ItemCount += ItemCount;
|
||||
inventory.markModified(`Consumables.${itemIndex}.ItemCount`);
|
||||
} else {
|
||||
Consumables.push({ ItemCount, ItemType });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const addRecipes = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | 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: IRawUpgrade[] | undefined) => {
|
||||
const { RawUpgrades } = inventory;
|
||||
itemsArray?.forEach(({ ItemType, ItemCount }) => {
|
||||
const itemIndex = RawUpgrades.findIndex(i => i.ItemType === ItemType);
|
||||
|
||||
if (itemIndex !== -1) {
|
||||
RawUpgrades[itemIndex].ItemCount += ItemCount;
|
||||
inventory.markModified(`RawUpgrades.${itemIndex}.ItemCount`);
|
||||
} else {
|
||||
RawUpgrades.push({ ItemCount, ItemType });
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -193,20 +232,28 @@ const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray: IChall
|
||||
const gearKeys = ["Suits", "Pistols", "LongGuns", "Melee"] as const;
|
||||
type GearKeysType = (typeof gearKeys)[number];
|
||||
|
||||
export const missionInventoryUpdate = async (data: IMissionInventoryUpdate, accountId: string): Promise<void> => {
|
||||
const { RawUpgrades, MiscItems, RegularCredits, ChallengeProgress } = data;
|
||||
export const missionInventoryUpdate = async (data: IMissionInventoryUpdate, accountId: string) => {
|
||||
const { RawUpgrades, MiscItems, RegularCredits, ChallengeProgress, FusionPoints, Consumables, Recipes } = data;
|
||||
const inventory = await getInventory(accountId);
|
||||
|
||||
// credits
|
||||
inventory.RegularCredits += RegularCredits || 0;
|
||||
|
||||
// endo
|
||||
inventory.FusionPoints += FusionPoints || 0;
|
||||
|
||||
// Gear XP
|
||||
gearKeys.forEach((key: GearKeysType) => addGearExpByCategory(inventory, data[key], key));
|
||||
|
||||
// Other
|
||||
// TODO: Ensure mods have a valid fusion level and items have a valid quantity, preferably inside of the functions themselves.
|
||||
addItemsByCategory(inventory, RawUpgrades, "RawUpgrades");
|
||||
addItemsByCategory(inventory, MiscItems, "MiscItems");
|
||||
// other
|
||||
addMods(inventory, RawUpgrades);
|
||||
addMiscItems(inventory, MiscItems);
|
||||
addConsumables(inventory, Consumables);
|
||||
addRecipes(inventory, Recipes);
|
||||
addChallenges(inventory, ChallengeProgress);
|
||||
|
||||
await inventory.save();
|
||||
const changedInventory = await inventory.save();
|
||||
return changedInventory.toJSON();
|
||||
};
|
||||
|
||||
export const addBooster = async (ItemType: string, time: number, accountId: string): Promise<void> => {
|
||||
@ -215,7 +262,7 @@ export const addBooster = async (ItemType: string, time: number, accountId: stri
|
||||
const inventory = await getInventory(accountId);
|
||||
const { Boosters } = inventory;
|
||||
|
||||
const itemIndex = Boosters.findIndex(i => i.ItemType === ItemType);
|
||||
const itemIndex = Boosters.findIndex(booster => booster.ItemType === ItemType);
|
||||
|
||||
if (itemIndex !== -1) {
|
||||
const existingBooster = Boosters[itemIndex];
|
||||
@ -228,4 +275,62 @@ export const addBooster = async (ItemType: string, time: number, accountId: stri
|
||||
await inventory.save();
|
||||
};
|
||||
|
||||
export const upgradeMod = async (
|
||||
{
|
||||
Upgrade,
|
||||
LevelDiff,
|
||||
Cost,
|
||||
FusionPointCost
|
||||
}: { Upgrade: ICrewShipSalvagedWeaponSkin; LevelDiff: number; Cost: number; FusionPointCost: number },
|
||||
accountId: string
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
const inventory = await getInventory(accountId);
|
||||
const { Upgrades, RawUpgrades } = inventory;
|
||||
const { ItemType, UpgradeFingerprint, ItemId } = Upgrade;
|
||||
|
||||
const safeUpgradeFingerprint = UpgradeFingerprint || '{"lvl":0}';
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const parsedUpgradeFingerprint = JSON.parse(safeUpgradeFingerprint);
|
||||
parsedUpgradeFingerprint.lvl += LevelDiff;
|
||||
const stringifiedUpgradeFingerprint = JSON.stringify(parsedUpgradeFingerprint);
|
||||
|
||||
let itemIndex = Upgrades.findIndex(upgrade => upgrade._id?.equals(ItemId!.$oid));
|
||||
|
||||
if (itemIndex !== -1) {
|
||||
Upgrades[itemIndex].UpgradeFingerprint = stringifiedUpgradeFingerprint;
|
||||
inventory.markModified(`Upgrades.${itemIndex}.UpgradeFingerprint`);
|
||||
} else {
|
||||
itemIndex =
|
||||
Upgrades.push({
|
||||
UpgradeFingerprint: stringifiedUpgradeFingerprint,
|
||||
ItemType
|
||||
}) - 1;
|
||||
|
||||
const rawItemIndex = RawUpgrades.findIndex(rawUpgrade => rawUpgrade.ItemType === ItemType);
|
||||
RawUpgrades[rawItemIndex].ItemCount--;
|
||||
if (RawUpgrades[rawItemIndex].ItemCount > 0) {
|
||||
inventory.markModified(`RawUpgrades.${rawItemIndex}.UpgradeFingerprint`);
|
||||
} else {
|
||||
RawUpgrades.splice(rawItemIndex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
inventory.RegularCredits -= Cost;
|
||||
inventory.FusionPoints -= FusionPointCost;
|
||||
|
||||
const changedInventory = await inventory.save();
|
||||
const itemId = changedInventory.toJSON().Upgrades[itemIndex]?.ItemId?.$oid;
|
||||
|
||||
if (!itemId) {
|
||||
throw new Error("Item Id not found in upgradeMod");
|
||||
}
|
||||
|
||||
return itemId;
|
||||
} catch (error) {
|
||||
console.error("Error in upgradeMod:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export { createInventory, addPowerSuit };
|
||||
|
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 };
|
@ -1,4 +1,4 @@
|
||||
export interface IGenericUpdate {
|
||||
NodeIntrosCompleted: string | string[];
|
||||
// AffiliationMods: any[];
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { Document, Types } from "mongoose";
|
||||
import { IOid } from "../commonTypes";
|
||||
import { IAbilityOverride, IColor, FocusSchool, IPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
@ -33,7 +34,7 @@ export interface IInventoryResponse {
|
||||
DailyFocus: number;
|
||||
GiftsRemaining: number;
|
||||
HandlerPoints: number;
|
||||
MiscItems: IConsumable[];
|
||||
MiscItems: IMiscItem[];
|
||||
ChallengesFixVersion: number;
|
||||
ChallengeProgress: IChallengeProgress[];
|
||||
RawUpgrades: IRawUpgrade[];
|
||||
@ -319,7 +320,8 @@ export interface ICrewShipSalvageBinClass {
|
||||
export interface ICrewShipSalvagedWeaponSkin {
|
||||
ItemType: string;
|
||||
UpgradeFingerprint?: string;
|
||||
ItemId: IOid;
|
||||
ItemId?: IOid;
|
||||
_id?: Types.ObjectId;
|
||||
}
|
||||
|
||||
export interface ICrewShipWeapon {
|
||||
@ -375,11 +377,6 @@ export interface IFlavourItem {
|
||||
ItemType: string;
|
||||
}
|
||||
|
||||
export interface IRawUpgrade {
|
||||
ItemCount: number;
|
||||
ItemType: string;
|
||||
}
|
||||
|
||||
export interface IMiscItem {
|
||||
ItemCount: number;
|
||||
ItemType: string;
|
||||
@ -933,9 +930,9 @@ export interface IProgress {
|
||||
}
|
||||
|
||||
export interface IRawUpgrade {
|
||||
ItemType: string;
|
||||
ItemCount: number;
|
||||
LastAdded?: IOid;
|
||||
ItemType: string;
|
||||
}
|
||||
|
||||
export interface IScoop {
|
||||
|
@ -1,6 +1,9 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { IOid } from "./commonTypes";
|
||||
import { IDate } from "./inventoryTypes/inventoryTypes";
|
||||
|
||||
export const inventoryFields = ["RawUpgrades", "MiscItems", "Consumables", "Recipes"] as const;
|
||||
export type IInventoryFieldType = (typeof inventoryFields)[number];
|
||||
export interface IMissionInventoryUpdateGear {
|
||||
ItemType: string;
|
||||
ItemName: string;
|
||||
@ -43,6 +46,21 @@ export interface IMissionInventoryUpdateChallange {
|
||||
Completed: any[];
|
||||
}
|
||||
|
||||
export interface IMissionInventoryUpdateRewardInfo {
|
||||
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 IMissionInventoryUpdate {
|
||||
rewardsMultiplier?: number;
|
||||
ActiveBoosters?: any[];
|
||||
@ -50,8 +68,27 @@ export interface IMissionInventoryUpdate {
|
||||
Pistols?: IMissionInventoryUpdateGear[];
|
||||
Suits?: IMissionInventoryUpdateGear[];
|
||||
Melee?: IMissionInventoryUpdateGear[];
|
||||
RawUpgrades?: IMissionInventoryUpdateCard[];
|
||||
RawUpgrades?: IMissionInventoryUpdateItem[];
|
||||
MiscItems?: IMissionInventoryUpdateItem[];
|
||||
Consumables?: IMissionInventoryUpdateItem[];
|
||||
Recipes?: IMissionInventoryUpdateItem[];
|
||||
RegularCredits?: number;
|
||||
ChallengeProgress?: IMissionInventoryUpdateChallange[];
|
||||
RewardInfo?: IMissionInventoryUpdateRewardInfo;
|
||||
FusionPoints?: number;
|
||||
}
|
||||
|
||||
export interface IMissionRewardResponse {
|
||||
StoreItem?: string;
|
||||
TypeName: string;
|
||||
UpgradeLevel?: number;
|
||||
ItemCount: number;
|
||||
TweetText: string;
|
||||
ProductCategory: string;
|
||||
}
|
||||
|
||||
export interface IReward {
|
||||
name: string;
|
||||
chance: number;
|
||||
rotation?: string;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export interface ISession {
|
||||
sessionId: string;
|
||||
creatorId: string;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Items, { Item, Weapon } from "warframe-items";
|
||||
import Items, { Category, Item, Warframe, Weapon } from "warframe-items";
|
||||
|
||||
type MinWeapon = Omit<Weapon, "patchlogs">;
|
||||
type MinItem = Omit<Item, "patchlogs">;
|
||||
@ -16,3 +16,45 @@ export const items: MinItem[] = new Items({ category: ["All"] }).map(item => {
|
||||
delete next.patchlogs;
|
||||
return next;
|
||||
});
|
||||
|
||||
const getNamesObj = (category: Category) =>
|
||||
new Items({ category: [category] }).reduce((acc, item) => {
|
||||
acc[item.name!.replace("'S", "'s")] = item.uniqueName!;
|
||||
return acc;
|
||||
}, {} as ImportAssertions);
|
||||
|
||||
export const modNames = getNamesObj("Mods");
|
||||
export const resourceNames = getNamesObj("Resources");
|
||||
export const miscNames = getNamesObj("Misc");
|
||||
export const relicNames = getNamesObj("Relics");
|
||||
export const skinNames = getNamesObj("Skins");
|
||||
export const arcaneNames = getNamesObj("Arcanes");
|
||||
export const gearNames = getNamesObj("Gear");
|
||||
|
||||
export const craftNames: ImportAssertions = Object.fromEntries(
|
||||
(
|
||||
new Items({
|
||||
category: [
|
||||
"Warframes",
|
||||
"Gear",
|
||||
"Melee",
|
||||
"Primary",
|
||||
"Secondary",
|
||||
"Sentinels",
|
||||
"Misc",
|
||||
"Arch-Gun",
|
||||
"Arch-Melee"
|
||||
]
|
||||
}) as Warframe[]
|
||||
)
|
||||
.flatMap(item => item.components || [])
|
||||
.filter(item => item.drops && item.drops[0])
|
||||
.map(item => [item.drops![0].type, item.uniqueName])
|
||||
);
|
||||
craftNames["Forma Blueprint"] = "/Lotus/Types/Recipes/Components/FormaBlueprint";
|
||||
|
||||
export const blueprintNames: ImportAssertions = Object.fromEntries(
|
||||
Object.keys(craftNames)
|
||||
.filter(name => name.includes("Blueprint"))
|
||||
.map(name => [name, craftNames[name]])
|
||||
);
|
||||
|
1
static/json/missions-drop-table.json
Normal file
1
static/json/missions-drop-table.json
Normal file
File diff suppressed because one or more lines are too long
30
static/json/scripts/missions-drop-table-get-script.js
Normal file
30
static/json/scripts/missions-drop-table-get-script.js
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user