Changes to Sneaky Assassin power-ups, including addition of compass power-up.

This commit is contained in:
CoderTim 2014-08-06 01:23:06 -04:00
parent 9e047847c2
commit 16353c4bc9
8 changed files with 153 additions and 76 deletions

View File

@ -185,11 +185,11 @@ public class SneakyAssassins extends SoloGame
{ {
if (team.IsAlive(player)) if (team.IsAlive(player))
{ {
Scoreboard.WriteOrdered("Powerups", C.cGreen + player.getName(), 0, true); Scoreboard.WriteOrdered("Powerups", C.cGreen + player.getName(), getPowerUpManager().getPowerUpCount(player), true);
} }
else else
{ {
Scoreboard.WriteOrdered("Powerups", C.cGray + player.getName(), 0, true); Scoreboard.WriteOrdered("Powerups", C.cGray + player.getName(), getPowerUpManager().getPowerUpCount(player), true);
} }
} }
} }
@ -197,7 +197,7 @@ public class SneakyAssassins extends SoloGame
{ {
for (Player player : team.GetPlayers(true)) for (Player player : team.GetPlayers(true))
{ {
Scoreboard.WriteOrdered("Powerups", C.cGreen + player.getName(), 0, true); Scoreboard.WriteOrdered("Powerups", C.cGreen + player.getName(), getPowerUpManager().getPowerUpCount(player), true);
} }
} }
else else

View File

@ -43,12 +43,7 @@ public class ArmorPowerUp extends PowerUp
boolean powerUp1 = powerUpArmor(player, random); boolean powerUp1 = powerUpArmor(player, random);
boolean powerUp2 = powerUpArmor(player, random); boolean powerUp2 = powerUpArmor(player, random);
if (powerUp1 || powerUp2) return powerUp1 || powerUp2;
UtilPlayer.message(player, F.main("Power-Up", "Your " + F.item("Armor") + " was upgraded."));
else
UtilPlayer.message(player, F.main("Power-Up", "Your " + F.item("Armor") + " is already fully upgraded!"));
return super.powerUpPlayer(player, random);
} }
public static boolean powerUpArmor(Player player, Random random) public static boolean powerUpArmor(Player player, Random random)

View File

@ -0,0 +1,26 @@
package nautilus.game.arcade.game.games.sneakyassassins.powerups;
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.inventory.*;
import java.util.*;
public class CompassPowerUp extends PowerUp
{
protected CompassPowerUp()
{
super(PowerUpType.COMPASS);
}
@Override
public boolean powerUpPlayer(Player player, Random random)
{
if (player.getInventory().contains(Material.COMPASS))
return false;
player.getInventory().addItem(new ItemStack(Material.COMPASS));
return true;
}
}

View File

@ -15,17 +15,10 @@ public abstract class PowerUp
_powerUpType = powerUpType; _powerUpType = powerUpType;
} }
public boolean powerUpPlayer(Player player, Random random)
{
player.playSound(player.getEyeLocation(), Sound.LEVEL_UP, 2f, 0.8f);
player.getInventory().addItem(SneakyAssassinKit.SMOKE_BOMB.clone());
return true;
}
public PowerUpType getPowerUpType() public PowerUpType getPowerUpType()
{ {
return _powerUpType; return _powerUpType;
} }
public abstract boolean powerUpPlayer(Player player, Random random);
} }

View File

