Axe restructuring.

This commit is contained in:
GJ 2013-01-15 16:16:46 -05:00
parent bbbd12d461
commit f40433fc99
7 changed files with 164 additions and 140 deletions

View File

@ -6,6 +6,7 @@ import com.gmail.nossr50.commands.SkillCommand;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.axes.Axes;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -20,14 +21,6 @@ public class AxesCommand extends SkillCommand {
private String skullSplitterLength; private String skullSplitterLength;
private String skullSplitterLengthEndurance; private String skullSplitterLengthEndurance;
private int bonusDamageAxesBonusMax = advancedConfig.getBonusDamageAxesBonusMax();
private int bonusDamageAxesMaxBonusLevel = advancedConfig.getBonusDamageAxesMaxBonusLevel();
private double critMaxChance = advancedConfig.getAxesCriticalChance();
private int critMaxBonusLevel = advancedConfig.getAxesCriticalMaxBonusLevel();
private int greaterImpactIncreaseLevel = advancedConfig.getArmorImpactIncreaseLevel();
private double greaterImpactBonusDamage = advancedConfig.getGreaterImpactBonusDamage();
private int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
private boolean canSkullSplitter; private boolean canSkullSplitter;
private boolean canCritical; private boolean canCritical;
private boolean canBonusDamage; private boolean canBonusDamage;
@ -43,12 +36,12 @@ public class AxesCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
float critChanceF; float critChanceF;
int skillCheck = Misc.skillCheck((int)skillValue, critMaxBonusLevel); int skillCheck = Misc.skillCheck((int) skillValue, Axes.criticalHitMaxBonusLevel);
//Armor Impact //Armor Impact
impactDamage = String.valueOf(1 + ((double) skillValue / (double) greaterImpactIncreaseLevel)); impactDamage = String.valueOf(1 + ((double) skillValue / (double) Axes.impactIncreaseLevel));
//Skull Splitter //Skull Splitter
int length = 2 + (int) ((double) skillValue / (double) abilityLengthIncreaseLevel); int length = 2 + (int) ((double) skillValue / (double) Misc.abilityLengthIncreaseLevel);
skullSplitterLength = String.valueOf(length); skullSplitterLength = String.valueOf(length);
if (Permissions.activationTwelve(player)) { if (Permissions.activationTwelve(player)) {
@ -67,16 +60,16 @@ public class AxesCommand extends SkillCommand {
skullSplitterLengthEndurance = String.valueOf(length); skullSplitterLengthEndurance = String.valueOf(length);
//Greater Impact //Greater Impact
greaterImpactDamage = String.valueOf(greaterImpactBonusDamage); greaterImpactDamage = String.valueOf(Axes.greaterImpactBonusDamage);
//Critical Strikes //Critical Strikes
if (skillValue >= critMaxBonusLevel) critChanceF = (float) critMaxChance; if (skillValue >= Axes.criticalHitMaxBonusLevel) critChanceF = (float) Axes.criticalHitMaxChance;
else critChanceF = (float) ((critMaxChance / critMaxBonusLevel) * skillCheck); else critChanceF = (float) ((Axes.criticalHitMaxChance / Axes.criticalHitMaxBonusLevel) * skillCheck);
critChance = percent.format(critChanceF / 100D); critChance = percent.format(critChanceF / 100D);
if (critChanceF * 1.3333D >= 100D) critChanceLucky = percent.format(1D); if (critChanceF * 1.3333D >= 100D) critChanceLucky = percent.format(1D);
else critChanceLucky = percent.format(critChanceF * 1.3333D / 100D); else critChanceLucky = percent.format(critChanceF * 1.3333D / 100D);
//Axe Mastery //Axe Mastery
if (skillValue >= bonusDamageAxesMaxBonusLevel) bonusDamage = String.valueOf(bonusDamageAxesBonusMax); if (skillValue >= Axes.bonusDamageMaxBonusLevel) bonusDamage = String.valueOf(Axes.bonusDamageMaxBonus);
else bonusDamage = String.valueOf(skillValue / ((double) bonusDamageAxesMaxBonusLevel / (double) bonusDamageAxesBonusMax)); else bonusDamage = String.valueOf(skillValue / ((double) Axes.bonusDamageMaxBonusLevel / (double) Axes.bonusDamageMaxBonus));
} }
@Override @Override

View File

@ -59,4 +59,27 @@ public class AxeManager extends SkillManager {
} }
} }
/**
* Check for Impact ability.
*
* @param event The event to modify
*/
public void impact(EntityDamageByEntityEvent event) {
if (Misc.isNPC(player) || !Permissions.impact(player)) {
return;
}
ImpactEventHandler eventHandler = new ImpactEventHandler(this, event);
if (eventHandler.livingDefender == null) {
return;
}
if (!Misc.hasArmor(eventHandler.livingDefender)) {
eventHandler.damageArmor();
}
else {
eventHandler.applyGreaterImpact();
}
}
} }

