Fully implemented Sneaky Assassins Power-Ups
This commit is contained in:
parent
fe1bf95342
commit
38e4240a61
@ -1,61 +0,0 @@
|
||||
package nautilus.game.arcade.game.games.sneakyassassins;
|
||||
|
||||
import mineplex.core.common.util.*;
|
||||
import mineplex.core.updater.*;
|
||||
import mineplex.core.updater.event.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.*;
|
||||
|
||||
public class PowerUp
|
||||
{
|
||||
private final PowerUpManager _powerUpManager;
|
||||
private final Location _location;
|
||||
private Location _effectLocation;
|
||||
|
||||
public PowerUp(PowerUpManager powerUpManager, Location location)
|
||||
{
|
||||
_powerUpManager = powerUpManager;
|
||||
_location = location;
|
||||
_effectLocation = getLocation().getBlock().getLocation().add(0.5, 0, 0.5);
|
||||
_effectLocation.setY(250);
|
||||
}
|
||||
|
||||
public PowerUpManager getPowerUpManager()
|
||||
{
|
||||
return _powerUpManager;
|
||||
}
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
return _location;
|
||||
}
|
||||
|
||||
public void activate()
|
||||
{
|
||||
Block block = getLocation().getBlock();
|
||||
|
||||
block.setType(Material.BEACON);
|
||||
for (int x = -1; x <= 1; x++)
|
||||
for (int z = -1; z <= 1; z++)
|
||||
block.getRelative(x, -1, z).setType(Material.IRON_BLOCK);
|
||||
}
|
||||
|
||||
public void onUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() == UpdateType.FASTEST && _effectLocation != null)
|
||||
{
|
||||
FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).with(FireworkEffect.Type.BURST).trail(false).build();
|
||||
UtilFirework.playFirework(_effectLocation, effect);
|
||||
|
||||
_effectLocation.setY(_effectLocation.getY() - 2);
|
||||
|
||||
if (_effectLocation.getY() - getLocation().getY() < 2)
|
||||
{
|
||||
effect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).with(FireworkEffect.Type.BALL_LARGE).trail(true).build();
|
||||
UtilFirework.playFirework(_effectLocation, effect);
|
||||
|
||||
_effectLocation = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package nautilus.game.arcade.game.games.sneakyassassins;
|
||||
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
public class PowerUpSpawn
|
||||
{
|
||||
private Block _beaconBlock;
|
||||
private Item _item;
|
||||
}
|
@ -2,12 +2,31 @@ package nautilus.game.arcade.game.games.sneakyassassins;
|
||||
|
||||
import mineplex.core.common.util.*;
|
||||
import nautilus.game.arcade.*;
|
||||
import nautilus.game.arcade.events.*;
|
||||
import nautilus.game.arcade.game.*;
|
||||
import nautilus.game.arcade.game.games.sneakyassassins.kits.*;
|
||||
import nautilus.game.arcade.game.games.sneakyassassins.powerups.*;
|
||||
import nautilus.game.arcade.kit.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.entity.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SneakyAssassins extends SoloGame
|
||||
{
|
||||
private static final Map<Material, Double> SWORD_DAMAGE = new EnumMap<>(Material.class);
|
||||
|
||||
static
|
||||
{
|
||||
SWORD_DAMAGE.put(Material.WOOD_SWORD, 3.0);
|
||||
SWORD_DAMAGE.put(Material.STONE_SWORD, 4.0);
|
||||
SWORD_DAMAGE.put(Material.GOLD_SWORD, 5.0);
|
||||
SWORD_DAMAGE.put(Material.IRON_SWORD, 6.0);
|
||||
SWORD_DAMAGE.put(Material.DIAMOND_SWORD, 7.0);
|
||||
}
|
||||
|
||||
private PowerUpManager _powerUpManager;
|
||||
|
||||
public SneakyAssassins(ArcadeManager manager)
|
||||
@ -38,4 +57,38 @@ public class SneakyAssassins extends SoloGame
|
||||
{
|
||||
return _powerUpManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGameStateChange(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetGame() == this)
|
||||
{
|
||||
switch (event.GetState())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerAttackWithSword(EntityDamageByEntityEvent event)
|
||||
{
|
||||
if (!(event.getDamager() instanceof Player))
|
||||
return;
|
||||
|
||||
Player damager = (Player) event.getDamager();
|
||||
|
||||
if (GetTeam(damager) == null)
|
||||
return;
|
||||
|
||||
if (damager.getItemInHand() == null)
|
||||
return;
|
||||
|
||||
Double damage = SWORD_DAMAGE.get(damager.getItemInHand().getType());
|
||||
|
||||
if (damage == null)
|
||||
return;
|
||||
|
||||
event.setDamage(damage);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,13 @@ public abstract class SneakyAssassinKit extends Kit
|
||||
{
|
||||
Manager.GetDisguise().disguise(new DisguiseVillager(player));
|
||||
|
||||
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD));
|
||||
player.getInventory().setArmorContents(new ItemStack[]{
|
||||
new ItemStack(Material.LEATHER_BOOTS),
|
||||
new ItemStack(Material.LEATHER_LEGGINGS),
|
||||
new ItemStack(Material.LEATHER_CHESTPLATE),
|
||||
new ItemStack(Material.LEATHER_HELMET)
|
||||
});
|
||||
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.INK_SACK, (byte) 0, 1,
|
||||
C.cYellow + C.Bold + "Right-Click" + C.cWhite + C.Bold + " - " + C.cGreen + C.Bold + "Smoke Bomb",
|
||||
new String[]
|
||||
|
@ -0,0 +1,72 @@
|
||||
package nautilus.game.arcade.game.games.sneakyassassins.powerups;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ArmorPowerUp extends PowerUp
|
||||
{
|
||||
private static final List<List<Material>> ARMOR_PROGRESSION = Arrays.asList(
|
||||
Arrays.asList(
|
||||
Material.LEATHER_BOOTS,
|
||||
Material.CHAINMAIL_BOOTS,
|
||||
Material.IRON_BOOTS
|
||||
),
|
||||
Arrays.asList(
|
||||
Material.LEATHER_LEGGINGS,
|
||||
Material.CHAINMAIL_LEGGINGS,
|
||||
Material.IRON_LEGGINGS
|
||||
),
|
||||
Arrays.asList(
|
||||
Material.LEATHER_CHESTPLATE,
|
||||
Material.CHAINMAIL_CHESTPLATE,
|
||||
Material.IRON_CHESTPLATE
|
||||
),
|
||||
Arrays.asList(
|
||||
Material.LEATHER_HELMET,
|
||||
Material.CHAINMAIL_HELMET,
|
||||
Material.IRON_HELMET
|
||||
)
|
||||
);
|
||||
|
||||
public ArmorPowerUp(PowerUpManager powerUpManager, Location location)
|
||||
{
|
||||
super(powerUpManager, PowerUpType.ARMOR, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void powerUpPlayer(Player player)
|
||||
{
|
||||
powerUpArmor(player);
|
||||
powerUpArmor(player);
|
||||
}
|
||||
|
||||
private void powerUpArmor(Player player)
|
||||
{
|
||||
ItemStack[] armor = player.getInventory().getArmorContents();
|
||||
|
||||
List<Integer> upgradeable = new ArrayList<>();
|
||||
|
||||
for (int level = 0; level < ARMOR_PROGRESSION.get(0).size(); level++)
|
||||
{
|
||||
for (int kind = 0; kind < armor.length; kind++)
|
||||
{
|
||||
if (ARMOR_PROGRESSION.get(kind).get(level) == armor[kind].getType())
|
||||
upgradeable.add(kind);
|
||||
}
|
||||
|
||||
if (!upgradeable.isEmpty())
|
||||
{
|
||||
int choice = upgradeable.get(getPowerUpManager().getRandom().nextInt(upgradeable.size()));
|
||||
int nextLevel = Math.min(ARMOR_PROGRESSION.get(choice).size() - 1, level + 1);
|
||||
|
||||
armor[choice] = new ItemStack(ARMOR_PROGRESSION.get(choice).get(nextLevel));
|
||||
player.getInventory().setArmorContents(armor);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package nautilus.game.arcade.game.games.sneakyassassins.powerups;
|
||||
|
||||
import mineplex.core.common.util.*;
|
||||
import mineplex.core.updater.*;
|
||||
import mineplex.core.updater.event.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.*;
|
||||
import org.bukkit.util.*;
|
||||
|
||||
public abstract class PowerUp
|
||||
{
|
||||
private final PowerUpManager _powerUpManager;
|
||||
private final PowerUpType _powerUpType;
|
||||
private final Location _location;
|
||||
private Location _effectLocation;
|
||||
private Block _beaconBlock;
|
||||
private Item _item;
|
||||
|
||||
public PowerUp(PowerUpManager powerUpManager, PowerUpType powerUpType, Location location)
|
||||
{
|
||||
_powerUpManager = powerUpManager;
|
||||
_powerUpType = powerUpType;
|
||||
_location = location;
|
||||
_effectLocation = getLocation().getBlock().getLocation().add(0.5, 0, 0.5);
|
||||
_effectLocation.setY(250);
|
||||
}
|
||||
|
||||
public PowerUpManager getPowerUpManager()
|
||||
{
|
||||
return _powerUpManager;
|
||||
}
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
return _location;
|
||||
}
|
||||
|
||||
public void activate()
|
||||
{
|
||||
_beaconBlock = getLocation().getBlock();
|
||||
_beaconBlock.setType(Material.BEACON);
|
||||
|
||||
for (int x = -1; x <= 1; x++)
|
||||
for (int z = -1; z <= 1; z++)
|
||||
_beaconBlock.getRelative(x, -1, z).setType(Material.IRON_BLOCK);
|
||||
}
|
||||
|
||||
public void onUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() == UpdateType.FASTEST && _effectLocation != null)
|
||||
{
|
||||
FireworkEffect effect = FireworkEffect
|
||||
.builder()
|
||||
.flicker(false)
|
||||
.withColor(getPowerUpType().getColor())
|
||||
.with(FireworkEffect.Type.BURST)
|
||||
.trail(false)
|
||||
.build();
|
||||
|
||||
UtilFirework.playFirework(_effectLocation, effect);
|
||||
|
||||
_effectLocation.setY(_effectLocation.getY() - 2);
|
||||
|
||||
if (_effectLocation.getY() - getLocation().getY() < 2)
|
||||
{
|
||||
_effectLocation = null;
|
||||
|
||||
Location itemLocation = _beaconBlock.getLocation().add(0.5, 1.5, 0.5);
|
||||
|
||||
effect = FireworkEffect
|
||||
.builder()
|
||||
.flicker(false)
|
||||
.withColor(getPowerUpType().getColor())
|
||||
.with(FireworkEffect.Type.BALL_LARGE)
|
||||
.trail(true)
|
||||
.build();
|
||||
|
||||
UtilFirework.playFirework(itemLocation, effect);
|
||||
|
||||
_item = itemLocation.getWorld().dropItem(itemLocation, new ItemStack(getPowerUpType().getItemType()));
|
||||
_item.setVelocity(new Vector(0, 0.15, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Item getItem()
|
||||
{
|
||||
return _item;
|
||||
}
|
||||
|
||||
public PowerUpType getPowerUpType()
|
||||
{
|
||||
return _powerUpType;
|
||||
}
|
||||
|
||||
public void remove()
|
||||
{
|
||||
if (getItem() != null)
|
||||
{
|
||||
getItem().remove();
|
||||
_item = null;
|
||||
}
|
||||
|
||||
_beaconBlock.setType(Material.AIR);
|
||||
|
||||
getPowerUpManager().removePowerUp(this);
|
||||
}
|
||||
|
||||
public abstract void powerUpPlayer(Player player);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package nautilus.game.arcade.game.games.sneakyassassins;
|
||||
package nautilus.game.arcade.game.games.sneakyassassins.powerups;
|
||||
|
||||
import mineplex.core.updater.*;
|
||||
import mineplex.core.updater.event.*;
|
||||
@ -6,7 +6,10 @@ import nautilus.game.arcade.events.*;
|
||||
import nautilus.game.arcade.game.*;
|
||||
import nautilus.game.arcade.game.Game.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.plugin.*;
|
||||
|
||||
import java.util.*;
|
||||
@ -16,7 +19,7 @@ public class PowerUpManager implements Listener
|
||||
private final Game _game;
|
||||
private final Random _random;
|
||||
private final List<Location> _spawnLocations;
|
||||
private final Set<PowerUp> _powerUps = new HashSet<>();
|
||||
private final List<PowerUp> _powerUps = new ArrayList<>();
|
||||
private Location _lastLocation = null;
|
||||
private int _nextSpawnCountdown = -1;
|
||||
|
||||
@ -41,19 +44,19 @@ public class PowerUpManager implements Listener
|
||||
|
||||
public Location nextLocation()
|
||||
{
|
||||
if (_spawnLocations.size() == 1)
|
||||
_lastLocation = _spawnLocations.get(0);
|
||||
else if (_spawnLocations.size() > 1)
|
||||
if (getSpawnLocations().size() == 1)
|
||||
_lastLocation = getSpawnLocations().get(0);
|
||||
else if (getSpawnLocations().size() > 1)
|
||||
{
|
||||
int index = getRandom().nextInt(_spawnLocations.size());
|
||||
int index = getRandom().nextInt(getSpawnLocations().size());
|
||||
|
||||
if (_lastLocation != null)
|
||||
{
|
||||
while (_spawnLocations.get(index).equals(_lastLocation))
|
||||
index = getRandom().nextInt(_spawnLocations.size());
|
||||
while (getSpawnLocations().get(index).equals(_lastLocation))
|
||||
index = getRandom().nextInt(getSpawnLocations().size());
|
||||
}
|
||||
|
||||
_lastLocation = _spawnLocations.get(index);
|
||||
_lastLocation = getSpawnLocations().get(index);
|
||||
}
|
||||
|
||||
return _lastLocation;
|
||||
@ -66,17 +69,22 @@ public class PowerUpManager implements Listener
|
||||
|
||||
public void spawnNextPowerUp()
|
||||
{
|
||||
PowerUp powerUp = new PowerUp(this, nextLocation());
|
||||
PowerUp powerUp = PowerUpType.values()[getRandom().nextInt(PowerUpType.values().length)].spawn(this, nextLocation());
|
||||
getPowerUps().add(powerUp);
|
||||
|
||||
powerUp.activate();
|
||||
}
|
||||
|
||||
public Set<PowerUp> getPowerUps()
|
||||
public List<PowerUp> getPowerUps()
|
||||
{
|
||||
return _powerUps;
|
||||
}
|
||||
|
||||
boolean removePowerUp(PowerUp powerUp)
|
||||
{
|
||||
return _powerUps.remove(powerUp);
|
||||
}
|
||||
|
||||
public void schedulePowerUpSpawn(int seconds)
|
||||
{
|
||||
_nextSpawnCountdown = seconds;
|
||||
@ -90,8 +98,19 @@ public class PowerUpManager implements Listener
|
||||
@EventHandler
|
||||
public void onGameStateChange(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetGame() == getGame() && event.GetState() == Game.GameState.Live)
|
||||
schedulePowerUpSpawn(5);
|
||||
if (event.GetGame() == getGame())
|
||||
{
|
||||
switch (event.GetState())
|
||||
{
|
||||
case Live:
|
||||
schedulePowerUpSpawn(20);
|
||||
break;
|
||||
|
||||
case Dead:
|
||||
HandlerList.unregisterAll(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -118,4 +137,44 @@ public class PowerUpManager implements Listener
|
||||
if (_game.GetState() == GameState.Dead)
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPowerUpDespawn(ItemDespawnEvent event)
|
||||
{
|
||||
if (getPowerUpByItem(event.getEntity()) != null)
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickUpPowerUp(PlayerPickupItemEvent event)
|
||||
{
|
||||
if (getGame().GetTeam(event.getPlayer()) != null)
|
||||
{
|
||||
PowerUp powerUp = getPowerUpByItem(event.getItem());
|
||||
|
||||
if (powerUp != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
powerUp.powerUpPlayer(event.getPlayer());
|
||||
powerUp.remove();
|
||||
|
||||
schedulePowerUpSpawn(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PowerUp getPowerUpByItem(Item item)
|
||||
{
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
for (PowerUp powerUp : getPowerUps())
|
||||
{
|
||||
if (powerUp.getItem() != null && powerUp.getItem().equals(item))
|
||||
return powerUp;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package nautilus.game.arcade.game.games.sneakyassassins.powerups;
|
||||
|
||||
import org.bukkit.*;
|
||||
|
||||
public enum PowerUpType
|
||||
{
|
||||
WEAPON(Material.DIAMOND_SWORD, Color.RED),
|
||||
ARMOR(Material.IRON_CHESTPLATE, Color.BLUE);
|
||||
|
||||
private final Material _itemType;
|
||||
private final Color _color;
|
||||
|
||||
PowerUpType(Material type, Color color)
|
||||
{
|
||||
_itemType = type;
|
||||
_color = color;
|
||||
}
|
||||
|
||||
public Material getItemType()
|
||||
{
|
||||
return _itemType;
|
||||
}
|
||||
|
||||
public Color getColor()
|
||||
{
|
||||
return _color;
|
||||
}
|
||||
|
||||
public PowerUp spawn(PowerUpManager powerUpManager, Location location)
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case WEAPON:
|
||||
return new WeaponPowerUp(powerUpManager, location);
|
||||
|
||||
case ARMOR:
|
||||
return new ArmorPowerUp(powerUpManager, location);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package nautilus.game.arcade.game.games.sneakyassassins.powerups;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class WeaponPowerUp extends PowerUp
|
||||
{
|
||||
private static final List<Material> SWORD_PROGRESSION = Arrays.asList(
|
||||
Material.WOOD_SWORD,
|
||||
Material.STONE_SWORD,
|
||||
Material.IRON_SWORD,
|
||||
Material.GOLD_SWORD,
|
||||
Material.DIAMOND_SWORD
|
||||
);
|
||||
|
||||
public WeaponPowerUp(PowerUpManager powerUpManager, Location location)
|
||||
{
|
||||
super(powerUpManager, PowerUpType.WEAPON, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void powerUpPlayer(Player player)
|
||||
{
|
||||
for (int swordType = 0; swordType < SWORD_PROGRESSION.size(); swordType++)
|
||||
{
|
||||
int swordSlot = player.getInventory().first(SWORD_PROGRESSION.get(swordType));
|
||||
|
||||
if (swordSlot != -1)
|
||||
{
|
||||
int newSwordType = Math.min(SWORD_PROGRESSION.size() - 1, swordType + 1);
|
||||
player.getInventory().setItem(swordSlot, new ItemStack(SWORD_PROGRESSION.get(newSwordType)));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user