From 71f42c6e7b28329256521bb1906a4efce4b5feb1 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Fri, 12 Sep 2014 23:15:53 -0500 Subject: [PATCH] Treasure updates --- .../src/mineplex/core/treasure/Treasure.java | 23 +++++------ .../core/treasure/TreasureManager.java | 38 +++++++++++++++---- .../animation/FireworksAnimation.java | 6 +-- .../core/treasure/reward/RewardManager.java | 15 +++++++- .../core/treasure/reward/RewardRarity.java | 18 ++++++++- .../treasure/reward/rewards/CoinReward.java | 2 +- .../treasure/reward/rewards/GadgetReward.java | 2 +- .../reward/rewards/InventoryReward.java | 2 +- .../reward/rewards/UnknownPackageReward.java | 2 +- .../mineplex/hub/modules/ParkourManager.java | 14 ++++++- 10 files changed, 91 insertions(+), 31 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index b93141a55..ad466aba5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -67,7 +67,7 @@ public class Treasure _chestData[2] = new ChestData(_centerBlock.getRelative(0, 1, 2), rewards[2]); _chestData[3] = new ChestData(_centerBlock.getRelative(0, 1, -2), rewards[3]); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " is opening treasure at " + F.elem(_centerBlock.getX() + ", " + _centerBlock.getZ()) + "!")); + Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " is opening a Treasure Chest")); } private void createCenterClay() @@ -130,19 +130,18 @@ public class Treasure } } + public int getFinishedTickCount() + { + return _finishedTickCount; + } + public void update() { if (_finished) { - if (_finishedTickCount >= 100) - { - finish(); - } - _finishedTickCount++; } - if (_tickCount == 5) { Block block = _centerBlock; @@ -276,6 +275,11 @@ public class Treasure return null; } + public Player getPlayer() + { + return _player; + } + public boolean isFinished() { boolean allOpened = true; @@ -288,7 +292,7 @@ public class Treasure return allOpened; } - public void finish() + public void cleanup() { for (ChestData chestData : _chestData) { @@ -317,9 +321,6 @@ public class Treasure animation.finish(); } _animations.clear(); - - TreasureFinishEvent event = new TreasureFinishEvent(_player, this); - Bukkit.getPluginManager().callEvent(event); } public TreasureStyle getStyle() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index d4e3e2921..fe53cbde4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -1,5 +1,7 @@ package mineplex.core.treasure; +import java.util.Iterator; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -20,6 +22,7 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; @@ -119,13 +122,13 @@ public class TreasureManager extends MiniPlugin { for (Treasure treasure : _playerTreasureMap.values()) { - treasure.finish(); + treasure.cleanup(); } } public void attemptOpenTreasure(Player player) { - if (!checkNearbyBlocks(player) || checkNearSpawn(player)) + if (!checkNearbyBlocks(player) || checkNearSpawn(player) || checkInAir(player)) return; TreasureStartEvent event = new TreasureStartEvent(player); @@ -133,7 +136,6 @@ public class TreasureManager extends MiniPlugin if (event.isCancelled()) { - player.sendMessage(F.main("Treasure", "Failed to create a treasure. Unknown reason")); return; } @@ -163,7 +165,7 @@ public class TreasureManager extends MiniPlugin Block block = centerBlock.getRelative(x, y, z); if (UtilBlock.solid(block)) { - UtilPlayer.message(player, F.main("Treasure", "You can not open a treasure at this spot. Please find an open location")); + UtilPlayer.message(player, F.main("Treasure", "You can't open chests here.")); return false; } } @@ -172,12 +174,22 @@ public class TreasureManager extends MiniPlugin return true; } + private boolean checkInAir(Player player) + { + boolean grounded = UtilEnt.isGrounded(player); + + if (!grounded) + UtilPlayer.message(player, F.main("Treasure", "You can't open chests while in the air.")); + + return !grounded; + } + private boolean checkNearSpawn(Player player) { boolean nearSpawn = UtilMath.offset2d(new Location(player.getWorld(), 0, 0, 0), player.getLocation()) < 10; if (nearSpawn) - UtilPlayer.message(player, F.main("Treasure", "You are too close to the spawn to open a treasure chest!")); + UtilPlayer.message(player, F.main("Treasure", "You can't open chests near spawn.")); return nearSpawn; } @@ -188,9 +200,21 @@ public class TreasureManager extends MiniPlugin if (event.getType() != UpdateType.TICK) return; - for (Treasure treasure : _playerTreasureMap.values()) + Iterator iterator = _playerTreasureMap.values().iterator(); + while(iterator.hasNext()) { + Treasure treasure = iterator.next(); + treasure.update(); + + if (treasure.isFinished() && treasure.getFinishedTickCount() >= 100) + { + treasure.cleanup(); + iterator.remove(); + + TreasureFinishEvent finishEvent = new TreasureFinishEvent(treasure.getPlayer(), treasure); + Bukkit.getPluginManager().callEvent(finishEvent); + } } } @@ -200,7 +224,7 @@ public class TreasureManager extends MiniPlugin if (_playerTreasureMap.containsKey(event.getPlayer())) { Treasure treasure = _playerTreasureMap.remove(event.getPlayer()); - treasure.finish(); + treasure.cleanup(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/FireworksAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/FireworksAnimation.java index bc5c58b67..b3e80a9c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/FireworksAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/FireworksAnimation.java @@ -41,13 +41,13 @@ public class FireworksAnimation extends Animation @Override protected void tick() { - if (getTicks() >= 20 * 3) + if (getTicks() >= 20) finish(); if (getTicks() % 10 == 0) { - double xDif = _random.nextGaussian() * 2; - double zDif = _random.nextGaussian() * 2; + double xDif = _random.nextGaussian() * 1; + double zDif = _random.nextGaussian() * 1; double yDif = (_random.nextInt(3) * _random.nextDouble()) + 2; FireworkEffect effect = FireworkEffect.builder().withColor(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255))) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardManager.java index cee10b136..0d45eb07f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardManager.java @@ -39,15 +39,21 @@ public class RewardManager { int currentReward = 0; ITreasureReward[] rewards = new ITreasureReward[4]; + boolean hasUncommon = false; while (currentReward < 4) { - ITreasureReward reward = nextReward(player, rewards); + ITreasureReward reward = nextReward(player, rewards, currentReward == 3 && !hasUncommon); + if (reward == null) { continue; } + if (reward.getRarity().ordinal() >= RewardRarity.UNCOMMON.ordinal()) + { + hasUncommon = true; + } rewards[currentReward] = reward; currentReward++; } @@ -56,6 +62,11 @@ public class RewardManager } private ITreasureReward nextReward(Player player, ITreasureReward[] excludedRewards) + { + return nextReward(player, excludedRewards, false); + } + + private ITreasureReward nextReward(Player player, ITreasureReward[] excludedRewards, boolean requiresUncommon) { double rand = _random.nextDouble(); RewardRarity rarity; @@ -70,7 +81,7 @@ public class RewardManager // 4% rarity = RewardRarity.RARE; } - else if (rand <= 0.30) + else if (rand <= 0.30 || requiresUncommon) { // 25% rarity = RewardRarity.UNCOMMON; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardRarity.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardRarity.java index b7d809415..c36222979 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardRarity.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/RewardRarity.java @@ -1,17 +1,31 @@ package mineplex.core.treasure.reward; +import mineplex.core.common.util.C; +import static mineplex.core.common.util.C.*; + /** * Created by Shaun on 9/2/2014. */ public enum RewardRarity { - /** * This will probably be used to figure out what effects are shown when the chest is opened * * (Fireworks, sounds, etc) */ - COMMON, UNCOMMON, RARE, VERY_RARE; + COMMON(cAqua), UNCOMMON(cGreen), RARE(cGold), VERY_RARE(cRed); + + private String _color; + + RewardRarity(String color) + { + _color = color; + } + + public String getColor() + { + return _color; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java index 573062197..52e061baa 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java @@ -54,7 +54,7 @@ public class CoinReward extends AbstractReward } }, "Treasure Chest", player.getName(), gemsToReward); - return C.cYellow + gemsToReward + " Coins"; + return getRarity().getColor() + gemsToReward + " Coins"; } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/GadgetReward.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/GadgetReward.java index 1eeca296a..304891611 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/GadgetReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/GadgetReward.java @@ -27,7 +27,7 @@ public class GadgetReward extends AbstractReward { _donationManager.Get(player.getName()).AddUnknownSalesPackagesOwned(_gadget.GetName()); - return _gadget.GetDisplayName(); + return getRarity().getColor() + _gadget.GetDisplayName(); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/InventoryReward.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/InventoryReward.java index c7f5d36ae..6ea8c7be5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/InventoryReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/InventoryReward.java @@ -47,7 +47,7 @@ public class InventoryReward extends AbstractReward _inventoryManager.addItemToInventory(player, "Item", _packageName, amountToGive); - return C.cAqua + amountToGive + " " + _name; + return getRarity().getColor() + amountToGive + " " + _name; } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java index 01a707bb5..0968e71d0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java @@ -29,7 +29,7 @@ public class UnknownPackageReward extends AbstractReward { _donationManager.Get(player.getName()).AddUnknownSalesPackagesOwned(_packageName); - return _name; + return getRarity().getColor() + _name; } @Override diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java index 321f0381f..1df2344d0 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java @@ -39,6 +39,7 @@ import mineplex.core.gadget.event.GadgetBlockEvent; import mineplex.core.mount.event.MountActivateEvent; import mineplex.core.recharge.Recharge; import mineplex.core.task.TaskManager; +import mineplex.core.treasure.event.TreasureStartEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.hub.HubManager; @@ -356,7 +357,7 @@ public class ParkourManager extends MiniPlugin if (!isParkourMode(player)) { //Inform - UtilPlayer.message(player, F.main("Parkour", "You must be in " + F.elem("Parkour Mode") + " to finish.")); + UtilPlayer.message(player, F.main("Parkour", "You must be in " + F.elem("Parkour Mode") + " to cleanup.")); UtilPlayer.message(player, F.main("Parkour", "Talk to the " + F.elem("Start NPC") + " to enter Parkour Mode.")); return; } @@ -418,7 +419,16 @@ public class ParkourManager extends MiniPlugin return false; } - + + @EventHandler + public void preventTreasureNearParkour(TreasureStartEvent event) + { + if (InsideParkour(event.getPlayer().getLocation())) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main("Parkour", "You can't open chests near Parkour.")); + } + } @EventHandler public void snakeUpdate(UpdateEvent event)