View File

@ -1,18 +1,6 @@
package com.gmail.nossr50.skills.axes; package com.gmail.nossr50.skills.axes;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class Axes { public class Axes {
public static int bonusDamageMaxBonus = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax(); public static int bonusDamageMaxBonus = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax();
@ -23,110 +11,10 @@ public class Axes {
public static double criticalHitPVPModifier = AdvancedConfig.getInstance().getAxesCriticalPVPModifier(); public static double criticalHitPVPModifier = AdvancedConfig.getInstance().getAxesCriticalPVPModifier();
public static double criticalHitPVEModifier = AdvancedConfig.getInstance().getAxesCriticalPVEModifier(); public static double criticalHitPVEModifier = AdvancedConfig.getInstance().getAxesCriticalPVEModifier();
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); public static int impactIncreaseLevel = AdvancedConfig.getInstance().getArmorImpactIncreaseLevel();
public static double impactMaxDurabilityDamageModifier = AdvancedConfig.getInstance().getArmorImpactMaxDurabilityDamage() / 100D;
/** public static double greaterImpactChance = AdvancedConfig.getInstance().getGreaterImpactChance();
* Check for Impact ability. public static double greaterImpactKnockbackMultiplier = AdvancedConfig.getInstance().getGreaterImpactModifier();
* public static int greaterImpactBonusDamage = AdvancedConfig.getInstance().getGreaterImpactBonusDamage();
* @param attacker The attacking player
* @param target The defending entity
* @param event The event to modify
*/
public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
if (attacker == null)
return;
/*
* TODO: Finish this skill. The idea is you will greatly damage an opponents armor.
* When they are unarmored, you have a proc that will stun them and deal additional damage.
*/
if (target instanceof Player) {
Player targetPlayer = (Player) target;
short durabilityDamage = 1; //Start with 1 durability damage
/* Every 50 Skill Levels you gain 1 durability damage (default values) */
int impactIncreaseLevel = advancedConfig.getArmorImpactIncreaseLevel();
double impactMaxDamage = advancedConfig.getArmorImpactMaxDurabilityDamage() / 100F;
short maxDurability;
durabilityDamage += (int) ((double) Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / (double) impactIncreaseLevel);
if (!hasArmor(targetPlayer)) {
applyGreaterImpact(attacker, target, event);
}
else {
for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) {
if (Math.random() * 100 > 75) {
int lowerdamage = 0;
for (int i = 0; i <= durabilityDamage; i ++) {
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
int level = armor.getEnchantmentLevel(Enchantment.DURABILITY);
if (Misc.getRandom().nextInt(level + 1) > 0) {
lowerdamage++;
}
}
}
int newDurabilityDamage = durabilityDamage - lowerdamage;
maxDurability = (short) (armor.getType().getMaxDurability() * impactMaxDamage);
if (newDurabilityDamage > maxDurability) newDurabilityDamage = maxDurability;
armor.setDurability((short) (armor.getDurability() + newDurabilityDamage)); //Damage armor piece
}
}
targetPlayer.updateInventory();
}
}
else {
applyGreaterImpact(attacker, target, event); //Since mobs are technically unarmored, this will always trigger
}
}
/**
* Apply Greater Impact ability.
*
* @param attacker The attacking player
* @param target The defending entity
* @param event The event to modify
*/
private static void applyGreaterImpact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
if (attacker == null)
return;
final double GREATER_IMPACT_CHANCE = advancedConfig.getGreaterImpactChance();
final double GREATER_IMPACT_MULTIPLIER = advancedConfig.getGreaterImpactModifier();
final int GREATER_IMPACT_DAMAGE = advancedConfig.getGreaterImpactBonusDamage();
if (!Permissions.greaterImpact(attacker)) {
return;
}
int randomChance = 100;
if (Permissions.luckyAxes(attacker)) {
randomChance = (int) (randomChance * 0.75);
}
if (Misc.getRandom().nextInt(randomChance) <= GREATER_IMPACT_CHANCE) {
event.setDamage(event.getDamage() + GREATER_IMPACT_DAMAGE);
target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
}
}
/**
* Check if a player has armor.
*
* @param player Player whose armor to check
* @return true if the player has armor, false otherwise
*/
private static boolean hasArmor(Player player) {
if (player == null)
return false;
PlayerInventory inventory = player.getInventory();
if (inventory.getBoots() != null || inventory.getChestplate() != null || inventory.getHelmet() != null || inventory.getLeggings() != null) {
return true;
}
return false;
}
} }

View File

