From 65f0a2fa1b35f42908eb26cdacc5da7987061a93 Mon Sep 17 00:00:00 2001 From: Soper Date: Tue, 4 May 2021 10:13:19 -0400 Subject: [PATCH] mortar interact and debug shell added --- src/xyz/soper/arty/Artillery.java | 31 ++++++++ .../arty/event/Listener/MortarInteract.java | 23 ++++++ src/xyz/soper/arty/item/BaseMortar.java | 20 ------ src/xyz/soper/arty/item/Mortar.java | 70 +++++++++++++++++++ src/xyz/soper/arty/item/NormalMortar.java | 16 ----- src/xyz/soper/arty/item/Shell.java | 36 ++++++++++ src/xyz/soper/arty/util/MortarHandler.java | 16 ++++- 7 files changed, 175 insertions(+), 37 deletions(-) delete mode 100644 src/xyz/soper/arty/item/BaseMortar.java create mode 100644 src/xyz/soper/arty/item/Mortar.java delete mode 100644 src/xyz/soper/arty/item/NormalMortar.java create mode 100644 src/xyz/soper/arty/item/Shell.java diff --git a/src/xyz/soper/arty/Artillery.java b/src/xyz/soper/arty/Artillery.java index 7353742..8fd4fd6 100644 --- a/src/xyz/soper/arty/Artillery.java +++ b/src/xyz/soper/arty/Artillery.java @@ -7,9 +7,14 @@ import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; import xyz.soper.arty.debug.DebugCommand; +import xyz.soper.arty.event.Listener.MortarInteract; + +import java.util.ArrayList; +import java.util.List; public class Artillery extends JavaPlugin { @@ -53,10 +58,36 @@ public class Artillery extends JavaPlugin { Bukkit.addRecipe(mortarRecipe); //END OF NORMAL MORTAR RECIPE + //START OF DEBUG SHELL RECIPE + ItemStack debugShell = new ItemStack(Material.ARROW); + ItemMeta debugShellMeta = debugShell.getItemMeta(); + + assert debugShellMeta != null; + debugShellMeta.setDisplayName(ChatColor.GRAY + "Shell"); + List debugShellLore = new ArrayList(); + debugShellLore.add("STATS:"); + debugShellLore.add("EXPLOSION: 1.0x"); + debugShellLore.add("PENETRATION: 1"); + debugShellLore.add("INCENDIARY: TRUE"); + debugShellLore.add("VELOCITY: 0.5"); + debugShellLore.add("FAIL CHANCE: 0.10"); + debugShellMeta.setLore(debugShellLore); + + debugShell.setItemMeta(debugShellMeta); + + NamespacedKey debugShellKey = new NamespacedKey(this, "debug_shell"); + ShapelessRecipe debugShellRecipe = new ShapelessRecipe(debugShellKey, debugShell); + debugShellRecipe.addIngredient(Material.ARROW); + debugShellRecipe.addIngredient(Material.GUNPOWDER); + + Bukkit.addRecipe(debugShellRecipe); + + this.getCommand("arty-debug").setExecutor(new DebugCommand()); //DEBUGGING: getServer().getPluginManager().registerEvents(new DebugCommand(), this); + getServer().getPluginManager().registerEvents(new MortarInteract(), this); } @Override diff --git a/src/xyz/soper/arty/event/Listener/MortarInteract.java b/src/xyz/soper/arty/event/Listener/MortarInteract.java index 27e1c7c..2f08760 100644 --- a/src/xyz/soper/arty/event/Listener/MortarInteract.java +++ b/src/xyz/soper/arty/event/Listener/MortarInteract.java @@ -1,15 +1,38 @@ package xyz.soper.arty.event.Listener; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Nameable; +import org.bukkit.block.Block; +import org.bukkit.block.Container; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import xyz.soper.arty.item.Mortar; +import xyz.soper.arty.item.Shell; +import xyz.soper.arty.util.MortarHandler; public class MortarInteract implements Listener { @EventHandler public void onClick(PlayerInteractEvent event){ if(event.getHand() == EquipmentSlot.OFF_HAND) return; + Player player = event.getPlayer(); + ItemStack item = player.getInventory().getItemInMainHand(); + Block block = event.getClickedBlock(); + if(block.getBlockData().getMaterial() == Material.BREWING_STAND){ + Nameable brewingStandMortar = (Nameable) event.getClickedBlock().getState(); + String blockName = brewingStandMortar.getCustomName(); + if(blockName.equals(ChatColor.GRAY + "Basic Mortar") || blockName.equals(ChatColor.GRAY + "Mortar")){ + if((item.getType() == Material.ARROW) && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equals(ChatColor.GRAY + "Shell")){ + MortarHandler mortarHandler = new MortarHandler(new Mortar(block)); + mortarHandler.fireShell(new Shell(item)); + } + } + } } } diff --git a/src/xyz/soper/arty/item/BaseMortar.java b/src/xyz/soper/arty/item/BaseMortar.java deleted file mode 100644 index 3d3a6c4..0000000 --- a/src/xyz/soper/arty/item/BaseMortar.java +++ /dev/null @@ -1,20 +0,0 @@ -package xyz.soper.arty.item; - -import org.bukkit.Location; -import org.bukkit.block.Block; - -public class BaseMortar { - - Location location; - - int failMultiplier = 25; - int maxCaliber = 125; - int dispersion = 20; - int range = 25; - boolean incendiaryCapable = false; - - BaseMortar(Block mortar){ - location = mortar.getLocation(); - } - -} diff --git a/src/xyz/soper/arty/item/Mortar.java b/src/xyz/soper/arty/item/Mortar.java new file mode 100644 index 0000000..de06593 --- /dev/null +++ b/src/xyz/soper/arty/item/Mortar.java @@ -0,0 +1,70 @@ +package xyz.soper.arty.item; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Nameable; +import org.bukkit.block.Block; +import org.bukkit.block.Container; + +public class Mortar { + + Location location; + + public static String BASIC_MORTAR_NAME = ChatColor.GRAY + "Basic Mortar"; + public static String NORMAL_MORTAR_NAME = ChatColor.GRAY + "Mortar"; + public static String INCENDIARY_CAPABLE_MORTAR_NAME = ChatColor.GRAY + "Incendiary Capable Mortar"; + public static String REINFORCED_MORTAR_NAME = ChatColor.GRAY + "Reinforced Mortar"; + + public int failMultiplier; //Multiplier to a fail chance. + public double jamChance; //If a fail happens, chance of it being a jam. + public double dudChance; //If a fail happens, chance of it being a dud shell (that fires but has no impact explosion) + public double catastrophicFailChance; //If a fail happens, chance of it being catastrophic. + public double maxVelocity; //Max initial velocity supported by this mortar + public double velocityMultiplier; //Multiplier applied to the shell's velocity + public boolean incendiaryCapable; //Is the mortar fit to fire an incendiary-type shell? + + public Mortar(Block mortar){ + location = mortar.getLocation(); + Nameable brewingStandMortar = (Nameable) mortar.getState(); + String mortarName = brewingStandMortar.getCustomName(); + + if(mortarName.equals(BASIC_MORTAR_NAME)){ + failMultiplier = 25; + jamChance = .4; + dudChance = .1; + catastrophicFailChance = .5; + maxVelocity = 1.5; + velocityMultiplier = .75; + incendiaryCapable = false; + } + else if(mortarName.equals(NORMAL_MORTAR_NAME)){ + failMultiplier = 3; + jamChance = .25; + dudChance = .5; + catastrophicFailChance = .25; + maxVelocity = 3.0; + velocityMultiplier = 1.0; + incendiaryCapable = false; + } + else if(mortarName.equals(INCENDIARY_CAPABLE_MORTAR_NAME)){ + failMultiplier = 3; + jamChance = .4; + dudChance = .2; + catastrophicFailChance = .4; + maxVelocity = 3.0; + velocityMultiplier = .9; + incendiaryCapable = false; + } + else if(mortarName.equals(REINFORCED_MORTAR_NAME)){ + failMultiplier = 1; + jamChance = .2; + dudChance = .7; + catastrophicFailChance = .1; + maxVelocity = 5.0; + velocityMultiplier = 1.0; + incendiaryCapable = false; + } + + } + +} diff --git a/src/xyz/soper/arty/item/NormalMortar.java b/src/xyz/soper/arty/item/NormalMortar.java deleted file mode 100644 index 8fc1cb0..0000000 --- a/src/xyz/soper/arty/item/NormalMortar.java +++ /dev/null @@ -1,16 +0,0 @@ -package xyz.soper.arty.item; - -import org.bukkit.block.Block; - -public class NormalMortar extends BaseMortar { - - int failMultiplier = 3; - int maxCaliber = 125; - int dispersion = 10; - int range = 50; - boolean incendiaryCapable = false; - - NormalMortar(Block mortar) { - super(mortar); - } -} diff --git a/src/xyz/soper/arty/item/Shell.java b/src/xyz/soper/arty/item/Shell.java new file mode 100644 index 0000000..3ce1dbd --- /dev/null +++ b/src/xyz/soper/arty/item/Shell.java @@ -0,0 +1,36 @@ +package xyz.soper.arty.item; + +import org.bukkit.inventory.ItemStack; + +import java.util.List; + +public class Shell { + + public double explosionMultiplier = 1.0; + public int penetration = 0; + public boolean incendiaryType = false; + public double baseVelocity = 2.5; + public double failChance = .01; + + public Shell(){ + + } + + public Shell(ItemStack shell){ + List stats = shell.getItemMeta().getLore(); + explosionMultiplier = Double.parseDouble(stats.get(1).substring(11, 14)); + penetration = Integer.parseInt(stats.get(2).substring(13)); + incendiaryType = Boolean.parseBoolean(stats.get(3).substring(12).toLowerCase()); + baseVelocity = Double.parseDouble(stats.get(4).substring(10)); + failChance = Double.parseDouble(stats.get(5).substring(13)); + } + + public Shell(double explosionMultiplier, int penetration, boolean incendiaryType, double baseVelocity, double failChance){ + this.explosionMultiplier = explosionMultiplier; + this.penetration = penetration; + this.incendiaryType = incendiaryType; + this.baseVelocity = baseVelocity; + this.failChance = failChance; + } + +} diff --git a/src/xyz/soper/arty/util/MortarHandler.java b/src/xyz/soper/arty/util/MortarHandler.java index e7e8f7e..7fed2e2 100644 --- a/src/xyz/soper/arty/util/MortarHandler.java +++ b/src/xyz/soper/arty/util/MortarHandler.java @@ -1,4 +1,18 @@ package xyz.soper.arty.util; +import xyz.soper.arty.item.Mortar; +import xyz.soper.arty.item.Shell; + public class MortarHandler { -} + + Mortar mortar; + + public MortarHandler(Mortar mortar){ + this.mortar = mortar; + } + + public void fireShell(Shell shell){ + + } + +} \ No newline at end of file