Compare commits

...

19 Commits

Author SHA1 Message Date
FatBoy c0cd365c1d add 4 to attack range to match clients stopping short 2024-06-06 19:59:40 -05:00
FatBoy ee5620036d add 4 to attack range to match clients stopping short 2024-06-06 19:52:35 -05:00
FatBoy 8ff06b1200 guild lookup no lonkger retursn null, return ErrantGuild 2024-06-04 21:15:45 -05:00
FatBoy a348056c86 check for null target when cancelling jobs 2024-06-04 21:09:45 -05:00
FatBoy 1c10f8a872 pet damage fixed 2024-06-04 20:47:08 -05:00
FatBoy 4f28fefbc2 mobs no longer try to cancel auto-attack jobs they dont have 2024-06-04 20:39:15 -05:00
FatBoy 9ff7e07545 can no longer repledge to noob island after level 20 2024-06-04 20:33:06 -05:00
FatBoy d5809fc4b1 attack delay catching 2024-06-03 21:49:01 -05:00
FatBoy 0c00832264 attack delay catching 2024-06-03 21:46:16 -05:00
FatBoy 300452d2d8 attack delay catching 2024-06-03 21:42:08 -05:00
FatBoy 9a9ea99bc7 attack delay catching 2024-06-03 21:35:37 -05:00
FatBoy d9ab1032f4 attack delay catching 2024-06-03 21:08:40 -05:00
FatBoy c2ea4424cf attack delay catching 2024-06-03 20:56:25 -05:00
FatBoy b22c07b000 attack speed pulled from cached value 2024-06-03 20:44:29 -05:00
FatBoy 8e70e0597e rentrant lock on modify health 2024-06-03 20:37:03 -05:00
FatBoy cf58e7b984 rentrant lock on combat 2024-06-03 20:17:04 -05:00
FatBoy ba81a24622 combat manage null check 2024-06-01 12:33:05 -05:00
FatBoy 007299eae5 null check in mobAI 2024-06-01 12:31:06 -05:00
FatBoy 5f92345d3e loreInore category of spells addition 2024-06-01 12:29:25 -05:00
9 changed files with 389 additions and 318 deletions
+334 -303
View File
@@ -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;
@@ -48,7 +47,7 @@ public enum CombatManager {
public static final int COMBAT_PARRY_ANIMATION = 299;
public static final int COMBAT_DODGE_ANIMATION = 300;
public static void combatCycle(AbstractCharacter attacker, AbstractWorldObject target) {
public static void combatCycle(AbstractCharacter attacker, AbstractWorldObject target, long addedDelay) {
//early exit checks
@@ -79,398 +78,413 @@ 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.RHELD,addedDelay);
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter))
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD);
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD,addedDelay);
return;
}
if (mainWeapon != null && offWeapon == null) {
//swing right hand only
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD);
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD,addedDelay);
return;
}
if (mainWeapon == null && offWeapon != null && !offWeapon.template.item_skill_used.equals("Block")) {
//swing left hand only
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD);
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD,addedDelay);
return;
}
if (mainWeapon == null && offWeapon != null && offWeapon.template.item_skill_used.equals("Block")) {
//no weapon equipped with a shield, punch with one hand
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD);
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD,addedDelay);
return;
}
if (mainWeapon != null && offWeapon != null && offWeapon.template.item_skill_used.equals("Block")) {
//one weapon equipped with a shield, swing with one hand
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD);
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD,addedDelay);
return;
}
if (mainWeapon != null && offWeapon != null && !offWeapon.template.item_skill_used.equals("Block")) {
//two weapons equipped, swing both hands
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD);
processAttack(attacker, target, mbEnums.EquipSlotType.RHELD,addedDelay);
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter))
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD);
processAttack(attacker, target, mbEnums.EquipSlotType.LHELD,addedDelay);
}
}
public static void processAttack(AbstractCharacter attacker, AbstractWorldObject target, mbEnums.EquipSlotType slot) {
public static void processAttack(AbstractCharacter attacker, AbstractWorldObject target, mbEnums.EquipSlotType slot, long addedDelay) {
if (slot == null || target == null || attacker == null)
return;
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();
PlayerBonuses bonus = attacker.getBonuses();
float rangeMod = 1.0f;
float attackRange = MBServerStatics.NO_WEAPON_RANGE;
float rangeMod = 1.0f;
float attackRange = MBServerStatics.NO_WEAPON_RANGE;
Item weapon = attacker.charItemManager.getEquipped(slot);
Item weapon = attacker.charItemManager.getEquipped(slot);
if (weapon != null) {
if (bonus != null)
rangeMod += bonus.getFloatPercentAll(mbEnums.ModType.WeaponRange, mbEnums.SourceType.None);
if (weapon != null) {
if (bonus != null)
rangeMod += bonus.getFloatPercentAll(mbEnums.ModType.WeaponRange, mbEnums.SourceType.None);
attackRange += weapon.template.item_weapon_max_range * rangeMod;
}
attackRange += weapon.template.item_weapon_max_range * rangeMod;
}
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
if (((Mob) attacker).isSiege())
attackRange = 300;
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
if (((Mob) attacker).isSiege())
attackRange = 300;
float distanceSquared = attacker.loc.distanceSquared(target.loc);
float distanceSquared = attacker.loc.distanceSquared(target.loc);
boolean inRange = false;
if (AbstractCharacter.IsAbstractCharacter(target)) {
attackRange += ((AbstractCharacter)target).calcHitBox();
} else {
}
if(attackRange > 15 && attacker.isMoving()){
//cannot shoot bow while moving;
return;
}
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:
if(attackRange > 15){
float rangeSquared = (attackRange + target.getBounds().getHalfExtents().x) * (attackRange + target.getBounds().getHalfExtents().x);
//float distanceSquared = attacker.loc.distanceSquared(target.loc);
if(distanceSquared < rangeSquared) {
inRange = true;
break;
}
}else {
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 * 100L;
}
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
((Mob) attacker).nextAttackTime = System.currentTimeMillis() + delay;
if (inRange) {
//handle retaliate
boolean inRange = false;
if (AbstractCharacter.IsAbstractCharacter(target)) {
if (((AbstractCharacter) target).combatTarget == null || !((AbstractCharacter) target).combatTarget.isAlive()) {
((AbstractCharacter) target).combatTarget = attacker;
if (target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat())
combatCycle((AbstractCharacter) target, attacker);
}
attackRange += ((AbstractCharacter) target).calcHitBox();
} else {
//need to handle building attacks range calculations here
}
// take stamina away from attacker if its not a mob
if (weapon != null && !attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) {
//check if Out of Stamina
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
if (attacker.getStamina() < (weapon.template.item_wt / 3f)) {
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
return;
}
}
float stam = weapon.template.item_wt / 3f;
stam = (stam < 1) ? 1 : stam;
attacker.modifyStamina(-(stam), attacker, true);
} else
attacker.modifyStamina(1, attacker, true);
attackRange += 4; // need to add 4 to the attack range to offset where the client stops short of legitimate range
//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 == mbEnums.EquipSlotType.LHELD) {
min = attacker.minDamageHandTwo;
max = attacker.maxDamageHandTwo;
atr = attacker.atrHandTwo;
}
//apply weapon powers before early exit for miss or passives
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);
}
}
int def = 0;
if (AbstractCharacter.IsAbstractCharacter(target))
def = ((AbstractCharacter) target).defenseRating;
//calculate hit chance based off ATR and DEF
int hitChance;
if (def == 0)
def = 1;
float dif = atr * 1f / 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 = getPassiveAnimation(mbEnums.PassiveType.None); // checking for a miss due to ATR vs Def
if (ThreadLocalRandom.current().nextInt(100) > hitChance) {
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim);
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchManager.sendToAllInRange(attacker, msg);
//we need to send the animation even if the attacker misses
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) 0, getSwingAnimation(weapon.template,null,slot));
DispatchManager.sendToAllInRange(target, cmm);
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
float distance = target.loc.distance(attacker.loc);
if (attackRange > 25 && attacker.isMoving()) {
//cannot shoot bow while moving;
return;
}
//calculate passive chances only if target is AbstractCharacter
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:
if (attackRange > 15) {
float rangeSquared = (attackRange + target.getBounds().getHalfExtents().x) * (attackRange + target.getBounds().getHalfExtents().x);
//float distanceSquared = attacker.loc.distanceSquared(target.loc);
if (distanceSquared < rangeSquared) {
inRange = true;
break;
}
} else {
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;
}
}
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);
//get delay for the auto attack job
long delay = 5000;
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 (weapon != null) {
// Passive chance clamped at 75
// int wepSpeed = (int) (weapon.template.item_weapon_wepspeed);
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 (weapon.getBonusPercent(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None) != 0f) //add weapon speed bonus
// wepSpeed *= (1 + weapon.getBonus(mbEnums.ModType.WeaponSpeed, mbEnums.SourceType.None));
if (hitRoll < dodgeChance)
passiveType = mbEnums.PassiveType.Dodge;
else if (hitRoll < blockChance)
passiveType = mbEnums.PassiveType.Block;
else if (hitRoll < parryChance)
passiveType = mbEnums.PassiveType.Parry;
// 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 * 100L;
//}
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)){
if(slot.equals(mbEnums.EquipSlotType.RHELD)){
delay = (long)(attacker.speedHandOne * 100L);
}else{
delay = (long)(attacker.speedHandTwo * 100L);
}
}
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
((Mob) attacker).nextAttackTime = System.currentTimeMillis() + delay;
delay += addedDelay;
if (inRange) {
//handle retaliate
if (AbstractCharacter.IsAbstractCharacter(target)) {
if (((AbstractCharacter) target).combatTarget == null || !((AbstractCharacter) target).combatTarget.isAlive()) {
((AbstractCharacter) target).combatTarget = attacker;
if (target.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) && ((AbstractCharacter) target).isCombat())
combatCycle((AbstractCharacter) target, attacker,0);
}
}
// take stamina away from attacker if its not a mob
if (weapon != null && !attacker.getObjectType().equals(mbEnums.GameObjectType.Mob)) {
//check if Out of Stamina
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
if (attacker.getStamina() < (weapon.template.item_wt / 3f)) {
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
return;
}
}
float stam = weapon.template.item_wt / 3f;
stam = (stam < 1) ? 1 : stam;
attacker.modifyStamina(-(stam), attacker, true);
} else
attacker.modifyStamina(1, 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 == mbEnums.EquipSlotType.LHELD) {
min = attacker.minDamageHandTwo;
max = attacker.maxDamageHandTwo;
atr = attacker.atrHandTwo;
}
//apply weapon powers before early exit for miss or passives
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);
}
}
if (!passiveType.equals(mbEnums.PassiveType.None)) {
passiveAnim = getPassiveAnimation(passiveType);
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value);
int def = 0;
if (AbstractCharacter.IsAbstractCharacter(target))
def = ((AbstractCharacter) target).defenseRating;
//calculate hit chance based off ATR and DEF
int hitChance;
if (def == 0)
def = 1;
float dif = atr * 1f / 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 = getPassiveAnimation(mbEnums.PassiveType.None); // checking for a miss due to ATR vs Def
if (ThreadLocalRandom.current().nextInt(100) > hitChance) {
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim);
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
else
DispatchManager.sendToAllInRange(attacker, msg);
//we need to send the animation even if the attacker misses
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) 0, getSwingAnimation(weapon.template,null,slot));
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) 0, getSwingAnimation(weapon.template, null, slot));
DispatchManager.sendToAllInRange(target, cmm);
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
return;
}
}
//calculate the base damage
int damage = ThreadLocalRandom.current().nextInt(min, max + 1);
if (damage == 0) {
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
return;
}
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob) && ((Mob)attacker).isPet())
calculatePetDamage(attacker);
//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))
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)) {
passiveAnim = getPassiveAnimation(passiveType);
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value);
//check damage shields
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
DispatchManager.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
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);
DispatchManager.sendToAllInRange(target, cmm);
}
}
if (resists != null) {
//check for damage type immunities
if (resists.immuneTo(damageType)) {
//set auto attack job
//we need to send the animation even if the attacker misses
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) 0, getSwingAnimation(weapon.template,null,slot));
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) 0, getSwingAnimation(weapon.template, null, slot));
DispatchManager.sendToAllInRange(target, cmm);
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
return;
}
//calculate resisted damage including fortitude
damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0);
}
}
//remove damage from target health
//calculate the base damage
int damage = ThreadLocalRandom.current().nextInt(min, max + 1);
if (damage == 0) {
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
return;
}
if (attacker.getObjectType().equals(mbEnums.GameObjectType.Mob) && ((Mob) attacker).isPet())
calculatePetDamage(attacker);
if (damage > 0) {
//get the damage type
if (AbstractCharacter.IsAbstractCharacter(target))
((AbstractCharacter) target).modifyHealth(-damage, attacker, true);
mbEnums.DamageType damageType;
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];
}
//get resists
Resists resists;
if (!AbstractCharacter.IsAbstractCharacter(target))
resists = ((Building) target).getResists(); //this is a building
else
((Building) target).modifyHealth(-damage, attacker);
resists = ((AbstractCharacter) target).getResists(); //this is a character
int attackAnim = getSwingAnimation(null, null, slot);
if (attacker.charItemManager.getEquipped().get(slot) != null) {
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
DeferredPowerJob weaponPower = ((PlayerCharacter) attacker).getWeaponPower();
attackAnim = getSwingAnimation(weapon.template, weaponPower, slot);
} else {
attackAnim = getSwingAnimation(weapon.template, null, slot);
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);
DispatchManager.sendToAllInRange(target, cmm);
}
}
if (resists != null) {
//check for damage type immunities
if (resists.immuneTo(damageType)) {
//set auto attack job
//we need to send the animation even if the attacker misses
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) 0, getSwingAnimation(weapon.template, null, slot));
DispatchManager.sendToAllInRange(target, cmm);
setAutoAttackJob(attacker, slot, delay);
return;
}
//calculate resisted damage including fortitude
if(attacker.getObjectType().equals(mbEnums.GameObjectType.Mob))
if(((Mob)attacker).isPet())
damage *= attacker.level * 0.1f;
damage = (int) resists.getResistedDamage(attacker, (AbstractCharacter) target, damageType, damage, 0);
}
}
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim);
DispatchManager.sendToAllInRange(target, cmm);
//remove damage from target health
if (damage > 0) {
if (AbstractCharacter.IsAbstractCharacter(target))
((AbstractCharacter) target).modifyHealth(-damage, attacker, true);
else
((Building) target).modifyHealth(-damage, attacker);
int attackAnim = getSwingAnimation(null, null, slot);
if (attacker.charItemManager.getEquipped().get(slot) != null) {
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
DeferredPowerJob weaponPower = ((PlayerCharacter) attacker).getWeaponPower();
attackAnim = getSwingAnimation(weapon.template, weaponPower, slot);
} else {
attackAnim = getSwingAnimation(weapon.template, null, slot);
}
}
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim);
DispatchManager.sendToAllInRange(target, cmm);
}
}
//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();
}
//set auto attack job
setAutoAttackJob(attacker, slot, delay);
}
public static void toggleCombat(boolean toggle, ClientConnection origin) {
@@ -604,6 +618,9 @@ public enum CombatManager {
public static void setAutoAttackJob(AbstractCharacter attacker, mbEnums.EquipSlotType slot, long delay) {
//calculate next allowed attack and update the timestamp
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) == false)
return; //mobs dont submit auto attack jobs
if(attacker.getTimestamps().containsKey("Attack" + slot.name()) && attacker.getTimestamps().get("Attack" + slot.name()) > System.currentTimeMillis())
return;
@@ -613,7 +630,7 @@ public enum CombatManager {
ConcurrentHashMap<String, JobContainer> timers = attacker.getTimers();
if (timers != null) {
AttackJob aj = new AttackJob(attacker, slot.ordinal(), true);
AttackJob aj = new AttackJob(attacker, slot.ordinal(), true, attacker.getCombatTarget());
JobContainer job;
job = JobScheduler.getInstance().scheduleJob(aj, (System.currentTimeMillis() + delay)); // offset 1 millisecond so no overlap issue
timers.put("Attack" + slot.name(), job);
@@ -621,7 +638,22 @@ 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) {
if(attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter) == false)
return;
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;
@@ -633,7 +665,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 -1
View File
@@ -172,7 +172,7 @@ public enum PowersManager {
public static void usePower(final PerformActionMsg msg, ClientConnection origin,
boolean sendCastToSelf) {
if (ConfigManager.MB_RULESET.getValue().equals("LORE")) {
if (ConfigManager.MB_RULESET.getValue().equals("LORE") && getPowerByToken(msg.getPowerUsedID()).ignoreLore() == false) {
PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerUsedID());
PlayerCharacter caster = origin.getPlayerCharacter();
PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID());
+7 -2
View File
@@ -12,6 +12,7 @@ package engine.jobs;
import engine.gameManager.CombatManager;
import engine.job.AbstractJob;
import engine.objects.AbstractCharacter;
import engine.objects.AbstractWorldObject;
public class AttackJob extends AbstractJob {
@@ -19,16 +20,20 @@ public class AttackJob extends AbstractJob {
private final int slot;
private final boolean success;
public AttackJob(AbstractCharacter source, int slot, boolean success) {
public final AbstractWorldObject target;
public AttackJob(AbstractCharacter source, int slot, boolean success, AbstractWorldObject target) {
super();
this.source = source;
this.slot = slot;
this.success = success;
this.target = target;
}
@Override
protected void doJob() {
CombatManager.combatCycle(this.source, this.source.combatTarget);
CombatManager.combatCycle(this.source,target,0);
}
public boolean success() {
+4 -4
View File
@@ -109,7 +109,7 @@ public class MobAI {
return;
}
if (mob.behaviourType.callsForHelp)
if (mob.behaviourType != null && mob.behaviourType.callsForHelp)
mobCallForHelp(mob);
if (!MovementUtilities.inRangeDropAggro(mob, target)) {
@@ -125,7 +125,7 @@ public class MobAI {
if (mob.isMoving() && mob.getRange() > 20)
return;
CombatManager.combatCycle(mob, target);
CombatManager.combatCycle(mob, target,0);
}
if (target.getPet() != null)
@@ -159,7 +159,7 @@ public class MobAI {
MovementManager.sendRWSSMsg(mob);
CombatManager.combatCycle(mob, target);
CombatManager.combatCycle(mob, target,0);
if (mob.isSiege()) {
PowerProjectileMsg ppm = new PowerProjectileMsg(mob, target);
@@ -183,7 +183,7 @@ public class MobAI {
//no weapons, default mob attack speed 3 seconds.
CombatManager.combatCycle(mob, target);
CombatManager.combatCycle(mob, target,0);
} catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackMob" + " " + e.getMessage());
@@ -2,6 +2,7 @@ package engine.net.client.handlers;
import engine.gameManager.BuildingManager;
import engine.gameManager.CombatManager;
import engine.jobs.AttackJob;
import engine.mbEnums;
import engine.net.client.ClientConnection;
import engine.net.client.msg.AttackCmdMsg;
@@ -82,7 +83,29 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
if (playerCharacter.isSit())
CombatManager.toggleSit(false, origin);
CombatManager.combatCycle(playerCharacter, target);
long addedDelay = 0;
//check if we are changing targets, cancel outstanding jobs if so
if (playerCharacter.getTimers().containsKey("Attack" + mbEnums.EquipSlotType.RHELD)) {
AttackJob ajR = ((AttackJob)playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.RHELD).getJob());
if(ajR.target != null && !ajR.target.equals(target)){
playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.RHELD).cancelJob();
addedDelay = ajR.getStopTime() - System.currentTimeMillis();
}else{
return true;
}
}
if (playerCharacter.getTimers().containsKey("Attack" + mbEnums.EquipSlotType.LHELD)) {
AttackJob ajL = ((AttackJob)playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.LHELD).getJob());
if(ajL.target != null && !ajL.target.equals(target)){
playerCharacter.getTimers().get("Attack" + mbEnums.EquipSlotType.LHELD).cancelJob();
addedDelay = ajL.getStopTime() - System.currentTimeMillis();
}else{
return true;
}
}
CombatManager.combatCycle(playerCharacter, target, addedDelay);
return true;
}
+2 -1
View File
@@ -1787,7 +1787,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
final boolean fromCost) {
try {
this.combatLock.writeLock().lock();
try {
boolean ready = this.healthLock.writeLock().tryLock(1, TimeUnit.SECONDS);
@@ -1852,6 +1852,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
return newHealth - oldHealth;
} finally {
this.healthLock.writeLock().unlock();
this.combatLock.writeLock().unlock();
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
@@ -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
+5 -6
View File
@@ -410,11 +410,10 @@ public class City extends AbstractWorldObject {
if(city.cityName.equals("Perdition") || city.cityName.equals("Bastion"))
continue; // cannot repledge to perdition or bastion
if (city.isNpc == 1 && city.getGuild().charter.canJoin(playerCharacter)) {
if(city.isNoobIsle == 1 && playerCharacter.level >= 21)
continue;
cities.add(city); // anyone of the same charter can teleport to a safehold of that charter
continue;
} else if (city.isNoobIsle == 1 && playerCharacter.level <= 20) {
cities.add(city); // everyone can go to noob island if they are under level 20
continue;
} else if (city.isOpen() && city.getTOL().rank > 4 && city.getGuild().charter.canJoin(playerCharacter))
if (!city.getTOL().reverseKOS) {
cities.add(city);//can repledge to any open ToL that player can fit into charter
@@ -640,17 +639,17 @@ public class City extends AbstractWorldObject {
public Guild getGuild() {
if (this.getTOL() == null)
return null;
return Guild.getErrantGuild();
if (this.isNpc == 1) {
if (this.getTOL().getOwner() == null)
return null;
return Guild.getErrantGuild();
return this.getTOL().getOwner().getGuild();
} else {
if (this.getTOL().getOwner() == null)
return null;
return Guild.getErrantGuild();
return this.getTOL().getOwner().getGuild();
}
}
+11
View File
@@ -633,4 +633,15 @@ public class PowersBase {
return description;
}
public boolean ignoreLore(){
switch(this.category){
case "HEAL":
case "BUFF":
case "DISPELL":
case "SUMMON":
return false;
}
return true;
}
}