mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Axe events.
This commit is contained in:
parent
d6fbf1be34
commit
26d5db07ef
@ -12,13 +12,20 @@ public abstract class McMMOPlayerCombatEvent extends FakeEntityDamageByEntityEve
|
||||
private SkillType skill;
|
||||
private int skillLevel;
|
||||
|
||||
public McMMOPlayerCombatEvent(Player player, Entity damager, Entity damagee, DamageCause cause, double damage, SkillType skill) {
|
||||
protected McMMOPlayerCombatEvent(Player player, Entity damager, Entity damagee, DamageCause cause, double damage, SkillType skill) {
|
||||
super(damager, damagee, cause, damage);
|
||||
this.player = player;
|
||||
this.skill = skill;
|
||||
skillLevel = UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
||||
}
|
||||
|
||||
protected McMMOPlayerCombatEvent(Player player, Entity damagee, DamageCause cause, double damage, SkillType skill) {
|
||||
super(player, damagee, cause, damage);
|
||||
this.player = player;
|
||||
this.skill = skill;
|
||||
skillLevel = UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
@ -7,8 +7,7 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerCombatEvent;
|
||||
|
||||
public class McMMOPlayerAxeCombatEvent extends McMMOPlayerCombatEvent {
|
||||
public McMMOPlayerAxeCombatEvent(Player player, Entity damager, Entity damagee, DamageCause cause, double damage) {
|
||||
super(player, damager, damagee, cause, damage, SkillType.AXES);
|
||||
public McMMOPlayerAxeCombatEvent(Player player, Entity damagee, DamageCause cause, double damage) {
|
||||
super(player, damagee, cause, damage, SkillType.AXES);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.gmail.nossr50.events.skills.axes;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class McMMOPlayerAxeMasteryEvent extends McMMOPlayerAxeCombatEvent {
|
||||
public McMMOPlayerAxeMasteryEvent(Player player, Entity damagee, double damage) {
|
||||
super(player, damagee, DamageCause.ENTITY_ATTACK, damage);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.gmail.nossr50.events.skills.axes;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class McMMOPlayerCriticalHitEvent extends McMMOPlayerAxeCombatEvent {
|
||||
public McMMOPlayerCriticalHitEvent(Player player, Entity damagee, double damage) {
|
||||
super(player, damagee, DamageCause.ENTITY_ATTACK, damage);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.gmail.nossr50.events.skills.axes;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class McMMOPlayerGreaterImpactEvent extends McMMOPlayerAxeCombatEvent {
|
||||
private Vector knockbackVelocity;
|
||||
|
||||
public McMMOPlayerGreaterImpactEvent(Player player, Entity damagee, double damage, Vector knockbackVelocity) {
|
||||
super(player, damagee, DamageCause.ENTITY_ATTACK, damage);
|
||||
this.knockbackVelocity = knockbackVelocity;
|
||||
}
|
||||
|
||||
public Vector getKnockbackVelocity() {
|
||||
return knockbackVelocity;
|
||||
}
|
||||
|
||||
public void setKnockbackVelocity(Vector knockbackVelocity) {
|
||||
this.knockbackVelocity = knockbackVelocity;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.gmail.nossr50.events.skills.axes;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class McMMOPlayerImpactEvent extends McMMOPlayerAxeEvent {
|
||||
private ItemStack armor;
|
||||
private short durabilityDamage;
|
||||
|
||||
public McMMOPlayerImpactEvent(Player player, ItemStack armor, short durabilityDamage) {
|
||||
super(player);
|
||||
this.armor = armor;
|
||||
this.durabilityDamage = durabilityDamage;
|
||||
}
|
||||
|
||||
public ItemStack getArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
public short getDurabilityDamage() {
|
||||
return durabilityDamage;
|
||||
}
|
||||
|
||||
public void setDurabilityDamage(short durabilityDamage) {
|
||||
this.durabilityDamage = durabilityDamage;
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ public class ArcheryManager extends SkillManager {
|
||||
* @param arrow The {@link Arrow} that damaged the target
|
||||
*/
|
||||
public void trackArrow(LivingEntity target, Arrow arrow) {
|
||||
if (!canTrack(arrow)) {
|
||||
if (!canTrackArrows(target, arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ public class ArcheryManager extends SkillManager {
|
||||
* @param arrow The {@link Arrow} that was fired
|
||||
*/
|
||||
public double skillShot(LivingEntity target, double damage, Arrow arrow) {
|
||||
if (!canUseSkillShot()) {
|
||||
if (!canUseSkillShot(target)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -124,14 +124,14 @@ public class ArcheryManager extends SkillManager {
|
||||
}
|
||||
|
||||
private boolean canDaze(LivingEntity target) {
|
||||
return target instanceof Player && Permissions.daze(getPlayer()) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel);
|
||||
return target.isValid() && target instanceof Player && Permissions.daze(getPlayer()) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel);
|
||||
}
|
||||
|
||||
private boolean canUseSkillShot() {
|
||||
return getSkillLevel() >= Archery.skillShotIncreaseLevel && Permissions.bonusDamage(getPlayer(), skill);
|
||||
private boolean canUseSkillShot(LivingEntity target) {
|
||||
return target.isValid() && getSkillLevel() >= Archery.skillShotIncreaseLevel && Permissions.bonusDamage(getPlayer(), skill);
|
||||
}
|
||||
|
||||
private boolean canTrack(Arrow arrow) {
|
||||
return Permissions.arrowRetrieval(getPlayer()) && !arrow.hasMetadata(mcMMO.infiniteArrowKey) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.retrieveMaxChance, Archery.retrieveMaxBonusLevel);
|
||||
private boolean canTrackArrows(LivingEntity target, Arrow arrow) {
|
||||
return target.isValid() && Permissions.arrowRetrieval(getPlayer()) && !arrow.hasMetadata(mcMMO.infiniteArrowKey) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.retrieveMaxChance, Archery.retrieveMaxBonusLevel);
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,13 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.skills.axes.McMMOPlayerAxeMasteryEvent;
|
||||
import com.gmail.nossr50.events.skills.axes.McMMOPlayerCriticalHitEvent;
|
||||
import com.gmail.nossr50.events.skills.axes.McMMOPlayerGreaterImpactEvent;
|
||||
import com.gmail.nossr50.events.skills.axes.McMMOPlayerImpactEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
@ -22,24 +26,20 @@ public class AxesManager extends SkillManager {
|
||||
super(mcMMOPlayer, SkillType.AXES);
|
||||
}
|
||||
|
||||
public boolean canUseAxeMastery() {
|
||||
return Permissions.bonusDamage(getPlayer(), skill);
|
||||
private boolean canUseAxeMastery(LivingEntity target) {
|
||||
return target.isValid() && Permissions.bonusDamage(getPlayer(), skill);
|
||||
}
|
||||
|
||||
public boolean canCriticalHit(LivingEntity target) {
|
||||
return target.isValid() && Permissions.criticalStrikes(getPlayer());
|
||||
private boolean canCriticalHit(LivingEntity target) {
|
||||
return target.isValid() && Permissions.criticalStrikes(getPlayer()) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel);
|
||||
}
|
||||
|
||||
public boolean canImpact(LivingEntity target) {
|
||||
return target.isValid() && Permissions.armorImpact(getPlayer()) && Axes.hasArmor(target);
|
||||
private boolean canImpact(LivingEntity target) {
|
||||
return target.isValid() && Axes.hasArmor(target) && Permissions.armorImpact(getPlayer());
|
||||
}
|
||||
|
||||
public boolean canGreaterImpact(LivingEntity target) {
|
||||
return target.isValid() && Permissions.greaterImpact(getPlayer()) && !Axes.hasArmor(target);
|
||||
}
|
||||
|
||||
public boolean canUseSkullSplitter(LivingEntity target) {
|
||||
return target.isValid() && mcMMOPlayer.getAbilityMode(AbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer());
|
||||
private boolean canUseGreaterImpact(LivingEntity target) {
|
||||
return target.isValid() && !Axes.hasArmor(target) && Permissions.greaterImpact(getPlayer()) && (Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,9 +48,18 @@ public class AxesManager extends SkillManager {
|
||||
* @param target The {@link LivingEntity} being affected by the ability
|
||||
*/
|
||||
public double axeMastery(LivingEntity target) {
|
||||
double axeBonus = Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus);
|
||||
if (!canUseAxeMastery(target)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return CombatUtils.callFakeDamageEvent(getPlayer(), target, axeBonus);
|
||||
McMMOPlayerAxeMasteryEvent event = new McMMOPlayerAxeMasteryEvent(getPlayer(), target, calculateAxeMasteryBonus());
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return event.getDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,24 +69,27 @@ public class AxesManager extends SkillManager {
|
||||
* @param damage The amount of damage initially dealt by the event
|
||||
*/
|
||||
public double criticalHit(LivingEntity target, double damage) {
|
||||
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) {
|
||||
if (!canCriticalHit(target)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Player player = getPlayer();
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
|
||||
|
||||
if (target instanceof Player) {
|
||||
boolean targetIsPlayer = target instanceof Player;
|
||||
|
||||
if (targetIsPlayer) {
|
||||
((Player) target).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
|
||||
|
||||
damage = (damage * Axes.criticalHitPVPModifier) - damage;
|
||||
}
|
||||
else {
|
||||
damage = (damage * Axes.criticalHitPVEModifier) - damage;
|
||||
}
|
||||
|
||||
return CombatUtils.callFakeDamageEvent(player, target, damage);
|
||||
McMMOPlayerCriticalHitEvent event = new McMMOPlayerCriticalHitEvent(player, target, calculateCriticalHitBonus(damage, targetIsPlayer));
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return event.getDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,12 +97,29 @@ public class AxesManager extends SkillManager {
|
||||
*
|
||||
* @param target The {@link LivingEntity} being affected by Impact
|
||||
*/
|
||||
public void impactCheck(LivingEntity target) {
|
||||
public void impact(LivingEntity target) {
|
||||
if (!canImpact(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getPlayer();
|
||||
int durabilityDamage = 1 + (getSkillLevel() / Axes.impactIncreaseLevel);
|
||||
McMMOPlayerImpactEvent event;
|
||||
|
||||
for (ItemStack armor : target.getEquipment().getArmorContents()) {
|
||||
if (ItemUtils.isArmor(armor) && Axes.impactChance > Misc.getRandom().nextInt(getActivationChance())) {
|
||||
//<<<<<<< HEAD
|
||||
SkillUtils.handleDurabilityChange(armor, durabilityDamage, Axes.impactMaxDurabilityModifier);
|
||||
//=======
|
||||
// event = new McMMOPlayerImpactEvent(player, armor, calculateImpactDurabilityDamage(durabilityDamage, armor));
|
||||
// mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
//
|
||||
// if (event.isCancelled()) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// armor.setDurability((short) (event.getDurabilityDamage() + armor.getDurability()));
|
||||
//>>>>>>> Axe events.
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,14 +130,21 @@ public class AxesManager extends SkillManager {
|
||||
* @param target The {@link LivingEntity} being affected by the ability
|
||||
*/
|
||||
public double greaterImpact(LivingEntity target) {
|
||||
if (!(Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance()))) {
|
||||
if (!canUseGreaterImpact(target)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Player player = getPlayer();
|
||||
|
||||
McMMOPlayerGreaterImpactEvent event = new McMMOPlayerGreaterImpactEvent(player, target, Axes.greaterImpactBonusDamage, player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ParticleEffectUtils.playGreaterImpactEffect(target);
|
||||
target.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
|
||||
target.setVelocity(event.getKnockbackVelocity());
|
||||
|
||||
if (mcMMOPlayer.useChatNotifications()) {
|
||||
player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
|
||||
@ -122,7 +158,7 @@ public class AxesManager extends SkillManager {
|
||||
}
|
||||
}
|
||||
|
||||
return CombatUtils.callFakeDamageEvent(player, target, Axes.greaterImpactBonusDamage);
|
||||
return event.getDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,7 +167,15 @@ public class AxesManager extends SkillManager {
|
||||
* @param target The {@link LivingEntity} being affected by the ability
|
||||
* @param damage The amount of damage initially dealt by the event
|
||||
*/
|
||||
public void skullSplitterCheck(LivingEntity target, double damage) {
|
||||
public void skullSplitter(LivingEntity target, double damage) {
|
||||
CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Axes.skullSplitterModifier, skill);
|
||||
}
|
||||
|
||||
private double calculateAxeMasteryBonus() {
|
||||
return Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus);
|
||||
}
|
||||
|
||||
private double calculateCriticalHitBonus(double damage, boolean isPlayer) {
|
||||
return (damage * (isPlayer ? Axes.criticalHitPVPModifier : Axes.criticalHitPVEModifier)) - damage;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||
@ -28,10 +27,6 @@ public class SwordsManager extends SkillManager {
|
||||
return target instanceof LivingEntity && Permissions.counterAttack(getPlayer());
|
||||
}
|
||||
|
||||
public boolean canUseSerratedStrike() {
|
||||
return mcMMOPlayer.getAbilityMode(AbilityType.SERRATED_STRIKES) && Permissions.serratedStrikes(getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Bleed effect.
|
||||
*
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
||||
@ -54,9 +55,7 @@ public final class CombatUtils {
|
||||
swordsManager.bleedCheck(target);
|
||||
}
|
||||
|
||||
if (swordsManager.canUseSerratedStrike()) {
|
||||
swordsManager.serratedStrikes(target, damage);
|
||||
}
|
||||
swordsManager.serratedStrikes(target, damage);
|
||||
|
||||
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
|
||||
}
|
||||
@ -70,24 +69,12 @@ public final class CombatUtils {
|
||||
|
||||
mcMMOPlayer.checkAbilityActivation(SkillType.AXES);
|
||||
|
||||
if (axesManager.canUseAxeMastery()) {
|
||||
bonusDamage += axesManager.axeMastery(target);
|
||||
}
|
||||
bonusDamage += axesManager.axeMastery(target);
|
||||
bonusDamage += axesManager.criticalHit(target, initialDamage);
|
||||
bonusDamage += axesManager.greaterImpact(target);
|
||||
|
||||
if (axesManager.canCriticalHit(target)) {
|
||||
bonusDamage += axesManager.criticalHit(target, initialDamage);
|
||||
}
|
||||
|
||||
if (axesManager.canImpact(target)) {
|
||||
axesManager.impactCheck(target);
|
||||
}
|
||||
else if (axesManager.canGreaterImpact(target)) {
|
||||
bonusDamage += axesManager.greaterImpact(target);
|
||||
}
|
||||
|
||||
if (axesManager.canUseSkullSplitter(target)) {
|
||||
axesManager.skullSplitterCheck(target, initialDamage);
|
||||
}
|
||||
axesManager.impact(target);
|
||||
axesManager.skullSplitter(target, initialDamage);
|
||||
|
||||
event.setDamage(initialDamage + bonusDamage);
|
||||
startGainXp(mcMMOPlayer, target, SkillType.AXES);
|
||||
@ -328,9 +315,15 @@ public final class CombatUtils {
|
||||
* @param attacker The attacking player
|
||||
* @param target The defending entity
|
||||
* @param damage The initial damage amount
|
||||
* @param type The type of skill being used
|
||||
* @param skill The type of skill being used
|
||||
*/
|
||||
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, SkillType type) {
|
||||
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, SkillType skill) {
|
||||
AbilityType ability = skill.getAbility();
|
||||
|
||||
if (!target.isValid() || !UserManager.getPlayer(attacker).getAbilityMode(ability) || !ability.getPermissions(attacker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit
|
||||
double damageAmount = Math.max(damage, 1);
|
||||
|
||||
@ -346,7 +339,7 @@ public final class CombatUtils {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
EventUtils.callFakeArmSwingEvent(attacker);
|
||||
|
||||
switch (type) {
|
||||
switch (skill) {
|
||||
case SWORDS:
|
||||
if (entity instanceof Player) {
|
||||
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
||||
|
Loading…
Reference in New Issue
Block a user