Browse Source

Fixing a bug where Lucky perk wasn't adding to success

nossr50 6 years ago
parent
commit
5f39a7cb80

+ 1 - 0
Changelog.txt

@@ -8,6 +8,7 @@ Key:
   - Removal
   - Removal
 
 
 Version 2.1.2
 Version 2.1.2
+    (Perks) Fixed a bug where the Lucky perk wasn't adding to success
     (Skills) Tree Feller now works on Mushroom Stems
     (Skills) Tree Feller now works on Mushroom Stems
     (Experience) Wood blocks now give XP and are affected by Tree Feller (6 sided bark blocks)
     (Experience) Wood blocks now give XP and are affected by Tree Feller (6 sided bark blocks)
     (API) Moved XPGainReason from skills to experience package
     (API) Moved XPGainReason from skills to experience package

+ 1 - 1
src/main/java/com/gmail/nossr50/skills/excavation/ExcavationManager.java

@@ -41,7 +41,7 @@ public class ExcavationManager extends SkillManager {
 
 
                 for (ExcavationTreasure treasure : treasures) {
                 for (ExcavationTreasure treasure : treasures) {
                     if (skillLevel >= treasure.getDropLevel()
                     if (skillLevel >= treasure.getDropLevel()
-                            && RandomChanceUtil.checkRandomChanceExecutionSuccess(treasure.getDropChance())) {
+                            && RandomChanceUtil.checkRandomChanceExecutionSuccess(getPlayer(), PrimarySkillType.EXCAVATION, treasure.getDropChance())) {
                         xp += treasure.getXp();
                         xp += treasure.getXp();
                         Misc.dropItem(location, treasure.getDrop());
                         Misc.dropItem(location, treasure.getDrop());
                     }
                     }

+ 16 - 0
src/main/java/com/gmail/nossr50/util/random/RandomChanceSkill.java

@@ -3,6 +3,7 @@ package com.gmail.nossr50.util.random;
 import com.gmail.nossr50.config.AdvancedConfig;
 import com.gmail.nossr50.config.AdvancedConfig;
 import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
 import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
 import com.gmail.nossr50.datatypes.skills.SubSkillType;
 import com.gmail.nossr50.datatypes.skills.SubSkillType;
+import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.player.UserManager;
 import com.gmail.nossr50.util.player.UserManager;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Player;
 
 
@@ -11,6 +12,7 @@ public class RandomChanceSkill implements RandomChanceExecution {
     protected final PrimarySkillType primarySkillType;
     protected final PrimarySkillType primarySkillType;
     protected final SubSkillType subSkillType;
     protected final SubSkillType subSkillType;
     protected final double probabilityCap;
     protected final double probabilityCap;
+    protected final boolean isLucky;
     private int skillLevel;
     private int skillLevel;
 
 
     public RandomChanceSkill(Player player, SubSkillType subSkillType)
     public RandomChanceSkill(Player player, SubSkillType subSkillType)
@@ -23,6 +25,11 @@ public class RandomChanceSkill implements RandomChanceExecution {
             this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
             this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
         else
         else
             this.skillLevel = 0;
             this.skillLevel = 0;
+
+        if(player != null)
+            isLucky = Permissions.lucky(player, primarySkillType);
+        else
+            isLucky = false;
     }
     }
 
 
     public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap)
     public RandomChanceSkill(Player player, SubSkillType subSkillType, boolean hasCap)
@@ -39,6 +46,11 @@ public class RandomChanceSkill implements RandomChanceExecution {
             this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
             this.skillLevel = UserManager.getPlayer(player).getSkillLevel(primarySkillType);
         else
         else
             this.skillLevel = 0;
             this.skillLevel = 0;
+
+        if(player != null)
+            isLucky = Permissions.lucky(player, primarySkillType);
+        else
+            isLucky = false;
     }
     }
 
 
     /**
     /**
@@ -97,4 +109,8 @@ public class RandomChanceSkill implements RandomChanceExecution {
     public double getProbabilityCap() {
     public double getProbabilityCap() {
         return probabilityCap;
         return probabilityCap;
     }
     }
+
+    public boolean isLucky() {
+        return isLucky;
+    }
 }
 }

+ 23 - 1
src/main/java/com/gmail/nossr50/util/random/RandomChanceUtil.java

@@ -63,11 +63,13 @@ public class RandomChanceUtil
      * Checks whether or not the random chance succeeds
      * Checks whether or not the random chance succeeds
      * @return true if the random chance succeeds
      * @return true if the random chance succeeds
      */
      */
-    public static boolean checkRandomChanceExecutionSuccess(double chance)
+    public static boolean checkRandomChanceExecutionSuccess(Player player, PrimarySkillType primarySkillType, double chance)
     {
     {
         //Check the odds
         //Check the odds
         chance *= 100;
         chance *= 100;
 
 
+        chance = addLuck(player, primarySkillType, chance);
+
         /*
         /*
          * Stuff like treasures can specify a drop chance from 0.05 to 100
          * Stuff like treasures can specify a drop chance from 0.05 to 100
          * Because of that we need to use a large int bound and multiply the chance by 100
          * Because of that we need to use a large int bound and multiply the chance by 100
@@ -143,6 +145,10 @@ public class RandomChanceUtil
             //Get chance of success
             //Get chance of success
             chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), maximumProbability, maximumBonusLevel);
             chanceOfSuccess = getChanceOfSuccess(randomChance.getXPos(), maximumProbability, maximumBonusLevel);
         }
         }
+
+        //Add Luck
+        chanceOfSuccess = addLuck(randomChance.isLucky(), chanceOfSuccess);
+
         return chanceOfSuccess;
         return chanceOfSuccess;
     }
     }
 
 
@@ -281,4 +287,20 @@ public class RandomChanceUtil
 
 
         return displayValues;
         return displayValues;
     }
     }
+
+    public static double addLuck(Player player, PrimarySkillType primarySkillType, double chance)
+    {
+        if(Permissions.lucky(player, primarySkillType))
+            return chance * 1.333D;
+        else
+            return chance;
+    }
+
+    public static double addLuck(boolean isLucky, double chance)
+    {
+        if(isLucky)
+            return chance * 1.333D;
+        else
+            return chance;
+    }
 }
 }