catapult implemented using new siege weapon system, cannons polished up. not tested completely. don't expect this code to work fully haaha

This commit is contained in:
NewGarbo 2016-02-03 15:28:53 +00:00
parent 6bba486385
commit 38cae1e3a2
12 changed files with 178 additions and 1044 deletions

View File

@ -59,7 +59,6 @@ public class BarrierCollisionBox implements Listener
public void Destruct()
{
System.out.println("Destructing...");
HandlerList.unregisterAll(this);
resetBlocks();
@ -96,13 +95,11 @@ public class BarrierCollisionBox implements Listener
private void onLeftClick(Location location, Player player)
{
System.out.println("Collision Box Left");
_leftClickListeners.forEach(listener -> listener.accept(location, player));
}
private void onRightClick(Location location, Player player)
{
System.out.println("Collision Box Right");
_rightClickListeners.forEach(listener -> listener.accept(location, player));
}
@ -155,10 +152,6 @@ public class BarrierCollisionBox implements Listener
onLeftClick(event.getBlock().getLocation(), event.getPlayer());
event.setCancelled(true);
}
else
{
System.out.println("BlockDamage: NOT IN BOX");
}
}
@EventHandler
@ -169,10 +162,6 @@ public class BarrierCollisionBox implements Listener
onLeftClick(event.getBlock().getLocation(), event.getPlayer());
event.setCancelled(true);
}
else
{
System.out.println("BlockBreak: NOT IN BOX");
}
}
@EventHandler
@ -188,10 +177,6 @@ public class BarrierCollisionBox implements Listener
onRightClick(event.getClickedBlock().getLocation(), event.getPlayer());
event.setCancelled(true);
}
else
{
System.out.println("PlayerInteract: NOT IN BOX");
}
}
public BarrierCollisionBox add(Location... location)

View File

@ -22,6 +22,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.weapon.AccessRule;
import mineplex.game.clans.clans.siege.weapon.AccessType;
import mineplex.game.clans.clans.siege.weapon.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
@ -142,6 +143,8 @@ public class Cannon extends SiegeWeapon
@Override
public void Fire(WeaponProjectile projectile)
{
projectile.setLocation(projectile.getLocation().add(.5, .2, .5));
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX);
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f));
}
@ -162,7 +165,6 @@ public class Cannon extends SiegeWeapon
{
if (getProjectile() != null)
{
System.out.println("ye");
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);
}
}
@ -172,7 +174,26 @@ public class Cannon extends SiegeWeapon
{
int firepower = getPowerLevel();
return new double[] { firepower, firepower };
double hMult = 0;
double yAdd = 0;
if (firepower == 1)
{
hMult = 0.6;
yAdd = 0.5;
}
else if (firepower == 2)
{
hMult = 1;
yAdd = 0.55;
}
else if (firepower >= 3)
{
hMult = 1.5;
yAdd = 0.6;
}
return new double[] { hMult, yAdd };
}
}

View File

