浏览代码

Simplified combat ability checks

bm01 13 年之前
父节点
当前提交
e61342177d
共有 2 个文件被更改,包括 43 次插入58 次删除
  1. 6 22
      src/main/java/com/gmail/nossr50/util/Combat.java
  2. 37 36
      src/main/java/com/gmail/nossr50/util/Skills.java

+ 6 - 22
src/main/java/com/gmail/nossr50/util/Combat.java

@@ -23,7 +23,6 @@ import com.gmail.nossr50.config.Config;
 import com.gmail.nossr50.datatypes.AbilityType;
 import com.gmail.nossr50.datatypes.PlayerProfile;
 import com.gmail.nossr50.datatypes.SkillType;
-import com.gmail.nossr50.datatypes.ToolType;
 import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
 import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
 import com.gmail.nossr50.locale.LocaleLoader;
@@ -64,8 +63,6 @@ public class Combat {
             ItemStack itemInHand = attacker.getItemInHand();
             PlayerProfile PPa = Users.getProfile(attacker);
 
-            combatAbilityChecks(attacker);
-
             if (ItemChecks.isSword(itemInHand)) {
                 if (targetIsPlayer || targetIsTamedPet) {
                     if (!configInstance.getSwordsPVP()) {
@@ -76,6 +73,8 @@ public class Combat {
                     return;
                 }
 
+                Skills.abilityCheck(attacker, SkillType.SWORDS);
+
                 SwordsManager swordsManager = new SwordsManager(attacker);
 
                 swordsManager.bleedCheck(target);
@@ -96,6 +95,8 @@ public class Combat {
                     return;
                 }
 
+                Skills.abilityCheck(attacker, SkillType.AXES);
+
                 if (permInstance.axeBonus(attacker)) {
                     Axes.axesBonus(attacker, event);
                 }
@@ -124,6 +125,8 @@ public class Combat {
                     return;
                 }
 
+                Skills.abilityCheck(attacker, SkillType.UNARMED);
+
                 UnarmedManager unarmedManager = new UnarmedManager(attacker);
 
                 unarmedManager.bonusDamage(event);
@@ -218,25 +221,6 @@ public class Combat {
         }
     }
 
-    /**
-     * Process combat abilities based on weapon preparation modes.
-     *
-     * @param attacker The player attacking
-     */
-    public static void combatAbilityChecks(Player attacker) {
-        PlayerProfile PPa = Users.getProfile(attacker);
-
-        if (PPa.getToolPreparationMode(ToolType.AXE)) {
-            Skills.abilityCheck(attacker, SkillType.AXES);
-        }
-        else if (PPa.getToolPreparationMode(ToolType.SWORD)) {
-            Skills.abilityCheck(attacker, SkillType.SWORDS);
-        }
-        else if (PPa.getToolPreparationMode(ToolType.FISTS)) {
-            Skills.abilityCheck(attacker, SkillType.UNARMED);
-        }
-    }
-
     /**
      * Process archery abilities.
      *

+ 37 - 36
src/main/java/com/gmail/nossr50/util/Skills.java

@@ -384,54 +384,55 @@ public class Skills {
      */
     public static void abilityCheck(Player player, SkillType type) {
         PlayerProfile PP = Users.getProfile(player);
-        AbilityType ability = type.getAbility();
         ToolType tool = type.getTool();
 
-        if (type.getTool().inHand(player.getItemInHand())) {
-            if (PP.getToolPreparationMode(tool)) {
-                PP.setToolPreparationMode(tool, false);
-            }
+        if (!PP.getToolPreparationMode(tool)) {
+            return;
+        }
 
-            /* 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 (!PP.getAbilityMode(ability) && !cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
-                    player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)");
-                    return;
-                }
-            }
+        PP.setToolPreparationMode(tool, false);
 
-            int ticks = 2 + (PP.getSkillLevel(type) / 50);
+        AbilityType ability = type.getAbility();
 
-            if (player.hasPermission("mcmmo.perks.activationtime.twelveseconds")) {
-                ticks = ticks + 12;
-            }
-            else if (player.hasPermission("mcmmo.perks.activationtime.eightseconds")) {
-                ticks = ticks + 8;
-            }
-            else if (player.hasPermission("mcmmo.perks.activationtime.fourseconds")) {
-                ticks = ticks + 4;
+        /* 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 (!PP.getAbilityMode(ability) && !cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
+                player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)");
+                return;
             }
+        }
 
-            int maxTicks = ability.getMaxTicks();
+        int ticks = 2 + (PP.getSkillLevel(type) / 50);
 
-            if (maxTicks != 0 && ticks > maxTicks) {
-                ticks = maxTicks;
-            }
+        if (player.hasPermission("mcmmo.perks.activationtime.twelveseconds")) {
+            ticks = ticks + 12;
+        }
+        else if (player.hasPermission("mcmmo.perks.activationtime.eightseconds")) {
+            ticks = ticks + 8;
+        }
+        else if (player.hasPermission("mcmmo.perks.activationtime.fourseconds")) {
+            ticks = ticks + 4;
+        }
 
-            if (!PP.getAbilityMode(ability) && cooldownOver(PP.getSkillDATS(ability), ability.getCooldown(), player)) {
-                player.sendMessage(ability.getAbilityOn());
+        int maxTicks = ability.getMaxTicks();
 
-                for (Player y : player.getWorld().getPlayers()) {
-                    if (y != player && Misc.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
-                        y.sendMessage(ability.getAbilityPlayer(player));
-                    }
-                }
+        if (maxTicks != 0 && ticks > maxTicks) {
+            ticks = maxTicks;
+        }
 
-                PP.setSkillDATS(ability, System.currentTimeMillis() + (ticks * TIME_CONVERSION_FACTOR));
-                PP.setAbilityMode(ability, true);
+        if (!PP.getAbilityMode(ability) && cooldownOver(PP.getSkillDATS(ability), ability.getCooldown(), player)) {
+            player.sendMessage(ability.getAbilityOn());
+
+            for (Player y : player.getWorld().getPlayers()) {
+                if (y != player && Misc.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
+                    y.sendMessage(ability.getAbilityPlayer(player));
+                }
             }
+
+            PP.setSkillDATS(ability, System.currentTimeMillis() + (ticks * TIME_CONVERSION_FACTOR));
+            PP.setAbilityMode(ability, true);
         }
     }