For Bisko to pull

This commit is contained in:
Morten 2015-09-22 16:12:51 +02:00
parent a5398cb773
commit 7838ad2bce
5 changed files with 329 additions and 41 deletions

View File

@ -13,6 +13,7 @@ import mineplex.core.hologram.Hologram.HologramTarget;
import mineplex.core.projectile.ProjectileUser;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
@ -100,6 +101,9 @@ public abstract class Challenge implements Listener
StartTime = System.currentTimeMillis();
Duration = getMaxTime();
Places = (int) Math.ceil(getChallengers().size() / 2D);
Bukkit.broadcastMessage("Players alive: " + Host.GetPlayers(true).size());
Bukkit.broadcastMessage("Players total: " + Host.GetPlayers(false).size());
}
public void EndOrder()
@ -157,6 +161,7 @@ public abstract class Challenge implements Listener
public boolean Finish()
{
boolean maxTimeReached = UtilTime.elapsed(StartTime, Duration);
ArrayList<Player> players = getChallengers();
if (players.size() <= Completed.size())
@ -180,8 +185,16 @@ public abstract class Challenge implements Listener
return true;
}
}
return UtilTime.elapsed(StartTime, Duration);
if(maxTimeReached)
{
onChallengeTimeEnd();
}
return maxTimeReached;
}
public void onChallengeTimeEnd() // Override-able
{
}
public int GetTimeLeft()

View File

@ -151,6 +151,7 @@ public class MineWare extends SoloGame implements IThrown
{
_challenges.add(ChallengePickASide.class);
_challenges.add(ChallengeKOTL.class);
_challenges.add(ChallengeWaveCrush.class);
_challenges.add(ChallengePunchThePig.class);
_challenges.add(ChallengeDogvsCat.class);
_challenges.add(ChallengeShootChickens.class);
@ -665,14 +666,12 @@ public class MineWare extends SoloGame implements IThrown
@Override
public void Idle(ProjectileUser data)
{
// TODO Auto-generated method stub
}
@Override
public void Expire(ProjectileUser data)
{
// TODO Auto-generated method stub
}
}

View File

@ -73,7 +73,7 @@ public class ChallengeBlockLobbers extends Challenge
@Override
public void generateRoom()
{
for(Location locs : UtilShapes.getCircle(new Location(Host.WorldData.World, 0, 0, 0), false, 14))
for(Location locs : UtilShapes.getCircle(new Location(Host.WorldData.World, 0, 0, 0), false, 11))
{
locs.getBlock().setType(Material.WOOL);
locs.getBlock().setData((byte) UtilMath.r(16));
@ -134,33 +134,16 @@ public class ChallengeBlockLobbers extends Challenge
{
return;
}
getFirstAvailableItem(event.getPlayer());
if(!_tBlocks.contains(event.getPlayer().getItemInHand().getType())) // Stupid compass... <3
{
return;
}
FallingBlock fBlock = event.getPlayer().getWorld()
.spawnFallingBlock(event.getPlayer().getLocation().clone().add(0, .4, 0), event.getPlayer().getItemInHand().getType(), (byte) 0);
FallingBlock fBlock = event.getPlayer().getWorld().spawnFallingBlock(event.getPlayer().getLocation().clone().add(0, .4, 0), event.getPlayer().getItemInHand().getType(), (byte) 0);
UtilInv.remove(event.getPlayer(), event.getPlayer().getItemInHand().getType(), (byte) 0, 1);
UtilAction.velocity(fBlock, event.getPlayer().getLocation().getDirection(), 1.5, false, 0.0, 0.3, 10.0, true);
Host.Manager.GetProjectile().AddThrow(fBlock, event.getPlayer(), Host, -1, true, false, true, 0.2f);
//TODO still doesn't work properly...
if(event.getPlayer().getItemInHand().getType() == Material.AIR || event.getPlayer().getItemInHand().getType() == null)
{
for(int i = 0; i <= 8; i++)
{
if(event.getPlayer().getInventory().getItem(i) == null)
{
continue;
}
if(event.getPlayer().getInventory().getItem(i).getType() != Material.AIR)
{
event.getPlayer().getInventory().setHeldItemSlot(i);
return;
}
}
}
}
@EventHandler
@ -211,4 +194,24 @@ public class ChallengeBlockLobbers extends Challenge
UtilAction.velocity(target, UtilAlg.getTrajectory2d(data.GetThrown().getLocation(), target.getLocation()), 0.65, false, 0, 0.3, 0.5, true);
data.GetThrown().remove();
}
public void getFirstAvailableItem(Player player)
{
if(player.getItemInHand().getType() == Material.AIR || player.getItemInHand().getType() == null)
{
for(int i = 0; i <= 8; i++)
{
if(player.getInventory().getItem(i) == null)
{
continue;
}
if(player.getInventory().getItem(i).getType() != Material.AIR)
{
player.getInventory().setHeldItemSlot(i);
return;
}
}
}
}
}