@ -0,0 +1,104 @@
package com.gmail.nossr50.skills.axes;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class ImpactEventHandler {
private AxeManager manager;
private Player player;
private EntityDamageByEntityEvent event;
private short durabilityDamage = 1;
private EntityEquipment equipment;
private ItemStack[] armorContents;
protected Entity defender;
protected LivingEntity livingDefender;
public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event) {
this.manager = manager;
this.player = manager.getPlayer();
this.event = event;
this.defender = event.getEntity();
if (defender instanceof LivingEntity) {
this.livingDefender = (LivingEntity) defender;
this.equipment = livingDefender.getEquipment();
this.armorContents = equipment.getArmorContents();
}
}
protected void damageArmor() {
/* Every 50 Skill Levels you gain 1 durability damage (default values) */
durabilityDamage += (short) (manager.getSkillLevel() / Axes.impactIncreaseLevel);
for (ItemStack armor : armorContents) {
if (Misc.getRandom().nextInt(100) > 75) {
for (int i = 0; i <= durabilityDamage; i++) {
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
handleDurabilityEnchantment(armor);
}
}
damageValidation(armor);
armor.setDurability((short) (armor.getDurability() + durabilityDamage));
}
}
equipment.setArmorContents(armorContents);
}
protected void applyGreaterImpact() {
if (!Permissions.greaterImpact(player)) {
return;
}
int randomChance = 100;
if (Permissions.luckyAxes(player)) {
randomChance = (int) (randomChance * 0.75);
}
if (Misc.getRandom().nextInt(randomChance) <= Axes.greaterImpactChance) {
handleGreaterImpactEffect();
sendAbilityMessge();
}
}
private void handleGreaterImpactEffect() {
event.setDamage(event.getDamage() + Axes.greaterImpactBonusDamage);
livingDefender.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
}
private void sendAbilityMessge() {
player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
if (livingDefender instanceof Player) {
((Player) livingDefender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
}
}
private void handleDurabilityEnchantment(ItemStack armor) {
int enchantmentLevel = armor.getEnchantmentLevel(Enchantment.DURABILITY);
if (Misc.getRandom().nextInt(enchantmentLevel + 1) > 0) {
durabilityDamage--;
}
}
private void damageValidation(ItemStack armor) {
short maxDurability = (short) (armor.getType().getMaxDurability() * Axes.impactMaxDurabilityDamageModifier);
if (durabilityDamage > maxDurability) {
durabilityDamage = maxDurability;
}
}
}

View File

@ -115,7 +115,7 @@ public class SuperBreakerEventHandler {
} }
private void calculateDurabilityLoss() { private void calculateDurabilityLoss() {
this.durabilityLoss = Misc.TOOL_DURABILITY_LOSS; this.durabilityLoss = Misc.toolDurabilityLoss;
if (blockType.equals(Material.OBSIDIAN)) { if (blockType.equals(Material.OBSIDIAN)) {
durabilityLoss = durabilityLoss * 5; durabilityLoss = durabilityLoss * 5;

View File

@ -33,7 +33,6 @@ import com.gmail.nossr50.runnables.GainXp;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxeManager; 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.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
@ -101,10 +100,7 @@ public class Combat {
axeManager.bonusDamage(event); axeManager.bonusDamage(event);
axeManager.criticalHitCheck(event); axeManager.criticalHitCheck(event);
axeManager.impact(event);
if (Permissions.impact(attacker)) {
Axes.impact(attacker, target, event);
}
if (attackerProfile.getAbilityMode(AbilityType.SKULL_SPLIITER) && Permissions.skullSplitter(attacker)) { if (attackerProfile.getAbilityMode(AbilityType.SKULL_SPLIITER) && Permissions.skullSplitter(attacker)) {
applyAbilityAoE(attacker, target, event.getDamage() / 2, SkillType.AXES); applyAbilityAoE(attacker, target, event.getDamage() / 2, SkillType.AXES);

View File

@ -11,10 +11,12 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
@ -25,11 +27,29 @@ import com.gmail.nossr50.party.PartyManager;
public class Misc { public class Misc {
private static Random random = new Random(); private static Random random = new Random();
public static final int TOOL_DURABILITY_LOSS = Config.getInstance().getAbilityToolDamage(); public static int toolDurabilityLoss = Config.getInstance().getAbilityToolDamage();
public static int abilityLengthIncreaseLevel = AdvancedConfig.getInstance().getAbilityLength();
public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
public static final int TIME_CONVERSION_FACTOR = 1000; public static final int TIME_CONVERSION_FACTOR = 1000;
public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0; public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;
/**
* Check if a player has armor.
*
* @param player Player whose armor to check
* @return true if the player has armor, false otherwise
*/
public static boolean hasArmor(LivingEntity entity) {
EntityEquipment equipment = entity.getEquipment();
if (equipment.getBoots() != null || equipment.getChestplate() != null || equipment.getHelmet() != null || equipment.getLeggings() != null) {
return true;
}
return false;
}
public static boolean isFriendlyPet(Player attacker, Tameable pet) { public static boolean isFriendlyPet(Player attacker, Tameable pet) {
if (pet.isTamed()) { if (pet.isTamed()) {
AnimalTamer tamer = pet.getOwner(); AnimalTamer tamer = pet.getOwner();