handle all weapon types in addWeapon

This commit is contained in:
Sainan 2024-06-19 02:10:11 +02:00
parent 4ba718f27a
commit 9bf636418a
2 changed files with 7 additions and 18 deletions

View File

@ -961,6 +961,7 @@ type InventoryDocumentProps = {
SpaceSuits: Types.DocumentArray<IEquipmentDatabase>; SpaceSuits: Types.DocumentArray<IEquipmentDatabase>;
SpaceGuns: Types.DocumentArray<IEquipmentDatabase>; SpaceGuns: Types.DocumentArray<IEquipmentDatabase>;
SpaceMelee: Types.DocumentArray<IEquipmentDatabase>; SpaceMelee: Types.DocumentArray<IEquipmentDatabase>;
SentinelWeapons: Types.DocumentArray<IEquipmentDatabase>;
}; };
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types

View File

@ -416,24 +416,12 @@ export const addWeapon = async (
): Promise<IEquipmentClient> => { ): Promise<IEquipmentClient> => {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
let weaponIndex; const weaponIndex = inventory[weaponType].push({
switch (weaponType) { ItemType: weaponName,
case "LongGuns": Configs: [],
case "Pistols": XP: 0,
case "Melee": ModularParts: modularParts
case "OperatorAmps": });
case "SpaceGuns":
case "SpaceMelee":
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(); const changedInventory = await inventory.save();
return changedInventory[weaponType][weaponIndex - 1].toJSON(); return changedInventory[weaponType][weaponIndex - 1].toJSON();