Browse Source

early exit for out of stam when attacking

combat-2
FatBoy-DOTC 7 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 { @@ -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 { @@ -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<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());
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
return;
}
@ -294,19 +290,8 @@ public enum CombatManager { @@ -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<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());
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
return;
}
}
@ -314,19 +299,8 @@ public enum CombatManager { @@ -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<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());
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
return;
}
//get the damage type
@ -394,19 +368,8 @@ public enum CombatManager { @@ -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<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());
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
return;
}
//calculate resisted damage including fortitude
@ -432,19 +395,8 @@ public enum CombatManager { @@ -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<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());
//set auto attack job
setAutoAttackJob(attacker,slot,delay);
}
@ -617,4 +569,21 @@ public enum CombatManager { @@ -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<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