ProjectAres/PGM/src/main/java/tc/oc/pgm/mutation/types/kit/MobsMutation.java

58 lines
2.1 KiB
Java
Raw Normal View History

2017-03-31 23:30:41 +02:00
package tc.oc.pgm.mutation.types.kit;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Range;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
2017-04-03 04:09:35 +02:00
import org.bukkit.entity.LivingEntity;
2017-03-31 23:30:41 +02:00
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SpawnEggMeta;
import tc.oc.commons.core.random.ImmutableWeightedRandomChooser;
import tc.oc.commons.core.random.WeightedRandomChooser;
import tc.oc.pgm.kits.FreeItemKit;
import tc.oc.pgm.kits.Kit;
import tc.oc.pgm.match.Match;
import tc.oc.pgm.match.MatchPlayer;
2017-04-03 04:09:35 +02:00
import tc.oc.pgm.mutation.types.EntityMutation;
2017-03-31 23:30:41 +02:00
import java.util.List;
2017-04-03 04:09:35 +02:00
public class MobsMutation extends EntityMutation<LivingEntity> {
2017-03-31 23:30:41 +02:00
final static ImmutableMap<EntityType, Integer> TYPE_MAP = new ImmutableMap.Builder<EntityType, Integer>()
.put(EntityType.ZOMBIE, 50)
.put(EntityType.SKELETON, 40)
.put(EntityType.SPIDER, 40)
.put(EntityType.CREEPER, 30)
.put(EntityType.BLAZE, 20)
.put(EntityType.GHAST, 20)
.put(EntityType.SHULKER, 20)
.put(EntityType.WITCH, 10)
.put(EntityType.ENDERMAN, 10)
.put(EntityType.PIG_ZOMBIE, 5)
.put(EntityType.WITHER_SKELETON, 1)
.build();
final static WeightedRandomChooser<EntityType, Integer> TYPES = new ImmutableWeightedRandomChooser<>(TYPE_MAP);
final static Range<Integer> AMOUNT = Range.closed(1, 3);
public MobsMutation(Match match) {
2017-04-03 04:09:35 +02:00
super(match, false);
2017-03-31 23:30:41 +02:00
}
@Override
public void kits(MatchPlayer player, List<Kit> kits) {
super.kits(player, kits);
2017-04-03 04:09:35 +02:00
int eggs = entropy().randomInt(AMOUNT);
2017-03-31 23:30:41 +02:00
for(int i = 0; i < eggs; i++) {
2017-04-03 04:09:35 +02:00
ItemStack item = item(Material.MONSTER_EGG, entropy().randomInt(AMOUNT));
2017-03-31 23:30:41 +02:00
SpawnEggMeta egg = (SpawnEggMeta) item.getItemMeta();
2017-04-03 04:09:35 +02:00
egg.setSpawnedType(TYPES.choose(entropy()));
2017-03-31 23:30:41 +02:00
item.setItemMeta(egg);
kits.add(new FreeItemKit(item));
}
}
}