feat: purchase modular weapon from daily special #1217
@ -3,9 +3,22 @@ import { ExportWeapons } from "warframe-public-export-plus";
|
||||
import { IMongoDate } from "@/src/types/commonTypes";
|
||||
import { toMongoDate } from "@/src/helpers/inventoryHelpers";
|
||||
import { CRng } from "@/src/services/rngService";
|
||||
import { ArtifactPolarity, EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||
import {
|
||||
addEquipment,
|
||||
applyDefaultUpgrades,
|
||||
getInventory,
|
||||
occupySlot,
|
||||
productCategoryToInventoryBin,
|
||||
updateCurrency
|
||||
} from "@/src/services/inventoryService";
|
||||
import { getDefaultUpgrades } from "@/src/services/itemDataService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { modularWeaponTypes } from "@/src/helpers/modularWeaponHelper";
|
||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||
|
||||
// op=SyncAll
|
||||
export const modularWeaponSaleController: RequestHandler = (_req, res) => {
|
||||
export const modularWeaponSaleController: RequestHandler = async (req, res) => {
|
||||
const partTypeToParts: Record<string, string[]> = {};
|
||||
for (const [uniqueName, data] of Object.entries(ExportWeapons)) {
|
||||
if (data.partType) {
|
||||
@ -15,9 +28,47 @@ export const modularWeaponSaleController: RequestHandler = (_req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
SaleInfos: getSaleInfos(partTypeToParts, Math.trunc(Date.now() / 86400000))
|
||||
});
|
||||
if (req.query.op == "SyncAll") {
|
||||
res.json({
|
||||
SaleInfos: getSaleInfos(partTypeToParts, Math.trunc(Date.now() / 86400000))
|
||||
});
|
||||
} else if (req.query.op == "Purchase") {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId);
|
||||
const payload = getJSONfromString<IModularWeaponPurchaseRequest>(String(req.body));
|
||||
const weaponInfo = getSaleInfos(partTypeToParts, payload.Revision).find(x => x.Name == payload.SaleName)!
|
||||
.Weapons[payload.ItemIndex];
|
||||
const category = modularWeaponTypes[weaponInfo.ItemType];
|
||||
const configs = applyDefaultUpgrades(inventory, getDefaultUpgrades(weaponInfo.ModularParts));
|
||||
const inventoryChanges: IInventoryChanges = {
|
||||
...addEquipment(
|
||||
inventory,
|
||||
category,
|
||||
weaponInfo.ItemType,
|
||||
weaponInfo.ModularParts,
|
||||
{},
|
||||
{
|
||||
Features: EquipmentFeatures.DOUBLE_CAPACITY | EquipmentFeatures.GILDED,
|
||||
ItemName: payload.ItemName,
|
||||
Configs: configs,
|
||||
Polarity: [
|
||||
{
|
||||
Slot: payload.PolarizeSlot,
|
||||
Value: payload.PolarizeValue
|
||||
}
|
||||
]
|
||||
}
|
||||
),
|
||||
...occupySlot(inventory, productCategoryToInventoryBin(category)!, true),
|
||||
...updateCurrency(inventory, weaponInfo.PremiumPrice, true)
|
||||
};
|
||||
await inventory.save();
|
||||
res.json({
|
||||
InventoryChanges: inventoryChanges
|
||||
});
|
||||
} else {
|
||||
throw new Error(`unknown modularWeaponSale op: ${String(req.query.op)}`);
|
||||
}
|
||||
};
|
||||
|
||||
const getSaleInfos = (partTypeToParts: Record<string, string[]>, day: number): IModularWeaponSaleInfo[] => {
|
||||
@ -124,3 +175,12 @@ interface IModularWeaponSaleItem {
|
||||
PremiumPrice: number;
|
||||
ModularParts: string[];
|
||||
}
|
||||
|
||||
interface IModularWeaponPurchaseRequest {
|
||||
SaleName: string;
|
||||
ItemIndex: number;
|
||||
Revision: number;
|
||||
ItemName: string;
|
||||
PolarizeSlot: number;
|
||||
PolarizeValue: ArtifactPolarity;
|
||||
}
|
||||
|
@ -201,6 +201,7 @@ apiRouter.post("/joinSession.php", joinSessionController);
|
||||
apiRouter.post("/login.php", loginController);
|
||||
apiRouter.post("/missionInventoryUpdate.php", missionInventoryUpdateController);
|
||||
apiRouter.post("/modularWeaponCrafting.php", modularWeaponCraftingController);
|
||||
apiRouter.post("/modularWeaponSale.php", modularWeaponSaleController);
|
||||
apiRouter.post("/nameWeapon.php", nameWeaponController);
|
||||
apiRouter.post("/placeDecoInComponent.php", placeDecoInComponentController);
|
||||
apiRouter.post("/playerSkills.php", playerSkillsController);
|
||||
|
Loading…
x
Reference in New Issue
Block a user