|
|
|
@ -12,6 +12,7 @@ import engine.job.JobContainer;
@@ -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;
@@ -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 {
@@ -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,7 +66,8 @@ public enum CombatManager {
@@ -59,7 +66,8 @@ public enum CombatManager {
|
|
|
|
|
if (mainWeapon == null && offWeapon == null) { |
|
|
|
|
//no weapons equipped, punch with both fists
|
|
|
|
|
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD); |
|
|
|
|
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD); |
|
|
|
|
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
|
|
|
|
|
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD); |
|
|
|
@ -81,12 +89,6 @@ public enum CombatManager {
@@ -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,239 +111,331 @@ public enum CombatManager {
@@ -109,239 +111,331 @@ 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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// take stamina away from attacker
|
|
|
|
|
//get delay for the auto attack job
|
|
|
|
|
long delay = 5000; |
|
|
|
|
|
|
|
|
|
if (weapon != null) { |
|
|
|
|
float stam = weapon.template.item_wt / 3f; |
|
|
|
|
stam = (stam < 1) ? 1 : stam; |
|
|
|
|
attacker.modifyStamina(-(stam), attacker, true); |
|
|
|
|
} else |
|
|
|
|
attacker.modifyStamina(-0.5f, attacker, true); |
|
|
|
|
|
|
|
|
|
//cancel things that are cancelled by an attack
|
|
|
|
|
|
|
|
|
|
attacker.cancelOnAttackSwing(); |
|
|
|
|
int wepSpeed = (int) (weapon.template.item_weapon_wepspeed); |
|
|
|
|
|
|
|
|
|
//declare relevant variables
|
|
|
|
|
if (weapon.getBonusPercent(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None) != 0f) //add weapon speed bonus
|
|
|
|
|
wepSpeed *= (1 + weapon.getBonus(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None)); |
|
|
|
|
|
|
|
|
|
int min = attacker.minDamageHandOne; |
|
|
|
|
int max = attacker.maxDamageHandOne; |
|
|
|
|
int atr = attacker.atrHandOne; |
|
|
|
|
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)); |
|
|
|
|
|
|
|
|
|
//get the proper stats based on which slot is attacking
|
|
|
|
|
if (wepSpeed < 10) |
|
|
|
|
wepSpeed = 10; //Old was 10, but it can be reached lower with legit buffs,effects.
|
|
|
|
|
|
|
|
|
|
if (slot == mbEnums.EquipSlotType.LHELD) { |
|
|
|
|
min = attacker.minDamageHandTwo; |
|
|
|
|
max = attacker.maxDamageHandTwo; |
|
|
|
|
atr = attacker.atrHandTwo; |
|
|
|
|
delay = wepSpeed * 100; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int def = 0; |
|
|
|
|
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) |
|
|
|
|
((Mob)attacker).nextAttackTime = System.currentTimeMillis() + delay; |
|
|
|
|
|
|
|
|
|
if (inRange) { |
|
|
|
|
|
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target)) |
|
|
|
|
def = ((AbstractCharacter) target).defenseRating; |
|
|
|
|
//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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//calculate hit chance based off ATR and DEF
|
|
|
|
|
DeferredPowerJob dpj = null; |
|
|
|
|
|
|
|
|
|
int hitChance; |
|
|
|
|
if (def == 0) |
|
|
|
|
def = 1; |
|
|
|
|
float dif = atr / def; |
|
|
|
|
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) { |
|
|
|
|
|
|
|
|
|
if (dif <= 0.8f) |
|
|
|
|
hitChance = 4; |
|
|
|
|
else |
|
|
|
|
hitChance = ((int) (450 * (dif - 0.8f)) + 4); |
|
|
|
|
dpj = ((PlayerCharacter) attacker).getWeaponPower(); |
|
|
|
|
|
|
|
|
|
if (target.getObjectType() == mbEnums.GameObjectType.Building) |
|
|
|
|
hitChance = 100; |
|
|
|
|
if (dpj != null) { |
|
|
|
|
dpj.attack(target, attackRange); |
|
|
|
|
|
|
|
|
|
int passiveAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD)); |
|
|
|
|
if (attacker.charItemManager.getEquipped().get(slot) != null) { |
|
|
|
|
passiveAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, null, true); |
|
|
|
|
} |
|
|
|
|
if (dpj.getPower() != null && (dpj.getPowerToken() == -1851459567 || dpj.getPowerToken() == -1851489518)) |
|
|
|
|
((PlayerCharacter) attacker).setWeaponPower(dpj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ThreadLocalRandom.current().nextInt(100) > hitChance) { |
|
|
|
|
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim); |
|
|
|
|
// take stamina away from attacker
|
|
|
|
|
|
|
|
|
|
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter) |
|
|
|
|
DispatchMessage.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); |
|
|
|
|
else |
|
|
|
|
DispatchMessage.sendToAllInRange(attacker, msg); |
|
|
|
|
if (weapon != null) { |
|
|
|
|
float stam = weapon.template.item_wt / 3f; |
|
|
|
|
stam = (stam < 1) ? 1 : stam; |
|
|
|
|
attacker.modifyStamina(-(stam), attacker, true); |
|
|
|
|
} else |
|
|
|
|
attacker.modifyStamina(-0.5f, attacker, true); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
//cancel things that are cancelled by an attack
|
|
|
|
|
|
|
|
|
|
//calculate passive chances only if target is AbstractCharacter
|
|
|
|
|
attacker.cancelOnAttackSwing(); |
|
|
|
|
|
|
|
|
|
if (EnumSet.of(mbEnums.GameObjectType.PlayerCharacter, mbEnums.GameObjectType.NPC, mbEnums.GameObjectType.Mob).contains(target.getObjectType())) { |
|
|
|
|
mbEnums.PassiveType passiveType = mbEnums.PassiveType.None; |
|
|
|
|
int hitRoll = ThreadLocalRandom.current().nextInt(100); |
|
|
|
|
//declare relevant variables
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
int min = attacker.minDamageHandOne; |
|
|
|
|
int max = attacker.maxDamageHandOne; |
|
|
|
|
int atr = attacker.atrHandOne; |
|
|
|
|
|
|
|
|
|
// Passive chance clamped at 75
|
|
|
|
|
//get the proper stats based on which slot is attacking
|
|
|
|
|
|
|
|
|
|
dodgeChance = Math.max(0, Math.min(75, dodgeChance)); |
|
|
|
|
blockChance = Math.max(0, Math.min(75, blockChance)); |
|
|
|
|
parryChance = Math.max(0, Math.min(75, parryChance)); |
|
|
|
|
if (slot == mbEnums.EquipSlotType.LHELD) { |
|
|
|
|
min = attacker.minDamageHandTwo; |
|
|
|
|
max = attacker.maxDamageHandTwo; |
|
|
|
|
atr = attacker.atrHandTwo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (hitRoll < dodgeChance) |
|
|
|
|
passiveType = mbEnums.PassiveType.Dodge; |
|
|
|
|
else if (hitRoll < blockChance) |
|
|
|
|
passiveType = mbEnums.PassiveType.Block; |
|
|
|
|
else if (hitRoll < parryChance) |
|
|
|
|
passiveType = mbEnums.PassiveType.Parry; |
|
|
|
|
int def = 0; |
|
|
|
|
|
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target)) |
|
|
|
|
def = ((AbstractCharacter) target).defenseRating; |
|
|
|
|
|
|
|
|
|
if (passiveType.equals(mbEnums.PassiveType.None) == false) { |
|
|
|
|
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value); |
|
|
|
|
//calculate hit chance based off ATR and DEF
|
|
|
|
|
|
|
|
|
|
int hitChance; |
|
|
|
|
if (def == 0) |
|
|
|
|
def = 1; |
|
|
|
|
float dif = atr / def; |
|
|
|
|
|
|
|
|
|
if (dif <= 0.8f) |
|
|
|
|
hitChance = 4; |
|
|
|
|
else |
|
|
|
|
hitChance = ((int) (450 * (dif - 0.8f)) + 4); |
|
|
|
|
|
|
|
|
|
if (target.getObjectType() == mbEnums.GameObjectType.Building) |
|
|
|
|
hitChance = 100; |
|
|
|
|
|
|
|
|
|
int passiveAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD)); |
|
|
|
|
if (attacker.charItemManager.getEquipped().get(slot) != null) { |
|
|
|
|
passiveAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, null, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ThreadLocalRandom.current().nextInt(100) > hitChance) { |
|
|
|
|
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim); |
|
|
|
|
|
|
|
|
|
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter) |
|
|
|
|
DispatchMessage.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); |
|
|
|
|
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; |
|
|
|
|
//calculate passive chances only if target is AbstractCharacter
|
|
|
|
|
|
|
|
|
|
//get the damage type
|
|
|
|
|
if (EnumSet.of(mbEnums.GameObjectType.PlayerCharacter, mbEnums.GameObjectType.NPC, mbEnums.GameObjectType.Mob).contains(target.getObjectType())) { |
|
|
|
|
mbEnums.PassiveType passiveType = mbEnums.PassiveType.None; |
|
|
|
|
int hitRoll = ThreadLocalRandom.current().nextInt(100); |
|
|
|
|
|
|
|
|
|
mbEnums.DamageType damageType; |
|
|
|
|
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 (attacker.charItemManager.getEquipped().get(slot) == null) { |
|
|
|
|
damageType = mbEnums.DamageType.CRUSHING; |
|
|
|
|
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) |
|
|
|
|
if (((Mob) attacker).isSiege()) |
|
|
|
|
damageType = mbEnums.DamageType.SIEGE; |
|
|
|
|
} else { |
|
|
|
|
damageType = (mbEnums.DamageType) attacker.charItemManager.getEquipped().get(slot).template.item_weapon_damage.keySet().toArray()[0]; |
|
|
|
|
} |
|
|
|
|
// Passive chance clamped at 75
|
|
|
|
|
|
|
|
|
|
//get resists
|
|
|
|
|
dodgeChance = Math.max(0, Math.min(75, dodgeChance)); |
|
|
|
|
blockChance = Math.max(0, Math.min(75, blockChance)); |
|
|
|
|
parryChance = Math.max(0, Math.min(75, parryChance)); |
|
|
|
|
|
|
|
|
|
Resists resists; |
|
|
|
|
if (hitRoll < dodgeChance) |
|
|
|
|
passiveType = mbEnums.PassiveType.Dodge; |
|
|
|
|
else if (hitRoll < blockChance) |
|
|
|
|
passiveType = mbEnums.PassiveType.Block; |
|
|
|
|
else if (hitRoll < parryChance) |
|
|
|
|
passiveType = mbEnums.PassiveType.Parry; |
|
|
|
|
|
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target) == false) |
|
|
|
|
resists = ((Building) target).getResists(); //this is a building
|
|
|
|
|
else |
|
|
|
|
resists = ((AbstractCharacter) target).getResists(); //this is a character
|
|
|
|
|
|
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target)) { |
|
|
|
|
AbstractCharacter absTarget = (AbstractCharacter) target; |
|
|
|
|
if (passiveType.equals(mbEnums.PassiveType.None) == false) { |
|
|
|
|
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value); |
|
|
|
|
|
|
|
|
|
//check damage shields
|
|
|
|
|
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter) |
|
|
|
|
DispatchMessage.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); |
|
|
|
|
else |
|
|
|
|
DispatchMessage.sendToAllInRange(attacker, msg); |
|
|
|
|
|
|
|
|
|
PlayerBonuses bonuses = absTarget.getBonuses(); |
|
|
|
|
//calculate next allowed attack and update the timestamp
|
|
|
|
|
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); |
|
|
|
|
|
|
|
|
|
if (bonuses != null) { |
|
|
|
|
//handle auto attack job creation
|
|
|
|
|
ConcurrentHashMap<String, JobContainer> timers = attacker.getTimers(); |
|
|
|
|
|
|
|
|
|
ConcurrentHashMap<AbstractEffectModifier, DamageShield> damageShields = bonuses.getDamageShields(); |
|
|
|
|
float total = 0; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (DamageShield ds : damageShields.values()) { |
|
|
|
|
//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()); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
//get the damage type
|
|
|
|
|
|
|
|
|
|
//get amount to damage back
|
|
|
|
|
mbEnums.DamageType damageType; |
|
|
|
|
|
|
|
|
|
float amount; |
|
|
|
|
if (attacker.charItemManager.getEquipped().get(slot) == null) { |
|
|
|
|
damageType = mbEnums.DamageType.CRUSHING; |
|
|
|
|
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) |
|
|
|
|
if (((Mob) attacker).isSiege()) |
|
|
|
|
damageType = mbEnums.DamageType.SIEGE; |
|
|
|
|
} else { |
|
|
|
|
damageType = (mbEnums.DamageType) attacker.charItemManager.getEquipped().get(slot).template.item_weapon_damage.keySet().toArray()[0]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ds.usePercent()) |
|
|
|
|
amount = damage * ds.getAmount() / 100; |
|
|
|
|
else |
|
|
|
|
amount = ds.getAmount(); |
|
|
|
|
//get resists
|
|
|
|
|
|
|
|
|
|
//get resisted damage for damagetype
|
|
|
|
|
Resists resists; |
|
|
|
|
|
|
|
|
|
if (resists != null) |
|
|
|
|
amount = resists.getResistedDamage(absTarget, attacker, ds.getDamageType(), amount, 0); |
|
|
|
|
total += amount; |
|
|
|
|
} |
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target) == false) |
|
|
|
|
resists = ((Building) target).getResists(); //this is a building
|
|
|
|
|
else |
|
|
|
|
resists = ((AbstractCharacter) target).getResists(); //this is a character
|
|
|
|
|
|
|
|
|
|
if (total > 0) { |
|
|
|
|
//apply Damage back
|
|
|
|
|
attacker.modifyHealth(-total, absTarget, true); |
|
|
|
|
TargetedActionMsg cmm = new TargetedActionMsg(attacker, attacker, total, 0); |
|
|
|
|
DispatchMessage.sendToAllInRange(target, cmm); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target)) { |
|
|
|
|
AbstractCharacter absTarget = (AbstractCharacter) target; |
|
|
|
|
|
|
|
|
|
if (resists != null) { |
|
|
|
|
//check damage shields
|
|
|
|
|
|
|
|
|
|
//check for damage type immunities
|
|
|
|
|
PlayerBonuses bonuses = absTarget.getBonuses(); |
|
|
|
|
|
|
|
|
|
if (resists.immuneTo(damageType)) |
|
|
|
|
return; |
|
|
|
|
if (bonuses != null) { |
|
|
|
|
|
|
|
|
|
//calculate resisted damage including fortitude
|
|
|
|
|
ConcurrentHashMap<AbstractEffectModifier, DamageShield> damageShields = bonuses.getDamageShields(); |
|
|
|
|
float total = 0; |
|
|
|
|
|
|
|
|
|
damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (DamageShield ds : damageShields.values()) { |
|
|
|
|
|
|
|
|
|
//remove damage from target health
|
|
|
|
|
//get amount to damage back
|
|
|
|
|
|
|
|
|
|
if (damage > 0) { |
|
|
|
|
float amount; |
|
|
|
|
|
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target)) |
|
|
|
|
((AbstractCharacter) target).modifyHealth(-damage, attacker, true); |
|
|
|
|
else |
|
|
|
|
((Building) target).setCurrentHitPoints(target.getCurrentHitpoints() - damage); |
|
|
|
|
if (ds.usePercent()) |
|
|
|
|
amount = damage * ds.getAmount() / 100; |
|
|
|
|
else |
|
|
|
|
amount = ds.getAmount(); |
|
|
|
|
|
|
|
|
|
int attackAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD)); |
|
|
|
|
if (attacker.charItemManager.getEquipped().get(slot) != null) { |
|
|
|
|
attackAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, null, slot.equals(mbEnums.EquipSlotType.RHELD)); |
|
|
|
|
} |
|
|
|
|
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim); |
|
|
|
|
DispatchMessage.sendToAllInRange(target, cmm); |
|
|
|
|
} |
|
|
|
|
DeferredPowerJob dpj = null; |
|
|
|
|
//get resisted damage for damagetype
|
|
|
|
|
|
|
|
|
|
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) { |
|
|
|
|
if (resists != null) |
|
|
|
|
amount = resists.getResistedDamage(absTarget, attacker, ds.getDamageType(), amount, 0); |
|
|
|
|
total += amount; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dpj = ((PlayerCharacter) attacker).getWeaponPower(); |
|
|
|
|
if (total > 0) { |
|
|
|
|
//apply Damage back
|
|
|
|
|
attacker.modifyHealth(-total, absTarget, true); |
|
|
|
|
TargetedActionMsg cmm = new TargetedActionMsg(attacker, attacker, total, 0); |
|
|
|
|
DispatchMessage.sendToAllInRange(target, cmm); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (dpj != null) { |
|
|
|
|
dpj.attack(target, attackRange); |
|
|
|
|
if (resists != null) { |
|
|
|
|
|
|
|
|
|
if (dpj.getPower() != null && (dpj.getPowerToken() == -1851459567 || dpj.getPowerToken() == -1851489518)) |
|
|
|
|
((PlayerCharacter) attacker).setWeaponPower(dpj); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//calculate next allowed attack and update the timestamp
|
|
|
|
|
//check for damage type immunities
|
|
|
|
|
|
|
|
|
|
long delay = 20 * 100; |
|
|
|
|
if (resists.immuneTo(damageType)) { |
|
|
|
|
//calculate next allowed attack and update the timestamp
|
|
|
|
|
attacker.getTimestamps().put("Attack" + slot.name(), System.currentTimeMillis() + delay); |
|
|
|
|
|
|
|
|
|
if (weapon != null) { |
|
|
|
|
//handle auto attack job creation
|
|
|
|
|
ConcurrentHashMap<String, JobContainer> timers = attacker.getTimers(); |
|
|
|
|
|
|
|
|
|
int wepSpeed = (int) (weapon.template.item_weapon_wepspeed); |
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
if (weapon.getBonusPercent(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None) != 0f) //add weapon speed bonus
|
|
|
|
|
wepSpeed *= (1 + weapon.getBonus(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None)); |
|
|
|
|
damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
//remove damage from target health
|
|
|
|
|
|
|
|
|
|
if (wepSpeed < 10) |
|
|
|
|
wepSpeed = 10; //Old was 10, but it can be reached lower with legit buffs,effects.
|
|
|
|
|
if (damage > 0) { |
|
|
|
|
|
|
|
|
|
delay = wepSpeed * 100; |
|
|
|
|
} |
|
|
|
|
if (AbstractCharacter.IsAbstractCharacter(target)) |
|
|
|
|
((AbstractCharacter) target).modifyHealth(-damage, attacker, true); |
|
|
|
|
else |
|
|
|
|
((Building) target).setCurrentHitPoints(target.getCurrentHitpoints() - damage); |
|
|
|
|
|
|
|
|
|
int attackAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD)); |
|
|
|
|
if (attacker.charItemManager.getEquipped().get(slot) != null) { |
|
|
|
|
attackAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, null, slot.equals(mbEnums.EquipSlotType.RHELD)); |
|
|
|
|
} |
|
|
|
|
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim); |
|
|
|
|
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) { |
|
|
|
|