From d1c147b0259e8c2b773822b9dfb7b931debc386b Mon Sep 17 00:00:00 2001 From: Spencer Date: Sun, 31 Dec 2017 20:12:23 -0500 Subject: [PATCH] Add Scavenger Kit to SG --- .../games/survivalgames/kit/KitScavenger.java | 30 +++ .../arcade/kit/perks/PerkItemBreakdown.java | 218 ++++++++++++++++++ 2 files changed, 248 insertions(+) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/kit/KitScavenger.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkItemBreakdown.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/kit/KitScavenger.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/kit/KitScavenger.java new file mode 100644 index 000000000..394547314 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/kit/KitScavenger.java @@ -0,0 +1,30 @@ +package nautilus.game.arcade.game.games.survivalgames.kit; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; +import nautilus.game.arcade.kit.perks.PerkItemBreakdown; + +public class KitScavenger extends SurvivalGamesKit +{ + private static final String[] DESCRIPTION = { + "Break down items for their parts!", + "", + "Left click a crafting table with items", + "to break them down." + }; + + private static final Perk[] PERKS = { + new PerkItemBreakdown() + }; + + private static final ItemStack IN_HAND = new ItemStack(Material.WORKBENCH); + + public KitScavenger(ArcadeManager manager) + { + super(manager, "Scavenger", KitAvailability.Gem, 4000, DESCRIPTION, PERKS, IN_HAND); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkItemBreakdown.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkItemBreakdown.java new file mode 100644 index 000000000..d2f6ebb85 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkItemBreakdown.java @@ -0,0 +1,218 @@ +package nautilus.game.arcade.kit.perks; + +import java.util.Random; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilItem; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.recharge.Recharge; + +import nautilus.game.arcade.kit.Perk; + +public class PerkItemBreakdown extends Perk +{ + private static final Random random = new Random(); + + // 90 seconds + private static final long ABILITY_COOLDOWN = 90000; + + public PerkItemBreakdown() + { + super("Item Breakdown", new String[] { + C.cYellow + "Left Click " + C.mBody + "a crafting table", + "with weapons, armor, and some food", + "to scavenge it for parts!" + }); + } + + @EventHandler + public void onWorkbenchClick(PlayerInteractEvent event) + { + if (event.getPlayer() == null) + { + return; + } + + if (event.getAction() != Action.LEFT_CLICK_BLOCK) + { + return; + } + + if (event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.WORKBENCH) + { + return; + } + + Player player = event.getPlayer(); + + if (!hasPerk(player)) + { + return; + } + + ItemStack item = player.getItemInHand(); + + if (item == null || item.getType() == Material.AIR) + { + return; + } + + int maxReturn; + if (UtilItem.isHelmet(item)) + { + maxReturn = 5; + } + else if (UtilItem.isChestplate(item)) + { + maxReturn = 8; + } + else if (UtilItem.isLeggings(item)) + { + maxReturn = 7; + } + else if (UtilItem.isBoots(item)) + { + maxReturn = 4; + } + else if (UtilItem.isSword(item)) + { + maxReturn = 2; + } + else if (UtilItem.isAxe(item)) + { + maxReturn = 3; + } + else if (item.getType() == Material.BOW) + { + // for the string that makes the bow + maxReturn = 3; + } + else if (item.getType() == Material.FISHING_ROD) + { + maxReturn = 2; + } + else if (item.getType() == Material.RAW_CHICKEN) + { + maxReturn = 2; + } + else if (item.getType() == Material.RAW_BEEF) + { + maxReturn = 2; + } + else + { + if (Recharge.Instance.usable(player, GetName())) + { + player.sendMessage(F.main(GetName(), "You can't break that item down.")); + } + return; + } + + if (!Recharge.Instance.use(player, GetName(), ABILITY_COOLDOWN, true, false)) + { + return; + } + + // Multiply max return by the percent of durability remaining to get the new max return, + // but it can't be less than 1. + // Turns out SG does not have durability, but keep this in case we ever add it. + //maxReturn = Math.min(1, (int) Math.floor(maxReturn * ((item.getType().getMaxDurability() - item.getDurability()) / item.getType().getMaxDurability()))); + + int returnAmount = random.nextInt(maxReturn) + 1; + + Material returnMat; + + if (item.getType() == Material.BOW || item.getType() == Material.FISHING_ROD) + { + returnMat = Material.STRING; + } + else if (UtilItem.isDiamondProduct(item)) + { + returnMat = Material.DIAMOND; + } + else if (UtilItem.isIronProduct(item)) + { + returnMat = Material.IRON_INGOT; + } + else if (UtilItem.isChainmailProduct(item)) + { + returnMat = Material.IRON_INGOT; + returnAmount = Math.floorDiv(returnAmount, 2); + } + else if (UtilItem.isGoldProduct(item)) + { + returnMat = Material.GOLD_INGOT; + } + else if (UtilItem.isStoneProduct(item)) + { + returnMat = Material.FLINT; + } + else if (UtilItem.isLeatherProduct(item)) + { + returnMat = Material.LEATHER; + } + else if (UtilItem.isWoodProduct(item)) + { + returnMat = Material.STICK; + } + else if (item.getType() == Material.RAW_CHICKEN) + { + returnMat = Material.FEATHER; + } + else if (item.getType() == Material.RAW_BEEF) + { + returnMat = Material.LEATHER; + } + else + { + player.sendMessage(F.main(GetName(), "Something went wrong, couldn't break down your item.")); + return; + } + + ItemStack returningItem = new ItemStack(returnMat, Math.max(returnAmount, 1)); + + if (item.getAmount() == 1) + { + player.setItemInHand(new ItemStack(Material.AIR)); + } + else + { + item.setAmount(item.getAmount() - 1); + } + + player.getInventory().addItem(returningItem); + + player.playSound(player.getLocation(), Sound.ANVIL_BREAK, 1F, 1F); + + // "You broke your Diamond Sword into 3 Diamonds!" + player.sendMessage(F.main(GetName(), + "You broke your " + + F.elem(ItemStackFactory.Instance.GetName(item, true)) + + C.mBody + " into " + + F.elem(returnAmount + + " " + + ItemStackFactory.Instance.GetName(returnMat, (byte) 0, true)) + + C.mBody + "!")); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + if (event.getPlayer() == null || event.getBlock() == null) + { + return; + } + + + } +}