forked from Upstream/mmocore
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 RandomAmount experience, tugs;
|
||||||
private final DropItem dropItem;
|
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);
|
MMOLineConfig config = new MMOLineConfig(value);
|
||||||
|
|
||||||
config.validate("tugs", "experience");
|
config.validate("tugs", "experience");
|
||||||
@ -24,22 +24,13 @@ public class FishingDropItem {
|
|||||||
tugs = new RandomAmount(config.getString("tugs"));
|
tugs = new RandomAmount(config.getString("tugs"));
|
||||||
experience = new RandomAmount(config.getString("experience"));
|
experience = new RandomAmount(config.getString("experience"));
|
||||||
|
|
||||||
this.minCoef = minCoef;
|
weight = config.getInt("weight", 1);
|
||||||
maxCoef = minCoef + (config.contains("coef") ? Math.min(1, config.getInt("coef")) : 1);
|
|
||||||
|
|
||||||
dropItem = MMOCore.plugin.loadManager.loadDropItem(config);
|
dropItem = MMOCore.plugin.loadManager.loadDropItem(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinCoefficient() {
|
public int getWeight() {
|
||||||
return minCoef;
|
return weight;
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxCoefficient() {
|
|
||||||
return maxCoef;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matchesCoefficient(int n) {
|
|
||||||
return n >= minCoef && n < maxCoef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DropItem getItem() {
|
public DropItem getItem() {
|
||||||
|
@ -46,11 +46,11 @@ public class FishingManager extends MMOManager {
|
|||||||
|
|
||||||
public class FishingDropTable {
|
public class FishingDropTable {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final int maxCoef;
|
|
||||||
|
|
||||||
private final Set<Condition> conditions = new HashSet<>();
|
private final Set<Condition> conditions = new HashSet<>();
|
||||||
private final List<FishingDropItem> items = new ArrayList<>();
|
private final List<FishingDropItem> items = new ArrayList<>();
|
||||||
|
private int maxWeight = 0;
|
||||||
|
|
||||||
public FishingDropTable(ConfigurationSection section) {
|
public FishingDropTable(ConfigurationSection section) {
|
||||||
Validate.notNull(section, "Could not load config");
|
Validate.notNull(section, "Could not load config");
|
||||||
this.id = section.getName();
|
this.id = section.getName();
|
||||||
@ -70,18 +70,16 @@ public class FishingManager extends MMOManager {
|
|||||||
List<String> list = section.getStringList("items");
|
List<String> list = section.getStringList("items");
|
||||||
Validate.notNull(list, "Could not load item list");
|
Validate.notNull(list, "Could not load item list");
|
||||||
|
|
||||||
int coef = 0;
|
|
||||||
for (String str : list)
|
for (String str : list)
|
||||||
try {
|
try {
|
||||||
FishingDropItem dropItem = new FishingDropItem(coef, str);
|
FishingDropItem dropItem = new FishingDropItem(str);
|
||||||
coef = dropItem.getMaxCoefficient();
|
maxWeight += dropItem.getWeight();
|
||||||
items.add(dropItem);
|
items.add(dropItem);
|
||||||
} catch (MMOLoadException exception) {
|
} catch (MMOLoadException exception) {
|
||||||
exception.printConsole("FishDropTables:" + id, "drop item");
|
exception.printConsole("FishDropTables:" + id, "drop item");
|
||||||
} catch (IllegalArgumentException | IndexOutOfBoundsException exception) {
|
} catch (IllegalArgumentException | IndexOutOfBoundsException exception) {
|
||||||
MMOCore.log(Level.WARNING, "[FishDropTables:" + id + "] Could not load item '" + str + "': " + exception.getMessage());
|
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.");
|
Validate.notEmpty(list, "The item list must not be empty.");
|
||||||
}
|
}
|
||||||
@ -98,11 +96,13 @@ public class FishingManager extends MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FishingDropItem getRandomItem() {
|
public FishingDropItem getRandomItem() {
|
||||||
int c = random.nextInt(maxCoef);
|
int weight = random.nextInt(maxWeight);
|
||||||
|
|
||||||
for (FishingDropItem item : items)
|
for (FishingDropItem item : items) {
|
||||||
if (item.matchesCoefficient(c))
|
weight -= item.getWeight();
|
||||||
return item;
|
|
||||||
|
if(weight <= 0) return item;
|
||||||
|
}
|
||||||
|
|
||||||
throw new NullPointerException("Could not find item in drop table");
|
throw new NullPointerException("Could not find item in drop table");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user