add hitbox to abs vs abs range checks
This commit is contained in:
@@ -86,9 +86,9 @@ public enum CombatManager {
|
|||||||
|
|
||||||
// heck if character can even attack yet
|
// heck if character can even attack yet
|
||||||
|
|
||||||
if (attacker.getTimestamps().containsKey("Attack" + slot.name()))
|
//if (attacker.getTimestamps().containsKey("Attack" + slot.name()))
|
||||||
if (System.currentTimeMillis() < attacker.getTimestamps().get("Attack" + slot.name()))
|
// if (System.currentTimeMillis() < attacker.getTimestamps().get("Attack" + slot.name()))
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
// check if character is in range to attack target
|
// check if character is in range to attack target
|
||||||
|
|
||||||
@@ -114,19 +114,19 @@ public enum CombatManager {
|
|||||||
|
|
||||||
boolean inRange = false;
|
boolean inRange = false;
|
||||||
|
|
||||||
float attackerHitbox = attacker.calcHitBox();
|
attackRange += attacker.calcHitBox();
|
||||||
switch(target.getObjectType()){
|
switch(target.getObjectType()){
|
||||||
case PlayerCharacter:
|
case PlayerCharacter:
|
||||||
case Mob:
|
case Mob:
|
||||||
float targetHitbox = ((AbstractCharacter)target).calcHitBox();
|
attackRange += ((AbstractCharacter)target).calcHitBox();
|
||||||
if(distanceSquared < ((attackRange + attackerHitbox + targetHitbox) * 2))
|
if(distanceSquared < attackRange * 2)
|
||||||
inRange = true;
|
inRange = true;
|
||||||
break;
|
break;
|
||||||
case Building:
|
case Building:
|
||||||
float locX = target.loc.x - target.getBounds().getHalfExtents().x;
|
float locX = target.loc.x - target.getBounds().getHalfExtents().x;
|
||||||
float locZ = target.loc.z - target.getBounds().getHalfExtents().y;
|
float locZ = target.loc.z - target.getBounds().getHalfExtents().y;
|
||||||
float sizeX = (target.getBounds().getHalfExtents().x + attackRange + attackerHitbox) * 2;
|
float sizeX = (target.getBounds().getHalfExtents().x + attackRange) * 2;
|
||||||
float sizeZ = (target.getBounds().getHalfExtents().y + attackRange + attackerHitbox) * 2;
|
float sizeZ = (target.getBounds().getHalfExtents().y + attackRange) * 2;
|
||||||
Rectangle2D.Float rect = new Rectangle2D.Float(locX,locZ,sizeX,sizeZ);
|
Rectangle2D.Float rect = new Rectangle2D.Float(locX,locZ,sizeX,sizeZ);
|
||||||
if(rect.contains(new Point2D.Float(attacker.loc.x,attacker.loc.z)))
|
if(rect.contains(new Point2D.Float(attacker.loc.x,attacker.loc.z)))
|
||||||
inRange = true;
|
inRange = true;
|
||||||
@@ -134,98 +134,62 @@ public enum CombatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!inRange)
|
if (inRange) {
|
||||||
return;
|
|
||||||
|
|
||||||
// take stamina away from attacker
|
// take stamina away from attacker
|
||||||
|
|
||||||
if (weapon != null) {
|
if (weapon != null) {
|
||||||
float stam = weapon.template.item_wt / 3f;
|
float stam = weapon.template.item_wt / 3f;
|
||||||
stam = (stam < 1) ? 1 : stam;
|
stam = (stam < 1) ? 1 : stam;
|
||||||
attacker.modifyStamina(-(stam), attacker, true);
|
attacker.modifyStamina(-(stam), attacker, true);
|
||||||
} else
|
} else
|
||||||
attacker.modifyStamina(-0.5f, attacker, true);
|
attacker.modifyStamina(-0.5f, attacker, true);
|
||||||
|
|
||||||
//cancel things that are cancelled by an attack
|
//cancel things that are cancelled by an attack
|
||||||
|
|
||||||
attacker.cancelOnAttackSwing();
|
attacker.cancelOnAttackSwing();
|
||||||
|
|
||||||
//declare relevant variables
|
//declare relevant variables
|
||||||
|
|
||||||
int min = attacker.minDamageHandOne;
|
int min = attacker.minDamageHandOne;
|
||||||
int max = attacker.maxDamageHandOne;
|
int max = attacker.maxDamageHandOne;
|
||||||
int atr = attacker.atrHandOne;
|
int atr = attacker.atrHandOne;
|
||||||
|
|
||||||
//get the proper stats based on which slot is attacking
|
//get the proper stats based on which slot is attacking
|
||||||
|
|
||||||
if (slot == mbEnums.EquipSlotType.LHELD) {
|
if (slot == mbEnums.EquipSlotType.LHELD) {
|
||||||
min = attacker.minDamageHandTwo;
|
min = attacker.minDamageHandTwo;
|
||||||
max = attacker.maxDamageHandTwo;
|
max = attacker.maxDamageHandTwo;
|
||||||
atr = attacker.atrHandTwo;
|
atr = attacker.atrHandTwo;
|
||||||
}
|
}
|
||||||
|
|
||||||
int def = 0;
|
int def = 0;
|
||||||
|
|
||||||
if (AbstractCharacter.IsAbstractCharacter(target))
|
if (AbstractCharacter.IsAbstractCharacter(target))
|
||||||
def = ((AbstractCharacter) target).defenseRating;
|
def = ((AbstractCharacter) target).defenseRating;
|
||||||
|
|
||||||
//calculate hit chance based off ATR and DEF
|
//calculate hit chance based off ATR and DEF
|
||||||
|
|
||||||
int hitChance;
|
int hitChance;
|
||||||
if (def == 0)
|
if (def == 0)
|
||||||
def = 1;
|
def = 1;
|
||||||
float dif = atr / def;
|
float dif = atr / def;
|
||||||
|
|
||||||
if (dif <= 0.8f)
|
if (dif <= 0.8f)
|
||||||
hitChance = 4;
|
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
|
else
|
||||||
DispatchMessage.sendToAllInRange(attacker, msg);
|
hitChance = ((int) (450 * (dif - 0.8f)) + 4);
|
||||||
|
|
||||||
return;
|
if (target.getObjectType() == mbEnums.GameObjectType.Building)
|
||||||
}
|
hitChance = 100;
|
||||||
|
|
||||||
//calculate passive chances only if target is AbstractCharacter
|
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 (EnumSet.of(mbEnums.GameObjectType.PlayerCharacter, mbEnums.GameObjectType.NPC, mbEnums.GameObjectType.Mob).contains(target.getObjectType())) {
|
if (ThreadLocalRandom.current().nextInt(100) > hitChance) {
|
||||||
mbEnums.PassiveType passiveType = mbEnums.PassiveType.None;
|
TargetedActionMsg msg = new TargetedActionMsg(attacker, target, 0f, passiveAnim);
|
||||||
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);
|
|
||||||
|
|
||||||
// Passive chance clamped at 75
|
|
||||||
|
|
||||||
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 (hitRoll < dodgeChance)
|
|
||||||
passiveType = mbEnums.PassiveType.Dodge;
|
|
||||||
else if (hitRoll < blockChance)
|
|
||||||
passiveType = mbEnums.PassiveType.Block;
|
|
||||||
else if (hitRoll < parryChance)
|
|
||||||
passiveType = mbEnums.PassiveType.Parry;
|
|
||||||
|
|
||||||
|
|
||||||
if (passiveType.equals(mbEnums.PassiveType.None) == false) {
|
|
||||||
TargetedActionMsg msg = new TargetedActionMsg(attacker, passiveAnim, target, passiveType.value);
|
|
||||||
|
|
||||||
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
|
if (target.getObjectType() == mbEnums.GameObjectType.PlayerCharacter)
|
||||||
DispatchMessage.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
DispatchMessage.dispatchMsgToInterestArea(target, msg, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
||||||
@@ -234,113 +198,149 @@ public enum CombatManager {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//calculate the base damage
|
//calculate passive chances only if target is AbstractCharacter
|
||||||
int damage = ThreadLocalRandom.current().nextInt(min, max + 1);
|
|
||||||
if (damage == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
//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) {
|
// Passive chance clamped at 75
|
||||||
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
|
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)) {
|
if (passiveType.equals(mbEnums.PassiveType.None) == false) {
|
||||||
AbstractCharacter absTarget = (AbstractCharacter) target;
|
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);
|
||||||
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
|
else
|
||||||
amount = ds.getAmount();
|
DispatchMessage.sendToAllInRange(attacker, msg);
|
||||||
|
|
||||||
//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;
|
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)
|
||||||
|
return;
|
||||||
|
|
||||||
if (damage > 0) {
|
//get the damage type
|
||||||
|
|
||||||
if (AbstractCharacter.IsAbstractCharacter(target))
|
mbEnums.DamageType damageType;
|
||||||
((AbstractCharacter) target).modifyHealth(-damage, attacker, 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];
|
||||||
|
}
|
||||||
|
|
||||||
|
//get resists
|
||||||
|
|
||||||
|
Resists resists;
|
||||||
|
|
||||||
|
if (AbstractCharacter.IsAbstractCharacter(target) == false)
|
||||||
|
resists = ((Building) target).getResists(); //this is a building
|
||||||
else
|
else
|
||||||
((Building) target).setCurrentHitPoints(target.getCurrentHitpoints() - damage);
|
resists = ((AbstractCharacter) target).getResists(); //this is a character
|
||||||
|
|
||||||
int attackAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD));
|
if (AbstractCharacter.IsAbstractCharacter(target)) {
|
||||||
if (attacker.charItemManager.getEquipped().get(slot) != null) {
|
AbstractCharacter absTarget = (AbstractCharacter) target;
|
||||||
attackAnim = getSwingAnimation(attacker.charItemManager.getEquipped().get(slot).template, null, slot.equals(mbEnums.EquipSlotType.RHELD));
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TargetedActionMsg cmm = new TargetedActionMsg(attacker, target, (float) damage, attackAnim);
|
|
||||||
DispatchMessage.sendToAllInRange(target, cmm);
|
|
||||||
}
|
|
||||||
DeferredPowerJob dpj = null;
|
|
||||||
|
|
||||||
if (attacker.getObjectType().equals(mbEnums.GameObjectType.PlayerCharacter)) {
|
//remove damage from target health
|
||||||
|
|
||||||
dpj = ((PlayerCharacter) attacker).getWeaponPower();
|
if (damage > 0) {
|
||||||
|
|
||||||
if (dpj != null) {
|
if (AbstractCharacter.IsAbstractCharacter(target))
|
||||||
dpj.attack(target, attackRange);
|
((AbstractCharacter) target).modifyHealth(-damage, attacker, true);
|
||||||
|
else
|
||||||
|
((Building) target).setCurrentHitPoints(target.getCurrentHitpoints() - damage);
|
||||||
|
|
||||||
if (dpj.getPower() != null && (dpj.getPowerToken() == -1851459567 || dpj.getPowerToken() == -1851489518))
|
int attackAnim = getSwingAnimation(null, null, slot.equals(mbEnums.EquipSlotType.RHELD));
|
||||||
((PlayerCharacter) attacker).setWeaponPower(dpj);
|
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;
|
||||||
|
|
||||||
|
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
|
//calculate next allowed attack and update the timestamp
|
||||||
|
|||||||
Reference in New Issue
Block a user