Managers control everything relating to players.

This commit is contained in:
GJ 2013-02-26 12:38:17 -05:00
parent 0cd07cf2fd
commit 55138f1599
6 changed files with 64 additions and 67 deletions

View File

@ -33,7 +33,6 @@ import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.herbalism.Herbalism;
@ -179,7 +178,7 @@ public class EntityListener implements Listener {
switch (cause) {
case FALL:
if (Acrobatics.canRoll(player)) {
if (SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).canRoll()) {
event.setDamage(SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).rollCheck(event.getDamage()));
if (event.getDamage() == 0) {

View File

@ -1,17 +1,7 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.skills.utilities.PerksUtils;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public final class Acrobatics {
public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax();
@ -36,27 +26,6 @@ public final class Acrobatics {
private Acrobatics() {};
public static boolean canRoll(Player player) {
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player);
}
public static boolean canDodge(Player player, Entity damager) {
if (Permissions.dodge(player)) {
if (damager instanceof Player && SkillType.ACROBATICS.getPVPEnabled()) {
return true;
}
else if (!(damager instanceof Player) && SkillType.ACROBATICS.getPVEEnabled() && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled)) {
return true;
}
}
return false;
}
protected static boolean isFatal(Player player, int damage) {
return player.getHealth() - damage < 1;
}
protected static int calculateModifiedDodgeDamage(int damage, int damageModifier) {
return Math.max(damage / damageModifier, 1);
}
@ -64,10 +33,4 @@ public final class Acrobatics {
protected static int calculateModifiedRollDamage(int damage, int damageThreshold) {
return Math.max(damage - damageThreshold, 0);
}
protected static boolean isSuccessfulRoll(Player player, double maxChance, int maxLevel, int successModifier) {
double successChance = (maxChance / maxLevel) * Math.min(Users.getPlayer(player).getProfile().getSkillLevel(SkillType.ACROBATICS), maxLevel) * successModifier;
return successChance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(player, SkillType.ACROBATICS));
}
}

View File

@ -1,5 +1,8 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.McMMOPlayer;
@ -17,6 +20,25 @@ public class AcrobaticsManager extends SkillManager {
super(mcMMOPlayer, SkillType.ACROBATICS);
}
public boolean canRoll() {
Player player = getPlayer();
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player);
}
public boolean canDodge(Entity damager) {
if (Permissions.dodge(getPlayer())) {
if (damager instanceof Player && SkillType.ACROBATICS.getPVPEnabled()) {
return true;
}
else if (!(damager instanceof Player) && SkillType.ACROBATICS.getPVEEnabled() && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled)) {
return true;
}
}
return false;
}
/**
* Handle the damage reduction and XP gain from the Dodge ability
*
@ -27,7 +49,7 @@ public class AcrobaticsManager extends SkillManager {
int modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier);
Player player = getPlayer();
if (!Acrobatics.isFatal(player, modifiedDamage) && SkillTools.activationSuccessful(player, skill, Acrobatics.dodgeMaxChance, Acrobatics.dodgeMaxBonusLevel)) {
if (!isFatal(modifiedDamage) && SkillTools.activationSuccessful(player, skill, Acrobatics.dodgeMaxChance, Acrobatics.dodgeMaxBonusLevel)) {
ParticleEffectUtils.playDodgeEffect(player);
PlayerProfile playerProfile = getProfile();
@ -62,32 +84,46 @@ public class AcrobaticsManager extends SkillManager {
int modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.rollThreshold);
if (!Acrobatics.isFatal(player, modifiedDamage) && Acrobatics.isSuccessfulRoll(player, Acrobatics.rollMaxChance, Acrobatics.rollMaxBonusLevel, 1)) {
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.rollMaxChance, Acrobatics.rollMaxBonusLevel, 1)) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
applyXpGain(damage * Acrobatics.rollXpModifier);
return modifiedDamage;
}
else if (!Acrobatics.isFatal(player, damage)) {
else if (!isFatal(damage)) {
applyXpGain(damage * Acrobatics.fallXpModifier);
}
return damage;
}
/**
* Handle the damage reduction and XP gain from the Graceful Roll ability
*
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the roll was successful, the original event damage otherwise
*/
private int gracefulRollCheck(Player player, int damage) {
int modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.gracefulRollThreshold);
if (!Acrobatics.isFatal(player, modifiedDamage) && Acrobatics.isSuccessfulRoll(player, Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollSuccessModifier)) {
if (!isFatal(modifiedDamage) && isSuccessfulRoll(Acrobatics.gracefulRollMaxChance, Acrobatics.gracefulRollMaxBonusLevel, Acrobatics.gracefulRollSuccessModifier)) {
player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
applyXpGain(damage * Acrobatics.rollXpModifier);
return modifiedDamage;
}
else if (!Acrobatics.isFatal(player, damage)) {
else if (!isFatal(damage)) {
applyXpGain(damage * Acrobatics.fallXpModifier);
}
return damage;
}
private boolean isSuccessfulRoll(double maxChance, int maxLevel, int successModifier) {
return ((maxChance / maxLevel) * Math.min(getSkillLevel(), maxLevel) * successModifier) > Misc.getRandom().nextInt(activationChance);
}
private boolean isFatal(int damage) {
return getPlayer().getHealth() - damage < 1;
}
}

