Browse Source

Unified Combat System

combat-2
FatBoy-DOTC 8 months ago
parent
commit
9d7f2f39fe
  1. 1358
      src/engine/gameManager/CombatManager.java
  2. 427
      src/engine/gameManager/FinalCombatManager.java
  3. 4
      src/engine/jobs/AttackJob.java
  4. 9
      src/engine/jobs/DeferredPowerJob.java
  5. 37
      src/engine/mobileAI/MobAI.java
  6. 357
      src/engine/mobileAI/utilities/CombatUtilities.java
  7. 21
      src/engine/net/client/ClientMessagePump.java
  8. 13
      src/engine/net/client/handlers/AttackCmdMsgHandler.java
  9. 10
      src/engine/objects/AbstractCharacter.java
  10. 4
      src/engine/powers/poweractions/StealPowerAction.java

1358
src/engine/gameManager/CombatManager.java

File diff suppressed because it is too large Load Diff

427
src/engine/gameManager/FinalCombatManager.java

@ -0,0 +1,427 @@
package engine.gameManager;
import engine.Enum;
import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.AttackJob;
import engine.jobs.DeferredPowerJob;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.TargetedActionMsg;
import engine.net.client.msg.UpdateStateMsg;
import engine.objects.*;
import engine.powers.DamageShield;
import engine.powers.effectmodifiers.AbstractEffectModifier;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
public class FinalCombatManager {
public static void combatCycle(AbstractCharacter attacker, AbstractWorldObject target) {
//early exit checks
if(attacker == null || target == null || !attacker.isAlive() || !target.isAlive())
return;
switch(target.getObjectType()){
case Building:
if(((Building)target).isVulnerable() == false)
return;
break;
case PlayerCharacter:
case Mob:
PlayerBonuses bonuses = ((AbstractCharacter)target).getBonuses();
if(bonuses != null && bonuses.getBool(Enum.ModType.ImmuneToAttack, Enum.SourceType.NONE))
return;
break;
case NPC:
return;
}
Item mainWeapon = attacker.getCharItemManager().getEquipped().get(Enum.EquipSlotType.RHELD);
Item offWeapon = attacker.getCharItemManager().getEquipped().get(Enum.EquipSlotType.LHELD);
if(mainWeapon == null && offWeapon == null){
//no weapons equipped, punch with both fists
processAttack(attacker,target,Enum.EquipSlotType.RHELD);
processAttack(attacker,target,Enum.EquipSlotType.LHELD);
}else if(mainWeapon == null && offWeapon != null && offWeapon.template.item_skill_required.containsKey("Block")){
//no weapon equipped with a shield, punch with one hand
processAttack(attacker,target,Enum.EquipSlotType.RHELD);
}else if(mainWeapon != null && offWeapon != null && offWeapon.template.item_skill_required.containsKey("Block")){
//one weapon equipped with a shield, swing with one hand
processAttack(attacker,target,Enum.EquipSlotType.RHELD);
}else if(mainWeapon != null && offWeapon != null && offWeapon.template.item_skill_required.containsKey("Block") == false){
//two weapons equipped, swing both hands
processAttack(attacker,target,Enum.EquipSlotType.RHELD);
processAttack(attacker,target,Enum.EquipSlotType.LHELD);
} else if(mainWeapon == null && offWeapon != null && offWeapon.template.item_skill_required.containsKey("Block") == false){
//swing left hand only
processAttack(attacker,target,Enum.EquipSlotType.LHELD);
}
}
public static void processAttack(AbstractCharacter attacker, AbstractWorldObject target, Enum.EquipSlotType slot){
//check 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();
float rangeMod = 1.0f;
float attackRange = MBServerStatics.NO_WEAPON_RANGE;
Item weapon = attacker.getCharItemManager().getEquipped(slot);
if (weapon != null) {
if (bonus != null)
rangeMod += bonus.getFloatPercentAll(Enum.ModType.WeaponRange, Enum.SourceType.NONE);
attackRange = weapon.template.item_weapon_max_range * rangeMod;
}
if(attacker.getObjectType().equals(Enum.GameObjectType.Mob))
if(((Mob)attacker).isSiege())
attackRange = 300;
float distanceSquared = attacker.loc.distanceSquared(target.loc);
if(distanceSquared > attackRange * attackRange)
return;
//take stamina away from attacker
if (weapon == null)
attacker.modifyStamina(-0.5f, attacker, true);
else {
float stam = weapon.template.item_wt / 3f;
stam = (stam < 1) ? 1 : stam;
attacker.modifyStamina(-(stam), attacker, true);
}
//cancel things that are cancelled by an attack
attacker.cancelOnAttackSwing();
//declare relevant variables
int min = attacker.minDamageHandOne;
int max = attacker.maxDamageHandOne;
int atr = attacker.atrHandOne;
//get the proper stats based on which slot is attacking
if(slot == Enum.EquipSlotType.LHELD){
min = attacker.minDamageHandTwo;
max = attacker.maxDamageHandTwo;
atr = attacker.atrHandTwo;
}
int def = 0;
if(AbstractCharacter.IsAbstractCharacter(target))
def = ((AbstractCharacter)target).defenseRating;
//calculate hit chance based off ATR and DEF
int hitChance;
float dif = atr / def;
if (dif <= 0.8f)
hitChance = 4;
else
hitChance = ((int) (450 * (dif - 0.8f)) + 4);
if (target.getObjectType() == Enum.GameObjectType.Building)
hitChance = 100;
int passiveAnim = getSwingAnimation(attacker.getCharItemManager().getEquipped().get(slot).template, null, true);
if(ThreadLocalRandom.current().nextInt(100) > hitChance) {
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim);
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchMessage.sendToAllInRange(attacker, msg);
return;
}
//calculate passive chances only if target is AbstractCharacter
if(AbstractCharacter.IsAbstractCharacter(target)){
int hitRoll = ThreadLocalRandom.current().nextInt(100);
float dodgeChance = ((AbstractCharacter) target).getPassiveChance("Dodge", attacker.getLevel(), true);
float blockChance = ((AbstractCharacter) target).getPassiveChance("Block", attacker.getLevel(), true);
float parryChance = ((AbstractCharacter) target).getPassiveChance("Parry", attacker.getLevel(), true);
if(hitRoll > dodgeChance || hitRoll > parryChance || hitRoll > blockChance){
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, MBServerStatics.COMBAT_SEND_BLOCK);
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchMessage.sendToAllInRange(attacker, msg);
return;
}
}
//calculate the base damage
int damage = ThreadLocalRandom.current().nextInt(min,max + 1);
if(damage == 0)
return;
//get the damage type
Enum.SourceType damageType;
if(attacker.getCharItemManager().getEquipped().get(slot) == null) {
damageType = Enum.SourceType.CRUSHING;
if(attacker.getObjectType().equals(Enum.GameObjectType.Mob))
if(((Mob)attacker).isSiege())
damageType = Enum.SourceType.SIEGE;
}else {
damageType = (Enum.SourceType) attacker.getCharItemManager().getEquipped().get(slot).template.item_weapon_damage.keySet().toArray()[0];
}
//get resists
Resists resists;
if(AbstractCharacter.IsAbstractCharacter(target) == false){
//this is a building
resists = ((Building) target).getResists();
}else{
//this is a character
resists = ((AbstractCharacter) target).getResists();
}
if(AbstractCharacter.IsAbstractCharacter(target)) {
AbstractCharacter absTarget = (AbstractCharacter) target;
//check damage shields
PlayerBonuses bonuses = absTarget.getBonuses();
if (bonuses != null) {
ConcurrentHashMap<AbstractEffectModifier, DamageShield> damageShields = bonuses.getDamageShields();
float total = 0;
for (DamageShield ds : damageShields.values()) {
//get amount to damage back
float amount;
if (ds.usePercent())
amount = damage * ds.getAmount() / 100;
else
amount = ds.getAmount();
//get resisted damage for damagetype
if (resists != null)
amount = resists.getResistedDamage(absTarget, attacker, ds.getDamageType(), amount, 0);
total += amount;
}
if (total > 0) {
//apply Damage back
attacker.modifyHealth(-total, absTarget, true);
TargetedActionMsg cmm = new TargetedActionMsg(attacker, attacker, total, 0);
DispatchMessage.sendToAllInRange(target, cmm);
}
}
if (resists != null) {
//check for damage type immunities
if (resists.immuneTo(damageType))
return;
//calculate resisted damage including fortitude
damage = (int) resists.getResistedDamage(attacker,(AbstractCharacter)target,damageType,damage,0);
}
}
//remove damage from target health
if(damage > 0){
if(AbstractCharacter.IsAbstractCharacter(target)){
((AbstractCharacter)target).modifyHealth(-damage, attacker, true);
}else{
((Building)target).setCurrentHitPoints(target.getCurrentHitpoints() - damage);
}
TargetedActionMsg cmm = new TargetedActionMsg(attacker,target, (float) damage,0);
DispatchMessage.sendToAllInRange(target, cmm);
}
//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(Enum.ModType.WeaponSpeed, Enum.SourceType.NONE) != 0f) //add weapon speed bonus
wepSpeed *= (1 + weapon.getBonus(Enum.ModType.WeaponSpeed, Enum.SourceType.NONE));
if (attacker.getBonuses() != null && attacker.getBonuses().getFloatPercentAll(Enum.ModType.AttackDelay, Enum.SourceType.NONE) != 0f) //add effects speed bonus
wepSpeed *= (1 + attacker.getBonuses().getFloatPercentAll(Enum.ModType.AttackDelay, Enum.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<String, JobContainer> timers = attacker.getTimers();
if (timers != null) {
AttackJob aj = new AttackJob(attacker, slot.ordinal(), true);
JobContainer job;
job = JobScheduler.getInstance().scheduleJob(aj, (delay + 1)); // offset 1 millisecond so no overlap issue
timers.put("Attack" + slot, job);
} else {
Logger.error("Unable to find Timers for Character " + attacker.getObjectUUID());
}
}
public static void toggleCombat(boolean toggle, ClientConnection origin) {
PlayerCharacter pc = SessionManager.getPlayerCharacter(origin);
if (pc == null)
return;
pc.setCombat(toggle);
if (!toggle) // toggle is move it to false so clear combat target
pc.setCombatTarget(null); //clear last combat target
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(pc);
DispatchMessage.dispatchMsgToInterestArea(pc, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);
}
public static void toggleSit(boolean toggle, ClientConnection origin) {
PlayerCharacter pc = SessionManager.getPlayerCharacter(origin);
if (pc == null)
return;
pc.setSit(toggle);
UpdateStateMsg rwss = new UpdateStateMsg();
rwss.setPlayer(pc);
DispatchMessage.dispatchMsgToInterestArea(pc, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
}
//Called when character takes damage.
public static void handleRetaliate(AbstractCharacter target, AbstractCharacter attacker) {
if (attacker == null || target == null)
return;
if (attacker.equals(target))
return;
if (target.isMoving() && target.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))
return;
if (!target.isAlive() || !attacker.isAlive())
return;
boolean isCombat = target.isCombat();
//If target in combat and has no target, then attack back
if(isCombat && target.combatTarget == null)
target.setCombatTarget(attacker);
}
public static int getSwingAnimation(ItemTemplate wb, DeferredPowerJob dpj, boolean mainHand) {
int token = 0;
if (dpj != null)
token = (dpj.getPower() != null) ? dpj.getPower().getToken() : 0;
if (token == 563721004) //kick animation
return 79;
if (wb == null)
return 75;
ItemTemplate template = wb;
if (mainHand) {
if (template.weapon_attack_anim_right.size() > 0) {
int animation;
int random = ThreadLocalRandom.current().nextInt(template.weapon_attack_anim_right.size());
try {
animation = template.weapon_attack_anim_right.get(random)[0];
return animation;
} catch (Exception e) {
Logger.error(e.getMessage());
return template.weapon_attack_anim_right.get(0)[0];
}
} else if (template.weapon_attack_anim_left.size() > 0) {
int animation;
int random = ThreadLocalRandom.current().nextInt(template.weapon_attack_anim_left.size());
try {
animation = template.weapon_attack_anim_left.get(random)[0];
return animation;
} catch (Exception e) {
Logger.error(e.getMessage());
return template.weapon_attack_anim_right.get(0)[0];
}
}
} else {
if (template.weapon_attack_anim_left.size() > 0) {
int animation;
int random = ThreadLocalRandom.current().nextInt(template.weapon_attack_anim_left.size());
try {
animation = template.weapon_attack_anim_left.get(random)[0];
return animation;
} catch (Exception e) {
Logger.error(e.getMessage());
return template.weapon_attack_anim_right.get(0)[0];
}
} else if (template.weapon_attack_anim_left.size() > 0) {
int animation;
int random = ThreadLocalRandom.current().nextInt(template.weapon_attack_anim_left.size());
try {
animation = template.weapon_attack_anim_left.get(random)[0];
return animation;
} catch (Exception e) {
Logger.error(e.getMessage());
return template.weapon_attack_anim_right.get(0)[0];
}
}
}
String required = template.item_skill_used;
String mastery = wb.item_skill_mastery_used;
if (required.equals("Unarmed Combat"))
return 75;
else if (required.equals("Sword")) {
if (ItemTemplate.isTwoHanded(template))
return 105;
else
return 98;
} else if (required.equals("Staff") || required.equals("Pole Arm")) {
return 85;
} else if (required.equals("Spear")) {
return 92;
} else if (required.equals("Hammer") || required.equals("Axe")) {
if (ItemTemplate.isTwoHanded(template)) {
return 105;
} else if (mastery.equals("Throwing")) {
return 115;
} else {
return 100;
}
} else if (required.equals("Dagger")) {
if (mastery.equals("Throwing")) {
return 117;
} else {
return 81;
}
} else if (required.equals("Crossbow")) {
return 110;
} else if (required.equals("Bow")) {
return 109;
} else if (ItemTemplate.isTwoHanded(template)) {
return 105;
} else {
return 100;
}
}
}

