early exit for out of stam when attacking

This commit is contained in:
2024-04-21 11:14:10 -05:00
parent 2391bd6606
commit bb5d257ae8
+35 -66
View File
@@ -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<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 {
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 {
//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 {
//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 {
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 {
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());
}
}