siege system changes

This commit is contained in:
NewGarbo 2016-02-21 20:33:52 +00:00
parent db7382d01e
commit 76cf65c267
5 changed files with 124 additions and 59 deletions

View File

@ -17,14 +17,17 @@ import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.Cannon;
import mineplex.game.clans.clans.siege.weapon.Catapult;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.core.repository.ClanTerritory;
public class SiegeManager extends MiniPlugin
{
@ -174,6 +177,14 @@ public class SiegeManager extends MiniPlugin
return false;
}
ClanTerritory claim = _clansManager.getClanUtility().getClaim(location);
if (claim != null && !claim.Owner.equals(_clansManager.getClan(player).getName()))
{
UtilPlayer.message(player, F.main("Clans", "You must place a Cannon in the Wilderness or your own Territory."));
return false;
}
spawnCannon(player, location);
return true;
@ -190,7 +201,15 @@ public class SiegeManager extends MiniPlugin
{
if (!_clansManager.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a CanCatapultnon."));
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Catapult."));
return false;
}
ClanTerritory claim = _clansManager.getClanUtility().getClaim(location);
if (claim != null && !claim.Owner.equals(_clansManager.getClan(player).getName()))
{
UtilPlayer.message(player, F.main("Clans", "You must place a Catapult in the Wilderness or your own Territory."));
return false;
}

View File

@ -38,7 +38,7 @@ public class SiegeWeaponRepository extends RepositoryBase
private static final String GET_WEAPONS_BY_SERVER = "SELECT * FROM clansSiegeWeapons WHERE serverId=?;";
private static final String UPDATE_WEAPON = "UPDATE clansSiegeWeapons SET health=?,yaw=?,lastFired=? WHERE uniqueId=?;";
private static final String INSERT_WEAPON = "INSERT INTO clansSiegeWeapons VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
private static final String INSERT_WEAPON = "INSERT INTO clansSiegeWeapons VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
private static final String DELETE_WEAPON = "DELETE FROM clansSiegeWeapons WHERE uniqueId=?;";

View File

@ -4,9 +4,11 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
@ -19,6 +21,7 @@ import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEnt;
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;
@ -28,7 +31,6 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
@ -40,6 +42,8 @@ public class Cannon extends SiegeWeapon
{
public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build();
private int _firepower = 1;
public Cannon(SiegeManager siegeManager, SiegeWeaponToken token)
{
super(1400, "Cannon", token, siegeManager.getClansManager(), siegeManager);
@ -49,12 +53,8 @@ public class Cannon extends SiegeWeapon
setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1));
setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0));
setFirepowerType(Material.SULPHUR);
setAmmunitionType(Material.TNT);
setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7));
setMaximumFirepowerPerSlot(3);
setAmmunitionSlot(4);
setMaximumAmmunitionPerSlot(1);
@ -178,6 +178,66 @@ public class Cannon extends SiegeWeapon
}));
}
@EventHandler
protected void InventoryClick(InventoryClickEvent event)
{
if (!event.getClickedInventory().equals(_inventory))
{
return;
}
if (event.getSlot() == 0)
{
int oldFirepower = _firepower;
_firepower = UtilMath.clamp(--_firepower, 1, 3);
if (oldFirepower != _firepower)
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}
else
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f);
}
event.setCancelled(true);
}
else if (event.getSlot() == 1)
{
event.setCancelled(true);
}
else if (event.getSlot() == 2)
{
int oldFirepower = _firepower;
_firepower = UtilMath.clamp(++_firepower, 1, 3);
if (oldFirepower != _firepower)
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f);
}
else
{
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f);
}
event.setCancelled(true);
}
}
private void updateInventory()
{
_inventory.setItem(0, new ItemBuilder(Material.LEVER).setTitle(C.cRed + "-1 Firepower").build());
_inventory.setItem(1, new ItemBuilder(Material.SULPHUR).setTitle(C.cWhiteB + "Firepower: " + C.cYellow + _firepower).build());
_inventory.setItem(2, new ItemBuilder(Material.LEVER).setTitle(C.cGreen + "+1 Firepower").build());
}
protected boolean CustomInventoryValid(int slot, ItemStack item)
{
return slot == 0 || slot == 1 || slot == 2;
}
private void loadEntities()
{
Slime filler = _location.getWorld().spawn(_location, Slime.class);
@ -260,9 +320,16 @@ public class Cannon extends SiegeWeapon
return "Unloaded";
}
protected int getPowerLevel()
{
return _firepower;
}
@Override
protected void Tick()
{
updateInventory();
if (getProjectile() != null)
{
UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);

View File

@ -18,6 +18,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
@ -195,7 +196,7 @@ public abstract class SiegeWeapon implements Listener
protected void damage(Player player)
{
int health = 1 + UtilMath.random.nextInt(10);
int health = 3 + UtilMath.random.nextInt(10);
removeHealth(health);
@ -249,13 +250,10 @@ public abstract class SiegeWeapon implements Listener
if (_inventory != null)
{
checkInv();
checkInventory();
}
if (getEntity("PLAYERMOUNT").getPassenger() != null)
{
_rider = (Player) getEntity("PLAYERMOUNT").getPassenger();
}
_rider = (Player) getEntity("PLAYERMOUNT").getPassenger();
if (!getNextState().equals(_currentState))
{
@ -480,6 +478,11 @@ public abstract class SiegeWeapon implements Listener
}
}
protected boolean CustomInventoryValid(int slot, ItemStack item)
{
return false;
}
private void dismount(Player player)
{
player.teleport(player.getLocation().add(0, 1, 0));
@ -658,7 +661,7 @@ public abstract class SiegeWeapon implements Listener
return _registeredStates.get(state);
}
public void checkInv()
public void checkInventory()
{
for (int slot = 0; slot < _inventory.getSize(); slot++)
{
@ -673,6 +676,11 @@ public abstract class SiegeWeapon implements Listener
{
if (item.getType() != _ammunitionType)
{
if (CustomInventoryValid(slot, item))
{
continue;
}
if (getRider() != null)
{
getRider().getInventory().addItem(item);
@ -705,6 +713,11 @@ public abstract class SiegeWeapon implements Listener
{
if (item.getType() != _firepowerType)
{
if (CustomInventoryValid(slot, item))
{
continue;
}
if (getRider() != null)
{
getRider().getInventory().addItem(item);
@ -735,6 +748,11 @@ public abstract class SiegeWeapon implements Listener
}
else
{
if (CustomInventoryValid(slot, item))
{
continue;
}
if (getRider() != null)
{
getRider().getInventory().addItem(item);
@ -754,37 +772,13 @@ public abstract class SiegeWeapon implements Listener
@EventHandler
public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event)
{
if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _location.clone().subtract(4, 2, 4), _location.clone().add(4, 2, 4)))
if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _location.clone().subtract(3, 2, 3), _location.clone().add(3, 2, 3)))
{
if (getHealth() > 750)
{
event.setCancelled(true);
}
kill();
int hprem = _baseDamage /* base damage */;
/* randomness */
hprem += UtilMath.random.nextInt(250);
/* distance calc */
double dist = UtilMath.offset2d(event.getProjectile().getLocation(), _location);
dist = Math.min(dist, 3);
hprem -= (400.d /* max damage loss caused by distance */ / 3.d) * dist;
removeHealth(hprem);
if (_alive)
{
UtilTextMiddle.display("Damage", "You damaged " + F.elem(getOwner().getName()) + "'s " + _name + " for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + getHealth() + C.cGray + ")", 10, 60, 10, event.getWeapon().getRider());
UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You damaged " + F.elem(getOwner().getName()) + "'s " + _name + " for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + getHealth() + C.cGray + ")"));
}
else
{
UtilTextMiddle.display("Damage", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".", 10, 60, 10, event.getWeapon().getRider());
UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + "."));
}
_ownerClan.inform("One of your Cannons has been destroyed!", null);
UtilTextMiddle.display("Damage", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".", 10, 60, 10, event.getWeapon().getRider());
UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + "."));
}
}

View File

@ -165,21 +165,6 @@ public class Gameplay extends MiniPlugin
if (event.getEntity() instanceof Player)
{
Player player = (Player) event.getEntity();
for (int slot = 0; slot < player.getInventory().getSize(); slot++)
{
ItemStack item = player.getInventory().getItem(slot);
if (item == null)
{
continue;
}
if (item.isSimilar(Outpost.SIEGE_DECLARATION_ARROW))
{
return;
}
}
ClientClass playerClass = _clansManager.getClassManager().Get(player);