2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.util.skills;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
import org.bukkit.Material;
|
2013-02-18 16:22:16 +01:00
|
|
|
import org.bukkit.entity.AnimalTamer;
|
2012-04-27 11:47:11 +02:00
|
|
|
import org.bukkit.entity.Animals;
|
2012-05-24 21:26:01 +02:00
|
|
|
import org.bukkit.entity.Arrow;
|
2012-04-27 11:47:11 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.IronGolem;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
2012-12-30 21:33:38 +01:00
|
|
|
import org.bukkit.entity.Skeleton;
|
2012-05-21 10:44:48 +02:00
|
|
|
import org.bukkit.entity.Tameable;
|
2012-04-27 11:47:11 +02:00
|
|
|
import org.bukkit.entity.Wolf;
|
|
|
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-08-23 10:16:22 +02:00
|
|
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
|
|
|
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
2013-05-21 19:36:44 +02:00
|
|
|
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
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;
|
2012-06-18 14:50:14 +02:00
|
|
|
import com.gmail.nossr50.skills.swords.Swords;
|
2013-03-03 16:09:41 +01:00
|
|
|
import com.gmail.nossr50.skills.swords.SwordsManager;
|
|
|
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
|
|
|
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.ItemUtils;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-04-24 17:40:34 +02:00
|
|
|
import com.gmail.nossr50.util.MobHealthbarUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.ModUtils;
|
2013-01-25 23:21:18 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public final class CombatUtils {
|
|
|
|
private CombatUtils() {}
|
2013-01-26 23:01:55 +01:00
|
|
|
|
2013-07-11 18:43:36 +02:00
|
|
|
private static void processSwordCombat(LivingEntity target, Player player, double damage) {
|
2013-06-07 19:55:49 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
|
|
|
|
|
|
|
|
if (swordsManager.canActivateAbility()) {
|
2013-10-15 19:03:33 +02:00
|
|
|
mcMMOPlayer.checkAbilityActivation(SkillType.SWORDS);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (swordsManager.canUseBleed()) {
|
|
|
|
swordsManager.bleedCheck(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swordsManager.canUseSerratedStrike()) {
|
|
|
|
swordsManager.serratedStrikes(target, damage);
|
|
|
|
}
|
|
|
|
|
|
|
|
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void processAxeCombat(LivingEntity target, Player player, 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(player);
|
|
|
|
AxesManager axesManager = mcMMOPlayer.getAxesManager();
|
|
|
|
|
|
|
|
if (axesManager.canActivateAbility()) {
|
2013-10-15 19:03:33 +02:00
|
|
|
mcMMOPlayer.checkAbilityActivation(SkillType.AXES);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (axesManager.canUseAxeMastery()) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += axesManager.axeMastery(target);
|
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)) {
|
2013-09-12 17:52:34 +02:00
|
|
|
axesManager.skullSplitterCheck(target, initialDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
event.setDamage(finalDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
startGainXp(mcMMOPlayer, target, SkillType.AXES);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void processUnarmedCombat(LivingEntity target, Player player, 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(player);
|
|
|
|
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
|
|
|
|
|
|
|
if (unarmedManager.canActivateAbility()) {
|
2013-10-15 19:03:33 +02:00
|
|
|
mcMMOPlayer.checkAbilityActivation(SkillType.UNARMED);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unarmedManager.canUseIronArm()) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += unarmedManager.ironArm(target);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unarmedManager.canUseBerserk()) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += unarmedManager.berserkDamage(target, initialDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unarmedManager.canDisarm(target)) {
|
|
|
|
unarmedManager.disarmCheck((Player) target);
|
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
event.setDamage(finalDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tamingManager.canUseSharpenedClaws()) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += tamingManager.sharpenedClaws(target, wolf);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tamingManager.canUseGore()) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += tamingManager.gore(target, initialDamage, wolf);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
event.setDamage(finalDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled()) {
|
|
|
|
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()) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += archeryManager.skillShot(target, initialDamage, arrow);
|
2013-09-11 16:17:24 +02:00
|
|
|
}
|
|
|
|
|
2013-06-07 19:55:49 +02:00
|
|
|
if (archeryManager.canDaze(target)) {
|
2013-09-12 17:52:34 +02:00
|
|
|
finalDamage += archeryManager.daze((Player) target, arrow);
|
2013-06-07 19:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) {
|
|
|
|
archeryManager.trackArrows(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
archeryManager.distanceXpBonus(target, arrow);
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
event.setDamage(finalDamage);
|
2013-06-07 19:55:49 +02:00
|
|
|
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
|
|
|
|
}
|
|
|
|
|
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();
|
2012-05-21 10:44:48 +02:00
|
|
|
|
2013-02-22 15:53:18 +01:00
|
|
|
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
|
2013-01-25 05:54:07 +01:00
|
|
|
Player player = (Player) attacker;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-02-19 01:46:50 +01:00
|
|
|
if (Misc.isNPCEntity(player)) {
|
2013-01-25 02:10:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-25 05:54:07 +01:00
|
|
|
ItemStack heldItem = player.getItemInHand();
|
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)) {
|
2013-03-03 21:42:56 +01:00
|
|
|
if (!shouldProcessSkill(target, SkillType.SWORDS)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2013-02-19 06:56:25 +01:00
|
|
|
if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
|
2013-06-07 19:55:49 +02:00
|
|
|
processSwordCombat(target, player, event.getDamage());
|
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)) {
|
2013-03-03 21:42:56 +01:00
|
|
|
if (!shouldProcessSkill(target, SkillType.AXES)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2013-02-19 06:56:25 +01:00
|
|
|
if (Permissions.skillEnabled(player, SkillType.AXES)) {
|
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
|
|
|
}
|
2013-03-03 14:21:19 +01:00
|
|
|
else if (heldItem.getType() == Material.AIR) {
|
2013-03-03 21:42:56 +01:00
|
|
|
if (!shouldProcessSkill(target, SkillType.UNARMED)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2013-02-19 06:56:25 +01:00
|
|
|
if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
|
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-07-17 16:29:42 +02:00
|
|
|
/* Temporary fix for MCPC+
|
|
|
|
*
|
|
|
|
* This will be reverted back to the switch statement once the fix is addressed on their end.
|
|
|
|
*/
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-08-20 20:10:49 +02:00
|
|
|
else if (damager.getType() == 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
|
|
|
|
2013-07-17 16:29:42 +02:00
|
|
|
if (tamer != null && tamer instanceof Player && shouldProcessSkill(target, SkillType.TAMING)) {
|
2013-06-07 19:55:49 +02:00
|
|
|
Player master = (Player) tamer;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-07-17 16:29:42 +02:00
|
|
|
if (!Misc.isNPCEntity(master) && Permissions.skillEnabled(master, SkillType.TAMING)) {
|
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-08-20 20:10:49 +02:00
|
|
|
else if (damager.getType() == EntityType.ARROW) {
|
2013-08-23 16:58:50 +02:00
|
|
|
Arrow arrow = (Arrow) damager;
|
|
|
|
LivingEntity shooter = arrow.getShooter();
|
2013-03-04 15:40:03 +01:00
|
|
|
|
2013-07-17 16:29:42 +02:00
|
|
|
if (shooter != null && shooter instanceof Player && shouldProcessSkill(target, SkillType.ARCHERY)) {
|
2013-03-04 15:40:03 +01:00
|
|
|
Player player = (Player) shooter;
|
|
|
|
|
2013-07-17 16:29:42 +02:00
|
|
|
if (!Misc.isNPCEntity(player) && Permissions.skillEnabled(player, SkillType.ARCHERY)) {
|
2013-08-23 16:58:50 +02:00
|
|
|
processArcheryCombat(target, player, event, arrow);
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
2013-07-17 16:29:42 +02:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 16:29:42 +02:00
|
|
|
// switch (damager.getType()) {
|
|
|
|
// case WOLF:
|
|
|
|
// Wolf wolf = (Wolf) damager;
|
|
|
|
// AnimalTamer tamer = wolf.getOwner();
|
|
|
|
//
|
|
|
|
// if (tamer == null || !(tamer instanceof Player) || !shouldProcessSkill(target, SkillType.TAMING)) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Player master = (Player) tamer;
|
|
|
|
//
|
|
|
|
// if (Misc.isNPCEntity(master)) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (Permissions.skillEnabled(master, SkillType.TAMING)) {
|
|
|
|
// processTamingCombat(target, master, wolf, event);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// break;
|
|
|
|
//
|
|
|
|
// case ARROW:
|
|
|
|
// LivingEntity shooter = ((Arrow) damager).getShooter();
|
|
|
|
//
|
|
|
|
// if (shooter == null || !(shooter instanceof Player) || !shouldProcessSkill(target, SkillType.ARCHERY)) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Player player = (Player) shooter;
|
|
|
|
//
|
|
|
|
// if (Misc.isNPCEntity(player)) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (Permissions.skillEnabled(player, SkillType.ARCHERY)) {
|
|
|
|
// processArcheryCombat(target, player, event, damager);
|
|
|
|
// }
|
|
|
|
// break;
|
|
|
|
//
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
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;
|
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
|
|
|
|
2013-03-03 16:09:41 +01:00
|
|
|
if (acrobaticsManager.canDodge(damager)) {
|
|
|
|
event.setDamage(acrobaticsManager.dodgeCheck(event.getDamage()));
|
2013-02-26 00:00:15 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
if (ItemUtils.isSword(player.getItemInHand())) {
|
|
|
|
if (!shouldProcessSkill(target, SkillType.SWORDS)) {
|
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
|
|
|
}
|
2013-04-05 04:11:11 +02:00
|
|
|
else if (attacker instanceof Player) {
|
|
|
|
Player player = (Player) attacker;
|
2013-04-23 05:19:26 +02:00
|
|
|
|
|
|
|
if (Misc.isNPCEntity(player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-24 17:40:34 +02:00
|
|
|
MobHealthbarUtils.handleMobHealthbars(player, target, event.getDamage());
|
2013-04-05 04:11:11 +02: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
|
|
|
*/
|
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
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2013-07-11 18:43:36 +02:00
|
|
|
public static void applyAbilityAoE(Player attacker, LivingEntity target, double damage, SkillType type) {
|
2013-03-01 06:52:01 +01:00
|
|
|
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); // 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;
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(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) {
|
|
|
|
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
BleedTimerTask.add(livingEntity, Swords.serratedStrikesBleedTicks);
|
|
|
|
break;
|
2012-05-03 16:39:17 +02:00
|
|
|
|
2013-05-22 06:01:19 +02:00
|
|
|
case AXES:
|
|
|
|
if (entity instanceof Player) {
|
2013-07-15 13:18:03 +02:00
|
|
|
((Player) entity).sendMessage(LocaleLoader.getString("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
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
dealDamage(livingEntity, damageAmount, attacker);
|
2013-05-22 06:01:19 +02:00
|
|
|
numberOfTargets--;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-15 07:19:14 +02:00
|
|
|
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType) {
|
|
|
|
startGainXp(mcMMOPlayer, target, skillType, 1.0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
* @param skillType The skill being used
|
|
|
|
*/
|
2013-09-24 18:24:59 +02:00
|
|
|
private static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType, double multiplier) {
|
2012-04-27 11:47:11 +02:00
|
|
|
double baseXP = 0;
|
|
|
|
|
|
|
|
if (target instanceof Player) {
|
2013-08-23 10:16:22 +02:00
|
|
|
if (!ExperienceConfig.getInstance().getExperienceGainsPlayerVersusPlayerEnabled()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2013-09-24 18:24:59 +02:00
|
|
|
if (ModUtils.isCustomEntity(target)) {
|
|
|
|
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
|
|
|
|
}
|
|
|
|
else if (target instanceof Animals) {
|
|
|
|
baseXP = ExperienceConfig.getInstance().getAnimalsXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
EntityType type = target.getType();
|
|
|
|
|
|
|
|
switch (type) {
|
2013-03-01 06:52:01 +01:00
|
|
|
case BAT:
|
2013-09-09 16:46:26 +02:00
|
|
|
case SQUID:
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP = ExperienceConfig.getInstance().getAnimalsXP();
|
2013-03-01 06:52:01 +01:00
|
|
|
break;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
case BLAZE:
|
|
|
|
case CAVE_SPIDER:
|
|
|
|
case CREEPER:
|
|
|
|
case ENDERMAN:
|
|
|
|
case GHAST:
|
|
|
|
case GIANT:
|
|
|
|
case MAGMA_CUBE:
|
|
|
|
case PIG_ZOMBIE:
|
|
|
|
case SILVERFISH:
|
|
|
|
case SLIME:
|
|
|
|
case SPIDER:
|
|
|
|
case ZOMBIE:
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
2012-12-30 21:33:38 +01:00
|
|
|
break;
|
2013-02-13 22:34:36 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
case SKELETON:
|
|
|
|
switch (((Skeleton) target).getSkeletonType()) {
|
|
|
|
case WITHER:
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP = ExperienceConfig.getInstance().getWitherSkeletonXP();
|
2013-03-01 06:52:01 +01:00
|
|
|
break;
|
|
|
|
default:
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
2013-03-01 06:52:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IRON_GOLEM:
|
|
|
|
if (!((IronGolem) target).isPlayerCreated()) {
|
2013-08-23 10:16:22 +02:00
|
|
|
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-09-25 16:42:19 +02:00
|
|
|
baseXP = 1.0;
|
|
|
|
ModUtils.addCustomEntity(target);
|
2013-03-01 06:52:01 +01:00
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
baseXP *= 10;
|
|
|
|
}
|
|
|
|
|
2013-05-15 07:19:14 +02:00
|
|
|
baseXP *= multiplier;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
if (baseXP != 0) {
|
2013-03-20 08:11:16 +01:00
|
|
|
new AwardCombatXpTask(mcMMOPlayer, skillType, baseXP, target).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
|
|
|
*/
|
2012-06-22 23:10:17 +02:00
|
|
|
public static boolean shouldBeAffected(Player player, Entity entity) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-08 00:46:41 +01:00
|
|
|
if (PartyManager.inSameParty(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
|
|
|
|
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()
|
2012-08-14 23:21:07 +02:00
|
|
|
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(player, entity, EntityDamageEvent.DamageCause.ENTITY_ATTACK, 1);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
|
|
|
|
|
|
|
if (ede.isCancelled()) {
|
|
|
|
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;
|
|
|
|
|
2013-05-23 04:30:09 +02:00
|
|
|
return (owner == attacker || PartyManager.inSameParty(attacker, owner));
|
2013-02-18 16:22:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-03 21:42:56 +01:00
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
public static boolean shouldProcessSkill(Entity target, SkillType skill) {
|
2013-05-21 19:36:44 +02:00
|
|
|
return (target instanceof Player || (target instanceof Tameable && ((Tameable) target).isTamed())) ? skill.getPVPEnabled() : skill.getPVEEnabled();
|
2013-03-03 21:42:56 +01:00
|
|
|
}
|
2013-09-12 17:52:34 +02:00
|
|
|
|
|
|
|
public static double callFakeDamageEvent(LivingEntity attacker, LivingEntity target, double damage) {
|
|
|
|
return callFakeDamageEvent(attacker, target, DamageCause.ENTITY_ATTACK, damage);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double callFakeDamageEvent(Entity attacker, LivingEntity target, DamageCause cause, double damage) {
|
|
|
|
if (Config.getInstance().getEventCallbackEnabled()) {
|
|
|
|
EntityDamageEvent damageEvent = attacker == null ? new FakeEntityDamageEvent(target, cause, damage) : new FakeEntityDamageByEntityEvent(attacker, target, cause, damage);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(damageEvent);
|
|
|
|
|
|
|
|
if (damageEvent.isCancelled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
damage = damageEvent.getDamage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return damage;
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|