Finished Undead Camp Event (Loot tables still need adjusting)

This commit is contained in:
Shaun Bennett 2015-06-30 15:28:50 -05:00
parent 0fdc4e0008
commit 0fce46f504
13 changed files with 246 additions and 37 deletions

View File

@ -50,7 +50,7 @@ public class BlockRestoreMap implements Runnable
block.setTypeIdAndData(material, data, false);
}
public void restoreTopDown(JavaPlugin plugin)
public void restoreTopDown(JavaPlugin plugin, final Runnable onComplete)
{
BlockDataRunnable run = new BlockDataRunnable(plugin, new RestoreIterator(this), new Runnable()
{
@ -58,6 +58,7 @@ public class BlockRestoreMap implements Runnable
public void run()
{
clear();
onComplete.run();
}
});

View File

@ -29,7 +29,7 @@ public class UtilMath
public static int rRange(int min, int max)
{
return min + r(max - min);
return min + r(1 + max - min);
}
public static double offset2d(Entity a, Entity b)

View File

@ -34,7 +34,7 @@ public class ItemLoot implements ILoot
@Override
public void dropLoot(Location location)
{
int count = _min + UtilMath.r(_max - _min);
int count = UtilMath.rRange(_min, _max);
ItemStack item = new ItemStack(_material, count, (short) 0, _data);
location.getWorld().dropItemNaturally(location, item);
}

View File

@ -42,11 +42,11 @@ public class LootManager
_commonSet.add(2, new ItemLoot(Material.IRON_BOOTS, 1, 1));
// Gear
_commonSet.add(2, new GearLoot(_gearManager));
_commonSet.add(1, new GearLoot(_gearManager));
// Gold
_commonSet.add(5, new GoldLoot(_goldManager, 100, 1000));
_commonSet.add(5, new GoldTokenLoot(100, 1000));
// _commonSet.add(5, new GoldLoot(_goldManager, 100, 1000));
_commonSet.add(1, new GoldTokenLoot(100, 1000));
}
private void populateRare()

View File

@ -83,12 +83,14 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
while (iterator.hasNext())
{
WorldEvent worldEvent = iterator.next();
if (worldEvent.getState() == EventState.COMPLETE)
if (worldEvent.getState() == EventState.COMPLETE || worldEvent.getState() == EventState.CANCELLED)
{
worldEvent.cleanup(false);
HandlerList.unregisterAll(worldEvent);
iterator.remove();
// If the event was cancelled, we don't need to run a cleanup
if (worldEvent.getState() == EventState.COMPLETE) worldEvent.cleanup(false);
removed = true;
_lastEventEnd = System.currentTimeMillis();
}

View File

@ -7,6 +7,9 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.world.ChunkUnloadEvent;
import mineplex.core.common.util.C;
@ -246,7 +249,34 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
updateEntityHealth();
applyDamage(event.GetDamage());
updateName();
_event.updateLastActive();
}
@EventHandler
public void damageType(CustomDamageEvent event)
{
if (_entity == null)
return;
if (!event.GetDamageeEntity().equals(_entity))
return;
DamageCause cause = event.GetCause();
if (cause == DamageCause.DROWNING || cause == DamageCause.FALL || cause == DamageCause.SUFFOCATION)
event.SetCancelled("Cancel");
}
@EventHandler
public void cancelCombust(EntityCombustEvent event)
{
if (_entity == null)
return;
if (!event.getEntity().equals(_entity))
return;
event.setCancelled(true);
}
}

View File

@ -5,5 +5,6 @@ public enum EventState
PREPARE,
LIVE,
UNLOADING,
COMPLETE
COMPLETE,
CANCELLED
}

View File

@ -16,10 +16,14 @@ import org.bukkit.event.block.BlockPhysicsEvent;
import mineplex.core.common.block.BlockRestoreMap;
import mineplex.core.common.block.schematic.SchematicRunnable;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.block.BlockData;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.EventMap;
@ -87,10 +91,15 @@ public abstract class WorldEvent implements Listener
public final void cancel()
{
cleanup(true);
setState(EventState.COMPLETE);
setState(EventState.CANCELLED);
customCancel();
}
protected final void triggerEnd()
{
setState(EventState.COMPLETE);
}
protected void customCancel()
{
@ -131,6 +140,11 @@ public abstract class WorldEvent implements Listener
return _name;
}
public void setName(String name)
{
_name = name;
}
protected Random getRandom()
{
return _random;
@ -160,7 +174,9 @@ public abstract class WorldEvent implements Listener
public void announceStart()
{
Bukkit.broadcastMessage(F.main("Event", F.elem(getName()) + " has started at coordinates " + F.elem(getCenterLocation().getX() + " " + getCenterLocation().getZ())));
UtilTextMiddle.display(C.cGreen + getName(), UtilWorld.locToStrClean(getCenterLocation()), 10, 40, 10);
Bukkit.broadcastMessage(F.main("Event", F.elem(getName()) + " has started at coordinates " + F.elem(UtilWorld.locToStrClean(getCenterLocation()))));
}
public void clearCreatures()
@ -182,7 +198,14 @@ public abstract class WorldEvent implements Listener
}
else
{
_blocks.restoreTopDown(_eventManager.getPlugin());
_blocks.restoreTopDown(_eventManager.getPlugin(), new Runnable()
{
@Override
public void run()
{
}
});
}
}
@ -268,10 +291,23 @@ public abstract class WorldEvent implements Listener
setState(EventState.COMPLETE);
}
@EventHandler
public void prepareTimeout(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (getState() != EventState.PREPARE)
return;
// Event was preparing for more than 5 minutes
if (getTicks() > 6000)
cancel();
}
@EventHandler
public void onPhysics(BlockPhysicsEvent event)
{
Bukkit.broadcastMessage(event.getBlock().getType() + "" );
if (_blocks.getChangedBlocks().contains(event.getBlock()))
event.setCancelled(true);
}

