forked from MagicBane/Server
Merge remote-tracking branch 'refs/remotes/origin/bugfix-combat-range' into feature-workorder2.4
This commit is contained in:
@@ -12,6 +12,7 @@ import engine.job.JobContainer;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.AttackJob;
|
||||
import engine.jobs.DeferredPowerJob;
|
||||
import engine.math.Bounds;
|
||||
import engine.mbEnums;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
@@ -23,6 +24,8 @@ import engine.powers.effectmodifiers.AbstractEffectModifier;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.EnumSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@@ -38,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)
|
||||
@@ -59,6 +66,7 @@ public enum CombatManager {
|
||||
if (mainWeapon == null && offWeapon == null) {
|
||||
//no weapons equipped, punch with both fists
|
||||
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD);
|
||||
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter))
|
||||
processAttack(attacker, target, mbEnums.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
|
||||
@@ -81,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();
|
||||
@@ -109,8 +111,80 @@ public enum CombatManager {
|
||||
|
||||
float distanceSquared = attacker.loc.distanceSquared(target.loc);
|
||||
|
||||
if (distanceSquared > attackRange * attackRange)
|
||||
return;
|
||||
boolean inRange = false;
|
||||
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)){
|
||||
attackRange += ((PlayerCharacter)attacker).getCharacterHeight() * 0.5f;
|
||||
}else {
|
||||
attackRange += attacker.calcHitBox();
|
||||
}
|
||||
switch(target.getObjectType()){
|
||||
case PlayerCharacter:
|
||||
attackRange += ((PlayerCharacter)target).getCharacterHeight() * 0.5f;
|
||||
if(distanceSquared < attackRange * attackRange)
|
||||
inRange = true;
|
||||
break;
|
||||
case Mob:
|
||||
attackRange += ((AbstractCharacter)target).calcHitBox();
|
||||
if(distanceSquared < attackRange * attackRange)
|
||||
inRange = true;
|
||||
break;
|
||||
case Building:
|
||||
float locX = target.loc.x - target.getBounds().getHalfExtents().x;
|
||||
float locZ = target.loc.z - target.getBounds().getHalfExtents().y;
|
||||
float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2;
|
||||
float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2;
|
||||
Rectangle2D.Float rect = new Rectangle2D.Float(locX,locZ,sizeX,sizeZ);
|
||||
if(rect.contains(new Point2D.Float(attacker.loc.x,attacker.loc.z)))
|
||||
inRange = true;
|
||||
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 || ((AbstractCharacter)target).combatTarget.isAlive() == false){
|
||||
((AbstractCharacter)target).combatTarget = attacker;
|
||||
if(target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat())
|
||||
combatCycle((AbstractCharacter) target, attacker);
|
||||
}
|
||||
}
|
||||
|
||||
DeferredPowerJob dpj = null;
|
||||
|
||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
||||
|
||||
dpj = ((PlayerCharacter) attacker).getWeaponPower();
|
||||
|
||||
if (dpj != null) {
|
||||
dpj.attack(target, attackRange);
|
||||
|
||||
if (dpj.getPower() != null && (dpj.getPowerToken() == -1851459567 || dpj.getPowerToken() == -1851489518))
|
||||
((PlayerCharacter) attacker).setWeaponPower(dpj);
|
||||
}
|
||||
}
|
||||
|
||||
// take stamina away from attacker
|
||||
|
||||
@@ -172,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<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());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -207,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<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());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//calculate the base damage
|
||||
int damage = ThreadLocalRandom.current().nextInt(min, max + 1);
|
||||
if (damage == 0)
|
||||
return;
|
||||
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());
|
||||
return;
|
||||
}
|
||||
//get the damage type
|
||||
|
||||
mbEnums.DamageType damageType;
|
||||
@@ -280,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<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());
|
||||
return;
|
||||
}
|
||||
//calculate resisted damage including fortitude
|
||||
|
||||
damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0);
|
||||
@@ -305,43 +431,11 @@ public enum CombatManager {
|
||||
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim);
|
||||
DispatchMessage.sendToAllInRange(target, cmm);
|
||||
}
|
||||
DeferredPowerJob dpj = null;
|
||||
|
||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
||||
|
||||
dpj = ((PlayerCharacter) attacker).getWeaponPower();
|
||||
|
||||
if (dpj != null) {
|
||||
dpj.attack(target, attackRange);
|
||||
|
||||
if (dpj.getPower() != null && (dpj.getPowerToken() == -1851459567 || dpj.getPowerToken() == -1851489518))
|
||||
((PlayerCharacter) attacker).setWeaponPower(dpj);
|
||||
}
|
||||
}
|
||||
//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<String, JobContainer> timers = attacker.getTimers();
|
||||
|
||||
if (timers != null) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
mob.nextAttackTime = System.currentTimeMillis() + delay;
|
||||
AttackTarget(mob, mob.getCombatTarget());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: CheckForAttack" + " " + e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user