Fix issues with double damage, double death messages, and other damage oddities.

Fixes #1450
This commit is contained in:
GJ 2013-09-12 11:52:34 -04:00
parent 44626c36a9
commit 58c7dcb705
5 changed files with 73 additions and 60 deletions

View File

@ -71,9 +71,9 @@ public class ArcheryManager extends SkillManager {
* @param defender The {@link Player} being affected by the ability * @param defender The {@link Player} being affected by the ability
* @param arrow The {@link Arrow} that was fired * @param arrow The {@link Arrow} that was fired
*/ */
public void daze(Player defender, Arrow arrow) { public double daze(Player defender, Arrow arrow) {
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel)) { if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel)) {
return; return 0;
} }
Location dazedLocation = defender.getLocation(); Location dazedLocation = defender.getLocation();
@ -90,7 +90,7 @@ public class ArcheryManager extends SkillManager {
getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed")); getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
} }
CombatUtils.dealDamage(defender, Archery.dazeModifier, DamageCause.PROJECTILE, arrow, mcMMOPlayer, SkillType.ARCHERY); return CombatUtils.callFakeDamageEvent(arrow, defender, DamageCause.PROJECTILE, Archery.dazeModifier);
} }
/** /**
@ -100,10 +100,10 @@ public class ArcheryManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event * @param damage The amount of damage initially dealt by the event
* @param arrow The {@link Arrow} that was fired * @param arrow The {@link Arrow} that was fired
*/ */
public void skillShot(LivingEntity target, double damage, Arrow arrow) { public double skillShot(LivingEntity target, double damage, Arrow arrow) {
double damageBonusPercent = Math.min(((getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage), Archery.skillShotMaxBonusPercentage); double damageBonusPercent = Math.min(((getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage), Archery.skillShotMaxBonusPercentage);
double archeryBonus = Math.min(damage * damageBonusPercent, Archery.skillShotMaxBonusDamage); double archeryBonus = Math.min(damage * damageBonusPercent, Archery.skillShotMaxBonusDamage);
CombatUtils.dealDamage(target, archeryBonus, DamageCause.PROJECTILE, arrow, mcMMOPlayer, SkillType.ARCHERY); return CombatUtils.callFakeDamageEvent(arrow, target, DamageCause.PROJECTILE, archeryBonus);
} }
} }

View File

