feat: handle defaultUpgrades for moas and hounds (#1012)
Closes #997 Reviewed-on: OpenWF/SpaceNinjaServer#1012 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>
This commit is contained in:
		
							parent
							
								
									3d82fee99e
								
							
						
					
					
						commit
						e6ec144f1f
					
				@ -2,7 +2,14 @@ import { RequestHandler } from "express";
 | 
				
			|||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { getInventory, updateCurrency, addEquipment, addMiscItems } from "@/src/services/inventoryService";
 | 
					import {
 | 
				
			||||||
 | 
					    getInventory,
 | 
				
			||||||
 | 
					    updateCurrency,
 | 
				
			||||||
 | 
					    addEquipment,
 | 
				
			||||||
 | 
					    addMiscItems,
 | 
				
			||||||
 | 
					    applyDefaultUpgrades
 | 
				
			||||||
 | 
					} from "@/src/services/inventoryService";
 | 
				
			||||||
 | 
					import { ExportWeapons } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const modularWeaponTypes: Record<string, TEquipmentKey> = {
 | 
					const modularWeaponTypes: Record<string, TEquipmentKey> = {
 | 
				
			||||||
    "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns",
 | 
					    "/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns",
 | 
				
			||||||
@ -36,8 +43,11 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
 | 
				
			|||||||
    const category = modularWeaponTypes[data.WeaponType];
 | 
					    const category = modularWeaponTypes[data.WeaponType];
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
 | 
				
			||||||
 | 
					    const configs = applyDefaultUpgrades(inventory, ExportWeapons[data.Parts[0]]?.defaultUpgrades);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Give weapon
 | 
					    // Give weapon
 | 
				
			||||||
    const weapon = addEquipment(inventory, category, data.WeaponType, data.Parts);
 | 
					    const inventoryChanges = addEquipment(inventory, category, data.WeaponType, data.Parts, {}, { Configs: configs });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Remove credits & parts
 | 
					    // Remove credits & parts
 | 
				
			||||||
    const miscItemChanges = [];
 | 
					    const miscItemChanges = [];
 | 
				
			||||||
@ -58,8 +68,8 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
 | 
				
			|||||||
    // Tell client what we did
 | 
					    // Tell client what we did
 | 
				
			||||||
    res.json({
 | 
					    res.json({
 | 
				
			||||||
        InventoryChanges: {
 | 
					        InventoryChanges: {
 | 
				
			||||||
 | 
					            ...inventoryChanges,
 | 
				
			||||||
            ...currencyChanges,
 | 
					            ...currencyChanges,
 | 
				
			||||||
            [category]: [weapon],
 | 
					 | 
				
			||||||
            MiscItems: miscItemChanges
 | 
					            MiscItems: miscItemChanges
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
@ -52,6 +52,7 @@ import {
 | 
				
			|||||||
    ExportSyndicates,
 | 
					    ExportSyndicates,
 | 
				
			||||||
    ExportUpgrades,
 | 
					    ExportUpgrades,
 | 
				
			||||||
    ExportWeapons,
 | 
					    ExportWeapons,
 | 
				
			||||||
 | 
					    IDefaultUpgrade,
 | 
				
			||||||
    TStandingLimitBin
 | 
					    TStandingLimitBin
 | 
				
			||||||
} from "warframe-public-export-plus";
 | 
					} from "warframe-public-export-plus";
 | 
				
			||||||
import { createShip } from "./shipService";
 | 
					import { createShip } from "./shipService";
 | 
				
			||||||
@ -532,6 +533,28 @@ export const addItems = async (
 | 
				
			|||||||
    return inventoryChanges;
 | 
					    return inventoryChanges;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const applyDefaultUpgrades = (
 | 
				
			||||||
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
 | 
					    defaultUpgrades: IDefaultUpgrade[] | undefined
 | 
				
			||||||
 | 
					): IItemConfig[] => {
 | 
				
			||||||
 | 
					    const modsToGive: IRawUpgrade[] = [];
 | 
				
			||||||
 | 
					    const configs: IItemConfig[] = [];
 | 
				
			||||||
 | 
					    if (defaultUpgrades) {
 | 
				
			||||||
 | 
					        const upgrades = [];
 | 
				
			||||||
 | 
					        for (const defaultUpgrade of defaultUpgrades) {
 | 
				
			||||||
 | 
					            modsToGive.push({ ItemType: defaultUpgrade.ItemType, ItemCount: 1 });
 | 
				
			||||||
 | 
					            if (defaultUpgrade.Slot != -1) {
 | 
				
			||||||
 | 
					                upgrades[defaultUpgrade.Slot] = defaultUpgrade.ItemType;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (upgrades.length != 0) {
 | 
				
			||||||
 | 
					            configs.push({ Upgrades: upgrades });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    addMods(inventory, modsToGive);
 | 
				
			||||||
 | 
					    return configs;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//TODO: maybe genericMethod for all the add methods, they share a lot of logic
 | 
					//TODO: maybe genericMethod for all the add methods, they share a lot of logic
 | 
				
			||||||
export const addSentinel = (
 | 
					export const addSentinel = (
 | 
				
			||||||
    inventory: TInventoryDatabaseDocument,
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
@ -543,23 +566,9 @@ export const addSentinel = (
 | 
				
			|||||||
        addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
 | 
					        addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const modsToGive: IRawUpgrade[] = [];
 | 
					 | 
				
			||||||
    const configs: IItemConfig[] = [];
 | 
					 | 
				
			||||||
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
 | 
					    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
 | 
				
			||||||
    if (ExportSentinels[sentinelName]?.defaultUpgrades) {
 | 
					    const configs: IItemConfig[] = applyDefaultUpgrades(inventory, ExportSentinels[sentinelName]?.defaultUpgrades);
 | 
				
			||||||
        const upgrades = [];
 | 
					 | 
				
			||||||
        for (const defaultUpgrade of ExportSentinels[sentinelName].defaultUpgrades) {
 | 
					 | 
				
			||||||
            modsToGive.push({ ItemType: defaultUpgrade.ItemType, ItemCount: 1 });
 | 
					 | 
				
			||||||
            if (defaultUpgrade.Slot != -1) {
 | 
					 | 
				
			||||||
                upgrades[defaultUpgrade.Slot] = defaultUpgrade.ItemType;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if (upgrades.length != 0) {
 | 
					 | 
				
			||||||
            configs.push({ Upgrades: upgrades });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    addMods(inventory, modsToGive);
 | 
					 | 
				
			||||||
    const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1;
 | 
					    const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1;
 | 
				
			||||||
    inventoryChanges.Sentinels ??= [];
 | 
					    inventoryChanges.Sentinels ??= [];
 | 
				
			||||||
    inventoryChanges.Sentinels.push(inventory.Sentinels[sentinelIndex].toJSON<IEquipmentClient>());
 | 
					    inventoryChanges.Sentinels.push(inventory.Sentinels[sentinelIndex].toJSON<IEquipmentClient>());
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user