Add Polly The Sheep
This commit is contained in:
parent
4435ceac26
commit
d4ebed79cc
@ -310,6 +310,7 @@ public class Explosion extends MiniPlugin
|
||||
_regenerateGround = false;
|
||||
_regenerateTime = TimeUnit.SECONDS.toMillis(20);
|
||||
_tntSpread = true;
|
||||
_temporaryDebris = true;
|
||||
}
|
||||
|
||||
public HashSet<FallingBlock> GetExplosionBlocks()
|
||||
|
@ -13,10 +13,13 @@ import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeWars;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.items.CakeDeployPlatform;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.items.CakeSheep;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.items.CakeWall;
|
||||
import nautilus.game.arcade.game.games.cakewars.team.CakeTeam;
|
||||
|
||||
@ -37,14 +40,27 @@ public class CakeItemModule extends CakeModule
|
||||
{
|
||||
_items.add(new CakeDeployPlatform(_game));
|
||||
_items.add(new CakeWall(_game));
|
||||
_items.add(new CakeSheep(_game));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup()
|
||||
{
|
||||
_items.forEach(CakeSpecialItem::cleanup);
|
||||
_items.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void live(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() != GameState.Live)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_items.forEach(CakeSpecialItem::setup);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
@ -81,7 +97,7 @@ public class CakeItemModule extends CakeModule
|
||||
return;
|
||||
}
|
||||
|
||||
for (CakeSpecialItem item :_items)
|
||||
for (CakeSpecialItem item : _items)
|
||||
{
|
||||
if (item.getItemStack().getType() != itemStack.getType())
|
||||
{
|
||||
@ -91,7 +107,7 @@ public class CakeItemModule extends CakeModule
|
||||
event.setCancelled(true);
|
||||
boolean inform = item.getCooldown() >= 1000;
|
||||
|
||||
if (!Recharge.Instance.use(player, item.getClass().getSimpleName(), item.getCooldown(), inform, inform))
|
||||
if (!Recharge.Instance.usable(player, item.getName(), inform))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -99,6 +115,7 @@ public class CakeItemModule extends CakeModule
|
||||
if (item.onClick(event, cakeTeam))
|
||||
{
|
||||
player.setItemInHand(UtilInv.decrement(itemStack));
|
||||
Recharge.Instance.useForce(player, item.getName(), item.getCooldown(), inform);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -15,22 +15,32 @@ public abstract class CakeSpecialItem
|
||||
|
||||
protected final CakeWars _game;
|
||||
private final ItemStack _itemStack;
|
||||
private final String _name;
|
||||
private final long _cooldown;
|
||||
|
||||
public CakeSpecialItem(CakeWars game, ItemStack itemStack)
|
||||
{
|
||||
this(game, itemStack, 0);
|
||||
this(game, itemStack, "CakeSpecialItem", 0);
|
||||
}
|
||||
|
||||
public CakeSpecialItem(CakeWars game, ItemStack itemStack, long cooldown)
|
||||
public CakeSpecialItem(CakeWars game, ItemStack itemStack, String name, long cooldown)
|
||||
{
|
||||
_game = game;
|
||||
_itemStack = itemStack;
|
||||
_name = name;
|
||||
_cooldown = cooldown;
|
||||
}
|
||||
|
||||
protected abstract boolean onClick(PlayerInteractEvent event, CakeTeam cakeTeam);
|
||||
|
||||
protected void setup()
|
||||
{
|
||||
}
|
||||
|
||||
protected void cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
protected boolean isInvalidBlock(Block block)
|
||||
{
|
||||
Location location = block.getLocation();
|
||||
@ -42,6 +52,11 @@ public abstract class CakeSpecialItem
|
||||
return _itemStack;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public long getCooldown()
|
||||
{
|
||||
return _cooldown;
|
||||
|
@ -0,0 +1,215 @@
|
||||
package nautilus.game.arcade.game.games.cakewars.item.items;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
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.common.util.UtilServer;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeWars;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.CakeSpecialItem;
|
||||
import nautilus.game.arcade.game.games.cakewars.team.CakeTeam;
|
||||
|
||||
public class CakeSheep extends CakeSpecialItem implements Listener
|
||||
{
|
||||
|
||||
public static final ItemStack ITEM_STACK = new ItemBuilder(Material.MONSTER_EGG, UtilEnt.getEntityEggData(EntityType.SHEEP))
|
||||
.setTitle(C.cPurpleB + "Polly The Sheep")
|
||||
.addLore(
|
||||
"",
|
||||
"Spawns Polly The Sheep...",
|
||||
"After " + C.cRed + "5 seconds" + C.cGray + " she explodes destroying",
|
||||
"all player placed blocks around her.",
|
||||
"If she is killed she does not explode.",
|
||||
"Warning! Polly has a", C.cRed + "20 second" + C.cGray + " cooldown between uses.")
|
||||
.setUnbreakable(true)
|
||||
.build();
|
||||
private static final long EXPLOSION_TIME = TimeUnit.SECONDS.toMillis(5);
|
||||
private static final int EXPLOSION_RADIUS = 7;
|
||||
private static final int NO_PLACE_RADIUS_SQUARED = 225;
|
||||
|
||||
public CakeSheep(CakeWars cakeWars)
|
||||
{
|
||||
super(cakeWars, ITEM_STACK, "Polly The Sheep", TimeUnit.SECONDS.toMillis(20));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setup()
|
||||
{
|
||||
UtilServer.RegisterEvents(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup()
|
||||
{
|
||||
UtilServer.Unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onClick(PlayerInteractEvent event, CakeTeam cakeTeam)
|
||||
{
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getClickedBlock().getLocation().add(0.5, 1, 0.5);
|
||||
|
||||
if (UtilMath.offset2dSquared(location, cakeTeam.getCake()) < NO_PLACE_RADIUS_SQUARED)
|
||||
{
|
||||
player.sendMessage(F.main("Game", "You cannot place " + F.name(getName()) + " this close to your cake."));
|
||||
return false;
|
||||
}
|
||||
|
||||
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, player.getLocation())));
|
||||
|
||||
DecimalFormat format = new DecimalFormat("0.0");
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
_game.CreatureAllowOverride = true;
|
||||
|
||||
Sheep sheep = location.getWorld().spawn(location, Sheep.class);
|
||||
sheep.setColor(cakeTeam.getGameTeam().getDyeColor());
|
||||
sheep.setCustomNameVisible(true);
|
||||
location.getWorld().playSound(location, Sound.SHEEP_SHEAR, 2, 0.8F);
|
||||
UtilEnt.vegetate(sheep);
|
||||
|
||||
_game.getArcadeManager().runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
int tick;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!sheep.isValid())
|
||||
{
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
long left = start + EXPLOSION_TIME - System.currentTimeMillis();
|
||||
|
||||
if (left <= 0)
|
||||
{
|
||||
Map<Block, Double> blocks = UtilBlock.getInRadius(location, EXPLOSION_RADIUS);
|
||||
Collection<Block> placedBlocks = _game.getCakePlayerModule().getPlacedBlocks();
|
||||
|
||||
location.getWorld().playSound(location, Sound.EXPLODE, 2, 1);
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, location.add(0, 0.5, 0), null, 0, 1, ViewDist.LONG);
|
||||
blocks.entrySet().removeIf(entry ->
|
||||
{
|
||||
Block block = entry.getKey();
|
||||
double scale = entry.getValue();
|
||||
|
||||
if (placedBlocks.contains(block))
|
||||
{
|
||||
double chance;
|
||||
|
||||
// I originally was going to use the NMS way to get the "hardness" of a block
|
||||
// but I decided against it as the values were way too varied for this game.
|
||||
// The value for chance should be taken from if the blocks was within half of
|
||||
// the explosion radius, after that it decreases.
|
||||
switch (block.getType())
|
||||
{
|
||||
case WOOL:
|
||||
chance = 0.8;
|
||||
break;
|
||||
case STAINED_CLAY:
|
||||
chance = 0.7;
|
||||
break;
|
||||
case WOOD:
|
||||
chance = 0.7;
|
||||
break;
|
||||
case ENDER_STONE:
|
||||
chance = 0.4;
|
||||
break;
|
||||
case OBSIDIAN:
|
||||
chance = 0.05;
|
||||
break;
|
||||
default:
|
||||
chance = 0.5;
|
||||
break;
|
||||
}
|
||||
|
||||
player.sendMessage(block.getType() + " c=" + chance + " s=" + scale);
|
||||
|
||||
chance *= scale;
|
||||
|
||||
player.sendMessage("p=" + chance);
|
||||
|
||||
if (Math.random() < chance)
|
||||
{
|
||||
placedBlocks.remove(block);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
_game.getArcadeManager().GetExplosion().BlockExplosion(blocks.keySet(), location, false);
|
||||
UtilPlayer.getInRadius(location, EXPLOSION_RADIUS).forEach((nearby, scale) ->
|
||||
{
|
||||
_game.getArcadeManager().GetDamage().NewDamageEvent(nearby, player, null, DamageCause.CUSTOM, 30 * scale, true, true, false, player.getName(), getName());
|
||||
});
|
||||
|
||||
sheep.remove();
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
sheep.setCustomName((tick % 2 == 0 ? cakeTeam.getGameTeam().GetColor() + C.Bold : C.cWhiteB) + format.format(left / 1000D));
|
||||
|
||||
if (tick % 6 == 0)
|
||||
{
|
||||
location.getWorld().playSound(location, Sound.SHEEP_IDLE, 2, 0.8F);
|
||||
}
|
||||
|
||||
tick++;
|
||||
}
|
||||
}, 0, 2);
|
||||
|
||||
_game.CreatureAllowOverride = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityDeath(EntityDeathEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof Sheep)
|
||||
{
|
||||
event.getDrops().clear();
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ public class CakeWall extends CakeSpecialItem
|
||||
|
||||
public CakeWall(CakeWars cakeWars)
|
||||
{
|
||||
super(cakeWars, ITEM_STACK, 500);
|
||||
super(cakeWars, ITEM_STACK, "Wool Wall", 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,6 +48,7 @@ import nautilus.game.arcade.game.games.cakewars.CakeModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeWars;
|
||||
import nautilus.game.arcade.game.games.cakewars.general.CakePlayerModule;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.items.CakeDeployPlatform;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.items.CakeSheep;
|
||||
import nautilus.game.arcade.game.games.cakewars.item.items.CakeWall;
|
||||
import nautilus.game.arcade.game.games.cakewars.shop.trap.CakeBearTrap;
|
||||
import nautilus.game.arcade.game.games.cakewars.shop.trap.CakeTNTTrap;
|
||||
@ -165,6 +166,8 @@ public class CakeShopModule extends CakeModule
|
||||
// Insta-Wall
|
||||
new CakeShopItem(CakeShopItemType.OTHER, CakeWall.ITEM_STACK, 2),
|
||||
|
||||
new CakeShopItem(CakeShopItemType.OTHER, CakeSheep.ITEM_STACK, 8),
|
||||
|
||||
// Traps
|
||||
new CakeTNTTrap(8),
|
||||
new CakeBearTrap(8)
|
||||
|
Loading…
Reference in New Issue
Block a user