2013-01-22 18:43:25 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
import org.bukkit.Material;
|
2012-06-15 02:53:11 +02:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
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;
|
2013-01-13 22:03:49 +01:00
|
|
|
import org.bukkit.entity.LightningStrike;
|
2012-04-27 11:47:11 +02:00
|
|
|
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;
|
2012-05-24 14:38:44 +02:00
|
|
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
2012-04-27 11:47:11 +02:00
|
|
|
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;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
|
|
|
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2012-06-08 23:48:41 +02:00
|
|
|
import com.gmail.nossr50.party.PartyManager;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.runnables.BleedTimer;
|
2012-06-05 16:13:10 +02:00
|
|
|
import com.gmail.nossr50.runnables.GainXp;
|
2013-01-25 02:10:50 +01:00
|
|
|
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
|
2012-06-11 22:11:23 +02:00
|
|
|
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
2013-01-25 02:10:50 +01:00
|
|
|
import com.gmail.nossr50.skills.archery.Archery;
|
2012-06-13 03:36:01 +02:00
|
|
|
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
2013-01-11 04:39:08 +01:00
|
|
|
import com.gmail.nossr50.skills.axes.AxeManager;
|
2013-01-25 02:10:50 +01:00
|
|
|
import com.gmail.nossr50.skills.axes.Axes;
|
2012-06-18 14:50:14 +02:00
|
|
|
import com.gmail.nossr50.skills.swords.Swords;
|
2012-06-21 15:04:45 +02:00
|
|
|
import com.gmail.nossr50.skills.swords.SwordsManager;
|
2013-01-25 02:10:50 +01:00
|
|
|
import com.gmail.nossr50.skills.taming.Taming;
|
2012-06-12 17:07:51 +02:00
|
|
|
import com.gmail.nossr50.skills.taming.TamingManager;
|
2013-01-25 03:55:56 +01:00
|
|
|
import com.gmail.nossr50.skills.unarmed.Unarmed;
|
2012-06-15 03:10:47 +02:00
|
|
|
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.util.ItemChecks;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-01-25 23:21:18 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public final class Combat {
|
2012-05-03 16:39:17 +02:00
|
|
|
private static Config configInstance = Config.getInstance();
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-01-27 00:02:01 +01:00
|
|
|
private Combat() {}
|
2013-01-26 23:01:55 +01: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-01-25 05:54:07 +01:00
|
|
|
public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
|
2012-06-22 18:54:49 +02:00
|
|
|
boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
|
2012-05-21 10:44:48 +02:00
|
|
|
boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
|
|
|
|
|
2013-01-25 05:54:07 +01:00
|
|
|
if (attacker instanceof Player) {
|
|
|
|
Player player = (Player) attacker;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-01-25 05:54:07 +01:00
|
|
|
if (Misc.isNPCPlayer(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
|
|
|
Material heldItemType = heldItem.getType();
|
|
|
|
|
|
|
|
if (ItemChecks.isSword(heldItem)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
if (targetIsPlayer || targetIsTamedPet) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (!Swords.pvpEnabled) {
|
2012-05-03 16:39:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 02:10:50 +01:00
|
|
|
else if (!Swords.pveEnabled) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Permissions.swords(player)) {
|
|
|
|
SwordsManager swordsManager = new SwordsManager(player);
|
|
|
|
PlayerProfile profile = swordsManager.getProfile();
|
|
|
|
boolean canSerratedStrike = Permissions.serratedStrikes(player); //So we don't have to check the same permission twice
|
|
|
|
|
|
|
|
if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
|
2013-01-26 23:01:55 +01:00
|
|
|
SkillTools.abilityCheck(player, SkillType.SWORDS);
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
2012-06-22 20:20:28 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Permissions.swordsBleed(player) && shouldBeAffected(player, target)) {
|
|
|
|
swordsManager.bleedCheck(target);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (profile.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) {
|
|
|
|
swordsManager.serratedStrikes(target, event.getDamage());
|
|
|
|
}
|
|
|
|
|
|
|
|
startGainXp(player, profile, target, SkillType.SWORDS);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2013-01-25 02:10:50 +01:00
|
|
|
else if (ItemChecks.isAxe(heldItem)) {
|
2012-06-22 18:54:49 +02:00
|
|
|
if (targetIsPlayer || targetIsTamedPet) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (!Axes.pvpEnabled) {
|
2012-05-03 16:39:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 02:10:50 +01:00
|
|
|
else if (!Axes.pveEnabled) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Permissions.axes(player)) {
|
|
|
|
AxeManager axeManager = new AxeManager(player);
|
|
|
|
PlayerProfile profile = axeManager.getProfile();
|
|
|
|
boolean canSkullSplit = Permissions.skullSplitter(player); //So we don't have to check the same permission twice
|
|
|
|
if (profile.getToolPreparationMode(ToolType.AXE) && canSkullSplit) {
|
2013-01-26 23:01:55 +01:00
|
|
|
SkillTools.abilityCheck(player, SkillType.AXES);
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Permissions.axeBonus(player)) {
|
|
|
|
axeManager.bonusDamage(event);
|
|
|
|
}
|
2012-06-22 20:20:28 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (!target.isDead() && Permissions.criticalHit(player) && shouldBeAffected(player, target)) {
|
|
|
|
axeManager.criticalHitCheck(event, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!target.isDead() && Permissions.impact(player)) {
|
|
|
|
axeManager.impact(event, target);
|
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (!target.isDead() && profile.getAbilityMode(AbilityType.SKULL_SPLIITER) && canSkullSplit) {
|
|
|
|
axeManager.skullSplitter(target, event.getDamage());
|
|
|
|
}
|
|
|
|
|
|
|
|
startGainXp(player, profile, target, SkillType.AXES);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2013-01-25 02:10:50 +01:00
|
|
|
else if (heldItemType == Material.AIR) {
|
2012-06-22 18:54:49 +02:00
|
|
|
if (targetIsPlayer || targetIsTamedPet) {
|
|
|
|
if (!configInstance.getUnarmedPVP()) {
|
2012-05-03 16:39:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-22 18:54:49 +02:00
|
|
|
else if (!configInstance.getUnarmedPVE()) {
|
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Permissions.unarmed(player)) {
|
|
|
|
UnarmedManager unarmedManager = new UnarmedManager(player);
|
|
|
|
PlayerProfile profile = unarmedManager.getProfile();
|
|
|
|
boolean canBerserk = Permissions.berserk(player); //So we don't have to check the same permission twice
|
|
|
|
|
|
|
|
if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
|
2013-01-26 23:01:55 +01:00
|
|
|
SkillTools.abilityCheck(player, SkillType.UNARMED);
|
2013-01-25 23:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Permissions.unarmedBonus(player)) {
|
|
|
|
unarmedManager.bonusDamage(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
|
|
|
|
unarmedManager.berserkDamage(event);
|
|
|
|
}
|
2012-06-22 20:20:28 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (target instanceof Player && Permissions.disarm(player)) {
|
|
|
|
unarmedManager.disarmCheck(target);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
startGainXp(player, unarmedManager.getProfile(), target, SkillType.UNARMED);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2013-01-25 23:21:18 +01:00
|
|
|
else if (heldItemType == Material.BONE && target instanceof Tameable && Permissions.beastLore(player)) {
|
2013-01-25 05:54:07 +01:00
|
|
|
TamingManager tamingManager = new TamingManager(player);
|
2012-06-12 20:42:38 +02:00
|
|
|
tamingManager.beastLore(target);
|
|
|
|
event.setCancelled(true);
|
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-01-25 05:54:07 +01:00
|
|
|
Entity damager = event.getDamager();
|
2012-07-03 03:05:55 +02:00
|
|
|
|
2013-01-25 05:54:07 +01:00
|
|
|
switch (damager.getType()) {
|
2012-06-22 18:54:49 +02:00
|
|
|
case WOLF:
|
2013-01-25 05:54:07 +01:00
|
|
|
Wolf wolf = (Wolf) damager;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
|
|
|
|
Player master = (Player) wolf.getOwner();
|
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Misc.isNPCPlayer(master)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-22 18:54:49 +02:00
|
|
|
if (targetIsPlayer || targetIsTamedPet) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (!Taming.pvpEnabled) {
|
2012-05-03 16:39:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 02:10:50 +01:00
|
|
|
else if (!Taming.pveEnabled) {
|
2012-06-22 18:54:49 +02:00
|
|
|
return;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Permissions.taming(master)) {
|
|
|
|
TamingManager tamingManager = new TamingManager(master);
|
|
|
|
int skillLevel = tamingManager.getSkillLevel();
|
|
|
|
|
|
|
|
if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(master)) {
|
|
|
|
tamingManager.fastFoodService(wolf, event.getDamage());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(master)) {
|
|
|
|
tamingManager.sharpenedClaws(event);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Permissions.gore(master)) {
|
|
|
|
tamingManager.gore(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target != master) {
|
|
|
|
startGainXp(master, tamingManager.getProfile(), target, SkillType.TAMING);
|
|
|
|
}
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2012-06-22 18:54:49 +02:00
|
|
|
|
|
|
|
break;
|
2012-07-03 03:05:55 +02:00
|
|
|
|
2012-06-22 18:54:49 +02:00
|
|
|
case ARROW:
|
2013-01-25 05:54:07 +01:00
|
|
|
LivingEntity shooter = ((Arrow) damager).getShooter();
|
2012-06-05 16:31:55 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
/* Break instead of return due to Dodge/Counter/Deflect abilities */
|
|
|
|
if (shooter == null || !(shooter instanceof Player)) {
|
2012-06-22 19:39:14 +02:00
|
|
|
break;
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-05 15:47:52 +02:00
|
|
|
if (targetIsPlayer || targetIsTamedPet) {
|
2013-01-25 02:10:50 +01:00
|
|
|
if (!Archery.pvpEnabled) {
|
2012-05-03 16:39:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 02:10:50 +01:00
|
|
|
else if (!Archery.pveEnabled) {
|
2012-06-05 15:47:52 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-05-03 16:39:17 +02:00
|
|
|
|
2012-06-05 16:31:55 +02:00
|
|
|
archeryCheck((Player) shooter, target, event);
|
2012-06-22 18:54:49 +02:00
|
|
|
break;
|
2012-07-03 01:26:40 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2012-06-22 19:39:14 +02:00
|
|
|
if (targetIsPlayer) {
|
2012-06-21 15:04:45 +02:00
|
|
|
Player player = (Player) target;
|
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Misc.isNPCPlayer(player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack heldItem = player.getItemInHand();
|
|
|
|
|
2013-01-25 05:54:07 +01:00
|
|
|
if (damager instanceof Player) {
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Swords.pvpEnabled && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
|
2013-01-25 03:55:56 +01:00
|
|
|
SwordsManager swordsManager = new SwordsManager(player);
|
2013-01-25 05:54:07 +01:00
|
|
|
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
2012-06-22 15:47:18 +02:00
|
|
|
}
|
2012-05-03 16:39:17 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Acrobatics.pvpEnabled && Permissions.dodge(player)) {
|
2013-01-25 03:55:56 +01:00
|
|
|
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
|
2013-01-25 02:10:50 +01:00
|
|
|
acrobaticsManager.dodgeCheck(event);
|
2012-06-22 18:54:49 +02:00
|
|
|
}
|
2013-01-25 03:55:56 +01:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Unarmed.pvpEnabled && heldItem.getType() == Material.AIR && Permissions.deflect(player)) {
|
2013-01-25 03:55:56 +01:00
|
|
|
UnarmedManager unarmedManager = new UnarmedManager(player);
|
|
|
|
unarmedManager.deflectCheck(event);
|
|
|
|
}
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
2012-06-22 18:54:49 +02:00
|
|
|
else {
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Swords.pveEnabled && damager instanceof LivingEntity && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
|
2013-01-25 03:55:56 +01:00
|
|
|
SwordsManager swordsManager = new SwordsManager(player);
|
2013-01-25 05:54:07 +01:00
|
|
|
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
2012-06-22 18:54:49 +02:00
|
|
|
}
|
2012-05-03 16:39:17 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Acrobatics.pveEnabled && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) && Permissions.dodge(player)) {
|
|
|
|
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
|
|
|
|
acrobaticsManager.dodgeCheck(event);
|
2012-06-22 18:54:49 +02:00
|
|
|
}
|
2012-05-03 16:39:17 +02:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process archery abilities.
|
|
|
|
*
|
2012-06-05 16:31:55 +02:00
|
|
|
* @param shooter The player shooting
|
|
|
|
* @param target The defending entity
|
2012-04-27 11:47:11 +02:00
|
|
|
* @param event The event to run the archery checks on.
|
|
|
|
*/
|
2013-01-25 23:21:18 +01:00
|
|
|
private static void archeryCheck(Player shooter, LivingEntity target, EntityDamageByEntityEvent event) {
|
2013-01-25 03:55:56 +01:00
|
|
|
if (Misc.isNPCPlayer(shooter)) {
|
|
|
|
return;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (Permissions.archery(shooter)) {
|
|
|
|
ArcheryManager archeryManager = new ArcheryManager(shooter);
|
|
|
|
archeryManager.skillShot(event);
|
2012-04-30 04:58:54 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (target instanceof Player && Permissions.daze(shooter)) {
|
|
|
|
archeryManager.dazeCheck((Player) target, event);
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (!(shooter.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE)) && Permissions.trackArrows(shooter)) {
|
|
|
|
archeryManager.trackArrows(target);
|
|
|
|
}
|
2012-06-13 03:36:01 +02:00
|
|
|
|
2013-01-25 23:21:18 +01:00
|
|
|
if (target != shooter) {
|
2013-01-29 07:58:03 +01:00
|
|
|
archeryManager.distanceXpBonus(target);
|
2013-01-25 23:21:18 +01:00
|
|
|
startGainXp(shooter, archeryManager.getProfile(), target, SkillType.ARCHERY);
|
|
|
|
}
|
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
|
|
|
|
* @param dmg Amount of damage to attempt to do
|
|
|
|
*/
|
|
|
|
public static void dealDamage(LivingEntity target, int dmg) {
|
|
|
|
dealDamage(target, dmg, EntityDamageEvent.DamageCause.CUSTOM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to damage target for value dmg with reason cause
|
|
|
|
*
|
|
|
|
* @param target LivingEntity which to attempt to damage
|
|
|
|
* @param dmg Amount of damage to attempt to do
|
|
|
|
* @param cause DamageCause to pass to damage event
|
|
|
|
*/
|
|
|
|
private static void dealDamage(LivingEntity target, int dmg, DamageCause cause) {
|
2012-05-03 16:39:17 +02:00
|
|
|
if (configInstance.getEventCallbackEnabled()) {
|
2012-06-05 15:57:10 +02:00
|
|
|
EntityDamageEvent ede = new FakeEntityDamageEvent(target, cause, dmg);
|
2012-06-07 00:02:22 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
if (ede.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
target.damage(ede.getDamage());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
target.damage(dmg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
|
|
|
|
*
|
|
|
|
* @param target LivingEntity which to attempt to damage
|
|
|
|
* @param dmg Amount of damage to attempt to do
|
|
|
|
* @param attacker Player to pass to event as damager
|
|
|
|
*/
|
|
|
|
private static void dealDamage(LivingEntity target, int dmg, Player attacker) {
|
2012-05-03 16:39:17 +02:00
|
|
|
if (configInstance.getEventCallbackEnabled()) {
|
2012-06-05 15:57:10 +02:00
|
|
|
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
|
2012-06-07 00:02:22 +02:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
if (ede.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
target.damage(ede.getDamage());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
target.damage(dmg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2012-06-21 15:04:45 +02:00
|
|
|
public static void applyAbilityAoE(Player attacker, LivingEntity target, int damage, SkillType type) {
|
2012-04-27 11:47:11 +02:00
|
|
|
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); //The higher the weapon tier, the more targets you hit
|
2012-04-28 06:14:19 +02:00
|
|
|
int damageAmount = damage;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
if (damageAmount < 1) {
|
|
|
|
damageAmount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
2013-01-25 03:55:56 +01:00
|
|
|
if ((entity instanceof Player && Misc.isNPCPlayer((Player) entity)) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
2012-04-28 06:14:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
if (numberOfTargets <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2012-06-18 14:50:14 +02:00
|
|
|
PlayerAnimationEvent armswing = new PlayerAnimationEvent(attacker);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
switch (type) {
|
|
|
|
case SWORDS:
|
|
|
|
if (entity instanceof Player) {
|
|
|
|
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2013-01-22 16:48:10 +01:00
|
|
|
BleedTimer.add((LivingEntity) entity, Swords.serratedStrikesBleedTicks);
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
break;
|
2012-05-03 16:39:17 +02:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
case AXES:
|
|
|
|
if (entity instanceof Player) {
|
|
|
|
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck"));
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
break;
|
2012-05-03 16:39:17 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
2012-05-01 01:32:50 +02:00
|
|
|
|
2012-04-28 06:14:19 +02:00
|
|
|
dealDamage((LivingEntity) entity, damageAmount, attacker);
|
|
|
|
numberOfTargets--;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the task that gives combat XP.
|
|
|
|
*
|
|
|
|
* @param attacker The attacking player
|
2012-07-03 16:04:04 +02:00
|
|
|
* @param profile The player's PlayerProfile
|
2012-04-27 11:47:11 +02:00
|
|
|
* @param target The defending entity
|
|
|
|
* @param skillType The skill being used
|
|
|
|
*/
|
2012-07-03 16:04:04 +02:00
|
|
|
public static void startGainXp(Player attacker, PlayerProfile profile, LivingEntity target, SkillType skillType) {
|
2012-04-27 11:47:11 +02:00
|
|
|
double baseXP = 0;
|
|
|
|
|
|
|
|
if (target instanceof Player) {
|
2012-05-03 16:39:17 +02:00
|
|
|
if (!configInstance.getExperienceGainsPlayerVersusPlayerEnabled()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player defender = (Player) target;
|
|
|
|
|
2012-06-12 05:32:56 +02:00
|
|
|
if (System.currentTimeMillis() >= Users.getProfile(defender).getRespawnATS() + 5) {
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = 20 * configInstance.getPlayerVersusPlayerXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-07 23:08:53 +01:00
|
|
|
else if (!mcMMO.placeStore.isSpawnedMob(target)) {
|
|
|
|
if (target instanceof Animals && !mcMMO.placeStore.isSpawnedPet(target)) {
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getAnimalsXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
EntityType type = target.getType();
|
|
|
|
|
|
|
|
switch (type) {
|
2012-12-30 21:33:38 +01:00
|
|
|
case BAT:
|
|
|
|
baseXP = configInstance.getAnimalsXP();
|
|
|
|
break;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
case BLAZE:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getBlazeXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CAVE_SPIDER:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getCaveSpiderXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CREEPER:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getCreeperXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ENDER_DRAGON:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getEnderDragonXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ENDERMAN:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getEndermanXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GHAST:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getGhastXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
2012-12-30 21:33:38 +01:00
|
|
|
case GIANT:
|
|
|
|
baseXP = configInstance.getGiantXP();
|
|
|
|
break;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
case MAGMA_CUBE:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getMagmaCubeXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IRON_GOLEM:
|
2012-05-24 16:35:46 +02:00
|
|
|
if (!((IronGolem) target).isPlayerCreated()) {
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getIronGolemXP();
|
2012-05-24 16:35:46 +02:00
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PIG_ZOMBIE:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getPigZombieXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SILVERFISH:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getSilverfishXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SKELETON:
|
2012-12-30 21:33:38 +01:00
|
|
|
switch(((Skeleton) target).getSkeletonType()) {
|
|
|
|
case WITHER:
|
|
|
|
baseXP = configInstance.getWitherSkeletonXP();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
baseXP = configInstance.getSkeletonXP();
|
|
|
|
break;
|
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
case SLIME:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getSlimeXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SPIDER:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getSpiderXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
2012-12-30 21:33:38 +01:00
|
|
|
case WITCH:
|
|
|
|
baseXP = configInstance.getWitchXP();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WITHER:
|
|
|
|
baseXP = configInstance.getWitherXP();
|
|
|
|
break;
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
case ZOMBIE:
|
2012-05-03 16:39:17 +02:00
|
|
|
baseXP = configInstance.getZombieXP();
|
2012-04-27 11:47:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
baseXP *= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (baseXP != 0) {
|
2012-07-03 16:04:04 +02:00
|
|
|
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GainXp(attacker, profile, skillType, baseXP, target), 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
|
|
|
|
* @param livingEntity The defending LivingEntity
|
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-01-26 23:01:55 +01:00
|
|
|
if (!defender.getWorld().getPVP() || defender == player || PartyManager.inSameParty(player, defender) || Users.getProfile(defender).getGodMode()) {
|
2012-06-21 15:04:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-08-14 23:21:07 +02:00
|
|
|
//It may seem a bit redundant but we need a check here to prevent bleed from being applied in applyAbilityAoE()
|
|
|
|
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-01-25 03:55:56 +01:00
|
|
|
if (Misc.isFriendlyPet(player, (Tameable) entity)) {
|
2013-01-14 17:55:43 +01:00
|
|
|
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
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|