@ -23,7 +23,7 @@ public class PowerUpManager implements Listener
private final List<PowerUpItem> _powerUps = new ArrayList<>(); private final List<PowerUpItem> _powerUps = new ArrayList<>();
private Location _lastLocation = null; private Location _lastLocation = null;
private int _nextSpawnCountdown = -1; private int _nextSpawnCountdown = -1;
private final Map<UUID, PowerUpType> _lastPowerUpType = new HashMap<>(); private final Map<UUID, Integer> _powerUpCount = new HashMap<>();
public PowerUpManager(Game game, Random random, List<Location> spawnLocations) public PowerUpManager(Game game, Random random, List<Location> spawnLocations)
{ {
@ -148,30 +148,84 @@ public class PowerUpManager implements Listener
} }
@EventHandler @EventHandler
public void onPlayerPickUpPowerUp(final PlayerPickupItemEvent event) public void onPlayerPickUpPowerUp(PlayerPickupItemEvent event)
{ {
if (getGame().IsPlaying(event.getPlayer())) if (!getGame().IsPlaying(event.getPlayer()))
{ return;
final PowerUpItem powerUp = getPowerUpByItem(event.getItem());
PowerUpItem powerUp = getPowerUpByItem(event.getItem());
if (powerUp == null)
return;
if (powerUp != null)
{
event.setCancelled(true); event.setCancelled(true);
PowerUpType lastType = _lastPowerUpType.get(event.getPlayer().getUniqueId());
if (lastType == null)
lastType = UtilAlg.Random(Arrays.asList(PowerUpType.values()));
int nextIndex = (Arrays.asList(PowerUpType.values()).indexOf(lastType) + 1) % PowerUpType.values().length;
PowerUp pu = PowerUpType.values()[nextIndex].getPowerUp();
pu.powerUpPlayer(event.getPlayer(), getRandom());
powerUp.remove(); powerUp.remove();
_lastPowerUpType.put(event.getPlayer().getUniqueId(), pu.getPowerUpType()); int count = incrementPowerUpCount(event.getPlayer());
if (PowerUpType.SMOKE_BOMB.powerUpPlayer(event.getPlayer(), getRandom()))
UtilPlayer.message(event.getPlayer(), F.main("Power-Up", "+1 " + F.item("Smoke Bomb")));
if (count < 5)
{
PowerUpType.WEAPON.powerUpPlayer(event.getPlayer(), getRandom());
PowerUpType.ARMOR.powerUpPlayer(event.getPlayer(), getRandom());
UtilPlayer.message(event.getPlayer(), F.main("Power-Up", "Your " + F.item("Sword") + " and " + F.item("Armor") + " have been upgraded"));
}
else if (count == 5)
{
PowerUpType.COMPASS.powerUpPlayer(event.getPlayer(), getRandom());
UtilPlayer.message(event.getPlayer(), F.main("Power-Up", "You now have a " + F.item("Compass") + " for tracking players"));
getGame().Announce(F.name(event.getPlayer().getName()) + " has become a " + F.skill("Master Assassin"));
}
schedulePowerUpSpawn(10); schedulePowerUpSpawn(10);
} }
@EventHandler
public void onUpdateCompass(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
if (getGame().GetState() != GameState.Live)
return;
Player[] players = Bukkit.getOnlinePlayers();
for (Player player : players)
{
if (!getGame().IsPlaying(player))
continue;
if (player.getInventory().contains(Material.COMPASS))
continue;
Player closest = null;
double minDistanceSquared = Double.NaN;
for (Player other : players)
{
if (other == player)
continue;
if (!getGame().IsPlaying(other))
continue;
double distanceSquared = player.getLocation().distanceSquared(other.getLocation());
if (closest == null || distanceSquared < minDistanceSquared)
{
closest = other;
minDistanceSquared = distanceSquared;
}
}
if (closest != null)
player.setCompassTarget(closest.getLocation());
} }
} }
@ -188,4 +242,20 @@ public class PowerUpManager implements Listener
return null; return null;
} }
public int getPowerUpCount(Player player)
{
Integer count = _powerUpCount.get(player.getUniqueId());
return count == null ? 0 : count;
}
public int incrementPowerUpCount(Player player)
{
int count = getPowerUpCount(player) + 1;
_powerUpCount.put(player.getUniqueId(), count);
return count;
}
} }

View File

@ -1,48 +1,26 @@
package nautilus.game.arcade.game.games.sneakyassassins.powerups; package nautilus.game.arcade.game.games.sneakyassassins.powerups;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.*;
import java.util.*;
public enum PowerUpType public enum PowerUpType
{ {
WEAPON(Material.DIAMOND_SWORD, DyeColor.RED), WEAPON(new WeaponPowerUp()),
ARMOR(Material.IRON_CHESTPLATE, DyeColor.BLUE); ARMOR(new ArmorPowerUp()),
SMOKE_BOMB(new SmokeBombPowerUp()),
COMPASS(new CompassPowerUp());
private final Material _itemType; private final PowerUp _powerUp;
private final DyeColor _color;
PowerUpType(Material type, DyeColor color) PowerUpType(PowerUp powerUp)
{ {
_itemType = type; _powerUp = powerUp;
_color = color;
} }
public Material getItemType() public boolean powerUpPlayer(Player player, Random random)
{ {
return _itemType; return _powerUp.powerUpPlayer(player, random);
}
public Color getColor()
{
return getDyeColor().getColor();
}
public DyeColor getDyeColor()
{
return _color;
}
public PowerUp getPowerUp()
{
switch (this)
{
case WEAPON:
return new WeaponPowerUp();
case ARMOR:
return new ArmorPowerUp();
default:
return null;
}
} }
} }

View File

@ -0,0 +1,20 @@
package nautilus.game.arcade.game.games.sneakyassassins.powerups;
import nautilus.game.arcade.game.games.sneakyassassins.kits.*;
import org.bukkit.entity.*;
import java.util.*;
public class SmokeBombPowerUp extends PowerUp
{
protected SmokeBombPowerUp()
{
super(PowerUpType.SMOKE_BOMB);
}
@Override
public boolean powerUpPlayer(Player player, Random random)
{
return player.getInventory().addItem(SneakyAssassinKit.SMOKE_BOMB.clone()).isEmpty();
}
}

View File

@ -1,6 +1,5 @@
package nautilus.game.arcade.game.games.sneakyassassins.powerups; package nautilus.game.arcade.game.games.sneakyassassins.powerups;
import mineplex.core.common.util.*;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.*; import org.bukkit.inventory.*;
@ -37,15 +36,11 @@ public class WeaponPowerUp extends PowerUp
{ {
player.getInventory().setItem(swordSlot, new ItemStack(SWORD_PROGRESSION.get(newSwordType))); player.getInventory().setItem(swordSlot, new ItemStack(SWORD_PROGRESSION.get(newSwordType)));
UtilPlayer.message(player, F.main("Power-Up", "Your " + F.item("Sword") + " was upgraded.")); return true;
return super.powerUpPlayer(player, random);
} }
} }
} }
UtilPlayer.message(player, F.main("Power-Up", "Your " + F.item("Sword") + " is already fully upgraded!")); return false;
return super.powerUpPlayer(player, random);
} }
} }