Start Axe restructuring.

This commit is contained in:
gmcferrin 2013-01-10 22:39:08 -05:00
parent 6496816692
commit a8abfdae5e
4 changed files with 62 additions and 27 deletions

View File

@ -0,0 +1,31 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public class AxeBonusDamageEventHandler {
private int skillLevel;
private EntityDamageByEntityEvent event;
private int damageBonus;
public AxeBonusDamageEventHandler(AxeManager manager, EntityDamageByEntityEvent event) {
this.skillLevel = manager.getSkillLevel();
this.event = event;
}
protected void calculateDamageBonus() {
int increaseLevel = Axes.maxBonusLevel / Axes.maxBonusDamage;
/* Add 1 DMG for every 50 skill levels (default value) */
damageBonus = skillLevel / increaseLevel;
if (damageBonus > Axes.maxBonusDamage) {
damageBonus = Axes.maxBonusDamage;
}
}
protected void modifyEventDamage() {
int damage = event.getDamage();
event.setDamage(damage + damageBonus);
}
}

View File

@ -1,5 +1,30 @@
package com.gmail.nossr50.skills.axes;
public class AxeManager {
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
public class AxeManager extends SkillManager {
public AxeManager(Player player) {
super(player, SkillType.AXES);
}
/**
* Apply bonus to damage done by axes.
*
* @param event The event to modify
*/
public void bonusDamage(EntityDamageByEntityEvent event) {
if (Misc.isNPC(player)) {
return;
}
AxeBonusDamageEventHandler eventHandler = new AxeBonusDamageEventHandler(this, event);
eventHandler.calculateDamageBonus();
eventHandler.modifyEventDamage();
}
}

View File

@ -20,32 +20,10 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class Axes {
public static int maxBonusDamage = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax();
public static int maxBonusLevel = AdvancedConfig.getInstance().getBonusDamageAxesMaxBonusLevel();
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
/**
* Apply bonus to damage done by axes.
*
* @param attacker The attacking player
* @param event The event to modify
*/
public static void axesBonus(Player attacker, EntityDamageByEntityEvent event) {
if (attacker == null)
return;
final int MAX_BONUS = advancedConfig.getBonusDamageAxesBonusMax();
final int MAX_LEVEL = advancedConfig.getBonusDamageAxesMaxBonusLevel();
final int INCREASE_LEVEL = MAX_LEVEL / MAX_BONUS;
/* Add 1 DMG for every 50 skill levels (default value) */
int bonus = (int) ((double) Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / (double) INCREASE_LEVEL);
if (bonus > MAX_BONUS) {
bonus = MAX_BONUS;
}
event.setDamage(event.getDamage() + bonus);
}
/**
* Check for critical chances on axe damage.
*
@ -112,7 +90,6 @@ public class Axes {
* @param target The defending entity
* @param event The event to modify
*/
@SuppressWarnings("deprecation")
public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
if (attacker == null)
return;

View File

@ -32,6 +32,7 @@ import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.GainXp;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxeManager;
import com.gmail.nossr50.skills.axes.Axes;
import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager;
@ -96,9 +97,10 @@ public class Combat {
}
Skills.abilityCheck(attacker, SkillType.AXES);
AxeManager axeManager = new AxeManager(attacker);
if (Permissions.axeBonus(attacker)) {
Axes.axesBonus(attacker, event);
axeManager.bonusDamage(event);
}
if (Permissions.criticalHit(attacker)) {