Browse Source

early exit for out of stam when attacking

combat-2
FatBoy-DOTC 8 months ago
parent
commit
bb5d257ae8
  1. 101
      src/engine/gameManager/CombatManager.java

101
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 // take stamina away from attacker
if (weapon != null) { if (weapon != null) {
float stam = weapon.template.item_wt / 3f; float stam = weapon.template.item_wt / 3f;
stam = (stam < 1) ? 1 : stam; stam = (stam < 1) ? 1 : stam;
@ -246,19 +253,8 @@ public enum CombatManager {
else else
DispatchMessage.sendToAllInRange(attacker, msg); DispatchMessage.sendToAllInRange(attacker, msg);
//calculate next allowed attack and update the timestamp //set auto attack job
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); setAutoAttackJob(attacker,slot,delay);
//handle auto attack job creation
ConcurrentHashMap<String, JobContainer> 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());
return; return;
} }
@ -294,19 +290,8 @@ public enum CombatManager {
else else
DispatchMessage.sendToAllInRange(attacker, msg); DispatchMessage.sendToAllInRange(attacker, msg);
//calculate next allowed attack and update the timestamp //set auto attack job
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); setAutoAttackJob(attacker,slot,delay);
//handle auto attack job creation
ConcurrentHashMap<String, JobContainer> 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());
return; return;
} }
} }
@ -314,19 +299,8 @@ public enum CombatManager {
//calculate the base damage //calculate the base damage
int damage = ThreadLocalRandom.current().nextInt(min, max + 1); int damage = ThreadLocalRandom.current().nextInt(min, max + 1);
if (damage == 0) { if (damage == 0) {
//calculate next allowed attack and update the timestamp //set auto attack job
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); setAutoAttackJob(attacker,slot,delay);
//handle auto attack job creation
ConcurrentHashMap<String, JobContainer> 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());
return; return;
} }
//get the damage type //get the damage type
@ -394,19 +368,8 @@ public enum CombatManager {
//check for damage type immunities //check for damage type immunities
if (resists.immuneTo(damageType)) { if (resists.immuneTo(damageType)) {
//calculate next allowed attack and update the timestamp //set auto attack job
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); setAutoAttackJob(attacker,slot,delay);
//handle auto attack job creation
ConcurrentHashMap<String, JobContainer> 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());
return; return;
} }
//calculate resisted damage including fortitude //calculate resisted damage including fortitude
@ -432,19 +395,8 @@ public enum CombatManager {
DispatchMessage.sendToAllInRange(target, cmm); DispatchMessage.sendToAllInRange(target, cmm);
} }
} }
//calculate next allowed attack and update the timestamp //set auto attack job
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); setAutoAttackJob(attacker,slot,delay);
//handle auto attack job creation
ConcurrentHashMap<String, JobContainer> 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());
} }
@ -617,4 +569,21 @@ public enum CombatManager {
return 100; 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<String, JobContainer> 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());
}
} }
Loading…
Cancel
Save