forked from OpenWF/SpaceNinjaServer
		
	feat: identify & repair railjack armaments (#1686)
Closes #1676 Reviewed-on: OpenWF/SpaceNinjaServer#1686 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									9940024a01
								
							
						
					
					
						commit
						66e34b7be9
					
				@ -1,17 +1,28 @@
 | 
			
		||||
import { addCrewShipSalvagedWeaponSkin, addCrewShipRawSalvage, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import {
 | 
			
		||||
    addCrewShipSalvagedWeaponSkin,
 | 
			
		||||
    addCrewShipRawSalvage,
 | 
			
		||||
    getInventory,
 | 
			
		||||
    addEquipment
 | 
			
		||||
} from "@/src/services/inventoryService";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { ICrewShipComponentFingerprint } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { ExportCustoms } from "warframe-public-export-plus";
 | 
			
		||||
import { ICrewShipComponentFingerprint, IInnateDamageFingerprint } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { ExportCustoms, ExportRailjackWeapons, ExportUpgrades } from "warframe-public-export-plus";
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
			
		||||
import { getRandomInt } from "@/src/services/rngService";
 | 
			
		||||
import { IFingerprintStat } from "@/src/helpers/rivenHelper";
 | 
			
		||||
 | 
			
		||||
export const crewShipIdentifySalvageController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
    const inventory = await getInventory(accountId, "CrewShipSalvagedWeaponSkins CrewShipRawSalvage");
 | 
			
		||||
    const inventory = await getInventory(
 | 
			
		||||
        accountId,
 | 
			
		||||
        "CrewShipSalvagedWeaponSkins CrewShipSalvagedWeapons CrewShipRawSalvage"
 | 
			
		||||
    );
 | 
			
		||||
    const payload = getJSONfromString<ICrewShipIdentifySalvageRequest>(String(req.body));
 | 
			
		||||
 | 
			
		||||
    const inventoryChanges: IInventoryChanges = {};
 | 
			
		||||
    if (payload.ItemType in ExportCustoms) {
 | 
			
		||||
        const meta = ExportCustoms[payload.ItemType];
 | 
			
		||||
        let upgradeFingerprint: ICrewShipComponentFingerprint = { compat: payload.ItemType, buffs: [] };
 | 
			
		||||
        if (meta.subroutines) {
 | 
			
		||||
@ -23,11 +34,31 @@ export const crewShipIdentifySalvageController: RequestHandler = async (req, res
 | 
			
		||||
        for (const upgrade of meta.randomisedUpgrades!) {
 | 
			
		||||
            upgradeFingerprint.buffs.push({ Tag: upgrade.tag, Value: Math.trunc(Math.random() * 0x40000000) });
 | 
			
		||||
        }
 | 
			
		||||
    const inventoryChanges: IInventoryChanges = addCrewShipSalvagedWeaponSkin(
 | 
			
		||||
        addCrewShipSalvagedWeaponSkin(
 | 
			
		||||
            inventory,
 | 
			
		||||
            payload.ItemType,
 | 
			
		||||
        JSON.stringify(upgradeFingerprint)
 | 
			
		||||
            JSON.stringify(upgradeFingerprint),
 | 
			
		||||
            inventoryChanges
 | 
			
		||||
        );
 | 
			
		||||
    } else {
 | 
			
		||||
        const meta = ExportRailjackWeapons[payload.ItemType];
 | 
			
		||||
        const upgradeType = meta.defaultUpgrades![0].ItemType;
 | 
			
		||||
        const upgradeMeta = ExportUpgrades[upgradeType];
 | 
			
		||||
        const buffs: IFingerprintStat[] = [];
 | 
			
		||||
        for (const buff of upgradeMeta.upgradeEntries!) {
 | 
			
		||||
            buffs.push({
 | 
			
		||||
                Tag: buff.tag,
 | 
			
		||||
                Value: Math.trunc(Math.random() * 0x40000000)
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        addEquipment(inventory, "CrewShipSalvagedWeapons", payload.ItemType, undefined, inventoryChanges, {
 | 
			
		||||
            UpgradeType: upgradeType,
 | 
			
		||||
            UpgradeFingerprint: JSON.stringify({
 | 
			
		||||
                compat: payload.ItemType,
 | 
			
		||||
                buffs
 | 
			
		||||
            } satisfies IInnateDamageFingerprint)
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inventoryChanges.CrewShipRawSalvage = [
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,7 @@ import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import {
 | 
			
		||||
    addCrewShipWeaponSkin,
 | 
			
		||||
    addEquipment,
 | 
			
		||||
    addItem,
 | 
			
		||||
    addMiscItems,
 | 
			
		||||
    addRecipes,
 | 
			
		||||
@ -382,18 +383,31 @@ interface IGuildTechContributeRequest {
 | 
			
		||||
const claimSalvagedComponent = (inventory: TInventoryDatabaseDocument, itemId: string): IInventoryChanges => {
 | 
			
		||||
    // delete personal tech project
 | 
			
		||||
    const personalTechProjectIndex = inventory.PersonalTechProjects.findIndex(x => x.CategoryItemId?.equals(itemId));
 | 
			
		||||
    if (personalTechProjectIndex != -1) {
 | 
			
		||||
    const personalTechProject = inventory.PersonalTechProjects[personalTechProjectIndex];
 | 
			
		||||
    inventory.PersonalTechProjects.splice(personalTechProjectIndex, 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const category = personalTechProject.ProductCategory! as "CrewShipWeapons" | "CrewShipWeaponSkins";
 | 
			
		||||
    const salvageCategory = category == "CrewShipWeapons" ? "CrewShipSalvagedWeapons" : "CrewShipSalvagedWeaponSkins";
 | 
			
		||||
 | 
			
		||||
    // find salved part & delete it
 | 
			
		||||
    const crewShipSalvagedWeaponSkinsIndex = inventory.CrewShipSalvagedWeaponSkins.findIndex(x => x._id.equals(itemId));
 | 
			
		||||
    const crewShipWeaponSkin = inventory.CrewShipSalvagedWeaponSkins[crewShipSalvagedWeaponSkinsIndex];
 | 
			
		||||
    inventory.CrewShipSalvagedWeaponSkins.splice(crewShipSalvagedWeaponSkinsIndex, 1);
 | 
			
		||||
    const salvageIndex = inventory[salvageCategory].findIndex(x => x._id.equals(itemId));
 | 
			
		||||
    const salvageItem = inventory[category][salvageIndex];
 | 
			
		||||
    inventory[salvageCategory].splice(salvageIndex, 1);
 | 
			
		||||
 | 
			
		||||
    // add final item
 | 
			
		||||
    const inventoryChanges = {
 | 
			
		||||
        ...addCrewShipWeaponSkin(inventory, crewShipWeaponSkin.ItemType, crewShipWeaponSkin.UpgradeFingerprint),
 | 
			
		||||
        ...(category == "CrewShipWeaponSkins"
 | 
			
		||||
            ? addCrewShipWeaponSkin(inventory, salvageItem.ItemType, salvageItem.UpgradeFingerprint)
 | 
			
		||||
            : addEquipment(
 | 
			
		||||
                  inventory,
 | 
			
		||||
                  category,
 | 
			
		||||
                  salvageItem.ItemType,
 | 
			
		||||
                  undefined,
 | 
			
		||||
                  {},
 | 
			
		||||
                  {
 | 
			
		||||
                      UpgradeFingerprint: salvageItem.UpgradeFingerprint
 | 
			
		||||
                  }
 | 
			
		||||
              )),
 | 
			
		||||
        ...occupySlot(inventory, InventorySlot.RJ_COMPONENT_AND_ARMAMENTS, false)
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1083,7 +1083,7 @@ export const addEquipment = (
 | 
			
		||||
            Configs: [],
 | 
			
		||||
            XP: 0,
 | 
			
		||||
            ModularParts: modularParts,
 | 
			
		||||
            IsNew: category != "CrewShipWeapons" ? true : undefined
 | 
			
		||||
            IsNew: category != "CrewShipWeapons" && category != "CrewShipSalvagedWeapons" ? true : undefined
 | 
			
		||||
        },
 | 
			
		||||
        defaultOverwrites
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user