Ring game
This commit is contained in:
parent
2062ca7efc
commit
0ffa67dfb8
@ -11,38 +11,40 @@ public class UtilShapes
|
||||
{
|
||||
private final static BlockFace[] radial =
|
||||
{
|
||||
BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST, BlockFace.NORTH,
|
||||
BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.SOUTH_WEST,
|
||||
BlockFace.WEST,
|
||||
BlockFace.NORTH_WEST,
|
||||
BlockFace.NORTH,
|
||||
BlockFace.NORTH_EAST,
|
||||
BlockFace.EAST,
|
||||
BlockFace.SOUTH_EAST
|
||||
};
|
||||
|
||||
public static ArrayList<Location> getCircle(Location loc, boolean hollow, double radius)
|
||||
{
|
||||
return getCircleBlocks(loc, radius, 0, hollow, false);
|
||||
return getSphereBlocks(loc, radius, 0, hollow);
|
||||
}
|
||||
|
||||
public static ArrayList<Location> getSphereBlocks(Location loc, double radius, double height, boolean hollow)
|
||||
{
|
||||
return getCircleBlocks(loc, radius, height, hollow, true);
|
||||
}
|
||||
|
||||
private static ArrayList<Location> getCircleBlocks(Location loc, double radius, double height, boolean hollow, boolean sphere)
|
||||
public static ArrayList<Location> getSphereBlocks(Location loc, double width, double height, boolean hollow)
|
||||
{
|
||||
ArrayList<Location> circleblocks = new ArrayList<Location>();
|
||||
double cx = loc.getBlockX();
|
||||
double cy = loc.getBlockY();
|
||||
double cz = loc.getBlockZ();
|
||||
|
||||
for (double y = (sphere ? cy - radius : cy); y < (sphere ? cy + radius : cy + height + 1); y++)
|
||||
for (double y = height; y < height + 1; y++)
|
||||
{
|
||||
for (double x = cx - radius; x <= cx + radius; x++)
|
||||
for (double x = -width; x <= width; x++)
|
||||
{
|
||||
for (double z = cz - radius; z <= cz + radius; z++)
|
||||
for (double z = -width; z <= width; z++)
|
||||
{
|
||||
double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (sphere ? (cy - y) * (cy - y) : 0);
|
||||
double dist = (x * x) + (z * z) + (y * y);
|
||||
|
||||
if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1)))
|
||||
if (dist < width * width
|
||||
&& !(hollow && Math.abs(x) - width < 1 && Math.abs(z) - width < 1 && Math.abs(y) - height < 1))
|
||||
{
|
||||
Location l = new Location(loc.getWorld(), x, y, z);
|
||||
Location l = new Location(loc.getWorld(), x + cx, y + cy, z + cz);
|
||||
circleblocks.add(l);
|
||||
}
|
||||
}
|
||||
@ -75,7 +77,8 @@ public class UtilShapes
|
||||
right = radial[high];
|
||||
return new BlockFace[]
|
||||
{
|
||||
left, right
|
||||
left,
|
||||
right
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -87,13 +90,19 @@ public class UtilShapes
|
||||
BlockFace[] faces = getSideBlockFaces(facing);
|
||||
return new Block[]
|
||||
{
|
||||
b.getRelative(faces[0]), b.getRelative(faces[1])
|
||||
b.getRelative(faces[0]),
|
||||
b.getRelative(faces[1])
|
||||
};
|
||||
}
|
||||
|
||||
public static BlockFace getFacing(float yaw)
|
||||
{
|
||||
return radial[Math.round(yaw / 45f) & 0x7];
|
||||
return radial[Math.round(yaw / 45f) % 8];
|
||||
}
|
||||
|
||||
public static float getFacing(BlockFace face)
|
||||
{
|
||||
return UtilAlg.GetYaw(new Vector(face.getModX(), face.getModY(), face.getModZ()).normalize());
|
||||
}
|
||||
|
||||
public static ArrayList<Location> getLinesDistancedPoints(Location startingPoint, Location endingPoint,
|
||||
@ -133,6 +142,24 @@ public class UtilShapes
|
||||
return locs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the blocks around 0,0,0
|
||||
*/
|
||||
public static ArrayList<Location> rotate(ArrayList<Location> locs, double degree)
|
||||
{
|
||||
ArrayList<Location> rotated = new ArrayList<Location>();
|
||||
|
||||
for (Location loc : locs)
|
||||
{
|
||||
double xRot = Math.cos(degree) * (loc.getX()) - Math.sin(degree) * (loc.getZ());
|
||||
double zRot = loc.getZ() + Math.sin(degree) * (loc.getX()) + Math.cos(degree) * (loc.getZ());
|
||||
|
||||
rotated.add(new Location(loc.getWorld(), xRot, loc.getY(), zRot));
|
||||
}
|
||||
|
||||
return rotated;
|
||||
}
|
||||
|
||||
public static ArrayList<Location> getDistancedCircle(Location center, double pointsDistance, double circleRadius)
|
||||
{
|
||||
return getPointsInCircle(center, (int) ((circleRadius * Math.PI * 2) / pointsDistance), circleRadius);
|
||||
@ -157,12 +184,14 @@ public class UtilShapes
|
||||
|
||||
new int[]
|
||||
{
|
||||
allowDiagonal ? facing.getModX() : facing.getModZ(), allowDiagonal ? 0 : -facing.getModX()
|
||||
allowDiagonal ? facing.getModX() : facing.getModZ(),
|
||||
allowDiagonal ? 0 : -facing.getModX()
|
||||
},
|
||||
|
||||
new int[]
|
||||
{
|
||||
allowDiagonal ? 0 : -facing.getModZ(), allowDiagonal ? facing.getModZ() : facing.getModX()
|
||||
allowDiagonal ? 0 : -facing.getModZ(),
|
||||
allowDiagonal ? facing.getModZ() : facing.getModX()
|
||||
}
|
||||
};
|
||||
|
||||
@ -189,7 +218,8 @@ public class UtilShapes
|
||||
{
|
||||
faces = new BlockFace[]
|
||||
{
|
||||
faces[1], faces[0]
|
||||
faces[1],
|
||||
faces[0]
|
||||
};
|
||||
}
|
||||
|
||||
@ -228,7 +258,8 @@ public class UtilShapes
|
||||
|
||||
return new Block[]
|
||||
{
|
||||
b.getRelative(faces[0]), b.getRelative(faces[1])
|
||||
b.getRelative(faces[0]),
|
||||
b.getRelative(faces[1])
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ public enum GameDisplay
|
||||
Dragons("Dragons", Material.ENDER_STONE, (byte)0, GameCategory.ARCADE, 13),
|
||||
DragonsTeams("Dragons Teams", Material.DRAGON_EGG, (byte)0, GameCategory.TEAM_VARIANT, 14),
|
||||
Draw("Draw My Thing", Material.BOOK_AND_QUILL, (byte)0, GameCategory.CLASSICS, 15),
|
||||
ElytraRings("ElytraRings", Material.ELYTRA, (byte) 0, GameCategory.CLASSICS, 61),
|
||||
Evolution("Evolution", Material.EMERALD, (byte)0, GameCategory.ARCADE, 16),
|
||||
Gravity("Gravity", Material.ENDER_PORTAL_FRAME, (byte)0, GameCategory.EXTRA, 18),
|
||||
Halloween("Halloween Horror", Material.PUMPKIN, (byte)0, GameCategory.CLASSICS, 19),
|
||||
|
@ -216,7 +216,7 @@ public class Arcade extends JavaPlugin
|
||||
for (String gameName : _serverConfiguration.getServerGroup().getGames().split(","))
|
||||
{
|
||||
try
|
||||
{
|
||||
{System.out.println(gameName);
|
||||
GameType type = GameType.valueOf(gameName);
|
||||
config.GameList.add(type);
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ import nautilus.game.arcade.managers.IdleManager;
|
||||
import nautilus.game.arcade.managers.MiscManager;
|
||||
import nautilus.game.arcade.player.ArcadePlayer;
|
||||
import nautilus.game.arcade.shop.ArcadeShop;
|
||||
import net.minecraft.server.v1_8_R3.EntityLiving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -41,6 +41,7 @@ import nautilus.game.arcade.game.games.oldmineware.OldMineWare;
|
||||
import nautilus.game.arcade.game.games.paintball.Paintball;
|
||||
import nautilus.game.arcade.game.games.quiver.Quiver;
|
||||
import nautilus.game.arcade.game.games.quiver.QuiverTeams;
|
||||
import nautilus.game.arcade.game.games.rings.ElytraRings;
|
||||
import nautilus.game.arcade.game.games.runner.Runner;
|
||||
import nautilus.game.arcade.game.games.searchanddestroy.SearchAndDestroy;
|
||||
import nautilus.game.arcade.game.games.sheep.SheepGame;
|
||||
@ -89,6 +90,7 @@ public enum GameType
|
||||
Dragons(Dragons.class, GameDisplay.Dragons),
|
||||
DragonsTeams(DragonsTeams.class, GameDisplay.DragonsTeams),
|
||||
Draw(Draw.class, GameDisplay.Draw),
|
||||
ElytraRings(ElytraRings.class, GameDisplay.ElytraRings),
|
||||
Evolution(Evolution.class, GameDisplay.Evolution),
|
||||
Gravity(Gravity.class, GameDisplay.Gravity),
|
||||
Halloween(Halloween.class, GameDisplay.Halloween, "http://file.mineplex.com/ResHalloween.zip", true),
|
||||
|
@ -0,0 +1,252 @@
|
||||
package nautilus.game.arcade.game.games.rings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilShapes;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
|
||||
import nautilus.game.arcade.game.SoloGame;
|
||||
import nautilus.game.arcade.game.games.uhc.KitUHC;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
|
||||
public class ElytraRings extends SoloGame
|
||||
{
|
||||
private HashMap<Integer, Ring> _rings = new HashMap<Integer, Ring>();
|
||||
private HashMap<UUID, Integer> _goneThrough = new HashMap<UUID, Integer>();
|
||||
private HashMap<UUID, Location> _lastLocation = new HashMap<UUID, Location>();
|
||||
|
||||
public ElytraRings(ArcadeManager manager)
|
||||
{
|
||||
super(manager, GameType.ElytraRings, new Kit[]
|
||||
{
|
||||
new KitUHC(manager)
|
||||
}, new String[]
|
||||
{
|
||||
"Fly through the rings!"
|
||||
});
|
||||
|
||||
DeathOut = false;
|
||||
DeathMessages = false;
|
||||
}
|
||||
|
||||
public void RespawnPlayer(final Player player)
|
||||
{
|
||||
player.eject();
|
||||
|
||||
if (_goneThrough.containsKey(player.getUniqueId()) && _rings.containsKey(_goneThrough.get(player.getUniqueId())))
|
||||
{
|
||||
Ring ring = _rings.get(_goneThrough.get(player.getUniqueId()));
|
||||
|
||||
player.teleport(ring.getCenter());
|
||||
}
|
||||
else if (_goneThrough.containsKey(player.getUniqueId()) && _rings.containsKey(_goneThrough.get(player.getUniqueId()) + 1))
|
||||
{
|
||||
Ring ring = _rings.get(_goneThrough.get(player.getUniqueId()) + 1);
|
||||
|
||||
player.teleport(ring.getCenter());
|
||||
}
|
||||
else
|
||||
{
|
||||
player.teleport(GetTeam(player).GetSpawn());
|
||||
}
|
||||
|
||||
Manager.Clear(player);
|
||||
|
||||
// Event
|
||||
PlayerGameRespawnEvent event = new PlayerGameRespawnEvent(this, player);
|
||||
UtilServer.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
// Re-Give Kit
|
||||
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
GetKit(player).ApplyKit(player);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ParseData()
|
||||
{
|
||||
Location loc = UtilAlg.getAverageLocation(GetTeamList().get(0).GetSpawns());
|
||||
BlockFace currentDirection = BlockFace.values()[UtilMath.r(4)];
|
||||
|
||||
while (_rings.size() < 30)
|
||||
{
|
||||
int dist = UtilMath.r(40);
|
||||
|
||||
loc = loc.getBlock().getRelative(currentDirection, 20).getLocation();
|
||||
|
||||
generateRing(loc, currentDirection, 2 + UtilMath.r(2) + UtilMath.r(2));
|
||||
}
|
||||
|
||||
loc = loc.getBlock().getRelative(currentDirection, 20).getLocation();
|
||||
|
||||
Ring ring = generateRing(loc, currentDirection, 7);
|
||||
|
||||
for (Block b : ring.getRing())
|
||||
{
|
||||
b.setType(Material.GOLD_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGameStart(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() != GameState.Prepare)
|
||||
return;
|
||||
|
||||
for (Player player : this.GetPlayers(true))
|
||||
{
|
||||
player.getInventory().setChestplate(new ItemStack(Material.ELYTRA));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMove(PlayerMoveEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (!IsAlive(event.getPlayer()))
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
int current = 1;
|
||||
|
||||
if (_goneThrough.containsKey(player.getUniqueId()))
|
||||
{
|
||||
current = _goneThrough.get(player.getUniqueId()) + 1;
|
||||
}
|
||||
|
||||
if (!_rings.containsKey(current))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Ring ring = _rings.get(current);
|
||||
|
||||
if (!ring.isMoveThroughRing(event.getFrom(), event.getTo()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_goneThrough.put(player.getUniqueId(), current + 1);
|
||||
|
||||
Announce(player.getName() + " has gone through ring " + current + "!");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSpeedBoost(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for (Player player : GetPlayers(true))
|
||||
{
|
||||
float exp = player.getExp();
|
||||
|
||||
exp += 0.02;
|
||||
|
||||
if (exp > 0.05 && _lastLocation.containsKey(player.getUniqueId()))
|
||||
{
|
||||
UtilAction.velocity(player, player.getLocation().getDirection());
|
||||
|
||||
if (!_goneThrough.containsKey(player.getUniqueId())
|
||||
|| _rings.containsKey(_goneThrough.get(player.getUniqueId()) + 1))
|
||||
{
|
||||
exp -= 0.05;
|
||||
}
|
||||
|
||||
for (Location loc : UtilShapes.getLinesDistancedPoints(_lastLocation.get(player.getUniqueId()),
|
||||
player.getLocation(), 0.3))
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.CLOUD, loc, 0.2F, 0.2F, 0.2F, 0, 3, ViewDist.LONGER);
|
||||
}
|
||||
|
||||
_lastLocation.put(player.getUniqueId(), player.getLocation());
|
||||
}
|
||||
|
||||
player.setExp(Math.min(exp, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onToggleSneak(PlayerToggleSneakEvent event)
|
||||
{
|
||||
if (!IsAlive(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (event.isSneaking())
|
||||
{
|
||||
_lastLocation.put(player.getUniqueId(), player.getLocation());
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastLocation.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
private Ring generateRing(Location center, BlockFace direction, int size)
|
||||
{
|
||||
ArrayList<Block> blocks = new ArrayList<Block>();
|
||||
ArrayList<Block> hole = new ArrayList<Block>();
|
||||
|
||||
for (Location loc : UtilShapes.rotate(UtilShapes.getSphereBlocks(center, size, size, true),
|
||||
UtilShapes.getFacing(direction)))
|
||||
{
|
||||
blocks.add(loc.getBlock());
|
||||
}
|
||||
|
||||
size--;
|
||||
|
||||
for (Location loc : UtilShapes.rotate(UtilShapes.getSphereBlocks(center, size, size, false),
|
||||
UtilShapes.getFacing(direction)))
|
||||
{
|
||||
hole.add(loc.getBlock());
|
||||
}
|
||||
|
||||
center.setDirection(new Vector(direction.getModX(), direction.getModY(), direction.getModZ()));
|
||||
|
||||
Ring ring = new Ring(blocks, hole, center.clone());
|
||||
|
||||
for (Block b : ring.getRing())
|
||||
{
|
||||
b.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 4, false);
|
||||
}
|
||||
|
||||
_rings.put(_rings.size() + 1, ring);
|
||||
|
||||
return ring;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package nautilus.game.arcade.game.games.rings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
|
||||
public class Ring
|
||||
{
|
||||
private ArrayList<Block> _core = new ArrayList<Block>();
|
||||
private ArrayList<Block> _ring = new ArrayList<Block>();
|
||||
private Location _center;
|
||||
|
||||
public Ring(ArrayList<Block> blocks, ArrayList<Block> inside, Location center)
|
||||
{
|
||||
_core = inside;
|
||||
_ring = blocks;
|
||||
_center = center;
|
||||
}
|
||||
|
||||
public Location getCenter()
|
||||
{
|
||||
return _center;
|
||||
}
|
||||
|
||||
public ArrayList<Block> getRing()
|
||||
{
|
||||
return _ring;
|
||||
}
|
||||
|
||||
public boolean isMoveThroughRing(Location from, Location to)
|
||||
{
|
||||
from = from.clone();
|
||||
to = to.clone();
|
||||
from.setX(from.getBlockX() + 0.5);
|
||||
from.setY(from.getBlockY() + 0.5);
|
||||
from.setZ(from.getBlockZ() + 0.5);
|
||||
to.setX(to.getBlockX() + 0.5);
|
||||
to.setY(to.getBlockY() + 0.5);
|
||||
to.setZ(to.getBlockZ() + 0.5);
|
||||
|
||||
Vector vec = UtilAlg.getTrajectory(from, to).multiply(0.5);
|
||||
double dist = UtilMath.offset(from, to);
|
||||
|
||||
while (dist > 0)
|
||||
{
|
||||
dist -= 0.5;
|
||||
|
||||
Location loc = from.getBlock().getLocation().add(0.5, 0.5, 0.5);
|
||||
|
||||
if (_core.contains(loc.getBlock()))
|
||||
return true;
|
||||
|
||||
if (_core.contains(loc.clone().add(loc.getX() == 0 ? 0 : loc.getX() > 0 ? 1 : -1, 0, 0)))
|
||||
return true;
|
||||
|
||||
if (_core.contains(loc.clone().add(0, loc.getY() == 0 ? 0 : loc.getY() > 0 ? 1 : -1, 0)))
|
||||
return true;
|
||||
|
||||
if (_core.contains(loc.clone().add(0, 0, loc.getZ() == 0 ? 0 : loc.getZ() > 0 ? 1 : -1)))
|
||||
return true;
|
||||
|
||||
from.add(vec);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user