Fixed issues with combat abilities not checking cooldowns in last few

dev builds.
This commit is contained in:
GJ 2013-01-25 17:21:18 -05:00
parent a4aebdc643
commit c4ec9a6df9
8 changed files with 133 additions and 153 deletions

View File

@ -42,6 +42,7 @@ import com.gmail.nossr50.skills.unarmed.Unarmed;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public class Combat {
@ -76,13 +77,25 @@ public class Combat {
return;
}
Skills.abilityCheck(player, SkillType.SWORDS);
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
SwordsManager swordsManager = new SwordsManager(player);
swordsManager.bleedCheck(target);
swordsManager.serratedStrikes(target, event.getDamage());
if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
Skills.abilityCheck(player, SkillType.SWORDS);
}
startGainXp(player, swordsManager.getProfile(), target, SkillType.SWORDS);
if (Permissions.swordsBleed(player) && shouldBeAffected(player, target)) {
swordsManager.bleedCheck(target);
}
if (profile.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) {
swordsManager.serratedStrikes(target, event.getDamage());
}
startGainXp(player, profile, target, SkillType.SWORDS);
}
}
else if (ItemChecks.isAxe(heldItem)) {
if (targetIsPlayer || targetIsTamedPet) {
@ -94,15 +107,32 @@ public class Combat {
return;
}
Skills.abilityCheck(player, SkillType.AXES);
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) {
Skills.abilityCheck(player, SkillType.AXES);
}
AxeManager axeManager = new AxeManager(player);
axeManager.bonusDamage(event);
axeManager.criticalHitCheck(event, target);
axeManager.impact(event, target);
axeManager.skullSplitter(target, event.getDamage());
if (Permissions.axeBonus(player)) {
axeManager.bonusDamage(event);
}
startGainXp(player, axeManager.getProfile(), target, SkillType.AXES);
if (!target.isDead() && Permissions.criticalHit(player) && shouldBeAffected(player, target)) {
axeManager.criticalHitCheck(event, target);
}
if (!target.isDead() && Permissions.impact(player)) {
axeManager.impact(event, target);
}
if (!target.isDead() && profile.getAbilityMode(AbilityType.SKULL_SPLIITER) && canSkullSplit) {
axeManager.skullSplitter(target, event.getDamage());
}
startGainXp(player, profile, target, SkillType.AXES);
}
}
else if (heldItemType == Material.AIR) {
if (targetIsPlayer || targetIsTamedPet) {
@ -114,16 +144,31 @@ public class Combat {
return;
}
Skills.abilityCheck(player, SkillType.UNARMED);
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
UnarmedManager unarmedManager = new UnarmedManager(player);
unarmedManager.bonusDamage(event);
unarmedManager.berserkDamage(event);
unarmedManager.disarmCheck(target);
if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
Skills.abilityCheck(player, SkillType.UNARMED);
}
startGainXp(player, unarmedManager.getProfile(), target, SkillType.UNARMED);
if (Permissions.unarmedBonus(player)) {
unarmedManager.bonusDamage(event);
}
if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
unarmedManager.berserkDamage(event);
}
if (target instanceof Player && Permissions.disarm(player)) {
unarmedManager.disarmCheck(target);
}
startGainXp(player, unarmedManager.getProfile(), target, SkillType.UNARMED);
}
}
else if (heldItemType == Material.BONE && target instanceof Tameable) {
else if (heldItemType == Material.BONE && target instanceof Tameable && Permissions.beastLore(player)) {
TamingManager tamingManager = new TamingManager(player);
tamingManager.beastLore(target);
event.setCancelled(true);
@ -139,6 +184,10 @@ public class Combat {
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
Player master = (Player) wolf.getOwner();
if (Misc.isNPCPlayer(master)) {
return;
}
if (targetIsPlayer || targetIsTamedPet) {
if (!Taming.pvpEnabled) {
return;
@ -148,12 +197,26 @@ public class Combat {
return;
}
TamingManager tamingManager = new TamingManager(master);
tamingManager.fastFoodService(wolf, event.getDamage());
tamingManager.sharpenedClaws(event);
tamingManager.gore(event);
if (Permissions.taming(master)) {
TamingManager tamingManager = new TamingManager(master);
int skillLevel = tamingManager.getSkillLevel();
startGainXp(master, tamingManager.getProfile(), target, SkillType.TAMING);
if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(master)) {
tamingManager.fastFoodService(wolf, event.getDamage());
}
if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(master)) {
tamingManager.sharpenedClaws(event);
}
if (Permissions.gore(master)) {
tamingManager.gore(event);
}
if (target != master) {
startGainXp(master, tamingManager.getProfile(), target, SkillType.TAMING);
}
}
}
break;
@ -161,8 +224,8 @@ public class Combat {
case ARROW:
LivingEntity shooter = ((Arrow) damager).getShooter();
//TODO: Is there a reason we're breaking here instead of returning?
if (shooter == null || shooter.getType() != EntityType.PLAYER) {
/* Break instead of return due to Dodge/Counter/Deflect abilities */
if (shooter == null || !(shooter instanceof Player)) {
break;
}
@ -185,33 +248,37 @@ public class Combat {
if (targetIsPlayer) {
Player player = (Player) target;
if (Misc.isNPCPlayer(player)) {
return;
}
ItemStack heldItem = player.getItemInHand();
if (damager instanceof Player) {
if (Swords.pvpEnabled) {
if (Swords.pvpEnabled && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
SwordsManager swordsManager = new SwordsManager(player);
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
}
if (Acrobatics.pvpEnabled) {
if (Acrobatics.pvpEnabled && Permissions.dodge(player)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
acrobaticsManager.dodgeCheck(event);
}
if (Unarmed.pvpEnabled && player.getItemInHand().getType() == Material.AIR) {
if (Unarmed.pvpEnabled && heldItem.getType() == Material.AIR && Permissions.deflect(player)) {
UnarmedManager unarmedManager = new UnarmedManager(player);
unarmedManager.deflectCheck(event);
}
}
else {
if (Swords.pveEnabled && damager instanceof LivingEntity) {
if (Swords.pveEnabled && damager instanceof LivingEntity && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
SwordsManager swordsManager = new SwordsManager(player);
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
}
if (Acrobatics.pveEnabled) {
if (!(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
acrobaticsManager.dodgeCheck(event);
}
if (Acrobatics.pveEnabled && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) && Permissions.dodge(player)) {
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
acrobaticsManager.dodgeCheck(event);
}
}
}
@ -224,24 +291,26 @@ public class Combat {
* @param target The defending entity
* @param event The event to run the archery checks on.
*/
public static void archeryCheck(Player shooter, LivingEntity target, EntityDamageByEntityEvent event) {
private static void archeryCheck(Player shooter, LivingEntity target, EntityDamageByEntityEvent event) {
if (Misc.isNPCPlayer(shooter)) {
return;
}
ArcheryManager archeryManager = new ArcheryManager(shooter);
archeryManager.skillShot(event);
if (Permissions.archery(shooter)) {
ArcheryManager archeryManager = new ArcheryManager(shooter);
archeryManager.skillShot(event);
if (target instanceof Player) {
archeryManager.dazeCheck((Player) target, event);
}
if (target instanceof Player && Permissions.daze(shooter)) {
archeryManager.dazeCheck((Player) target, event);
}
if (!(shooter.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE))) {
archeryManager.trackArrows(target);
}
if (!(shooter.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE)) && Permissions.trackArrows(shooter)) {
archeryManager.trackArrows(target);
}
if (target != shooter) {
startGainXp(shooter, archeryManager.getProfile(), target, SkillType.ARCHERY);
if (target != shooter) {
startGainXp(shooter, archeryManager.getProfile(), target, SkillType.ARCHERY);
}
}
}

View File

@ -6,7 +6,6 @@ import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class AcrobaticsManager extends SkillManager {
public AcrobaticsManager (Player player) {
@ -46,10 +45,6 @@ public class AcrobaticsManager extends SkillManager {
* @param event The event to check
*/
public void dodgeCheck(EntityDamageEvent event) {
if (Misc.isNPCPlayer(player) || !Permissions.dodge(player)) {
return;
}
DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
double chance = (Acrobatics.dodgeMaxChance / Acrobatics.dodgeMaxBonusLevel) * eventHandler.skillModifier;

View File

@ -20,10 +20,6 @@ public class ArcheryManager extends SkillManager {
* @param livingEntity Entity damaged by the arrow
*/
public void trackArrows(LivingEntity livingEntity) {
if (Misc.isNPCPlayer(player) || !Permissions.trackArrows(player)) {
return;
}
ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
double chance = (Archery.retrieveMaxChance / Archery.retrieveMaxBonusLevel) * eventHandler.skillModifier;
@ -40,10 +36,6 @@ public class ArcheryManager extends SkillManager {
* @param event The event to modify
*/
public void dazeCheck(Player defender, EntityDamageEvent event) {
if (Misc.isNPCPlayer(player) || !Permissions.daze(player)) {
return;
}
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
double chance = (Archery.dazeMaxBonus / Archery.dazeMaxBonusLevel) * eventHandler.skillModifier;

View File

@ -2,14 +2,11 @@ package com.gmail.nossr50.skills.axes;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gmail.nossr50.skills.AbilityType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class AxeManager extends SkillManager {
public AxeManager(Player player) {
@ -22,10 +19,6 @@ public class AxeManager extends SkillManager {
* @param event The event to modify
*/
public void bonusDamage(EntityDamageByEntityEvent event) {
if (!Permissions.axeBonus(player)) {
return;
}
AxeBonusDamageEventHandler eventHandler = new AxeBonusDamageEventHandler(this, event);
eventHandler.calculateDamageBonus();
@ -38,10 +31,6 @@ public class AxeManager extends SkillManager {
* @param event The event to modify
*/
public void criticalHitCheck(EntityDamageByEntityEvent event, LivingEntity target) {
if (target.isDead() || (target instanceof Tameable && Misc.isFriendlyPet(player, (Tameable) target)) || !Permissions.criticalHit(player)) {
return;
}
CriticalHitEventHandler eventHandler = new CriticalHitEventHandler(this, event, target);
double chance = (Axes.criticalHitMaxChance / Axes.criticalHitMaxBonusLevel) * eventHandler.skillModifier;
@ -58,10 +47,6 @@ public class AxeManager extends SkillManager {
* @param event The event to modify
*/
public void impact(EntityDamageByEntityEvent event, LivingEntity target) {
if (target.isDead() || !Permissions.impact(player)) {
return;
}
ImpactEventHandler eventHandler = new ImpactEventHandler(this, event, target);
if (Misc.hasArmor(target)) {
@ -78,10 +63,6 @@ public class AxeManager extends SkillManager {
* @param event The event to process
*/
public void skullSplitter(LivingEntity target, int damage) {
if (target.isDead() || !profile.getAbilityMode(AbilityType.SKULL_SPLIITER) || !Permissions.skullSplitter(player)) {
return;
}
SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(player, damage, target);
eventHandler.applyAbilityEffects();
}

View File

@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.Combat;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
public class CounterAttackEventHandler {
@ -23,13 +22,6 @@ public class CounterAttackEventHandler {
this.damage = damage;
}
protected boolean isHoldingSword() {
if (player == null)
return false;
return ItemChecks.isSword(player.getItemInHand());
}
protected void calculateSkillModifier() {
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Swords.counterAttackMaxBonusLevel);
}

View File

@ -3,12 +3,9 @@ package com.gmail.nossr50.skills.swords;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.skills.AbilityType;
import com.gmail.nossr50.skills.Combat;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class SwordsManager extends SkillManager {
public SwordsManager (Player player) {
@ -21,50 +18,32 @@ public class SwordsManager extends SkillManager {
* @param defender The defending entity
*/
public void bleedCheck(LivingEntity defender) {
if (!Permissions.swordsBleed(player)) {
return;
}
BleedEventHandler eventHandler = new BleedEventHandler(this, defender);
if (Combat.shouldBeAffected(player, defender)) {
BleedEventHandler eventHandler = new BleedEventHandler(this, defender);
float chance = (float) ((Swords.bleedMaxChance / Swords.bleedMaxBonusLevel) * skillLevel);
if (chance > Swords.bleedMaxChance) chance = (float) Swords.bleedMaxChance;
float chance = (float) ((Swords.bleedMaxChance / Swords.bleedMaxBonusLevel) * skillLevel);
if (chance > Swords.bleedMaxChance) chance = (float) Swords.bleedMaxChance;
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.addBleedTicks();
eventHandler.sendAbilityMessages();
}
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.addBleedTicks();
eventHandler.sendAbilityMessages();
}
}
public void counterAttackChecks(LivingEntity attacker, int damage) {
if (!Permissions.counterAttack(player)) {
return;
}
CounterAttackEventHandler eventHandler = new CounterAttackEventHandler(this, attacker, damage);
eventHandler.calculateSkillModifier();
if (eventHandler.isHoldingSword()) {
eventHandler.calculateSkillModifier();
float chance = (float) ((Swords.counterAttackMaxChance / Swords.counterAttackMaxBonusLevel) * skillLevel);
if (chance > Swords.counterAttackMaxChance) chance = (float) Swords.counterAttackMaxChance;
float chance = (float) ((Swords.counterAttackMaxChance / Swords.counterAttackMaxBonusLevel) * skillLevel);
if (chance > Swords.counterAttackMaxChance) chance = (float) Swords.counterAttackMaxChance;
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.dealDamage();
eventHandler.sendAbilityMessages();
}
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.dealDamage();
eventHandler.sendAbilityMessages();
}
}
public void serratedStrikes(LivingEntity target, int damage) {
if (!profile.getAbilityMode(AbilityType.SERRATED_STRIKES) || !Permissions.serratedStrikes(player)) {
return;
}
SerratedStrikesEventHandler eventHandler = new SerratedStrikesEventHandler(this, target, damage);
eventHandler.applyAbilityEffects();
}
}

View File

@ -56,12 +56,10 @@ public class TamingManager extends SkillManager {
* @param damage The damage being absorbed by the wolf
*/
public void fastFoodService(Wolf wolf, int damage) {
if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(player)) {
if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
eventHandler.modifyHealth(damage);
}
eventHandler.modifyHealth(damage);
}
}
@ -71,11 +69,8 @@ public class TamingManager extends SkillManager {
* @param event The event to modify
*/
public void sharpenedClaws(EntityDamageEvent event) {
if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(player)) {
SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
eventHandler.modifyEventDamage();
}
SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
eventHandler.modifyEventDamage();
}
/**
@ -84,10 +79,6 @@ public class TamingManager extends SkillManager {
* @param event The event to modify
*/
public void gore(EntityDamageEvent event) {
if (!Permissions.gore(player)) {
return;
}
GoreEventHandler eventHandler = new GoreEventHandler(this, event);
float chance = (float) ((Taming.goreMaxChance / Taming.goreMaxBonusLevel) * skillLevel);
@ -153,10 +144,6 @@ public class TamingManager extends SkillManager {
* @param livingEntity The entity to examine
*/
public void beastLore(LivingEntity livingEntity) {
if (!Permissions.beastLore(player)) {
return;
}
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity);
eventHandler.sendInspectMessage();
}

View File

@ -4,7 +4,6 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.skills.AbilityType;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.util.Misc;
@ -21,10 +20,6 @@ public class UnarmedManager extends SkillManager {
* @param defender The defending player
*/
public void disarmCheck(LivingEntity defender) {
if (!(defender instanceof Player) || !Permissions.disarm(player)) {
return;
}
Player defendingPlayer = (Player) defender;
DisarmEventHandler eventHandler = new DisarmEventHandler(this, defendingPlayer);
@ -49,10 +44,6 @@ public class UnarmedManager extends SkillManager {
* @param event The event to modify
*/
public void deflectCheck(EntityDamageEvent event) {
if (!Permissions.deflect(player)) {
return;
}
DeflectEventHandler eventHandler = new DeflectEventHandler(this, event);
float chance = (float) ((Unarmed.deflectMaxChance / Unarmed.deflectMaxBonusLevel) * skillLevel);
@ -65,9 +56,7 @@ public class UnarmedManager extends SkillManager {
}
public void berserkDamage(EntityDamageEvent event) {
if (!profile.getAbilityMode(AbilityType.BERSERK) || !Permissions.berserk(player)) {
event.setDamage((int) (event.getDamage() * Unarmed.berserkDamageModifier));
}
event.setDamage((int) (event.getDamage() * Unarmed.berserkDamageModifier));
}
/**
@ -76,10 +65,6 @@ public class UnarmedManager extends SkillManager {
* @param event The event to modify.
*/
public void bonusDamage(EntityDamageEvent event) {
if (!Permissions.unarmedBonus(player)) {
return;
}
UnarmedBonusDamageEventHandler eventHandler = new UnarmedBonusDamageEventHandler(this, event);
eventHandler.calculateDamageBonus();