@ -1,162 +0,0 @@
package mineplex.game.clans.clans.siege.cannon;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
public class CannonCrater implements Listener
{
private static final double EXPL_RADIUS = 3;
public static final Material CHARRED_TYPE = Material.OBSIDIAN;
private Cannon _host;
private Location _origin;
private long _birthTime;
private List<CraterBlock> _blocks;
public CannonCrater(Cannon cannon, Location origin)
{
_host = cannon;
_origin = origin;
_birthTime = System.currentTimeMillis();
_blocks = new ArrayList<>();
UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
createExplosion();
}
@EventHandler
public void updateEffects(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
_blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> {
long lifetime = System.currentTimeMillis() - _birthTime;
long max = 80000;
if (block.Location.getBlock().getType() != CHARRED_TYPE)
{
return;
}
// Water touching the charred blocks
if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext())
{
return;
}
if (lifetime < max)
{
UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX);
UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX);
}
else
{
HandlerList.unregisterAll(this);
}
});
}
private void createExplosion()
{
_blocks.add(new CraterBlock(_origin, 0, Material.AIR));
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
int iR = (int) EXPL_RADIUS + 1;
for (int x = -iR; x <= iR; x++)
{
for (int z = -iR; z <= iR; z++)
{
for (int y = -iR; y <= iR; y++)
{
Block curBlock = _origin.getBlock().getRelative(x, y, z);
double offset = UtilMath.offset(_origin, curBlock.getLocation());
if (offset <= EXPL_RADIUS)
{
blockList.put(curBlock, offset);
}
}
}
}
for (Entry<Block, Double> entry : blockList.entrySet())
{
Block block = entry.getKey();
double distance = entry.getValue();
boolean air = distance <= 2 || (Math.random() > (distance) / 3.65d);
if (block.getType() == Material.AIR) continue;
if (air)
{
_blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR));
Block above = block;
while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType()))
{
_blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR));
}
}
}
_blocks.forEach(CraterBlock::set);
for (Entry<Block, Double> entry : blockList.entrySet())
{
Block block = entry.getKey();
double distance = entry.getValue();
if (block.getType() == Material.AIR) continue;
if (
distance > 2 &&
Math.random() > .75 &&
UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) &&
!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) &&
!block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) &&
!block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE))
{
_blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE));
}
}
_blocks.forEach(CraterBlock::set);
}
}

View File

@ -1,34 +0,0 @@
package mineplex.game.clans.clans.siege.cannon;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public enum CannonState
{
UNLOADED(Material.SPONGE, (byte) 1 /* wet sponge */),
LOADED(Material.SPONGE, (byte) 0 /* regular sponge */);
private Material _material;
private byte _data;
CannonState(Material material, byte data)
{
_material = material;
_data = data;
}
public byte getData()
{
return _data;
}
public Material getMaterial()
{
return _material;
}
public ItemStack toItemStack()
{
return new ItemStack(_material, 1, (short) 0, _data);
}
}

View File

@ -1,32 +0,0 @@
package mineplex.game.clans.clans.siege.cannon;
import org.bukkit.Location;
import org.bukkit.Material;
public class CraterBlock
{
public Material Type;
public byte Data;
public double DistanceToOrigin;
public Location Location;
public CraterBlock(Location location, double dist, Material type, byte data)
{
Location = location;
DistanceToOrigin = dist;
Type = type;
Data = data;
}
public CraterBlock(Location location, double dist, Material type)
{
this(location, dist, type, (byte) 0);
}
public void set()
{
Location.getBlock().setType(Type);
Location.getBlock().setData(Data);
}
}

View File

