fix(fight): equipment exp gains were causing errors if nothing was equipped
authorxangelo <me@xangelo.ca>
Thu, 5 Dec 2024 15:02:08 +0000 (10:02 -0500)
committerxangelo <me@xangelo.ca>
Thu, 5 Dec 2024 15:02:08 +0000 (10:02 -0500)
src/server/fight.ts

index e27a87d4deece23de44a646c48c74b47f8274fb1..af8c644cecc14607e5087cd3168eb96a0cbbb227 100644 (file)
@@ -173,16 +173,18 @@ export async function fightRound(
     }
   });
 
-  const equipmentExpGains = (
-    await increaseExp(player.id, increaseExpToEquipment)
-  ).filter((obj) => {
-    return levelFromExp(obj.previous_exp) < levelFromExp(obj.new_exp);
-  });
-  // check if any of the equipment levelled up
-  if (equipmentExpGains.length) {
-    // increment random stats
-    await increaseEquipmentLevel(player.id, equipmentExpGains);
-  }
+  if(Object.keys(increaseExpToEquipment).length) {
+    const equipmentExpGains = (
+      await increaseExp(player.id, increaseExpToEquipment)
+    ).filter((obj) => {
+      return levelFromExp(obj.previous_exp) < levelFromExp(obj.new_exp);
+    });
+    // check if any of the equipment levelled up
+    if (equipmentExpGains.length) {
+      // increment random stats
+      await increaseEquipmentLevel(player.id, equipmentExpGains);
+    }
+}
 
   // @TODO implement flee based on dex + vigor
   if (data.action === "flee") {