View File

@ -4,7 +4,7 @@ import mineplex.core.common.util.UtilMath;
public enum CampSize
{
SMALL("Small Camp", 10, 0, 1),
SMALL("Small Camp", 15, 0, 1),
MEDIUM("Medium Camp", 20, 10, 2),

View File

@ -5,18 +5,22 @@ import org.bukkit.material.MaterialData;
public enum CampType
{
OAK(new MaterialData(Material.LOG, (byte) 0), new MaterialData(Material.WOOD, (byte) 0)),
SPRUCE(new MaterialData(Material.LOG, (byte) 1), new MaterialData(Material.WOOD, (byte) 1)),
BIRCH(new MaterialData(Material.LOG, (byte) 2), new MaterialData(Material.WOOD, (byte) 2)),
JUNGLE(new MaterialData(Material.LOG, (byte) 3), new MaterialData(Material.WOOD, (byte) 3));
OAK(new MaterialData(Material.LOG, (byte) 0), new MaterialData(Material.WOOD, (byte) 0), Material.ENDER_CHEST, Material.BURNING_FURNACE),
SPRUCE(new MaterialData(Material.LOG, (byte) 1), new MaterialData(Material.WOOD, (byte) 1), Material.ENDER_CHEST, Material.BURNING_FURNACE),
BIRCH(new MaterialData(Material.LOG, (byte) 2), new MaterialData(Material.WOOD, (byte) 2), Material.ENDER_CHEST, Material.BURNING_FURNACE),
JUNGLE(new MaterialData(Material.LOG, (byte) 3), new MaterialData(Material.WOOD, (byte) 3), Material.ENDER_CHEST, Material.BURNING_FURNACE);
private MaterialData _log;
private MaterialData _wood;
private Material _chest;
private Material _furance;
CampType(MaterialData log, MaterialData wood)
CampType(MaterialData log, MaterialData wood, Material chest, Material furnace)
{
_log = log;
_wood = wood;
_chest = chest;
_furance = furnace;
}
public MaterialData getLog()
@ -28,4 +32,14 @@ public enum CampType
{
return _wood;
}
public Material getFurnace()
{
return _furance;
}
public Material getChest()
{
return _chest;
}
}

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.clans.worldevent.event.undead;
import java.util.HashSet;
import java.util.Iterator;
import org.bukkit.Effect;
import org.bukkit.Location;
@ -14,6 +15,7 @@ import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
@ -21,6 +23,10 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.event.EventState;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
@ -34,8 +40,8 @@ public class UndeadCamp extends WorldEvent
private int _towerLeft = 0;
private int _undeadCount = 0;
private CampType _campType;
private CampSize _campSize;
private final CampType _campType;
private final CampSize _campSize;
private HashSet<Block> _chests;
public UndeadCamp(WorldEventManager eventManager, Location centerLocation)
@ -43,7 +49,7 @@ public class UndeadCamp extends WorldEvent
super(eventManager, "Undead Camp", centerLocation);
_campSize = CampSize.getCampSize(UtilServer.getPlayers().length);
_campType = CampType.JUNGLE;
_campType = CampType.values()[getRandom().nextInt(CampType.values().length)];
_chests = new HashSet<Block>();
_hutLeft = _campSize.generateHutCount();
@ -72,6 +78,7 @@ public class UndeadCamp extends WorldEvent
else
{
System.out.println("Constructed " + getName() + " at " + UtilWorld.locToStrClean(getCenterLocation()) + ".");
announceStart();
setState(EventState.LIVE);
}
}
@ -209,8 +216,8 @@ public class UndeadCamp extends WorldEvent
private void addFurnace(Block chest)
{
setBlock(chest, 61, (byte) (UtilMath.r(4) + 2));
// _chests.add(chest);
setBlock(chest, Material.BURNING_FURNACE, (byte) (UtilMath.r(4) + 2));
_chests.add(chest);
}
private void createUndead()
@ -223,7 +230,7 @@ public class UndeadCamp extends WorldEvent
registerCreature(new UndeadWarrior(this, loc.add(0.5, 0.5, 0.5)));
_poleLeft--;
// _poleLeft--;
// ResetIdleTicks();
}
@ -345,7 +352,54 @@ public class UndeadCamp extends WorldEvent
// Loot
int count = 1 + UtilMath.r(3);
for (int i = 0; i < count; i++)
getEventManager().getLoot().dropCommon(block.getLocation());
getEventManager().getLoot().dropCommon(block.getLocation().add(0.5, 0.5, 0.5));
}
private void openFurnace(Block block)
{
_chests.remove(block);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.BURNING_FURNACE.getId());
setBlock(block, Material.AIR);
for (int i=0 ; i<UtilMath.r(25) ; i++)
block.getWorld().dropItemNaturally(block.getLocation().add(0.5, 0.5, 0.5),
ItemStackFactory.Instance.CreateStack(Material.IRON_INGOT));
for (int i=0 ; i<UtilMath.r(25) ; i++)
block.getWorld().dropItemNaturally(block.getLocation().add(0.5, 0.5, 0.5),
ItemStackFactory.Instance.CreateStack(Material.GOLD_INGOT));
for (int i=0 ; i<UtilMath.r(25) ; i++)
block.getWorld().dropItemNaturally(block.getLocation().add(0.5, 0.5, 0.5),
ItemStackFactory.Instance.CreateStack(Material.DIAMOND));
for (int i=0 ; i<UtilMath.r(25) ; i++)
block.getWorld().dropItemNaturally(block.getLocation().add(0.5, 0.5, 0.5),
ItemStackFactory.Instance.CreateStack(Material.LEATHER));
}
@EventHandler
public void checkEnd(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
// Remove any broken chests/furnaces
Iterator<Block> it = _chests.iterator();
while (it.hasNext())
{
Block block = it.next();
if (block.getType() != _campType.getChest() && block.getType() != _campType.getFurnace())
it.remove();
}
if (_chests.size() == 0)
{
triggerEnd();
}
}
@EventHandler
@ -354,8 +408,17 @@ public class UndeadCamp extends WorldEvent
Block block = event.getClickedBlock();
if (_chests.contains(block))
{
openChest(block);
event.setCancelled(true);
if (!Recharge.Instance.use(event.getPlayer(), "Loot Chest", 60000, true, false))
return;
if (block.getType() == Material.ENDER_CHEST) openChest(block);
else if (block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE) openFurnace(block);
updateLastActive();
UtilPlayer.message(event.getPlayer(), F.main(getName(), "You smash open an " + F.elem("Undead Chest") + "!"));
}
}
}

