Browse Source

rentrant lock on combat

combat-3
FatBoy-DOTC 5 months ago
parent
commit
cf58e7b984
  1. 34
      src/engine/gameManager/CombatManager.java
  2. 1
      src/engine/objects/AbstractWorldObject.java

34
src/engine/gameManager/CombatManager.java

@ -12,7 +12,6 @@ import engine.job.JobContainer; @@ -12,7 +12,6 @@ import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.AttackJob;
import engine.jobs.DeferredPowerJob;
import engine.math.Vector3f;
import engine.mbEnums;
import engine.net.client.ClientConnection;
import engine.net.client.msg.TargetedActionMsg;
@ -125,18 +124,12 @@ public enum CombatManager { @@ -125,18 +124,12 @@ public enum CombatManager {
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
if (!attacker.isCombat())
return;
//check if this slot is on attack timer, if timer has passed clear it, else early exit
if(attacker.getTimers() != null && attacker.getTimers().containsKey("Attack"+slot.name()))
if(attacker.getTimers().get("Attack"+slot.name()).timeToExecutionLeft() <= 0)
attacker.getTimers().remove("Attack"+slot.name());
else
return;
}
target.combatLock.writeLock().lock();
// check if character is in range to attack target
try {
PlayerBonuses bonus = attacker.getBonuses();
float rangeMod = 1.0f;
@ -473,7 +466,12 @@ public enum CombatManager { @@ -473,7 +466,12 @@ public enum CombatManager {
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
} catch (Exception ex) {
cancelAutoAttackJob(attacker,slot);
//Logger.error("COMBAT CAUGHT ERROR: " + ex.getMessage());
} finally {
target.combatLock.writeLock().unlock();
}
}
public static void toggleCombat(boolean toggle, ClientConnection origin) {
@ -624,7 +622,20 @@ public enum CombatManager { @@ -624,7 +622,20 @@ public enum CombatManager {
Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID());
}
public static int calculatePetDamage(AbstractCharacter agent) {
public static void cancelAutoAttackJob(AbstractCharacter attacker, mbEnums.EquipSlotType slot) {
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis());
//handle auto attack job creation
ConcurrentHashMap<String, JobContainer> timers = attacker.getTimers();
if (timers != null) {
timers.get("Attack" + slot.name()).cancelJob();
} else
Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID());
}
public static void calculatePetDamage(AbstractCharacter agent) {
//damage calc for pet
float range;
float damage;
@ -636,7 +647,6 @@ public enum CombatManager { @@ -636,7 +647,6 @@ public enum CombatManager {
dmgMultiplier += agent.getLevel() * 0.1f;
range = (float) (maxDmg - minDmg);
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
return (int) (damage * dmgMultiplier);
}
public static double getMinDmg(double min, AbstractCharacter agent) {
int primary = agent.getStatStrCurrent();

1
src/engine/objects/AbstractWorldObject.java

@ -59,6 +59,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { @@ -59,6 +59,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject {
private Vector3f rot = new Vector3f(0.0f, 0.0f, 0.0f);
private int objectTypeMask = 0;
private Bounds bounds;
public ReentrantReadWriteLock combatLock = new ReentrantReadWriteLock();
/**
* No Id Constructor

Loading…
Cancel
Save