Fix various mutations

This commit is contained in:
BuildTools 2017-06-05 00:11:04 -07:00
parent eeef5c6051
commit be0853fea8
3 changed files with 49 additions and 40 deletions

View File

@ -50,11 +50,10 @@ public class EnchantmentMutation extends KitMutation {
.build();
final static ImmutableMap<Enchantment, Integer> TOOLS_MAP = new ImmutableMap.Builder<Enchantment, Integer>()
.put(Enchantment.DIG_SPEED, 10)
.put(Enchantment.SILK_TOUCH, 5)
.put(Enchantment.LOOT_BONUS_BLOCKS, 5)
.put(Enchantment.LOOT_BONUS_MOBS, 5)
.put(Enchantment.LUCK, 1)
.put(Enchantment.DIG_SPEED, 15)
.put(Enchantment.DURABILITY, 10)
.put(Enchantment.SILK_TOUCH, 1)
.put(Enchantment.LOOT_BONUS_BLOCKS, 1)
.build();
final static ImmutableMap<Enchantment, Integer> BOWS_MAP = new ImmutableMap.Builder<Enchantment, Integer>()
@ -66,6 +65,7 @@ public class EnchantmentMutation extends KitMutation {
final static Map<Enchantment, Integer> FISHING_MAP = new ImmutableMap.Builder<Enchantment, Integer>()
.put(Enchantment.KNOCKBACK, 3)
.put(Enchantment.LURE, 1)
.put(Enchantment.LUCK, 1)
.build();
final static WeightedRandomChooser<Integer, Integer> LEVELS = new ImmutableWeightedRandomChooser<>(LEVELS_MAP);
@ -88,16 +88,21 @@ public class EnchantmentMutation extends KitMutation {
WeightedRandomChooser<Enchantment, Integer> chooser;
if(item == null || ItemUtils.isNothing(item)) {
return;
} else if(ItemUtils.isTool(item)) {
chooser = TOOLS;
} else if(ItemUtils.isWeapon(item)) {
chooser = WEAPONS;
} else if(ItemUtils.isArmor(item)) {
if(equipment.getBoots().equals(item)) {
chooser = BOOTS;
ItemStack armor = equipment.getBoots();
if (armor != null) {
if (armor.equals(item)) {
chooser = BOOTS;
} else {
chooser = ARMOR;
}
} else {
chooser = ARMOR;
}
} else if(ItemUtils.isTool(item)) {
chooser = TOOLS;
} else if(Material.FISHING_ROD.equals(item.getType())) {
chooser = FISHING;
} else if(Material.BOW.equals(item.getType())) {
@ -152,4 +157,4 @@ public class EnchantmentMutation extends KitMutation {
savedEnchantments.clear();
}
}
}

View File

@ -3,9 +3,7 @@ package tc.oc.pgm.mutation.types.kit;
import com.google.common.collect.ImmutableMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -22,13 +20,12 @@ import tc.oc.pgm.match.Match;
import tc.oc.pgm.match.MatchPlayer;
import tc.oc.pgm.mutation.types.EntityMutation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static tc.oc.commons.core.util.Optionals.cast;
public class EquestrianMutation extends EntityMutation<AbstractHorse> {
public class EquestrianMutation extends EntityMutation<LivingEntity> {
final static ImmutableMap<EntityType, Integer> TYPE_MAP = new ImmutableMap.Builder<EntityType, Integer>()
.put(EntityType.HORSE, 100)
@ -79,31 +76,35 @@ public class EquestrianMutation extends EntityMutation<AbstractHorse> {
super.apply(player);
Location location = player.getLocation();
if(spawnable(location)) {
spawn(location, (Class<AbstractHorse>) TYPES.choose(entropy()).getEntityClass(), player);
register(world().spawn(location, (Class<LivingEntity>) TYPES.choose(entropy()).getEntityClass()), player);
}
}
@Override
public AbstractHorse register(AbstractHorse horse, @Nullable MatchPlayer owner) {
super.register(horse, owner);
if(owner != null) {
horse.setAdult();
horse.setJumpStrength(2 * entropy().randomDouble());
horse.setDomestication(1);
horse.setMaxDomestication(1);
horse.setTamed(true);
horse.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0));
horse.setOwner(owner.getBukkit());
horse.setPassenger(owner.getBukkit());
cast(horse, Horse.class).ifPresent(horsey -> {
horsey.setStyle(entropy().randomElement(Horse.Style.values()));
horsey.setColor(entropy().randomElement(Horse.Color.values()));
HorseInventory inventory = horsey.getInventory();
inventory.setSaddle(item(Material.SADDLE));
inventory.setArmor(item(ARMOR.choose(entropy())));
});
public LivingEntity register(LivingEntity entity, @Nullable MatchPlayer owner) {
super.register(entity, owner);
if (entity instanceof AbstractHorse) {
AbstractHorse horse = (AbstractHorse)entity;
if(owner != null) {
horse.setAdult();
horse.setJumpStrength(2 * entropy().randomDouble());
horse.setDomestication(1);
horse.setMaxDomestication(1);
horse.setTamed(true);
horse.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0));
horse.setOwner(owner.getBukkit());
horse.setPassenger(owner.getBukkit());
cast(horse, Horse.class).ifPresent(horsey -> {
horsey.setStyle(entropy().randomElement(Horse.Style.values()));
horsey.setColor(entropy().randomElement(Horse.Color.values()));
HorseInventory inventory = horsey.getInventory();
inventory.setSaddle(item(Material.SADDLE));
inventory.setArmor(item(ARMOR.choose(entropy())));
});
}
return horse;
}
return horse;
return entity;
}
public boolean spawnable(Location location) {

View File

@ -2,6 +2,7 @@ package tc.oc.pgm.mutation.types.targetable;
import com.google.common.collect.Range;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.util.Vector;
import tc.oc.pgm.match.Match;
@ -13,7 +14,7 @@ import java.time.Duration;
import java.time.Instant;
import java.util.List;
public class BomberMutation extends EntityMutation<TNTPrimed> implements TargetMutation {
public class BomberMutation extends EntityMutation<Entity> implements TargetMutation {
final static Duration FREQUENCY = Duration.ofSeconds(30);
final static Range<Integer> TARGETS = Range.closed(2, 5);
@ -33,7 +34,7 @@ public class BomberMutation extends EntityMutation<TNTPrimed> implements TargetM
int height = entropy().randomInt(HEIGHT);
Location location = player.getLocation().clone().add(0, height, 0);
for(int i = 0; i < bombs; i++) {
TNTPrimed tnt = spawn(location, TNTPrimed.class);
TNTPrimed tnt = (TNTPrimed) register(world().spawn(location, TNTPrimed.class),null);
tnt.setGlowing(true);
tnt.setIsIncendiary(false);
tnt.setFuseTicks(200);
@ -69,8 +70,10 @@ public class BomberMutation extends EntityMutation<TNTPrimed> implements TargetM
}
@Override
public void remove(TNTPrimed entity) {
entity.setFuseTicks(entropy().randomInt(TICKS));
public void remove(Entity entity) {
if (entity instanceof TNTPrimed) {
((TNTPrimed)entity).setFuseTicks(entropy().randomInt(TICKS));
}
}
@Override
@ -82,7 +85,7 @@ public class BomberMutation extends EntityMutation<TNTPrimed> implements TargetM
@Override
public void tick() {
TargetMutation.super.tick();
entities().filter(TNTPrimed::isOnGround).forEach(this::despawn);
entities().filter(Entity::isOnGround).forEach(this::despawn);
}
}