Added Draw

This commit is contained in:
Chiss 2013-11-29 23:38:38 +11:00
parent f927f2c1be
commit 8807854b57
7 changed files with 889 additions and 29 deletions

View File

@ -1,6 +1,7 @@
package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -91,9 +92,16 @@ public class UtilText
return locs;
}
public static void MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align)
public static Collection<Block> MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align)
{
return MakeText(string, loc, face, id, data, align, true);
}
public static Collection<Block> MakeText(String string, Location loc, BlockFace face, int id, byte data, TextAlign align, boolean setAir)
{
HashSet<Block> changes = new HashSet<Block>();
if (alphabet.isEmpty())
PopulateAlphabet();
@ -124,40 +132,43 @@ public class UtilText
HashSet<Chunk> chunks = new HashSet<Chunk>();
//Clean
World world = loc.getWorld();
int bX = loc.getBlockX();
int bY = loc.getBlockY();
int bZ = loc.getBlockZ();
for (int y=0 ; y<5 ; y++)
if (setAir)
{
if (align == TextAlign.CENTER)
for (int i=-48 ; i<=48 ; i++)
{
chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
}
World world = loc.getWorld();
int bX = loc.getBlockX();
int bY = loc.getBlockY();
int bZ = loc.getBlockZ();
for (int y=0 ; y<5 ; y++)
{
if (align == TextAlign.CENTER)
for (int i=-48 ; i<=48 ; i++)
{
chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
}
if (align == TextAlign.LEFT)
for (int i=0 ; i<=96 ; i++)
{
chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
}
if (align == TextAlign.LEFT)
for (int i=0 ; i<=96 ; i++)
{
chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
}
if (align == TextAlign.RIGHT)
for (int i=-96 ; i<=0 ; i++)
{
chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
}
if (align == TextAlign.RIGHT)
for (int i=-96 ; i<=0 ; i++)
{
chunks.add(MapUtil.ChunkBlockChange(world, bX + i * face.getModX(), bY + i * face.getModY(), bZ + i * face.getModZ(), 0, (byte)0));
}
bY -=1;
}
world = block.getWorld();
bX = block.getX();
bY = block.getY();
bZ = block.getZ();
bY -=1;
}
}
World world = block.getWorld();
int bX = block.getX();
int bY = block.getY();
int bZ = block.getZ();
//Make Blocks
for (char c : string.toLowerCase().toCharArray())
@ -173,6 +184,7 @@ public class UtilText
{
if (letter[x][y] == 1)
{
changes.add(world.getBlockAt(bX, bY, bZ));
chunks.add(MapUtil.ChunkBlockChange(world, bX, bY, bZ, id, data));
}
@ -203,6 +215,8 @@ public class UtilText
}
MapUtil.ResendChunksForNearbyPlayers(chunks);
return changes;
}
private static void PopulateAlphabet()

View File

@ -14,6 +14,7 @@ import nautilus.game.arcade.game.games.deathtag.DeathTag;
import nautilus.game.arcade.game.games.dragonescape.DragonEscape;
import nautilus.game.arcade.game.games.dragonriders.DragonRiders;
import nautilus.game.arcade.game.games.dragons.Dragons;
import nautilus.game.arcade.game.games.draw.Draw;
import nautilus.game.arcade.game.games.evolution.Evolution;
import nautilus.game.arcade.game.games.halloween.Halloween;
import nautilus.game.arcade.game.games.hideseek.HideSeek;
@ -53,6 +54,7 @@ public class GameFactory
else if (gameType == GameType.Dragons) return new Dragons(_manager);
else if (gameType == GameType.DragonEscape) return new DragonEscape(_manager);
else if (gameType == GameType.DragonRiders) return new DragonRiders(_manager);
else if (gameType == GameType.Draw) return new Draw(_manager);
else if (gameType == GameType.Evolution) return new Evolution(_manager);
else if (gameType == GameType.Halloween) return new Halloween(_manager);
else if (gameType == GameType.HideSeek) return new HideSeek(_manager);

