chore: add suits to freestanding inventory
This commit is contained in:
		
							parent
							
								
									e6432b5052
								
							
						
					
					
						commit
						603708de2f
					
				@ -1,7 +1,7 @@
 | 
				
			|||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { ItemType, toAddItemRequest } from "@/src/helpers/customHelpers/addItemHelpers";
 | 
					import { ItemType, toAddItemRequest } from "@/src/helpers/customHelpers/addItemHelpers";
 | 
				
			||||||
import { getWeaponType } from "@/src/services/itemDataService";
 | 
					import { getWeaponType } from "@/src/services/itemDataService";
 | 
				
			||||||
import { addPowerSuit, addEquipment } from "@/src/services/inventoryService";
 | 
					import { addPowerSuit, addEquipment, getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const addItemController: RequestHandler = async (req, res) => {
 | 
					const addItemController: RequestHandler = async (req, res) => {
 | 
				
			||||||
@ -10,8 +10,10 @@ const addItemController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    switch (request.type) {
 | 
					    switch (request.type) {
 | 
				
			||||||
        case ItemType.Powersuit: {
 | 
					        case ItemType.Powersuit: {
 | 
				
			||||||
            const powersuit = await addPowerSuit(request.InternalName, accountId);
 | 
					            const inventory = await getInventory(accountId);
 | 
				
			||||||
            res.json(powersuit);
 | 
					            const inventoryChanges = addPowerSuit(inventory, request.InternalName);
 | 
				
			||||||
 | 
					            await inventory.save();
 | 
				
			||||||
 | 
					            res.json(inventoryChanges);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        case ItemType.Weapon: {
 | 
					        case ItemType.Weapon: {
 | 
				
			||||||
 | 
				
			|||||||
@ -216,7 +216,9 @@ export const addItem = async (
 | 
				
			|||||||
        case "Powersuits":
 | 
					        case "Powersuits":
 | 
				
			||||||
            switch (typeName.substr(1).split("/")[2]) {
 | 
					            switch (typeName.substr(1).split("/")[2]) {
 | 
				
			||||||
                default: {
 | 
					                default: {
 | 
				
			||||||
                    const inventoryChanges = await addPowerSuit(typeName, accountId);
 | 
					                    const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					                    const inventoryChanges = addPowerSuit(inventory, typeName);
 | 
				
			||||||
 | 
					                    await inventory.save();
 | 
				
			||||||
                    await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
 | 
					                    await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
 | 
				
			||||||
                    return {
 | 
					                    return {
 | 
				
			||||||
                        InventoryChanges: {
 | 
					                        InventoryChanges: {
 | 
				
			||||||
@ -244,7 +246,9 @@ export const addItem = async (
 | 
				
			|||||||
                    };
 | 
					                    };
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                case "EntratiMech": {
 | 
					                case "EntratiMech": {
 | 
				
			||||||
                    const inventoryChanges = await addMechSuit(typeName, accountId);
 | 
					                    const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					                    const inventoryChanges = addMechSuit(inventory, typeName);
 | 
				
			||||||
 | 
					                    await inventory.save();
 | 
				
			||||||
                    await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
 | 
					                    await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
 | 
				
			||||||
                    return {
 | 
					                    return {
 | 
				
			||||||
                        InventoryChanges: {
 | 
					                        InventoryChanges: {
 | 
				
			||||||
@ -403,55 +407,60 @@ export const addSentinelWeapon = async (typeName: string, accountId: string): Pr
 | 
				
			|||||||
    return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON<IEquipmentClient>();
 | 
					    return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON<IEquipmentClient>();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addPowerSuit = async (powersuitName: string, accountId: string): Promise<IInventoryChanges> => {
 | 
					export const addPowerSuit = (
 | 
				
			||||||
    const inventoryChanges: IInventoryChanges = {};
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
 | 
					    powersuitName: string,
 | 
				
			||||||
 | 
					    inventoryChanges: IInventoryChanges = {}
 | 
				
			||||||
 | 
					): IInventoryChanges => {
 | 
				
			||||||
    const specialItems = getExalted(powersuitName);
 | 
					    const specialItems = getExalted(powersuitName);
 | 
				
			||||||
    if (specialItems) {
 | 
					    if (specialItems) {
 | 
				
			||||||
        for await (const specialItem of specialItems) {
 | 
					        for (const specialItem of specialItems) {
 | 
				
			||||||
            await addSpecialItem(specialItem, accountId, inventoryChanges);
 | 
					            addSpecialItem(inventory, specialItem, inventoryChanges);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const suitIndex = inventory.Suits.push({ ItemType: powersuitName, Configs: [], UpgradeVer: 101, XP: 0 }) - 1;
 | 
				
			||||||
    const suitIndex = inventory.Suits.push({ ItemType: powersuitName, Configs: [], UpgradeVer: 101, XP: 0 });
 | 
					    inventoryChanges.Suits ??= [];
 | 
				
			||||||
    const changedInventory = await inventory.save();
 | 
					    (inventoryChanges.Suits as IEquipmentClient[]).push(inventory.Suits[suitIndex].toJSON<IEquipmentClient>());
 | 
				
			||||||
    inventoryChanges.Suits = [changedInventory.Suits[suitIndex - 1].toJSON()];
 | 
					 | 
				
			||||||
    return inventoryChanges;
 | 
					    return inventoryChanges;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addMechSuit = async (mechsuitName: string, accountId: string): Promise<IInventoryChanges> => {
 | 
					export const addMechSuit = (
 | 
				
			||||||
    const inventoryChanges: IInventoryChanges = {};
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
 | 
					    mechsuitName: string,
 | 
				
			||||||
 | 
					    inventoryChanges: IInventoryChanges = {}
 | 
				
			||||||
 | 
					): IInventoryChanges => {
 | 
				
			||||||
    const specialItems = getExalted(mechsuitName);
 | 
					    const specialItems = getExalted(mechsuitName);
 | 
				
			||||||
    if (specialItems) {
 | 
					    if (specialItems) {
 | 
				
			||||||
        for await (const specialItem of specialItems) {
 | 
					        for (const specialItem of specialItems) {
 | 
				
			||||||
            await addSpecialItem(specialItem, accountId, inventoryChanges);
 | 
					            addSpecialItem(inventory, specialItem, inventoryChanges);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					    const suitIndex = inventory.MechSuits.push({ ItemType: mechsuitName, Configs: [], UpgradeVer: 101, XP: 0 }) - 1;
 | 
				
			||||||
    const suitIndex = inventory.MechSuits.push({ ItemType: mechsuitName, Configs: [], UpgradeVer: 101, XP: 0 });
 | 
					    inventoryChanges.MechSuits ??= [];
 | 
				
			||||||
    const changedInventory = await inventory.save();
 | 
					    (inventoryChanges.MechSuits as IEquipmentClient[]).push(inventory.MechSuits[suitIndex].toJSON<IEquipmentClient>());
 | 
				
			||||||
    inventoryChanges.MechSuits = [changedInventory.MechSuits[suitIndex - 1].toJSON()];
 | 
					 | 
				
			||||||
    return inventoryChanges;
 | 
					    return inventoryChanges;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addSpecialItem = async (
 | 
					export const addSpecialItem = (
 | 
				
			||||||
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
    itemName: string,
 | 
					    itemName: string,
 | 
				
			||||||
    accountId: string,
 | 
					 | 
				
			||||||
    inventoryChanges: IInventoryChanges
 | 
					    inventoryChanges: IInventoryChanges
 | 
				
			||||||
): Promise<void> => {
 | 
					): void => {
 | 
				
			||||||
    const inventory = await getInventory(accountId);
 | 
					 | 
				
			||||||
    if (inventory.SpecialItems.find(x => x.ItemType == itemName)) {
 | 
					    if (inventory.SpecialItems.find(x => x.ItemType == itemName)) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    const specialItemIndex = inventory.SpecialItems.push({
 | 
					    const specialItemIndex =
 | 
				
			||||||
 | 
					        inventory.SpecialItems.push({
 | 
				
			||||||
            ItemType: itemName,
 | 
					            ItemType: itemName,
 | 
				
			||||||
            Configs: [],
 | 
					            Configs: [],
 | 
				
			||||||
            Features: 1,
 | 
					            Features: 1,
 | 
				
			||||||
            UpgradeVer: 101,
 | 
					            UpgradeVer: 101,
 | 
				
			||||||
            XP: 0
 | 
					            XP: 0
 | 
				
			||||||
    });
 | 
					        }) - 1;
 | 
				
			||||||
    const changedInventory = await inventory.save();
 | 
					 | 
				
			||||||
    inventoryChanges.SpecialItems ??= [];
 | 
					    inventoryChanges.SpecialItems ??= [];
 | 
				
			||||||
    (inventoryChanges.SpecialItems as object[]).push(changedInventory.SpecialItems[specialItemIndex - 1].toJSON());
 | 
					    (inventoryChanges.SpecialItems as IEquipmentClient[]).push(
 | 
				
			||||||
 | 
					        inventory.SpecialItems[specialItemIndex].toJSON<IEquipmentClient>()
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addSpaceSuit = async (spacesuitName: string, accountId: string): Promise<IEquipmentClient> => {
 | 
					export const addSpaceSuit = async (spacesuitName: string, accountId: string): Promise<IEquipmentClient> => {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user