View File

@ -5,16 +5,11 @@ import java.util.Iterator;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class Archery {
private static List<TrackedEntity> trackedEntities = new ArrayList<TrackedEntity>();
@ -32,18 +27,6 @@ public class Archery {
public static double distanceXpModifer = 0.025;
public static boolean canDaze(Player player, LivingEntity target) {
return target instanceof Player && Permissions.daze(player);
}
public static boolean canSkillShot(Player player) {
return SkillTools.unlockLevelReached(player, SkillType.ARCHERY, skillShotIncreaseLevel) && Permissions.bonusDamage(player, SkillType.ARCHERY);
}
public static boolean canTrackArrows(Player player) {
return !(player.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE)) && Permissions.arrowRetrieval(player);
}
protected static void incrementTrackerValue(LivingEntity livingEntity) {
for (TrackedEntity trackedEntity : trackedEntities) {
if (trackedEntity.getLivingEntity().getEntityId() == livingEntity.getEntityId()) {

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Location;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
@ -12,6 +13,7 @@ import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class ArcheryManager extends SkillManager {
@ -19,6 +21,22 @@ public class ArcheryManager extends SkillManager {
super(mcMMOPlayer, SkillType.ARCHERY);
}
public boolean canDaze(LivingEntity target) {
return target instanceof Player && Permissions.daze(getPlayer());
}
public boolean canSkillShot() {
Player player = getPlayer();
return SkillTools.unlockLevelReached(player, skill, Archery.skillShotIncreaseLevel) && Permissions.bonusDamage(player, skill);
}
public boolean canTrackArrows() {
Player player = getPlayer();
return !(player.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE)) && Permissions.arrowRetrieval(player);
}
/**
* Calculate bonus XP awarded for Archery when hitting a far-away target.
*

View File

@ -28,8 +28,6 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.skills.SkillManagerStore;
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.runnables.CombatXpGiver;
import com.gmail.nossr50.skills.swords.Swords;
@ -252,7 +250,7 @@ public final class CombatTools {
ItemStack heldItem = player.getItemInHand();
if (Acrobatics.canDodge(player, damager)) {
if (SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).canDodge(damager)) {
event.setDamage(SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).dodgeCheck(event.getDamage()));
}
@ -284,7 +282,7 @@ public final class CombatTools {
if (Permissions.skillEnabled(shooter, SkillType.ARCHERY)) {
String playerName = shooter.getName();
if (Archery.canSkillShot(shooter)) {
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canSkillShot()) {
event.setDamage(SkillManagerStore.getInstance().getArcheryManager(playerName).skillShotCheck(event.getDamage()));
}
@ -292,11 +290,11 @@ public final class CombatTools {
SkillManagerStore.getInstance().getUnarmedManager(((Player) target).getName()).deflectCheck(event);
}
if (Archery.canDaze(shooter, target)) {
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canDaze(target)) {
event.setDamage(SkillManagerStore.getInstance().getArcheryManager(playerName).dazeCheck((Player) target, event.getDamage()));
}
if (Archery.canTrackArrows(shooter)) {
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canTrackArrows()) {
SkillManagerStore.getInstance().getArcheryManager(playerName).trackArrows(target);
}