View File

@ -1,8 +1,13 @@
package mineplex.game.clans.clans.worldevent.event.undead.creature;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Zombie;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilMath;
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
@ -16,12 +21,36 @@ public class UndeadArcher extends EventCreature<Skeleton>
@Override
protected void spawnCustom()
{
Skeleton entity = getEntity();
EntityEquipment eq = entity.getEquipment();
eq.setItemInHand(new ItemStack(Material.BOW));
eq.setHelmet(new ItemStack(Material.CHAINMAIL_HELMET));
eq.setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
eq.setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));
eq.setBoots(new ItemStack(Material.CHAINMAIL_BOOTS));
}
@Override
public void dieCustom()
{
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_HELMET));
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_CHESTPLATE));
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_LEGGINGS));
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_BOOTS));
if (Math.random() > 0.90)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.BOW));
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.ARROW, UtilMath.r(12) + 1));
for (int i=0 ; i<UtilMath.r(5) + 1 ; i++)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.EMERALD));
}
}

View File

@ -2,11 +2,17 @@ package mineplex.game.clans.clans.worldevent.event.undead.creature;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
@ -32,23 +38,50 @@ public class UndeadWarrior extends EventCreature<Zombie>
public void dieCustom()
{
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_HELMET));
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.IRON_HELMET));
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_CHESTPLATE));
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.IRON_CHESTPLATE));
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_LEGGINGS));
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.IRON_LEGGINGS));
if (Math.random() > 0.97)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.CHAINMAIL_BOOTS));
if (Math.random() > 0.90)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.BOW));
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.ARROW, UtilMath.r(12) + 1));
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.IRON_BOOTS));
for (int i=0 ; i<UtilMath.r(5) + 1 ; i++)
getEntity().getWorld().dropItem(getEntity().getLocation(), new org.bukkit.inventory.ItemStack(Material.EMERALD));
}
@EventHandler
public void leap(UpdateEvent event)
{
if (getEntity() == null)
return;
if (event.getType() != UpdateType.FAST)
return;
if (Math.random() < 0.9)
return;
Zombie zombie = getEntity();
if (zombie.getTarget() == null)
return;
double dist = UtilMath.offset(zombie.getTarget(), zombie);
if (dist <= 3 || dist > 16)
return;
double power = 0.8 + (1.2 * ((dist-3)/13d));
//Leap
UtilAction.velocity(zombie, UtilAlg.getTrajectory(zombie, zombie.getTarget()),
power, false, 0, 0.2, 1, true);
//Effect
zombie.getWorld().playSound(zombie.getLocation(), Sound.ZOMBIE_HURT, 1f, 2f);
}
}