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;
|
2019-05-15 00:14:30 +02:00
|
|
|
import com.gmail.nossr50.datatypes.meta.OldName;
|
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-03-28 00:30:29 +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;
|
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;
|
2019-05-15 00:14:30 +02:00
|
|
|
import org.bukkit.metadata.MetadataValue;
|
2019-01-15 07:11:58 +01:00
|
|
|
import org.bukkit.projectiles.ProjectileSource;
|
|
|
|
|
|
|
|
import java.util.EnumMap;
|
|
|
|
import java.util.HashMap;
|
2019-05-15 00:14:30 +02:00
|
|
|
import java.util.List;
|
2019-01-15 07:11:58 +01:00
|
|
|
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-03-28 00:30:29 +01:00
|
|
|
double finalDamage = initialDamage;
|
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
|
|
|
}
|
|
|
|
|
2019-03-27 20:11:11 +01:00
|
|
|
//Add Stab Damage
|
|
|
|
if(swordsManager.canUseStab())
|
|
|
|
{
|
2019-03-28 00:30:29 +01:00
|
|
|
finalDamage+=swordsManager.getStabDamage();
|
2019-03-27 20:11:11 +01:00
|
|
|
}
|
|
|
|
|
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-03-28 00:30:29 +01:00
|
|
|
if(canUseLimitBreak(player, SubSkillType.SWORDS_SWORDS_LIMIT_BREAK))
|
|
|
|
{
|
|
|
|
finalDamage+=getLimitBreakDamage(player, SubSkillType.SWORDS_SWORDS_LIMIT_BREAK);
|
|
|
|
}
|
|
|
|
|
|
|
|
applyScaledModifiers(initialDamage, finalDamage, event);
|
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()) {
|
2019-03-28 00:30:29 +01:00
|
|
|
finalDamage+=axesManager.axeMastery();
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (axesManager.canImpact(target)) {
|
|
|
|
axesManager.impactCheck(target);
|
|
|
|
}
|
|
|
|
else if (axesManager.canGreaterImpact(target)) {
|
2019-03-28 00:30:29 +01: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
|
|
|
}
|
|
|
|
|
2019-03-28 00:30:29 +01:00
|
|
|
if (axesManager.canCriticalHit(target)) {
|
|
|
|
finalDamage+=axesManager.criticalHit(target, finalDamage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(canUseLimitBreak(player, SubSkillType.AXES_AXES_LIMIT_BREAK))
|
|
|
|
{
|
|
|
|
finalDamage+=getLimitBreakDamage(player, SubSkillType.AXES_AXES_LIMIT_BREAK);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2019-03-28 00:30:29 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-03 22:17:42 +01:00
|
|
|
if(unarmedManager.isPunchingCooldownOver())
|
|
|
|
{
|
2019-03-28 00:30:29 +01:00
|
|
|
//Only execute bonuses if the player is not spamming
|
2019-02-03 22:17:42 +01:00
|
|
|
if (unarmedManager.canUseIronArm()) {
|
2019-03-28 00:30:29 +01:00
|
|
|
finalDamage+=unarmedManager.ironArm();
|
2019-02-03 22:17:42 +01:00
|
|
|
}
|
2013-06-07 19:55:49 +02:00
|
|
|
|
2019-02-03 22:17:42 +01:00
|
|
|
if (unarmedManager.canUseBerserk()) {
|
2019-03-28 00:30:29 +01:00
|
|
|
finalDamage+=unarmedManager.berserkDamage(finalDamage);
|
2019-02-03 22:17:42 +01:00
|
|
|
}
|
2013-06-07 19:55:49 +02:00
|
|
|
|
2019-02-03 22:17:42 +01:00
|
|
|
if (unarmedManager.canDisarm(target)) {
|
|
|
|
unarmedManager.disarmCheck((Player) target);
|
|
|
|
}
|
2019-03-28 00:30:29 +01:00
|
|
|
|
|
|
|
if(canUseLimitBreak(player, SubSkillType.UNARMED_UNARMED_LIMIT_BREAK))
|
|
|
|
{
|
|
|
|
finalDamage+=getLimitBreakDamage(player, SubSkillType.UNARMED_UNARMED_LIMIT_BREAK);
|
|
|
|
}
|
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.UNARMED);
|
2019-06-30 21:19:45 +02:00
|
|
|
unarmedManager.setLastAttacked(System.currentTimeMillis()); //Track how often the player is punching
|
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()) {
|
2019-03-28 00:30:29 +01:00
|
|
|
finalDamage+=tamingManager.sharpenedClaws();
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tamingManager.canUseGore()) {
|
2019-03-28 00:30:29 +01: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();
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
2019-03-28 00:30:29 +01:00
|
|
|
|
|
|
|
double finalDamage = event.getDamage();
|
2013-06-07 19:55:49 +02:00
|
|
|
|
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()) {
|
2019-03-28 00:30:29 +01: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)) {
|
2019-03-28 00:30:29 +01: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()) {
|
2019-06-18 22:06:26 +02:00
|
|
|
archeryManager.retrieveArrows(target, arrow);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2019-03-28 00:30:29 +01:00
|
|
|
if(canUseLimitBreak(player, SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK))
|
|
|
|
{
|
|
|
|
finalDamage+=getLimitBreakDamage(player, SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK);
|
|
|
|
}
|
|
|
|
|
2019-02-01 01:55:09 +01:00
|
|
|
double distanceMultiplier = archeryManager.distanceXpBonusMultiplier(target, arrow);
|
2019-06-26 07:29:02 +02:00
|
|
|
double forceMultiplier = 1.0; //Hacky Fix - some plugins spawn arrows and assign them to players after the ProjectileLaunchEvent fires
|
|
|
|
|
|
|
|
if(arrow.hasMetadata(mcMMO.bowForceKey))
|
|
|
|
forceMultiplier = arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble();
|
2013-06-07 19:55:49 +02:00
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
applyScaledModifiers(initialDamage, finalDamage, event);
|
2019-06-26 07:29:02 +02:00
|
|
|
startGainXp(mcMMOPlayer, target, PrimarySkillType.ARCHERY, forceMultiplier * distanceMultiplier);
|
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) {
|
2019-03-28 12:22:26 +01:00
|
|
|
Entity damager = event.getDamager();
|
|
|
|
EntityType entityType = damager.getType();
|
|
|
|
|
|
|
|
if (target instanceof Player) {
|
2019-06-17 16:00:39 +02:00
|
|
|
if (Misc.isNPCEntityExcludingVillagers(target)) {
|
2019-03-28 12:22:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player player = (Player) target;
|
|
|
|
if (!UserManager.hasPlayerDataKey(player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
|
|
|
|
|
|
|
if (acrobaticsManager.canDodge(target)) {
|
|
|
|
event.setDamage(acrobaticsManager.dodgeCheck(event.getDamage()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ItemUtils.isSword(player.getInventory().getItemInMainHand())) {
|
|
|
|
if (!PrimarySkillType.SWORDS.shouldProcess(target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
|
|
|
|
|
|
|
|
if (swordsManager.canUseCounterAttack(damager)) {
|
|
|
|
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2019-03-28 12:22:26 +01:00
|
|
|
Wolf wolf = (Wolf) damager;
|
2013-07-17 16:29:42 +02:00
|
|
|
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-06-17 16:00:39 +02:00
|
|
|
if (!Misc.isNPCEntityExcludingVillagers(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) {
|
2019-03-28 12:22:26 +01: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-06-17 16:00:39 +02:00
|
|
|
if (!Misc.isNPCEntityExcludingVillagers(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-06-17 16:00:39 +02:00
|
|
|
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(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
|
|
|
}
|
2019-05-15 00:14:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This cleans up names from displaying in chat as hearts
|
|
|
|
* @param entity target entity
|
|
|
|
*/
|
2019-05-15 00:29:15 +02:00
|
|
|
public static void fixNames(LivingEntity entity)
|
2019-05-15 00:14:30 +02:00
|
|
|
{
|
|
|
|
List<MetadataValue> metadataValue = entity.getMetadata("mcMMO_oldName");
|
|
|
|
|
|
|
|
if(metadataValue.size() <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(metadataValue != null)
|
|
|
|
{
|
|
|
|
OldName oldName = (OldName) metadataValue.get(0);
|
|
|
|
entity.setCustomName(oldName.asString());
|
|
|
|
entity.setCustomNameVisible(false);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2019-03-28 00:30:29 +01:00
|
|
|
public static int getLimitBreakDamage(Player player, SubSkillType subSkillType) {
|
|
|
|
return RankUtils.getRank(player, subSkillType);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if player has access to their weapons limit break
|
|
|
|
* @param player target player
|
|
|
|
* @return true if the player has access to the limit break
|
|
|
|
*/
|
|
|
|
public static boolean canUseLimitBreak(Player player, SubSkillType subSkillType) {
|
|
|
|
return RankUtils.hasUnlockedSubskill(player, subSkillType)
|
|
|
|
&& Permissions.isSubSkillEnabled(player, subSkillType);
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-01-28 07:26:45 +01:00
|
|
|
dealDamage(target, damage, DamageCause.CUSTOM, 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????
|
2019-03-24 22:20:20 +01:00
|
|
|
target.damage(getFakeDamageFinalResult(attacker, target, damage, modifiers));
|
2014-06-29 14:11:38 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-24 22:20:20 +01:00
|
|
|
if(canDamage(attacker, target, cause, damage))
|
|
|
|
target.damage(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;
|
|
|
|
}
|
|
|
|
|
2019-03-25 03:02:08 +01:00
|
|
|
double incDmg = getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, damage);
|
2019-01-22 00:14:01 +01:00
|
|
|
|
2019-01-24 01:08:41 +01:00
|
|
|
double newHealth = Math.max(0, target.getHealth() - incDmg);
|
2019-03-24 06:57:44 +01:00
|
|
|
|
|
|
|
if(newHealth == 0)
|
|
|
|
{
|
|
|
|
target.damage(9999, attacker);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
target.setHealth(newHealth);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void dealNoInvulnerabilityTickDamageRupture(LivingEntity target, double damage, Entity attacker, int toolTier) {
|
|
|
|
if (target.isDead()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
|
2019-03-25 03:02:08 +01:00
|
|
|
target.damage(damage, attacker);
|
|
|
|
|
|
|
|
// //IFrame storage
|
|
|
|
//// int noDamageTicks = target.getNoDamageTicks();
|
|
|
|
//
|
|
|
|
//// String debug = "BLEED DMG RESULT: INC DMG:"+damage+", HP-Before:"+target.getHealth()+", HP-After:";
|
|
|
|
//
|
|
|
|
//// double incDmg = getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, damage);
|
|
|
|
//
|
|
|
|
//// double newHealth = Math.max(0, target.getHealth() - incDmg);
|
|
|
|
//
|
|
|
|
// //Don't kill things with a stone or wooden weapon
|
|
|
|
//// if(toolTier < 3 && newHealth == 0)
|
|
|
|
//// return;
|
|
|
|
//
|
|
|
|
// target.setMetadata(mcMMO.CUSTOM_DAMAGE_METAKEY, mcMMO.metadataValue);
|
|
|
|
//
|
|
|
|
// if(newHealth == 0 && !(target instanceof Player))
|
|
|
|
// {
|
|
|
|
// target.damage(99999, attacker);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
//// Vector beforeRuptureVec = new Vector(target.getVelocity().getX(), target.getVelocity().getY(), target.getVelocity().getZ()); ;
|
|
|
|
// target.damage(damage, attacker);
|
|
|
|
//// debug+=target.getHealth();
|
|
|
|
// Bukkit.broadcastMessage(debug);
|
|
|
|
//// target.setNoDamageTicks(noDamageTicks); //Do not add additional IFrames
|
|
|
|
//// target.setVelocity(beforeRuptureVec);
|
|
|
|
// }
|
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
|
|
|
|
2019-06-17 16:00:39 +02:00
|
|
|
if (Misc.isNPCEntityExcludingVillagers(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
2013-05-22 06:01:19 +02:00
|
|
|
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-03-24 06:57:44 +01:00
|
|
|
UserManager.getPlayer(attacker).getSwordsManager().ruptureCheck(target);
|
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
|
|
|
|
2019-06-19 00:28:56 +02:00
|
|
|
if (target.hasMetadata(mcMMO.entityMetadataKey)
|
|
|
|
//Epic Spawners compatibility
|
|
|
|
|| target.hasMetadata("ES")) {
|
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
|
|
|
|
2019-04-13 00:17:05 +02:00
|
|
|
//TODO: NPC Interaction?
|
|
|
|
if(UserManager.getPlayer(defender) == null)
|
|
|
|
return true;
|
|
|
|
|
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()
|
2019-03-24 22:20:20 +01:00
|
|
|
if (getFakeDamageFinalResult(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
|
2019-03-24 22:20:20 +01:00
|
|
|
public static double getFakeDamageFinalResult(Entity attacker, Entity target, double damage) {
|
|
|
|
return getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, new EnumMap<DamageModifier, Double>(ImmutableMap.of(DamageModifier.BASE, damage)));
|
2014-06-29 14:11:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2019-03-24 22:20:20 +01:00
|
|
|
public static double getFakeDamageFinalResult(Entity attacker, Entity target, DamageCause damageCause, double damage) {
|
|
|
|
EntityDamageEvent damageEvent = sendEntityDamageEvent(attacker, target, damageCause, damage);
|
2014-07-11 21:33:35 +02:00
|
|
|
|
|
|
|
if (damageEvent.isCancelled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return damageEvent.getFinalDamage();
|
2013-09-12 17:52:34 +02:00
|
|
|
}
|
|
|
|
|
2019-03-24 22:20:20 +01:00
|
|
|
public static boolean canDamage(Entity attacker, Entity target, DamageCause damageCause, double damage) {
|
|
|
|
EntityDamageEvent damageEvent = sendEntityDamageEvent(attacker, target, damageCause, damage);
|
|
|
|
|
|
|
|
if (damageEvent.isCancelled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static EntityDamageEvent sendEntityDamageEvent(Entity attacker, Entity target, DamageCause damageCause, double damage) {
|
|
|
|
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, damageCause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, damageCause, damage);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
|
|
|
|
return damageEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double getFakeDamageFinalResult(Entity attacker, Entity target, Map<DamageModifier, Double> modifiers) {
|
|
|
|
return getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, modifiers);
|
2014-06-29 14:11:38 +02:00
|
|
|
}
|
|
|
|
|
2019-03-24 22:20:20 +01:00
|
|
|
public static double getFakeDamageFinalResult(Entity attacker, Entity target, double damage, Map<DamageModifier, Double> modifiers) {
|
|
|
|
return getFakeDamageFinalResult(attacker, target, DamageCause.ENTITY_ATTACK, getScaledModifiers(damage, modifiers));
|
2014-06-29 14:11:38 +02:00
|
|
|
}
|
|
|
|
|
2019-03-24 22:20:20 +01:00
|
|
|
public static double getFakeDamageFinalResult(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;
|
|
|
|
|
2019-06-17 16:00:39 +02:00
|
|
|
if (Misc.isNPCEntityExcludingVillagers(player) || Misc.isNPCEntityExcludingVillagers(target)) {
|
2014-03-03 16:29:14 +01:00
|
|
|
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
|
|
|
}
|