mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-22 10:36:00 +01:00
Convert rewards to the new ThingPicker framework.
This commit makes breaking changes to the Arena interface to switch to the new ThingPicker framework for rewards. It is unfortuante that the Arena interface has so many disparate responsibilities that changes like these are necessary on such a central component when the change itself is actually very isolated to just rewards handling. With this change, rewards are now wrapped in pickers, which should give way to some grouping and "well-defined entropy".
This commit is contained in:
parent
dd54f70682
commit
bff1ab5694
@ -24,6 +24,7 @@ import com.garbagemule.MobArena.repairable.RepairableComparator;
|
||||
import com.garbagemule.MobArena.repairable.RepairableContainer;
|
||||
import com.garbagemule.MobArena.things.InvalidThingInputString;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.things.ThingPicker;
|
||||
import com.garbagemule.MobArena.util.ClassChests;
|
||||
import com.garbagemule.MobArena.util.inventory.InventoryManager;
|
||||
import com.garbagemule.MobArena.util.timer.AutoStartTimer;
|
||||
@ -121,7 +122,7 @@ public class ArenaImpl implements Arena
|
||||
private WaveManager waveManager;
|
||||
private MASpawnThread spawnThread;
|
||||
private SheepBouncer sheepBouncer;
|
||||
private Map<Integer,List<Thing>> everyWaveMap, afterWaveMap;
|
||||
private Map<Integer, ThingPicker> everyWaveMap, afterWaveMap;
|
||||
|
||||
// Misc
|
||||
private ArenaListener eventListener;
|
||||
@ -337,12 +338,12 @@ public class ArenaImpl implements Arena
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Map.Entry<Integer,List<Thing>>> getEveryWaveEntrySet() {
|
||||
public Set<Map.Entry<Integer, ThingPicker>> getEveryWaveEntrySet() {
|
||||
return everyWaveMap.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Thing> getAfterWaveReward(int wave) {
|
||||
public ThingPicker getAfterWaveReward(int wave) {
|
||||
return afterWaveMap.get(wave);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.garbagemule.MobArena.healthbar.HealthBar;
|
||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.things.ExperienceThing;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.things.ThingPicker;
|
||||
import com.garbagemule.MobArena.waves.MABoss;
|
||||
import com.garbagemule.MobArena.waves.MACreature;
|
||||
import com.garbagemule.MobArena.waves.Wave;
|
||||
@ -353,13 +354,13 @@ public class MASpawnThread implements Runnable
|
||||
}
|
||||
|
||||
private void grantRewards(int wave) {
|
||||
for (Map.Entry<Integer, List<Thing>> entry : arena.getEveryWaveEntrySet()) {
|
||||
for (Map.Entry<Integer, ThingPicker> entry : arena.getEveryWaveEntrySet()) {
|
||||
if (wave > 0 && wave % entry.getKey() == 0) {
|
||||
addReward(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
List<Thing> after = arena.getAfterWaveReward(wave);
|
||||
ThingPicker after = arena.getAfterWaveReward(wave);
|
||||
if (after != null) {
|
||||
addReward(after);
|
||||
}
|
||||
@ -388,9 +389,9 @@ public class MASpawnThread implements Runnable
|
||||
/**
|
||||
* Rewards all players with an item from the input String.
|
||||
*/
|
||||
private void addReward(List<Thing> rewards) {
|
||||
private void addReward(ThingPicker picker) {
|
||||
for (Player p : arena.getPlayersInArena()) {
|
||||
Thing reward = rewards.get(MobArena.random.nextInt(rewards.size()));
|
||||
Thing reward = picker.pick();
|
||||
rewardManager.addReward(p, reward);
|
||||
|
||||
if (reward == null) {
|
||||
|
@ -4,7 +4,10 @@ import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.things.InvalidThingInputString;
|
||||
import com.garbagemule.MobArena.things.RandomThingPicker;
|
||||
import com.garbagemule.MobArena.things.SingleThingPicker;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.things.ThingPicker;
|
||||
import com.garbagemule.MobArena.util.TextUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -40,10 +43,10 @@ public class MAUtils
|
||||
* type of wave ("after" or "every") and the config-file. If
|
||||
* no keys exist in the config-file, an empty map is returned.
|
||||
*/
|
||||
public static Map<Integer,List<Thing>> getArenaRewardMap(MobArena plugin, ConfigurationSection config, String arena, String type)
|
||||
public static Map<Integer, ThingPicker> getArenaRewardMap(MobArena plugin, ConfigurationSection config, String arena, String type)
|
||||
{
|
||||
//String arenaPath = "arenas." + arena + ".rewards.waves.";
|
||||
Map<Integer,List<Thing>> result = new HashMap<>();
|
||||
Map<Integer, ThingPicker> result = new HashMap<>();
|
||||
|
||||
String typePath = "rewards.waves." + type;
|
||||
if (!config.contains(typePath)) return result;
|
||||
@ -61,16 +64,17 @@ public class MAUtils
|
||||
String path = typePath + "." + wave;
|
||||
String rewards = config.getString(path);
|
||||
|
||||
List<Thing> things = new ArrayList<>();
|
||||
List<ThingPicker> pickers = new ArrayList<>();
|
||||
for (String reward : rewards.split(",")) {
|
||||
try {
|
||||
Thing thing = plugin.getThingManager().parse(reward.trim());
|
||||
things.add(thing);
|
||||
ThingPicker picker = new SingleThingPicker(thing);
|
||||
pickers.add(picker);
|
||||
} catch (InvalidThingInputString e) {
|
||||
throw new ConfigError("Failed to parse reward for wave " + wave + " in the '" + type + "' branch of arena " + arena + ": " + e.getInput());
|
||||
}
|
||||
}
|
||||
result.put(wave, things);
|
||||
result.put(wave, new RandomThingPicker(pickers, MobArena.random));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import com.garbagemule.MobArena.leaderboards.Leaderboard;
|
||||
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||
import com.garbagemule.MobArena.repairable.Repairable;
|
||||
import com.garbagemule.MobArena.things.Thing;
|
||||
import com.garbagemule.MobArena.things.ThingPicker;
|
||||
import com.garbagemule.MobArena.util.inventory.InventoryManager;
|
||||
import com.garbagemule.MobArena.util.timer.AutoStartTimer;
|
||||
import com.garbagemule.MobArena.waves.WaveManager;
|
||||
@ -65,9 +66,9 @@ public interface Arena
|
||||
|
||||
List<Thing> getEntryFee();
|
||||
|
||||
Set<Map.Entry<Integer,List<Thing>>> getEveryWaveEntrySet();
|
||||
Set<Map.Entry<Integer, ThingPicker>> getEveryWaveEntrySet();
|
||||
|
||||
List<Thing> getAfterWaveReward(int wave);
|
||||
ThingPicker getAfterWaveReward(int wave);
|
||||
|
||||
Set<Player> getPlayersInArena();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user