2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.util.skills;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-08-23 10:16:22 +02:00
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
2019-01-28 03:11:51 +01:00
|
|
|
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
2019-01-22 00:14:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
|
|
|
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-06-08 23:48:41 +02:00
|
|
|
import com.gmail.nossr50.party.PartyManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.runnables.skills.AwardCombatXpTask;
|
|
|
|
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
2013-03-03 16:09:41 +01:00
|
|
|
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
|
|
|
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
|
|
|
import com.gmail.nossr50.skills.axes.AxesManager;
|
|
|
|
import com.gmail.nossr50.skills.swords.SwordsManager;
|
|
|
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
|
|
|
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.util.*;
|
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2014-06-29 14:11:38 +02:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.GameMode;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.*;
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.projectiles.ProjectileSource;
|
|
|
|
|
|
|
|
import java.util.EnumMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2014-06-29 14:11:38 +02:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public final class CombatUtils {
|
|
|
|
private CombatUtils() {}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2014-06-29 14:11:38 +02:00
|
|
|
private static void processSwordCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
|
2017-03-07 03:03:15 +01:00
|
|
|
if (event.getCause() == DamageCause.THORNS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
|
2014-06-29 14:11:38 +02:00
|
|
|
double initialDamage = event.getDamage();
|
2019-01-24 01:01:30 +01:00
|
|
|
|
2014-06-29 14:11:38 +02:00
|
|
|
Map<DamageModifier, Double> modifiers = getModifiers(event);
|
2013-06-07 19:55:49 +02:00
|
|
|
|
|
|
|
if (swordsManager.canActivateAbility()) {
|
2019-01-13 08:54:53 +01:00
|
|
|
mcMMOPlayer.checkAbilityActivation(PrimarySkillType.SWORDS);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 01:21:34 +01:00
|
|
|
if(target.getHealth() - event.getFinalDamage() >= 1)
|
|
|
|
{
|
|
|
|
if (swordsManager.canUseRupture()) {
|
|
|
|
swordsManager.ruptureCheck(target);
|
|
|
|
}
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (swordsManager.canUseSerratedStrike()) {
|
2014-06-29 14:11:38 +02:00
|
|
|
swordsManager.serratedStrikes(target, initialDamage, modifiers);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
startGainXp(mcMMOPlayer, target, PrimarySkillType.SWORDS);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void processAxeCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
|
2017-03-07 03:03:15 +01:00
|
|
|
if (event.getCause() == DamageCause.THORNS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
double initialDamage = event.getDamage();
|
|
|
|
double finalDamage = initialDamage;
|
2014-06-29 16:38:40 +02:00
|
|
|
Map<DamageModifier, Double> modifiers = getModifiers(event);
|
2013-09-12 17:52:34 +02:00
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
AxesManager axesManager = mcMMOPlayer.getAxesManager();
|
|
|
|
|
|
|
|
if (axesManager.canActivateAbility()) {
|
2019-01-13 08:54:53 +01:00
|
|
|
mcMMOPlayer.checkAbilityActivation(PrimarySkillType.AXES);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (axesManager.canUseAxeMastery()) {
|
2014-06-29 16:38:40 +02:00
|
|
|
finalDamage += axesManager.axeMastery();
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (axesManager.canCriticalHit(target)) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += axesManager.criticalHit(target, initialDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (axesManager.canImpact(target)) {
|
|
|
|
axesManager.impactCheck(target);
|
|
|
|
}
|
|
|
|
else if (axesManager.canGreaterImpact(target)) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += axesManager.greaterImpact(target);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (axesManager.canUseSkullSplitter(target)) {
|
2014-06-29 16:38:40 +02:00
|
|
|
axesManager.skullSplitterCheck(target, initialDamage, modifiers);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
applyScaledModifiers(initialDamage, finalDamage, event);
|
2019-01-13 08:54:53 +01:00
|
|
|
startGainXp(mcMMOPlayer, target, PrimarySkillType.AXES);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void processUnarmedCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
|
2017-03-07 03:03:15 +01:00
|
|
|
if (event.getCause() == DamageCause.THORNS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
double initialDamage = event.getDamage();
|
|
|
|
double finalDamage = initialDamage;
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
|
|
|
|
|
|
|
if (unarmedManager.canActivateAbility()) {
|
2019-01-13 08:54:53 +01:00
|
|
|
mcMMOPlayer.checkAbilityActivation(PrimarySkillType.UNARMED);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unarmedManager.canUseIronArm()) {
|
2014-06-29 16:38:40 +02:00
|
|
|
finalDamage += unarmedManager.ironArm();
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unarmedManager.canUseBerserk()) {
|
2014-06-29 16:38:40 +02:00
|
|
|
finalDamage += unarmedManager.berserkDamage(initialDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unarmedManager.canDisarm(target)) {
|
|
|
|
unarmedManager.disarmCheck((Player) target);
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
applyScaledModifiers(initialDamage, finalDamage, event);
|
2019-01-13 08:54:53 +01:00
|
|
|
startGainXp(mcMMOPlayer, target, PrimarySkillType.UNARMED);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void processTamingCombat(LivingEntity target, Player master, Wolf wolf, EntityDamageByEntityEvent event) {
|
2013-09-12 17:52:34 +02:00
|
|
|
double initialDamage = event.getDamage();
|
|
|
|
double finalDamage = initialDamage;
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
|
|
|
|
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
|
|
|
|
|
|
|
if (tamingManager.canUseFastFoodService()) {
|
|
|
|
tamingManager.fastFoodService(wolf, event.getDamage());
|
|
|
|
}
|
|
|
|
|
2013-09-17 00:55:38 +02:00
|
|
|
tamingManager.pummel(target, wolf);
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
if (tamingManager.canUseSharpenedClaws()) {
|
2014-06-29 16:38:40 +02:00
|
|
|
finalDamage += tamingManager.sharpenedClaws();
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tamingManager.canUseGore()) {
|
2014-06-29 16:38:40 +02:00
|
|
|
finalDamage += tamingManager.gore(target, initialDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
applyScaledModifiers(initialDamage, finalDamage, event);
|
2019-01-13 08:54:53 +01:00
|
|
|
startGainXp(mcMMOPlayer, target, PrimarySkillType.TAMING);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) {
|
2013-09-12 17:52:34 +02:00
|
|
|
double initialDamage = event.getDamage();
|
|
|
|
double finalDamage = initialDamage;
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (target instanceof Player && PrimarySkillType.UNARMED.getPVPEnabled()) {
|
2013-06-07 19:55:49 +02:00
|
|
|
UnarmedManager unarmedManager = UserManager.getPlayer((Player) target).getUnarmedManager();
|
|
|
|
|
|
|
|
if (unarmedManager.canDeflect()) {
|
|
|
|
event.setCancelled(unarmedManager.deflectCheck());
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 16:17:24 +02:00
|
|
|
if (archeryManager.canSkillShot()) {
|
2014-06-29 16:38:40 +02:00
|
|
|
finalDamage += archeryManager.skillShot(initialDamage);
|
2013-09-11 16:17:24 +02:00
|
|
|
}
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
if (archeryManager.canDaze(target)) {
|
2014-06-29 16:38:40 +02:00
|
|
|
finalDamage += archeryManager.daze((Player) target);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2013-11-22 18:32:23 +01:00
|
|
|
if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canRetrieveArrows()) {
|
|
|
|
archeryManager.retrieveArrows(target);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
archeryManager.distanceXpBonus(target, arrow);
|
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
applyScaledModifiers(initialDamage, finalDamage, event);
|
2019-01-13 08:54:53 +01:00
|
|
|
startGainXp(mcMMOPlayer, target, PrimarySkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
/**
|
|
|
|
* Apply combat modifiers and process and XP gain.
|
|
|
|
*
|
|
|
|
* @param event The event to run the combat checks on.
|
|
|
|
*/
|
2013-06-07 19:55:49 +02:00
|
|
|
public static void processCombatAttack(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
|
2013-02-22 15:53:18 +01:00
|
|
|
Entity damager = event.getDamager();
|
2013-10-31 20:03:06 +01:00
|
|
|
EntityType entityType = damager.getType();
|
2012-05-21 10:44:48 +02:00
|
|
|
|
2013-10-31 20:03:06 +01:00
|
|
|
if (attacker instanceof Player && entityType == EntityType.PLAYER) {
|
2013-01-25 05:54:07 +01:00
|
|
|
Player player = (Player) attacker;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2014-02-16 00:11:15 +01:00
|
|
|
if (!UserManager.hasPlayerDataKey(player)) {
|
2013-01-25 02:10:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
2013-01-25 02:10:50 +01:00
|
|
|
|
2013-03-03 14:21:19 +01:00
|
|
|
if (target instanceof Tameable) {
|
2013-03-04 15:40:03 +01:00
|
|
|
if (heldItem.getType() == Material.BONE) {
|
2013-06-07 19:55:49 +02:00
|
|
|
TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager();
|
2013-03-04 15:40:03 +01:00
|
|
|
|
|
|
|
if (tamingManager.canUseBeastLore()) {
|
|
|
|
tamingManager.beastLore(target);
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2013-03-03 14:21:19 +01:00
|
|
|
}
|
2013-03-07 15:18:27 +01:00
|
|
|
|
|
|
|
if (isFriendlyPet(player, (Tameable) target)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-03 14:21:19 +01:00
|
|
|
}
|
2013-03-03 14:38:00 +01:00
|
|
|
|
|
|
|
if (ItemUtils.isSword(heldItem)) {
|
2019-01-13 08:54:53 +01:00
|
|
|
if (!PrimarySkillType.SWORDS.shouldProcess(target)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (PrimarySkillType.SWORDS.getPermissions(player)) {
|
2014-06-29 16:38:40 +02:00
|
|
|
processSwordCombat(target, player, event);
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
else if (ItemUtils.isAxe(heldItem)) {
|
2019-01-13 08:54:53 +01:00
|
|
|
if (!PrimarySkillType.AXES.shouldProcess(target)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (PrimarySkillType.AXES.getPermissions(player)) {
|
2013-06-07 19:55:49 +02:00
|
|
|
processAxeCombat(target, player, event);
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2014-12-29 06:12:46 +01:00
|
|
|
else if (ItemUtils.isUnarmed(heldItem)) {
|
2019-01-13 08:54:53 +01:00
|
|
|
if (!PrimarySkillType.UNARMED.shouldProcess(target)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (PrimarySkillType.UNARMED.getPermissions(player)) {
|
2013-06-07 19:55:49 +02:00
|
|
|
processUnarmedCombat(target, player, event);
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2013-01-25 05:54:07 +01:00
|
|
|
}
|
2012-06-22 18:54:49 +02:00
|
|
|
|
2013-10-31 20:03:06 +01:00
|
|
|
else if (entityType == EntityType.WOLF) {
|
2013-07-17 16:29:42 +02:00
|
|
|
Wolf wolf = (Wolf) damager;
|
|
|
|
AnimalTamer tamer = wolf.getOwner();
|
2013-01-25 23:21:18 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (tamer != null && tamer instanceof Player && PrimarySkillType.TAMING.shouldProcess(target)) {
|
2013-06-07 19:55:49 +02:00
|
|
|
Player master = (Player) tamer;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (!Misc.isNPCEntity(master) && PrimarySkillType.TAMING.getPermissions(master)) {
|
2013-06-07 19:55:49 +02:00
|
|
|
processTamingCombat(target, master, wolf, event);
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
2013-07-17 16:29:42 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-31 20:03:06 +01:00
|
|
|
else if (entityType == EntityType.ARROW) {
|
2013-08-23 16:58:50 +02:00
|
|
|
Arrow arrow = (Arrow) damager;
|
2014-02-01 00:33:28 +01:00
|
|
|
ProjectileSource projectileSource = arrow.getShooter();
|
2013-03-04 15:40:03 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (projectileSource != null && projectileSource instanceof Player && PrimarySkillType.ARCHERY.shouldProcess(target)) {
|
2014-02-01 00:33:28 +01:00
|
|
|
Player player = (Player) projectileSource;
|
2013-03-04 15:40:03 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (!Misc.isNPCEntity(player) && PrimarySkillType.ARCHERY.getPermissions(player)) {
|
2013-08-23 16:58:50 +02:00
|
|
|
processArcheryCombat(target, player, event, arrow);
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
2014-04-18 23:15:20 +02:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntity(player) && PrimarySkillType.TAMING.getPermissions(player)) {
|
2014-04-18 23:15:20 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
|
|
|
tamingManager.attackTarget(target);
|
|
|
|
}
|
2013-07-17 16:29:42 +02:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2013-03-03 21:42:56 +01:00
|
|
|
if (target instanceof Player) {
|
2013-06-07 19:55:49 +02:00
|
|
|
if (Misc.isNPCEntity(target)) {
|
2013-01-25 23:21:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
Player player = (Player) target;
|
2014-08-08 05:46:22 +02:00
|
|
|
if (!UserManager.hasPlayerDataKey(player)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-03 16:09:41 +01:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
2013-01-25 23:21:18 +01:00
|
|
|
|
2014-04-18 00:49:40 +02:00
|
|
|
if (acrobaticsManager.canDodge(target)) {
|
2013-03-03 16:09:41 +01:00
|
|
|
event.setDamage(acrobaticsManager.dodgeCheck(event.getDamage()));
|
2013-02-26 00:00:15 +01:00
|
|
|
}
|
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
if (ItemUtils.isSword(player.getInventory().getItemInMainHand())) {
|
2019-01-13 08:54:53 +01:00
|
|
|
if (!PrimarySkillType.SWORDS.shouldProcess(target)) {
|
2013-02-28 17:52:56 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-02-02 20:23:40 +01:00
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-03-05 03:59:16 +01:00
|
|
|
if (swordsManager.canUseCounterAttack(damager)) {
|
2013-03-04 15:40:03 +01:00
|
|
|
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
|
|
|
}
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to damage target for value dmg with reason CUSTOM
|
|
|
|
*
|
|
|
|
* @param target LivingEntity which to attempt to damage
|
2013-08-23 16:58:50 +02:00
|
|
|
* @param damage Amount of damage to attempt to do
|
2012-04-27 11:47:11 +02:00
|
|
|
*/
|
2014-06-29 16:38:40 +02:00
|
|
|
@Deprecated
|
2013-08-23 16:58:50 +02:00
|
|
|
public static void dealDamage(LivingEntity target, double damage) {
|
2013-09-12 17:52:34 +02:00
|
|
|
dealDamage(target, damage, DamageCause.CUSTOM, null);
|
2013-08-23 16:58:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-06-29 14:11:38 +02:00
|
|
|
@Deprecated
|
2013-09-12 17:52:34 +02:00
|
|
|
public static void dealDamage(LivingEntity target, double damage, LivingEntity attacker) {
|
|
|
|
dealDamage(target, damage, DamageCause.ENTITY_ATTACK, attacker);
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 14:11:38 +02:00
|
|
|
/**
|
|
|
|
* 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, Map<DamageModifier, Double> modifiers, LivingEntity attacker) {
|
|
|
|
if (target.isDead()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aren't we applying the damage twice????
|
|
|
|
target.damage(callFakeDamageEvent(attacker, target, damage, modifiers));
|
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
/**
|
|
|
|
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
|
|
|
|
*
|
|
|
|
* @param target LivingEntity which to attempt to damage
|
2013-08-23 16:58:50 +02:00
|
|
|
* @param damage Amount of damage to attempt to do
|
2012-04-27 11:47:11 +02:00
|
|
|
* @param attacker Player to pass to event as damager
|
|
|
|
*/
|
2014-06-29 16:38:40 +02:00
|
|
|
@Deprecated
|
2013-09-12 17:52:34 +02:00
|
|
|
public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) {
|
2013-08-28 17:29:30 +02:00
|
|
|
if (target.isDead()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
target.damage(callFakeDamageEvent(attacker, target, cause, damage));
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2019-01-22 00:14:01 +01:00
|
|
|
public static void dealNoInvulnerabilityTickDamage(LivingEntity target, double damage, Entity attacker) {
|
|
|
|
if (target.isDead()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double incDmg = callFakeDamageEvent(attacker, target, DamageCause.CUSTOM, damage);
|
|
|
|
|
2019-01-24 01:08:41 +01:00
|
|
|
double newHealth = Math.max(0, target.getHealth() - incDmg);
|
|
|
|
target.setHealth(newHealth);
|
2019-01-22 00:14:01 +01:00
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
/**
|
|
|
|
* Apply Area-of-Effect ability actions.
|
|
|
|
*
|
|
|
|
* @param attacker The attacking player
|
|
|
|
* @param target The defending entity
|
|
|
|
* @param damage The initial damage amount
|
|
|
|
* @param type The type of skill being used
|
|
|
|
*/
|
2019-01-13 08:54:53 +01:00
|
|
|
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, Map<DamageModifier, Double> modifiers, PrimarySkillType type) {
|
2016-03-11 15:20:23 +01:00
|
|
|
int numberOfTargets = getTier(attacker.getInventory().getItemInMainHand()); // The higher the weapon tier, the more targets you hit
|
2013-07-11 18:43:36 +02:00
|
|
|
double damageAmount = Math.max(damage, 1);
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
|
|
|
if (numberOfTargets <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
if (Misc.isNPCEntity(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-18 14:50:14 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
LivingEntity livingEntity = (LivingEntity) entity;
|
2013-10-18 14:31:00 +02:00
|
|
|
EventUtils.callFakeArmSwingEvent(attacker);
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
switch (type) {
|
|
|
|
case SWORDS:
|
|
|
|
if (entity instanceof Player) {
|
2019-01-14 07:21:16 +01:00
|
|
|
NotificationManager.sendPlayerInformation((Player)entity, NotificationType.SUBSKILL_MESSAGE, "Swords.Combat.SS.Struck");
|
2013-05-22 06:01:19 +02:00
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2019-01-24 00:29:31 +01:00
|
|
|
BleedTimerTask.add(livingEntity, attacker, UserManager.getPlayer(attacker).getSwordsManager().getRuptureBleedTicks(), RankUtils.getRank(attacker, SubSkillType.SWORDS_RUPTURE));
|
2013-05-22 06:01:19 +02:00
|
|
|
break;
|
2012-05-03 16:39:17 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
case AXES:
|
|
|
|
if (entity instanceof Player) {
|
2019-01-14 07:21:16 +01:00
|
|
|
NotificationManager.sendPlayerInformation((Player)entity, NotificationType.SUBSKILL_MESSAGE, "Axes.Combat.SS.Struck");
|
2013-05-22 06:01:19 +02:00
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
break;
|
2012-05-03 16:39:17 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
default:
|
|
|
|
break;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2013-05-22 06:01:19 +02:00
|
|
|
|
2014-08-14 05:24:32 +02:00
|
|
|
dealDamage(livingEntity, damageAmount, attacker);
|
2013-05-22 06:01:19 +02:00
|
|
|
numberOfTargets--;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType) {
|
|
|
|
startGainXp(mcMMOPlayer, target, primarySkillType, 1.0);
|
2013-05-15 07:19:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
/**
|
|
|
|
* Start the task that gives combat XP.
|
|
|
|
*
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer The attacking player
|
2012-04-27 11:47:11 +02:00
|
|
|
* @param target The defending entity
|
2019-01-13 08:54:53 +01:00
|
|
|
* @param primarySkillType The skill being used
|
2012-04-27 11:47:11 +02:00
|
|
|
*/
|
2019-01-13 08:54:53 +01:00
|
|
|
private static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType, double multiplier) {
|
2012-04-27 11:47:11 +02:00
|
|
|
double baseXP = 0;
|
2014-04-18 21:56:03 +02:00
|
|
|
XPGainReason xpGainReason;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
if (target instanceof Player) {
|
2019-01-22 00:43:54 +01:00
|
|
|
if (!ExperienceConfig.getInstance().getExperienceGainsPlayerVersusPlayerEnabled() || PartyManager.inSameParty(mcMMOPlayer.getPlayer(), (Player) target)) {
|
2012-04-27 11:47:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-18 21:56:03 +02:00
|
|
|
xpGainReason = XPGainReason.PVP;
|
2012-04-27 11:47:11 +02:00
|
|
|
Player defender = (Player) target;
|
|
|
|
|
2013-09-22 22:58:12 +02:00
|
|
|
if (defender.isOnline() && SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) {
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP = 20 * ExperienceConfig.getInstance().getPlayerVersusPlayerXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-15 06:31:00 +02:00
|
|
|
else {
|
2014-02-03 20:48:43 +01:00
|
|
|
if (mcMMO.getModManager().isCustomEntity(target)) {
|
|
|
|
baseXP = mcMMO.getModManager().getEntity(target).getXpMultiplier();
|
2013-09-24 18:24:59 +02:00
|
|
|
}
|
|
|
|
else if (target instanceof Animals) {
|
2016-12-05 03:42:26 +01:00
|
|
|
EntityType type = target.getType();
|
2016-12-05 02:53:51 +01:00
|
|
|
baseXP = ExperienceConfig.getInstance().getAnimalsXP(type);
|
|
|
|
}
|
|
|
|
else if (target instanceof Monster)
|
|
|
|
{
|
|
|
|
EntityType type = target.getType();
|
2018-05-16 17:07:07 +02:00
|
|
|
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EntityType type = target.getType();
|
|
|
|
|
|
|
|
if (ExperienceConfig.getInstance().hasCombatXP(type)) {
|
|
|
|
if (type == EntityType.IRON_GOLEM)
|
|
|
|
{
|
|
|
|
if (!((IronGolem) target).isPlayerCreated()) {
|
|
|
|
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
2017-04-15 06:04:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-16 17:07:07 +02:00
|
|
|
baseXP = 1.0;
|
|
|
|
mcMMO.getModManager().addCustomEntity(target);
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2013-05-26 17:55:24 +02:00
|
|
|
}
|
2013-05-15 06:31:00 +02:00
|
|
|
|
2013-05-26 17:55:24 +02:00
|
|
|
if (target.hasMetadata(mcMMO.entityMetadataKey)) {
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP *= ExperienceConfig.getInstance().getSpawnedMobXpMultiplier();
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2015-01-10 12:31:13 +01:00
|
|
|
if (target.hasMetadata(mcMMO.bredMetadataKey)) {
|
|
|
|
baseXP *= ExperienceConfig.getInstance().getBredMobXpMultiplier();
|
|
|
|
}
|
|
|
|
|
2014-04-18 21:56:03 +02:00
|
|
|
xpGainReason = XPGainReason.PVE;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
baseXP *= 10;
|
|
|
|
}
|
|
|
|
|
2013-05-15 07:19:14 +02:00
|
|
|
baseXP *= multiplier;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
if (baseXP != 0) {
|
2019-01-13 08:54:53 +01:00
|
|
|
new AwardCombatXpTask(mcMMOPlayer, primarySkillType, baseXP, target, xpGainReason).runTaskLater(mcMMO.p, 0);
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
2012-06-18 14:50:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if the given LivingEntity should be affected by a combat ability.
|
|
|
|
*
|
|
|
|
* @param player The attacking Player
|
2013-01-31 01:42:40 +01:00
|
|
|
* @param entity The defending Entity
|
2012-06-22 23:10:17 +02:00
|
|
|
* @return true if the Entity should be damaged, false otherwise.
|
2012-06-18 14:50:14 +02:00
|
|
|
*/
|
2013-10-18 14:31:00 +02:00
|
|
|
private static boolean shouldBeAffected(Player player, Entity entity) {
|
2012-06-22 23:10:17 +02:00
|
|
|
if (entity instanceof Player) {
|
|
|
|
Player defender = (Player) entity;
|
2012-06-21 15:04:45 +02:00
|
|
|
|
2013-03-03 17:06:05 +01:00
|
|
|
if (!defender.getWorld().getPVP() || defender == player || UserManager.getPlayer(defender).getGodMode()) {
|
2013-02-05 14:35:51 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-28 22:08:48 +01:00
|
|
|
if ((PartyManager.inSameParty(player, defender) || PartyManager.areAllies(player, defender)) && !(Permissions.friendlyFire(player) && Permissions.friendlyFire(defender))) {
|
2012-06-21 15:04:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2014-04-05 13:12:20 +02:00
|
|
|
// Vanished players should not be able to get hit by AoE effects
|
|
|
|
if (!player.canSee(defender)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-02 04:21:22 +02:00
|
|
|
|
|
|
|
// Spectators should not be affected
|
|
|
|
if (defender.getGameMode() == GameMode.SPECTATOR) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-05 13:12:20 +02:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
// It may seem a bit redundant but we need a check here to prevent bleed from being applied in applyAbilityAoE()
|
2013-10-18 14:31:00 +02:00
|
|
|
if (callFakeDamageEvent(player, entity, 1.0) == 0) {
|
2012-08-14 23:21:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-06-22 23:10:17 +02:00
|
|
|
else if (entity instanceof Tameable) {
|
2013-02-18 16:22:16 +01:00
|
|
|
if (isFriendlyPet(player, (Tameable) entity)) {
|
2013-02-08 00:46:41 +01:00
|
|
|
// isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party
|
|
|
|
// So we can make some assumptions here, about our casting and our check
|
|
|
|
Player owner = (Player) ((Tameable) entity).getOwner();
|
|
|
|
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire(owner))) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-18 14:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 15:04:45 +02:00
|
|
|
return true;
|
2012-06-18 14:50:14 +02:00
|
|
|
}
|
2013-02-18 16:22:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an entity is currently invincible.
|
|
|
|
*
|
2013-02-22 18:10:15 +01:00
|
|
|
* @param entity The {@link LivingEntity} to check
|
|
|
|
* @param eventDamage The damage from the event the entity is involved in
|
2013-02-18 16:22:16 +01:00
|
|
|
* @return true if the entity is invincible, false otherwise
|
|
|
|
*/
|
2013-07-11 18:43:36 +02:00
|
|
|
public static boolean isInvincible(LivingEntity entity, double eventDamage) {
|
2013-02-18 16:22:16 +01:00
|
|
|
/*
|
|
|
|
* So apparently if you do more damage to a LivingEntity than its last damage int you bypass the invincibility.
|
|
|
|
* So yeah, this is for that.
|
|
|
|
*/
|
2013-05-21 19:27:52 +02:00
|
|
|
return (entity.getNoDamageTicks() > entity.getMaximumNoDamageTicks() / 2.0F) && (eventDamage <= entity.getLastDamage());
|
2013-02-18 16:22:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an entity is currently friendly toward a given player.
|
|
|
|
*
|
|
|
|
* @param attacker The player to check.
|
|
|
|
* @param pet The entity to check.
|
|
|
|
* @return true if the entity is friendly, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isFriendlyPet(Player attacker, Tameable pet) {
|
|
|
|
if (pet.isTamed()) {
|
|
|
|
AnimalTamer tamer = pet.getOwner();
|
|
|
|
|
|
|
|
if (tamer instanceof Player) {
|
|
|
|
Player owner = (Player) tamer;
|
|
|
|
|
2014-02-28 22:08:48 +01:00
|
|
|
return (owner == attacker || PartyManager.inSameParty(attacker, owner) || PartyManager.areAllies(attacker, owner));
|
2013-02-18 16:22:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-03 21:42:56 +01:00
|
|
|
|
2014-06-29 14:11:38 +02:00
|
|
|
@Deprecated
|
2013-10-18 14:31:00 +02:00
|
|
|
public static double callFakeDamageEvent(Entity attacker, Entity target, double damage) {
|
2014-06-29 14:11:38 +02:00
|
|
|
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause damageCause, double damage) {
|
2014-07-11 21:33:35 +02:00
|
|
|
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, damageCause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, damageCause, damage);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
|
|
|
|
|
|
|
|
if (damageEvent.isCancelled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return damageEvent.getFinalDamage();
|
2013-09-12 17:52:34 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 14:11:38 +02:00
|
|
|
public static double callFakeDamageEvent(Entity attacker, Entity target, Map<DamageModifier, Double> modifiers) {
|
|
|
|
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, modifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double callFakeDamageEvent(Entity attacker, Entity target, double damage, Map<DamageModifier, Double> modifiers) {
|
2014-06-29 16:38:40 +02:00
|
|
|
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, getScaledModifiers(damage, modifiers));
|
2014-06-29 14:11:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static double callFakeDamageEvent(Entity attacker, Entity target, DamageCause cause, Map<DamageModifier, Double> modifiers) {
|
2014-07-11 21:33:35 +02:00
|
|
|
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, modifiers) : new FakeEntityDamageByEntityEvent(attacker, target, cause, modifiers);
|
2014-06-29 15:13:06 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
|
2014-06-29 14:11:38 +02:00
|
|
|
|
2014-06-29 15:13:06 +02:00
|
|
|
if (damageEvent.isCancelled()) {
|
|
|
|
return 0;
|
2014-06-29 14:11:38 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 15:13:06 +02:00
|
|
|
return damageEvent.getFinalDamage();
|
2014-06-29 14:11:38 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
private static Map<DamageModifier, Double> getModifiers(EntityDamageEvent event) {
|
2014-06-29 14:11:38 +02:00
|
|
|
Map<DamageModifier, Double> modifiers = new HashMap<DamageModifier, Double>();
|
|
|
|
for (DamageModifier modifier : DamageModifier.values()) {
|
|
|
|
modifiers.put(modifier, event.getDamage(modifier));
|
|
|
|
}
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
private static Map<DamageModifier, Double> getScaledModifiers(double damage, Map<DamageModifier, Double> modifiers) {
|
2014-06-29 14:11:38 +02:00
|
|
|
Map<DamageModifier, Double> scaledModifiers = new HashMap<DamageModifier, Double>();
|
|
|
|
|
2014-07-03 12:33:03 +02:00
|
|
|
for (DamageModifier modifier : modifiers.keySet()) {
|
2014-06-29 14:11:38 +02:00
|
|
|
if (modifier == DamageModifier.BASE) {
|
2014-07-03 12:33:03 +02:00
|
|
|
scaledModifiers.put(modifier, damage);
|
2014-06-29 14:11:38 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
scaledModifiers.put(modifier, damage * modifiers.get(modifier));
|
2013-09-12 17:52:34 +02:00
|
|
|
}
|
|
|
|
|
2014-06-29 14:11:38 +02:00
|
|
|
return scaledModifiers;
|
2013-09-12 17:52:34 +02:00
|
|
|
}
|
2014-01-03 17:07:13 +01:00
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
public static EntityDamageByEntityEvent applyScaledModifiers(double initialDamage, double finalDamage, EntityDamageByEntityEvent event) {
|
|
|
|
// No additional damage
|
|
|
|
if (initialDamage == finalDamage) {
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (DamageModifier modifier : DamageModifier.values()) {
|
|
|
|
if (!event.isApplicable(modifier)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modifier == DamageModifier.BASE) {
|
|
|
|
event.setDamage(modifier, finalDamage);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setDamage(modifier, finalDamage / initialDamage * event.getDamage(modifier));
|
|
|
|
}
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2014-01-03 17:07:13 +01:00
|
|
|
/**
|
|
|
|
* Get the upgrade tier of the item in hand.
|
|
|
|
*
|
|
|
|
* @param inHand The item to check the tier of
|
|
|
|
* @return the tier of the item
|
|
|
|
*/
|
|
|
|
private static int getTier(ItemStack inHand) {
|
|
|
|
int tier = 0;
|
|
|
|
|
|
|
|
if (ItemUtils.isWoodTool(inHand)) {
|
|
|
|
tier = 1;
|
|
|
|
}
|
|
|
|
else if (ItemUtils.isStoneTool(inHand)) {
|
|
|
|
tier = 2;
|
|
|
|
}
|
|
|
|
else if (ItemUtils.isIronTool(inHand)) {
|
|
|
|
tier = 3;
|
|
|
|
}
|
|
|
|
else if (ItemUtils.isGoldTool(inHand)) {
|
|
|
|
tier = 1;
|
|
|
|
}
|
|
|
|
else if (ItemUtils.isDiamondTool(inHand)) {
|
|
|
|
tier = 4;
|
|
|
|
}
|
2014-02-03 20:48:43 +01:00
|
|
|
else if (mcMMO.getModManager().isCustomTool(inHand)) {
|
|
|
|
tier = mcMMO.getModManager().getTool(inHand).getTier();
|
2014-01-03 17:07:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return tier;
|
|
|
|
}
|
2014-03-03 16:29:14 +01:00
|
|
|
|
2019-01-15 16:19:00 +01:00
|
|
|
public static void handleHealthbars(Entity attacker, LivingEntity target, double damage, mcMMO plugin) {
|
2014-03-03 16:29:14 +01:00
|
|
|
if (!(attacker instanceof Player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = (Player) attacker;
|
|
|
|
|
|
|
|
if (Misc.isNPCEntity(player) || Misc.isNPCEntity(target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-07 17:23:02 +02:00
|
|
|
if (!player.hasMetadata(mcMMO.playerDataKey)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-24 00:39:04 +01:00
|
|
|
MobHealthbarUtils.handleMobHealthbars(target, damage, plugin);
|
2014-03-03 16:29:14 +01:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|