Explorar o código

Burn it with fire

nossr50 %!s(int64=6) %!d(string=hai) anos
pai
achega
3831ca6b0f

+ 1 - 0
Changelog.txt

@@ -9,6 +9,7 @@ Key:
 
 Version 2.0.1
  ! mcMMO skills will now be on a scale from 1-100 instead of 0-1000 (I'll be explaining this in a write-up)
+ ! Refactored some unreadable code relating to SecondaryAbility activation in SkillUtils
 
 
 Version 2.0.0

+ 4 - 3
src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java

@@ -1,5 +1,6 @@
 package com.gmail.nossr50.skills.acrobatics;
 
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import org.bukkit.Location;
 import org.bukkit.Material;
 import org.bukkit.enchantments.Enchantment;
@@ -54,7 +55,7 @@ public class AcrobaticsManager extends SkillManager {
         double modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier);
         Player player = getPlayer();
 
-        if (!isFatal(modifiedDamage) && SkillUtils.activationSuccessful(SecondaryAbility.DODGE, player, getSkillLevel(), activationChance)) {
+        if (!isFatal(modifiedDamage) && SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.DODGE, player, this.skill, getSkillLevel(), activationChance)) {
             ParticleEffectUtils.playDodgeEffect(player);
 
             if (mcMMOPlayer.useChatNotifications()) {
@@ -87,7 +88,7 @@ public class AcrobaticsManager extends SkillManager {
 
         double modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.rollThreshold);
 
-        if (!isFatal(modifiedDamage) && SkillUtils.activationSuccessful(SecondaryAbility.ROLL, player, getSkillLevel(), activationChance)) {
+        if (!isFatal(modifiedDamage) && SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.ROLL, player, this.skill, getSkillLevel(), activationChance)) {
             player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text"));
             applyXpGain(calculateRollXP(damage, true), XPGainReason.PVE);
 
@@ -111,7 +112,7 @@ public class AcrobaticsManager extends SkillManager {
     private double gracefulRollCheck(double damage) {
         double modifiedDamage = Acrobatics.calculateModifiedRollDamage(damage, Acrobatics.gracefulRollThreshold);
 
-        if (!isFatal(modifiedDamage) && SkillUtils.activationSuccessful(SecondaryAbility.GRACEFUL_ROLL, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!isFatal(modifiedDamage) && SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.GRACEFUL_ROLL, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             getPlayer().sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc"));
             applyXpGain(calculateRollXP(damage, true), XPGainReason.PVE);
 

+ 4 - 3
src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java

@@ -1,5 +1,6 @@
 package com.gmail.nossr50.skills.archery;
 
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import org.bukkit.Location;
 import org.bukkit.entity.Entity;
 import org.bukkit.entity.LivingEntity;
@@ -58,7 +59,7 @@ public class ArcheryManager extends SkillManager {
      * @param target The {@link LivingEntity} damaged by the arrow
      */
     public void retrieveArrows(LivingEntity target) {
-        if (SkillUtils.activationSuccessful(SecondaryAbility.RETRIEVE, getPlayer(), getSkillLevel(), activationChance)) {
+        if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.RETRIEVE, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             Archery.incrementTrackerValue(target);
         }
     }
@@ -69,7 +70,7 @@ public class ArcheryManager extends SkillManager {
      * @param defender The {@link Player} being affected by the ability
      */
     public double daze(Player defender) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.DAZE, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.DAZE, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             return 0;
         }
 
@@ -96,7 +97,7 @@ public class ArcheryManager extends SkillManager {
      * @param damage The amount of damage initially dealt by the event
      */
     public double skillShot(double damage) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.SKILL_SHOT, getPlayer())) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.ALWAYS_FIRES, SecondaryAbility.SKILL_SHOT, getPlayer(), null, 0, 0)) {
             return damage;
         }
 

+ 6 - 4
src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java

@@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.axes;
 
 import java.util.Map;
 
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import org.bukkit.entity.LivingEntity;
 import org.bukkit.entity.Player;
 import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
@@ -54,7 +55,7 @@ public class AxesManager extends SkillManager {
      * Handle the effects of the Axe Mastery ability
      */
     public double axeMastery() {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.AXE_MASTERY, getPlayer())) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.ALWAYS_FIRES, SecondaryAbility.AXE_MASTERY, getPlayer(), null, 0, 0)) {
             return 0;
         }
 
@@ -68,7 +69,7 @@ public class AxesManager extends SkillManager {
      * @param damage The amount of damage initially dealt by the event
      */
     public double criticalHit(LivingEntity target, double damage) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.CRITICAL_HIT, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.CRITICAL_HIT, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             return 0;
         }
 
@@ -104,7 +105,7 @@ public class AxesManager extends SkillManager {
 
         for (ItemStack armor : target.getEquipment().getArmorContents()) {
             if (armor != null && ItemUtils.isArmor(armor)) {
-                if (SkillUtils.activationSuccessful(SecondaryAbility.ARMOR_IMPACT, getPlayer(), Axes.impactChance, activationChance)) {
+                if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_STATIC_CHANCE, SecondaryAbility.ARMOR_IMPACT, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
                     SkillUtils.handleDurabilityChange(armor, durabilityDamage, Axes.impactMaxDurabilityModifier);
                 }
             }
@@ -117,7 +118,8 @@ public class AxesManager extends SkillManager {
      * @param target The {@link LivingEntity} being affected by the ability
      */
     public double greaterImpact(LivingEntity target) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.GREATER_IMPACT, getPlayer(), Axes.greaterImpactChance, activationChance)) {
+        //static chance (3rd param)
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_STATIC_CHANCE, SecondaryAbility.GREATER_IMPACT, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             return 0;
         }
 

+ 6 - 5
src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java

@@ -12,6 +12,7 @@ import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
 import com.gmail.nossr50.skills.SkillManager;
 import com.gmail.nossr50.util.*;
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.Location;
 import org.bukkit.Material;
@@ -157,7 +158,7 @@ public class HerbalismManager extends SkillManager {
         }
 
         for (int i = greenTerra ? 2 : 1; i != 0; i--) {
-            if (SkillUtils.activationSuccessful(SecondaryAbility.HERBALISM_DOUBLE_DROPS, getPlayer(), getSkillLevel(), activationChance)) {
+            if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.HERBALISM_DOUBLE_DROPS, player, this.skill, getSkillLevel(), activationChance)) {
                 for (ItemStack item : drops) {
                     Misc.dropItems(Misc.getBlockCenter(blockState), item, amount);
                 }
@@ -172,7 +173,7 @@ public class HerbalismManager extends SkillManager {
      * @return true if the ability was successful, false otherwise
      */
     public boolean processGreenThumbBlocks(BlockState blockState) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.GREEN_THUMB_BLOCK, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.GREEN_THUMB_BLOCK, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             getPlayer().sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
             return false;
         }
@@ -187,7 +188,7 @@ public class HerbalismManager extends SkillManager {
      * @return true if the ability was successful, false otherwise
      */
     public boolean processHylianLuck(BlockState blockState) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.HYLIAN_LUCK, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.HYLIAN_LUCK, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             return false;
         }
 
@@ -242,7 +243,7 @@ public class HerbalismManager extends SkillManager {
         playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
         player.updateInventory();
 
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.SHROOM_THUMB, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.SHROOM_THUMB, player, this.skill, getSkillLevel(), activationChance)) {
             player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
             return false;
         }
@@ -299,7 +300,7 @@ public class HerbalismManager extends SkillManager {
             return;
         }
 
-        if (!greenTerra && !SkillUtils.activationSuccessful(SecondaryAbility.GREEN_THUMB_PLANT, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!greenTerra && !SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.GREEN_THUMB_PLANT, player, this.skill, getSkillLevel(), activationChance)) {
             return;
         }
 

+ 3 - 1
src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java

@@ -15,6 +15,7 @@ import com.gmail.nossr50.util.BlockUtils;
 import com.gmail.nossr50.util.EventUtils;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Permissions;
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.Material;
@@ -76,8 +77,9 @@ public class MiningManager extends SkillManager {
 
         boolean silkTouch = player.getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH);
 
+        //TODO: Make this readable
         for (int i = mcMMOPlayer.getAbilityMode(skill.getAbility()) ? 2 : 1; i != 0; i--) {
-            if (SkillUtils.activationSuccessful(SecondaryAbility.MINING_DOUBLE_DROPS, getPlayer(), getSkillLevel(), activationChance)) {
+            if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.MINING_DOUBLE_DROPS, player, this.skill, getSkillLevel(), activationChance)) {
                 if (silkTouch) {
                     Mining.handleSilkTouchDrops(blockState);
                 }

+ 2 - 1
src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java

@@ -15,6 +15,7 @@ import com.gmail.nossr50.util.EventUtils;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.StringUtils;
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.Material;
 import org.bukkit.Sound;
@@ -266,7 +267,7 @@ public class RepairManager extends SkillManager {
      * @return true if bonus granted, false otherwise
      */
     private boolean checkPlayerProcRepair() {
-        if (SkillUtils.activationSuccessful(SecondaryAbility.SUPER_REPAIR, getPlayer(), getSkillLevel(), activationChance)) {
+        if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.SUPER_REPAIR, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             getPlayer().sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy"));
             return true;
         }

+ 2 - 1
src/main/java/com/gmail/nossr50/skills/smelting/SmeltingManager.java

@@ -16,6 +16,7 @@ import com.gmail.nossr50.util.EventUtils;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.skills.ParticleEffectUtils;
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.ChatColor;
 import org.bukkit.Material;
@@ -40,7 +41,7 @@ public class SmeltingManager extends SkillManager {
     }
 
     public boolean isSecondSmeltSuccessful() {
-        return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.SECOND_SMELT) && SkillUtils.activationSuccessful(SecondaryAbility.SECOND_SMELT, getPlayer(), getSkillLevel(), activationChance);
+        return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.SECOND_SMELT) && SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.SECOND_SMELT, getPlayer(), this.skill, getSkillLevel(), activationChance);
     }
 
     /**

+ 3 - 2
src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java

@@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.swords;
 
 import java.util.Map;
 
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import org.bukkit.entity.Entity;
 import org.bukkit.entity.LivingEntity;
 import org.bukkit.entity.Player;
@@ -48,7 +49,7 @@ public class SwordsManager extends SkillManager {
      * @param target The defending entity
      */
     public void bleedCheck(LivingEntity target) {
-        if (SkillUtils.activationSuccessful(SecondaryAbility.BLEED, getPlayer(), getSkillLevel(), activationChance)) {
+        if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.BLEED, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
 
             if (getSkillLevel() >= AdvancedConfig.getInstance().getMaxBonusLevel(SecondaryAbility.BLEED)) {
                 BleedTimerTask.add(target, Swords.bleedMaxTicks);
@@ -82,7 +83,7 @@ public class SwordsManager extends SkillManager {
             return;
         }
 
-        if (SkillUtils.activationSuccessful(SecondaryAbility.COUNTER, getPlayer(), getSkillLevel(), activationChance)) {
+        if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.COUNTER, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             CombatUtils.dealDamage(attacker, damage / Swords.counterAttackModifier, getPlayer());
 
             getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Countered"));

+ 4 - 2
src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java

@@ -18,6 +18,7 @@ import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.StringUtils;
 import com.gmail.nossr50.util.player.UserManager;
 import com.gmail.nossr50.util.skills.ParticleEffectUtils;
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.Location;
 import org.bukkit.Sound;
@@ -83,7 +84,8 @@ public class TamingManager extends SkillManager {
      * @param damage The damage being absorbed by the wolf
      */
     public void fastFoodService(Wolf wolf, double damage) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.FAST_FOOD, getPlayer(), Taming.fastFoodServiceActivationChance, activationChance)) {
+        //static chance (3rd param)
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_STATIC_CHANCE, SecondaryAbility.FAST_FOOD, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             return;
         }
 
@@ -103,7 +105,7 @@ public class TamingManager extends SkillManager {
      * @param damage The initial damage
      */
     public double gore(LivingEntity target, double damage) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.GORE, getPlayer(), getSkillLevel(), activationChance)) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.GORE, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             return 0;
         }
 

+ 7 - 5
src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java

@@ -14,6 +14,7 @@ import com.gmail.nossr50.util.ItemUtils;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.player.UserManager;
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.Material;
 import org.bukkit.block.BlockState;
@@ -55,7 +56,7 @@ public class UnarmedManager extends SkillManager {
     }
 
     public boolean blockCrackerCheck(BlockState blockState) {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.BLOCK_CRACKER, getPlayer())) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.ALWAYS_FIRES, SecondaryAbility.BLOCK_CRACKER, getPlayer(), null, 0, 0)) {
             return false;
         }
 
@@ -81,7 +82,7 @@ public class UnarmedManager extends SkillManager {
      * @param defender The defending player
      */
     public void disarmCheck(Player defender) {
-        if (SkillUtils.activationSuccessful(SecondaryAbility.DISARM, getPlayer(), getSkillLevel(), activationChance) && !hasIronGrip(defender)) {
+        if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.DISARM, getPlayer(), this.skill, getSkillLevel(), activationChance) && !hasIronGrip(defender)) {
             if (EventUtils.callDisarmEvent(defender).isCancelled()) {
                 return;
             }
@@ -101,7 +102,7 @@ public class UnarmedManager extends SkillManager {
      * Check for arrow deflection.
      */
     public boolean deflectCheck() {
-        if (SkillUtils.activationSuccessful(SecondaryAbility.DEFLECT, getPlayer(), getSkillLevel(), activationChance)) {
+        if (SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.DEFLECT, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
             return true;
         }
@@ -124,10 +125,11 @@ public class UnarmedManager extends SkillManager {
      * Handle the effects of the Iron Arm ability
      */
     public double ironArm() {
-        if (!SkillUtils.activationSuccessful(SecondaryAbility.IRON_ARM, getPlayer())) {
+        if (!SkillUtils.isActivationSuccessful(SecondarySkillActivationType.ALWAYS_FIRES, SecondaryAbility.IRON_ARM, getPlayer(), null, 0, 0)) {
             return 0;
         }
 
+        //linear check no cap
         return Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
     }
 
@@ -138,7 +140,7 @@ public class UnarmedManager extends SkillManager {
      * @return true if the defender was not disarmed, false otherwise
      */
     private boolean hasIronGrip(Player defender) {
-        if (!Misc.isNPCEntity(defender) && Permissions.secondaryAbilityEnabled(defender, SecondaryAbility.IRON_GRIP) && SkillUtils.activationSuccessful(SecondaryAbility.IRON_GRIP, defender, skill)) {
+        if (!Misc.isNPCEntity(defender) && Permissions.secondaryAbilityEnabled(defender, SecondaryAbility.IRON_GRIP) && SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_NO_CAP, SecondaryAbility.IRON_GRIP, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
             defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
             getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
 

+ 2 - 1
src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java

@@ -13,6 +13,7 @@ import com.gmail.nossr50.skills.SkillManager;
 import com.gmail.nossr50.skills.woodcutting.Woodcutting.ExperienceGainMethod;
 import com.gmail.nossr50.util.*;
 import com.gmail.nossr50.util.skills.CombatUtils;
+import com.gmail.nossr50.util.skills.SecondarySkillActivationType;
 import com.gmail.nossr50.util.skills.SkillUtils;
 import org.bukkit.Material;
 import org.bukkit.block.Block;
@@ -38,7 +39,7 @@ public class WoodcuttingManager extends SkillManager {
     }
 
     protected boolean canGetDoubleDrops() {
-        return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.WOODCUTTING_DOUBLE_DROPS) && SkillUtils.activationSuccessful(SecondaryAbility.WOODCUTTING_DOUBLE_DROPS, getPlayer(), getSkillLevel(), activationChance);
+        return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.WOODCUTTING_DOUBLE_DROPS) && SkillUtils.isActivationSuccessful(SecondarySkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SecondaryAbility.WOODCUTTING_DOUBLE_DROPS, getPlayer(), this.skill, getSkillLevel(), activationChance);
     }
 
     /**

+ 11 - 0
src/main/java/com/gmail/nossr50/util/skills/SecondarySkillActivationType.java

@@ -0,0 +1,11 @@
+package com.gmail.nossr50.util.skills;
+
+/**
+ * Defines the type of random calculations to use with a given skill
+ */
+public enum SecondarySkillActivationType {
+    RANDOM_LINEAR_100_SCALE_NO_CAP, //A skill level of 100 would guarantee the proc with this
+    RANDOM_LINEAR_100_SCALE_WITH_CAP, //This one is based on a scale of 1-100 but with a specified cap for max bonus
+    RANDOM_STATIC_CHANCE, //The skill always has a SPECIFIC chance to succeed
+    ALWAYS_FIRES //This skill isn't chance based and always fires
+}

+ 82 - 25
src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java

@@ -25,7 +25,6 @@ import org.bukkit.inventory.Recipe;
 import org.bukkit.inventory.ShapedRecipe;
 import org.bukkit.inventory.ShapelessRecipe;
 import org.bukkit.inventory.meta.ItemMeta;
-import org.bukkit.block.data.BlockData;
 import org.bukkit.potion.PotionEffect;
 import org.bukkit.potion.PotionEffectType;
 
@@ -198,43 +197,101 @@ public class SkillUtils {
         itemStack.setDurability((short) Math.min(itemStack.getDurability() + durabilityModifier, maxDurability));
     }
 
-    public static boolean activationSuccessful(SecondaryAbility skillAbility, Player player, SkillType skill) {
-        return activationSuccessful(skillAbility, player, UserManager.getPlayer(player).getSkillLevel(skill), PerksUtils.handleLuckyPerks(player, skill));
+    /**
+     * Checks whether or not the given skill succeeds
+     * @param skillAbility The ability corresponding to this check
+     * @param player The player whose skill levels we are checking against
+     * @param skillLevel The skill level of the corresponding skill
+     * @param activationChance used to determine activation chance
+     * @param maxChance maximum chance
+     * @param maxLevel maximum skill level bonus
+     * @return true if random chance succeeds and the event isn't cancelled
+     */
+    private static boolean performRandomSkillCheck(SecondaryAbility skillAbility, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
+        double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
+        return performRandomSkillCheckStatic(skillAbility, player, activationChance, chance);
     }
 
-    public static boolean activationSuccessful(SecondaryAbility skillAbility, Player player, int skillLevel, int activationChance) {
-        return activationSuccessful(skillAbility, player, skillLevel, activationChance, AdvancedConfig.getInstance().getMaxChance(skillAbility), AdvancedConfig.getInstance().getMaxBonusLevel(skillAbility));
+    /**
+     * This method is the final step in determining if a Sub-Skill / Secondary Skill in mcMMO successfully activates either from chance or otherwise
+     *
+     * There are 4 types of Sub-Skill / Secondary Skill activations in mcMMO
+     * 1) Random Chance with a linear increase to 100% (At 100 Skill Level)
+     * 2) Random Chance with a linear increase to 100% at 100 Skill Level but caps out earlier in the curve (At x/100 Skill Level)
+     * 3) Random Chance with a pre-determined activation roll and threshold roll
+     * 4) Skills that are not chance based
+     *
+     * Random skills check for success based on numbers and then fire a cancellable event, if that event is not cancelled they succeed
+     * All other skills just fire the cancellable event and succeed if it is not cancelled
+     *
+     * @param skillAbility The identifier for this specific sub-skill
+     * @param player The owner of this sub-skill
+     * @param skill The identifier for the parent of our sub-skill
+     * @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
+     * @param secondarySkillActivationType this value represents what kind of activation procedures this sub-skill uses
+     * @return returns true if all conditions are met and they event is not cancelled
+     */
+    public static boolean isActivationSuccessful(SecondarySkillActivationType secondarySkillActivationType, SecondaryAbility skillAbility, Player player,
+                                                    SkillType skill, int skillLevel, int activationChance)
+    {
+        //Maximum chance to succeed
+        double maxChance = AdvancedConfig.getInstance().getMaxChance(skillAbility);
+        //Maximum roll we can make
+        int maxBonusLevel = AdvancedConfig.getInstance().getMaxBonusLevel(skillAbility);
+
+        switch(secondarySkillActivationType)
+        {
+            //100 Skill = Guaranteed
+            case RANDOM_LINEAR_100_SCALE_NO_CAP:
+                return performRandomSkillCheck(skillAbility, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), 100.0D, 100);
+            case RANDOM_LINEAR_100_SCALE_WITH_CAP:
+                return performRandomSkillCheck(skillAbility, player, skillLevel, PerksUtils.handleLuckyPerks(player, skill), AdvancedConfig.getInstance().getMaxChance(skillAbility), AdvancedConfig.getInstance().getMaxBonusLevel(skillAbility));
+            case RANDOM_STATIC_CHANCE:
+                //Grab the static activation chance of this skill
+                double staticRoll = getSecondaryAbilityStaticChance(skillAbility) / activationChance;
+                return performRandomSkillCheckStatic(skillAbility, player, activationChance, staticRoll);
+            case ALWAYS_FIRES:
+                SecondaryAbilityEvent event = EventUtils.callSecondaryAbilityEvent(player, skillAbility);
+                return !event.isCancelled();
+                default:
+                    return false;
+        }
     }
 
-    public static boolean activationSuccessful(SecondaryAbility skillAbility, Player player, int skillLevel, int activationChance, double maxChance, int maxLevel) {
-        double chance = (maxChance / maxLevel) * Math.min(skillLevel, maxLevel) / activationChance;
-        return propagateSecondaryAbilityEvent(skillAbility, player, activationChance, chance);
+    /**
+     * Grabs static activation rolls for Secondary Abilities
+     * @param secondaryAbility The secondary ability to grab properties of
+     * @return The static activation roll involved in the RNG calculation
+     */
+    public static double getSecondaryAbilityStaticChance(SecondaryAbility secondaryAbility)
+    {
+        switch(secondaryAbility)
+        {
+            case ARMOR_IMPACT:
+                return AdvancedConfig.getInstance().getImpactChance();
+            case GREATER_IMPACT:
+                return AdvancedConfig.getInstance().getGreaterImpactChance();
+            case FAST_FOOD:
+                return AdvancedConfig.getInstance().getFastFoodChance();
+                default:
+                    return 100.0D;
+        }
     }
 
     /**
-     * Sends an event out regarding activation of RNG based sub-skills
-     * @param skillAbility The random-chance ability
-     * @param player The player that the skill belong to
-     * @param activationChance parameter used in activation calculations
-     * @param chance parameter used in activation calculations
-     * @return returns true if successful
+     * Used to determine whether or not a sub-skill activates from random chance (using static values)
+     * @param skillAbility The identifier for this specific sub-skill
+     * @param player The owner of this sub-skill
+     * @param activationChance This is the value that we roll against, 100 is normal, and 75 is for lucky perk
+     * @param chance This is the static modifier for our random calculations
+     * @return true if random chance was successful and the event wasn't cancelled
      */
-    private static boolean propagateSecondaryAbilityEvent(SecondaryAbility skillAbility, Player player, int activationChance, double chance) {
+    private static boolean performRandomSkillCheckStatic(SecondaryAbility skillAbility, Player player, int activationChance, double chance) {
         SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(player, skillAbility, chance);
         mcMMO.p.getServer().getPluginManager().callEvent(event);
         return (event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance) && !event.isCancelled();
     }
 
-    public static boolean activationSuccessful(SecondaryAbility skillAbility, Player player, double staticChance, int activationChance) {
-        double chance = staticChance / activationChance;
-        return propagateSecondaryAbilityEvent(skillAbility, player, activationChance, chance);
-    }
-
-    public static boolean activationSuccessful(SecondaryAbility skillAbility, Player player) {
-        SecondaryAbilityEvent event = EventUtils.callSecondaryAbilityEvent(player, skillAbility);
-        return !event.isCancelled();
-    }
-
     public static boolean treasureDropSuccessful(Player player, double dropChance, int activationChance) {
         SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(player, SecondaryAbility.EXCAVATION_TREASURE_HUNTER, dropChance / activationChance);
         mcMMO.p.getServer().getPluginManager().callEvent(event);

+ 24 - 24
src/main/resources/advanced.yml

@@ -29,7 +29,7 @@ Skills:
             # MaxBonusLevel: On this level or higher, the dodge chance will not go higher than <ChanceMax>
             # DamageModifier: Dodge damage will be divided by this modifier
             ChanceMax: 20.0
-            MaxBonusLevel: 800
+            MaxBonusLevel: 80
             DamageModifier: 2.0
 
         Roll:
@@ -37,7 +37,7 @@ Skills:
             # MaxBonusLevel: On this level or higher, the roll chance will not go higher than <ChanceMax>
             # DamageThreshold: The max damage a player can negate with a roll
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
             DamageThreshold: 7.0
 
         GracefulRoll:
@@ -45,7 +45,7 @@ Skills:
             # MaxBonusLevel: On this level or higher, the graceful roll chance will not go higher than <ChanceMax>
             # DamageThreshold: The max damage a player can negate with a graceful roll
             ChanceMax: 100.0
-            MaxBonusLevel: 500
+            MaxBonusLevel: 50
             DamageThreshold: 14.0
     #
     #  Settings for Alchemy
@@ -57,7 +57,7 @@ Skills:
             # MinSpeed: Minimum brewing speed allowed when at <UnlockLevel> or lower
             # MaxSpeed: Maximum brewing speed allowed when at <MaxBonusLevel> or higher
             UnlockLevel: 100
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
             MinSpeed: 1.0
             MaxSpeed: 4.0
             
@@ -89,14 +89,14 @@ Skills:
             # MaxBonusLevel: Maximum bonus level of Daze, when a player reaches this level his chance of causing a daze will be <ChanceMax>
             # Modifier: Extra damage for arrows that cause a daze (2 damage = 1 heart)
             ChanceMax: 50.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
             BonusDamage: 4.0
 
         Retrieve:
             # ChanceMax: Maximum chance of retrieving arrows when on <MaxBonusLevel> or higher
             # MaxBonusLevel: Maximum bonus level for Arrow retrieval, at this level the chance of retrieving arrows from mobs is <ChanceMax>
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         # ForceMultiplier: Multiply the force of the bow by this for an XP boost.
         ForceMultiplier: 2.0
@@ -108,7 +108,7 @@ Skills:
             # MaxBonus: Maximum bonus damage when on <MaxBonusLevel> or higher
             # MaxBonusLevel: Level where <MaxBonus> is reached
             MaxBonus: 4.0
-            MaxBonusLevel: 200
+            MaxBonusLevel: 20
 
         CriticalHit:
             # ChanceMax: Maximum chance of causing a critical hit when on <MaxBonusLevel> or higher
@@ -203,25 +203,25 @@ Skills:
             # MaxBonusLevel: On this level, GreenThumb chance will be <ChanceMax>
             StageChange: 200
             ChanceMax: 100.0
-            MaxBonusLevel: 1500
+            MaxBonusLevel: 150
 
         DoubleDrops:
             # ChanceMax: Maximum chance of receiving double drops when on <MaxBonusLevel> or higher
             # MaxBonusLevel: Level when <ChanceMax> of receiving double drops is reached
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         HylianLuck:
             # ChanceMax: Maximum chance of Hylian Luck when on <MaxBonusLevel> or higher
             # MaxBonusLevel: On this level, Hylian Luck chance will be <ChanceMax>
             ChanceMax: 10.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         ShroomThumb:
             # ChanceMax: Maximum chance of ShroomThumb when on <MaxBonusLevel> or higher
             # MaxBonusLevel: On this level, ShroomThumb chance will be <ChanceMax>
             ChanceMax: 50.0
-            MaxBonusLevel: 1500
+            MaxBonusLevel: 100
     #
     #  Settings for Mining
     ###
@@ -230,7 +230,7 @@ Skills:
             # ChanceMax: Maximum chance of receiving double drops when on <MaxBonusLevel> or higher
             # MaxBonusLevel: Level when <ChanceMax> of receiving double drops is reached
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         # BlastMining_Rank: BlastMining rank unlocks
         BlastMining:
@@ -306,13 +306,13 @@ Skills:
             # MaxBonusPercentage: Maximum bonus percentage for Repair Mastery
             # MaxBonusLevel: On this level, the maximum bonus is reached
             MaxBonusPercentage: 200.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         SuperRepair:
             # ChanceMax: Maximum chance of Super Repair when on <MaxBonusLevel> or higher
             # MaxBonusLevel: On this level, Super Repair chance will be <ChanceMax>
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         ArcaneForging:
             May_Lose_Enchants: true
@@ -351,7 +351,7 @@ Skills:
         # MaxPercentage: Maximum percentage of materials to be returned when Salvaging
         # MaxPercentageLevel: On this level, the Salvage percentage will be <MaxPercentage>
         MaxPercentage: 100.0
-        MaxPercentageLevel: 1000
+        MaxPercentageLevel: 100
 
         # AdvancedSalvage_UnlockLevel: The level at which Advance Salvage become available
         AdvancedSalvage:
@@ -401,13 +401,13 @@ Skills:
             # Multiplier: The furnace burn time will be multiplied by this value.
             # MaxBonusLevel: On this level, the efficiency multiplier will stop increasing
             Multiplier: 3.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         SecondSmelt:
             # ChanceMax: Maximum chance of triggering Second Smelt
             # MaxBonusLevel: On this level, the chance to cause Second Smelt will be <ChanceMax>
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         FluxMining:
             # UnlockLevel: Level when Flux Mining becomes available
@@ -445,7 +445,7 @@ Skills:
             # ChanceMax: Maximum chance of triggering bleeding
             # MaxBonusLevel: On this level, the chance to cause Bleeding will be <ChanceMax>
             ChanceMax: 75.0
-            MaxBonusLevel: 750
+            MaxBonusLevel: 75
 
             # DamagePlayer: Bleeding damage dealt to players
             # DamageMobs: Bleeding damage dealt to mobs
@@ -463,7 +463,7 @@ Skills:
             # ChanceMax: Maximum chance of triggering a counter attack
             # MaxBonusLevel: On this level, the chance to Counter will be <ChanceMax>
             ChanceMax: 30.0
-            MaxBonusLevel: 600
+            MaxBonusLevel: 60
 
             # DamageModifier: Damaged caused by the damager will get divided by this modifier and dealt back to the damager
             DamageModifier: 2.0
@@ -481,7 +481,7 @@ Skills:
             # ChanceMax: Maximum chance of triggering gore
             # MaxBonusLevel: On this level, the chance to cause Gore will be <ChanceMax>
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
             # BleedTicks: Determines the length of the bleeding effect
             # Modifier: Damage will get multiplied by this modifier
@@ -538,20 +538,20 @@ Skills:
             # MaxBonusLevel: Level when the maximum chance to disarm is reached
             # AntiTheft: Determines if only the disarmed player can retrieve disarmed items
             ChanceMax: 33.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
             AntiTheft: false
 
         Deflect:
             # ChanceMax: Maximum chance of deflecting arrows
             # MaxBonusLevel: Level when the maximum chance to deflect is reached
             ChanceMax: 50.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         IronGrip:
             # ChanceMax: Maximum chance of preventing being disarmed
             # MaxBonusLevel: Level when the maximum chance to prevent being disarmed is reached
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 
         IronArm:
             # BonusMin: Minimum bonus damage for unarmed
@@ -572,7 +572,7 @@ Skills:
             # ChanceMax: Maximum chance of receiving double drops
             # MaxBonusLevel: Level when the maximum chance of receiving double drops is reached
             ChanceMax: 100.0
-            MaxBonusLevel: 1000
+            MaxBonusLevel: 100
 #
 #  Customize the kraken!
 ###