@ -1,549 +1,205 @@
package mineplex.game.clans.clans.siege.catapult;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.entity.Slime;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.hologram.Hologram;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.siege.BarrierCollisionBox;
import mineplex.game.clans.clans.siege.weapon.AccessRule;
import mineplex.game.clans.clans.siege.weapon.AccessType;
import mineplex.game.clans.clans.siege.weapon.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.clans.siege.weapon.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.WeaponStateInfo;
public class Catapult implements Listener
public class Catapult extends SiegeWeapon
{
public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build();
public static final int COOLDOWN = 10 * 1000 /* 20 seconds*/;
public static final int MAX_CHARGES = 3;
public static final int MAX_COBBLE = 1;
public static final double MAX_HEALTH = 600;
public static final int COBBLE_SLOT = 4;
public static final List<Integer> CHARGE_SLOTS = Arrays.asList(1, 3, 5, 7);
public static final List<Integer> EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8);
private static final double[] VERT_POWER = { 0.9, 1.25631, 1.5382 };
private static final double[] HORIZ_POWER = { 1.2, 1.6241, 1.9231 };
private List<Float> _rotationPoints;
private Location _location;
private CatapultState _state;
private float _curYaw;
private float _nextYaw;
// Entity Information
private List<Entity> _entities;
private CatapultProjectile _projectile;
private Inventory _inventory;
private long _lastFired = -1;
private ClanInfo _clan;
private double _health = MAX_HEALTH;
private Hologram _healthHologram;
private BarrierCollisionBox _collisionBox;
public Catapult(Location location, ClanInfo clan)
{
_location = location;
_state = CatapultState.UNLOADED;
super(location, 600.d, "Catapult", clan, clan.Clans);
_rotationPoints = new ArrayList<>();
_entities = new ArrayList<>();
location.add(.5, 0, .5);
_collisionBox = BarrierCollisionBox.all(_location.clone().subtract(1, 0, 1), _location.clone().add(1.5, 2, 1.5));
_collisionBox.Construct();
_collisionBox.registerRight((block, player) -> handleOpenInv(player));
_collisionBox.registerLeft((block, player) -> handleLeftClick(player, -1));
setBoundingBox(1);
for (int i = 0; i < 20; i++)
{
_rotationPoints.add((360.f / 20.f) * i);
}
setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0));
setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0));
setStateInfo("Fired", new WeaponStateInfo(Material.LAPIS_BLOCK, (byte) 0));
_inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Catapult");
loadEntities();
_clan = clan;
setFirepowerType(Material.FIREBALL);
setAmmunitionType(Material.COBBLESTONE);
_healthHologram = new Hologram(ClansManager.getInstance().getHologramManager(), location.clone().add(.5, 3.7, .5), "Catapult Health", getDisplayHealth());
_healthHologram.start();
setFirepowerSlots(1, 3, 5, 7);
setMaximumFirepowerPerSlot(3);
updateEntities();
}
public void cleanup()
{
_entities.forEach(Entity::remove);
setAmmunitionSlot(4);
setMaximumAmmunitionPerSlot(1);
_entities.clear();
setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(1.5d));
_healthHologram.stop();
_healthHologram = null;
_collisionBox.Destruct();
HandlerList.unregisterAll(this);
}
private void updateEntities()
{
if (_entities.isEmpty())
{
ArmorStand armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class);
UtilEnt.setFakeHead(armorStand, true);
armorStand.teleport(getArmorStandLocation());
armorStand.setVisible(false);
armorStand.setGravity(false);
armorStand.setHelmet(_state.toItemStack());
_entities.add(armorStand);
}
else
{
getArmorStand().setHelmet(_state.toItemStack());
}
}
private CraftArmorStand getArmorStand()
{
return (CraftArmorStand) UtilMath.getFirst(_entities);
}
private Location getArmorStandLocation()
{
return _location.clone().add(.5, -.65, .5);
}
private void setState(CatapultState state)
{
_state = state;
updateEntities();
}
public void fire()
{
CatapultProjectile projectile = new CatapultProjectile(this, _location.clone().add(.5, 3, .5), Material.COBBLESTONE, (float) Math.toDegrees(getArmorStand().getHeadPose().getY()));
_projectile = projectile;
double vVel = VERT_POWER[getPower() - 1];
double hMulti = HORIZ_POWER[getPower() - 1];
Vector velocity = UtilAlg.getTrajectory(
getArmorStand().getLocation(),
UtilAlg.moveForward(
getArmorStand().getLocation(),
2.,
(float) Math.toDegrees(getArmorStand().getHeadPose().getY()), true))
.multiply(hMulti)
.setY(vVel);
projectile.setVelocity(velocity);
_inventory.setItem(COBBLE_SLOT, UtilInv.decrement(_inventory.getItem(COBBLE_SLOT)));
CHARGE_SLOTS.forEach(_inventory::clear);
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getArmorStandLocation(), Sound.BAT_TAKEOFF, 1.f, 1.f));
_lastFired = System.currentTimeMillis();
}
@EventHandler
public void onCloseInv(InventoryCloseEvent event)
{
if (!event.getInventory().equals(_inventory))
{
return;
}
ClansManager.getInstance().runSyncLater(() -> {
if (event.getPlayer().getInventory().equals(_inventory))
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
if (!_owner.isMember(player))
{
return;
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false;
}
if (canBeFired())
if (!canBeFired())
{
UtilTextMiddle.display("Catapult Ready", "Power Level: " + C.cGreen + UtilText.repeat("", getPower()) + C.cRed + UtilText.repeat("", MAX_CHARGES - getPower()), 20, 100, 20, (Player) event.getPlayer());
}
}, 3L);
}
public void updateProjectile()
{
if (_projectile != null)
{
if (_projectile.dead())
{
_projectile = null;
return;
UtilPlayer.message(player, F.main("Clans", "Catapult is not loaded correctly."));
return false;
}
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);
}
}
private void attemptFire(Player human)
{
if (!_clan.isMember(human))
{
UtilPlayer.message(human, F.main("Clans", "This catapult is not owned by your Clan."));
return;
}
if (System.currentTimeMillis() - _lastFired < COOLDOWN)
{
UtilPlayer.message(human, F.main("Clans", "Catapult is cooling down. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + C.mBody + ")")));
return;
}
fire();
}
private void handleOpenInv(Player player)
{
if (_inventory == null)
{
cleanup();
return;
}
if (!_clan.isMember(player))
{
UtilPlayer.message(player, F.main("Clans", "This catapult is not owned by your Clan."));
return;
}
if (!_inventory.getViewers().isEmpty())
{
UtilPlayer.message(player, F.main("Clans", "Someone is already looking in this catapult."));
return;
}
player.openInventory(_inventory);
}
private int getPower()
{
int power = 0;
for (int slot : CHARGE_SLOTS)
{
if (_inventory.getItem(slot) != null)
if (System.currentTimeMillis() - _lastFired < 20000)
{
power += _inventory.getItem(slot).getAmount();
}
}
return power / 4;
}
private int getCobblestone()
{
return _inventory.getItem(COBBLE_SLOT) != null ? _inventory.getItem(COBBLE_SLOT).getAmount() : 0;
}
private boolean canBeFired()
{
return getCobblestone() > 0 && getPower() > 0 && _projectile == null;
}
@EventHandler
public void updateState(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
CatapultState newState = _inventory.getItem(COBBLE_SLOT) != null ? CatapultState.LOADED : CatapultState.UNLOADED;
if ((System.currentTimeMillis() - _lastFired) <= 3000)
{
newState = CatapultState.FIRED;
}
if (_state != newState)
{
setState(newState);
}
if (!_inventory.getViewers().isEmpty())
{
checkInv((Player) _inventory.getViewers().get(0));
}
updateProjectile();
}
public void checkInv(Player human)
{
for (int slot = 0; slot < 9; slot++)
{
ItemStack item = _inventory.getItem(slot);
if (item == null)
{
continue;
UtilPlayer.message(player, F.main("Clans", "Catapult is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")"));
return false;
}
if (slot == COBBLE_SLOT)
if (!isRiding(player))
{
if (item.getType() != Material.COBBLESTONE)
{
human.getInventory().addItem(item);
_inventory.setItem(slot, null);
}
else
{
if (item.getAmount() > MAX_CHARGES)
{
human.getInventory().addItem(new ItemStack(Material.COBBLESTONE, item.getAmount() - MAX_COBBLE));
_inventory.setItem(slot, new ItemStack(Material.COBBLESTONE, MAX_COBBLE));
}
}
return false;
}
else if (CHARGE_SLOTS.contains(slot))
return true;
}));
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_owner.isMember(player))
{
if (item.getType() != Material.FIREBALL)
{
human.getInventory().addItem(item);
_inventory.setItem(slot, null);
}
else
{
if (item.getAmount() > MAX_CHARGES)
{
human.getInventory().addItem(new ItemStack(Material.FIREBALL, item.getAmount() - MAX_CHARGES));
_inventory.setItem(slot, new ItemStack(Material.FIREBALL, MAX_CHARGES));
}
}
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false;
}
else if (EMPTY_SLOTS.contains(slot)) // also classes as just an 'else{}'
if (getRider() != null && !getRider().equals(player))
{
human.getInventory().addItem(item);
_inventory.setItem(slot, null);
UtilPlayer.message(player, F.main("Clans", "Someone is already riding this Catapult."));
return false;
}
return !player.equals(getRider());
}));
System.out.println("Cannon initialized.");
}
private void loadEntities()
{
Slime slime = _location.getWorld().spawn(_location, Slime.class);
UtilEnt.silence(slime, true);
UtilEnt.Vegetate(slime);
slime.setSize(-1);
slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
addEntity(slime, "Filler");
slime = _location.getWorld().spawn(_location, Slime.class);
UtilEnt.silence(slime, true);
UtilEnt.Vegetate(slime);
slime.setSize(-1);
slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
getEntity("Filler").setPassenger(slime);
addEntity(slime, "PLAYERMOUNT");
ArmorStand armorStand = _location.getWorld().spawn(_location, ArmorStand.class);
UtilEnt.setFakeHead(armorStand, true);
armorStand.teleport(_location);
armorStand.setVisible(false);
armorStand.setGravity(false);
armorStand.setPassenger(getEntity("Filler"));
addEntity(armorStand, "WEAPON");
}
@Override
public void Fire(WeaponProjectile projectile)
{
projectile.setLocation(projectile.getLocation().add(.5, .2, .5));
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX);
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f));
}
@Override
public String getNextState()
{
if (System.currentTimeMillis() - _lastFired < 4500)
{
return "Fired";
}
if (getAmmunition() > 0)
{
return "Loaded";
}
return "Unloaded";
}
@Override
protected void Tick()
{
if (getProjectile() != null)
{
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);
}
}
@EventHandler
public void onInteract(PlayerInteractAtEntityEvent event)
{
if (_entities.contains(event.getRightClicked()))
@Override
protected double[] getProjectileVelocity()
{
int firepower = getPowerLevel();
double hMult = 0;
double yAdd = 0;
if (firepower == 1)
{
handleOpenInv(event.getPlayer());
event.setCancelled(true);
hMult = 0.6;
yAdd = 0.8;
}
else if (firepower == 2)
{
hMult = 1;
yAdd = 1.2;
}
else if (firepower >= 3)
{
hMult = 1.5;
yAdd = 1.35;
}
return new double[] { hMult, yAdd };
}
@EventHandler
public void onInteract(PlayerInteractEntityEvent event)
{
if (_entities.contains(event.getRightClicked()))
{
handleOpenInv(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler
public void onInteract(PlayerArmorStandManipulateEvent event)
{
if (_entities.contains(event.getRightClicked()))
{
handleOpenInv(event.getPlayer());
event.setCancelled(true);
}
}
public void handleLeftClick(Player player, double damage)
{
if (!_clan.isMember(player))
{
removeHealth(damage == -1 ? calcDmg(player) : damage);
}
else
{
attemptFire(player);
}
}
private double calcDmg(Player player)
{
ItemStack item = player.getItemInHand();
if (item == null)
{
return 1;
}
double dmg = UtilItem.getAttackDamage(item.getType());
switch(item.getType())
{
case RECORD_4:
dmg += 7;
case GREEN_RECORD:
dmg += 6;
case GOLD_RECORD:
dmg += 9;
case RECORD_3:
dmg += 1;
case RECORD_5:
dmg += 7;
default:
}
return dmg;
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
ArmorStand armorStand = getArmorStand();
double standYaw = _curYaw % 360;
double nextYaw = _nextYaw % 360;
// riderYaw = 350 and standYaw = 20
// dif should be -30 and not 330
double dif = nextYaw - standYaw;
if (dif > 180) dif -= 360;
if (dif < -180) dif += 360;
_curYaw = (float) (standYaw + Math.min(dif / 10.f, 4f));
armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(_curYaw), 0));
}
@EventHandler
public void onDamage(EntityDamageEvent event)
{
if (_entities.contains(event.getEntity()))
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onDmg(EntityDamageByEntityEvent event)
{
if (!(event.getDamager() instanceof Player))
{
return;
}
if (!_entities.contains(event.getEntity()))
{
return;
}
if (!_clan.isMember((Player) event.getDamager()))
{
removeHealth(event.getFinalDamage());
}
if (!_clan.isMember((Player) event.getDamager()))
{
UtilPlayer.message((Player) event.getDamager(), F.main("Clans", "This catapult is not owned by your Clan."));
return;
}
if (canBeFired())
attemptFire((Player) event.getDamager());
else
_nextYaw = ((Player) event.getDamager()).getLocation().getYaw();
}
// Health Managemnet
public double getHealth()
{
return _health;
}
public String getDisplayHealth()
{
return UtilText.getProgress(null, _health / MAX_HEALTH, null, false, 12);
}
public void setHealth(double health)
{
_health = UtilMath.clamp(health, 0, MAX_HEALTH);
_healthHologram.setText("Catapult Health", getDisplayHealth());
if (_health == 0)
{
cleanup();
}
}
public void removeHealth(double health)
{
setHealth(_health - health);
}
public void addHealth(double health)
{
setHealth(_health + health);
}
}

View File

@ -1,163 +0,0 @@
package mineplex.game.clans.clans.siege.catapult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.cannon.CraterBlock;
public class CatapultCrater implements Listener
{
private static final double EXPL_RADIUS = 3;
public static final Material CHARRED_TYPE = Material.OBSIDIAN;
private Catapult _host;
private Location _origin;
private long _birthTime;
private List<CraterBlock> _blocks;
public CatapultCrater(Catapult cannon, Location origin)
{
_host = cannon;
_origin = origin;
_birthTime = System.currentTimeMillis();
_blocks = new ArrayList<>();
UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
createExplosion();
}
@EventHandler
public void updateEffects(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
_blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> {
long lifetime = System.currentTimeMillis() - _birthTime;
long max = 80000;
if (block.Location.getBlock().getType() != CHARRED_TYPE)
{
return;
}
// Water touching the charred blocks
if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext())
{
return;
}
if (lifetime < max)
{
UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX);
UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX);
}
else
{
HandlerList.unregisterAll(this);
}
});
}
private void createExplosion()
{
_blocks.add(new CraterBlock(_origin, 0, Material.AIR));
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
int iR = (int) EXPL_RADIUS + 1;
for (int x = -iR; x <= iR; x++)
{
for (int z = -iR; z <= iR; z++)
{
for (int y = -iR; y <= iR; y++)
{
Block curBlock = _origin.getBlock().getRelative(x, y, z);
double offset = UtilMath.offset(_origin, curBlock.getLocation());
if (offset <= EXPL_RADIUS)
{
blockList.put(curBlock, offset);
}
}
}
}
for (Entry<Block, Double> entry : blockList.entrySet())
{
Block block = entry.getKey();
double distance = entry.getValue();
boolean air = distance <= 1.5 || (Math.random() > (distance) / 3.65d);
if (block.getType() == Material.AIR) continue;
if (air)
{
_blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR));
Block above = block;
while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType()))
{
_blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR));
}
}
}
_blocks.forEach(CraterBlock::set);
for (Entry<Block, Double> entry : blockList.entrySet())
{
Block block = entry.getKey();
double distance = entry.getValue();
if (block.getType() == Material.AIR) continue;
if (
distance > 1 &&
Math.random() > .85 &&
UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) &&
!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) &&
!block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) &&
!block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE))
{
_blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE));
_blocks.add(new CraterBlock(block.getLocation().clone().add(0, 1, 0), distance, Material.FIRE));
}
}
_blocks.forEach(CraterBlock::set);
}
}