4
src/engine/jobs/AttackJob.java

@ -9,7 +9,7 @@
package engine.jobs; package engine.jobs;
import engine.gameManager.CombatManager; import engine.gameManager.FinalCombatManager;
import engine.job.AbstractJob; import engine.job.AbstractJob;
import engine.objects.AbstractCharacter; import engine.objects.AbstractCharacter;
@ -28,7 +28,7 @@ public class AttackJob extends AbstractJob {
@Override @Override
protected void doJob() { protected void doJob() {
CombatManager.doCombat(this.source, slot); FinalCombatManager.combatCycle(this.source,this.source.combatTarget);
} }
public boolean success() { public boolean success() {

9
src/engine/jobs/DeferredPowerJob.java

@ -9,7 +9,6 @@
package engine.jobs; package engine.jobs;
import engine.gameManager.CombatManager;
import engine.gameManager.PowersManager; import engine.gameManager.PowersManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.objects.AbstractCharacter; import engine.objects.AbstractCharacter;
@ -77,10 +76,12 @@ public class DeferredPowerJob extends AbstractEffectJob {
// Wtf? Method returns TRUE if rage test fails? Seriously? // Wtf? Method returns TRUE if rage test fails? Seriously?
//DO valid range check ONLY for weapon powers with range less than attack range. //DO valid range check ONLY for weapon powers with range less than attack range.
if (attackRange > powerRange) if (attackRange > powerRange) {
if (CombatManager.NotInRange((AbstractCharacter) this.source, tar, powerRange)) float rangeSquared = this.source.loc.distanceSquared(tar.loc);
if (rangeSquared > powerRange * powerRange) {
return; return;
}
}
//Range check passed, apply power and clear weapon power. //Range check passed, apply power and clear weapon power.
((PlayerCharacter) this.source).setWeaponPower(null); ((PlayerCharacter) this.source).setWeaponPower(null);

37
src/engine/mobileAI/MobAI.java

@ -16,7 +16,6 @@ import engine.math.Vector3f;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.mobileAI.Threads.MobAIThread; import engine.mobileAI.Threads.MobAIThread;
import engine.mobileAI.Threads.Respawner; import engine.mobileAI.Threads.Respawner;
import engine.mobileAI.utilities.CombatUtilities;
import engine.mobileAI.utilities.MovementUtilities; import engine.mobileAI.utilities.MovementUtilities;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.msg.PerformActionMsg; import engine.net.client.msg.PerformActionMsg;
@ -66,7 +65,7 @@ public class MobAI {
} }
if (!CombatUtilities.inRangeToAttack(mob, target)) if (mob.getRange() * mob.getRange() < mob.loc.distanceSquared(target.loc))
return; return;
switch (target.getObjectType()) { switch (target.getObjectType()) {
@ -108,7 +107,7 @@ public class MobAI {
return; return;
} }
if (CombatUtilities.inRange2D(mob, target, mob.getRange())) { if (mob.getRange() * mob.getRange() >= mob.loc.distanceSquared(target.loc)) {
//no weapons, default mob attack speed 3 seconds. //no weapons, default mob attack speed 3 seconds.
@ -126,7 +125,7 @@ public class MobAI {
ItemBase offHand = mob.getWeaponItemBase(false); ItemBase offHand = mob.getWeaponItemBase(false);
if (mainHand == null && offHand == null) { if (mainHand == null && offHand == null) {
CombatUtilities.combatCycle(mob, target, true, null); FinalCombatManager.combatCycle(mob, target);
int delay = 3000; int delay = 3000;
if (mob.isSiege()) if (mob.isSiege())
delay = 11000; delay = 11000;
@ -135,13 +134,13 @@ public class MobAI {
int delay = 3000; int delay = 3000;
if (mob.isSiege()) if (mob.isSiege())
delay = 11000; delay = 11000;
CombatUtilities.combatCycle(mob, target, true, mob.getWeaponItemBase(true)); FinalCombatManager.combatCycle(mob, target);
mob.setLastAttackTime(System.currentTimeMillis() + delay); mob.setLastAttackTime(System.currentTimeMillis() + delay);
} else if (mob.getWeaponItemBase(false) != null) { } else if (mob.getWeaponItemBase(false) != null) {
int attackDelay = 3000; int attackDelay = 3000;
if (mob.isSiege()) if (mob.isSiege())
attackDelay = 11000; attackDelay = 11000;
CombatUtilities.combatCycle(mob, target, false, mob.getWeaponItemBase(false)); FinalCombatManager.combatCycle(mob, target);
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay); mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
} }
} }
@ -180,7 +179,7 @@ public class MobAI {
ItemBase offHand = mob.getWeaponItemBase(false); ItemBase offHand = mob.getWeaponItemBase(false);
if (mainHand == null && offHand == null) { if (mainHand == null && offHand == null) {
CombatUtilities.combatCycle(mob, target, true, null); FinalCombatManager.combatCycle(mob, target);
int delay = 3000; int delay = 3000;
if (mob.isSiege()) if (mob.isSiege())
delay = 15000; delay = 15000;
@ -189,13 +188,13 @@ public class MobAI {
int attackDelay = 3000; int attackDelay = 3000;
if (mob.isSiege()) if (mob.isSiege())
attackDelay = 15000; attackDelay = 15000;
CombatUtilities.combatCycle(mob, target, true, mob.getWeaponItemBase(true)); FinalCombatManager.combatCycle(mob, target);
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay); mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
} else if (mob.getWeaponItemBase(false) != null) { } else if (mob.getWeaponItemBase(false) != null) {
int attackDelay = 3000; int attackDelay = 3000;
if (mob.isSiege()) if (mob.isSiege())
attackDelay = 15000; attackDelay = 15000;
CombatUtilities.combatCycle(mob, target, false, mob.getWeaponItemBase(false)); FinalCombatManager.combatCycle(mob, target);
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay); mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
} }
@ -223,7 +222,7 @@ public class MobAI {
ItemBase offHand = mob.getWeaponItemBase(false); ItemBase offHand = mob.getWeaponItemBase(false);
if (mainHand == null && offHand == null) { if (mainHand == null && offHand == null) {
CombatUtilities.combatCycle(mob, target, true, null); FinalCombatManager.combatCycle(mob, target);
int delay = 3000; int delay = 3000;
if (mob.isSiege()) if (mob.isSiege())
delay = 11000; delay = 11000;
@ -232,13 +231,13 @@ public class MobAI {
int attackDelay = 3000; int attackDelay = 3000;
if (mob.isSiege()) if (mob.isSiege())
attackDelay = 11000; attackDelay = 11000;
CombatUtilities.combatCycle(mob, target, true, mob.getWeaponItemBase(true)); FinalCombatManager.combatCycle(mob, target);
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay); mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
} else if (mob.getWeaponItemBase(false) != null) { } else if (mob.getWeaponItemBase(false) != null) {
int attackDelay = 3000; int attackDelay = 3000;
if (mob.isSiege()) if (mob.isSiege())
attackDelay = 11000; attackDelay = 11000;
CombatUtilities.combatCycle(mob, target, false, mob.getWeaponItemBase(false)); FinalCombatManager.combatCycle(mob, target);
mob.setLastAttackTime(System.currentTimeMillis() + attackDelay); mob.setLastAttackTime(System.currentTimeMillis() + attackDelay);
if (target.getCombatTarget() == null) { if (target.getCombatTarget() == null) {
target.setCombatTarget(mob); target.setCombatTarget(mob);
@ -423,15 +422,9 @@ public class MobAI {
if (mob.isPlayerGuard()) if (mob.isPlayerGuard())
powerRank = getGuardPowerRank(mob); powerRank = getGuardPowerRank(mob);
//check for hit-roll
if (mobPower.requiresHitRoll)
if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget()))
return false;
// Cast the spell // Cast the spell
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { if (mob.getRange() * mob.getRange() >= mob.loc.distanceSquared(target.loc)) {
PerformActionMsg msg; PerformActionMsg msg;
@ -745,7 +738,7 @@ public class MobAI {
//move back to owner //move back to owner
if (CombatUtilities.inRange2D(mob, mob.guardCaptain, 6)) if (mob.getRange() * mob.getRange() >= mob.loc.distanceSquared(mob.guardCaptain.loc))
return; return;
mob.destination = mob.guardCaptain.getLoc(); mob.destination = mob.guardCaptain.getLoc();
@ -852,7 +845,7 @@ public class MobAI {
try { try {
if (mob.getCombatTarget() != null && CombatUtilities.inRange2D(mob, mob.getCombatTarget(), MobAIThread.AI_BASE_AGGRO_RANGE * 0.5f)) if (mob.getCombatTarget() != null && mob.getRange() * mob.getRange() >= MobAIThread.AI_BASE_AGGRO_RANGE * 0.5f)
return; return;
if (mob.isPlayerGuard() && !mob.despawned) { if (mob.isPlayerGuard() && !mob.despawned) {
@ -902,7 +895,7 @@ public class MobAI {
mob.getTimestamps().put("lastChase",System.currentTimeMillis()); mob.getTimestamps().put("lastChase",System.currentTimeMillis());
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mob.getRange()) == false) { if (mob.getRange() * mob.getRange() <= mob.loc.distanceSquared(mob.combatTarget.loc)) {
if (mob.getRange() > 15) { if (mob.getRange() > 15) {
mob.destination = mob.getCombatTarget().getLoc(); mob.destination = mob.getCombatTarget().getLoc();
MovementUtilities.moveToLocation(mob, mob.destination, 0, false); MovementUtilities.moveToLocation(mob, mob.destination, 0, false);

357
src/engine/mobileAI/utilities/CombatUtilities.java

@ -1,357 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.mobileAI.utilities;
import engine.Enum.DispatchChannel;
import engine.Enum.GameObjectType;
import engine.Enum.ModType;
import engine.Enum.SourceType;
import engine.gameManager.ChatManager;
import engine.gameManager.CombatManager;
import engine.math.Vector3fImmutable;
import engine.net.DispatchMessage;
import engine.net.client.msg.TargetedActionMsg;
import engine.objects.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.util.concurrent.ThreadLocalRandom;
import static engine.math.FastMath.sqr;
public class CombatUtilities {
public static boolean inRangeToAttack(Mob agent, AbstractWorldObject target) {
if (Float.isNaN(agent.getLoc().x))
return false;
try {
Vector3fImmutable sl = agent.getLoc();
Vector3fImmutable tl = target.getLoc();
//add Hitbox's to range.
float range = agent.getRange();
range += CombatManager.calcHitBox(target) + CombatManager.calcHitBox(agent);
return !(sl.distanceSquared(tl) > sqr(range));
} catch (Exception e) {
Logger.error(e.toString());
return false;
}
}
public static boolean inRange2D(AbstractWorldObject entity1, AbstractWorldObject entity2, double range) {
return entity1.getLoc().distanceSquared2D(entity2.getLoc()) < range * range;
}
public static void swingIsBlock(Mob agent, AbstractWorldObject target, int animation) {
if (!target.isAlive())
return;
TargetedActionMsg msg = new TargetedActionMsg(agent, animation, target, MBServerStatics.COMBAT_SEND_BLOCK);
if (target.getObjectType() == GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchMessage.sendToAllInRange(agent, msg);
}
public static void swingIsParry(Mob agent, AbstractWorldObject target, int animation) {
if (!target.isAlive())
return;
TargetedActionMsg msg = new TargetedActionMsg(agent, animation, target, MBServerStatics.COMBAT_SEND_PARRY);
if (target.getObjectType() == GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchMessage.sendToAllInRange(agent, msg);
}
public static void swingIsDodge(Mob agent, AbstractWorldObject target, int animation) {
if (!target.isAlive())
return;
TargetedActionMsg msg = new TargetedActionMsg(agent, animation, target, MBServerStatics.COMBAT_SEND_DODGE);
if (target.getObjectType() == GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchMessage.sendToAllInRange(agent, msg);
}
public static void swingIsDamage(Mob agent, AbstractWorldObject target, float damage, int animation) {
if (agent.isSiege() == true) {
damage = ThreadLocalRandom.current().nextInt(1000) + 1500;
}
float trueDamage = damage;
if (!target.isAlive())
return;
if (AbstractWorldObject.IsAbstractCharacter(target))
trueDamage = ((AbstractCharacter) target).modifyHealth(-damage, agent, false);
else if (target.getObjectType() == GameObjectType.Building)
trueDamage = ((Building) target).modifyHealth(-damage, agent);
//Don't send 0 damage kay thanx.
if (trueDamage == 0)
return;
TargetedActionMsg msg = new TargetedActionMsg(agent, target, damage, animation);
if (target.getObjectType() == GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchMessage.sendToAllInRange(agent, msg);
//check damage shields
if (AbstractWorldObject.IsAbstractCharacter(target) && target.isAlive() && target.getObjectType() != GameObjectType.Mob)
CombatManager.handleDamageShields(agent, (AbstractCharacter) target, damage);
}
public static boolean canSwing(Mob agent) {
return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.NONE));
}
public static void swingIsMiss(Mob agent, AbstractWorldObject target, int animation) {
TargetedActionMsg msg = new TargetedActionMsg(agent, target, 0f, animation);
if (target.getObjectType() == GameObjectType.PlayerCharacter)
DispatchMessage.dispatchMsgToInterestArea(target, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchMessage.sendToAllInRange(agent, msg);
}
public static boolean triggerDefense(Mob agent, AbstractWorldObject target) {
int defenseScore = 0;
int attackScore = agent.getAtrHandOne();
switch (target.getObjectType()) {
case PlayerCharacter:
defenseScore = ((AbstractCharacter) target).getDefenseRating();
break;
case Mob:
Mob mob = (Mob) target;
if (mob.isSiege())
defenseScore = attackScore;
break;
case Building:
return false;
}
int hitChance;
if (attackScore > defenseScore || defenseScore == 0)
hitChance = 94;
else if (attackScore == defenseScore && target.getObjectType() == GameObjectType.Mob)
hitChance = 10;
else {
float dif = attackScore / defenseScore;
if (dif <= 0.8f)
hitChance = 4;
else
hitChance = ((int) (450 * (dif - 0.8f)) + 4);
if (target.getObjectType() == GameObjectType.Building)
hitChance = 100;
}
return ThreadLocalRandom.current().nextInt(100) > hitChance;
}
public static boolean triggerBlock(Mob agent, AbstractWorldObject ac) {
return triggerPassive(agent, ac, "Block");
}
public static boolean triggerParry(Mob agent, AbstractWorldObject ac) {
return triggerPassive(agent, ac, "Parry");
}
public static boolean triggerDodge(Mob agent, AbstractWorldObject ac) {
return triggerPassive(agent, ac, "Dodge");
}
public static boolean triggerPassive(Mob agent, AbstractWorldObject ac, String type) {
float chance = 0;
if (AbstractWorldObject.IsAbstractCharacter(ac))
chance = ((AbstractCharacter) ac).getPassiveChance(type, agent.getLevel(), true);
if (chance > 75f)
chance = 75f;
if (agent.isSiege() && AbstractWorldObject.IsAbstractCharacter(ac))
chance = 100;
return ThreadLocalRandom.current().nextInt(100) < chance;
}
public static void combatCycle(Mob agent, AbstractWorldObject target, boolean mainHand, ItemBase wb) {
if (!agent.isAlive() || !target.isAlive())
return;
if (target.getObjectType() == GameObjectType.PlayerCharacter)
if (!((PlayerCharacter) target).isActive())
return;
int anim = 75;
float speed;
if (mainHand)
speed = agent.getSpeedHandOne();
else
speed = agent.getSpeedHandTwo();
SourceType dt = SourceType.CRUSHING;
if (agent.isSiege())
dt = SourceType.SIEGE;
if (wb != null) {
anim = CombatManager.getSwingAnimation(wb, null, mainHand);
dt = wb.getDamageType();
} else if (!mainHand)
return;
Resists res = null;
PlayerBonuses bonus = null;
switch (target.getObjectType()) {
case Building:
res = ((Building) target).getResists();
break;
case PlayerCharacter:
res = ((PlayerCharacter) target).getResists();
bonus = ((PlayerCharacter) target).getBonuses();
break;
case Mob:
Mob mob = (Mob) target;
res = mob.getResists();
bonus = ((Mob) target).getBonuses();
break;
}
//must not be immune to all or immune to attack
if (bonus != null && !bonus.getBool(ModType.NoMod, SourceType.IMMUNETOATTACK))
if (res != null && (res.immuneToAll() || res.immuneToAttacks() || res.immuneTo(dt)))
return;
int passiveAnim = CombatManager.getSwingAnimation(wb, null, mainHand);
if (canSwing(agent)) {
if (triggerDefense(agent, target)) {
swingIsMiss(agent, target, passiveAnim);
return;
} else if (triggerDodge(agent, target)) {
swingIsDodge(agent, target, passiveAnim);
return;
} else if (triggerParry(agent, target)) {
swingIsParry(agent, target, passiveAnim);
return;
} else if (triggerBlock(agent, target)) {
swingIsBlock(agent, target, passiveAnim);
return;
}
swingIsDamage(agent, target, determineDamage(agent), anim);
if (agent.getWeaponPower() != null)
agent.getWeaponPower().attack(target, MBServerStatics.ONE_MINUTE);
}
if (target.getObjectType().equals(GameObjectType.PlayerCharacter)) {
PlayerCharacter player = (PlayerCharacter) target;
if (player.getDebug(64))
ChatManager.chatSayInfo(player, "Debug Combat: Mob UUID " + agent.getObjectUUID() + " || Building ID = " + agent.getBuildingID() + " || Floor = " + agent.getInFloorID() + " || Level = " + agent.getInBuilding());//combat debug
}
//SIEGE MONSTERS DO NOT ATTACK GUARDSs
if (target.getObjectType() == GameObjectType.Mob)
if (((Mob) target).isSiege())
return;
//handle the retaliate
if (AbstractWorldObject.IsAbstractCharacter(target))
CombatManager.handleRetaliate((AbstractCharacter) target, agent);
if (target.getObjectType() == GameObjectType.Mob) {
Mob targetMob = (Mob) target;
if (targetMob.isSiege())
return;
}
}
public static float determineDamage(Mob agent) {
//early exit for null
if (agent == null)
return 0;
AbstractWorldObject target = agent.getCombatTarget();
if (target == null)
return 0;
int damage = 0;
SourceType dt = getDamageType(agent);
damage = ThreadLocalRandom.current().nextInt((int)getMinDmg(agent), (int)getMaxDmg(agent) + 1);
if (AbstractWorldObject.IsAbstractCharacter(target)) {
if (((AbstractCharacter) target).isSit()) {
damage *= 2.5f; //increase damage if sitting
}
return (int) (((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, damage, 0));
}
if (target.getObjectType() == GameObjectType.Building) {
Building building = (Building) target;
Resists resists = building.getResists();
return (int) ((damage * (1 - (resists.getResist(dt, 0) / 100))));
}
return damage;
}
public static SourceType getDamageType(Mob agent) {
SourceType dt = SourceType.CRUSHING;
if (agent.getEquip().get(1) != null) {
return agent.getEquip().get(1).getItemBase().getDamageType();
}
if (agent.getEquip().get(2) != null && ItemTemplate.isShield(agent.getEquip().get(2).template) == false) {
return agent.getEquip().get(2).getItemBase().getDamageType();
}
return dt;
}
public static double getMinDmg(Mob agent) {
if (agent.equip.get(2) != null && !ItemTemplate.isShield(agent.equip.get(2).template))
return agent.minDamageHandTwo;
else
return agent.minDamageHandOne;
}
public static double getMaxDmg(Mob agent) {
if (agent.equip.get(2) != null && !ItemTemplate.isShield(agent.equip.get(2).template))
return agent.maxDamageHandTwo;
else
return agent.maxDamageHandOne;
}
}

21
src/engine/net/client/ClientMessagePump.java

@ -1237,7 +1237,22 @@ public class ClientMessagePump implements NetMsgHandler {
&& (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal())) && (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal()))
return; return;
CombatManager.setAttackTarget(msg, conn); //CombatManager.setAttackTarget(msg, conn);
if(msg.getTargetType() == GameObjectType.Building.ordinal()){
conn.getPlayerCharacter().getPet().setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID()));
}
switch(msg.getTargetType()) {
case 53: //player character
conn.getPlayerCharacter().getPet().setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID()));
break;
case 37://mob
conn.getPlayerCharacter().getPet().setCombatTarget(Mob.getMob(msg.getTargetID()));
break;
case 8://mob
conn.getPlayerCharacter().getPet().setCombatTarget(BuildingManager.getBuilding(msg.getTargetID()));
break;
}
if (pet.getCombatTarget() == null) if (pet.getCombatTarget() == null)
return; return;
} }
@ -1430,10 +1445,10 @@ public class ClientMessagePump implements NetMsgHandler {
social((SocialMsg) msg, origin); social((SocialMsg) msg, origin);
break; break;
case COMBATMODE: case COMBATMODE:
CombatManager.toggleCombat((ToggleCombatMsg) msg, origin); FinalCombatManager.toggleCombat(((ToggleCombatMsg) msg).toggleCombat(),origin);
break; break;
case ARCCOMBATMODEATTACKING: case ARCCOMBATMODEATTACKING:
CombatManager.toggleCombat((SetCombatModeMsg) msg, origin); FinalCombatManager.toggleCombat(((SetCombatModeMsg) msg).getToggle(),origin);
break; break;
case MODIFYGUILDSTATE: case MODIFYGUILDSTATE:
ToggleLfgRecruitingMsg tlrm = (ToggleLfgRecruitingMsg) msg; ToggleLfgRecruitingMsg tlrm = (ToggleLfgRecruitingMsg) msg;

13
src/engine/net/client/handlers/AttackCmdMsgHandler.java

@ -3,7 +3,7 @@ package engine.net.client.handlers;
import engine.Enum; import engine.Enum;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.CombatManager; import engine.gameManager.FinalCombatManager;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.AttackCmdMsg; import engine.net.client.msg.AttackCmdMsg;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
@ -70,15 +70,16 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
//put in combat if not already //put in combat if not already
if (!playerCharacter.isCombat()) if (!playerCharacter.isCombat()) {
CombatManager.toggleCombat(true, origin); //CombatManager.toggleCombat(true, origin);
FinalCombatManager.toggleCombat(true,origin);
}
//make character stand if sitting //make character stand if sitting
if (playerCharacter.isSit()) if (playerCharacter.isSit())
CombatManager.toggleSit(false, origin); FinalCombatManager.toggleSit(false, origin);
CombatManager.AttackTarget(playerCharacter, target); FinalCombatManager.combatCycle(playerCharacter,target);
return true; return true;
} }

10
src/engine/objects/AbstractCharacter.java

@ -1332,7 +1332,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
//TODO why is Handle REtaliate and cancelontakedamage in modifyHealth? shouldnt this be outside this method? //TODO why is Handle REtaliate and cancelontakedamage in modifyHealth? shouldnt this be outside this method?
if (value < 0f && !fromCost) { if (value < 0f && !fromCost) {
this.cancelOnTakeDamage(); this.cancelOnTakeDamage();
CombatManager.handleRetaliate(this, attacker); FinalCombatManager.handleRetaliate(this, attacker);
} }
if(this.getObjectType().equals(GameObjectType.Mob)){ if(this.getObjectType().equals(GameObjectType.Mob)){
@ -1399,7 +1399,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
} }
if (value < 0f && !fromCost) { if (value < 0f && !fromCost) {
this.cancelOnTakeDamage(); this.cancelOnTakeDamage();
CombatManager.handleRetaliate(this, attacker); FinalCombatManager.handleRetaliate(this, attacker);
} }
return newMana - oldMana; return newMana - oldMana;
} }
@ -1438,7 +1438,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
} }
if (value < 0f && !fromCost) { if (value < 0f && !fromCost) {
this.cancelOnTakeDamage(); this.cancelOnTakeDamage();
CombatManager.handleRetaliate(this, attacker); FinalCombatManager.handleRetaliate(this, attacker);
} }
return newStamina - oldStamina; return newStamina - oldStamina;
} }
@ -1473,7 +1473,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
} }
if (oldMana > newMana && !fromCost) { if (oldMana > newMana && !fromCost) {
this.cancelOnTakeDamage(); this.cancelOnTakeDamage();
CombatManager.handleRetaliate(this, attacker); FinalCombatManager.handleRetaliate(this, attacker);
} }
return newMana - oldMana; return newMana - oldMana;
} }
@ -1508,7 +1508,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
} }
if (oldStamina > newStamina && !fromCost) { if (oldStamina > newStamina && !fromCost) {
this.cancelOnTakeDamage(); this.cancelOnTakeDamage();
CombatManager.handleRetaliate(this, attacker); FinalCombatManager.handleRetaliate(this, attacker);
} }
return newStamina - oldStamina; return newStamina - oldStamina;

4
src/engine/powers/poweractions/StealPowerAction.java

@ -12,7 +12,7 @@ package engine.powers.poweractions;
import engine.Enum; import engine.Enum;
import engine.Enum.ItemType; import engine.Enum.ItemType;
import engine.gameManager.ChatManager; import engine.gameManager.ChatManager;
import engine.gameManager.CombatManager; import engine.gameManager.FinalCombatManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
@ -132,7 +132,7 @@ public class StealPowerAction extends AbstractPowerAction {
ownerPC.setLastPlayerAttackTime(); ownerPC.setLastPlayerAttackTime();
//Handle target attacking back if in combat and has no other target //Handle target attacking back if in combat and has no other target
CombatManager.handleRetaliate(ownerAC, sourcePlayer); FinalCombatManager.handleRetaliate(ownerAC, sourcePlayer);
} else } else
return; return;

Loading…
Cancel
Save