forked from OpenWF/SpaceNinjaServer
		
	feat: handle purchasing of archwing, archgun, & archmelee (#326)
This commit is contained in:
		
							parent
							
								
									f1237d562d
								
							
						
					
					
						commit
						1fe8351dca
					
				@ -197,7 +197,8 @@ ArchonCrystalUpgradeSchema.set("toJSON", {
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const EquipmentSchema = new Schema<IEquipmentDatabase>({
 | 
			
		||||
const EquipmentSchema = new Schema<IEquipmentDatabase>(
 | 
			
		||||
    {
 | 
			
		||||
        ItemType: String,
 | 
			
		||||
        Configs: [ItemConfigSchema],
 | 
			
		||||
        UpgradeVer: Number,
 | 
			
		||||
@ -214,12 +215,14 @@ const EquipmentSchema = new Schema<IEquipmentDatabase>({
 | 
			
		||||
        InfestationDate: Date,
 | 
			
		||||
        InfestationDays: Number,
 | 
			
		||||
        InfestationType: String,
 | 
			
		||||
    ModularParts: [String],
 | 
			
		||||
        ModularParts: { type: [String], default: undefined },
 | 
			
		||||
        UnlockLevel: Number,
 | 
			
		||||
        Expiry: Date,
 | 
			
		||||
        SkillTree: String,
 | 
			
		||||
        ArchonCrystalUpgrades: { type: [ArchonCrystalUpgradeSchema], default: undefined }
 | 
			
		||||
});
 | 
			
		||||
    },
 | 
			
		||||
    { id: false }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
EquipmentSchema.virtual("ItemId").get(function () {
 | 
			
		||||
    return { $oid: this._id.toString() } satisfies IOid;
 | 
			
		||||
@ -955,6 +958,10 @@ type InventoryDocumentProps = {
 | 
			
		||||
    Sentinels: Types.DocumentArray<IEquipmentDatabase>;
 | 
			
		||||
    Horses: Types.DocumentArray<IEquipmentDatabase>;
 | 
			
		||||
    PendingRecipes: Types.DocumentArray<IPendingRecipeDatabase>;
 | 
			
		||||
    SpaceSuits: Types.DocumentArray<IEquipmentDatabase>;
 | 
			
		||||
    SpaceGuns: Types.DocumentArray<IEquipmentDatabase>;
 | 
			
		||||
    SpaceMelee: Types.DocumentArray<IEquipmentDatabase>;
 | 
			
		||||
    SentinelWeapons: Types.DocumentArray<IEquipmentDatabase>;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/ban-types
 | 
			
		||||
 | 
			
		||||
@ -92,21 +92,8 @@ export const addItem = async (
 | 
			
		||||
    // Path-based duck typing
 | 
			
		||||
    switch (typeName.substr(1).split("/")[1]) {
 | 
			
		||||
        case "Powersuits":
 | 
			
		||||
            if (typeName.includes("EntratiMech")) {
 | 
			
		||||
                const mechSuit = await addMechSuit(typeName, accountId);
 | 
			
		||||
                await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
 | 
			
		||||
                logger.debug("mech suit", mechSuit);
 | 
			
		||||
                return {
 | 
			
		||||
                    InventoryChanges: {
 | 
			
		||||
                        MechBin: {
 | 
			
		||||
                            count: 1,
 | 
			
		||||
                            platinum: 0,
 | 
			
		||||
                            Slots: -1
 | 
			
		||||
                        },
 | 
			
		||||
                        MechSuits: [mechSuit]
 | 
			
		||||
                    }
 | 
			
		||||
                };
 | 
			
		||||
            }
 | 
			
		||||
            switch (typeName.substr(1).split("/")[2]) {
 | 
			
		||||
                default: {
 | 
			
		||||
                    const suit = await addPowerSuit(typeName, accountId);
 | 
			
		||||
                    await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
 | 
			
		||||
                    return {
 | 
			
		||||
@ -119,6 +106,37 @@ export const addItem = async (
 | 
			
		||||
                            Suits: [suit]
 | 
			
		||||
                        }
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
                case "Archwing": {
 | 
			
		||||
                    const spaceSuit = await addSpaceSuit(typeName, accountId);
 | 
			
		||||
                    await updateSlots(accountId, InventorySlot.SPACESUITS, 0, 1);
 | 
			
		||||
                    return {
 | 
			
		||||
                        InventoryChanges: {
 | 
			
		||||
                            SpaceSuitBin: {
 | 
			
		||||
                                count: 1,
 | 
			
		||||
                                platinum: 0,
 | 
			
		||||
                                Slots: -1
 | 
			
		||||
                            },
 | 
			
		||||
                            SpaceSuits: [spaceSuit]
 | 
			
		||||
                        }
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
                case "EntratiMech": {
 | 
			
		||||
                    const mechSuit = await addMechSuit(typeName, accountId);
 | 
			
		||||
                    await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
 | 
			
		||||
                    return {
 | 
			
		||||
                        InventoryChanges: {
 | 
			
		||||
                            MechBin: {
 | 
			
		||||
                                count: 1,
 | 
			
		||||
                                platinum: 0,
 | 
			
		||||
                                Slots: -1
 | 
			
		||||
                            },
 | 
			
		||||
                            MechSuits: [mechSuit]
 | 
			
		||||
                        }
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case "Weapons":
 | 
			
		||||
            const weaponType = getWeaponType(typeName);
 | 
			
		||||
            const weapon = await addWeapon(weaponType, typeName, accountId);
 | 
			
		||||
@ -277,6 +295,13 @@ export const addSpecialItem = async (itemName: string, accountId: string) => {
 | 
			
		||||
    return changedInventory.SpecialItems[specialItemIndex - 1].toJSON();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const addSpaceSuit = async (spacesuitName: string, accountId: string) => {
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
    const suitIndex = inventory.SpaceSuits.push({ ItemType: spacesuitName, Configs: [], UpgradeVer: 101, XP: 0 });
 | 
			
		||||
    const changedInventory = await inventory.save();
 | 
			
		||||
    return changedInventory.SpaceSuits[suitIndex - 1].toJSON();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const updateSlots = async (accountId: string, slotName: SlotNames, slotAmount: number, extraAmount: number) => {
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
 | 
			
		||||
@ -391,22 +416,12 @@ export const addWeapon = async (
 | 
			
		||||
): Promise<IEquipmentClient> => {
 | 
			
		||||
    const inventory = await getInventory(accountId);
 | 
			
		||||
 | 
			
		||||
    let weaponIndex;
 | 
			
		||||
    switch (weaponType) {
 | 
			
		||||
        case "LongGuns":
 | 
			
		||||
        case "Pistols":
 | 
			
		||||
        case "Melee":
 | 
			
		||||
        case "OperatorAmps":
 | 
			
		||||
            weaponIndex = inventory[weaponType].push({
 | 
			
		||||
    const weaponIndex = inventory[weaponType].push({
 | 
			
		||||
        ItemType: weaponName,
 | 
			
		||||
        Configs: [],
 | 
			
		||||
        XP: 0,
 | 
			
		||||
        ModularParts: modularParts
 | 
			
		||||
    });
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            throw new Error("unknown weapon type: " + weaponType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const changedInventory = await inventory.save();
 | 
			
		||||
    return changedInventory[weaponType][weaponIndex - 1].toJSON();
 | 
			
		||||
 | 
			
		||||
@ -358,6 +358,7 @@ export interface ICombat {
 | 
			
		||||
export enum InventorySlot {
 | 
			
		||||
    SUITS = "SuitBin",
 | 
			
		||||
    WEAPONS = "WeaponBin",
 | 
			
		||||
    SPACESUITS = "SpaceSuitBin",
 | 
			
		||||
    MECHSUITS = "MechBin",
 | 
			
		||||
    PVE_LOADOUTS = "PveBonusLoadoutBin",
 | 
			
		||||
    SENTINELS = "SentinelBin"
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user