View File

@ -12,6 +12,7 @@ public enum GameType
DragonEscape("Dragon Escape"),
DragonRiders("Dragon Riders"),
Dragons("Dragons"),
Draw("Draw My Thing"),
Evolution("Evolution"),
Halloween("Halloween Horror"),
HideSeek("Block Hunt"),

View File

@ -0,0 +1,15 @@
package nautilus.game.arcade.game.games;
import org.bukkit.entity.Player;
public class GameScore
{
public org.bukkit.entity.Player Player;
public double Score;
public GameScore(Player player, double i)
{
Player = player;
Score = i;
}
}

View File

@ -0,0 +1,667 @@
package nautilus.game.arcade.game.games.draw;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
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.UtilDisplay;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilText.TextAlign;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
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.game.GameTeam;
import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.GameScore;
import nautilus.game.arcade.game.games.draw.kits.KitPlayer;
import nautilus.game.arcade.kit.Kit;
public class Draw extends SoloGame
{
private ArrayList<GameScore> _ranks = new ArrayList<GameScore>();
private ArrayList<String> _lastScoreboard = new ArrayList<String>();
private GameTeam _drawers = null;
private GameTeam _guessers = null;
//Brush
private byte _brushColor = 15;
private Location _brushPrevious = null;
//Round
private int _roundCount = 0;
private int _roundMax = 0;
private ArrayList<Player> _roundPlayer = new ArrayList<Player>();
private long _roundTime = 0;
private DrawRound _round = null;
private ArrayList<Block> _canvas = new ArrayList<Block>();
private Location _drawerLocation = null;
private Location _textLocation = null;
private Collection<Block> _textBlocks = null;
private String[] _words;
public Draw(ArcadeManager manager)
{
super(manager, GameType.Draw,
new Kit[]
{
new KitPlayer(manager),
},
new String[]
{
"Take turns to draw something",
"Right-Click with Swords to draw",
"Hints are given at top of screen",
});
this.Damage = false;
this.HungerSet = 20;
this.WorldTimeSet = 8000;
_words = new String[]
{
"Bird", "Volcano", "Love", "Dance", "Hair", "Glasses", "Domino", "Dice", "Computer", "Top Hat", "Beard", "Wind", "Rain", "Minecraft",
"Push", "Fighting", "Juggle", "Clown", "Miner", "Creeper", "Ghast", "Spider", "Punch", "Roll", "River", "Desert", "Cold", "Pregnant",
"Photo", "Quick", "Mario", "Luigi", "Bridge", "Turtle", "Door Knob", "Mineplex", "Binoculars", "Telescope", "Planet",
"Moon", "Comet", "Flower", "Squirrel", "Horse Riding", "Chef", "Elephant", "Yoshi", "Shotgun", "Pistol", "James Bond",
"Truck", "Helicopter", "Hot Air Balloon", "Sprout", "Yelling", "Muscles", "Skinny", "Zombie", "Lava", "Snake", "Motorbike", "Whale",
"Boat", "Letterbox", "Window", "Lollipop", "Handcuffs", "Police", "Uppercut", "Windmill", "Eyepatch", "Campfire", "Rainbow", "Storm", "Pikachu",
"Charmander", "Tornado", "Crying", "King", "Hobo", "Worm", "Snail", "XBox", "Playstation", "Nintendo", "Duck", "Pull", "Dinosaur", "Alligator",
"Ankle", "Angel", "Acorn", "Bread", "Booty", "Bacon", "Crown", "Donut", "Drill", "Crack", "Leash", "Magic", "Wizard", "Igloo", "Plant", "Screw",
"Rifle", "Puppy", "Stool", "Stamp", "Letter", "Witch", "Zebra", "Wagon", "Compass", "Watch", "Clock", "Time", "Cyclops", "Coconut", "Hang",
"Penguin", "Confused", "Bucket", "Lion", "Rubbish", "Spaceship", "Bowl", "Shark", "Pizza", "Pyramid", "Dress", "Pants", "Shorts", "Boots", "Boy",
"Girl", "Math", "Sunglasses", "Frog", "Chair", "Cake", "Grapes", "Kiss", "Snorlax", "Earth", "Spaghetti", "Murder", "Couch", "Family", "Milk",
"Blood", "Pig", "Giraffe", "Mouse", "Couch", "Fat", "Chocolate", "Camel", "Cheese", "Beans", "Water", "Chicken", "Cannibal", "Zipper",
"Book", "Swimming", "Horse", "Paper", "Toaster", "Television", "Hammer", "Piano", "Sleeping", "Yawn", "Sheep", "Night", "Chest", "Lamp", "Redstone",
"Grass", "Plane", "Ocean", "Lake", "Melon", "Pumpkin", "Gift", "Fishing", "Pirate", "Lightning", "Stomach", "Belly Button", "Fishing Rod",
"Iron Ore", "Diamonds", "Emeralds", "Nether Portal", "Ender Dragon", "Rabbit", "Harry Potter", "Miley Cyrus", "Torch", "Light", "Battery",
};
}
@Override
public void ParseData()
{
for (Location loc : WorldData.GetCustomLocs("159"))
_canvas.add(loc.getBlock());
_drawerLocation = WorldData.GetDataLocs("RED").get(0);
_textLocation = WorldData.GetDataLocs("YELLOW").get(0);
Reset();
}
@Override
@EventHandler
public void CustomTeamGeneration(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Recruit)
return;
_guessers = this.GetTeamList().get(0);
_guessers.SetName("Guessers");
_guessers.SetColor(ChatColor.GREEN);
}
@EventHandler
public void CreateDrawers(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
return;
//Undead Team
_drawers = new GameTeam("Drawer", ChatColor.RED, WorldData.GetDataLocs("RED"));
GetTeamList().add(_drawers);
}
@EventHandler
public void AddDrawers(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
return;
ArrayList<Player> players = GetPlayers(true);
for (int i=0 ; i<2 ; i++)
for (Player player : players)
{
_roundPlayer.add(player);
_roundMax++;
}
}
@EventHandler
public void RemoveDrawer(PlayerQuitEvent event)
{
while (_roundPlayer.contains(event.getPlayer()))
{
_roundPlayer.remove(event.getPlayer());
_roundMax--;
}
Iterator<GameScore> scoreIterator = _ranks.iterator();
while (scoreIterator.hasNext())
{
GameScore score = scoreIterator.next();
if (score.Player.equals(event.getPlayer()))
scoreIterator.remove();
}
}
@EventHandler
public void RoundUpdate(UpdateEvent event)
{
if (!IsLive())
return;
if (event.getType() != UpdateType.FAST)
return;
//End Round
if (_round != null && (_round.IsDone() || _drawers.GetPlayers(true).isEmpty() || _round.AllGuessed(_guessers.GetPlayers(true))))
{
Announce(C.cGold + C.Bold + "Round " + (_roundCount+1) + " Ended: " + C.cYellow + C.Bold + "The word was " + _round.Word + "!");
_textBlocks = UtilText.MakeText(_round.Word, _textLocation, BlockFace.NORTH, 159, (byte)15, TextAlign.CENTER);
_roundTime = System.currentTimeMillis();
_round = null;
//Remove Old Drawers
for (Player player : _drawers.GetPlayers(false))
{
_drawers.RemovePlayer(player);
_guessers.AddPlayer(player);
UtilInv.Clear(player);
player.setAllowFlight(false);
player.setFlying(false);
player.teleport(_guessers.GetSpawn());
}
_roundCount++;
EndCheck();
}
if ((_round == null && UtilTime.elapsed(_roundTime, 5000) && !_roundPlayer.isEmpty()))
{
Reset();
//Select New Drawer
Player drawer = _roundPlayer.remove(0);
_guessers.RemovePlayer(drawer);
_drawers.AddPlayer(drawer);
//Create Round
_round = new DrawRound(this, drawer, _words[UtilMath.r(_words.length)]);
//Prep Drawer
drawer.teleport(_drawerLocation);
drawer.setAllowFlight(true);
drawer.setFlying(true);
drawer.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WOOD_SWORD, (byte)0, 1, "Paint Brush"));
drawer.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.BUCKET, (byte)0, 1, "Paint Bucket"));
drawer.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.TNT, (byte)0, 1, "Clear Canvas"));
Announce(C.cGold + C.Bold + "Round " + (_roundCount+1) + ": " + C.cYellow + C.Bold + drawer.getName() + " is drawing!");
UtilPlayer.message(drawer, C.cWhite + C.Bold + "You must draw: " + C.cGreen + C.Bold + _round.Word);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void Guess(AsyncPlayerChatEvent event)
{
if (!IsLive())
return;
if (_round == null)
return;
Player player = event.getPlayer();
if (event.getMessage().toLowerCase().contains(_round.Word.toLowerCase()))
{
if (_guessers.HasPlayer(player))
{
//First Guess
int score = 1;
if (_round.Guessed.isEmpty())
{
score = 3;
//Points for Drawer
AddScore(_round.Drawer, 2);
this.AddGems(_round.Drawer, 2, "Drawing Word", true);
}
if (_round.Guessed(player))
{
AddScore(player, score);
Announce(C.cYellow + C.Bold + "+" + score + " " + C.cGreen + C.Bold + player.getName() + " has guessed the word!");
if (score == 1)
this.AddGems(player, 1, "Guessing Word", true);
else
this.AddGems(player, 4, "Guessing Word First", true);
}
else
{
UtilPlayer.message(player, F.main("Game", "You have already guessed the word!"));
}
}
event.setCancelled(true);
return;
}
}
@EventHandler
public void TextUpdate(UpdateEvent event)
{
if (!IsLive())
return;
if (event.getType() != UpdateType.TICK)
return;
if (_round == null)
return;
for (Player player : UtilServer.getPlayers())
{
if (_drawers.HasPlayer(player))
{
UtilDisplay.displayTextBar(Manager.GetPlugin(), player, _round.GetTimePercent(), C.cYellow + C.Bold + "Draw " + ChatColor.RESET + C.Bold + _round.Word);
}
else
{
UtilDisplay.displayTextBar(Manager.GetPlugin(), player, _round.GetTimePercent(), C.cYellow + C.Bold + "Guess " + ChatColor.RESET + C.Bold + _round.GetRevealedWord());
}
}
}
@EventHandler
public void DrawerMove(PlayerMoveEvent event)
{
if (!IsLive())
return;
if (!_drawers.HasPlayer(event.getPlayer()))
return;
if (UtilMath.offset(event.getFrom(), event.getTo()) > 0)
{
event.setTo(event.getFrom());
Player player = event.getPlayer();
if (Recharge.Instance.use(player, "Instruct", 1000, false))
{
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 0.5f);
UtilPlayer.message(player, C.cRed + C.Bold + "Block with your Sword to Draw!");
}
}
}
@EventHandler
public void Paint(UpdateEvent event)
{
if (!IsLive())
return;
if (event.getType() != UpdateType.TICK)
return;
for (Player player : _drawers.GetPlayers(true))
{
if (!player.isBlocking())
{
_brushPrevious = null;
continue;
}
Block block = player.getTargetBlock(null, 200);
if (block == null || !_canvas.contains(block))
continue;
if (block.getData() == _brushColor)
continue;
//Color
block.setData(_brushColor);
//Join Dots
if (_brushPrevious != null)
{
while (UtilMath.offset(_brushPrevious, block.getLocation().add(0.5, 0.5, 0.5)) > 0.5)
{
_brushPrevious.add(UtilAlg.getTrajectory(_brushPrevious, block.getLocation().add(0.5, 0.5, 0.5)).multiply(0.5));
Block fixBlock = _brushPrevious.getBlock();
if (!_canvas.contains(fixBlock))
continue;
fixBlock.setData(_brushColor);
}
}
for (Player other : UtilServer.getPlayers())
other.playSound(other.getLocation(), Sound.FIZZ, 0.2f, 2f);
_brushPrevious = block.getLocation().add(0.5, 0.5, 0.5);
}
}
@EventHandler
public void PaintReset(PlayerInteractEvent event)
{
if (!IsLive())
return;
Player player = event.getPlayer();
if (!UtilGear.isMat(player.getItemInHand(), Material.TNT))
return;
if (!_drawers.HasPlayer(player))
return;
if (!Recharge.Instance.use(player, "Clear Canvas", 5000, true))
return;
byte color = _brushColor;
Reset();
_brushColor = color;
for (Player other : UtilServer.getPlayers())
other.playSound(other.getLocation(), Sound.EXPLODE, 0.5f, 1.5f);
}
@EventHandler
public void PaintBucket(PlayerInteractEvent event)
{
if (!IsLive())
return;
Player player = event.getPlayer();
if (!UtilGear.isMat(player.getItemInHand(), Material.BUCKET))
return;
if (!_drawers.HasPlayer(player))
return;
Block block = player.getTargetBlock(null, 200);
if (block == null || !_canvas.contains(block))
return;
//Fill
byte color = block.getData();
if (color == _brushColor)
return;
FillRecurse(block, color);
for (Player other : UtilServer.getPlayers())
other.playSound(other.getLocation(), Sound.SPLASH, 0.4f, 1.5f);
}
public void FillRecurse(Block block, byte color)
{
if (block.getData() != color)
return;
if (!_canvas.contains(block))
return;
block.setData(_brushColor);
for (Block other : UtilBlock.getSurrounding(block, false))
{
FillRecurse(other, color);
}
}
@EventHandler
public void ColorSelect(PlayerInteractEvent event)
{
if (!IsLive())
return;
Player player = event.getPlayer();
if (!_drawers.HasPlayer(player))
return;
Block block = player.getTargetBlock(null, 200);
if (block == null || block.getType() != Material.WOOL || _canvas.contains(block))
return;
_brushColor = block.getData();
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 2f, 1f);
}
private void Reset()
{
for (Block block : _canvas)
{
if (block.getTypeId() != 35 || block.getData() != 0)
block.setTypeIdAndData(35, (byte)0, false);
}
_brushColor = 15;
if (_textBlocks != null)
{
for (Block block : _textBlocks)
block.setType(Material.AIR);
_textBlocks.clear();
_textBlocks = null;
}
}
public void AddScore(Player player, double amount)
{
for (GameScore score : _ranks)
{
if (score.Player.equals(player))
{
score.Score += amount;
EndCheck();
return;
}
}
_ranks.add(new GameScore(player, amount));
}
private void SortScores()
{
for (int i=0 ; i<_ranks.size() ; i++)
{
for (int j=_ranks.size()-1 ; j>0 ; j--)
{
if (_ranks.get(j).Score > _ranks.get(j-1).Score)
{
GameScore temp = _ranks.get(j);
_ranks.set(j, _ranks.get(j-1));
_ranks.set(j-1, temp);
}
}
}
}
@Override
public void EndCheck()
{
if (!IsLive())
return;
if ((_roundCount == _roundMax && UtilTime.elapsed(_roundTime, 5000)) || GetPlayers(true).size() <= 1)
{
SortScores();
//Set Places
_places.clear();
for (int i=0 ; i<_ranks.size() ; i++)
_places.add(i, _ranks.get(i).Player);
//Award Gems
if (_ranks.size() >= 1)
AddGems(_ranks.get(0).Player, 20, "1st Place", false);
if (_ranks.size() >= 2)
AddGems(_ranks.get(1).Player, 15, "2nd Place", false);
if (_ranks.size() >= 3)
AddGems(_ranks.get(2).Player, 10, "3rd Place", false);
//Participation
for (Player player : GetPlayers(false))
if (player.isOnline())
AddGems(player, 10, "Participation", false);
SetState(GameState.End);
AnnounceEnd(_places);
}
}
@Override
@EventHandler
public void ScoreboardUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
//Wipe Last
for (String string : _lastScoreboard)
GetScoreboard().resetScores(Bukkit.getOfflinePlayer(string));
_lastScoreboard.clear();
SortScores();
int index = 15;
//Rounds
String out = C.cRed + " ";
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
out = C.cRed + " ";
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
out = C.cWhite + "Round:";
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
out = C.cYellow + Math.min(_roundCount+1, _roundMax) + " of " + _roundMax;
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
//Drawer
out = C.cRed + " ";
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
out = C.cWhite + "Drawer:";
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
out = C.cYellow + "None";
if (_round != null)
out = C.cYellow + _round.Drawer.getName();
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
out = C.cRed + " ";
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
//Scores
out = C.cWhite + "Scores:";
_lastScoreboard.add(out);
if (out.length() >= 16)
out = out.substring(0, 15);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
//Write New
for (int i=0 ; i<_ranks.size() && index > 0 ; i++)
{
GameScore score = _ranks.get(i);
out = (int)score.Score + " " + C.cYellow + score.Player.getName();
if (out.length() >= 16)
out = out.substring(0, 15);
_lastScoreboard.add(out);
GetObjectiveSide().getScore(Bukkit.getOfflinePlayer(out)).setScore(index--);
}
}
}

