Allow potion effects on all wave types.

Boss waves already support potion effects, but with this commit, the potions node moves up as a common node, so all waves that spawn monsters (all but upgrade waves) can now spawn those monsters with a list of potion effects applied to them. It's not possible to give certain potion effects to specific monster types. All monsters get all the effects listed in the node.

Because we aren't actually giving potions but potion effects, the node is renamed from "potions" to "effects". However, to preserve backwards compatibility, both names are supported in this commit.

Closes #453
This commit is contained in:
Andreas Troelsen 2018-06-11 23:26:37 +02:00
parent 84249640d1
commit 9594bd6126
10 changed files with 72 additions and 20 deletions

View File

@ -166,6 +166,9 @@ public class MASpawnThread implements Runnable
// Spawn the monster
LivingEntity e = entry.getKey().spawn(arena, world, spawnpoint);
// Add potion effects
e.addPotionEffects(w.getEffects());
// Add it to the arena.
monsterManager.addMonster(e);
@ -196,7 +199,6 @@ public class MASpawnThread implements Runnable
boss.setDrops(bw.getDrops());
bw.addMABoss(boss);
bw.activateAbilities(arena);
e.addPotionEffects(bw.getPotions());
if (bw.getBossName() != null) {
e.setCustomName(bw.getBossName());
e.setCustomNameVisible(true);

View File

@ -4,7 +4,9 @@ import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.enums.WaveBranch;
import com.garbagemule.MobArena.waves.enums.WaveType;
import org.bukkit.Location;
import org.bukkit.potion.PotionEffect;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -20,7 +22,12 @@ public abstract class AbstractWave implements Wave
private int firstWave, frequency, priority;
private List<Location> spawnpoints;
private List<PotionEffect> effects;
public AbstractWave() {
this.effects = new ArrayList<>();
}
@Override
public abstract Map<MACreature, Integer> getMonstersToSpawn(int wave, int playerCount, Arena arena);
@ -38,6 +45,16 @@ public abstract class AbstractWave implements Wave
this.spawnpoints = spawnpoints;
}
@Override
public List<PotionEffect> getEffects() {
return effects;
}
@Override
public void setEffects(List<PotionEffect> effects) {
this.effects = effects;
}
@Override
public void announce(Arena arena, int wave) {
type.announce(arena, wave);

View File

@ -4,6 +4,7 @@ import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.waves.enums.WaveBranch;
import com.garbagemule.MobArena.waves.enums.WaveType;
import org.bukkit.Location;
import org.bukkit.potion.PotionEffect;
import java.util.List;
import java.util.Map;
@ -40,6 +41,22 @@ public interface Wave
*/
void setSpawnpoints(List<Location> spawnpoints);
/**
* Get a list of potion effects that the monsters of this wave
* will be given when they spawn.
*
* @return a list of potion effects, may be empty
*/
List<PotionEffect> getEffects();
/**
* Set the list of potion effects that the monsters of this wave
* will be given when they spawn.
*
* @param effects a list of potion effects, must be non-null
*/
void setEffects(List<PotionEffect> effects);
/**
* Announce to all players that this wave is spawning.
* @param arena an arena

View File

@ -32,13 +32,16 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
public class WaveParser
{
@ -135,6 +138,9 @@ public class WaveParser
// Grab the specific spawnpoints if any
List<Location> spawnpoints = getSpawnpoints(arena, name, config);
// Potion effects
List<PotionEffect> effects = getPotionEffects(config);
// Recurrent must have priority + frequency, single must have firstWave
if (branch == WaveBranch.RECURRENT && (priority == -1 || frequency <= 0)) {
arena.getPlugin().getLogger().warning(WaveError.RECURRENT_NODES.format(name, arena.configName()));
@ -157,6 +163,9 @@ public class WaveParser
// Aaand the spawnpoints
result.setSpawnpoints(spawnpoints);
// Potions
result.setEffects(effects);
return result;
}
@ -324,13 +333,6 @@ public class WaveParser
List<ItemStack> drops = ItemParser.parseItems(drp);
result.setDrops(drops);
// Potions!
String pots = config.getString("potions");
if (pots != null) {
List<PotionEffect> potions = PotionEffectParser.parsePotionEffects(pots);
if (potions != null) result.setPotions(potions);
}
return result;
}
@ -412,6 +414,26 @@ public class WaveParser
return result;
}
private static List<PotionEffect> getPotionEffects(ConfigurationSection config) {
String value = config.getString("effects");
if (value == null) {
value = config.getString("potions");
}
if (value != null) {
List<PotionEffect> parsed = PotionEffectParser.parsePotionEffects(value);
return (parsed != null) ? parsed : Collections.emptyList();
}
List<String> list = config.getStringList("effects");
if (list.isEmpty()) {
list = config.getStringList("potions");
}
return list.stream()
.map(PotionEffectParser::parsePotionEffect)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
private static Map<String,List<Upgrade>> getUpgradeMap(ConfigurationSection config) {
ConfigurationSection section = config.getConfigurationSection("upgrades");

View File

@ -13,7 +13,6 @@ import com.garbagemule.MobArena.waves.ability.AbilityInfo;
import com.garbagemule.MobArena.waves.enums.BossHealth;
import com.garbagemule.MobArena.waves.enums.WaveType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.ArrayList;
import java.util.HashMap;
@ -40,13 +39,11 @@ public class BossWave extends AbstractWave
private Thing reward;
private List<ItemStack> drops;
private List<PotionEffect> potions;
public BossWave(MACreature monster) {
this.monster = monster;
this.bosses = new HashSet<>();
this.abilities = new ArrayList<>();
this.potions = new ArrayList<>();
this.activated = false;
this.abilityAnnounce = false;
this.setType(WaveType.BOSS);
@ -138,14 +135,6 @@ public class BossWave extends AbstractWave
this.drops = drops;
}
public List<PotionEffect> getPotions() {
return potions;
}
public void setPotions(List<PotionEffect> potions) {
this.potions = potions;
}
public void activateAbilities(Arena arena) {
if (activated) {
return;
@ -175,7 +164,6 @@ public class BossWave extends AbstractWave
result.flatHealth = this.flatHealth;
result.reward = this.reward;
result.drops = this.drops;
result.potions = this.potions;
result.bossName = this.bossName;
// From AbstractWave
@ -183,6 +171,7 @@ public class BossWave extends AbstractWave
result.setHealthMultiplier(getHealthMultiplier());
result.setName(getName());
result.setSpawnpoints(getSpawnpoints());
result.setEffects(getEffects());
return result;
}
}

View File

@ -100,6 +100,7 @@ public class DefaultWave extends AbstractWave
result.setHealthMultiplier(getHealthMultiplier());
result.setName(getName());
result.setSpawnpoints(getSpawnpoints());
result.setEffects(getEffects());
return result;
}
}

View File

@ -61,6 +61,7 @@ public class SpecialWave extends AbstractWave
result.setHealthMultiplier(getHealthMultiplier());
result.setName(getName());
result.setSpawnpoints(getSpawnpoints());
result.setEffects(getEffects());
return result;
}
}

View File

@ -73,6 +73,7 @@ public class SupplyWave extends AbstractWave
result.setHealthMultiplier(getHealthMultiplier());
result.setName(getName());
result.setSpawnpoints(getSpawnpoints());
result.setEffects(getEffects());
return result;
}
}

View File

@ -50,6 +50,7 @@ public class SwarmWave extends AbstractWave
result.setHealthMultiplier(getHealthMultiplier());
result.setName(getName());
result.setSpawnpoints(getSpawnpoints());
result.setEffects(getEffects());
return result;
}
}

View File

@ -61,6 +61,7 @@ public class UpgradeWave extends AbstractWave
result.setHealthMultiplier(getHealthMultiplier());
result.setName(getName());
result.setSpawnpoints(getSpawnpoints());
result.setEffects(getEffects());
return result;
}