@ -54,10 +54,10 @@ public class AxesManager extends SkillManager {
* *
* @param target The {@link LivingEntity} being affected by the ability * @param target The {@link LivingEntity} being affected by the ability
*/ */
public void axeMastery(LivingEntity target) { public double axeMastery(LivingEntity target) {
double axeBonus = Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus); double axeBonus = Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus);
CombatUtils.dealDamage(target, axeBonus, getPlayer(), mcMMOPlayer, SkillType.AXES); return CombatUtils.callFakeDamageEvent(getPlayer(), target, axeBonus);
} }
/** /**
@ -66,9 +66,9 @@ public class AxesManager extends SkillManager {
* @param target The {@link LivingEntity} being affected by the ability * @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event * @param damage The amount of damage initially dealt by the event
*/ */
public void criticalHit(LivingEntity target, double damage) { public double criticalHit(LivingEntity target, double damage) {
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) { if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) {
return; return 0;
} }
Player player = getPlayer(); Player player = getPlayer();
@ -84,7 +84,7 @@ public class AxesManager extends SkillManager {
damage = (damage * Axes.criticalHitPVEModifier) - damage; damage = (damage * Axes.criticalHitPVEModifier) - damage;
} }
CombatUtils.dealDamage(target, damage, player, mcMMOPlayer, SkillType.AXES); return CombatUtils.callFakeDamageEvent(player, target, damage);
} }
/** /**
@ -112,9 +112,9 @@ public class AxesManager extends SkillManager {
* *
* @param target The {@link LivingEntity} being affected by the ability * @param target The {@link LivingEntity} being affected by the ability
*/ */
public void greaterImpact(LivingEntity target) { public double greaterImpact(LivingEntity target) {
if (!(Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance()))) { if (!(Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance()))) {
return; return 0;
} }
Player player = getPlayer(); Player player = getPlayer();
@ -134,7 +134,7 @@ public class AxesManager extends SkillManager {
} }
} }
CombatUtils.dealDamage(target, Axes.greaterImpactBonusDamage, player, mcMMOPlayer, SkillType.AXES); return CombatUtils.callFakeDamageEvent(player, target, Axes.greaterImpactBonusDamage);
} }
/** /**

View File

@ -109,9 +109,9 @@ public class TamingManager extends SkillManager {
* @param damage The initial damage * @param damage The initial damage
* @param wolf The wolf using the ability * @param wolf The wolf using the ability
*/ */
public void gore(LivingEntity target, double damage, Wolf wolf) { public double gore(LivingEntity target, double damage, Wolf wolf) {
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Taming.goreMaxChance, Taming.goreMaxBonusLevel)) { if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Taming.goreMaxChance, Taming.goreMaxBonusLevel)) {
return; return 0;
} }
BleedTimerTask.add(target, Taming.goreBleedTicks); BleedTimerTask.add(target, Taming.goreBleedTicks);
@ -123,11 +123,11 @@ public class TamingManager extends SkillManager {
getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore")); getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));
damage = (damage * Taming.goreModifier) - damage; damage = (damage * Taming.goreModifier) - damage;
CombatUtils.dealDamage(target, damage, wolf, mcMMOPlayer, SkillType.TAMING); return CombatUtils.callFakeDamageEvent(wolf, target, damage);
} }
public void sharpenedClaws(LivingEntity target, Wolf wolf) { public double sharpenedClaws(LivingEntity target, Wolf wolf) {
CombatUtils.dealDamage(target, Taming.sharpenedClawsBonusDamage, wolf, mcMMOPlayer, SkillType.TAMING); return CombatUtils.callFakeDamageEvent(wolf, target, Taming.sharpenedClawsBonusDamage);
} }
/** /**

View File

@ -113,10 +113,10 @@ public class UnarmedManager extends SkillManager {
* @param target The {@link LivingEntity} being affected by the ability * @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event * @param damage The amount of damage initially dealt by the event
*/ */
public void berserkDamage(LivingEntity target, double damage) { public double berserkDamage(LivingEntity target, double damage) {
damage = (damage * Unarmed.berserkDamageModifier) - damage; damage = (damage * Unarmed.berserkDamageModifier) - damage;
CombatUtils.dealDamage(target, damage, getPlayer(), mcMMOPlayer, SkillType.UNARMED); return CombatUtils.callFakeDamageEvent(getPlayer(), target, damage);
} }
/** /**
@ -124,10 +124,10 @@ public class UnarmedManager extends SkillManager {
* *
* @param target The {@link LivingEntity} being affected by the ability * @param target The {@link LivingEntity} being affected by the ability
*/ */
public void ironArm(LivingEntity target) { public double ironArm(LivingEntity target) {
int unarmedBonus = Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage); int unarmedBonus = Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
CombatUtils.dealDamage(target, unarmedBonus, getPlayer(), mcMMOPlayer, SkillType.UNARMED); return CombatUtils.callFakeDamageEvent(getPlayer(), target, unarmedBonus);
} }
/** /**

View File

@ -66,6 +66,9 @@ public final class CombatUtils {
} }
private static void processAxeCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) { private static void processAxeCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
double initialDamage = event.getDamage();
double finalDamage = initialDamage;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
AxesManager axesManager = mcMMOPlayer.getAxesManager(); AxesManager axesManager = mcMMOPlayer.getAxesManager();
@ -74,28 +77,32 @@ public final class CombatUtils {
} }
if (axesManager.canUseAxeMastery()) { if (axesManager.canUseAxeMastery()) {
axesManager.axeMastery(target); finalDamage += axesManager.axeMastery(target);
} }
if (axesManager.canCriticalHit(target)) { if (axesManager.canCriticalHit(target)) {
axesManager.criticalHit(target, event.getDamage()); finalDamage += axesManager.criticalHit(target, initialDamage);
} }
if (axesManager.canImpact(target)) { if (axesManager.canImpact(target)) {
axesManager.impactCheck(target); axesManager.impactCheck(target);
} }
else if (axesManager.canGreaterImpact(target)) { else if (axesManager.canGreaterImpact(target)) {
axesManager.greaterImpact(target); finalDamage += axesManager.greaterImpact(target);
} }
if (axesManager.canUseSkullSplitter(target)) { if (axesManager.canUseSkullSplitter(target)) {
axesManager.skullSplitterCheck(target, event.getDamage()); axesManager.skullSplitterCheck(target, initialDamage);
} }
event.setDamage(finalDamage);
startGainXp(mcMMOPlayer, target, SkillType.AXES); startGainXp(mcMMOPlayer, target, SkillType.AXES);
} }
private static void processUnarmedCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) { private static void processUnarmedCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
double initialDamage = event.getDamage();
double finalDamage = initialDamage;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager(); UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
@ -104,21 +111,25 @@ public final class CombatUtils {
} }
if (unarmedManager.canUseIronArm()) { if (unarmedManager.canUseIronArm()) {
unarmedManager.ironArm(target); finalDamage += unarmedManager.ironArm(target);
} }
if (unarmedManager.canUseBerserk()) { if (unarmedManager.canUseBerserk()) {
unarmedManager.berserkDamage(target, event.getDamage()); finalDamage += unarmedManager.berserkDamage(target, initialDamage);
} }
if (unarmedManager.canDisarm(target)) { if (unarmedManager.canDisarm(target)) {
unarmedManager.disarmCheck((Player) target); unarmedManager.disarmCheck((Player) target);
} }
event.setDamage(finalDamage);
startGainXp(mcMMOPlayer, target, SkillType.UNARMED); startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
} }
private static void processTamingCombat(LivingEntity target, Player master, Wolf wolf, EntityDamageByEntityEvent event) { private static void processTamingCombat(LivingEntity target, Player master, Wolf wolf, EntityDamageByEntityEvent event) {
double initialDamage = event.getDamage();
double finalDamage = initialDamage;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
TamingManager tamingManager = mcMMOPlayer.getTamingManager(); TamingManager tamingManager = mcMMOPlayer.getTamingManager();
@ -127,17 +138,21 @@ public final class CombatUtils {
} }
if (tamingManager.canUseSharpenedClaws()) { if (tamingManager.canUseSharpenedClaws()) {
tamingManager.sharpenedClaws(target, wolf); finalDamage += tamingManager.sharpenedClaws(target, wolf);
} }
if (tamingManager.canUseGore()) { if (tamingManager.canUseGore()) {
tamingManager.gore(target, event.getDamage(), wolf); finalDamage += tamingManager.gore(target, initialDamage, wolf);
} }
event.setDamage(finalDamage);
startGainXp(mcMMOPlayer, target, SkillType.TAMING); startGainXp(mcMMOPlayer, target, SkillType.TAMING);
} }
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) { private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) {
double initialDamage = event.getDamage();
double finalDamage = initialDamage;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager(); ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
@ -154,11 +169,11 @@ public final class CombatUtils {
} }
if (archeryManager.canSkillShot()) { if (archeryManager.canSkillShot()) {
archeryManager.skillShot(target, event.getDamage(), arrow); finalDamage += archeryManager.skillShot(target, initialDamage, arrow);
} }
if (archeryManager.canDaze(target)) { if (archeryManager.canDaze(target)) {
archeryManager.daze((Player) target, arrow); finalDamage += archeryManager.daze((Player) target, arrow);
} }
if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) { if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) {
@ -167,6 +182,7 @@ public final class CombatUtils {
archeryManager.distanceXpBonus(target, arrow); archeryManager.distanceXpBonus(target, arrow);
event.setDamage(finalDamage);
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble()); startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
} }
@ -348,7 +364,7 @@ public final class CombatUtils {
* @param damage Amount of damage to attempt to do * @param damage Amount of damage to attempt to do
*/ */
public static void dealDamage(LivingEntity target, double damage) { public static void dealDamage(LivingEntity target, double damage) {
dealDamage(target, damage, DamageCause.CUSTOM, null, null, null); dealDamage(target, damage, DamageCause.CUSTOM, null);
} }
/** /**
@ -358,8 +374,8 @@ public final class CombatUtils {
* @param damage Amount of damage to attempt to do * @param damage Amount of damage to attempt to do
* @param attacker Player to pass to event as damager * @param attacker Player to pass to event as damager
*/ */
public static void dealDamage(LivingEntity target, double damage, LivingEntity attacker, McMMOPlayer mcMMOPlayer, SkillType skill) { public static void dealDamage(LivingEntity target, double damage, LivingEntity attacker) {
dealDamage(target, damage, DamageCause.ENTITY_ATTACK, attacker, mcMMOPlayer, skill); dealDamage(target, damage, DamageCause.ENTITY_ATTACK, attacker);
} }
/** /**
@ -369,34 +385,12 @@ public final class CombatUtils {
* @param damage Amount of damage to attempt to do * @param damage Amount of damage to attempt to do
* @param attacker Player to pass to event as damager * @param attacker Player to pass to event as damager
*/ */
public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker, McMMOPlayer mcMMOPlayer, SkillType skill) { public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) {
if (target.isDead()) { if (target.isDead()) {
return; return;
} }
if (Config.getInstance().getEventCallbackEnabled()) { target.damage(callFakeDamageEvent(attacker, target, cause, damage));
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
if (damageEvent.isCancelled()) {
return;
}
damage = damageEvent.getDamage();
}
if (mcMMOPlayer != null) {
startGainXp(mcMMOPlayer, target, skill);
}
int damageTicks = target.getNoDamageTicks();
double lastDamage = target.getLastDamage();
target.setMetadata(mcMMO.customDamageKey, mcMMO.metadataValue);
target.damage(damage, attacker);
target.setNoDamageTicks(damageTicks);
target.setLastDamage(lastDamage);
} }
/** /**
@ -443,7 +437,7 @@ public final class CombatUtils {
break; break;
} }
dealDamage(livingEntity, damageAmount, attacker, UserManager.getPlayer(attacker), type); dealDamage(livingEntity, damageAmount, attacker);
numberOfTargets--; numberOfTargets--;
} }
} }
@ -630,4 +624,23 @@ public final class CombatUtils {
public static boolean shouldProcessSkill(Entity target, SkillType skill) { public static boolean shouldProcessSkill(Entity target, SkillType skill) {
return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? skill.getPVPEnabled() : skill.getPVEEnabled(); return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? skill.getPVPEnabled() : skill.getPVEEnabled();
} }
public static double callFakeDamageEvent(LivingEntity attacker, LivingEntity target, double damage) {
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, damage);
}
public static double callFakeDamageEvent(Entity attacker, LivingEntity target, DamageCause cause, double damage) {
if (Config.getInstance().getEventCallbackEnabled()) {
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
if (damageEvent.isCancelled()) {
return 0;
}
damage = damageEvent.getDamage();
}
return damage;
}
} }