mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-29 03:49:07 +00:00
category & statistics
This commit is contained in:
@@ -20,6 +20,7 @@ package net.momirealms.customfishing.api.manager;
|
||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public interface LootManager {
|
||||
@@ -27,4 +28,8 @@ public interface LootManager {
|
||||
@Nullable List<String> getLootGroup(String key);
|
||||
|
||||
@Nullable Loot getLoot(String key);
|
||||
|
||||
Collection<String> getAllLootKeys();
|
||||
|
||||
Collection<Loot> getAllLoots();
|
||||
}
|
||||
|
||||
@@ -27,27 +27,30 @@ import java.util.Map;
|
||||
|
||||
public class Condition {
|
||||
|
||||
protected @NotNull Location location;
|
||||
protected final @NotNull Player player;
|
||||
protected Location location;
|
||||
protected final Player player;
|
||||
protected final @NotNull Map<String, String> args;
|
||||
|
||||
public Condition(Player player) {
|
||||
public Condition(@NotNull Player player) {
|
||||
this(player.getLocation(), player, new HashMap<>());
|
||||
}
|
||||
|
||||
public Condition(Player player, Map<String, String> args) {
|
||||
public Condition(@NotNull Player player, @NotNull Map<String, String> args) {
|
||||
this(player.getLocation(), player, args);
|
||||
}
|
||||
|
||||
public Condition(@NotNull Location location, @NotNull Player player, @NotNull Map<String, String> args) {
|
||||
public Condition(Location location, Player player, @NotNull Map<String, String> args) {
|
||||
this.location = location;
|
||||
this.player = player;
|
||||
this.args = args;
|
||||
this.args.put("{player}", player.getName());
|
||||
this.args.put("{x}", String.valueOf(location.getX()));
|
||||
this.args.put("{y}", String.valueOf(location.getY()));
|
||||
this.args.put("{z}", String.valueOf(location.getZ()));
|
||||
this.args.put("{world}", location.getWorld().getName());
|
||||
if (player != null)
|
||||
this.args.put("{player}", player.getName());
|
||||
if (location != null) {
|
||||
this.args.put("{x}", String.valueOf(location.getX()));
|
||||
this.args.put("{y}", String.valueOf(location.getY()));
|
||||
this.args.put("{z}", String.valueOf(location.getZ()));
|
||||
this.args.put("{world}", location.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void setLocation(@NotNull Location location) {
|
||||
@@ -58,12 +61,10 @@ public class Condition {
|
||||
this.args.put("{world}", location.getWorld().getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class GameGroup implements GameConfig {
|
||||
}
|
||||
GameSettings settings = new GameSettings(
|
||||
ThreadLocalRandom.current().nextInt(minTime, maxTime + 1),
|
||||
(int) (ThreadLocalRandom.current().nextInt(minDifficulty, maxDifficulty + 1) + effect.getDifficultyModifier())
|
||||
(int) Math.min(100, Math.max(1, ThreadLocalRandom.current().nextInt(minDifficulty, maxDifficulty + 1) + effect.getDifficultyModifier()))
|
||||
);
|
||||
return Pair.of(gameInstance, settings);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package net.momirealms.customfishing.api.mechanic.statistic;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import net.momirealms.customfishing.api.data.StatisticData;
|
||||
import net.momirealms.customfishing.api.mechanic.action.Action;
|
||||
import net.momirealms.customfishing.api.mechanic.condition.Condition;
|
||||
import net.momirealms.customfishing.api.mechanic.condition.FishingPreparation;
|
||||
import net.momirealms.customfishing.api.mechanic.loot.Loot;
|
||||
|
||||
@@ -38,9 +39,9 @@ public class Statistics {
|
||||
this.total = statisticMap.values().stream().mapToInt(Integer::intValue).sum();
|
||||
}
|
||||
|
||||
public synchronized void addLootAmount(Loot loot, FishingPreparation fishingPreparation, int amount) {
|
||||
public synchronized void addLootAmount(Loot loot, Condition condition, int amount) {
|
||||
if (amount == 1) {
|
||||
addSingleLootAmount(loot, fishingPreparation);
|
||||
addSingleLootAmount(loot, condition);
|
||||
return;
|
||||
}
|
||||
Integer previous = statisticMap.get(loot.getID());
|
||||
@@ -48,23 +49,23 @@ public class Statistics {
|
||||
int after = previous + amount;
|
||||
statisticMap.put(loot.getID(), after);
|
||||
total += amount;
|
||||
doSuccessTimesAction(previous, after, fishingPreparation, loot);
|
||||
doSuccessTimesAction(previous, after, condition, loot);
|
||||
}
|
||||
|
||||
private void doSuccessTimesAction(Integer previous, int after, FishingPreparation fishingPreparation, Loot loot) {
|
||||
private void doSuccessTimesAction(Integer previous, int after, Condition condition, Loot loot) {
|
||||
HashMap<Integer, Action[]> actionMap = loot.getSuccessTimesActionMap();
|
||||
if (actionMap != null) {
|
||||
for (Map.Entry<Integer, Action[]> entry : actionMap.entrySet()) {
|
||||
if (entry.getKey() > previous && entry.getKey() <= after) {
|
||||
for (Action action : entry.getValue()) {
|
||||
action.trigger(fishingPreparation);
|
||||
action.trigger(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addSingleLootAmount(Loot loot, FishingPreparation fishingPreparation) {
|
||||
private void addSingleLootAmount(Loot loot, Condition condition) {
|
||||
Integer previous = statisticMap.get(loot.getID());
|
||||
if (previous == null) previous = 0;
|
||||
int after = previous + 1;
|
||||
@@ -73,7 +74,7 @@ public class Statistics {
|
||||
Action[] actions = loot.getSuccessTimesActionMap().get(after);
|
||||
if (actions != null)
|
||||
for (Action action : actions) {
|
||||
action.trigger(fishingPreparation);
|
||||
action.trigger(condition);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,12 +83,9 @@ public class Statistics {
|
||||
return amount == null ? 0 : amount;
|
||||
}
|
||||
|
||||
public boolean hasFished(String key) {
|
||||
return statisticMap.containsKey(key);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
statisticMap.clear();
|
||||
total = 0;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getStatisticMap() {
|
||||
@@ -95,6 +93,10 @@ public class Statistics {
|
||||
}
|
||||
|
||||
public void setData(String key, int value) {
|
||||
if (value <= 0) {
|
||||
statisticMap.remove(key);
|
||||
return;
|
||||
}
|
||||
statisticMap.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user