View File

@ -28,7 +28,8 @@ import org.bukkit.scheduler.BukkitRunnable;
public class ChallengeMiniOITQ extends Challenge
{
private long _gameTime = System.currentTimeMillis() + ((UtilMath.r(5) + 10)*1000);
private long _gameTime;
public ChallengeMiniOITQ(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Mini OITQ", "One Arrow! One Kill!", "Don't miss!");
@ -39,9 +40,9 @@ public class ChallengeMiniOITQ extends Challenge
{
ArrayList<Location> spawns = new ArrayList<Location>();
for(int x = -(getArenaSize() - 1); x <= getArenaSize()-1; x++)
for(int x = -(getArenaSize() - 1); x <= getArenaSize() - 1; x++)
{
for(int z = -(getArenaSize() - 1); z <= getArenaSize()-1; z++)
for(int z = -(getArenaSize() - 1); z <= getArenaSize() - 1; z++)
{
if(x % 2 == 0 && z % 2 == 0)
{
@ -56,8 +57,8 @@ public class ChallengeMiniOITQ extends Challenge
public void cleanupRoom()
{
Host.DamagePvE = false;
for(Entity entities: Host.WorldData.World.getEntities())
for(Entity entities : Host.WorldData.World.getEntities())
{
if(entities instanceof Arrow)
{
@ -69,7 +70,8 @@ public class ChallengeMiniOITQ extends Challenge
@Override
public void setupPlayers()
{
for(Player player: Host.GetPlayers(true))
_gameTime = System.currentTimeMillis() + ((UtilMath.r(5) + 10) * 1000);
for(Player player : Host.GetPlayers(true))
{
player.getInventory().addItem(new ItemBuilder(Material.BOW).setTitle(C.cGreen + "1Shot1Kill").build());
player.getInventory().addItem(new ItemStack(Material.ARROW));
@ -116,7 +118,7 @@ public class ChallengeMiniOITQ extends Challenge
}
}
}
@EventHandler
public void gameTime(UpdateEvent event)
{
@ -129,16 +131,18 @@ public class ChallengeMiniOITQ extends Challenge
return;
}
if((System.currentTimeMillis() >= _gameTime))
for(Player player: Host.GetPlayers(true))
{
if(isDone(player))
for(Player player : Host.GetPlayers(true))
{
return;
if(isDone(player))
{
continue;
}
setLost(player);
}
setLost(player);
}
}
@EventHandler
public void onArrowHitPlayer(EntityDamageByEntityEvent event)
{
@ -148,7 +152,7 @@ public class ChallengeMiniOITQ extends Challenge
}
if(!(event.getDamager() instanceof Arrow)) // Damager = Arrow (player)
{
return;
return;
}
if(!(event.getEntity() instanceof Player)) // Damaged = player
{
@ -157,17 +161,17 @@ public class ChallengeMiniOITQ extends Challenge
Arrow arrow = (Arrow) event.getDamager();
Player shooter = (Player) arrow.getShooter();
Player damaged = (Player) event.getEntity();
if(isDone(shooter) || isDone(damaged))
{
event.setCancelled(true);
return;
}
SetCompleted(shooter, true);
setLost(damaged, true);
}
@EventHandler
public void onSuffication(EntityDamageEvent event)
{
@ -185,5 +189,5 @@ public class ChallengeMiniOITQ extends Challenge
}
event.setCancelled(true);
}
}

View File

@ -0,0 +1,269 @@
package nautilus.game.arcade.game.games.mineware.challenges;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ListIterator;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.mineware.Challenge;
import nautilus.game.arcade.game.games.mineware.MineWare;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
public class ChallengeWaveCrush extends Challenge
{
private boolean _inProgress = false;
private boolean _endHandling = true;
private int _waveAmount = 0;
private int _waveSpeed = 40; // in ticks
private ArrayList<Integer> _colorList = new ArrayList<Integer>(Arrays.asList(14, 11, 9, 3, 1, 4, 13, 5));
public ChallengeWaveCrush(MineWare host)
{
super(host, ChallengeType.FirstComplete, "Wave Crush", "Avoid the crushing waves!");
}
@Override
public ArrayList<Location> getSpawns()
{
ArrayList<Location> spawns = new ArrayList<Location>();
for(int x = -15; x <= -13; x++)
{
for(int z = -(getArenaSize() - 1); z <= getArenaSize() - 1; z++)
{
if(x % 2 == 0 && z % 2 == 0)
{
spawns.add(getCenter().clone().add(x + 0.5, 2.1, z + 0.5));
}
}
}
return spawns;
}
@Override
public void cleanupRoom()
{
_inProgress = false;
for(int x = -16; x <= 15; x++)
{
for(int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for(int y = 0; y <= 10; y++)
{
Block b = Host.WorldData.World.getBlockAt(x, y, z);
{
if(b.getType() != Material.AIR)
{
if(!getModifiedBlocks().contains(b))
{
b.setType(Material.AIR);
}
}
}
}
}
}
}
@Override
public void setupPlayers()
{
_inProgress = true;
new BukkitRunnable()
{
@Override
public void run()
{
_waveAmount++;
Block choosenBlock;
if(!_inProgress || !Host.IsLive())
{
this.cancel();
}
choosenBlock = Host.WorldData.World.getBlockAt(15, 1, UtilMath.r(getArenaSize() * 2) - getArenaSize());
while(choosenBlock.getType() == Material.AIR)
{
choosenBlock = Host.WorldData.World.getBlockAt(15, 1, UtilMath.r(getArenaSize() * 2) - getArenaSize());
}
waveStartingPoint(choosenBlock, 2);
if(_waveAmount % 3 == 0)
{
_waveSpeed--;
}
}
}.runTaskTimer(Host.Manager.getPlugin(), 20 * 3, _waveSpeed);
}
@Override
public void generateRoom()
{
int var = 0;
int colorPicker = 0;
for(int x = -16; x <= 15; x++)
{
for(int z = -getArenaSize(); z <= getArenaSize(); z++)
{
for(int y = 0; y <= 1; y++)
{
Block b = getCenter().getBlock().getRelative(x, y, z);
if(y == 0)
{
b.setType(Material.BEDROCK);
}
else if(y > 0)
{
b.setType(Material.WOOL);
b.setData(_colorList.get(colorPicker).byteValue());
}
if(b.getType() != Material.AIR)
{
addBlock(b);
}
}
}
if(var % 5 == 0 && (colorPicker != _colorList.size() - 1))
{
colorPicker++;
}
var++;
}
}
public void OnChallengeEnd()
{
for(Player player : Host.GetPlayers(true))
{
if(!isDone(player))
{
SetCompleted(player);
}
}
new BukkitRunnable()
{
@Override
public void run()
{
for(Entity fBlocks : Host.WorldData.World.getEntities())
{
if(fBlocks instanceof FallingBlock)
{
fBlocks.remove();
}
}
}
}.runTaskLater(Host.Manager.getPlugin(), 20);
}
@Override
public void onCollide(LivingEntity target, Block block, ProjectileUser data)
{
if(!Host.IsLive())
{
return;
}
if(!(data.GetThrown() instanceof FallingBlock))
{
return;
}
if(!(target instanceof Player))
{
return;
}
Player thePlayer = (Player) target;
if(isDone(thePlayer))
{
return;
}
Host.Manager.GetDamage().NewDamageEvent(target, null, null, DamageCause.PROJECTILE, 9999.0, false, false, false, "Falling Block",
"Wave crush");
}
@EventHandler
public void onEndHandling(UpdateEvent event)
{
if(!Host.IsLive())
{
return;
}
if(event.getType() != UpdateType.TICK)
{
return;
}
if(!_inProgress && _endHandling)
{
Bukkit.broadcastMessage("End event heard!");
OnChallengeEnd();
_endHandling = false;
}
}
public void waveStartingPoint(Block block, int radius)
{
Block pickedBlock = Host.WorldData.World.getBlockAt(block.getX(), block.getY(), block.getZ() - radius);
if(radius != 1)
{
for(int i = 0; i <= (radius * 2) + 1; i++)
{
waveCreation(Host.WorldData.World.getBlockAt(pickedBlock.getX(), pickedBlock.getY(), pickedBlock.getZ() + i));
}
}
else
{
waveCreation(pickedBlock);
}
}
public void waveCreation(final Block block)
{
new BukkitRunnable()
{
Block theBlock = block;
@SuppressWarnings("deprecation")
@Override
public void run()
{
if(!_inProgress)
{
this.cancel();
}
if(theBlock.getType() == Material.AIR)
{
this.cancel();
}
FallingBlock fBlock = Host.WorldData.World.spawnFallingBlock(theBlock.getLocation().clone().add(0, 1, 0), theBlock.getType(),
theBlock.getData());
Host.Manager.GetProjectile().AddThrow(fBlock, null, Host, -1, true, false, true, 0.2f);
fBlock.setVelocity(new Vector(0, 10, 0).normalize());
theBlock.setType(Material.AIR);
theBlock = Host.WorldData.World.getBlockAt(theBlock.getX() - 1, theBlock.getY(), theBlock.getZ());
}
}.runTaskTimer(Host.Manager.getPlugin(), 0, 2);
}
}