Bonuses code added, but nonfunctional.
This commit is contained in:
parent
0c167081e1
commit
a79767fdff
@ -18,6 +18,8 @@ import net.milkbowl.vault.economy.Economy;
|
|||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
//import net.minecraft.server.v1_4_R1.EntityWolf;
|
//import net.minecraft.server.v1_4_R1.EntityWolf;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -13082,16 +13084,54 @@ class updateInventoryTask implements Runnable {
|
|||||||
Map<Enchantment, Integer> itemEnchantments = anvilInv.getItem(INPUT).getEnchantments();
|
Map<Enchantment, Integer> itemEnchantments = anvilInv.getItem(INPUT).getEnchantments();
|
||||||
Map<Enchantment, Integer> bookEnchantments = new java.util.HashMap<Enchantment, Integer>();
|
Map<Enchantment, Integer> bookEnchantments = new java.util.HashMap<Enchantment, Integer>();
|
||||||
|
|
||||||
|
// Get enchanted book "enchantment" and enchantments.
|
||||||
bookEnchantments.putAll(anvilInv.getItem(MAGIC).getEnchantments());
|
bookEnchantments.putAll(anvilInv.getItem(MAGIC).getEnchantments());
|
||||||
Bukkit.getLogger().info("Size: " + bookEnchantments.size());
|
|
||||||
bookEnchantments.putAll(((EnchantmentStorageMeta)(anvilInv.getItem(MAGIC).getItemMeta())).getStoredEnchants());
|
bookEnchantments.putAll(((EnchantmentStorageMeta)(anvilInv.getItem(MAGIC).getItemMeta())).getStoredEnchants());
|
||||||
Bukkit.getLogger().info("Size After: " + bookEnchantments.size());
|
|
||||||
|
|
||||||
|
// Get the list of bonuses from both items.
|
||||||
|
Map<String, Double> itemBonuses = new java.util.HashMap<String, Double>();
|
||||||
|
Map<String, Double> bookBonuses = new java.util.HashMap<String, Double>();
|
||||||
|
|
||||||
|
if (anvilInv.getItem(INPUT).getItemMeta().hasLore()) {
|
||||||
|
for (int i = 0; i < anvilInv.getItem(INPUT).getItemMeta().getLore().size(); i++) {
|
||||||
|
// Put enchantments together for the input. Also stacks identical enchantments.
|
||||||
|
Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(INPUT).getItemMeta().getLore().get(i));
|
||||||
|
|
||||||
|
if (getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)) != null) {
|
||||||
|
if (itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) == null) {
|
||||||
|
|
||||||
|
Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
|
||||||
|
itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Bukkit.getLogger().info("Stacking bonus: " + itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
|
||||||
|
itemBonuses.put(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)), itemBonuses.get(getEnchantmentName(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i))) + getEnchantmentNumb(anvilInv.getItem(INPUT).getItemMeta().getLore().get(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (anvilInv.getItem(MAGIC).getItemMeta().hasLore()) {
|
||||||
|
for (int i = 0; i < anvilInv.getItem(MAGIC).getItemMeta().getLore().size(); i++) {
|
||||||
|
// Put enchantments together for the MAGIC. Also stacks identical enchantments.
|
||||||
|
Bukkit.getLogger().info("Iterating bonus: " + anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i));
|
||||||
|
if (bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) == null) {
|
||||||
|
|
||||||
|
Bukkit.getLogger().info("New bonus: " + getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
|
||||||
|
bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Bukkit.getLogger().info("Stacking bonus: " + bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + " + " + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
|
||||||
|
bookBonuses.put(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)), bookBonuses.get(getEnchantmentName(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i))) + getEnchantmentNumb(anvilInv.getItem(MAGIC).getItemMeta().getLore().get(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate appropriate possible enchantments
|
||||||
Map<Enchantment, Integer> probableEnchantments = new java.util.HashMap<Enchantment, Integer>();
|
Map<Enchantment, Integer> probableEnchantments = new java.util.HashMap<Enchantment, Integer>();
|
||||||
|
|
||||||
for (Enchantment e : bookEnchantments.keySet()) {
|
for (Enchantment e : bookEnchantments.keySet()) {
|
||||||
Bukkit.getLogger().info("Iterating enchantment: " + e);
|
Bukkit.getLogger().info("Iterating enchantment: " + e);
|
||||||
Bukkit.getLogger().info("Item get: " + itemEnchantments.get(e));
|
|
||||||
|
|
||||||
if (itemEnchantments.get(e) == null || bookEnchantments.get(e) > itemEnchantments.get(e)) {
|
if (itemEnchantments.get(e) == null || bookEnchantments.get(e) > itemEnchantments.get(e)) {
|
||||||
// Book enchantment is larger in magnitude. Assign it as a possible outcome.
|
// Book enchantment is larger in magnitude. Assign it as a possible outcome.
|
||||||
@ -13102,9 +13142,25 @@ class updateInventoryTask implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (probableEnchantments.size() == 0) {
|
// Generate appropriate possible bonuses
|
||||||
|
Map<String, Double> probableBonuses = new java.util.HashMap<String, Double>();
|
||||||
|
|
||||||
|
for (String e : bookBonuses.keySet()) {
|
||||||
|
Bukkit.getLogger().info("Iterating bonus: " + e);
|
||||||
|
|
||||||
|
if (itemBonuses.get(e) == null || bookBonuses.get(e) > itemBonuses.get(e)) {
|
||||||
|
// Book enchantment is larger in magnitude. Assign it as a possible outcome.
|
||||||
|
probableBonuses.put(e, bookBonuses.get(e));
|
||||||
|
} else if (bookBonuses.get(e) == itemBonuses.get(e)) {
|
||||||
|
// Book enchantment is same in magnitude. Upgrade by half.
|
||||||
|
probableBonuses.put(e, Math.floor(bookBonuses.get(e) * 1.5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (probableEnchantments.size() == 0 && probableBonuses.size() == 0) {
|
||||||
// No possible valid enchantments. Output nothing
|
// No possible valid enchantments. Output nothing
|
||||||
} else {
|
} else {
|
||||||
|
if (probableEnchantments.size() != 0) {
|
||||||
// Randomly select an enchantment to add.
|
// Randomly select an enchantment to add.
|
||||||
int random = (int)(Math.random() * probableEnchantments.size());
|
int random = (int)(Math.random() * probableEnchantments.size());
|
||||||
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size());
|
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableEnchantments.size());
|
||||||
@ -13191,7 +13247,185 @@ class updateInventoryTask implements Runnable {
|
|||||||
anvilInv.getItem(OUTPUT).removeEnchantment(appliedEnchant);
|
anvilInv.getItem(OUTPUT).removeEnchantment(appliedEnchant);
|
||||||
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
|
anvilInv.getItem(OUTPUT).addUnsafeEnchantment(appliedEnchant, magnitude);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Can't add enchant, but can add bonus. Prepare output for bonus.
|
||||||
|
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (probableBonuses.size() != 0) {
|
||||||
|
// Randomly select a bonus to add.
|
||||||
|
int random = (int)(Math.random() * probableBonuses.size());
|
||||||
|
Bukkit.getLogger().info("Randomized to # " + (random + 1) + " out of " + probableBonuses.size());
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
String appliedEnchant = null;
|
||||||
|
double magnitude = 0;
|
||||||
|
for (String e : probableBonuses.keySet()) {
|
||||||
|
|
||||||
|
if (i == random) {
|
||||||
|
// Rolled this one
|
||||||
|
appliedEnchant = e;
|
||||||
|
magnitude = probableBonuses.get(e);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cost = 0;
|
||||||
|
|
||||||
|
if (itemBonuses.get(appliedEnchant) == null) {
|
||||||
|
// This bonus doesn't exist. Calculate full cost.
|
||||||
|
|
||||||
|
cost = 30;
|
||||||
|
|
||||||
|
ItemStack orbs = new ItemStack(Material.SLIME_BALL);
|
||||||
|
|
||||||
|
ItemMeta temp_meta = orbs.getItemMeta();
|
||||||
|
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
|
||||||
|
List<String> temp_meta_lore = new ArrayList<String>();
|
||||||
|
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
|
||||||
|
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
|
||||||
|
|
||||||
|
if (cost > player.getLevel()) {
|
||||||
|
orbs.setType(Material.MAGMA_CREAM);
|
||||||
|
temp_meta_lore.add("");
|
||||||
|
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
|
||||||
|
} else {
|
||||||
|
temp_meta_lore.add("");
|
||||||
|
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
|
||||||
|
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_meta.setLore(temp_meta_lore);
|
||||||
|
orbs.setItemMeta(temp_meta);
|
||||||
|
|
||||||
|
orbs.setAmount(cost);
|
||||||
|
anvilInv.setItem(LEVELS, orbs);
|
||||||
|
|
||||||
|
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
||||||
|
|
||||||
|
// Change entry matching modified lore
|
||||||
|
List<String> bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore();
|
||||||
|
|
||||||
|
for (int i1 = 0; i1 < bonusesLore.size(); i1++) {
|
||||||
|
String e = bonusesLore.get(i1);
|
||||||
|
|
||||||
|
if (containsEnchantment(e, appliedEnchant)) {
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Critical Chance")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Health")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Durability")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Block Chance")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// This enchantment exists. Calculate incremental cost.
|
||||||
|
|
||||||
|
cost = (int)(30 * itemBonuses.get(appliedEnchant) / probableBonuses.get(appliedEnchant)); // Make sure it's at least one level
|
||||||
|
|
||||||
|
ItemStack orbs = new ItemStack(Material.SLIME_BALL);
|
||||||
|
|
||||||
|
ItemMeta temp_meta = orbs.getItemMeta();
|
||||||
|
temp_meta.setDisplayName(ChatColor.YELLOW + "Experience Cost");
|
||||||
|
List<String> temp_meta_lore = new ArrayList<String>();
|
||||||
|
temp_meta_lore.add(ChatColor.ITALIC + "This operation costs " + cost + " levels.");
|
||||||
|
temp_meta_lore.add(ChatColor.ITALIC + "You currently have " + player.getLevel() + " levels.");
|
||||||
|
|
||||||
|
if (cost > player.getLevel()) {
|
||||||
|
orbs.setType(Material.MAGMA_CREAM);
|
||||||
|
temp_meta_lore.add("");
|
||||||
|
temp_meta_lore.add(ChatColor.RED + "You can't afford this!");
|
||||||
|
} else {
|
||||||
|
temp_meta_lore.add("");
|
||||||
|
temp_meta_lore.add(ChatColor.GREEN + "Completing the operation will");
|
||||||
|
temp_meta_lore.add(ChatColor.GREEN + "bring you to " + (player.getLevel() - cost) + " levels.");
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_meta.setLore(temp_meta_lore);
|
||||||
|
orbs.setItemMeta(temp_meta);
|
||||||
|
|
||||||
|
orbs.setAmount(cost);
|
||||||
|
anvilInv.setItem(LEVELS, orbs);
|
||||||
|
|
||||||
|
anvilInv.setItem(OUTPUT, anvilInv.getItem(INPUT).clone());
|
||||||
|
|
||||||
|
// Change entry matching modified lore
|
||||||
|
List<String> bonusesLore = anvilInv.getItem(OUTPUT).getItemMeta().getLore();
|
||||||
|
|
||||||
|
for (int i1 = 0; i1 < bonusesLore.size(); i1++) {
|
||||||
|
String e = bonusesLore.get(i1);
|
||||||
|
|
||||||
|
if (containsEnchantment(e, appliedEnchant)) {
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Critical Chance")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Critical Chance");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Armor Penetration")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Armor Penetration");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Life Steal")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Life Steal");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Attack Speed")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Attack Speed");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Damage");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Health")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+" "+ChatColor.BLUE+"Health");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Damage Reduction")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Damage Reduction");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Durability")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Durability");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Block Chance")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Block Chance");
|
||||||
|
}
|
||||||
|
if (appliedEnchant.equalsIgnoreCase("Speed Boost Chance")) {
|
||||||
|
bonusesLore.set(i1, ChatColor.YELLOW+"+"+magnitude+"% "+ChatColor.BLUE+"Speed Boost Chance");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
anvilInv.getItem(OUTPUT).getItemMeta().setLore(bonusesLore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// TRY EVERYTHING
|
||||||
|
player.getInventory().setContents(player.getInventory().getContents());
|
||||||
|
anvilInv.setContents(anvilInv.getContents());
|
||||||
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13231,4 +13465,35 @@ class updateInventoryTask implements Runnable {
|
|||||||
// player.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(anvilInv.getItem(MATERIALS).getType(), anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded));
|
// player.getWorld().dropItemNaturally(player.getLocation(), new ItemStack(anvilInv.getItem(MATERIALS).getType(), anvilInv.getItem(MATERIALS).getAmount() - maxItemsNeeded));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getEnchantmentNumb(String s) {
|
||||||
|
//Parse the string for spaces.
|
||||||
|
String[] enchant = s.split(" ");
|
||||||
|
if (enchant[0].contains(ChatColor.YELLOW+"")) {
|
||||||
|
String newstring = ((enchant[0].replace(ChatColor.YELLOW.getChar(), ' ')).replace('%', ' ')).replace(Character.toString((char)0x00A7), Character.toString((char)0x0020));
|
||||||
|
//Bukkit.getLogger().info("Enchant number is "+Double.valueOf(newstring));
|
||||||
|
return Double.valueOf(newstring);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnchantmentName(String s) {
|
||||||
|
//Parse the string for spaces.
|
||||||
|
String[] enchant = s.split(ChatColor.BLUE+"");
|
||||||
|
if (enchant.length > 1) {
|
||||||
|
return enchant[1];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean containsEnchantment(String s, String enchant) {
|
||||||
|
if (s.contains(enchant)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user