From 5fbbae1493298bb8b2464a38362f4a4a441aa79e Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Feb 2017 18:55:38 +0000 Subject: [PATCH] The SamitoD quest --- .../gemhunters/quest/QuestModule.java | 17 +++- .../quest/types/ChestOpenerQuest.java | 3 - .../gemhunters/quest/types/Quest.java | 9 ++- .../gemhunters/quest/types/SamitoDQuest.java | 80 +++++++++++++++++++ .../mineplex/gemhunters/world/SewerMobs.java | 12 ++- 5 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index 433f7d3f2..72ae6680c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -23,10 +23,12 @@ import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.menu.Menu; +import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.quest.types.ChestOpenerQuest; import mineplex.gemhunters.quest.types.Quest; +import mineplex.gemhunters.quest.types.SamitoDQuest; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -36,7 +38,13 @@ public class QuestModule extends MiniClientPlugin private static final int MAX_QUESTS = 5; private static final long RESET_QUESTS_TIME = TimeUnit.MINUTES.toMillis(15); - private final Quest[] _quests = { new ChestOpenerQuest(0, "Chest Opener", 100, 250, 5), new ChestOpenerQuest(1, "Grand Chest Opener", 200, 500, 20), new ChestOpenerQuest(2, "Superior Chest Opener", 500, 750, 40) }; + private final Quest[] _quests = { + new ChestOpenerQuest(0, "Chest Opener", 100, 250, 5), + new ChestOpenerQuest(1, "Grand Chest Opener", 200, 500, 20), + new ChestOpenerQuest(2, "Superior Chest Opener", 500, 750, 40), + + new SamitoDQuest(3, "Give to the Homeless", "Donate " + F.count(String.valueOf(10)) + " gems to the Hobo.", 100, 300, 10) + }; private final WorldDataModule _worldData; @@ -95,7 +103,7 @@ public class QuestModule extends MiniClientPlugin } public void updateQuests(Player player) - { + { QuestPlayerData playerData = Get(player); List quests = playerData.getPossibleQuests(); @@ -211,6 +219,11 @@ public class QuestModule extends MiniClientPlugin public void updateQuestItem(Quest quest, Player player) { + if (!Recharge.Instance.use(player, "Quest Update Item", 1000, false, false)) + { + return; + } + ItemStack itemStack = getItemStack(quest, player, false, true); for (ItemStack items : player.getInventory().getContents()) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java index 8a8514b80..3ab14a3b1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java @@ -39,13 +39,10 @@ public class ChestOpenerQuest extends Quest if (!isActive(player)) { - DebugModule.getInstance().d("Not active."); return; } int amount = getAndIncrement(player, 1); - - DebugModule.getInstance().d("amount = " + amount); if (amount >= _goal) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java index 47a56ae0c..96d50c705 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java @@ -16,6 +16,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.quest.QuestModule; +import mineplex.gemhunters.world.WorldDataModule; public abstract class Quest implements Listener { @@ -30,6 +31,7 @@ public abstract class Quest implements Listener protected final CoreClientManager _clientManager; protected final DonationManager _donation; protected final EconomyModule _economy; + protected final WorldDataModule _worldData; private final Map _counter; @@ -45,7 +47,8 @@ public abstract class Quest implements Listener _clientManager = Managers.require(CoreClientManager.class); _donation = Managers.require(DonationManager.class); _economy = Managers.require(EconomyModule.class); - + _worldData = Managers.require(WorldDataModule.class); + _counter = new HashMap<>(); UtilServer.getServer().getPluginManager().registerEvents(this, UtilServer.getPlugin()); @@ -71,9 +74,9 @@ public abstract class Quest implements Listener return newAmount; } - public int remove(Player player) + public void remove(Player player) { - return _counter.remove(player.getUniqueId()); + _counter.remove(player.getUniqueId()); } public void onStart(Player player) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java new file mode 100644 index 000000000..215defd3c --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java @@ -0,0 +1,80 @@ +package mineplex.gemhunters.quest.types; + +import org.bukkit.FireworkEffect.Type; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilMath; +import mineplex.gemhunters.debug.DebugModule; + +public class SamitoDQuest extends Quest +{ + + private static final String NPC_NAME = "Hobo"; + private static final String[] REACTIONS = { + "Well hello there folks and welcome... to... my... youtube channel", + "WILLIAMMMMMMM", + "ALEXXXXXXXXXX", + }; + + private final Location _pot; + private final int _gemsToDonate; + + public SamitoDQuest(int id, String name, String description, int startCost, int completeReward, int gemsToDonate) + { + super(id, name, description, startCost, completeReward); + + _pot = _worldData.getCustomLocation("QUEST_SAM").get(0); + _pot.getBlock().setType(Material.FLOWER_POT); + + _gemsToDonate = gemsToDonate; + } + + @Override + public float getProgress(Player player) + { + return 0; + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + Player player = event.getPlayer(); + + if (event.isCancelled() || !isActive(player)) + { + return; + } + + DebugModule.getInstance().d(event.getEventName()); + + Block block = event.getClickedBlock(); + + if (block == null) + { + return; + } + + if (UtilMath.offsetSquared(block.getLocation(), _pot) < 4) + { + if (_economy.getGems(player) < _gemsToDonate) + { + player.sendMessage(F.main(NPC_NAME, "Awww come on man, even alex has more gems than you.")); + return; + } + + player.sendMessage(F.main(NPC_NAME, REACTIONS[UtilMath.random.nextInt(REACTIONS.length)])); + _economy.removeFromStore(player, _gemsToDonate); + UtilFirework.playFirework(_pot, Type.BURST, Color.GREEN, true, false); + onReward(player); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java index b9e363f43..f26fb895c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java @@ -1,7 +1,6 @@ package mineplex.gemhunters.world; import java.util.HashSet; -import java.util.Random; import java.util.Set; import org.bukkit.Bukkit; @@ -16,7 +15,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilMath; import mineplex.core.updater.UpdateType; @@ -55,8 +53,14 @@ public class SewerMobs implements Listener } EntityType type = UtilMath.random.nextBoolean() ? EntityType.ZOMBIE : EntityType.SKELETON; + Location location = getRandomLocation(world); - _entities.add(world.spawnEntity(getRandomLocation(world), type)); + if (location == null) + { + continue; + } + + _entities.add(world.spawnEntity(location, type)); } } @@ -66,7 +70,7 @@ public class SewerMobs implements Listener while (attempts < 40) { - Location location = new Location(world, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS, 46, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS); + Location location = new Location(world, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS, 51, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS); if (!isSuitable(location.getBlock())) {