Made luck level improve fish length too
This commit is contained in:
parent
1b160b5ca7
commit
8d5c369877
|
|
@ -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
|
||||
* @return a random length for this fish
|
||||
*/
|
||||
public float generateLength() {
|
||||
return new Random().nextFloat(minLength, maxLength);
|
||||
public float generateLength(int luckLevel) {
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@ import com.alttd.fishingevent.config.Fishes;
|
|||
import com.alttd.fishingevent.fish.Fish;
|
||||
import com.alttd.fishingevent.objects.*;
|
||||
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.Optional;
|
||||
|
|
@ -22,10 +19,7 @@ public class FishGenerator {
|
|||
this.logger = logger;
|
||||
}
|
||||
|
||||
public Optional<Fish> getFish(ItemStack fishingRod, FishType fishType) {
|
||||
if (!fishingRod.getType().equals(Material.FISHING_ROD))
|
||||
return Optional.empty();
|
||||
int luckLevel = fishingRod.getEnchantmentLevel(Enchantment.LUCK);
|
||||
public Optional<Fish> getFish(int luckLevel, FishType fishType) {
|
||||
int maxChanceRange = rarityManager.getMaxChanceRange(fishType);
|
||||
int rarityValue = CustomRandom.generateNumber(0, maxChanceRange, luckLevel + 1);
|
||||
Optional<Rarity> optionalRarity = rarityManager.getRarityFromNumber(fishType, rarityValue);
|
||||
|
|
|
|||
|
|
@ -200,14 +200,19 @@ public class CatchFish implements Listener {
|
|||
ItemStack activeItem = player.getInventory().getItemInMainHand();
|
||||
if (!activeItem.getType().equals(Material.FISHING_ROD))
|
||||
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()) {
|
||||
logger.warning("Unable to get water fish for %", event.getPlayer().getName());
|
||||
return Optional.empty();
|
||||
}
|
||||
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));
|
||||
Optional<ItemStack> fishItem = fish.createItem(player, length, pointsValue);
|
||||
if (fishItem.isEmpty()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user