mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 03:04:44 +02:00
Squashed commit of the following:
commit cb3e057dee1f2b29838ab654a526baac1baab7d6 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:43:57 2013 -0500 1.4.00 release commit 4f9628d2e4cde31c8946e9a911ee6f10e1fb6b35 Author: NuclearW <incongruency@gmail.com> Date: Fri Mar 1 00:07:30 2013 -0500 \r -> \n commit b2ca22e0477c747143b0f08a28a096967ee6ffd7 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:53:56 2013 -0500 Commented-out code shouldn't be done like that. commit 92f131712cc671e3e616c14a22e22769ef6d6d0b Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 23:45:36 2013 -0500 More things we missed. commit 408b03766f6261a03a862a1ab7f5835772feda4a Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 23:20:13 2013 -0500 Format: util through spout and backup lib commit d6bd2c29bbb51bee3607247468cfe145d4f38c9e Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:50:08 2013 -0500 The things we missed the first time through... commit 393f0b889aa1b7011ee81ee7b15413d8824b8cfb Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 22:05:29 2013 -0500 Formatting: Skills commit c097a6e188a7b760dd1b4389ed81dca417146b16 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:30:12 2013 -0500 Organize imports. commit 34c3e74be7eb5f983f21d969e30155c5d82c01c1 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:45 2013 -0500 Fixed a missing fallthrough comment from ChatCommand commit b4a76c9f022a2fd98bdd8f083accfea03becfd71 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 19:09:36 2013 -0500 Formatting: datatypes.* through events.* commit 3e57dd41d3265a7c8106c7eb026df926770a4d15 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:56:15 2013 -0500 Fix issue with bad rebase commit e8c8e06b2971555b7334e49128257e3af6f36892 Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 17:35:32 2013 -0500 Formatting: DatabaseManager, LeaderboardManager, DatabaseUpdateType, and PlayerStat commit 13ecf1cc41f377a12991e357ac10abdcda24d6de Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:31:43 2013 -0500 Format: listeners.* through runnables.* commit 71686e3c0d96c2dcf25442b91703fadda1ea3bb0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 17:13:57 2013 -0500 Format PartyLockCommand commit d50abed10bf94e1a88df3dc5cc07c259aea920ea Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 16:54:08 2013 -0500 Format: base through config.* commit 7004823eeebbae5be7728bf9cafc3b04e57b64cf Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:21:40 2013 -0500 Example of using spaces to align like things commit 534190cfe2481e466fe459d65628550458cc2993 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:12:19 2013 -0500 Capitalization commit 5b61d3ba4c8d81e6f358b0cf4f460abfe9798414 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 15:07:43 2013 -0500 Updated readme, added standards.md commit 5ec0df70fb82c527420a2f437f27f31bd758f884 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 14:42:16 2013 -0500 Markdown was here, Creole is a loser commit 70d557c59d086b6a5fb5e0e63c0c1d8eb4c8d19c Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 13:46:24 2013 -0500 Move MCStats shading to .metrics.mcstats commit eb9d67e66b1659d6abd2397ecf403343cfeffdda Author: GJ <gjmcferrin@gmail.com> Date: Thu Feb 28 13:37:37 2013 -0500 Move ALL the packages! commit 8ffa9e7b75417b6c7f158613d4b4ffb783dcf2d0 Author: NuclearW <incongruency@gmail.com> Date: Thu Feb 28 12:37:12 2013 -0500 /r/n -> /n
This commit is contained in:
600
src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java
Normal file
600
src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java
Normal file
@ -0,0 +1,600 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Arrow;
|
||||
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;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Tameable;
|
||||
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.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.ToolType;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.runnables.skills.AwardCombatXpTask;
|
||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||
import com.gmail.nossr50.skills.SkillManagerStore;
|
||||
import com.gmail.nossr50.skills.axes.AxeManager;
|
||||
import com.gmail.nossr50.skills.swords.Swords;
|
||||
import com.gmail.nossr50.skills.taming.Taming;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModUtils;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
public final class CombatUtils {
|
||||
private CombatUtils() {}
|
||||
|
||||
/**
|
||||
* Apply combat modifiers and process and XP gain.
|
||||
*
|
||||
* @param event The event to run the combat checks on.
|
||||
*/
|
||||
public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
|
||||
boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
|
||||
boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
|
||||
Entity damager = event.getDamager();
|
||||
|
||||
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
|
||||
Player player = (Player) attacker;
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target instanceof Tameable && isFriendlyPet(player, (Tameable) target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
Material heldItemType = heldItem.getType();
|
||||
|
||||
if (ItemUtils.isSword(heldItem)) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!SkillType.SWORDS.getPVPEnabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!SkillType.SWORDS.getPVEEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
PlayerProfile profile = mcMMOPlayer.getProfile();
|
||||
String playerName = player.getName();
|
||||
boolean canSerratedStrike = Permissions.serratedStrikes(player); // So we don't have to check the same permission twice
|
||||
|
||||
if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
|
||||
SkillUtils.abilityCheck(player, SkillType.SWORDS);
|
||||
}
|
||||
|
||||
if (Permissions.bleed(player)) {
|
||||
SkillManagerStore.getInstance().getSwordsManager(playerName).bleedCheck(target);
|
||||
}
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) {
|
||||
SkillManagerStore.getInstance().getSwordsManager(playerName).serratedStrikes(target, event.getDamage());
|
||||
}
|
||||
|
||||
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
|
||||
}
|
||||
}
|
||||
else if (ItemUtils.isAxe(heldItem)) {
|
||||
if (((targetIsPlayer || targetIsTamedPet) && !SkillType.AXES.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.AXES.getPVEEnabled())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(player, SkillType.AXES)) {
|
||||
AxeManager axeManager = SkillManagerStore.getInstance().getAxeManager(player.getName());
|
||||
|
||||
if (axeManager.canActivateAbility()) {
|
||||
SkillUtils.abilityCheck(player, SkillType.AXES);
|
||||
}
|
||||
|
||||
if (axeManager.canUseAxeMastery()) {
|
||||
event.setDamage(axeManager.axeMasteryCheck(event.getDamage()));
|
||||
}
|
||||
|
||||
if (axeManager.canCriticalHit(target)) {
|
||||
event.setDamage(axeManager.criticalHitCheck(target, event.getDamage()));
|
||||
}
|
||||
|
||||
if (axeManager.canImpact(target)) {
|
||||
axeManager.impactCheck(target);
|
||||
}
|
||||
else if (axeManager.canGreaterImpact(target)) {
|
||||
event.setDamage(axeManager.greaterImpactCheck(target, event.getDamage()));
|
||||
}
|
||||
|
||||
if (axeManager.canUseSkullSplitter(target)) {
|
||||
axeManager.skullSplitterCheck(target, event.getDamage());
|
||||
}
|
||||
|
||||
startGainXp(axeManager.getMcMMOPlayer(), target, SkillType.AXES);
|
||||
}
|
||||
}
|
||||
else if (heldItemType == Material.AIR) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!SkillType.UNARMED.getPVPEnabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!SkillType.UNARMED.getPVEEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
PlayerProfile profile = mcMMOPlayer.getProfile();
|
||||
String playerName = player.getName();
|
||||
|
||||
boolean canBerserk = Permissions.berserk(player); // So we don't have to check the same permission twice
|
||||
|
||||
if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
|
||||
SkillUtils.abilityCheck(player, SkillType.UNARMED);
|
||||
}
|
||||
|
||||
if (Permissions.bonusDamage(player, SkillType.UNARMED)) {
|
||||
event.setDamage(SkillManagerStore.getInstance().getUnarmedManager(playerName).ironArmCheck(event.getDamage()));
|
||||
}
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
|
||||
event.setDamage(SkillManagerStore.getInstance().getUnarmedManager(playerName).berserkDamage(event.getDamage()));
|
||||
}
|
||||
|
||||
if (target instanceof Player && Permissions.disarm(player)) {
|
||||
Player defender = (Player) target;
|
||||
|
||||
if (defender.getItemInHand().getType() != Material.AIR) {
|
||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).disarmCheck((Player) target);
|
||||
}
|
||||
}
|
||||
|
||||
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
||||
}
|
||||
}
|
||||
else if (heldItemType == Material.BONE && target instanceof Tameable && Permissions.beastLore(player)) {
|
||||
SkillManagerStore.getInstance().getTamingManager(player.getName()).beastLore(target);
|
||||
}
|
||||
}
|
||||
|
||||
switch (damager.getType()) {
|
||||
case WOLF:
|
||||
Wolf wolf = (Wolf) damager;
|
||||
|
||||
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
|
||||
Player master = (Player) wolf.getOwner();
|
||||
|
||||
if (Misc.isNPCEntity(master)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!SkillType.TAMING.getPVPEnabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!SkillType.TAMING.getPVEEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(master, SkillType.TAMING)) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
|
||||
int skillLevel = SkillManagerStore.getInstance().getTamingManager(master.getName()).getSkillLevel();
|
||||
|
||||
if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(master)) {
|
||||
SkillManagerStore.getInstance().getTamingManager(master.getName()).fastFoodService(wolf, event.getDamage());
|
||||
}
|
||||
|
||||
if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(master)) {
|
||||
SkillManagerStore.getInstance().getTamingManager(master.getName()).sharpenedClaws(event);
|
||||
}
|
||||
|
||||
if (Permissions.gore(master)) {
|
||||
SkillManagerStore.getInstance().getTamingManager(master.getName()).gore(event);
|
||||
}
|
||||
|
||||
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ARROW:
|
||||
LivingEntity shooter = ((Arrow) damager).getShooter();
|
||||
|
||||
/* Break instead of return due to Dodge/Counter/Deflect abilities */
|
||||
if (shooter == null || !(shooter instanceof Player)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!SkillType.ARCHERY.getPVPEnabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!SkillType.ARCHERY.getPVEEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
archeryCheck((Player) shooter, target, event);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (targetIsPlayer) {
|
||||
Player player = (Player) target;
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
if (SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).canDodge(damager)) {
|
||||
event.setDamage(SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).dodgeCheck(event.getDamage()));
|
||||
}
|
||||
|
||||
if (damager instanceof Player) {
|
||||
if (SkillType.SWORDS.getPVPEnabled() && ItemUtils.isSword(heldItem) && Permissions.counterAttack(player)) {
|
||||
SkillManagerStore.getInstance().getSwordsManager(player.getName()).counterAttackChecks((LivingEntity) damager, event.getDamage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (SkillType.SWORDS.getPVEEnabled() && damager instanceof LivingEntity && ItemUtils.isSword(heldItem) && Permissions.counterAttack(player)) {
|
||||
SkillManagerStore.getInstance().getSwordsManager(player.getName()).counterAttackChecks((LivingEntity) damager, event.getDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process archery abilities.
|
||||
*
|
||||
* @param shooter The player shooting
|
||||
* @param target The defending entity
|
||||
* @param event The event to run the archery checks on.
|
||||
*/
|
||||
private static void archeryCheck(Player shooter, LivingEntity target, EntityDamageByEntityEvent event) {
|
||||
if (Misc.isNPCEntity(shooter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(shooter, SkillType.ARCHERY)) {
|
||||
String playerName = shooter.getName();
|
||||
|
||||
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canSkillShot()) {
|
||||
event.setDamage(SkillManagerStore.getInstance().getArcheryManager(playerName).skillShotCheck(event.getDamage()));
|
||||
}
|
||||
|
||||
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled() && ((Player) target).getItemInHand().getType() == Material.AIR && Permissions.arrowDeflect((Player) target)) {
|
||||
event.setCancelled(SkillManagerStore.getInstance().getUnarmedManager(((Player) target).getName()).deflectCheck());
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canDaze(target)) {
|
||||
event.setDamage(SkillManagerStore.getInstance().getArcheryManager(playerName).dazeCheck((Player) target, event.getDamage()));
|
||||
}
|
||||
|
||||
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canTrackArrows()) {
|
||||
SkillManagerStore.getInstance().getArcheryManager(playerName).trackArrows(target);
|
||||
}
|
||||
|
||||
SkillManagerStore.getInstance().getArcheryManager(playerName).distanceXpBonus(target);
|
||||
startGainXp(UserManager.getPlayer(shooter), target, SkillType.ARCHERY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (Config.getInstance().getEventCallbackEnabled()) {
|
||||
EntityDamageEvent ede = new FakeEntityDamageEvent(target, cause, dmg);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
||||
|
||||
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) {
|
||||
if (Config.getInstance().getEventCallbackEnabled()) {
|
||||
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
||||
|
||||
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
|
||||
*/
|
||||
public static void applyAbilityAoE(Player attacker, LivingEntity target, int damage, SkillType type) {
|
||||
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); // The higher the weapon tier, the more targets you hit
|
||||
int damageAmount = damage;
|
||||
|
||||
if (damageAmount < 1) {
|
||||
damageAmount = 1;
|
||||
}
|
||||
|
||||
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
||||
if (Misc.isNPCEntity(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (numberOfTargets <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
PlayerAnimationEvent armswing = new PlayerAnimationEvent(attacker);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
||||
|
||||
switch (type) {
|
||||
case SWORDS:
|
||||
if (entity instanceof Player) {
|
||||
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
||||
}
|
||||
|
||||
BleedTimerTask.add((LivingEntity) entity, Swords.serratedStrikesBleedTicks);
|
||||
|
||||
break;
|
||||
|
||||
case AXES:
|
||||
if (entity instanceof Player) {
|
||||
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck"));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
dealDamage((LivingEntity) entity, damageAmount, attacker);
|
||||
numberOfTargets--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the task that gives combat XP.
|
||||
*
|
||||
* @param mcMMOPlayer The attacking player
|
||||
* @param target The defending entity
|
||||
* @param skillType The skill being used
|
||||
*/
|
||||
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType) {
|
||||
double baseXP = 0;
|
||||
|
||||
if (target instanceof Player) {
|
||||
if (!Config.getInstance().getExperienceGainsPlayerVersusPlayerEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player defender = (Player) target;
|
||||
|
||||
if (System.currentTimeMillis() >= UserManager.getPlayer(defender).getProfile().getRespawnATS() + 5) {
|
||||
baseXP = 20 * Config.getInstance().getPlayerVersusPlayerXP();
|
||||
}
|
||||
}
|
||||
else if (!target.hasMetadata(mcMMO.entityMetadataKey)) {
|
||||
if (target instanceof Animals) {
|
||||
if (ModUtils.isCustomEntity(target)) {
|
||||
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
|
||||
}
|
||||
else {
|
||||
baseXP = Config.getInstance().getAnimalsXP();
|
||||
}
|
||||
}
|
||||
else {
|
||||
EntityType type = target.getType();
|
||||
|
||||
switch (type) {
|
||||
case BAT:
|
||||
baseXP = Config.getInstance().getAnimalsXP();
|
||||
break;
|
||||
|
||||
case BLAZE:
|
||||
case CAVE_SPIDER:
|
||||
case CREEPER:
|
||||
case ENDER_DRAGON:
|
||||
case ENDERMAN:
|
||||
case GHAST:
|
||||
case GIANT:
|
||||
case MAGMA_CUBE:
|
||||
case PIG_ZOMBIE:
|
||||
case SILVERFISH:
|
||||
case SLIME:
|
||||
case SPIDER:
|
||||
case WITCH:
|
||||
case WITHER:
|
||||
case ZOMBIE:
|
||||
baseXP = Config.getInstance().getCombatXP(type);
|
||||
break;
|
||||
|
||||
// Temporary workaround for custom entities
|
||||
case UNKNOWN:
|
||||
baseXP = 1.0;
|
||||
break;
|
||||
|
||||
case SKELETON:
|
||||
switch (((Skeleton) target).getSkeletonType()) {
|
||||
case WITHER:
|
||||
baseXP = Config.getInstance().getWitherSkeletonXP();
|
||||
break;
|
||||
default:
|
||||
baseXP = Config.getInstance().getCombatXP(type);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case IRON_GOLEM:
|
||||
if (!((IronGolem) target).isPlayerCreated()) {
|
||||
baseXP = Config.getInstance().getCombatXP(type);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ModUtils.isCustomEntity(target)) {
|
||||
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
baseXP *= 10;
|
||||
}
|
||||
|
||||
if (baseXP != 0) {
|
||||
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new AwardCombatXpTask(mcMMOPlayer, skillType, baseXP, target), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the given LivingEntity should be affected by a combat ability.
|
||||
*
|
||||
* @param player The attacking Player
|
||||
* @param entity The defending Entity
|
||||
* @return true if the Entity should be damaged, false otherwise.
|
||||
*/
|
||||
public static boolean shouldBeAffected(Player player, Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
Player defender = (Player) entity;
|
||||
|
||||
if (!defender.getWorld().getPVP() || defender == player || UserManager.getPlayer(defender).getProfile().getGodMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PartyManager.inSameParty(player, defender) && !(Permissions.friendlyFire(player) && Permissions.friendlyFire(defender))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Tameable) {
|
||||
if (isFriendlyPet(player, (Tameable) entity)) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if an entity is currently invincible.
|
||||
*
|
||||
* @param entity The {@link LivingEntity} to check
|
||||
* @param eventDamage The damage from the event the entity is involved in
|
||||
* @return true if the entity is invincible, false otherwise
|
||||
*/
|
||||
public static boolean isInvincible(LivingEntity entity, int eventDamage) {
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
if ((entity.getNoDamageTicks() > entity.getMaximumNoDamageTicks() / 2.0F) && (eventDamage <= entity.getLastDamage())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
if (owner == attacker || PartyManager.inSameParty(attacker, owner)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
|
||||
public final class ParticleEffectUtils {
|
||||
|
||||
private ParticleEffectUtils() {};
|
||||
|
||||
public static void playBleedEffect(LivingEntity livingEntity) {
|
||||
if (!Config.getInstance().getBleedEffectEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
livingEntity.getWorld().playEffect(livingEntity.getEyeLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE);
|
||||
}
|
||||
|
||||
public static void playDodgeEffect(Player player) {
|
||||
if (!Config.getInstance().getDodgeEffectEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = player.getEyeLocation();
|
||||
World world = player.getWorld();
|
||||
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH_EAST);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.SOUTH_WEST);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.EAST);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.SELF);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.WEST);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.NORTH_EAST);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.NORTH);
|
||||
world.playEffect(location, Effect.SMOKE, BlockFace.NORTH_WEST);
|
||||
}
|
||||
|
||||
public static void playGreaterImpactEffect(LivingEntity livingEntity) {
|
||||
if (!Config.getInstance().getGreaterImpactEffectEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location location = livingEntity.getEyeLocation();
|
||||
|
||||
livingEntity.getWorld().createExplosion(location.getX(), location.getY(), location.getZ(), 0F, false, false);
|
||||
}
|
||||
|
||||
public static void playAbilityEnabledEffect(Player player) {
|
||||
if (!Config.getInstance().getAbilityActivationEffectEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fireworkParticleShower(player, Color.GREEN);
|
||||
}
|
||||
|
||||
public static void playAbilityDisabledEffect(Player player) {
|
||||
if (!Config.getInstance().getAbilityDeactivationEffectEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
fireworkParticleShower(player, Color.RED);
|
||||
}
|
||||
|
||||
private static void fireworkParticleShower(Player player, Color color) {
|
||||
Location location = player.getLocation();
|
||||
location.setY(location.getY() - 1.0);
|
||||
location.setPitch(-90);
|
||||
|
||||
Firework firework = (Firework) player.getWorld().spawnEntity(location, EntityType.FIREWORK);
|
||||
FireworkMeta fireworkMeta = firework.getFireworkMeta();
|
||||
FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(color).with(Type.BALL_LARGE).trail(true).build();
|
||||
fireworkMeta.addEffect(effect);
|
||||
fireworkMeta.addEffect(effect);
|
||||
fireworkMeta.setPower(0);
|
||||
firework.setFireworkMeta(fireworkMeta);
|
||||
}
|
||||
}
|
79
src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java
Normal file
79
src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public final class PerksUtils {
|
||||
private static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75;
|
||||
private static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100;
|
||||
|
||||
private PerksUtils() {};
|
||||
|
||||
public static int handleCooldownPerks(Player player, int cooldown) {
|
||||
if (Permissions.halvedCooldowns(player)) {
|
||||
cooldown *= 0.5;
|
||||
}
|
||||
else if (Permissions.thirdedCooldowns(player)) {
|
||||
cooldown *= (1.0 / 3.0);
|
||||
}
|
||||
else if (Permissions.quarteredCooldowns(player)) {
|
||||
cooldown *= 0.75;
|
||||
}
|
||||
|
||||
return cooldown;
|
||||
}
|
||||
|
||||
public static int handleActivationPerks(Player player, int ticks, int maxTicks) {
|
||||
if (Permissions.twelveSecondActivationBoost(player)) {
|
||||
ticks += 12;
|
||||
}
|
||||
else if (Permissions.eightSecondActivationBoost(player)) {
|
||||
ticks += 8;
|
||||
}
|
||||
else if (Permissions.fourSecondActivationBoost(player)) {
|
||||
ticks += 4;
|
||||
}
|
||||
|
||||
if (maxTicks != 0 && ticks > maxTicks) {
|
||||
ticks = maxTicks;
|
||||
}
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
public static int handleXpPerks(Player player, int xp) {
|
||||
if (Permissions.quadrupleXp(player)) {
|
||||
xp *= 4;
|
||||
}
|
||||
else if (Permissions.tripleXp(player)) {
|
||||
xp *= 3;
|
||||
}
|
||||
else if (Permissions.doubleAndOneHalfXp(player)) {
|
||||
xp *= 2.5;
|
||||
}
|
||||
else if (Permissions.doubleXp(player)) {
|
||||
xp *= 2;
|
||||
}
|
||||
else if (Permissions.oneAndOneHalfXp(player)) {
|
||||
xp *= 1.5;
|
||||
}
|
||||
|
||||
return xp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate activation chance for a skill.
|
||||
*
|
||||
* @param isLucky true if the player has the appropriate "lucky" perk, false otherwise
|
||||
* @return the activation chance
|
||||
*/
|
||||
public static int handleLuckyPerks(Player player, SkillType skill) {
|
||||
if (Permissions.lucky(player, skill)) {
|
||||
return LUCKY_SKILL_ACTIVATION_CHANCE;
|
||||
}
|
||||
|
||||
return NORMAL_SKILL_ACTIVATION_CHANCE;
|
||||
}
|
||||
}
|
628
src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java
Normal file
628
src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java
Normal file
@ -0,0 +1,628 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.HiddenConfig;
|
||||
import com.gmail.nossr50.config.spout.SpoutConfig;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.ToolType;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModUtils;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.spout.SpoutUtils;
|
||||
|
||||
public class SkillUtils {
|
||||
public static int handleFoodSkills(Player player, SkillType skill, int eventFoodLevel, int baseLevel, int maxLevel, int rankChange) {
|
||||
int skillLevel = UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
||||
|
||||
int currentFoodLevel = player.getFoodLevel();
|
||||
int foodChange = eventFoodLevel - currentFoodLevel;
|
||||
|
||||
for (int i = baseLevel; i <= maxLevel; i += rankChange) {
|
||||
if (skillLevel >= i) {
|
||||
foodChange++;
|
||||
}
|
||||
}
|
||||
|
||||
return currentFoodLevel + foodChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the cooldown for an item or ability is expired.
|
||||
*
|
||||
* @param oldTime The time the ability or item was last used
|
||||
* @param cooldown The amount of time that must pass between uses
|
||||
* @param player The player whose cooldown is being checked
|
||||
* @return true if the cooldown is over, false otherwise
|
||||
*/
|
||||
public static boolean cooldownOver(long oldTime, int cooldown, Player player) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
int adjustedCooldown = PerksUtils.handleCooldownPerks(player, cooldown);
|
||||
|
||||
if (currentTime - oldTime >= (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the time remaining until the cooldown expires.
|
||||
*
|
||||
* @param deactivatedTimeStamp Time of deactivation
|
||||
* @param cooldown The length of the cooldown
|
||||
* @return the number of seconds remaining before the cooldown expires
|
||||
*/
|
||||
public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) {
|
||||
return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the player when the cooldown expires.
|
||||
*
|
||||
* @param player The player to send a message to
|
||||
* @param profile The profile of the player
|
||||
* @param ability The ability to watch cooldowns for
|
||||
*/
|
||||
public static void watchCooldown(Player player, PlayerProfile profile, AbilityType ability) {
|
||||
if (player == null || profile == null || ability == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!profile.getAbilityInformed(ability) && cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
profile.setAbilityInformed(ability, true);
|
||||
player.sendMessage(ability.getAbilityRefresh());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process activating abilities & readying the tool.
|
||||
*
|
||||
* @param player The player using the ability
|
||||
* @param skill The skill the ability is tied to
|
||||
*/
|
||||
public static void activationCheck(Player player, SkillType skill) {
|
||||
if (Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && !player.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
AbilityType ability = skill.getAbility();
|
||||
ToolType tool = skill.getTool();
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
|
||||
if (ModUtils.isCustomTool(inHand) && !ModUtils.getToolFromItemStack(inHand).isAbilityEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if any abilities are active */
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!profile.getAbilityUse()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (AbilityType x : AbilityType.values()) {
|
||||
if (profile.getAbilityMode(x)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Woodcutting & Axes need to be treated differently.
|
||||
* Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action
|
||||
*/
|
||||
if (ability.getPermissions(player) && tool.inHand(inHand) && !profile.getToolPreparationMode(tool)) {
|
||||
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
|
||||
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
||||
player.sendMessage(tool.getRaiseTool());
|
||||
}
|
||||
|
||||
profile.setToolPreparationATS(tool, System.currentTimeMillis());
|
||||
profile.setToolPreparationMode(tool, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors various things relating to skill abilities.
|
||||
*
|
||||
* @param player The player using the skill
|
||||
* @param profile The profile of the player
|
||||
* @param curTime The current system time
|
||||
* @param skill The skill being monitored
|
||||
*/
|
||||
public static void monitorSkill(Player player, PlayerProfile profile, long curTime, SkillType skill) {
|
||||
final int FOUR_SECONDS = 4000;
|
||||
|
||||
ToolType tool = skill.getTool();
|
||||
AbilityType ability = skill.getAbility();
|
||||
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.getToolPreparationMode(tool) && curTime - (profile.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) {
|
||||
profile.setToolPreparationMode(tool, false);
|
||||
|
||||
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
||||
player.sendMessage(tool.getLowerTool());
|
||||
}
|
||||
}
|
||||
|
||||
if (ability.getPermissions(player)) {
|
||||
if (profile.getAbilityMode(ability) && (profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
|
||||
if (ability == AbilityType.BERSERK) {
|
||||
player.setCanPickupItems(true);
|
||||
}
|
||||
else if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
|
||||
handleAbilitySpeedDecrease(player);
|
||||
}
|
||||
|
||||
profile.setAbilityMode(ability, false);
|
||||
profile.setAbilityInformed(ability, false);
|
||||
|
||||
ParticleEffectUtils.playAbilityDisabledEffect(player);
|
||||
|
||||
if (profile.useChatNotifications()) {
|
||||
player.sendMessage(ability.getAbilityOff());
|
||||
}
|
||||
|
||||
sendSkillMessage(player, ability.getAbilityPlayerOff(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the XP of a skill.
|
||||
*
|
||||
* @param skillType The skill to check
|
||||
* @param player The player whose skill to check
|
||||
* @param profile The profile of the player whose skill to check
|
||||
*/
|
||||
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
|
||||
int skillups = 0;
|
||||
int xpRemoved = 0;
|
||||
|
||||
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
||||
|
||||
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
||||
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Config.getInstance().getPowerLevelCap() >= UserManager.getPlayer(player).getPowerLevel() + 1)) {
|
||||
int xp = profile.getXpToLevel(skillType);
|
||||
xpRemoved += xp;
|
||||
|
||||
profile.removeXp(skillType, xp);
|
||||
skillups++;
|
||||
profile.skillUp(skillType, 1);
|
||||
}
|
||||
else {
|
||||
profile.addLevels(skillType, 0);
|
||||
}
|
||||
}
|
||||
|
||||
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType, skillups);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
|
||||
|
||||
if (eventToFire.isCancelled()) {
|
||||
profile.modifySkill(skillType, profile.getSkillLevel(skillType) - skillups);
|
||||
profile.setSkillXpLevel(skillType, profile.getSkillXpLevel(skillType) + xpRemoved);
|
||||
return;
|
||||
}
|
||||
|
||||
String capitalized = StringUtils.getCapitalized(skillType.toString());
|
||||
|
||||
/* Spout Stuff */
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||
SpoutUtils.levelUpNotification(skillType, spoutPlayer);
|
||||
|
||||
/* Update custom titles */
|
||||
if (SpoutConfig.getInstance().getShowPowerLevel()) {
|
||||
spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", spoutPlayer.getName(), UserManager.getPlayer(player).getPowerLevel()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", skillups, profile.getSkillLevel(skillType)));
|
||||
}
|
||||
}
|
||||
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||
profile.getSpoutHud().updateXpBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given string represents a valid skill
|
||||
*
|
||||
* @param skillName The name of the skill to check
|
||||
* @return true if this is a valid skill, false otherwise
|
||||
*/
|
||||
public static boolean isSkill(String skillName) {
|
||||
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
|
||||
return isLocalizedSkill(skillName);
|
||||
}
|
||||
|
||||
if (SkillType.getSkill(skillName) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isLocalizedSkill(String skillName) {
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skillName.equalsIgnoreCase(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getSkillName(SkillType skill) {
|
||||
if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
|
||||
return StringUtils.getCapitalized(LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".SkillName"));
|
||||
}
|
||||
|
||||
return StringUtils.getCapitalized(skill.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has any combat skill permissions.
|
||||
*
|
||||
* @param player The player to check permissions for
|
||||
* @return true if the player has combat skills, false otherwise
|
||||
*/
|
||||
public static boolean hasCombatSkills(Player player) {
|
||||
if (Permissions.skillEnabled(player, SkillType.AXES)
|
||||
|| Permissions.skillEnabled(player, SkillType.ARCHERY)
|
||||
|| Permissions.skillEnabled(player, SkillType.SWORDS)
|
||||
|| Permissions.skillEnabled(player, SkillType.TAMING)
|
||||
|| Permissions.skillEnabled(player, SkillType.UNARMED)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has any gathering skill permissions.
|
||||
*
|
||||
* @param player The player to check permissions for
|
||||
* @return true if the player has gathering skills, false otherwise
|
||||
*/
|
||||
public static boolean hasGatheringSkills(Player player) {
|
||||
if (Permissions.skillEnabled(player, SkillType.EXCAVATION)
|
||||
|| Permissions.skillEnabled(player, SkillType.FISHING)
|
||||
|| Permissions.skillEnabled(player, SkillType.HERBALISM)
|
||||
|| Permissions.skillEnabled(player, SkillType.MINING)
|
||||
|| Permissions.skillEnabled(player, SkillType.WOODCUTTING)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has any misc skill permissions.
|
||||
*
|
||||
* @param player The player to check permissions for
|
||||
* @return true if the player has misc skills, false otherwise
|
||||
*/
|
||||
public static boolean hasMiscSkills(Player player) {
|
||||
if (Permissions.skillEnabled(player, SkillType.ACROBATICS)
|
||||
|| Permissions.skillEnabled(player, SkillType.SMELTING)
|
||||
|| Permissions.skillEnabled(player, SkillType.REPAIR)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if an ability can be activated.
|
||||
*
|
||||
* @param player The player activating the ability
|
||||
* @param type The skill the ability is based on
|
||||
*/
|
||||
public static void abilityCheck(Player player, SkillType type) {
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
ToolType tool = type.getTool();
|
||||
AbilityType ability = type.getAbility();
|
||||
|
||||
profile.setToolPreparationMode(tool, false);
|
||||
|
||||
/*
|
||||
* Axes and Woodcutting are odd because they share the same tool.
|
||||
* We show them the too tired message when they take action.
|
||||
*/
|
||||
if (type == SkillType.WOODCUTTING || type == SkillType.AXES) {
|
||||
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) {
|
||||
int ticks = PerksUtils.handleActivationPerks(player, 2 + (profile.getSkillLevel(type) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxTicks());
|
||||
|
||||
ParticleEffectUtils.playAbilityEnabledEffect(player);
|
||||
|
||||
if (profile.useChatNotifications()) {
|
||||
player.sendMessage(ability.getAbilityOn());
|
||||
}
|
||||
|
||||
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player));
|
||||
|
||||
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
|
||||
profile.setAbilityMode(ability, true);
|
||||
|
||||
if (ability == AbilityType.BERSERK) {
|
||||
player.setCanPickupItems(false);
|
||||
}
|
||||
else if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
|
||||
handleAbilitySpeedIncrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if ability should be triggered.
|
||||
*
|
||||
* @param player The player using the ability
|
||||
* @param block The block modified by the ability
|
||||
* @param ability The ability to check
|
||||
* @return true if the ability should activate, false otherwise
|
||||
*/
|
||||
public static boolean triggerCheck(Player player, Block block, AbilityType ability) {
|
||||
boolean activate = true;
|
||||
|
||||
switch (ability) {
|
||||
case BERSERK:
|
||||
case LEAF_BLOWER:
|
||||
if (!ability.blockCheck(block.getState())) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!blockBreakSimulate(block, player, true)) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
case SUPER_BREAKER:
|
||||
case GREEN_TERRA:
|
||||
if (!ability.blockCheck(block.getState())) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return activate;
|
||||
}
|
||||
|
||||
public static void sendSkillMessage(Player player, String message) {
|
||||
for (Player otherPlayer : player.getWorld().getPlayers()) {
|
||||
if (otherPlayer != player && Misc.isNear(player.getLocation(), otherPlayer.getLocation(), Misc.SKILL_MESSAGE_MAX_SENDING_DISTANCE)) {
|
||||
otherPlayer.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a skill level is higher than the max bonus level of the ability.
|
||||
*
|
||||
* @param skillLevel Skill level to check
|
||||
* @param maxLevel Max level of the ability
|
||||
* @return whichever value is lower
|
||||
*/
|
||||
public static int skillCheck(int skillLevel, int maxLevel) {
|
||||
// TODO: Could we just use Math.min(skillLevel, maxLevel) here?
|
||||
if (skillLevel > maxLevel) {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
return skillLevel;
|
||||
}
|
||||
|
||||
public static void handleAbilitySpeedIncrease(Player player) {
|
||||
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
if (heldItem == null || heldItem.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
int efficiencyLevel = heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED);
|
||||
ItemMeta itemMeta = heldItem.getItemMeta();
|
||||
List<String> itemLore = new ArrayList<String>();
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
itemLore = itemMeta.getLore();
|
||||
}
|
||||
|
||||
itemLore.add("mcMMO Ability Tool");
|
||||
itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel + 5, true);
|
||||
|
||||
itemMeta.setLore(itemLore);
|
||||
heldItem.setItemMeta(itemMeta);
|
||||
}
|
||||
else {
|
||||
int duration = 0;
|
||||
int amplifier = 0;
|
||||
|
||||
if (player.hasPotionEffect(PotionEffectType.FAST_DIGGING)) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getType() == PotionEffectType.FAST_DIGGING) {
|
||||
duration = effect.getDuration();
|
||||
amplifier = effect.getAmplifier();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
int ticks = 0;
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.SUPER_BREAKER)) {
|
||||
ticks = ((int) (profile.getSkillDATS(AbilityType.SUPER_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR;
|
||||
}
|
||||
else if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
|
||||
ticks = ((int) (profile.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) - System.currentTimeMillis())) / Misc.TIME_CONVERSION_FACTOR;
|
||||
}
|
||||
|
||||
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
|
||||
player.addPotionEffect(abilityBuff, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleAbilitySpeedDecrease(Player player) {
|
||||
if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
|
||||
for (int i = 0; i < playerInventory.getContents().length; i++) {
|
||||
ItemStack item = playerInventory.getItem(i);
|
||||
playerInventory.setItem(i, removeAbilityBuff(item));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.removePotionEffect(PotionEffectType.FAST_DIGGING);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack removeAbilityBuff(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
return item;
|
||||
}
|
||||
|
||||
if (!ItemUtils.isPickaxe(item) && !ItemUtils.isShovel(item)) {
|
||||
return item;
|
||||
}
|
||||
|
||||
if (item.containsEnchantment(Enchantment.DIG_SPEED)) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
List<String> itemLore = itemMeta.getLore();
|
||||
|
||||
if (itemLore.remove("mcMMO Ability Tool")) {
|
||||
int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED);
|
||||
|
||||
if (efficiencyLevel <= 5) {
|
||||
itemMeta.removeEnchant(Enchantment.DIG_SPEED);
|
||||
}
|
||||
else {
|
||||
itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel - 5, true);
|
||||
}
|
||||
|
||||
itemMeta.setLore(itemLore);
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a block break event.
|
||||
*
|
||||
* @param block The block to break
|
||||
* @param player The player breaking the block
|
||||
* @param shouldArmSwing true if an armswing event should be fired, false otherwise
|
||||
* @return true if the event wasn't cancelled, false otherwise
|
||||
*/
|
||||
public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) {
|
||||
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
|
||||
|
||||
// Support for NoCheat
|
||||
if (shouldArmSwing) {
|
||||
pluginManger.callEvent(new FakePlayerAnimationEvent(player));
|
||||
}
|
||||
|
||||
FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getItemInHand(), true);
|
||||
pluginManger.callEvent(damageEvent);
|
||||
|
||||
FakeBlockBreakEvent breakEvent = new FakeBlockBreakEvent(block, player);
|
||||
pluginManger.callEvent(breakEvent);
|
||||
|
||||
if (!damageEvent.isCancelled() && !breakEvent.isCancelled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean activationSuccessful(Player player, SkillType skill, double maxChance, int maxLevel) {
|
||||
int skillLevel = UserManager.getPlayer(player).getProfile().getSkillLevel(skill);
|
||||
int activationChance = PerksUtils.handleLuckyPerks(player, skill);
|
||||
double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel);
|
||||
|
||||
return chance > Misc.getRandom().nextInt(activationChance);
|
||||
}
|
||||
|
||||
public static boolean activationSuccessful(Player player, SkillType skill, double chance) {
|
||||
return chance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(player, skill));
|
||||
}
|
||||
|
||||
public static boolean unlockLevelReached(Player player, SkillType skill, int unlockLevel) {
|
||||
return UserManager.getPlayer(player).getProfile().getSkillLevel(skill) > unlockLevel;
|
||||
}
|
||||
|
||||
public static boolean treasureDropSuccessful(double dropChance, int activationChance) {
|
||||
return dropChance > Misc.getRandom().nextDouble() * activationChance;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user