mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-03-01 15:51:06 +01:00
Rewrote the fishing coef system into an optimized weight system
This commit is contained in:
parent
29d6557553
commit
652294ccc3
@ -14,9 +14,9 @@ public class FishingDropItem {
|
||||
private final RandomAmount experience, tugs;
|
||||
private final DropItem dropItem;
|
||||
|
||||
private final int minCoef, maxCoef;
|
||||
private final int weight;
|
||||
|
||||
public FishingDropItem(int minCoef, String value) {
|
||||
public FishingDropItem(String value) {
|
||||
MMOLineConfig config = new MMOLineConfig(value);
|
||||
|
||||
config.validate("tugs", "experience");
|
||||
@ -24,22 +24,13 @@ public class FishingDropItem {
|
||||
tugs = new RandomAmount(config.getString("tugs"));
|
||||
experience = new RandomAmount(config.getString("experience"));
|
||||
|
||||
this.minCoef = minCoef;
|
||||
maxCoef = minCoef + (config.contains("coef") ? Math.min(1, config.getInt("coef")) : 1);
|
||||
weight = config.getInt("weight", 1);
|
||||
|
||||
dropItem = MMOCore.plugin.loadManager.loadDropItem(config);
|
||||
}
|
||||
|
||||
public int getMinCoefficient() {
|
||||
return minCoef;
|
||||
}
|
||||
|
||||
public int getMaxCoefficient() {
|
||||
return maxCoef;
|
||||
}
|
||||
|
||||
public boolean matchesCoefficient(int n) {
|
||||
return n >= minCoef && n < maxCoef;
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public DropItem getItem() {
|
||||
|
@ -46,11 +46,11 @@ public class FishingManager extends MMOManager {
|
||||
|
||||
public class FishingDropTable {
|
||||
private final String id;
|
||||
private final int maxCoef;
|
||||
|
||||
private final Set<Condition> conditions = new HashSet<>();
|
||||
private final List<FishingDropItem> items = new ArrayList<>();
|
||||
|
||||
private int maxWeight = 0;
|
||||
|
||||
public FishingDropTable(ConfigurationSection section) {
|
||||
Validate.notNull(section, "Could not load config");
|
||||
this.id = section.getName();
|
||||
@ -70,18 +70,16 @@ public class FishingManager extends MMOManager {
|
||||
List<String> list = section.getStringList("items");
|
||||
Validate.notNull(list, "Could not load item list");
|
||||
|
||||
int coef = 0;
|
||||
for (String str : list)
|
||||
try {
|
||||
FishingDropItem dropItem = new FishingDropItem(coef, str);
|
||||
coef = dropItem.getMaxCoefficient();
|
||||
FishingDropItem dropItem = new FishingDropItem(str);
|
||||
maxWeight += dropItem.getWeight();
|
||||
items.add(dropItem);
|
||||
} catch (MMOLoadException exception) {
|
||||
exception.printConsole("FishDropTables:" + id, "drop item");
|
||||
} catch (IllegalArgumentException | IndexOutOfBoundsException exception) {
|
||||
MMOCore.log(Level.WARNING, "[FishDropTables:" + id + "] Could not load item '" + str + "': " + exception.getMessage());
|
||||
}
|
||||
maxCoef = coef;
|
||||
|
||||
Validate.notEmpty(list, "The item list must not be empty.");
|
||||
}
|
||||
@ -98,11 +96,13 @@ public class FishingManager extends MMOManager {
|
||||
}
|
||||
|
||||
public FishingDropItem getRandomItem() {
|
||||
int c = random.nextInt(maxCoef);
|
||||
int weight = random.nextInt(maxWeight);
|
||||
|
||||
for (FishingDropItem item : items)
|
||||
if (item.matchesCoefficient(c))
|
||||
return item;
|
||||
for (FishingDropItem item : items) {
|
||||
weight -= item.getWeight();
|
||||
|
||||
if(weight <= 0) return item;
|
||||
}
|
||||
|
||||
throw new NullPointerException("Could not find item in drop table");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user