diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java index 4a2a26e..3e880fd 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java @@ -1,11 +1,14 @@ package xyz.oribuin.fishing.augment.impl; import dev.rosewood.rosegarden.config.CommentedConfigurationSection; -import dev.rosewood.rosegarden.config.CommentedFileConfiguration; +import dev.rosewood.rosegarden.utils.StringPlaceholders; import org.jetbrains.annotations.NotNull; import xyz.oribuin.fishing.api.event.ConditionCheckEvent; import xyz.oribuin.fishing.augment.Augment; import xyz.oribuin.fishing.fish.condition.impl.BiomeCondition; +import xyz.oribuin.fishing.util.FishUtils; + +import java.util.List; /** * The functionality of this augment is provided in BiomeCondition.java @@ -28,20 +31,11 @@ public AugmentBiomeDisrupt() { public void onConditionCheck(ConditionCheckEvent event, int level) { if (!(event.getCondition() instanceof BiomeCondition)) return; - if (this.shouldIgnoreBiome(level)) { - event.setResult(true); - } - } + StringPlaceholders plc = StringPlaceholders.of("level", level); + double chance = FishUtils.evaluate(plc.apply(this.chanceFormula)); + if (Math.random() > chance) return; - /** - * Should the biome restrictions be ignored for the player - * - * @param level The level of the augment - * - * @return Results in true if the biome restrictions should be ignored - */ - public boolean shouldIgnoreBiome(int level) { - return Math.random() * 100 < (int) (level * 0.20); + event.setResult(true); } /** @@ -68,4 +62,18 @@ public void saveSettings(@NotNull CommentedConfigurationSection config) { config.set("chance-formula", this.chanceFormula); } + /** + * The comments to be generated at the top of the file when it is created + * + * @return The comments + */ + @Override + public List comments() { + return List.of( + "Augment [Biome Disruption] - When a player catches a fish, there is a chance to ignore the biome restrictions.", + "", + "chance-formula: The formula to calculate the chance to ignore the biome restrictions" + ); + } + } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java index 018027f..154d28c 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java @@ -1,7 +1,7 @@ package xyz.oribuin.fishing.augment.impl; import dev.rosewood.rosegarden.config.CommentedConfigurationSection; -import dev.rosewood.rosegarden.config.CommentedFileConfiguration; +import dev.rosewood.rosegarden.utils.StringPlaceholders; import net.kyori.adventure.text.Component; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -10,10 +10,13 @@ import xyz.oribuin.fishing.augment.Augment; import xyz.oribuin.fishing.fish.Fish; import xyz.oribuin.fishing.fish.condition.Weather; +import xyz.oribuin.fishing.util.FishUtils; + +import java.util.List; public class AugmentCallOfTheSea extends Augment { - private double chancePerLevel = 5.0; + private String chanceFormula = "%level% * 0.05"; // 5% per level private int minFish = 1; private int maxFish = 3; @@ -32,8 +35,9 @@ public AugmentCallOfTheSea() { public void onInitialCatch(InitialFishCatchEvent event, int level) { if (Weather.CLEAR.isState(event.getHook().getLocation())) return; - int chanceToTrigger = (int) (this.chancePerLevel * level); - if (Math.random() * 100 > chanceToTrigger) return; + StringPlaceholders plc = StringPlaceholders.of("level", level); + double chance = FishUtils.evaluate(plc.apply(this.chanceFormula)); + if (Math.random() > chance) return; int fishCaught = this.minFish + (int) (Math.random() * (this.maxFish - this.minFish)); event.setAmountToCatch(event.getAmountToCatch() + fishCaught); @@ -63,7 +67,7 @@ public void onFishCatch(FishContext context, Fish fish, ItemStack stack) { public void loadSettings(@NotNull CommentedConfigurationSection config) { super.loadSettings(config); - this.chancePerLevel = config.getDouble("chance-per-level", 5); // 5% Chance per level + this.chanceFormula = config.getString("chance-formula", this.chanceFormula); // 5% per level this.minFish = config.getInt("min-fish", 1); // Minimum fish caught this.maxFish = config.getInt("max-fish", 3); // Maximum fish caught } @@ -77,9 +81,26 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { public void saveSettings(@NotNull CommentedConfigurationSection config) { super.saveSettings(config); - config.set("chance-per-level", this.chancePerLevel); + config.set("chance-formula", this.chanceFormula); config.set("min-fish", this.minFish); config.set("max-fish", this.maxFish); } + /** + * The comments to be generated at the top of the file when it is created + * + * @return The comments + */ + @Override + public List comments() { + return List.of( + "Augment [Call Of The Sea] - When it is raining, there is a chance to catch multiple fish", + "in a single catch.", + "", + "chance-formula: The formula to calculate the chance this augment triggers", + "min-fish: The minimum additional fish caught", + "max-fish: The maximum additional fish caught" + ); + } + } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java index 4122a67..ee26fa7 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java @@ -1,7 +1,7 @@ package xyz.oribuin.fishing.augment.impl; import dev.rosewood.rosegarden.config.CommentedConfigurationSection; -import dev.rosewood.rosegarden.config.CommentedFileConfiguration; +import dev.rosewood.rosegarden.utils.StringPlaceholders; import net.kyori.adventure.text.Component; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -10,10 +10,13 @@ import xyz.oribuin.fishing.augment.Augment; import xyz.oribuin.fishing.fish.Fish; import xyz.oribuin.fishing.fish.condition.Weather; +import xyz.oribuin.fishing.util.FishUtils; + +import java.util.List; public class AugmentHotspot extends Augment { - private double chancePerLevel = 5.0; + private String chanceFormula = "%level% * 0.05"; // 5% per level private int minFish = 1; private int maxFish = 3; @@ -32,8 +35,9 @@ public AugmentHotspot() { public void onInitialCatch(InitialFishCatchEvent event, int level) { if (!Weather.CLEAR.isState(event.getHook().getLocation())) return; - int chanceToTrigger = (int) (this.chancePerLevel * level); - if (Math.random() * 100 > chanceToTrigger) return; + StringPlaceholders plc = StringPlaceholders.of("level", level); + double chance = FishUtils.evaluate(plc.apply(this.chanceFormula)); + if (Math.random() * 100 > chance) return; int fishCaught = this.minFish + (int) (Math.random() * (this.maxFish - this.minFish)); event.setAmountToCatch(event.getAmountToCatch() + fishCaught); @@ -64,7 +68,7 @@ public void onFishCatch(FishContext context, Fish fish, ItemStack stack) { public void loadSettings(@NotNull CommentedConfigurationSection config) { super.loadSettings(config); - this.chancePerLevel = config.getDouble("chance-per-level", 5); // 5% Chance per level + this.chanceFormula = config.getString("chance-formula", this.chanceFormula); // 5% per level this.minFish = config.getInt("min-fish", 1); // Minimum fish caught this.maxFish = config.getInt("max-fish", 3); // Maximum fish caught } @@ -78,9 +82,26 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { public void saveSettings(@NotNull CommentedConfigurationSection config) { super.saveSettings(config); - config.set("chance-per-level", this.chancePerLevel); + config.set("chance-formula", this.chanceFormula); config.set("min-fish", this.minFish); config.set("max-fish", this.maxFish); } + /** + * The comments to be generated at the top of the file when it is created + * + * @return The comments + */ + @Override + public List comments() { + return List.of( + "Augment [Hotspot] - When the weather is clear, there is a chance to catch multiple fish", + "in a single catch.", + "", + "chance-formula: The formula to calculate the chance this augment triggers", + "min-fish: The minimum additional fish caught", + "max-fish: The maximum additional fish caught" + ); + } + } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPerception.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPerception.java new file mode 100644 index 0000000..ad64295 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPerception.java @@ -0,0 +1,58 @@ +package xyz.oribuin.fishing.augment.impl; + +import dev.rosewood.rosegarden.config.CommentedConfigurationSection; +import org.jetbrains.annotations.NotNull; +import xyz.oribuin.fishing.augment.Augment; + +import java.util.List; + +public class AugmentPerception extends Augment { + + private String formula = "%entropy% + %level% * 0.05"; + + /** + * Create a new augment instance with a name and description + */ + public AugmentPerception() { + super("perception", "Increases the base entropy earned from catching fish."); + } + + /** + * Load the settings from the configuration file + * + * @param config The configuration file to load + */ + @Override + public void loadSettings(@NotNull CommentedConfigurationSection config) { + super.loadSettings(config); + + this.formula = config.getString("formula", this.formula); + } + + /** + * Save the configuration file for the configurable class + * + * @param config The configuration file to save + */ + @Override + public void saveSettings(@NotNull CommentedConfigurationSection config) { + super.saveSettings(config); + + config.set("formula", this.formula); + } + + /** + * The comments to be generated at the top of the file when it is created + * + * @return The comments + */ + @Override + public List comments() { + return List.of( + "Augment [Perception] - Increases the base entropy earned from catching fish.", + "", + "formula: The formula to calculate the additional entropy earned per level" + ); + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java index f2bec02..037b496 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java @@ -1,13 +1,17 @@ package xyz.oribuin.fishing.augment.impl; import dev.rosewood.rosegarden.config.CommentedConfigurationSection; +import dev.rosewood.rosegarden.utils.StringPlaceholders; import org.jetbrains.annotations.NotNull; import xyz.oribuin.fishing.api.event.InitialFishCatchEvent; import xyz.oribuin.fishing.augment.Augment; +import xyz.oribuin.fishing.util.FishUtils; + +import java.util.List; public class AugmentSaturate extends Augment { - private double chancePerLevel = 25.0; + private String chanceFormula = "%level% * 0.15"; // 15% per level public AugmentSaturate() { super("saturate", "Fully saturates the player when they catch a fish"); @@ -24,11 +28,12 @@ public AugmentSaturate() { public void onInitialCatch(InitialFishCatchEvent event, int level) { if (event.getPlayer().getFoodLevel() >= 20.0) return; - int chanceToTrigger = (int) (this.chancePerLevel * level); - if (Math.random() * 100 > chanceToTrigger) return; + StringPlaceholders plc = StringPlaceholders.of("level", level); + double chance = FishUtils.evaluate(plc.apply(this.chanceFormula)); + if (Math.random() * 100 > chance) return; event.getPlayer().setFoodLevel(20); - event.getPlayer().sendMessage("You have been fully saturated!"); + event.getPlayer().sendMessage("You have been fully saturated!"); // todo: use locale } /** @@ -40,7 +45,7 @@ public void onInitialCatch(InitialFishCatchEvent event, int level) { public void loadSettings(@NotNull CommentedConfigurationSection config) { super.loadSettings(config); - this.chancePerLevel = config.getDouble("chance-per-level", 5); // 5% Chance per level + this.chanceFormula = config.getString("chance-formula", this.chanceFormula); } /** @@ -52,7 +57,21 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { public void saveSettings(@NotNull CommentedConfigurationSection config) { super.saveSettings(config); - config.set("chance-per-level", this.chancePerLevel); + config.set("chance-formula", this.chanceFormula); + } + + /** + * The comments to be generated at the top of the file when it is created + * + * @return The comments + */ + @Override + public List comments() { + return List.of( + "Augment [Saturate] - Fully saturates the player when they catch a fish", + "", + "chance-formula: The formula to calculate the chance of the player being fully saturated" + ); } }