-compass
-deathmatch
-various fixes
This commit is contained in:
Chiss 2013-11-25 20:59:46 +11:00
parent e469c5705b
commit 48e392fdf0
6 changed files with 368 additions and 46 deletions

View File

@ -190,14 +190,14 @@ public class MapUtil
@SuppressWarnings("unchecked")
public static void SendChunkForPlayer(int x, int z, Player player)
{
System.out.println("Sending Chunk " + x + ", " + z);
//System.out.println("Sending Chunk " + x + ", " + z);
((CraftPlayer)player).getHandle().chunkCoordIntPairQueue.add(new ChunkCoordIntPair(x, z));
}
@SuppressWarnings("unchecked")
public static void SendMultiBlockForPlayer(int x, int z, short[] dirtyBlocks, int dirtyCount, World world, Player player)
{
System.out.println("Sending MultiBlockChunk " + x + ", " + z);
//System.out.println("Sending MultiBlockChunk " + x + ", " + z);
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new Packet52MultiBlockChange(x, z, dirtyBlocks, dirtyCount, ((CraftWorld)world).getHandle()));
}

View File

@ -66,7 +66,7 @@ public class UtilFirework
return null;
}
public static Firework launchFirework(Location loc, FireworkEffect fe, Vector dir)
public static Firework launchFirework(Location loc, FireworkEffect fe, Vector dir, int power)
{
try
{
@ -74,11 +74,12 @@ public class UtilFirework
FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
data.clearEffects();
data.setPower(1);
data.setPower(power);
data.addEffect(fe);
fw.setFireworkMeta(data);
fw.setVelocity(dir);
if (dir != null)
fw.setVelocity(dir);
return fw;
}

View File

@ -21,6 +21,7 @@ public class Condition
CUSTOM,
ABSORBTION,
BLINDNESS,
CONFUSION,
DAMAGE_RESISTANCE,
@ -28,6 +29,7 @@ public class Condition
FIRE_RESISTANCE,
HARM,
HEAL,
HEALTH_BOOST,
HUNGER,
INCREASE_DAMAGE,
INVISIBILITY,

View File

@ -5,6 +5,7 @@ import mineplex.minecraft.game.core.condition.conditions.*;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
public class ConditionFactory
@ -258,4 +259,12 @@ public class ConditionFactory
ConditionType.NIGHT_VISION, mult, (int)(20 * duration), extend,
Material.EYE_OF_ENDER, (byte)0, showIndicator, ambient));
}
public Condition HealthBoost(String reason, LivingEntity ent, LivingEntity source,
double duration, int mult, boolean extend, boolean showIndicator, boolean ambient)
{
return Manager.AddCondition(new Condition(Manager, reason, ent, source,
ConditionType.HEALTH_BOOST, mult, (int)(20 * duration), extend,
Material.APPLE, (byte)0, showIndicator, ambient));
}
}

View File

@ -136,7 +136,7 @@ public class CompassAddon extends MiniPlugin
@EventHandler
public void InventoryClick(InventoryClickEvent event)
{
UtilInv.DisallowMovementOf(event, "Target Compass", Material.COMPASS, (byte)0, true);
//UtilInv.DisallowMovementOf(event, "Target Compass", Material.COMPASS, (byte)0, true);
}
@EventHandler

View File

