diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/BlockInfo.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/BlockInfo.java new file mode 100644 index 000000000..830b5ee0c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/BlockInfo.java @@ -0,0 +1,25 @@ +package nautilus.game.arcade.game.games.draw; + +import org.bukkit.Material; + +public class BlockInfo +{ + private Material _type; + private byte _data; + + public BlockInfo(Material type, byte data) + { + _type = type; + _data = data; + } + + public Material getType() + { + return _type; + } + + public byte getData() + { + return _data; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/Draw.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/Draw.java index 82939c072..c6874b29e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/Draw.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/Draw.java @@ -10,7 +10,6 @@ import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -19,6 +18,7 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -57,7 +57,6 @@ import nautilus.game.arcade.stats.DrawGuessStatTracker; import nautilus.game.arcade.stats.KeenEyeStatTracker; import nautilus.game.arcade.stats.MrSquiggleStatTracker; import nautilus.game.arcade.stats.PureLuckStatTracker; -import sun.misc.REException; public class Draw extends SoloGame { @@ -83,6 +82,7 @@ public class Draw extends SoloGame private ArrayList _canvas = new ArrayList(); private Location _drawerLocation = null; private Location _textLocation = null; + private UndoRedoData _drawerUndoRedo = null; private Collection _textBlocks = null; @@ -366,6 +366,8 @@ public class Draw extends SoloGame //Create Round _round = new DrawRound(this, drawer); + _drawerUndoRedo = new UndoRedoData(this, drawer); + //Prep Drawer drawer.teleport(_drawerLocation); @@ -383,7 +385,9 @@ public class Draw extends SoloGame drawer.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.IRON_HOE, (byte)0, 1, "Paint Bucket")); drawer.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.GOLD_HOE, (byte)0, 1, "Clear Canvas")); - Announce(C.cGold + C.Bold + "Round " + (_roundCount+1) + ": " + C.cYellow + C.Bold + drawer.getName() + " is drawing!"); + drawer.getInventory().setItem(10, ItemStackFactory.Instance.CreateStack(Material.ARROW, (byte)0, 1, "Paint")); + + Announce(C.cGold + C.Bold + "Round " + (_roundCount + 1) + ": " + C.cYellow + C.Bold + drawer.getName() + " is drawing!"); } } @@ -566,6 +570,86 @@ public class Draw extends SoloGame tool.update(); } + @EventHandler + public void sprayCan(UpdateEvent e) + { + if (e.getType() != UpdateType.TICK) + return; + + if (!IsLive()) + return; + + for (Player p : _drawers.GetPlayers(true)) + { + if (!UtilGear.isMat(p.getItemInHand(), Material.BOW)) + continue; + + if (!UtilPlayer.isChargingBow(p)) + { + _brushPrevious = null; + continue; + } + + Block block = p.getTargetBlock((HashSet)null, 200); + if (block == null || !_canvas.contains(block)) + continue; + + // Spray + block.setType(_brushMaterial); + block.setData(_brushColor); + + for (Block surround : UtilBlock.getSurrounding(block, true)) + { + if (!_canvas.contains(surround)) + continue; + + if (Math.random() > 0.1) + { + block.setType(_brushMaterial); + block.setData(_brushColor); + } + } + + for (Player other : UtilServer.getPlayers()) + other.playSound(other.getLocation(), Sound.FIZZ, 0.2f, 2f); + + _lockDrawer = false; + + _brushPrevious = block.getLocation().add(0.5, 0.5, 0.5); + } + } + + @EventHandler + public void undoRedo(PlayerInteractEvent e) + { + if (!IsLive()) + return; + + Player p = e.getPlayer(); + + if (!isDrawer(p)) + return; + + Block block = p.getTargetBlock((HashSet)null, 200); + if (block == null || block.getType() != Material.STAINED_CLAY) + return; + + if (block.getData() == 14) + _drawerUndoRedo.undo(); // Undo + else if (block.getData() == 5) + _drawerUndoRedo.redo(); // Redo + } + + @EventHandler + public void sprayCanArrowCancel(EntityShootBowEvent e) + { + if (e.getEntity() instanceof Player) + { + e.setCancelled(true); + ((Player)e.getEntity()).updateInventory(); + } + } + @EventHandler public void Paint(UpdateEvent event) { @@ -958,10 +1042,8 @@ public class Draw extends SoloGame _lockDrawer = b; } - //fdmsdmfsdfpmsd - /** - * TODO: - * - Spray Can - * - Undo/Redo - */ + public UndoRedoData getDrawerUndoRedo() + { + return _drawerUndoRedo; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/UndoRedoData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/UndoRedoData.java new file mode 100644 index 000000000..99ecbeacd --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/UndoRedoData.java @@ -0,0 +1,99 @@ +package nautilus.game.arcade.game.games.draw; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.recharge.Recharge; + +public class UndoRedoData +{ + private Player _player; + private ArrayList> _steps; + private int _stepIndex; + private Draw _host; + + public UndoRedoData(Draw host, Player player) + { + _player = player; + _steps = new ArrayList<>(); + _stepIndex = 0; + _host = host; + + takeSnapshot(); // Grab current white stage. + } + + public void takeSnapshot() + { + if (_stepIndex > 0) + { + // They have drawn on top of an undo. + // Set this to the current stage and + // remove snapshots in front. + for (int i = 0; i < _stepIndex; i++) + _steps.remove(0); // Remove "current" (old) snapshot. + + _stepIndex = 0; + } + + HashMap snapshot = new HashMap<>(); + + for (Block b : _host.getCanvas()) + snapshot.put(b, new BlockInfo(b.getType(), b.getData())); + + _steps.add(0, snapshot); + } + + public void undo() + { + if (_stepIndex == (_steps.size() - 1)) + { + // No snapshots to go back to. + _player.sendMessage(F.main("Game", C.cRed + "Nothing left to undo!")); + return; + } + + if (!Recharge.Instance.use(_player, "Undo", 5000, true, false)) + return; + + _player.sendMessage(F.main("Game", "You used " + C.mSkill + "Undo" + C.mBody + ".")); + + _stepIndex++; // Move back a snapshot. + resetBlocks(); + } + + public void redo() + { + if (_stepIndex == 0) + { + // No steps to go forward to. + _player.sendMessage(F.main("Game", C.cRed + "Nothing left to redo!")); + return; + } + + if (!Recharge.Instance.use(_player, "Redo", 5000, true, false)) + return; + + _player.sendMessage(F.main("Recharge", "You used " + C.mSkill + "Redo" + C.mBody + ".")); + + _stepIndex--; // Move forward a step. + resetBlocks(); + } + + private void resetBlocks() + { + HashMap step = _steps.get(_stepIndex); + for (Block b : step.keySet()) + { + // Reset blocks. + b.setType(step.get(b).getType()); + b.setData(step.get(b).getData()); + //b.getWorld().getBlockAt(b.getLocation()).setType(step.get(b).getType()); + //b.getWorld().getBlockAt(b.getLocation()).setData(step.get(b).getData()); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/Tool.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/Tool.java index f2c59da59..3dad41646 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/Tool.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/Tool.java @@ -8,6 +8,7 @@ import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilEvent.ActionType; +import nautilus.game.arcade.game.games.draw.BlockInfo; import nautilus.game.arcade.game.games.draw.Draw; import org.bukkit.Material; @@ -18,28 +19,6 @@ import org.bukkit.event.player.PlayerInteractEvent; public abstract class Tool { - public class BlockInfo - { - private Material _type; - private byte _data; - - public BlockInfo(Material type, byte data) - { - _type = type; - _data = data; - } - - public Material getType() - { - return _type; - } - - public byte getData() - { - return _data; - } - } - protected Draw Host; protected Player _drawer; @@ -84,6 +63,8 @@ public abstract class Tool if (!_drawer.isOnline() || !Host.isDrawer(_drawer) || !_drawer.isBlocking()) { + Host.getDrawerUndoRedo().takeSnapshot(); // Save final shape. + _drawer = null; _start = null; _past.clear(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolCircle.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolCircle.java index 820b1d8b7..5d94d33a2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolCircle.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolCircle.java @@ -3,6 +3,7 @@ package nautilus.game.arcade.game.games.draw.tools; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; +import nautilus.game.arcade.game.games.draw.BlockInfo; import nautilus.game.arcade.game.games.draw.Draw; import org.bukkit.Location; @@ -56,7 +57,7 @@ public class ToolCircle extends Tool } _new.put(block, new BlockInfo(type, color)); - block.setData(Host.getColor()); block.setType(Host.getBrushMaterial()); + block.setData(Host.getColor()); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolLine.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolLine.java index 2f69b1912..07517383a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolLine.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolLine.java @@ -2,6 +2,7 @@ package nautilus.game.arcade.game.games.draw.tools; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; +import nautilus.game.arcade.game.games.draw.BlockInfo; import nautilus.game.arcade.game.games.draw.Draw; import org.bukkit.Location; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolSquare.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolSquare.java index fc8fac2be..3fddd22ad 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolSquare.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/draw/tools/ToolSquare.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.draw.tools; +import nautilus.game.arcade.game.games.draw.BlockInfo; import nautilus.game.arcade.game.games.draw.Draw; import org.bukkit.Location; @@ -81,6 +82,7 @@ public class ToolSquare extends Tool } _new.put(block, new BlockInfo(type, color)); + block.setType(Host.getBrushMaterial()); block.setData(Host.getColor()); } }