projectiles refactor

This commit is contained in:
ShermansWorld committed 2024-01-07 12:43:57 -05:00
1 parent 80a058a2f1
commit 339fad98f3
9 files changed
+210 -133

No files matched your search

@@ -5,51 +5,77 @@ import com.github.alathra.siegeengines.SiegeEnginesUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class EntityProjectile implements GunnersProjectile {
public String ProjectileType = "Entity";
public int EntityCount = 20;
public int ArrowOnlyDamage = 6;
public Boolean DelayedFire = false;
public int DelayTime = 6;
public EntityType EntityTyp = EntityType.ARROW;
public float Inaccuracy = 0.2f;
public Particle ParticleType = Particle.EXPLOSION_LARGE;
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
public class EntityProjectile extends SiegeEngineProjectile {
// Defaults
public int entityCount = 20;
public int arrowOnlyDamage = 6;
public Boolean delayedFire = false;
public int delayTime = 6;
public EntityType entityType = EntityType.ARROW;
public float inaccuracy = 0.2f;
public Particle particleType = Particle.EXPLOSION_LARGE;
public Sound soundType = Sound.ENTITY_GENERIC_EXPLODE;
private boolean playSound = true;
public EntityProjectile(ItemStack ammunitionItem) {
super(ProjectileType.ENTITY, ammunitionItem);
// Defaults
}
public static EntityProjectile getDefaultFireballShot() {
EntityProjectile fireProj = new EntityProjectile(new ItemStack(Material.FIRE_CHARGE));
fireProj.entityCount = 4;
fireProj.entityType = EntityType.SMALL_FIREBALL;
fireProj.particleType = Particle.WHITE_ASH;
fireProj.soundType = Sound.ENTITY_BLAZE_SHOOT;
fireProj.inaccuracy = 0.75f;
return fireProj;
}
public static EntityProjectile getDefaultScatterShot() {
EntityProjectile scatterProj = new EntityProjectile(new ItemStack(Material.TNT));
scatterProj.inaccuracy = 0.5f;
scatterProj.entityCount = 24;
scatterProj.particleType = Particle.ELECTRIC_SPARK;
scatterProj.soundType = Sound.ITEM_CROSSBOW_SHOOT;
return scatterProj;
}
@Override
public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) {
PlaySound = true;
playSound = true;
int baseDelay = 0;
for (int i = 0; i < EntityCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
for (int i = 0; i < entityCount; i++) {
if (delayedFire) {
baseDelay += delayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
CreateEntity(entity, FireLocation, velocity, player);
}, (long) baseDelay);
} else {
CreateEntity(entity, FireLocation, velocity, player);
}
}
}
private boolean PlaySound = true;
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
World world = entity.getLocation().getWorld();
Entity arrow = world.spawnEntity(loc, EntityTyp);
if (Inaccuracy != 0f) {
Entity arrow = world.spawnEntity(loc, entityType);
if (inaccuracy != 0f) {
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
.subtract(Randomise()));
} else {
@@ -68,18 +94,22 @@ public class EntityProjectile implements GunnersProjectile {
if (player instanceof org.bukkit.projectiles.ProjectileSource)
arr.setShooter((org.bukkit.projectiles.ProjectileSource) player);
}
if (PlaySound) {
world.playSound(loc, this.SoundType, 20, 2);
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
if (!DelayedFire) {
PlaySound = false;
if (playSound) {
world.playSound(loc, this.soundType, 20, 2);
world.spawnParticle(this.particleType, loc.getX(), loc.getY(), loc.getZ(), 0);
if (!delayedFire) {
playSound = false;
}
}
}
private Vector Randomise() {
return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
return new Vector(SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1));
}
public ProjectileType getProjectileType() {
return projectileType;
}
}
@@ -12,31 +12,60 @@ import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Snowball;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class ExplosiveProjectile implements GunnersProjectile {
public String ProjectileType = "Explosive";
public Boolean PlaceBlocks = false;
public Material BlockToPlace = Material.COBWEB;
public int BlocksToPlaceAmount = 3;
public float ExplodePower = 2;
public float Inaccuracy = 0.3f;
public int ProjectilesCount = 1;
public Boolean DelayedFire = false;
public int DelayTime = 6;
public Particle ParticleType = Particle.EXPLOSION_LARGE;
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
private boolean PlaySound = true;
public Boolean AlertOnLanding = false;
public class ExplosiveProjectile extends SiegeEngineProjectile {
// Defaults
public Boolean placeBlocks = false;
public Material blockToPlace = Material.COBWEB;
public int blocksToPlaceAmount = 3;
public float explodePower = 2;
public float inaccuracy = 0.3f;
public int projectilesCount = 1;
public Boolean delayedFire = false;
public int delayTime = 6;
public Particle particleType = Particle.EXPLOSION_LARGE;
public Sound soundType = Sound.ENTITY_GENERIC_EXPLODE;
public Boolean alertOnLanding = false;
private boolean playSound = true;
public ExplosiveProjectile(ItemStack ammunitionItem) {
super(ProjectileType.EXPLOSIVE, ammunitionItem);
}
public static ExplosiveProjectile getDefaultStoneShot() {
ExplosiveProjectile stoneProj = new ExplosiveProjectile(new ItemStack(Material.COBBLESTONE));
stoneProj.explodePower = 1;
return stoneProj;
}
public static ExplosiveProjectile getDefaultRepeatingShot() {
ExplosiveProjectile repeatingProj = new ExplosiveProjectile(new ItemStack(Material.TNT));
repeatingProj.explodePower = 1;
repeatingProj.projectilesCount = 5;
repeatingProj.delayedFire = true;
repeatingProj.inaccuracy = 0.75f;
return repeatingProj;
}
public static ExplosiveProjectile getDefaultBreachShot() {
ExplosiveProjectile breachProj = new ExplosiveProjectile(new ItemStack(Material.IRON_BLOCK));
breachProj.explodePower = 3;
breachProj.projectilesCount = 1;
return breachProj;
}
@Override
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
PlaySound = true;
playSound = true;
int baseDelay = 0;
for (int i = 0; i < ProjectilesCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
for (int i = 0; i < projectilesCount; i++) {
if (delayedFire) {
baseDelay += delayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
CreateEntity(entity, loc, velocity, player);
}, (long) baseDelay);
@@ -54,7 +83,7 @@ public class ExplosiveProjectile implements GunnersProjectile {
ball.setShooter((org.bukkit.projectiles.ProjectileSource) player);
ClickHandler.projectiles.put(tnt.getUniqueId(), this);
if (Inaccuracy != 0f) {
if (inaccuracy != 0f) {
tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
.subtract(Randomise()));
} else {
@@ -63,19 +92,23 @@ public class ExplosiveProjectile implements GunnersProjectile {
tnt.setMetadata("isExplosiveProj", SiegeEnginesUtil.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt));
if (PlaySound) {
world.playSound(loc, this.SoundType, 20, 2);
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
if (!DelayedFire) {
PlaySound = false;
if (playSound) {
world.playSound(loc, this.soundType, 20, 2);
world.spawnParticle(this.particleType, loc.getX(), loc.getY(), loc.getZ(), 0);
if (!delayedFire) {
playSound = false;
}
}
}
private Vector Randomise() {
return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
return new Vector(SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1));
}
public ProjectileType getProjectileType() {
return projectileType;
}
}
@@ -1,11 +0,0 @@
package com.github.alathra.siegeengines.projectile;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
public interface GunnersProjectile {
public void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity);
public String ProjectileType = "Default";
}
@@ -18,15 +18,19 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
public class PotionProjectile implements GunnersProjectile {
public String ProjectileType = "Potion";
public class PotionProjectile extends SiegeEngineProjectile {
public int EntityCount = 3;
public Boolean DelayedFire = false;
public int DelayTime = 6;
public float Inaccuracy = 0.1f;
public Particle ParticleType = Particle.EXPLOSION_LARGE;
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
public PotionProjectile(ItemStack ammunitionItem) {
super(ProjectileType.POTION, ammunitionItem);
}
@Override
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
//TODO Auto-generated method stub
@@ -68,4 +72,8 @@ public class PotionProjectile implements GunnersProjectile {
private Vector Randomise() {
return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1));
}
public ProjectileType getProjectileType() {
return projectileType;
}
}
@@ -0,0 +1,5 @@
package com.github.alathra.siegeengines.projectile;
public enum ProjectileType {
DEFAULT, ENTITY, EXPLOSIVE, POTION;
}
@@ -0,0 +1,29 @@
package com.github.alathra.siegeengines.projectile;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public abstract class SiegeEngineProjectile {
protected ProjectileType projectileType;
protected ItemStack ammunitionItem;
public SiegeEngineProjectile(ProjectileType projectileType, @NotNull ItemStack ammunitionItem ) {
this.projectileType = projectileType;
this.ammunitionItem = ammunitionItem;
}
public abstract void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity);
public ProjectileType getType() {
return projectileType;
}
public ItemStack getAmmuinitionItem() {
return ammunitionItem;
}
}