mortar now does some failure calculation, need to complete todos for fireShell method
parent
edd34d3d11
commit
b5edf54e1f
|
@ -1,36 +1,50 @@
|
||||||
package xyz.soper.arty.item;
|
package xyz.soper.arty.item;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Nameable;
|
import org.bukkit.Nameable;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class Mortar {
|
public class Mortar {
|
||||||
|
|
||||||
public Location location;
|
/**The block that represents this mortar.*/
|
||||||
|
private final Block block;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The direction this mortar is facing. The shell will ultimately be fired in this direction.
|
||||||
|
*/
|
||||||
|
private Vector direction;
|
||||||
|
|
||||||
public static final String BASIC_MORTAR_NAME = ChatColor.GRAY + "Basic Mortar";
|
public static final String BASIC_MORTAR_NAME = ChatColor.GRAY + "Basic Mortar";
|
||||||
public static final String NORMAL_MORTAR_NAME = ChatColor.GRAY + "Mortar";
|
public static final String NORMAL_MORTAR_NAME = ChatColor.GRAY + "Mortar";
|
||||||
public static final String INCENDIARY_CAPABLE_MORTAR_NAME = ChatColor.GRAY + "Incendiary Capable Mortar";
|
public static final String INCENDIARY_CAPABLE_MORTAR_NAME = ChatColor.GRAY + "Incendiary Capable Mortar";
|
||||||
public static final String REINFORCED_MORTAR_NAME = ChatColor.GRAY + "Reinforced Mortar";
|
public static final String REINFORCED_MORTAR_NAME = ChatColor.GRAY + "Reinforced Mortar";
|
||||||
|
|
||||||
public int failMultiplier; //Multiplier to a fail chance.
|
/**Multiplier to a fail chance.*/
|
||||||
public double jamChance; //If a fail happens, chance of it being a jam.
|
public int failMultiplier;
|
||||||
public double dudChance; //If a fail happens, chance of it being a dud shell (that fires but has no impact explosion)
|
/**If a fail happens, chance of it being a jam.*/
|
||||||
public double catastrophicFailChance; //If a fail happens, chance of it being catastrophic.
|
public double jamChance;
|
||||||
public double maxVelocity; //Max initial velocity supported by this mortar
|
/**If a fail happens, chance of it being a dud shell (that fires but has no explosion on impact)*/
|
||||||
public double velocityMultiplier; //Multiplier applied to the shell's velocity
|
public double dudChance;
|
||||||
public boolean incendiaryCapable; //Is the mortar fit to fire an incendiary-type shell?
|
/**If a fail happens, chance of it being catastrophic.*/
|
||||||
|
public double catastrophicFailChance;
|
||||||
private Vector direction;
|
/**Max initial velocity supported by this mortar*/
|
||||||
|
public double maxVelocity;
|
||||||
private Block block;
|
/**Multiplier applied to the shell's velocity*/
|
||||||
|
public double velocityMultiplier;
|
||||||
|
/**Is the mortar fit to fire an incendiary-type shell?*/
|
||||||
|
public boolean incendiaryCapable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Mortar block wrapper using the specified block.
|
||||||
|
* WARNING: This does NOT check if the block is actually a mortar.
|
||||||
|
* @param mortar Placed block in the world that represents a mortar.
|
||||||
|
*/
|
||||||
public Mortar(Block mortar){
|
public Mortar(Block mortar){
|
||||||
block = mortar;
|
block = mortar;
|
||||||
location = mortar.getLocation();
|
|
||||||
Nameable brewingStandMortar = (Nameable) mortar.getState();
|
Nameable brewingStandMortar = (Nameable) mortar.getState();
|
||||||
String mortarName = brewingStandMortar.getCustomName();
|
String mortarName = brewingStandMortar.getCustomName();
|
||||||
|
|
||||||
|
@ -72,6 +86,42 @@ public class Mortar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Block that represents this mortar object
|
||||||
|
* @return Mortar as a Block
|
||||||
|
*/
|
||||||
|
public Block getBlock() {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines type of failure the provided shell and this mortar experienced
|
||||||
|
* @param shell Shell that interacted with this mortar object
|
||||||
|
* @return
|
||||||
|
* 0 for non-failure;
|
||||||
|
* 1 for non-firing jam;
|
||||||
|
* 2 for no impact explosion dud;
|
||||||
|
* 3 for catastrophic failure
|
||||||
|
*/
|
||||||
|
public int getFailureType(Shell shell){
|
||||||
|
if(isFailure(shell)){
|
||||||
|
Random random = new Random(block.getWorld().getSeed() + System.currentTimeMillis());
|
||||||
|
double randDouble = random.nextDouble();
|
||||||
|
//TODO: compare random double and create an algo to determine type of failure.
|
||||||
|
}
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the shell and mortar interaction failed
|
||||||
|
* @param shell Shell that interacted with this mortar object
|
||||||
|
* @return True if the interaction failed (did not fire properly)
|
||||||
|
*/
|
||||||
|
private boolean isFailure(Shell shell){
|
||||||
|
Random random = new Random(block.getWorld().getSeed() + System.currentTimeMillis());
|
||||||
|
return random.nextDouble() < failMultiplier*shell.failChance;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isMortar(Block block){
|
public static boolean isMortar(Block block){
|
||||||
if(block != null
|
if(block != null
|
||||||
&& block.getBlockData().getMaterial() == Material.BREWING_STAND
|
&& block.getBlockData().getMaterial() == Material.BREWING_STAND
|
||||||
|
@ -82,7 +132,8 @@ public class Mortar {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isStringMortar(String string){
|
private static boolean isStringMortar(String string){
|
||||||
if(string.equals(BASIC_MORTAR_NAME)
|
if(string != null
|
||||||
|
|| string.equals(BASIC_MORTAR_NAME)
|
||||||
|| string.equals(NORMAL_MORTAR_NAME)
|
|| string.equals(NORMAL_MORTAR_NAME)
|
||||||
|| string.equals(REINFORCED_MORTAR_NAME)
|
|| string.equals(REINFORCED_MORTAR_NAME)
|
||||||
|| string.equals(INCENDIARY_CAPABLE_MORTAR_NAME)){
|
|| string.equals(INCENDIARY_CAPABLE_MORTAR_NAME)){
|
||||||
|
@ -90,12 +141,4 @@ public class Mortar {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Block that represents this mortar object
|
|
||||||
* @return Mortar as a Block
|
|
||||||
*/
|
|
||||||
public Block getBlock() {
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,18 @@ public class MortarHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fireShell(Shell shell, ProjectileSource shooter){
|
public void fireShell(Shell shell, ProjectileSource shooter){
|
||||||
|
//TODO: Use linkProjectile method and finalize fireShell method to create a proper non-debug fireShell method.
|
||||||
|
//As it stands, this method creates a shell with no actual data so the Shell wrapper uses default values.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Vector debugVector = new Vector(1, 1, 0).normalize();
|
Vector debugVector = new Vector(1, 1, 0).normalize();
|
||||||
mortar.getBlock().getWorld().playSound(mortar.location, "entity.generic.explode", 1, 1.5F);
|
mortar.getBlock().getWorld().playSound(
|
||||||
|
mortar.getBlock().getLocation(),
|
||||||
|
"entity.generic.explode",
|
||||||
|
1,
|
||||||
|
1.5F
|
||||||
|
);
|
||||||
Location mortarLocation = mortar.getBlock().getLocation().add(.5, 1, .5);
|
Location mortarLocation = mortar.getBlock().getLocation().add(.5, 1, .5);
|
||||||
Arrow shellProjectile = mortar.getBlock().getWorld().spawn(mortarLocation, Arrow.class);
|
Arrow shellProjectile = mortar.getBlock().getWorld().spawn(mortarLocation, Arrow.class);
|
||||||
shellProjectile.setVelocity(debugVector.multiply(shell.baseVelocity));
|
shellProjectile.setVelocity(debugVector.multiply(shell.baseVelocity));
|
||||||
|
@ -27,7 +37,8 @@ public class MortarHandler {
|
||||||
shellProjectile.setCustomName("shell");
|
shellProjectile.setCustomName("shell");
|
||||||
mortar.getBlock().getWorld().spawnParticle(Particle.SMOKE_NORMAL, mortarLocation, 500, .5, 0, .5, .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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue