mortar interact and debug shell added

master
Soper Aylamo 2021-05-04 10:13:19 -04:00
parent e8f19d8b42
commit 65f0a2fa1b
Signed by: Soper
GPG Key ID: A27AC885ACC3BEAE
7 changed files with 175 additions and 37 deletions

View File

@ -7,9 +7,14 @@ import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import xyz.soper.arty.debug.DebugCommand; 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 { public class Artillery extends JavaPlugin {
@ -53,10 +58,36 @@ public class Artillery extends JavaPlugin {
Bukkit.addRecipe(mortarRecipe); Bukkit.addRecipe(mortarRecipe);
//END OF NORMAL MORTAR RECIPE //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<String> debugShellLore = new ArrayList<String>();
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()); this.getCommand("arty-debug").setExecutor(new DebugCommand());
//DEBUGGING: //DEBUGGING:
getServer().getPluginManager().registerEvents(new DebugCommand(), this); getServer().getPluginManager().registerEvents(new DebugCommand(), this);
getServer().getPluginManager().registerEvents(new MortarInteract(), this);
} }
@Override @Override

View File

@ -1,15 +1,38 @@
package xyz.soper.arty.event.Listener; 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.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot; 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 { public class MortarInteract implements Listener {
@EventHandler @EventHandler
public void onClick(PlayerInteractEvent event){ public void onClick(PlayerInteractEvent event){
if(event.getHand() == EquipmentSlot.OFF_HAND) return; 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));
}
}
}
} }
} }

View File

@ -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();
}
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}

View File

@ -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<String> 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;
}
}

View File

@ -1,4 +1,18 @@
package xyz.soper.arty.util; package xyz.soper.arty.util;
import xyz.soper.arty.item.Mortar;
import xyz.soper.arty.item.Shell;
public class MortarHandler { public class MortarHandler {
}
Mortar mortar;
public MortarHandler(Mortar mortar){
this.mortar = mortar;
}
public void fireShell(Shell shell){
}
}