View File

@ -1,97 +0,0 @@
package mineplex.game.clans.clans.siege.catapult;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
public class CatapultProjectile implements Listener
{
private FallingBlock _sand;
private Catapult _host;
public CatapultProjectile(Catapult host, Location location, Material material, float yaw)
{
_host = host;
_sand = location.getWorld().spawnFallingBlock(location, material, (byte) 0);
_sand.setDropItem(false);
UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
}
@EventHandler
public void update(UpdateEvent event)
{
if (_sand.getTicksLived() >= 20 && UtilBlock.getInRadius(_sand.getLocation(), 1.5).keySet().stream().filter(block -> !UtilItem.isBoundless(block.getType())).iterator().hasNext() && Math.abs(_sand.getVelocity().getX()) < 0.05 || Math.abs(_sand.getVelocity().getZ()) < 0.05)
{
remove();
}
else if (_sand.isDead())
{
remove();
}
}
@EventHandler
public void onBlockFall(EntityChangeBlockEvent event)
{
if (event.getEntity().equals(_sand))
{
event.setCancelled(true);
remove();
}
}
public void remove()
{
HandlerList.unregisterAll(this);
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getLocation(), Sound.EXPLODE, 1.f, 1.f));
new CatapultCrater(_host, _sand.getLocation());
_sand.remove();
_sand = null;
}
public boolean dead()
{
return _sand == null || _sand.isDead();
}
public Location getLocation()
{
return _sand.getLocation();
}
public Vector getVelocity()
{
return _sand.getVelocity();
}
public int getTicksLived()
{
return _sand.getTicksLived();
}
public void setVelocity(Vector velocity)
{
_sand.setVelocity(velocity);
}
}

