mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-03 18:33:16 +01:00
More Axe restructuring, changing some config values from int to double,
added function to duplicate code.
This commit is contained in:
parent
dd766d5363
commit
0587741437
@ -51,10 +51,10 @@ public class AdvancedConfig extends ConfigLoader {
|
||||
public int getBonusDamageAxesBonusMax() { return config.getInt("Skills.Axes.DamageIncrease_MaxBonus", 4); }
|
||||
public int getBonusDamageAxesMaxBonusLevel() { return config.getInt("Skills.Axes.DamageIncrease_MaxBonusLevel", 200); }
|
||||
|
||||
public double getAxesCriticalChance() { return config.getDouble("Skills.Axes.AxesCritical_MaxChance", 37.50); }
|
||||
public double getAxesCriticalChance() { return config.getDouble("Skills.Axes.AxesCritical_MaxChance", 37.50D); }
|
||||
public int getAxesCriticalMaxBonusLevel() { return config.getInt("Skills.Axes.AxesCritical_MaxBonusLevel", 750); }
|
||||
public double getAxesCriticalPVPModifier() { return config.getDouble("Skills.Axes.AxesCritical_PVP_Modifier", 1.5); }
|
||||
public int getAxesCriticalPVEModifier() { return config.getInt("Skills.Axes.AxesCritical_PVE_Modifier", 2); }
|
||||
public double getAxesCriticalPVPModifier() { return config.getDouble("Skills.Axes.AxesCritical_PVP_Modifier", 1.5D); }
|
||||
public double getAxesCriticalPVEModifier() { return config.getDouble("Skills.Axes.AxesCritical_PVE_Modifier", 2.0D); }
|
||||
|
||||
public int getGreaterImpactChance() { return config.getInt("Skills.Axes.GreaterImpact_Chance", 25); }
|
||||
public double getGreaterImpactModifier() { return config.getDouble("Skills.Axes.GreaterImpact_KnockbackModifier", 1.5); }
|
||||
|
@ -13,13 +13,13 @@ public class AxeBonusDamageEventHandler {
|
||||
}
|
||||
|
||||
protected void calculateDamageBonus() {
|
||||
int increaseLevel = Axes.maxBonusLevel / Axes.maxBonusDamage;
|
||||
int increaseLevel = Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus;
|
||||
|
||||
/* Add 1 DMG for every 50 skill levels (default value) */
|
||||
damageBonus = skillLevel / increaseLevel;
|
||||
|
||||
if (damageBonus > Axes.maxBonusDamage) {
|
||||
damageBonus = Axes.maxBonusDamage;
|
||||
if (damageBonus > Axes.bonusDamageMaxBonus) {
|
||||
damageBonus = Axes.bonusDamageMaxBonus;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.gmail.nossr50.skills.axes;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public class AxeManager extends SkillManager {
|
||||
public AxeManager(Player player) {
|
||||
@ -18,7 +20,7 @@ public class AxeManager extends SkillManager {
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public void bonusDamage(EntityDamageByEntityEvent event) {
|
||||
if (Misc.isNPC(player)) {
|
||||
if (Misc.isNPC(player) || !Permissions.axeBonus(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -27,4 +29,34 @@ public class AxeManager extends SkillManager {
|
||||
eventHandler.calculateDamageBonus();
|
||||
eventHandler.modifyEventDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for critical chances on axe damage.
|
||||
*
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public void criticalHitCheck(EntityDamageByEntityEvent event) {
|
||||
if (Misc.isNPC(player) || !Permissions.criticalHit(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CriticalHitEventHandler eventHandler = new CriticalHitEventHandler(this, event);
|
||||
|
||||
if (eventHandler.defender instanceof Tameable && Misc.isFriendlyPet(player, (Tameable) eventHandler.defender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int randomChance = 100;
|
||||
if (Permissions.luckyAxes(player)) {
|
||||
randomChance = (int) (randomChance * 0.75);
|
||||
}
|
||||
|
||||
double chance = (Axes.criticalHitMaxChance / Axes.criticalHitMaxBonusLevel) * eventHandler.skillModifier;
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.defender.isDead()) {
|
||||
eventHandler.modifyEventDamage();
|
||||
eventHandler.sendAbilityMessages();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,88 +1,30 @@
|
||||
package com.gmail.nossr50.skills.axes;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
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.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
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();
|
||||
public static int bonusDamageMaxBonus = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax();
|
||||
public static int bonusDamageMaxBonusLevel = AdvancedConfig.getInstance().getBonusDamageAxesMaxBonusLevel();
|
||||
|
||||
public static int criticalHitMaxBonusLevel = AdvancedConfig.getInstance().getAxesCriticalMaxBonusLevel();
|
||||
public static double criticalHitMaxChance = AdvancedConfig.getInstance().getAxesCriticalChance();
|
||||
public static double criticalHitPVPModifier = AdvancedConfig.getInstance().getAxesCriticalPVPModifier();
|
||||
public static double criticalHitPVEModifier = AdvancedConfig.getInstance().getAxesCriticalPVEModifier();
|
||||
|
||||
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
|
||||
/**
|
||||
* Check for critical chances on axe damage.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) {
|
||||
if (attacker == null)
|
||||
return;
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
if (entity instanceof Tameable) {
|
||||
Tameable pet = (Tameable) entity;
|
||||
|
||||
if (pet.isTamed()) {
|
||||
AnimalTamer tamer = pet.getOwner();
|
||||
|
||||
if (tamer instanceof Player) {
|
||||
Player owner = (Player) tamer;
|
||||
|
||||
if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final int MAX_BONUS_LEVEL = advancedConfig.getAxesCriticalMaxBonusLevel();
|
||||
final double MAX_CHANCE = advancedConfig.getAxesCriticalChance();
|
||||
final double PVP_MODIFIER = advancedConfig.getAxesCriticalPVPModifier();
|
||||
final int PVE_MODIFIER = advancedConfig.getAxesCriticalPVEModifier();
|
||||
|
||||
PlayerProfile attackerProfile = Users.getProfile(attacker);
|
||||
int skillLevel = attackerProfile.getSkillLevel(SkillType.AXES);
|
||||
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
|
||||
|
||||
int randomChance = 100;
|
||||
double chance = (MAX_CHANCE / MAX_BONUS_LEVEL) * skillCheck;
|
||||
if (chance > MAX_CHANCE) chance = MAX_CHANCE;
|
||||
|
||||
if (Permissions.luckyAxes(attacker)) {
|
||||
randomChance = (int) (randomChance * 0.75);
|
||||
}
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(randomChance) && !entity.isDead()) {
|
||||
int damage = event.getDamage();
|
||||
|
||||
if (entity instanceof Player) {
|
||||
event.setDamage((int) (damage * PVP_MODIFIER));
|
||||
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
|
||||
}
|
||||
else {
|
||||
event.setDamage(damage * PVE_MODIFIER);
|
||||
}
|
||||
attacker.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Impact ability.
|
||||
*
|
||||
|
@ -0,0 +1,47 @@
|
||||
package com.gmail.nossr50.skills.axes;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class CriticalHitEventHandler {
|
||||
private AxeManager manager;
|
||||
private EntityDamageByEntityEvent event;
|
||||
private int damage;
|
||||
|
||||
protected Entity defender;
|
||||
protected int skillModifier;
|
||||
|
||||
public CriticalHitEventHandler(AxeManager manager, EntityDamageByEntityEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
this.defender = event.getEntity();
|
||||
this.damage = event.getDamage();
|
||||
|
||||
calculateSkillModifier();
|
||||
}
|
||||
|
||||
protected void modifyEventDamage() {
|
||||
if (defender instanceof Player) {
|
||||
event.setDamage((int) (damage * Axes.criticalHitPVPModifier));
|
||||
}
|
||||
else {
|
||||
event.setDamage((int) (damage * Axes.criticalHitPVEModifier));
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendAbilityMessages() {
|
||||
manager.getPlayer().sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
|
||||
|
||||
if (defender instanceof Player) {
|
||||
((Player) defender).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateSkillModifier() {
|
||||
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Axes.criticalHitMaxBonusLevel);
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.gmail.nossr50.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -100,13 +99,8 @@ public class Combat {
|
||||
Skills.abilityCheck(attacker, SkillType.AXES);
|
||||
AxeManager axeManager = new AxeManager(attacker);
|
||||
|
||||
if (Permissions.axeBonus(attacker)) {
|
||||
axeManager.bonusDamage(event);
|
||||
}
|
||||
|
||||
if (Permissions.criticalHit(attacker)) {
|
||||
Axes.axeCriticalCheck(attacker, event);
|
||||
}
|
||||
axeManager.bonusDamage(event);
|
||||
axeManager.criticalHitCheck(event);
|
||||
|
||||
if (Permissions.impact(attacker)) {
|
||||
Axes.impact(attacker, target, event);
|
||||
@ -550,16 +544,8 @@ public class Combat {
|
||||
else if (entity instanceof Tameable) {
|
||||
Tameable pet = (Tameable) entity;
|
||||
|
||||
if (pet.isTamed()) {
|
||||
AnimalTamer tamer = pet.getOwner();
|
||||
|
||||
if (tamer instanceof Player) {
|
||||
Player owner = (Player) tamer;
|
||||
|
||||
if (owner == player || PartyManager.getInstance().inSameParty(player, owner)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (Misc.isFriendlyPet(player, pet)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,11 @@ import java.util.Random;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -18,6 +20,7 @@ import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.events.items.McMMOItemSpawnEvent;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
|
||||
public class Misc {
|
||||
private static Random random = new Random();
|
||||
@ -27,6 +30,22 @@ public class Misc {
|
||||
public static final int TIME_CONVERSION_FACTOR = 1000;
|
||||
public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;
|
||||
|
||||
public static boolean isFriendlyPet(Player attacker, Tameable pet) {
|
||||
if (pet.isTamed()) {
|
||||
AnimalTamer tamer = pet.getOwner();
|
||||
|
||||
if (tamer instanceof Player) {
|
||||
Player owner = (Player) tamer;
|
||||
|
||||
if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isNPC(Player player) {
|
||||
if (player == null || Users.getProfile(player) == null || player.hasMetadata("NPC")) {
|
||||
return true;
|
||||
|
@ -47,8 +47,8 @@ Skills:
|
||||
# SkillShot_IncreasePercentage: This is a percentage value, 0.1 = 10%
|
||||
# SkillShot_MaxBonus: When the SkillShot_MaxBonus has been reached, the bonus percentage will not go up anymore. 2.0 = 200%
|
||||
SkillShot_IncreaseLevel: 50
|
||||
SkillShot_IncreasePercentage: 0.1D
|
||||
SkillShot_MaxBonus: 2.0D
|
||||
SkillShot_IncreasePercentage: 0.1
|
||||
SkillShot_MaxBonus: 2.0
|
||||
|
||||
# Daze_MaxChance: Maximum chance of causing daze to opponents
|
||||
# Daze_MaxBonusLevel: Maximum bonus level of Daze, when a player reaches this level his chance of causing a daze will be "Daze_MaxChance"
|
||||
@ -77,7 +77,7 @@ Skills:
|
||||
|
||||
# Damage modifier of critical hits for PVP / PVE, when causing a critical hit the damage gets multiplied by the modifier
|
||||
AxesCritical_PVP_Modifier: 1.5
|
||||
AxesCritical_PVE_Modifier: 2
|
||||
AxesCritical_PVE_Modifier: 2.0
|
||||
|
||||
# GreaterImpact_Chance: Chance of hitting with GreaterImpact, knocksbacks mobs
|
||||
# GreaterImpact_KnockbackModifier: Velocity modifier of GreaterImpact hits, this determines how great the knockback is
|
||||
|
Loading…
Reference in New Issue
Block a user