From 2aaca661e2cf6ae2d74882d08a5dd8cb028e46fb Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 13 Apr 2024 19:44:03 -0500 Subject: [PATCH] new combat finalized --- src/engine/gameManager/CombatManager.java | 115 ++++++++++++++++------ src/engine/mobileAI/MobAI.java | 13 +-- 2 files changed, 85 insertions(+), 43 deletions(-) diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index 9b5561e1..71c7fae3 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -41,6 +41,10 @@ public enum CombatManager { if (attacker == null || target == null || !attacker.isAlive() || !target.isAlive()) return; + if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) + if (((Mob) attacker).nextAttackTime > System.currentTimeMillis()) + return; + switch (target.getObjectType()) { case Building: if (((Building) target).isVulnerable() == false) @@ -85,12 +89,6 @@ public enum CombatManager { public static void processAttack(AbstractCharacter attacker, AbstractWorldObject target, mbEnums.EquipSlotType slot) { - // heck if character can even attack yet - - //if (attacker.getTimestamps().containsKey("Attack" + slot.name())) - // if (System.currentTimeMillis() < attacker.getTimestamps().get("Attack" + slot.name())) - // return; - // check if character is in range to attack target PlayerBonuses bonus = attacker.getBonuses(); @@ -141,13 +139,36 @@ public enum CombatManager { break; } + //get delay for the auto attack job + long delay = 5000; + + if (weapon != null) { + + int wepSpeed = (int) (weapon.template.item_weapon_wepspeed); + + if (weapon.getBonusPercent(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None) != 0f) //add weapon speed bonus + wepSpeed *= (1 + weapon.getBonus(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None)); + + if (attacker.getBonuses() != null && attacker.getBonuses().getFloatPercentAll(mbEnums.ModType.AttackDelay, mbEnums.SourceType.None) != 0f) //add effects speed bonus + wepSpeed *= (1 + attacker.getBonuses().getFloatPercentAll(mbEnums.ModType.AttackDelay, mbEnums.SourceType.None)); + + if (wepSpeed < 10) + wepSpeed = 10; //Old was 10, but it can be reached lower with legit buffs,effects. + + delay = wepSpeed * 100; + } + + if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) + ((Mob)attacker).nextAttackTime = System.currentTimeMillis() + delay; if (inRange) { //handle retaliate if(AbstractCharacter.IsAbstractCharacter(target)){ - if(((AbstractCharacter)target).combatTarget == null){ + if(((AbstractCharacter)target).combatTarget == null || ((AbstractCharacter)target).combatTarget.isAlive() == false){ ((AbstractCharacter)target).combatTarget = attacker; + if(target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat()) + combatCycle((AbstractCharacter) target, attacker); } } @@ -225,6 +246,19 @@ 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()); return; } @@ -260,15 +294,41 @@ 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()); return; } } //calculate the base damage int damage = ThreadLocalRandom.current().nextInt(min, max + 1); - if (damage == 0) + 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()); return; - + } //get the damage type mbEnums.DamageType damageType; @@ -333,9 +393,22 @@ public enum CombatManager { //check for damage type immunities - if (resists.immuneTo(damageType)) - return; + 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()); + return; + } //calculate resisted damage including fortitude damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0); @@ -360,29 +433,9 @@ public enum CombatManager { } } //calculate next allowed attack and update the timestamp - - long delay = 20 * 100; - - if (weapon != null) { - - int wepSpeed = (int) (weapon.template.item_weapon_wepspeed); - - if (weapon.getBonusPercent(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None) != 0f) //add weapon speed bonus - wepSpeed *= (1 + weapon.getBonus(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None)); - - if (attacker.getBonuses() != null && attacker.getBonuses().getFloatPercentAll(mbEnums.ModType.AttackDelay, mbEnums.SourceType.None) != 0f) //add effects speed bonus - wepSpeed *= (1 + attacker.getBonuses().getFloatPercentAll(mbEnums.ModType.AttackDelay, mbEnums.SourceType.None)); - - if (wepSpeed < 10) - wepSpeed = 10; //Old was 10, but it can be reached lower with legit buffs,effects. - - delay = wepSpeed * 100; - } - attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); //handle auto attack job creation - ConcurrentHashMap timers = attacker.getTimers(); if (timers != null) { diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index e51b7e34..27e9173a 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -764,19 +764,8 @@ public class MobAI { mob.setCombatTarget(null); return; } - if (System.currentTimeMillis() > mob.getNextAttackTime()) { - int delay = 3000; - if (mob.charItemManager.getEquipped().get(mbEnums.EquipSlotType.RHELD) != null) { - delay = (int) (mob.charItemManager.getEquipped().get(mbEnums.EquipSlotType.RHELD).template.item_weapon_wepspeed * 100); - } - if (mob.charItemManager.getEquipped().get(mbEnums.EquipSlotType.LHELD) != null && mob.charItemManager.getEquipped().get(mbEnums.EquipSlotType.LHELD).template.item_type.equals(mbEnums.ItemType.WEAPON)) { - delay += (int) (mob.charItemManager.getEquipped().get(mbEnums.EquipSlotType.LHELD).template.item_weapon_wepspeed * 100); - } + AttackTarget(mob, mob.getCombatTarget()); - - mob.nextAttackTime = System.currentTimeMillis() + delay; - AttackTarget(mob, mob.getCombatTarget()); - } } catch (Exception e) { Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckForAttack" + " " + e.getMessage()); }