shell class handles crafting and checks

master
Soper Aylamo 2021-05-16 02:43:49 -04:00
parent 1817f2c252
commit 5fdce6b5a8
Signed by: Soper
GPG Key ID: A27AC885ACC3BEAE
3 changed files with 47 additions and 32 deletions

View File

@ -12,6 +12,7 @@ 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 xyz.soper.arty.event.Listener.MortarInteract;
import xyz.soper.arty.item.Shell;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -59,28 +60,13 @@ public class Artillery extends JavaPlugin {
//END OF NORMAL MORTAR RECIPE //END OF NORMAL MORTAR RECIPE
//START OF DEBUG SHELL 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"); NamespacedKey debugShellKey = new NamespacedKey(this, "debug_shell");
ShapelessRecipe debugShellRecipe = new ShapelessRecipe(debugShellKey, debugShell); ShapelessRecipe debugShellRecipe = new ShapelessRecipe(debugShellKey, new Shell().getShell());
debugShellRecipe.addIngredient(Material.ARROW); debugShellRecipe.addIngredient(Material.ARROW);
debugShellRecipe.addIngredient(Material.GUNPOWDER); debugShellRecipe.addIngredient(Material.GUNPOWDER);
Bukkit.addRecipe(debugShellRecipe); Bukkit.addRecipe(debugShellRecipe);
//END OF DEBUG SHELL RECIPE
this.getCommand("arty-debug").setExecutor(new DebugCommand()); this.getCommand("arty-debug").setExecutor(new DebugCommand());

View File

@ -2,8 +2,12 @@ package xyz.soper.arty.item;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -11,7 +15,7 @@ import java.util.List;
*/ */
public class Shell { public class Shell {
public double explosionMultiplier = 1.0; public double explosivePower = 2.5;
public int penetration = 0; public int penetration = 0;
public boolean incendiaryType = false; public boolean incendiaryType = false;
public double baseVelocity = 2.5; public double baseVelocity = 2.5;
@ -24,7 +28,6 @@ public class Shell {
*/ */
public Shell(){ public Shell(){
isFired = false; isFired = false;
//TODO: Create default constructor
} }
/** /**
@ -35,7 +38,7 @@ public class Shell {
isFired = false; isFired = false;
if(isShell(shell)){ if(isShell(shell)){
List<String> stats = shell.getItemMeta().getLore(); List<String> stats = shell.getItemMeta().getLore();
explosionMultiplier = Double.parseDouble(stats.get(1).substring(11, 14)); explosivePower = Double.parseDouble(stats.get(1).substring(11));
penetration = Integer.parseInt(stats.get(2).substring(13)); penetration = Integer.parseInt(stats.get(2).substring(13));
incendiaryType = Boolean.parseBoolean(stats.get(3).substring(12).toLowerCase()); incendiaryType = Boolean.parseBoolean(stats.get(3).substring(12).toLowerCase());
baseVelocity = Double.parseDouble(stats.get(4).substring(10)); baseVelocity = Double.parseDouble(stats.get(4).substring(10));
@ -43,22 +46,30 @@ public class Shell {
} }
} }
/** TODO: Finish documentation for this /**
* Creates a shell with the specified statistics. * Creates a shell item wrapper with the specified statistics.
* @param explosionMultiplier Explosion multiplier. 1 represents default 3 (for blockDamage) * @param explosivePower Explosion power. Default is 2.5. 3 represents a creeper explosion, 4 is a TNT explosion.
* @param penetration Penetration value. Represents the amount of blocks the shell can penetrate before exploding. * @param penetration Penetration value. Represents the amount of blocks the shell can penetrate before exploding.
* @param incendiaryType Determines if the shell is capable of starting fires. * @param incendiaryType Determines if the shell is capable of starting fires.
* @param baseVelocity * @param baseVelocity Initial velocity of the shell. Determines the speed of the shell and range. Dependent on maximum velocity of the mortar.
* @param failChance * @param failChance Chance of the shell failing. Type of failure is dependent on the mortar type.
*/ */
public Shell(double explosionMultiplier, int penetration, boolean incendiaryType, double baseVelocity, double failChance){ public Shell(double explosivePower, int penetration, boolean incendiaryType, double baseVelocity, double failChance){
this.explosionMultiplier = explosionMultiplier; this.explosivePower = explosivePower;
this.penetration = penetration; this.penetration = penetration;
this.incendiaryType = incendiaryType; this.incendiaryType = incendiaryType;
this.baseVelocity = baseVelocity; this.baseVelocity = baseVelocity;
this.failChance = failChance; this.failChance = failChance;
} }
/**
* Creates a shell entity wrapper from a shell entity in the world. If
* @param shell Entity that represents a shell entity
*/
public Shell(Entity shell){
}
/** /**
* Checks if the item stack is a shell * Checks if the item stack is a shell
* @param item ItemStack to check against * @param item ItemStack to check against
@ -72,18 +83,36 @@ public class Shell {
return false; return false;
} }
/**
* Returns a shell ItemStack represented by this object.
* @return A shell with the stats in this object.
*/
public ItemStack getShell(){ public ItemStack getShell(){
//TODO: Create getShell method that returns ItemStack with shell metadata. ItemStack shell = new ItemStack(Material.ARROW);
ItemMeta shellMeta = shell.getItemMeta();
return null; shellMeta.setDisplayName(ChatColor.GRAY + "Shell");
List<String> shellLore = new ArrayList<String>();
shellLore.add("STATS:");
shellLore.add("EXPLOSION: " + explosivePower);
shellLore.add("PENETRATION: " + penetration);
shellLore.add("INCENDIARY: " + incendiaryType);
shellLore.add("VELOCITY: " + baseVelocity);
shellLore.add("FAIL CHANCE: " + failChance);
shellMeta.setLore(shellLore);
shell.setItemMeta(shellMeta);
return shell;
} }
/** /**
* Uses the stats defined by this function to create a shell with lore and item information. * Uses the stats defined by this function to create a shell with lore and item information.
* @return * @return
*/ */
private ItemStack createShell(){ @Deprecated private ItemStack createShell(){
//TODO: Create createShell method //TODO: Figure out the initial purpose of this method
return null; return null;
} }

View File

@ -25,7 +25,7 @@ public class MortarHandler {
shellProjectile.setVelocity(debugVector.multiply(shell.baseVelocity)); shellProjectile.setVelocity(debugVector.multiply(shell.baseVelocity));
shellProjectile.setShooter(shooter); shellProjectile.setShooter(shooter);
shellProjectile.setCustomName("shell"); shellProjectile.setCustomName("shell");
mortar.getBlock().getWorld().spawnParticle(Particle.SMOKE_NORMAL, mortarLocation, 500, 0, 0, 0, .5); mortar.getBlock().getWorld().spawnParticle(Particle.SMOKE_NORMAL, mortarLocation, 500, .5, 0, .5, .5);
//TODO: Experiment with spawnParticle offset parameters. This may create more realistic smoke. //TODO: Experiment with spawnParticle offset parameters. This may create more realistic smoke.
if(shooter instanceof Player) ((Player) shooter).sendMessage("DEBUG: Shell fired with a velocity " + shell.baseVelocity); if(shooter instanceof Player) ((Player) shooter).sendMessage("DEBUG: Shell fired with a velocity " + shell.baseVelocity);
} }