From bb5d257ae89070e42d64a363dae09c4adc3eb21c Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 21 Apr 2024 11:14:10 -0500 Subject: [PATCH] early exit for out of stam when attacking --- src/engine/gameManager/CombatManager.java | 101 ++++++++-------------- 1 file changed, 35 insertions(+), 66 deletions(-) diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index 71c7fae3..138c7135 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -186,8 +186,15 @@ public enum CombatManager { } } + //check if Out of Stamina + if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) { + if (attacker.getStamina() < (weapon.template.item_wt / 3f)) { + //set auto attack job + setAutoAttackJob(attacker,slot,delay); + return; + } + } // take stamina away from attacker - if (weapon != null) { float stam = weapon.template.item_wt / 3f; stam = (stam < 1) ? 1 : stam; @@ -246,19 +253,8 @@ public enum CombatManager { else DispatchMessage.sendToAllInRange(attacker, msg); - //calculate next allowed attack and update the timestamp - attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); - - //handle auto attack job creation - ConcurrentHashMap timers = attacker.getTimers(); - - if (timers != null) { - AttackJob aj = new AttackJob(attacker, slot.ordinal(), true); - JobContainer job; - job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue - timers.put("Attack" + slot, job); - } else - Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID()); + //set auto attack job + setAutoAttackJob(attacker,slot,delay); return; } @@ -294,19 +290,8 @@ public enum CombatManager { else DispatchMessage.sendToAllInRange(attacker, msg); - //calculate next allowed attack and update the timestamp - attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); - - //handle auto attack job creation - ConcurrentHashMap timers = attacker.getTimers(); - - if (timers != null) { - AttackJob aj = new AttackJob(attacker, slot.ordinal(), true); - JobContainer job; - job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue - timers.put("Attack" + slot, job); - } else - Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID()); + //set auto attack job + setAutoAttackJob(attacker,slot,delay); return; } } @@ -314,19 +299,8 @@ public enum CombatManager { //calculate the base damage int damage = ThreadLocalRandom.current().nextInt(min, max + 1); if (damage == 0) { - //calculate next allowed attack and update the timestamp - attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); - - //handle auto attack job creation - ConcurrentHashMap timers = attacker.getTimers(); - - if (timers != null) { - AttackJob aj = new AttackJob(attacker, slot.ordinal(), true); - JobContainer job; - job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue - timers.put("Attack" + slot, job); - } else - Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID()); + //set auto attack job + setAutoAttackJob(attacker,slot,delay); return; } //get the damage type @@ -394,19 +368,8 @@ public enum CombatManager { //check for damage type immunities if (resists.immuneTo(damageType)) { - //calculate next allowed attack and update the timestamp - attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); - - //handle auto attack job creation - ConcurrentHashMap timers = attacker.getTimers(); - - if (timers != null) { - AttackJob aj = new AttackJob(attacker, slot.ordinal(), true); - JobContainer job; - job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue - timers.put("Attack" + slot, job); - } else - Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID()); + //set auto attack job + setAutoAttackJob(attacker,slot,delay); return; } //calculate resisted damage including fortitude @@ -432,19 +395,8 @@ public enum CombatManager { DispatchMessage.sendToAllInRange(target, cmm); } } - //calculate next allowed attack and update the timestamp - attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); - - //handle auto attack job creation - ConcurrentHashMap timers = attacker.getTimers(); - - if (timers != null) { - AttackJob aj = new AttackJob(attacker, slot.ordinal(), true); - JobContainer job; - job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue - timers.put("Attack" + slot, job); - } else - Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID()); + //set auto attack job + setAutoAttackJob(attacker,slot,delay); } @@ -617,4 +569,21 @@ public enum CombatManager { return 100; } } + + public static void setAutoAttackJob(AbstractCharacter attacker, mbEnums.EquipSlotType slot, long delay){ + //calculate next allowed attack and update the timestamp + attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); + + //handle auto attack job creation + ConcurrentHashMap timers = attacker.getTimers(); + + if (timers != null) { + AttackJob aj = new AttackJob(attacker, slot.ordinal(), true); + JobContainer job; + job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue + timers.put("Attack" + slot, job); + } else + Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID()); + + } } \ No newline at end of file