View File

@ -1,35 +0,0 @@
package mineplex.game.clans.clans.siege.catapult;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public enum CatapultState
{
UNLOADED(Material.PACKED_ICE, (byte) 0),
LOADED(Material.ENDER_PORTAL_FRAME, (byte) 0),
FIRED(Material.LAPIS_BLOCK, (byte) 1);
private Material _material;
private byte _data;
CatapultState(Material material, byte data)
{
_material = material;
_data = data;
}
public byte getData()
{
return _data;
}
public Material getMaterial()
{
return _material;
}
public ItemStack toItemStack()
{
return new ItemStack(_material, 1, (short) 0, _data);
}
}

View File

@ -1,11 +1,9 @@
package mineplex.game.clans.clans.siege.cannon;
package mineplex.game.clans.clans.siege.weapon;
import java.util.function.Predicate;
import org.bukkit.entity.Player;
import mineplex.game.clans.clans.siege.weapon.AccessType;
public class AccessRule
{
private Predicate<Player> _access;

View File

@ -38,7 +38,6 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.BarrierCollisionBox;
import mineplex.game.clans.clans.siege.cannon.AccessRule;
public abstract class SiegeWeapon implements Listener
{
@ -180,7 +179,10 @@ public abstract class SiegeWeapon implements Listener
protected boolean canBeFired()
{
return getPowerLevel() > 0 && _projectile == null;
System.out.println(getPowerLevel());
System.out.println(getAmmunition());
return getPowerLevel() > 0 && getAmmunition() > 0 && _projectile == null;
}
protected WeaponProjectile getProjectile()
@ -260,7 +262,7 @@ public abstract class SiegeWeapon implements Listener
{
ItemStack item = _inventory.getItem(slot);
if (item == null || !item.getType().equals(_ammunitionType))
if (item == null || !item.getType().equals(_firepowerType))
{
continue;
}
@ -268,11 +270,7 @@ public abstract class SiegeWeapon implements Listener
power += _inventory.getItem(slot).getAmount();
}
if (UtilMath.isOdd(power))
{
power -= 4;
}
System.out.println("Power: " + power);
return power / 4;
}
@ -350,7 +348,7 @@ public abstract class SiegeWeapon implements Listener
return;
}
if (_fireAccess.allow(AccessType.RCLICK_BB, player) && canBeFired())
if (_fireAccess.allow(AccessType.RCLICK_BB, player))
{
fire(player);
}
@ -372,7 +370,7 @@ public abstract class SiegeWeapon implements Listener
return;
}
if (_fireAccess.allow(AccessType.LCLICK_BB, player) && canBeFired())
if (_fireAccess.allow(AccessType.LCLICK_BB, player))
{
fire(player);
return;

View File

@ -19,7 +19,6 @@ import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.siege.cannon.CannonCrater;
public class WeaponProjectile implements Listener
{