Skip to content

Commit

Permalink
better comments & swaps to formulas
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Oct 25, 2024
1 parent 3f6a297 commit 8a24379
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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<String> 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"
);
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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
}
Expand All @@ -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<String> 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"
);
}

}
33 changes: 27 additions & 6 deletions src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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
}
Expand All @@ -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<String> 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"
);
}

}
Original file line number Diff line number Diff line change
@@ -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<String> 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"
);
}

}
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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<String> 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"
);
}

}

0 comments on commit 8a24379

Please sign in to comment.