diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index 378144a..470bcad 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/sig/plugin/TwosideKeeper/CustomDamage.java b/src/sig/plugin/TwosideKeeper/CustomDamage.java index 64854fa..c5b1067 100644 --- a/src/sig/plugin/TwosideKeeper/CustomDamage.java +++ b/src/sig/plugin/TwosideKeeper/CustomDamage.java @@ -42,6 +42,7 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import org.bukkit.util.Vector; +import aPlugin.API; import sig.plugin.TwosideKeeper.Events.EntityDamagedEvent; import sig.plugin.TwosideKeeper.Events.PlayerDodgeEvent; import sig.plugin.TwosideKeeper.HelperStructures.ArtifactAbility; @@ -126,6 +127,7 @@ public class CustomDamage { } else { dmg = CalculateDamage(damage, damager, target, weapon, reason, flags); } + dmg += CalculateBonusTrueDamage(damager); if (damager!=null) { TwosideKeeper.logHealth(target,target.getHealth(),dmg,damager); } @@ -144,6 +146,17 @@ public class CustomDamage { } } + private static double CalculateBonusTrueDamage(Entity damager) { + if (getDamagerEntity(damager) instanceof Player) { + double bonus_truedmg = 0; + Player p = (Player)getDamagerEntity(damager); + bonus_truedmg += API.getPlayerBonuses(p).getBonusTrueDamage(); + return bonus_truedmg; + } else { + return 0.0; + } + } + public static double CalculateDamage(double damage, Entity damager, LivingEntity target, ItemStack weapon, String reason) { return CalculateDamage(damage,damager,target,weapon,reason,0); @@ -201,10 +214,12 @@ public class CustomDamage { } dmg += addToPlayerLogger(damager,target,"Execute",(((GenericFunctions.getAbilityValue(ArtifactAbility.EXECUTION, weapon)*5.0)*(1-(target.getHealth()/target.getMaxHealth()))))); if (shooter instanceof Player) { + dmg += addToPlayerLogger(damager,target,"Tactics Bonus Damage",API.getPlayerBonuses((Player)shooter).getBonusDamage()); dmg += addToPlayerLogger(damager,target,"Execute Set Bonus",(((ItemSet.TotalBaseAmountBasedOnSetBonusCount(GenericFunctions.getEquipment(shooter),(Player)shooter, ItemSet.LORASAADI, 4, 4)*5.0)*(1-(target.getHealth()/target.getMaxHealth()))))); if (PlayerMode.getPlayerMode((Player)shooter)==PlayerMode.BARBARIAN) { dmg += addMultiplierToPlayerLogger(damager,target,"Barbarian Execute Mult",dmg * (1-(target.getHealth()/target.getMaxHealth()))); } + dmg += addMultiplierToPlayerLogger(damager,target,"Tactics Bonus Mult",dmg * API.getPlayerBonuses((Player)shooter).getBonusOverallDamageMultiplier()); } dmg += addMultiplierToPlayerLogger(damager,target,"Striker Mult",dmg * calculateStrikerMultiplier(shooter,target)); double preemptivedmg = addMultiplierToPlayerLogger(damager,target,"Preemptive Strike Mult",dmg * calculatePreemptiveStrikeMultiplier(target,shooter)); @@ -224,6 +239,7 @@ public class CustomDamage { dmg += critdmg; double armorpendmg = addToPlayerLogger(damager,target,"Armor Pen",calculateArmorPen(damager,dmg,weapon)); dmg -= getDamageFromBarbarianSetBonus(target); + dmg -= getDamageReduction(target); addToLoggerActual(damager,dmg); addToPlayerRawDamage(dmg,target); if (!isFlagSet(flags, TRUEDMG)) { @@ -241,6 +257,17 @@ public class CustomDamage { return dmg; } + private static double getDamageReduction(LivingEntity target) { + if (target instanceof Player) { + double reduction = 0; + Player p = (Player)target; + reduction += API.getPlayerBonuses(p).getBonusFlatDamageReduction(); + return reduction; + } else { + return 0.0; + } + } + private static double calculateAirborneAttackMultiplier(LivingEntity shooter) { if (shooter==null) {return 0.0;} if (shooter instanceof Player) { @@ -1403,6 +1430,7 @@ public class CustomDamage { int partylevel = 0; int rangeraegislevel = 0; double rangerdmgdiv = 0; + double tacticspct = 0; if (target instanceof LivingEntity) { ItemStack[] armor = GenericFunctions.getEquipment(target); @@ -1531,6 +1559,7 @@ public class CustomDamage { /*if (ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, p.getEquipment().getItemInMainHand())) { dmgreduction /= ArtifactAbility.containsEnchantment(ArtifactAbility.GREED, p.getEquipment().getItemInMainHand())?2:1; }*/ + tacticspct = API.getPlayerBonuses(p).getBonusPercentDamageReduction(); setbonus = ((100-ItemSet.TotalBaseAmountBasedOnSetBonusCount(GenericFunctions.getEquipment(p), p, ItemSet.SONGSTEEL, 4, 4))/100d); } @@ -1551,6 +1580,7 @@ public class CustomDamage { *(1d-((explosionprotectionlevel)/100d)) *(1d-rangerdmgdiv) *(1d-((partylevel*10d)/100d)) + *(1d-tacticspct) *setbonus *((target instanceof Player && ((Player)target).isBlocking())?(PlayerMode.isDefender((Player)target))?0.30:0.50:1) *((target instanceof Player)?((PlayerMode.isDefender((Player)target))?0.9:(target.getEquipment().getItemInOffHand()!=null && target.getEquipment().getItemInOffHand().getType()==Material.SHIELD)?0.95:1):1); @@ -2021,6 +2051,7 @@ public class CustomDamage { critchance += (PlayerMode.isRanger(p)?(GenericFunctions.getPotionEffectLevel(PotionEffectType.SLOW, p)+1)*0.1:0.0); critchance += ItemSet.TotalBaseAmountBasedOnSetBonusCount(GenericFunctions.getHotbarItems(p), p, ItemSet.MOONSHADOW, 5, 4)/100d; critchance += ItemSet.GetTotalBaseAmount(GenericFunctions.getHotbarItems(p), p, ItemSet.WOLFSBANE)/100d; + critchance += API.getPlayerBonuses(p).getBonusCriticalChance(); critchance += (pd.slayermegahit)?1.0:0.0; if (reason!=null && reason.equalsIgnoreCase("power swing")) { critchance += 1.0d; @@ -2051,6 +2082,7 @@ public class CustomDamage { GenericFunctions.getBowMode(weapon)==BowMode.SNIPE) { critdmg+=1.0; } + critdmg+=API.getPlayerBonuses(p).getBonusCriticalDamage(); critdmg+=ItemSet.GetTotalBaseAmount(GenericFunctions.getHotbarItems(p), p, ItemSet.MOONSHADOW)/100d; } TwosideKeeper.log("Crit Damage is "+critdmg, 5); @@ -2167,6 +2199,7 @@ public class CustomDamage { GenericFunctions.getBowMode(weapon)==BowMode.DEBILITATION) { finaldmg += dmg*0.5; } + finaldmg += API.getPlayerBonuses(p).getBonusArmorPenetration(); } if (finaldmg>=dmg) { return dmg; @@ -2364,6 +2397,7 @@ public class CustomDamage { PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); lifestealpct += ItemSet.TotalBaseAmountBasedOnSetBonusCount(GenericFunctions.getEquipment(p), p, ItemSet.DAWNTRACKER, 3, 3)/100d; lifestealpct += pd.lifestealstacks/100d; + lifestealpct += API.getPlayerBonuses(p).getBonusLifesteal(); if (reason!=null && reason.equalsIgnoreCase("power swing")) { lifestealpct += 1.0d; } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index e10dccc..0f0fe0f 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -842,6 +842,19 @@ public class GenericFunctions { case WALL_SIGN:{ return "Sign"; } + case ANVIL:{ + switch (type.getDurability()) { + case 0:{ + return "Anvil"; + } + case 1:{ + return "Slightly Damaged Anvil"; + } + case 2:{ + return "Very Damaged Anvil"; + } + } + } case SKULL_ITEM:{ switch (type.getDurability()) { case 0:{ diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/Habitation.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/Habitation.java index d125a9c..dcc7f72 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/Habitation.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/Habitation.java @@ -144,7 +144,6 @@ public class Habitation { public void loadLocationHashesFromConfig() { File file = new File(TwosideKeeper.plugin.getDataFolder()+"/locationhashes.data"); - // if file doesnt exists, then create it if (file.exists()) { try( FileReader fw = new FileReader(TwosideKeeper.plugin.getDataFolder()+"/locationhashes.data"); @@ -171,7 +170,6 @@ public class Habitation { TwosideKeeper.log("[Habitat]Loaded "+lines+" habitats successfully.",2); } catch (IOException e) { e.printStackTrace(); - //exception handling left as an exercise for the reader } } } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/BlockUtils.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/BlockUtils.java new file mode 100644 index 0000000..db6886c --- /dev/null +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/BlockUtils.java @@ -0,0 +1,47 @@ +package sig.plugin.TwosideKeeper.HelperStructures.Utils; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.material.Chest; + +public class BlockUtils { + public static boolean LocationInFrontOfBlockIsFree(Block b) { + if (b.getType()==Material.CHEST || + b.getType()==Material.TRAPPED_CHEST || + b.getType()==Material.ENDER_CHEST) { + Chest c = new Chest(0,b.getData()); + BlockFace bf = c.getFacing(); + //Check the block relative to here. + Block b2 = b.getRelative(bf); + return (b2.getType()==Material.AIR); + } else { + return false; + } + } + + public static BlockFace GetBlockFacingDirection(Block b) { + if (b.getType()==Material.CHEST || + b.getType()==Material.TRAPPED_CHEST || + b.getType()==Material.ENDER_CHEST) { + Chest c = new Chest(0,b.getData()); + BlockFace bf = c.getFacing(); + return bf; + } else { + return null; + } + } + + public static Block GetBlockInFrontOfBlock(Block b) { + if (b.getType()==Material.CHEST || + b.getType()==Material.TRAPPED_CHEST || + b.getType()==Material.ENDER_CHEST) { + Chest c = new Chest(0,b.getData()); + BlockFace bf = c.getFacing(); + //Check the block relative to here. + return b.getRelative(bf); + } else { + return null; + } + } +} diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemUtils.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemUtils.java index 64fd92e..3b99239 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemUtils.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Utils/ItemUtils.java @@ -33,4 +33,48 @@ public class ItemUtils { item.setItemMeta(m); } + public static void setDisplayName(ItemStack item, String name) { + ItemMeta m = item.getItemMeta(); + m.setDisplayName(name); + item.setItemMeta(m); + } + + public static boolean isValidLoreItem(ItemStack item) { + return (item!=null && item.hasItemMeta() && item.getItemMeta().hasLore()); + } + + public static boolean LoreContains(ItemStack item, String string) { + if (isValidLoreItem(item)) { + List lore = item.getItemMeta().getLore(); + if (lore.contains(string)) { + return true; + } + } + return false; + } + + public static boolean LoreContainsSubstring(ItemStack item, String string) { + if (isValidLoreItem(item)) { + List lore = item.getItemMeta().getLore(); + for (String l : lore) { + if (l.contains(string)) { + return true; + } + } + } + return false; + } + + public static String GetLoreLine(ItemStack item, int line_numb) { + if (isValidLoreItem(item)) { + List lore = item.getItemMeta().getLore(); + if (lore.size()>line_numb) { + return lore.get(line_numb); + } else { + return ""; + } + } + return ""; + } + } diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java index 6e88245..1a98699 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java @@ -1,8 +1,15 @@ package sig.plugin.TwosideKeeper.HelperStructures; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -14,6 +21,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Banner; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Chest; import org.bukkit.block.Sign; import org.bukkit.block.banner.Pattern; @@ -43,6 +51,7 @@ import sig.plugin.TwosideKeeper.Artifact; import sig.plugin.TwosideKeeper.TwosideKeeper; import sig.plugin.TwosideKeeper.WorldShopManager; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; +import sig.plugin.TwosideKeeper.HelperStructures.Utils.BlockUtils; import sig.plugin.TwosideKeeper.HelperStructures.Utils.ItemUtils; public class WorldShop { @@ -52,6 +61,8 @@ public class WorldShop { int amt; int storedamt = 0; int id; + public static HashMap pricelist = new HashMap(); + public static String price_file = TwosideKeeper.plugin.getDataFolder()+"/ShopPrices.data"; public WorldShop (ItemStack i, int amt, int storedamt, double p, String player, int shopID) { this.item=i; @@ -90,8 +101,40 @@ public class WorldShop { return item; } public double GetUnitPrice() { - return price; + if (owner.equalsIgnoreCase("admin")) { + return GetWorldShopPrice(item); + } else { + return price; + } } + private static double GetWorldShopPrice(ItemStack item) { + if (!pricelist.containsKey(item.getType())) { + //Create a new key for this item. + TwosideKeeper.log("Material "+ChatColor.YELLOW+item.getType()+ChatColor.RESET+" does not have a price set yet! Adding to price list!", 1); + AddEntryToFile(item.getType()); + } + return pricelist.get(item.getType()); + } + + private static void AddEntryToFile(Material type) { + File file = new File(price_file); + + if (!file.exists()) { + PopulateNewFile(file); + } + try( + FileWriter fw = new FileWriter(price_file, true); + BufferedWriter bw = new BufferedWriter(fw);) + { + bw.write(type.name()+","+"0.50"); + bw.newLine(); + pricelist.put(type, 0.50); + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + public int getID() { return id; } @@ -934,9 +977,10 @@ public class WorldShop { for (Material mat : Material.values()) { ItemStack result = new ItemStack(Material.TRAPPED_CHEST); ItemUtils.addLore(result,ChatColor.DARK_PURPLE+"World Shop Chest"); - ItemUtils.addLore(result,ChatColor.MAGIC+""+ChatColor.BLACK+mat.name()); + ItemUtils.addLore(result,ChatColor.BLACK+""+ChatColor.MAGIC+mat.name()); ItemUtils.addLore(result,ChatColor.LIGHT_PURPLE+"Place in the world to setup a"); ItemUtils.addLore(result,ChatColor.LIGHT_PURPLE+"world shop that sells "+ChatColor.YELLOW+GenericFunctions.UserFriendlyMaterialName(mat)); + ItemUtils.setDisplayName(result,ChatColor.YELLOW+GenericFunctions.UserFriendlyMaterialName(mat)+" Shop Chest"); ItemUtils.hideEnchantments(result); result.addUnsafeEnchantment(Enchantment.LUCK, 4); ShapelessRecipe rec = new ShapelessRecipe(result); @@ -946,4 +990,102 @@ public class WorldShop { Bukkit.addRecipe(rec); } } + + public static void loadShopPrices() { + File file = new File(price_file); + + if (file.exists()) { + LoadPricesIntoPriceList(file); + } else { + try { + TwosideKeeper.log(ChatColor.GOLD+"No World Shop Price file detected. Creating a new one...", 1); + long start_time = System.currentTimeMillis(); + file.createNewFile(); + PopulateNewFile(file); + TwosideKeeper.log(ChatColor.AQUA+"Finished creating World Shop Price file with "+Material.values().length+" entries. Elapsed Time: "+(System.currentTimeMillis()-start_time)+"ms", 1); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private static void LoadPricesIntoPriceList(File file) { + try( + FileReader fw = new FileReader(price_file); + BufferedReader bw = new BufferedReader(fw);) + { + String readline = bw.readLine(); + int lines = 0; + do { + if (readline!=null) { + lines++; + String[] split = readline.split(","); + double price = Double.parseDouble(split[1]); + pricelist.put(Material.valueOf(split[0]), price); + readline = bw.readLine(); + }} while (readline!=null); + TwosideKeeper.log("[WorldShop]Loaded "+lines+" shop entries successfully.",2); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void PopulateNewFile(File file) { + try( + FileWriter fw = new FileWriter(price_file, false); + BufferedWriter bw = new BufferedWriter(fw);) + { + for (Material mat : Material.values()) { + bw.write(mat.name()+","+"0.50"); + bw.newLine(); + pricelist.put(mat, 0.50); + } + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static boolean isPlaceableWorldShop(ItemStack item) { + if (ItemUtils.isValidLoreItem(item) && + ItemUtils.LoreContains(item,ChatColor.DARK_PURPLE+"World Shop Chest")) { + return true; + } + return false; + } + + public static void CreateNewWorldShop(Block b, ItemStack item) { + Chest c = (Chest)b.getState(); + c.getBlockInventory().addItem(item); + //From block B, add a Wall Sign attached to this block. + BlockFace bf = BlockUtils.GetBlockFacingDirection(b); + Block wallsign = b.getRelative(bf); //This will be the sign. + wallsign.setType(Material.WALL_SIGN); + //Make it face the opposite way of the chest. + org.bukkit.material.Sign sign = (org.bukkit.material.Sign)(wallsign.getState().getData()); + sign.setFacingDirection(bf); + DecimalFormat df = new DecimalFormat("0.00"); + wallsign.setData(sign.getData()); + Sign s = (Sign)wallsign.getState(); + s.setLine(0,"shop"); + WorldShop shop = TwosideKeeper.TwosideShops.CreateWorldShop(s, item, 10000, GetWorldShopPrice(item), "admin"); + /*s.setLine(0, ChatColor.BLUE+"-- SHOP --"); + s.setLine(1, GenericFunctions.UserFriendlyMaterialName(item)); + s.setLine(2, "$"+df.format(GetWorldShopPrice(item))+ChatColor.DARK_BLUE+" [x10000]"); + DecimalFormat df2 = new DecimalFormat("000000"); + s.setLine(3, ChatColor.DARK_GRAY+df2.format(TwosideKeeper.WORLD_SHOP_ID)); + TwosideKeeper.WORLD_SHOP_ID++;*/ + WorldShop.spawnShopItem(s.getLocation(), shop); + TwosideKeeper.TwosideShops.SaveWorldShopData(shop); + } + + public static ItemStack ExtractPlaceableShopMaterial(ItemStack item) { + if (isPlaceableWorldShop(item)) { + Material mat = Material.valueOf(ItemUtils.GetLoreLine(item, 1).replace(ChatColor.BLACK+""+ChatColor.MAGIC, "")); + return new ItemStack(mat); + } else { + TwosideKeeper.log("THIS SHOULD NOT BE HAPPENING! Trying to extract from a non-world shop item!", 0); + return new ItemStack(Material.AIR); + } + } } diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java index 212763d..3f02305 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeper.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeper.java @@ -186,6 +186,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.Common.Habitation; import sig.plugin.TwosideKeeper.HelperStructures.Common.RecipeCategory; import sig.plugin.TwosideKeeper.HelperStructures.Common.RecipeLinker; import sig.plugin.TwosideKeeper.HelperStructures.Effects.LavaPlume; +import sig.plugin.TwosideKeeper.HelperStructures.Utils.BlockUtils; import sig.plugin.TwosideKeeper.HelperStructures.Utils.SoundUtils; import sig.plugin.TwosideKeeper.Logging.BowModeLogger; import sig.plugin.TwosideKeeper.Logging.LootLogger; @@ -790,6 +791,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { //Announce the server has restarted soon after. WorldShop.createWorldShopRecipes(); + WorldShop.loadShopPrices(); if (!LOOT_TABLE_NEEDS_POPULATING) { Loot.DefineLootChests(); @@ -942,7 +944,6 @@ public class TwosideKeeper extends JavaPlugin implements Listener { ((org.bukkit.craftbukkit.v1_9_R1.entity.CraftLivingEntity)p).getHandle().setAbsorptionHearts(Float.valueOf(args[0])); }*/ if (args.length>0) { - switch (args[0]) { case "ADD":{ ItemStack quiver = p.getInventory().getExtraContents()[0]; @@ -970,6 +971,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { }break; } } + Monster m = MonsterController.convertMonster((Monster)p.getWorld().spawnEntity(p.getLocation(),EntityType.ZOMBIE), MonsterDifficulty.ELITE); /* StackTraceElement[] stacktrace = new Throwable().getStackTrace(); StringBuilder stack = new StringBuilder("Mini stack tracer:"); @@ -2891,6 +2893,17 @@ public class TwosideKeeper extends JavaPlugin implements Listener { } } + if (WorldShop.isPlaceableWorldShop(ev.getItemInHand())) { + if (BlockUtils.LocationInFrontOfBlockIsFree(ev.getBlockPlaced())) { + //ev.getPlayer().sendMessage("ALLOWED!"); + WorldShop.CreateNewWorldShop(ev.getBlockPlaced(),WorldShop.ExtractPlaceableShopMaterial(ev.getItemInHand())); + } else { + //ev.getPlayer().sendMessage("DENIED!"); + ev.setCancelled(true); + } + return; + } + if (GenericFunctions.isArtifactEquip(ev.getItemInHand()) && ev.getItemInHand().getType().toString().contains("HOE")) { AwakenedArtifact.addPotentialEXP(ev.getItemInHand(), 4, ev.getPlayer());