forked from OpenWF/SpaceNinjaServer
		
	feat: trade in modular weapons for standing (#1172)
Closes #1055 Reviewed-on: OpenWF/SpaceNinjaServer#1172
This commit is contained in:
		
							parent
							
								
									292ac9d41b
								
							
						
					
					
						commit
						de4fe0311c
					
				
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -17,7 +17,7 @@
 | 
				
			|||||||
        "mongoose": "^8.11.0",
 | 
					        "mongoose": "^8.11.0",
 | 
				
			||||||
        "morgan": "^1.10.0",
 | 
					        "morgan": "^1.10.0",
 | 
				
			||||||
        "typescript": ">=4.7.4 <5.6.0",
 | 
					        "typescript": ">=4.7.4 <5.6.0",
 | 
				
			||||||
        "warframe-public-export-plus": "^0.5.43",
 | 
					        "warframe-public-export-plus": "^0.5.44",
 | 
				
			||||||
        "warframe-riven-info": "^0.1.2",
 | 
					        "warframe-riven-info": "^0.1.2",
 | 
				
			||||||
        "winston": "^3.17.0",
 | 
					        "winston": "^3.17.0",
 | 
				
			||||||
        "winston-daily-rotate-file": "^5.0.0"
 | 
					        "winston-daily-rotate-file": "^5.0.0"
 | 
				
			||||||
@ -4006,9 +4006,9 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/warframe-public-export-plus": {
 | 
					    "node_modules/warframe-public-export-plus": {
 | 
				
			||||||
      "version": "0.5.43",
 | 
					      "version": "0.5.44",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.43.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.5.44.tgz",
 | 
				
			||||||
      "integrity": "sha512-LeF7HmsjOPsJDtgr66x3iMEIAQgcxKNM54VG895FTemgHLLo34UGDyeS1yIfY67WxxbTUgW3MkHQLlCEJXD14w=="
 | 
					      "integrity": "sha512-0EH3CQBCuuELiLBL1brc/o6Qx8CK723TJF5o68VXc60ha93Juo6LQ+dV+QgzFvVQ5RZTjBLtKB4MP8qw3YHCUQ=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/warframe-riven-info": {
 | 
					    "node_modules/warframe-riven-info": {
 | 
				
			||||||
      "version": "0.1.2",
 | 
					      "version": "0.1.2",
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,7 @@
 | 
				
			|||||||
    "mongoose": "^8.11.0",
 | 
					    "mongoose": "^8.11.0",
 | 
				
			||||||
    "morgan": "^1.10.0",
 | 
					    "morgan": "^1.10.0",
 | 
				
			||||||
    "typescript": ">=4.7.4 <5.6.0",
 | 
					    "typescript": ">=4.7.4 <5.6.0",
 | 
				
			||||||
    "warframe-public-export-plus": "^0.5.43",
 | 
					    "warframe-public-export-plus": "^0.5.44",
 | 
				
			||||||
    "warframe-riven-info": "^0.1.2",
 | 
					    "warframe-riven-info": "^0.1.2",
 | 
				
			||||||
    "winston": "^3.17.0",
 | 
					    "winston": "^3.17.0",
 | 
				
			||||||
    "winston-daily-rotate-file": "^5.0.0"
 | 
					    "winston-daily-rotate-file": "^5.0.0"
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,19 @@
 | 
				
			|||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
 | 
					import {
 | 
				
			||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					    addMiscItems,
 | 
				
			||||||
 | 
					    freeUpSlot,
 | 
				
			||||||
 | 
					    getInventory,
 | 
				
			||||||
 | 
					    getStandingLimit,
 | 
				
			||||||
 | 
					    updateStandingLimit
 | 
				
			||||||
 | 
					} from "@/src/services/inventoryService";
 | 
				
			||||||
 | 
					import { IMiscItem, InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IOid } from "@/src/types/commonTypes";
 | 
					import { IOid } from "@/src/types/commonTypes";
 | 
				
			||||||
import { ExportSyndicates } from "warframe-public-export-plus";
 | 
					import { ExportSyndicates, ExportWeapons } from "warframe-public-export-plus";
 | 
				
			||||||
import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
 | 
					import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
 | 
				
			||||||
 | 
					import { logger } from "@/src/utils/logger";
 | 
				
			||||||
 | 
					import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
				
			||||||
 | 
					import { EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const syndicateStandingBonusController: RequestHandler = async (req, res) => {
 | 
					export const syndicateStandingBonusController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
@ -12,6 +21,7 @@ export const syndicateStandingBonusController: RequestHandler = async (req, res)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const syndicateMeta = ExportSyndicates[request.Operation.AffiliationTag];
 | 
					    const syndicateMeta = ExportSyndicates[request.Operation.AffiliationTag];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Process items
 | 
				
			||||||
    let gainedStanding = 0;
 | 
					    let gainedStanding = 0;
 | 
				
			||||||
    request.Operation.Items.forEach(item => {
 | 
					    request.Operation.Items.forEach(item => {
 | 
				
			||||||
        const medallion = (syndicateMeta.medallions ?? []).find(medallion => medallion.itemType == item.ItemType);
 | 
					        const medallion = (syndicateMeta.medallions ?? []).find(medallion => medallion.itemType == item.ItemType);
 | 
				
			||||||
@ -21,9 +31,35 @@ export const syndicateStandingBonusController: RequestHandler = async (req, res)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        item.ItemCount *= -1;
 | 
					        item.ItemCount *= -1;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
    addMiscItems(inventory, request.Operation.Items);
 | 
					    addMiscItems(inventory, request.Operation.Items);
 | 
				
			||||||
 | 
					    const inventoryChanges: IInventoryChanges = {};
 | 
				
			||||||
 | 
					    inventoryChanges.MiscItems = request.Operation.Items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Process modular weapon
 | 
				
			||||||
 | 
					    if (request.Operation.ModularWeaponId.$oid != "000000000000000000000000") {
 | 
				
			||||||
 | 
					        const category = req.query.Category as "LongGuns" | "Pistols" | "Melee" | "OperatorAmps";
 | 
				
			||||||
 | 
					        const weapon = inventory[category].id(request.Operation.ModularWeaponId.$oid)!;
 | 
				
			||||||
 | 
					        if (gainedStanding !== 0) {
 | 
				
			||||||
 | 
					            throw new Error(`modular weapon standing bonus should be mutually exclusive`);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        weapon.ModularParts!.forEach(part => {
 | 
				
			||||||
 | 
					            const partStandingBonus = ExportWeapons[part].donationStandingBonus;
 | 
				
			||||||
 | 
					            if (partStandingBonus === undefined) {
 | 
				
			||||||
 | 
					                throw new Error(`no standing bonus for ${part}`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            logger.debug(`modular weapon part ${part} gives ${partStandingBonus} standing`);
 | 
				
			||||||
 | 
					            gainedStanding += partStandingBonus;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        if (weapon.Features && (weapon.Features & EquipmentFeatures.GILDED) != 0) {
 | 
				
			||||||
 | 
					            gainedStanding *= 2;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        inventoryChanges.RemovedIdItems = [{ ItemId: request.Operation.ModularWeaponId }];
 | 
				
			||||||
 | 
					        inventory[category].pull({ _id: request.Operation.ModularWeaponId.$oid });
 | 
				
			||||||
 | 
					        const slotBin = category == "OperatorAmps" ? InventorySlot.AMPS : InventorySlot.WEAPONS;
 | 
				
			||||||
 | 
					        freeUpSlot(inventory, slotBin);
 | 
				
			||||||
 | 
					        inventoryChanges[slotBin] = { count: -1, platinum: 0, Slots: 1 };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag);
 | 
					    let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag);
 | 
				
			||||||
    if (!syndicate) {
 | 
					    if (!syndicate) {
 | 
				
			||||||
@ -50,9 +86,7 @@ export const syndicateStandingBonusController: RequestHandler = async (req, res)
 | 
				
			|||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.json({
 | 
					    res.json({
 | 
				
			||||||
        InventoryChanges: {
 | 
					        InventoryChanges: inventoryChanges,
 | 
				
			||||||
            MiscItems: request.Operation.Items
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        AffiliationMods: [
 | 
					        AffiliationMods: [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Tag: request.Operation.AffiliationTag,
 | 
					                Tag: request.Operation.AffiliationTag,
 | 
				
			||||||
@ -67,6 +101,6 @@ interface ISyndicateStandingBonusRequest {
 | 
				
			|||||||
        AffiliationTag: string;
 | 
					        AffiliationTag: string;
 | 
				
			||||||
        AlternateBonusReward: ""; // ???
 | 
					        AlternateBonusReward: ""; // ???
 | 
				
			||||||
        Items: IMiscItem[];
 | 
					        Items: IMiscItem[];
 | 
				
			||||||
 | 
					        ModularWeaponId: IOid;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    ModularWeaponId: IOid; // Seems to just be "000000000000000000000000", also note there's a "Category" query field
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user