Let's do this the right way.

This commit is contained in:
GJ 2013-08-23 10:58:50 -04:00 committed by TfT_02
parent 59f545d5ce
commit 6bfc1b84de
5 changed files with 124 additions and 108 deletions

View File

@ -1,9 +1,11 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Location;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -15,6 +17,7 @@ import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class ArcheryManager extends SkillManager {
@ -68,8 +71,11 @@ public class ArcheryManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public double dazeCheck(Player defender, double damage) {
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel)) {
public void daze(Player defender, Arrow arrow) {
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel)) {
return;
}
Location dazedLocation = defender.getLocation();
dazedLocation.setPitch(90 - Misc.getRandom().nextInt(181));
@ -84,10 +90,7 @@ public class ArcheryManager extends SkillManager {
getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
}
return damage + Archery.dazeModifier;
}
return damage;
CombatUtils.dealDamage(defender, Archery.dazeModifier, DamageCause.PROJECTILE, arrow);
}
/**
@ -96,10 +99,10 @@ public class ArcheryManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage
*/
public double skillShotCheck(double damage) {
public void skillShot(LivingEntity target, double damage, Arrow arrow) {
double damageBonusPercent = Math.min(((getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage), Archery.skillShotMaxBonusPercentage);
double archeryBonus = damage * damageBonusPercent;
return damage + archeryBonus;
CombatUtils.dealDamage(target, archeryBonus, DamageCause.PROJECTILE, arrow);
}
}

View File

@ -55,10 +55,10 @@ public class AxesManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage
*/
public double axeMasteryCheck(double damage) {
public void axeMastery(LivingEntity target) {
double axeBonus = Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus);
return damage + axeBonus;
CombatUtils.dealDamage(target, axeBonus, getPlayer());
}
/**
@ -68,20 +68,25 @@ public class AxesManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public double criticalHitCheck(LivingEntity target, double damage) {
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) {
getPlayer().sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
public void criticalHit(LivingEntity target, double damage) {
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) {
return;
}
Player player = getPlayer();
player.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
if (target instanceof Player) {
((Player) target).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
return damage * Axes.criticalHitPVPModifier;
damage = (damage * Axes.criticalHitPVPModifier) - damage;
}
else {
damage = (damage * Axes.criticalHitPVEModifier) - damage;
}
return damage * Axes.criticalHitPVEModifier;
}
return damage;
CombatUtils.dealDamage(target, damage, player);
}
/**
@ -111,8 +116,11 @@ public class AxesManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
*/
public double greaterImpactCheck(LivingEntity target, double damage) {
if (Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance())) {
public void greaterImpact(LivingEntity target) {
if (!(Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance()))) {
return;
}
Player player = getPlayer();
ParticleEffectUtils.playGreaterImpactEffect(target);
@ -130,10 +138,7 @@ public class AxesManager extends SkillManager {
}
}
return damage + Axes.greaterImpactBonusDamage;
}
return damage;
CombatUtils.dealDamage(target, Axes.greaterImpactBonusDamage, player);
}
/**

View File

@ -19,6 +19,7 @@ import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class TamingManager extends SkillManager {
@ -103,8 +104,11 @@ public class TamingManager extends SkillManager {
* @param target The LivingEntity to apply Gore on
* @param damage The initial damage
*/
public double gore(LivingEntity target, double damage) {
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Taming.goreMaxChance, Taming.goreMaxBonusLevel)) {
public void gore(LivingEntity target, double damage, Wolf wolf) {
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Taming.goreMaxChance, Taming.goreMaxBonusLevel)) {
return;
}
BleedTimerTask.add(target, Taming.goreBleedTicks);
if (target instanceof Player) {
@ -112,10 +116,13 @@ public class TamingManager extends SkillManager {
}
getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));
return damage * Taming.goreModifier;
damage = (damage * Taming.goreModifier) - damage;
CombatUtils.dealDamage(target, damage, wolf);
}
return damage;
public void sharpenedClaws(LivingEntity target, Wolf wolf) {
CombatUtils.dealDamage(target, Taming.sharpenedClawsBonusDamage, wolf);
}
/**

View File

@ -16,6 +16,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class UnarmedManager extends SkillManager {
@ -95,8 +96,10 @@ public class UnarmedManager extends SkillManager {
return false;
}
public double berserkDamage(double damage) {
return damage * Unarmed.berserkDamageModifier;
public void berserkDamage(LivingEntity target, double damage) {
damage = (damage * Unarmed.berserkDamageModifier) - damage;
CombatUtils.dealDamage(target, damage, getPlayer());
}
/**
@ -105,10 +108,10 @@ public class UnarmedManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage
*/
public double ironArmCheck(double damage) {
public void ironArm(LivingEntity target) {
int unarmedBonus = Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
return damage + unarmedBonus;
CombatUtils.dealDamage(target, unarmedBonus, getPlayer());
}
/**

View File

@ -34,7 +34,6 @@ import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxesManager;
import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.ItemUtils;
@ -75,18 +74,18 @@ public final class CombatUtils {
}
if (axesManager.canUseAxeMastery()) {
dealDamage(target, axesManager.axeMasteryCheck(event.getDamage()), player);
axesManager.axeMastery(target);
}
if (axesManager.canCriticalHit(target)) {
dealDamage(target, axesManager.criticalHitCheck(target, event.getDamage()), player);
axesManager.criticalHit(target, event.getDamage());
}
if (axesManager.canImpact(target)) {
axesManager.impactCheck(target);
}
else if (axesManager.canGreaterImpact(target)) {
dealDamage(target, axesManager.greaterImpactCheck(target, event.getDamage()), player);
axesManager.greaterImpact(target);
}
if (axesManager.canUseSkullSplitter(target)) {
@ -105,11 +104,11 @@ public final class CombatUtils {
}
if (unarmedManager.canUseIronArm()) {
dealDamage(target, unarmedManager.ironArmCheck(event.getDamage()), player);
unarmedManager.ironArm(target);
}
if (unarmedManager.canUseBerserk()) {
dealDamage(target, unarmedManager.berserkDamage(event.getDamage()), player);
unarmedManager.berserkDamage(target, event.getDamage());
}
if (unarmedManager.canDisarm(target)) {
@ -128,22 +127,22 @@ public final class CombatUtils {
}
if (tamingManager.canUseSharpenedClaws()) {
dealDamage(target, Taming.sharpenedClawsBonusDamage, master);
tamingManager.sharpenedClaws(target, wolf);
}
if (tamingManager.canUseGore()) {
dealDamage(target, tamingManager.gore(target, event.getDamage()), master);
tamingManager.gore(target, event.getDamage(), wolf);
}
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
}
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) {
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
if (archeryManager.canSkillShot()) {
dealDamage(target, archeryManager.skillShotCheck(event.getDamage()), player);
archeryManager.skillShot(target, event.getDamage(), arrow);
}
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled()) {
@ -159,7 +158,7 @@ public final class CombatUtils {
}
if (archeryManager.canDaze(target)) {
dealDamage(target, archeryManager.dazeCheck((Player) target, event.getDamage()), player);
archeryManager.daze((Player) target, arrow);
}
if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) {
@ -251,13 +250,14 @@ public final class CombatUtils {
}
}
else if (damager.getType() == EntityType.ARROW) {
LivingEntity shooter = ((Arrow) damager).getShooter();
Arrow arrow = (Arrow) damager;
LivingEntity shooter = arrow.getShooter();
if (shooter != null && shooter instanceof Player && shouldProcessSkill(target, SkillType.ARCHERY)) {
Player player = (Player) shooter;
if (!Misc.isNPCEntity(player) && Permissions.skillEnabled(player, SkillType.ARCHERY)) {
processArcheryCombat(target, player, event, damager);
processArcheryCombat(target, player, event, arrow);
}
}
}
@ -345,56 +345,54 @@ public final class CombatUtils {
* Attempt to damage target for value dmg with reason CUSTOM
*
* @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do
* @param damage Amount of damage to attempt to do
*/
public static void dealDamage(LivingEntity target, double dmg) {
dealDamage(target, dmg, EntityDamageEvent.DamageCause.CUSTOM);
}
/**
* Attempt to damage target for value dmg with reason cause
*
* @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do
* @param cause DamageCause to pass to damage event
*/
private static void dealDamage(LivingEntity target, double dmg, DamageCause cause) {
public static void dealDamage(LivingEntity target, double damage) {
if (Config.getInstance().getEventCallbackEnabled()) {
EntityDamageEvent ede = new FakeEntityDamageEvent(target, cause, dmg);
EntityDamageEvent ede = new FakeEntityDamageEvent(target, DamageCause.CUSTOM, damage);
mcMMO.p.getServer().getPluginManager().callEvent(ede);
if (ede.isCancelled()) {
return;
}
target.damage(ede.getDamage());
}
else {
target.damage(dmg);
damage = ede.getDamage();
}
target.damage(damage);
}
/**
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
*
* @param target LivingEntity which to attempt to damage
* @param dmg 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
*/
private static void dealDamage(LivingEntity target, double dmg, Player attacker) {
public static void dealDamage(LivingEntity target, double damage, LivingEntity attacker) {
dealDamage(target, damage, DamageCause.ENTITY_ATTACK, attacker);
}
/**
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
*
* @param target LivingEntity which to attempt to damage
* @param damage Amount of damage to attempt to do
* @param attacker Player to pass to event as damager
*/
public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) {
if (Config.getInstance().getEventCallbackEnabled()) {
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
mcMMO.p.getServer().getPluginManager().callEvent(ede);
if (ede.isCancelled()) {
return;
}
target.damage(ede.getDamage());
}
else {
target.damage(dmg);
damage = ede.getDamage();
}
target.damage(damage);
}
/**