@ -8,7 +8,6 @@ import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Color;
import org.bukkit.Effect;
import org.bukkit.FireworkEffect;
@ -20,11 +19,13 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
@ -37,9 +38,10 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@ -71,6 +73,7 @@ import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.hungergames.kit.*;
import nautilus.game.arcade.kit.Kit;
@ -86,13 +89,12 @@ public class HungerGames extends SoloGame
private Location _spawn;
//Creep
private int _maxSpreadRate = 100;
private int _maxSpreadRate = 120;
private ArrayList<Location> _redLocations = new ArrayList<Location>();
private int _spreadType = 0;
private String _spreadName = "";
private boolean _ignoreLiquids = true;
private ArrayList<Entry<Integer, Integer>> _spreadTypeBlocks;
private Location _spreadSafe = null;
private HashMap<Player, Long> _redOutTime = new HashMap<Player, Long>();
private HashMap<Integer, HashMap<Integer, HashSet<Integer>>> _redMap = new HashMap<Integer, HashMap<Integer, HashSet<Integer>>>();
@ -104,6 +106,11 @@ public class HungerGames extends SoloGame
private Location _supplyEffect = null;
private ArrayList<Block> _supplyChests = new ArrayList<Block>();
//Deathmatch
private boolean _deathmatchCountdown = false;
private boolean _deathmatchLive = false;
private long _deathmatchTime = 0;
//Debug
private long totalTime = 0;
@ -256,8 +263,8 @@ public class HungerGames extends SoloGame
int spawn = 0;
//Chests
System.out.println("Chests: " + Math.min(180, chests.size()));
for (int i=0 ; i<180 && !chests.isEmpty() ; i++)
System.out.println("Chests: " + Math.min(220, chests.size()));
for (int i=0 ; i<220 && !chests.isEmpty() ; i++)
{
Location loc = chests.remove(UtilMath.r(chests.size()));
@ -292,7 +299,7 @@ public class HungerGames extends SoloGame
int done = 0;
while (done < 20)
while (done < 30)
{
Block block = UtilBlock.getHighest(WorldData.World, WorldData.MinX + UtilMath.r(xDiff), WorldData.MinZ + UtilMath.r(zDiff), ignore);
@ -380,17 +387,17 @@ public class HungerGames extends SoloGame
//Weapons
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.WOOD_AXE));
for (int i = 0; i < 48; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_AXE));
for (int i = 0; i < 24; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_AXE));
for (int i = 0; i < 32; i++) _baseChestLoot.add(new ItemStack(Material.STONE_AXE));
for (int i = 0; i < 24; i++) _baseChestLoot.add(new ItemStack(Material.IRON_AXE));
for (int i = 0; i < 16; i++) _baseChestLoot.add(new ItemStack(Material.IRON_AXE));
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.WOOD_SWORD));
for (int i = 0; i < 48; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_SWORD));
for (int i = 0; i < 24; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_SWORD));
for (int i = 0; i < 32; i++) _baseChestLoot.add(new ItemStack(Material.STONE_SWORD));
for (int i = 0; i < 12; i++) _baseChestLoot.add(new ItemStack(Material.IRON_SWORD));
for (int i = 0; i < 32; i++) _baseChestLoot.add(new ItemStack(Material.BOW));
for (int i = 0; i < 64; i++) _baseChestLoot.add(new ItemStack(Material.ARROW, 4));
for (int i = 0; i < 48; i++) _baseChestLoot.add(new ItemStack(Material.BOW));
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.ARROW, 3));
for (int i = 0; i < 32; i++) _baseChestLoot.add(new ItemStack(Material.TNT, 1));
for (int i = 0; i < 64; i++) _baseChestLoot.add(new ItemStack(Material.WEB, 2));
@ -405,16 +412,17 @@ public class HungerGames extends SoloGame
for (int i = 0; i < 48; i++) _baseChestLoot.add(new ItemStack(Material.COOKIE));
for (int i = 0; i < 48; i++) _baseChestLoot.add(new ItemStack(Material.ROTTEN_FLESH));
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.WHEAT, 2));
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.WHEAT, 6));
//Misc
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.COMPASS, 1));
for (int i = 0; i < 48; i++) _baseChestLoot.add(new ItemStack(Material.EXP_BOTTLE, 1));
for (int i = 0; i < 36; i++) _baseChestLoot.add(new ItemStack(Material.GOLD_INGOT, 2));
for (int i = 0; i < 24; i++) _baseChestLoot.add(new ItemStack(Material.IRON_INGOT));
for (int i = 0; i < 3; i++) _baseChestLoot.add(new ItemStack(Material.DIAMOND));
for (int i = 0; i < 64; i++) _baseChestLoot.add(new ItemStack(Material.STICK, 4));
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.FLINT, 3));
for (int i = 0; i < 128; i++) _baseChestLoot.add(new ItemStack(Material.FEATHER, 3));
for (int i = 0; i < 64; i++) _baseChestLoot.add(new ItemStack(Material.FLINT, 3));
for (int i = 0; i < 64; i++) _baseChestLoot.add(new ItemStack(Material.FEATHER, 3));
for (int i = 0; i < 32; i++) _baseChestLoot.add(new ItemStack(Material.BOAT));
for (int i = 0; i < 64; i++) _baseChestLoot.add(new ItemStack(Material.FISHING_ROD));
@ -458,7 +466,7 @@ public class HungerGames extends SoloGame
}
@EventHandler
public void SpeedApply(GameStateChangeEvent event)
public void StartEffectApply(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Live)
return;
@ -466,6 +474,9 @@ public class HungerGames extends SoloGame
for (Player player : GetPlayers(true))
{
Manager.GetCondition().Factory().Speed("Start Speed", player, player, 30, 1, false, false, false);
Manager.GetCondition().Factory().HealthBoost("Start Health", player, player, 30, 1, false, false, false);
player.setHealth(player.getMaxHealth());
}
}
@ -530,7 +541,7 @@ public class HungerGames extends SoloGame
public int RedMax()
{
return _maxSpreadRate + 100;// + (24 - GetPlayers(true).size())*2;
return _maxSpreadRate;// + (24 - GetPlayers(true).size())*2;
}
@EventHandler
@ -620,6 +631,13 @@ public class HungerGames extends SoloGame
public boolean RedSpread(Block block)
{
if (block == null || block.getType() == Material.AIR)
return false;
//Inside Boundary
if (UtilMath.offset(_spawn, block.getLocation()) < 48)
return false;
//Liquid
if (block.isLiquid())
{
@ -653,7 +671,7 @@ public class HungerGames extends SoloGame
return false;
}
if (!UtilBlock.solid(block) || UtilBlock.airFoliage(block) || block.getType() == Material.CHEST)
if ((!UtilBlock.solid(block) || UtilBlock.airFoliage(block) || block.getType() == Material.CHEST))
{
if (!block.isLiquid())
{
@ -673,25 +691,11 @@ public class HungerGames extends SoloGame
//Outside Boundaries
if (block.getX() < WorldData.MinX || block.getX() > WorldData.MaxX || block.getZ() < WorldData.MinZ || block.getZ() > WorldData.MaxZ)
{
return false;
}
//Inside Boundary
if (_spreadSafe == null)
{
_spreadSafe = GetSpectatorLocation().clone();
_spreadSafe.setY(GetTeamList().get(0).GetSpawn().getY());
}
if (UtilMath.offset(_spreadSafe, block.getLocation()) < 32)
return false;
//Not Visible
if (!UtilBlock.isVisible(block))
{
return false;
}
//Apply
_redLocations.add(block.getLocation());
@ -700,6 +704,9 @@ public class HungerGames extends SoloGame
public void RedChangeBlock(Location loc, int id, byte data)
{
if (!IsLive())
return;
MapUtil.ChunkBlockChange(loc, id, data);
//Save Red
@ -744,6 +751,9 @@ public class HungerGames extends SoloGame
if (event.getType() != UpdateType.FASTER)
return;
if (!IsLive())
return;
for (Player player : _redChunks.keySet())
{
//Remove Far Away
@ -762,14 +772,39 @@ public class HungerGames extends SoloGame
if (_redChunks.get(player).isEmpty())
continue;
//Get Best
//XXX Currently, just using a FIFO queue to select
// Add weighting to select the best chunk based on time/distance/count.
ChunkChange change = _redChunks.get(player).remove(0);
//change.Changes contains Location/Id/Data for all pending changes in this chunk
//Get Fittest Chunk to Update
int bestId = -1;
double bestScore = 0;
for (int i=0 ; i<_redChunks.get(player).size() ; i++)
{
ChunkChange change = _redChunks.get(player).get(i);
//Base Score, 1 per block
double score = change.Changes.size();
//Time Score, 1 per second
score += (System.currentTimeMillis() - change.Time)/1000d;
//Distance Divisor
int x = Math.abs(player.getLocation().getChunk().getX() - change.Chunk.getX());
int z = Math.abs(player.getLocation().getChunk().getZ() - change.Chunk.getZ());
double dist = Math.sqrt(x*x + z*z);
score = score/dist;
if (bestId == -1 || score > bestScore)
{
bestId = i;
bestScore = score;
}
}
if (bestId == -1)
continue;
//Send MultiBlock or Chunk Update for Fittest Chunk
ChunkChange change = _redChunks.get(player).remove(bestId);
//XXX Simply replace this line with the the Multiblocks packet.
if (change.DirtyCount >= 63)
MapUtil.SendChunkForPlayer(change.Chunk.getX(), change.Chunk.getZ(), player);
else
@ -849,11 +884,17 @@ public class HungerGames extends SoloGame
{
if (Math.random() > 0.8)
{
/*
Vector traj = UtilAlg.getTrajectory(block.getLocation().add(0.5, 1.5, 0.5), player.getLocation());
Snowball ball = player.getWorld().spawn(block.getLocation().add(0.5, 1.5, 0.5).subtract(traj.clone().multiply(8 + UtilMath.r(8))), Snowball.class);
ball.setVelocity(UtilAlg.getTrajectory(ball.getLocation(), player.getEyeLocation().add(0, 3, 0)).add(new Vector(Math.random()-0.5, Math.random()-0.5, Math.random()-0.5).multiply(0.1)));
*/
player.playEffect(block.getLocation(), Effect.STEP_SOUND, Material.OBSIDIAN);
player.sendMessage("Block @ " + UtilWorld.locToStrClean(block.getLocation()));
}
}
@ -881,6 +922,12 @@ public class HungerGames extends SoloGame
near = true;
}
}
if (!near)
{
if (_deathmatchLive && UtilMath.offset(player.getLocation(), _spawn) > 48)
near = true;
}
if (near)
{
@ -1037,6 +1084,231 @@ public class HungerGames extends SoloGame
UtilParticle.PlayParticle(ParticleType.SPELL, block.getLocation().add(0.5, 0.5, 0.5), 0.3f, 0.3f, 0.3f, 0, 1);
}
}
@EventHandler
public void DeathmatchUpdate(UpdateEvent event)
{
if (!IsLive())
return;
if (_deathmatchLive)
{
if (event.getType() != UpdateType.SEC)
return;
if (_deathmatchTime <= 0)
return;
Announce(C.cRed + C.Bold + "Deathmatch in " + _deathmatchTime + "...");
_deathmatchTime--;
}
else if (_deathmatchCountdown)
{
if (event.getType() != UpdateType.TICK)
return;
long timeLeft = 60000 - (System.currentTimeMillis() - _deathmatchTime);
if (timeLeft > 0)
{
GetObjectiveSide().setDisplayName(
ChatColor.WHITE + "§lDeathmatch: " + C.cGreen + "§l"
+ UtilTime.MakeStr(timeLeft));
}
else
{
GetObjectiveSide().setDisplayName(
ChatColor.WHITE + "§lDeathmatch");
_deathmatchLive = true;
GetTeamList().get(0).SpawnTeleport();
_redLocations.clear();
for (Block block : UtilBlock.getInRadius(_spawn, 52d).keySet())
RedSpread(block);
_deathmatchTime = 10;
}
}
else
{
if (event.getType() != UpdateType.SEC)
return;
if (!UtilTime.elapsed(GetStateTime(), 360000))
return;
if (GetPlayers(true).size() > 4)
return;
if (!UtilTime.elapsed(_deathmatchTime, 60000))
return;
Announce(C.cGreen + C.Bold + "Type " + ChatColor.RESET + C.Bold + "/dm" + C.cGreen + C.Bold + " to start Deathmatch!");
_deathmatchTime = System.currentTimeMillis();
}
}
@EventHandler
public void DeathmatchMoveCancel(PlayerMoveEvent event)
{
if (!_deathmatchLive)
return;
if (_deathmatchTime <= 0)
return;
if (UtilMath.offset2d(event.getFrom(), event.getTo()) == 0)
return;
event.setTo(event.getFrom());
}
@EventHandler(priority = EventPriority.LOWEST)
public void DeathmatchDamage(CustomDamageEvent event)
{
if (!_deathmatchLive)
return;
if (_deathmatchTime <= 0)
return;
event.SetCancelled("Deathmatch");
}
@EventHandler(priority = EventPriority.LOWEST)
public void DeathmatchStart(PlayerCommandPreprocessEvent event)
{
if (!event.getMessage().equalsIgnoreCase("/dm"))
return;
event.setCancelled(true);
if (!IsLive())
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "Deathmatch cannot be started now."));
return;
}
if (!UtilTime.elapsed(GetStateTime(), 360000))
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "Deathmatch cannot be started now."));
return;
}
if (GetPlayers(true).size() > 4)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "Deathmatch cannot be started now."));
return;
}
if (_deathmatchCountdown)
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "Deathmatch cannot be started now."));
return;
}
_deathmatchCountdown = true;
Announce(C.cGreen + C.Bold + event.getPlayer().getName() + " has initiated Deathmatch!");
Announce(C.cGreen + C.Bold + "Deathmatch starting in 60 seconds...");
_deathmatchTime = System.currentTimeMillis();
for (Player player : UtilServer.getPlayers())
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 1f);
}
@EventHandler(priority = EventPriority.LOWEST)
public void CropTrample(PlayerInteractEvent event)
{
if (event.getAction() != Action.PHYSICAL)
return;
if (event.getPlayer().getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.SOIL)
return;
event.setCancelled(true);
}
@EventHandler
public void CompassUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (!IsLive())
return;
//Night Time > Drop Target
if (WorldData.World.getTime() > 14000 && WorldData.World.getTime() < 23000 && _supplyCurrent != null)
{
for (Player player : GetPlayers(true))
{
player.setCompassTarget(_supplyCurrent);
for (int i : player.getInventory().all(Material.COMPASS).keySet())
{
ItemStack stack = player.getInventory().getItem(i);
ItemMeta itemMeta = stack.getItemMeta();
itemMeta.setDisplayName(
C.cWhite + C.Bold + "Supply Drop Location: " + C.cYellow + UtilMath.trim(1, UtilMath.offset(player.getLocation(), _supplyCurrent)));
stack.setItemMeta(itemMeta);
player.getInventory().setItem(i, stack);
}
}
}
//Player Target
else
{
for (Player player : GetPlayers(true))
{
Player target = null;
double bestDist = 0;
for (Player other : Manager.GetGame().GetPlayers(true))
{
if (other.equals(player))
continue;
if (other.isSneaking())
continue;
double dist = UtilMath.offset(player, other);
if (target == null || dist < bestDist)
{
target = other;
bestDist = dist;
}
}
if (target != null)
{
player.setCompassTarget(target.getLocation());
for (int i : player.getInventory().all(Material.COMPASS).keySet())
{
ItemStack stack = player.getInventory().getItem(i);
ItemMeta itemMeta = stack.getItemMeta();
itemMeta.setDisplayName(
" " + C.cWhite + C.Bold + "Nearest Player: " + C.cYellow + target.getName() +
" " + C.cWhite + C.Bold + "Distance: " + C.cYellow + UtilMath.trim(1, bestDist));
stack.setItemMeta(itemMeta);
player.getInventory().setItem(i, stack);
}
}
}
}
}
@EventHandler
public void TNTDelay(GameStateChangeEvent event)
@ -1168,7 +1440,11 @@ public class HungerGames extends SoloGame
if (!(event.GetEvent().getEntity() instanceof Player))
return;
FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.RED).with(Type.BALL_LARGE).trail(false).build();
for (int i=0 ; i<3 ; i++)
UtilFirework.launchFirework(event.GetEvent().getEntity().getLocation(), effect, null, 3);
if (event.GetLog().GetKiller() == null)
return;
@ -1199,4 +1475,38 @@ public class HungerGames extends SoloGame
{
_redChunks.remove(event.getPlayer());
}
private long _helpTimer = 0;
private int _helpIndex = 0;
private String[] _help = new String[]
{
C.cGreen + "Use a Compass to find and kill enemies!",
C.cAqua + "Crouch to become invisible to Compass tracking!",
C.cGreen + "Avoid the Deep Freeze at all costs!",
C.cAqua + "Use TNT & Tripwires to make traps!",
C.cGreen + "You lose Speed 2 at start of game if you attack.",
C.cAqua + "Avoid enemies who have better gear than you!",
C.cGreen + "Compass finds Supply Drops during night time.",
C.cAqua + "Compass finds Players during day time.",
};
@EventHandler
public void StateUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (this.GetState() != GameState.Recruit)
return;
if (!UtilTime.elapsed(_helpTimer, 8000))
return;
_helpTimer = System.currentTimeMillis();
for (Player player : UtilServer.getPlayers())
UtilPlayer.message(player, C.cWhite + C.Bold + "TIP " + ChatColor.RESET + _help[_helpIndex]);
_helpIndex = (_helpIndex + 1)%_help.length;
}
}