From ba4ab654b2ddae6493e603a9b42e65aa9e4b88e9 Mon Sep 17 00:00:00 2001 From: aPunch Date: Tue, 21 Feb 2012 18:57:14 -0600 Subject: [PATCH] added setting for dropping item after reforging --- .../apunch/blacksmith/BlacksmithCharacter.java | 17 +++++++++++++---- src/net/apunch/blacksmith/util/Settings.java | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/net/apunch/blacksmith/BlacksmithCharacter.java b/src/net/apunch/blacksmith/BlacksmithCharacter.java index 13299a5..9e0e5e6 100644 --- a/src/net/apunch/blacksmith/BlacksmithCharacter.java +++ b/src/net/apunch/blacksmith/BlacksmithCharacter.java @@ -41,6 +41,7 @@ public class BlacksmithCharacter extends Character { private int maxReforgeDelay = Setting.MAX_REFORGE_DELAY.asInt(); private int reforgeCooldown = Setting.REFORGE_COOLDOWN.asInt(); private int failChance = Setting.FAIL_CHANCE.asInt(); + private boolean dropItem = Setting.DROP_ITEM.asBoolean(); public BlacksmithCharacter() { plugin = (Blacksmith) Bukkit.getServer().getPluginManager().getPlugin("Blacksmith"); @@ -79,6 +80,8 @@ public class BlacksmithCharacter extends Character { reforgeCooldown = key.getInt("delays-in-seconds.reforge-cooldown"); if (key.keyExists("percent-chance-to-fail-reforge")) failChance = key.getInt("percent-chance-to-fail-reforge"); + if (key.keyExists("drop-item")) + dropItem = key.getBoolean("drop-item"); } @Override @@ -140,6 +143,7 @@ public class BlacksmithCharacter extends Character { key.setInt("delays-in-seconds.maximum", maxReforgeDelay); key.setInt("delays-in-seconds.reforge-cooldown", reforgeCooldown); key.setInt("percent-chance-to-fail-reforge", failChance); + key.setBoolean("drop-item", dropItem); } public String getInsufficientFundsMessage() { @@ -171,7 +175,12 @@ public class BlacksmithCharacter extends Character { npc.chat(player, reforgeItemInHand() ? successMsg : failMsg); if (npc.getBukkitEntity() instanceof Player) ((Player) npc.getBukkitEntity()).setItemInHand(null); - player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), reforge); + if (dropItem) + player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), reforge); + else { + for (ItemStack stack : player.getInventory().addItem(reforge).values()) + player.getWorld().dropItemNaturally(npc.getBukkitEntity().getLocation(), stack); + } session = null; // Start cooldown Calendar wait = Calendar.getInstance(); @@ -194,7 +203,7 @@ public class BlacksmithCharacter extends Character { } } // Damage the item - short durability = (short) (reforge.getDurability() + reforge.getDurability() * random.nextInt(5)); + short durability = (short) (reforge.getDurability() + reforge.getDurability() * random.nextInt(8)); short maxDurability = reforge.getType().getMaxDurability(); if (durability <= 0) durability = (short) (maxDurability / 3); @@ -203,9 +212,9 @@ public class BlacksmithCharacter extends Character { reforge.setDurability(durability); return false; } - int chance = 25; + int chance = 10; if (reforge.getDurability() == 0) - chance *= 2; + chance *= 4; else reforge.setDurability((short) 0); // Add random enchantments diff --git a/src/net/apunch/blacksmith/util/Settings.java b/src/net/apunch/blacksmith/util/Settings.java index 1be4bef..b2cf283 100644 --- a/src/net/apunch/blacksmith/util/Settings.java +++ b/src/net/apunch/blacksmith/util/Settings.java @@ -39,6 +39,7 @@ public class Settings { BUSY_WITH_REFORGE_MESSAGE("defaults.messages.busy-with-reforge", "I'm working on it. Be patient!"), COOLDOWN_UNEXPIRED_MESSAGE("defaults.messages.cooldown-not-expired", "You've already had your chance! Give me a break!"), COST_MESSAGE("defaults.messages.cost", "It will cost to reforge that ! Click again to reforge!"), + DROP_ITEM("defaults.drop-item", true), ENCHANTMENT_MODIFIER("enchantment-modifiers.default", 5), FAIL_CHANCE("defaults.percent-chance-to-fail-reforge", 10), FAIL_MESSAGE("defaults.messages.fail-reforge", "Whoops! Didn't mean to do that! Maybe next time?"),