9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 03:49:07 +00:00

improved default config

This commit is contained in:
XiaoMoMi
2023-09-09 22:52:38 +08:00
parent 7f9cc4f2c0
commit f3f89480ac
33 changed files with 1052 additions and 335 deletions

View File

@@ -18,8 +18,8 @@
package net.momirealms.customfishing.api.manager;
import net.momirealms.customfishing.api.common.Key;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier;
import net.momirealms.customfishing.api.mechanic.effect.FishingEffect;
import org.jetbrains.annotations.Nullable;
public interface EffectManager {
@@ -30,5 +30,5 @@ public interface EffectManager {
@Nullable EffectCarrier getEffect(String namespace, String id);
Effect getInitialEffect();
FishingEffect getInitialEffect();
}

View File

@@ -24,5 +24,6 @@ public enum ActionTrigger {
HOOK,
CONSUME,
CAST,
BITE, LAND
BITE,
LAND
}

View File

@@ -21,8 +21,9 @@ import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.mechanic.GlobalSettings;
import net.momirealms.customfishing.api.mechanic.action.Action;
import net.momirealms.customfishing.api.mechanic.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.effect.Effect;
import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier;
import net.momirealms.customfishing.api.mechanic.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.effect.FishingEffect;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@@ -42,7 +43,7 @@ public class FishingPreparation extends Condition {
private @Nullable ItemStack baitItemStack;
private final @NotNull ItemStack rodItemStack;
private final List<EffectCarrier> utilEffects;
private final Effect enchantEffect;
private final List<EffectCarrier> enchantEffects;
private boolean canFish = true;
public FishingPreparation(Player player, CustomFishingPlugin plugin) {
@@ -53,7 +54,7 @@ public class FishingPreparation extends Condition {
ItemStack offHandItem = playerInventory.getItemInOffHand();
this.utilEffects = new ArrayList<>();
this.enchantEffect = plugin.getEffectManager().getInitialEffect();
this.enchantEffects = new ArrayList<>();
boolean rodOnMainHand = mainHandItem.getType() == Material.FISHING_ROD;
this.rodItemStack = rodOnMainHand ? mainHandItem : offHandItem;
String rodItemID = plugin.getItemManager().getAnyItemID(this.rodItemStack);
@@ -85,7 +86,11 @@ public class FishingPreparation extends Condition {
}
}
EffectCarrier utilEffect = plugin.getEffectManager().getEffect("util", bagItemID);
if (utilEffect != null && !uniqueUtils.contains(bagItemID) && utilEffect.isConditionMet(this)) {
if (utilEffect != null && !uniqueUtils.contains(bagItemID)) {
if (!utilEffect.isConditionMet(this)) {
this.canFish = false;
return;
}
utilEffects.add(utilEffect);
uniqueUtils.add(bagItemID);
}
@@ -108,10 +113,16 @@ public class FishingPreparation extends Condition {
}
}
for (String enchant : plugin.getIntegrationManager().getEnchantments(rodItemStack)) {
System.out.println(enchant);
EffectCarrier enchantEffect = plugin.getEffectManager().getEffect("enchant", enchant);
if (enchantEffect != null && enchantEffect.isConditionMet(this)) {
this.enchantEffect.merge(enchantEffect.getEffect());
if (enchantEffect != null) {
if (!enchantEffect.isConditionMet(this)) {
this.canFish = false;
return;
}
this.enchantEffects.add(enchantEffect);
}
}
}
@@ -140,15 +151,26 @@ public class FishingPreparation extends Condition {
return this.canFish;
}
public void mergeEffect(Effect effect) {
if (this.rodEffect != null)
effect.merge(this.rodEffect.getEffect());
if (this.enchantEffect != null)
effect.merge(this.enchantEffect);
if (this.baitEffect != null)
effect.merge(this.baitEffect.getEffect());
public void mergeEffect(FishingEffect effect) {
if (this.rodEffect != null) {
for (EffectModifier modifier : rodEffect.getEffectModifiers()) {
modifier.modify(effect, this);
}
}
if (this.baitEffect != null) {
for (EffectModifier modifier : baitEffect.getEffectModifiers()) {
modifier.modify(effect, this);
}
}
for (EffectCarrier util : utilEffects) {
effect.merge(util.getEffect());
for (EffectModifier modifier : util.getEffectModifiers()) {
modifier.modify(effect, this);
}
}
for (EffectCarrier enchant : enchantEffects) {
for (EffectModifier modifier : enchant.getEffectModifiers()) {
modifier.modify(effect, this);
}
}
}

View File

@@ -1,89 +0,0 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.mechanic.effect;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.mechanic.loot.Modifier;
import java.util.ArrayList;
import java.util.List;
public class AbstractEffect implements Effect {
protected boolean lavaFishing = false;
protected double multipleLootChance = 0;
protected double sizeMultiplier = 1;
protected double scoreMultiplier = 1;
protected double timeModifier = 1;
protected double difficultyModifier = 0;
protected double gameTimeModifier = 0;
protected List<Pair<String, Modifier>> lootWeightModifier = new ArrayList<>();
@Override
public boolean canLavaFishing() {
return lavaFishing;
}
@Override
public double getMultipleLootChance() {
return multipleLootChance;
}
@Override
public double getSizeMultiplier() {
return sizeMultiplier;
}
@Override
public double getScoreMultiplier() {
return scoreMultiplier;
}
@Override
public double getTimeModifier() {
return timeModifier;
}
@Override
public double getGameTimeModifier() {
return gameTimeModifier;
}
@Override
public double getDifficultyModifier() {
return difficultyModifier;
}
@Override
public AbstractEffect merge(Effect another) {
if (another == null) return this;
if (another.canLavaFishing()) this.lavaFishing = true;
this.scoreMultiplier += (another.getScoreMultiplier() -1);
this.sizeMultiplier += (another.getSizeMultiplier() -1);
this.timeModifier += (another.getTimeModifier() -1);
this.multipleLootChance += another.getMultipleLootChance();
this.difficultyModifier += another.getDifficultyModifier();
this.gameTimeModifier += another.getGameTimeModifier();
return this;
}
@Override
public List<Pair<String, Modifier>> getLootWeightModifier() {
return lootWeightModifier;
}
}

View File

@@ -18,7 +18,7 @@
package net.momirealms.customfishing.api.mechanic.effect;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.mechanic.loot.Modifier;
import net.momirealms.customfishing.api.mechanic.loot.WeightModifier;
import java.util.List;
@@ -32,13 +32,15 @@ public interface Effect {
double getScoreMultiplier();
double getTimeModifier();
double getHookTimeModifier();
double getGameTimeModifier();
double getDifficultyModifier();
Effect merge(Effect another);
List<Pair<String, WeightModifier>> getWeightModifier();
List<Pair<String, Modifier>> getLootWeightModifier();
List<Pair<String, WeightModifier>> getWeightModifierIgnored();
void merge(Effect bonus);
}

View File

@@ -13,7 +13,7 @@ public class EffectCarrier {
private Key key;
private Requirement[] requirements;
private Effect effect;
private EffectModifier[] effect;
private Map<ActionTrigger, Action[]> actionMap;
private boolean persist;
@@ -40,7 +40,7 @@ public class EffectCarrier {
return this;
}
public Builder effect(Effect effect) {
public Builder effect(EffectModifier[] effect) {
item.effect = effect;
return this;
}
@@ -63,7 +63,7 @@ public class EffectCarrier {
return requirements;
}
public Effect getEffect() {
public EffectModifier[] getEffectModifiers() {
return effect;
}
@@ -80,6 +80,7 @@ public class EffectCarrier {
return persist;
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isConditionMet(Condition condition) {
if (requirements == null) return true;
for (Requirement requirement : requirements) {

View File

@@ -0,0 +1,8 @@
package net.momirealms.customfishing.api.mechanic.effect;
import net.momirealms.customfishing.api.mechanic.condition.Condition;
public interface EffectModifier {
void modify(FishingEffect effect, Condition condition);
}

View File

@@ -18,11 +18,126 @@
package net.momirealms.customfishing.api.mechanic.effect;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.mechanic.loot.Modifier;
import net.momirealms.customfishing.api.mechanic.loot.WeightModifier;
import java.util.ArrayList;
import java.util.List;
public class FishingEffect extends AbstractEffect {
public class FishingEffect implements Effect {
private boolean lavaFishing = false;
private double multipleLootChance = 0;
private double sizeMultiplier = 1;
private double scoreMultiplier = 1;
private double hookTimeModifier = 1;
private double difficultyModifier = 0;
private double gameTimeModifier = 0;
private final List<Pair<String, WeightModifier>> weightModifier = new ArrayList<>();
private final List<Pair<String, WeightModifier>> weightModifierIgnored = new ArrayList<>();
public FishingEffect setLavaFishing(boolean lavaFishing) {
this.lavaFishing = lavaFishing;
return this;
}
public FishingEffect setMultipleLootChance(double multipleLootChance) {
this.multipleLootChance = multipleLootChance;
return this;
}
public FishingEffect setSizeMultiplier(double sizeMultiplier) {
this.sizeMultiplier = sizeMultiplier;
return this;
}
public FishingEffect setScoreMultiplier(double scoreMultiplier) {
this.scoreMultiplier = scoreMultiplier;
return this;
}
public FishingEffect setHookTimeModifier(double timeModifier) {
this.hookTimeModifier = timeModifier;
return this;
}
public FishingEffect setDifficultyModifier(double difficultyModifier) {
this.difficultyModifier = difficultyModifier;
return this;
}
public FishingEffect setGameTimeModifier(double gameTimeModifier) {
this.gameTimeModifier = gameTimeModifier;
return this;
}
public FishingEffect addWeightModifier(List<Pair<String, WeightModifier>> weightModifier) {
this.weightModifier.addAll(weightModifier);
return this;
}
public FishingEffect addWeightModifierIgnored(List<Pair<String, WeightModifier>> weightModifierIgnored) {
this.weightModifierIgnored.addAll(weightModifierIgnored);
return this;
}
@Override
public boolean canLavaFishing() {
return lavaFishing;
}
@Override
public double getMultipleLootChance() {
return multipleLootChance;
}
@Override
public double getSizeMultiplier() {
return sizeMultiplier;
}
@Override
public double getScoreMultiplier() {
return scoreMultiplier;
}
@Override
public double getHookTimeModifier() {
return hookTimeModifier;
}
@Override
public double getGameTimeModifier() {
return gameTimeModifier;
}
@Override
public double getDifficultyModifier() {
return difficultyModifier;
}
@Override
public List<Pair<String, WeightModifier>> getWeightModifier() {
return weightModifier;
}
@Override
public List<Pair<String, WeightModifier>> getWeightModifierIgnored() {
return weightModifierIgnored;
}
@Override
public void merge(Effect another) {
if (another == null) return;
if (another.canLavaFishing()) this.lavaFishing = true;
this.scoreMultiplier += (another.getScoreMultiplier() -1);
this.sizeMultiplier += (another.getSizeMultiplier() -1);
this.hookTimeModifier += (another.getHookTimeModifier() -1);
this.multipleLootChance += another.getMultipleLootChance();
this.difficultyModifier += another.getDifficultyModifier();
this.gameTimeModifier += another.getGameTimeModifier();
this.weightModifierIgnored.addAll(another.getWeightModifierIgnored());
this.weightModifier.addAll(another.getWeightModifier());
}
public static class Builder {
@@ -32,8 +147,13 @@ public class FishingEffect extends AbstractEffect {
this.effect = new FishingEffect();
}
public Builder lootWeightModifier(List<Pair<String, Modifier>> modifier) {
effect.lootWeightModifier = modifier;
public Builder addWeightModifier(List<Pair<String, WeightModifier>> modifier) {
effect.weightModifier.addAll(modifier);
return this;
}
public Builder addWeightModifierIgnored(List<Pair<String, WeightModifier>> modifier) {
effect.weightModifierIgnored.addAll(modifier);
return this;
}
@@ -53,7 +173,7 @@ public class FishingEffect extends AbstractEffect {
}
public Builder timeModifier(double timeModifier) {
effect.timeModifier = timeModifier;
effect.hookTimeModifier = timeModifier;
return this;
}

View File

@@ -19,6 +19,7 @@ package net.momirealms.customfishing.api.mechanic.item;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.common.Tuple;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
@@ -50,6 +51,8 @@ public interface ItemBuilder extends BuildableItem {
ItemBuilder enchantment(List<Pair<String, Short>> enchantments, boolean store);
ItemBuilder randomEnchantments(List<Tuple<Double, String, Short>> enchantments, boolean store);
ItemBuilder maxDurability(int max);
ItemBuilder price(float base, float bonus);

View File

@@ -19,6 +19,6 @@ package net.momirealms.customfishing.api.mechanic.loot;
import org.bukkit.entity.Player;
public interface Modifier {
public interface WeightModifier {
double modify(Player player, double weight);
}