Made luck level improve fish length too

This commit is contained in:
Teriuihi 2023-09-30 00:22:47 +02:00
parent 1b160b5ca7
commit 8d5c369877
3 changed files with 18 additions and 11 deletions

View File

@ -92,8 +92,16 @@ public class Fish {
* Gives back a different result each call, it generates a length based on the min and max length values for a fish * Gives back a different result each call, it generates a length based on the min and max length values for a fish
* @return a random length for this fish * @return a random length for this fish
*/ */
public float generateLength() { public float generateLength(int luckLevel) {
return new Random().nextFloat(minLength, maxLength); float modifiedMinLength = minLength;
if (luckLevel >= 1 && luckLevel <= 5) {
float improvement = luckLevel * 0.1f * (maxLength - minLength);
float availableSpace = maxLength - minLength - 1;
modifiedMinLength += Math.min(improvement, availableSpace);
}
return new Random().nextFloat(modifiedMinLength, maxLength);
} }
public net.kyori.adventure.text.@NotNull Component fishName() { public net.kyori.adventure.text.@NotNull Component fishName() {

View File

@ -4,9 +4,6 @@ import com.alttd.fishingevent.config.Fishes;
import com.alttd.fishingevent.fish.Fish; import com.alttd.fishingevent.fish.Fish;
import com.alttd.fishingevent.objects.*; import com.alttd.fishingevent.objects.*;
import com.alttd.fishingevent.util.Logger; import com.alttd.fishingevent.util.Logger;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -22,10 +19,7 @@ public class FishGenerator {
this.logger = logger; this.logger = logger;
} }
public Optional<Fish> getFish(ItemStack fishingRod, FishType fishType) { public Optional<Fish> getFish(int luckLevel, FishType fishType) {
if (!fishingRod.getType().equals(Material.FISHING_ROD))
return Optional.empty();
int luckLevel = fishingRod.getEnchantmentLevel(Enchantment.LUCK);
int maxChanceRange = rarityManager.getMaxChanceRange(fishType); int maxChanceRange = rarityManager.getMaxChanceRange(fishType);
int rarityValue = CustomRandom.generateNumber(0, maxChanceRange, luckLevel + 1); int rarityValue = CustomRandom.generateNumber(0, maxChanceRange, luckLevel + 1);
Optional<Rarity> optionalRarity = rarityManager.getRarityFromNumber(fishType, rarityValue); Optional<Rarity> optionalRarity = rarityManager.getRarityFromNumber(fishType, rarityValue);

View File

@ -200,14 +200,19 @@ public class CatchFish implements Listener {
ItemStack activeItem = player.getInventory().getItemInMainHand(); ItemStack activeItem = player.getInventory().getItemInMainHand();
if (!activeItem.getType().equals(Material.FISHING_ROD)) if (!activeItem.getType().equals(Material.FISHING_ROD))
activeItem = player.getInventory().getItemInOffHand(); activeItem = player.getInventory().getItemInOffHand();
Optional<Fish> optionalFish = waterFishGenerator.getFish(activeItem, fishType); if (!activeItem.getType().equals(Material.FISHING_ROD)) {
return Optional.empty();
}
int luckLevel = activeItem.getEnchantmentLevel(Enchantment.LUCK);
Optional<Fish> optionalFish = waterFishGenerator.getFish(luckLevel, fishType);
if (optionalFish.isEmpty()) { if (optionalFish.isEmpty()) {
logger.warning("Unable to get water fish for %", event.getPlayer().getName()); logger.warning("Unable to get water fish for %", event.getPlayer().getName());
return Optional.empty(); return Optional.empty();
} }
Fish fish = optionalFish.get(); Fish fish = optionalFish.get();
float length = fish.generateLength(); float length = fish.generateLength(luckLevel);
int pointsValue = Math.min(fish.getRarity().maxPointLimit(), pointsManagement.calculatePoints(fish.getRarity(), length)); int pointsValue = Math.min(fish.getRarity().maxPointLimit(), pointsManagement.calculatePoints(fish.getRarity(), length));
Optional<ItemStack> fishItem = fish.createItem(player, length, pointsValue); Optional<ItemStack> fishItem = fish.createItem(player, length, pointsValue);
if (fishItem.isEmpty()) { if (fishItem.isEmpty()) {