View File

@ -0,0 +1,125 @@
package nautilus.game.arcade.game.games.draw;
import java.util.ArrayList;
import java.util.HashSet;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
public class DrawRound
{
public Draw Host;
public Player Drawer;
public String Word;
public int Revealed = 0;
public boolean[] WordReveal;
public long Time;
public double TimeMax = 45;
public HashSet<String> Guessed = new HashSet<String>();
public DrawRound(Draw draw, Player player, String word)
{
Host = draw;
Drawer = player;
Word = word;
Time = System.currentTimeMillis();
WordReveal = new boolean[word.length()];
for (int i=0 ; i< WordReveal.length ; i++)
WordReveal[i] = false;
}
public boolean Guessed(Player player)
{
if (Guessed.add(player.getName()))
{
TimeMax -= 5;
return true;
}
return false;
}
public void UpdateReveal()
{
int required = (int) (((System.currentTimeMillis()-Time)/1000d) / (TimeMax*1.75) * (double)Word.length());
if (Revealed < required)
{
for (int i=0 ; i<50 ; i++)
{
int j = UtilMath.r(WordReveal.length);
if (WordReveal[j] == false && Word.charAt(j) != ' ')
{
WordReveal[j] = true;
Revealed++;
for (Player player : UtilServer.getPlayers())
{
if (Host.GetTeam(ChatColor.RED).HasPlayer(player))
continue;
player.playSound(player.getLocation(), Sound.CHICKEN_EGG_POP, 1.5f, 2f);
}
break;
}
}
}
}
public String GetRevealedWord()
{
String out = "";
for (int i=0 ; i<Word.length() ; i++)
{
if (Word.charAt(i) == ' ')
{
out += " ";
}
else if (WordReveal[i])
{
out += Word.charAt(i) + " ";
}
else
{
out += "_ ";
}
}
if (out.length() > 0)
out = out.substring(0, out.length()-1);
return out;
}
public boolean IsDone()
{
UpdateReveal();
return UtilTime.elapsed(Time, (long)(TimeMax * 1000));
}
public double GetTimePercent()
{
return (TimeMax - (double)(System.currentTimeMillis()-Time)/1000d)/45d;
}
public boolean AllGuessed(ArrayList<Player> players)
{
for (Player player : players)
if (!Guessed.contains(player.getName()))
return false;
return true;
}
}

View File

@ -0,0 +1,36 @@
package nautilus.game.arcade.game.games.draw.kits;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
public class KitPlayer extends Kit
{
public KitPlayer(ArcadeManager manager)
{
super(manager, "Player", KitAvailability.Free,
new String[]
{
""
},
new Perk[]
{
},
EntityType.SKELETON,
null);
}
@Override
public void GiveItems(Player player)
{
}
}