Added Mob Bomb Gadget

This commit is contained in:
Sam 2017-12-20 21:17:33 +00:00 committed by Alexander Meech
parent 8f5a8e882e
commit 93d7257ce9
5 changed files with 264 additions and 3 deletions

View File

@ -396,8 +396,6 @@ public class UtilEnt
creatureMap.put("Zombie", EntityType.ZOMBIE);
creatureMap.put("Guardian", EntityType.GUARDIAN);
creatureMap.put("Rabbit", EntityType.RABBIT);
creatureMap.put("Item", EntityType.DROPPED_ITEM);
}
}
@ -453,6 +451,8 @@ public class UtilEnt
public static String getName(EntityType type)
{
populate();
for (String cur : creatureMap.keySet())
if (creatureMap.get(cur) == type)
return cur;

View File

@ -128,6 +128,7 @@ import mineplex.core.gadget.gadgets.item.ItemFlowerGift;
import mineplex.core.gadget.gadgets.item.ItemFreezeCannon;
import mineplex.core.gadget.gadgets.item.ItemLovePotion;
import mineplex.core.gadget.gadgets.item.ItemMelonLauncher;
import mineplex.core.gadget.gadgets.item.ItemMobBomb;
import mineplex.core.gadget.gadgets.item.ItemOAndX;
import mineplex.core.gadget.gadgets.item.ItemPaintballGun;
import mineplex.core.gadget.gadgets.item.ItemPaintbrush;
@ -512,6 +513,7 @@ public class GadgetManager extends MiniPlugin
addGadget(new ItemFlowerGift(this));
addGadget(new ItemCandy(this));
addGadget(new ItemOAndX(this));
addGadget(new ItemMobBomb(this));
// Costume
addGadget(new OutfitRaveSuitHelmet(this));

View File

@ -0,0 +1,258 @@
package mineplex.core.gadget.gadgets.item;
import java.text.DecimalFormat;
import java.time.Month;
import java.time.YearMonth;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.ItemGadget;
import mineplex.core.gadget.util.CostConstants;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
public class ItemMobBomb extends ItemGadget
{
private static final PotionEffect SLOWNESS = new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 5, false, false);
private static final int TIME_TIL_EXPLODE = 4;
private static final ItemStack[] GORE = new ItemStack[]
{
new ItemStack(Material.BONE),
new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 1)
};
private static final DecimalFormat FORMAT = new DecimalFormat("0.0");
private static final String[] ONE_LINERS =
{
"Guess he... burned the bacon...",
"Guess he couldn't... bear it...",
"What do you call a cow with no legs? Ground beef.",
"What do you call a cow during an earthquake? A milkshake.",
"Letting the cat out of the bag is a whole lot easier than putting it back in.",
"My email password has been hacked. That's the third time I've had to rename the cat."
};
private final Map<Player, MobType> _typeMap;
public ItemMobBomb(GadgetManager manager)
{
super(manager, "Mob Bomb", new String[]
{
C.cGray + "Tick.. tick.. tick..",
"",
C.cWhite + "Left click to cycle through",
C.cWhite + "different mobs.",
C.cWhite + "Right click to launch the",
C.cWhite + "Mob bomb!"
}, CostConstants.POWERPLAY_BONUS, Material.DIAMOND_BARDING, (byte) 0, TimeUnit.SECONDS.toMillis(8), null);
Free = false;
setPPCYearMonth(YearMonth.of(2018, Month.JANUARY));
_typeMap = new HashMap<>();
}
@Override
public void enableCustom(Player player, boolean message)
{
_typeMap.put(player, MobType.PIG);
super.enableCustom(player, message);
}
@Override
public void disableCustom(Player player, boolean message)
{
super.disableCustom(player, message);
_typeMap.remove(player);
}
@Override
protected void giveItem(Player player)
{
player.getInventory().setItem(Manager.getActiveItemSlot(), new ItemBuilder(getDisplayMaterial(), getDisplayData())
.setTitle(F.item(getName()) + " - " + F.skill(_typeMap.get(player).Name) + " - " + F.name(" Left") + " - " + F.name("Cycle") + "/" + F.name("Right") + " - " + F.name("Fire"))
.build());
}
@Override
public void ActivateCustom(Player player)
{
}
@Override
@EventHandler
public void Activate(PlayerInteractEvent event)
{
Player player = event.getPlayer();
if (!isActive(player) || !IsItem(player))
{
return;
}
if (UtilEvent.isAction(event, ActionType.L) && Recharge.Instance.use(player, getName() + " Switch", 250, false, false))
{
_typeMap.put(player, _typeMap.get(player).next());
giveItem(player);
}
else if (UtilEvent.isAction(event, ActionType.R) && Recharge.Instance.use(player, getName(), _recharge, true, true))
{
launchBomb(player, _typeMap.get(player));
}
}
private void launchBomb(Player player, MobType type)
{
Location location = player.getEyeLocation();
LivingEntity entity = (LivingEntity) location.getWorld().spawnEntity(location, type.Type);
UtilEnt.ghost(entity, true, false);
entity.addPotionEffect(SLOWNESS);
entity.setCustomNameVisible(true);
entity.setVelocity(location.getDirection());
Manager.runSyncTimer(new BukkitRunnable()
{
double timer = TIME_TIL_EXPLODE;
boolean tick = false;
@Override
public void run()
{
timer -= 0.1;
tick = !tick;
Location entityLocation = entity.getLocation().add(0, 0.8, 0);
if (timer < 0 && !entity.isValid())
{
applyVelocity(UtilItem.dropItem(type.ToDrop, entityLocation, false, false, 25 + UtilMath.r(10), false));
for (ItemStack itemStack : GORE)
{
applyVelocity(UtilItem.dropItem(itemStack, entityLocation, false, false, 25 + UtilMath.r(10), false));
}
if (timer < -1.5)
{
UtilParticle.PlayParticleToAll(ParticleType.CLOUD, entityLocation, 0.8F, 0.4F, 0.8F, 0, 30, ViewDist.NORMAL);
cancel();
}
}
else
{
if (tick && entity instanceof Sheep)
{
((Sheep) entity).setColor(timer < 1.5 ? DyeColor.RED : DyeColor.YELLOW);
}
entity.setCustomName((tick ? C.cRedB : C.cWhiteB) + FORMAT.format(timer));
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, entityLocation, 0.8F, 0.4F, 0.8F, 0, (int) (8 - (timer * 2)), ViewDist.NORMAL);
if (timer < 0)
{
entityLocation.getWorld().playSound(location, type.DeathSound, 1, 1);
entity.remove();
UtilFirework.playFirework(entityLocation, FireworkEffect.builder()
.with(Type.BURST)
.withColor(type.Colour)
.withFade(Color.WHITE)
.withFlicker()
.build());
player.sendMessage(F.main(Manager.getName(), UtilMath.randomElement(ONE_LINERS)));
for (Player nearby : UtilPlayer.getNearby(entityLocation, 4))
{
UtilAction.velocity(nearby, UtilAlg.getTrajectory2d(entity, player).setY(0.5 + (Math.random() / 3)));
}
}
}
}
}, 1, 2);
}
private void applyVelocity(Item item)
{
item.setVelocity(new Vector((Math.random() - 0.5) / 1.5, Math.random() / 2 + 0.3, (Math.random() - 0.5) / 1.5));
}
private enum MobType
{
PIG(EntityType.PIG, Sound.PIG_DEATH, Material.GRILLED_PORK, Color.FUCHSIA),
CHICKEN(EntityType.CHICKEN, Sound.CHICKEN_HURT, Material.COOKED_CHICKEN, Color.WHITE),
COW(EntityType.COW, Sound.COW_HURT, Material.COOKED_BEEF, Color.MAROON),
MOOSHROOM(EntityType.MUSHROOM_COW, Sound.COW_IDLE, Material.MUSHROOM_SOUP, Color.RED, Color.MAROON),
SHEEP(EntityType.SHEEP, Sound.SHEEP_IDLE, Material.COOKED_MUTTON, Color.RED, Color.YELLOW),
SQUID(EntityType.SQUID, Sound.SPLASH, Material.INK_SACK, Color.AQUA, Color.BLUE),
VILLAGER(EntityType.VILLAGER, Sound.VILLAGER_YES, Material.EMERALD, Color.GREEN, Color.LIME),
CAVE_SPIDER(EntityType.CAVE_SPIDER, Sound.SPIDER_DEATH, Material.FERMENTED_SPIDER_EYE, Color.RED, Color.BLUE),
CREEPER(EntityType.CREEPER, Sound.CREEPER_DEATH, Material.SULPHUR, Color.LIME, Color.BLACK),
SKELETON(EntityType.SKELETON, Sound.SKELETON_DEATH, Material.BOW, Color.GRAY, Color.BLACK),
SLIME(EntityType.SLIME, Sound.SLIME_WALK, Material.SLIME_BALL, Color.LIME),
ZOMBIE(EntityType.ZOMBIE, Sound.ZOMBIE_DEATH, Material.ROTTEN_FLESH, Color.GREEN),
OCELOT(EntityType.OCELOT, Sound.CAT_HISS, Material.RAW_FISH, Color.YELLOW),
WOLF(EntityType.WOLF, Sound.WOLF_DEATH, Material.BONE, Color.RED, Color.WHITE),
GOLEM(EntityType.IRON_GOLEM, Sound.IRONGOLEM_DEATH, Material.IRON_BLOCK, Color.GRAY);
EntityType Type;
String Name;
Sound DeathSound;
ItemStack ToDrop;
Color[] Colour;
MobType(EntityType type, Sound sound, Material toDrop, Color... colours)
{
Type = type;
Name = UtilEnt.getName(type);
DeathSound = sound;
ToDrop = new ItemStack(toDrop);
Colour = colours;
}
public MobType next()
{
return values()[(ordinal() + 1) % values().length];
}
}
}

View File

@ -101,7 +101,7 @@ public abstract class ItemGadget extends Gadget
}
}
private void giveItem(Player player)
protected void giveItem(Player player)
{
player.getInventory().setItem(Manager.getActiveItemSlot(), ItemStackFactory.Instance.CreateStack(getDisplayMaterial(), getDisplayData(), 1, F.item((isUsingAmmo() ? getAmmoCount(player) + " " : "") + getName())));
}

View File

@ -45,6 +45,7 @@ public class PowerPlayClubRewards
.put(YearMonth.of(2017, Month.OCTOBER), new UnknownSalesPackageItem("Ghast Morph"))
.put(YearMonth.of(2017, Month.NOVEMBER), new UnknownSalesPackageItem("Tic Tac Toe"))
.put(YearMonth.of(2017, Month.DECEMBER), new UnknownSalesPackageItem("Sledge Mount"))
.put(YearMonth.of(2018, Month.JANUARY), new UnknownSalesPackageItem("Mob Bomb"))
.build();
public interface PowerPlayClubItem