diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 7f980d389..46c6dd349 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -1215,13 +1215,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed UtilServer.getServer().getPluginManager().callEvent(event); // Re-Give Kit - Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() - { - public void run() - { - GetKit(player).ApplyKit(player); - } - }, 0); + Manager.runSyncLater(() -> GetKit(player).ApplyKit(player), 0); } public void RespawnPlayerTeleport(Player player) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java index 736dcf189..62c399321 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java @@ -44,6 +44,7 @@ import nautilus.game.arcade.game.games.moba.kit.hp.HPManager; import nautilus.game.arcade.game.games.moba.kit.larissa.HeroLarissa; import nautilus.game.arcade.game.games.moba.kit.rowena.HeroRowena; import nautilus.game.arcade.game.games.moba.minion.MinionManager; +import nautilus.game.arcade.game.games.moba.modes.MobaMapType; import nautilus.game.arcade.game.games.moba.overtime.OvertimeManager; import nautilus.game.arcade.game.games.moba.progression.MobaProgression; import nautilus.game.arcade.game.games.moba.shop.MobaShop; @@ -195,9 +196,6 @@ public class Moba extends TeamGame @Override public void ParseData() { - // Register all "Managers" - _listeners.forEach(UtilServer::RegisterEvents); - // Make all spawns face the center of the map for (List locations : WorldData.SpawnLocs.values()) { @@ -206,49 +204,69 @@ public class Moba extends TeamGame SpectatorSpawn = WorldData.GetCustomLocs("CENTER").get(0); - // Leaderboards - if (Manager.IsRewardStats()) + MobaMapType mapType = null; + + for (String key : WorldData.GetAllCustomLocs().keySet()) { - if (Manager.GetLobby() instanceof NewGameLobbyManager) + try + { + mapType = MobaMapType.valueOf(key); + break; + } + catch (IllegalArgumentException e) { - Map> lobbyCustomLocs = ((NewGameLobbyManager) Manager.GetLobby()).getCustomLocs(); - LeaderboardManager leaderboard = Managers.get(LeaderboardManager.class); - Pair winPair = Pair.create("Win", "Wins"); - Pair killPair = Pair.create("Kill", "Kills"); - Pair goldPair = Pair.create("Gold", "Gold"); - - { - Location location = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_DAILY_WINS", new Leaderboard("Top Daily Wins", winPair, new String[]{GetName() + ".Wins"}, LeaderboardSQLType.DAILY, location, 10)); - } - { - Location location = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_DAILY_KILLS", new Leaderboard("Top Daily Kills", killPair, new String[]{GetName() + ".Kills"}, LeaderboardSQLType.DAILY, location, 10)); - } - { - Location location = lobbyCustomLocs.get("TOP_DAILY_GOLD").get(0); - leaderboard.registerLeaderboard("TOP_HOG_DAILY_GOLD", new Leaderboard("Top Daily Gold Earned", goldPair, new String[]{GetName() + ".GoldEarned"}, LeaderboardSQLType.DAILY, location, 10)); - } - { - Location location = lobbyCustomLocs.get("TOP_WINS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_WINS", new Leaderboard("Top Wins", winPair, new String[]{GetName() + ".Wins"}, LeaderboardSQLType.ALL, location, 10)); - } - { - Location location = lobbyCustomLocs.get("TOP_KILLS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_KILLS", new Leaderboard("Top Kills", killPair, new String[]{GetName() + ".Kills"}, LeaderboardSQLType.ALL, location, 10)); - } - { - Location location = lobbyCustomLocs.get("TOP_GOLD").get(0); - leaderboard.registerLeaderboard("TOP_HOG_GOLD", new Leaderboard("Top Gold Earned", goldPair, new String[]{GetName() + ".GoldEarned"}, LeaderboardSQLType.ALL, location, 10)); - } - - _progression.spawnRoleViewers(lobbyCustomLocs); - - _board = _mapManager.createPlayerBoard(lobbyCustomLocs.get("HERO_VIEWER").get(0), BlockFace.EAST, 7, 4, ITEM_IMAGES); - _selector = new MapBoardSelector(_board); - _selector.createHolograms(lobbyCustomLocs.get("HERO_VIEWER NEXT").get(0), lobbyCustomLocs.get("HERO_VIEWER BACK").get(0)); } } + + if (mapType == null) + { + mapType = MobaMapType.HEROES_VALLEY; + } + + registerManager(mapType.createInstance(this)); + + if (Manager.IsRewardStats() && Manager.GetLobby() instanceof NewGameLobbyManager) + { + Map> lobbyCustomLocs = ((NewGameLobbyManager) Manager.GetLobby()).getCustomLocs(); + LeaderboardManager leaderboard = Managers.get(LeaderboardManager.class); + Pair winPair = Pair.create("Win", "Wins"); + Pair killPair = Pair.create("Kill", "Kills"); + Pair goldPair = Pair.create("Gold", "Gold"); + + { + Location location = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0); + leaderboard.registerLeaderboard("TOP_HOG_DAILY_WINS", new Leaderboard("Top Daily Wins", winPair, new String[]{GetName() + ".Wins"}, LeaderboardSQLType.DAILY, location, 10)); + } + { + Location location = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0); + leaderboard.registerLeaderboard("TOP_HOG_DAILY_KILLS", new Leaderboard("Top Daily Kills", killPair, new String[]{GetName() + ".Kills"}, LeaderboardSQLType.DAILY, location, 10)); + } + { + Location location = lobbyCustomLocs.get("TOP_DAILY_GOLD").get(0); + leaderboard.registerLeaderboard("TOP_HOG_DAILY_GOLD", new Leaderboard("Top Daily Gold Earned", goldPair, new String[]{GetName() + ".GoldEarned"}, LeaderboardSQLType.DAILY, location, 10)); + } + { + Location location = lobbyCustomLocs.get("TOP_WINS").get(0); + leaderboard.registerLeaderboard("TOP_HOG_WINS", new Leaderboard("Top Wins", winPair, new String[]{GetName() + ".Wins"}, LeaderboardSQLType.ALL, location, 10)); + } + { + Location location = lobbyCustomLocs.get("TOP_KILLS").get(0); + leaderboard.registerLeaderboard("TOP_HOG_KILLS", new Leaderboard("Top Kills", killPair, new String[]{GetName() + ".Kills"}, LeaderboardSQLType.ALL, location, 10)); + } + { + Location location = lobbyCustomLocs.get("TOP_GOLD").get(0); + leaderboard.registerLeaderboard("TOP_HOG_GOLD", new Leaderboard("Top Gold Earned", goldPair, new String[]{GetName() + ".GoldEarned"}, LeaderboardSQLType.ALL, location, 10)); + } + + _progression.spawnRoleViewers(lobbyCustomLocs); + + _board = _mapManager.createPlayerBoard(lobbyCustomLocs.get("HERO_VIEWER").get(0), BlockFace.EAST, 7, 4, ITEM_IMAGES); + _selector = new MapBoardSelector(_board); + _selector.createHolograms(lobbyCustomLocs.get("HERO_VIEWER NEXT").get(0), lobbyCustomLocs.get("HERO_VIEWER BACK").get(0)); + } + + // Register all "Managers" + _listeners.forEach(UtilServer::RegisterEvents); } @EventHandler(priority = EventPriority.LOWEST) @@ -269,10 +287,7 @@ public class Moba extends TeamGame MobaUtil.setTeamEntity(player, GetTeam(player)); } - // Cleanup tutorial boards - _mapManager.cleanupBoard(_board); - _selector.cleanup(); - _progression.removeRoleViewers(); + cleanupLobby(); } @EventHandler @@ -295,6 +310,17 @@ public class Moba extends TeamGame player.setGameMode(GameMode.ADVENTURE); } + private void cleanupLobby() + { + if (_mapManager != null && _board != null) + { + _mapManager.cleanupBoard(_board); + _selector.cleanup(); + } + + _progression.removeRoleViewers(); + } + @Override public void disable() { @@ -302,6 +328,8 @@ public class Moba extends TeamGame _listeners.forEach(UtilServer::Unregister); _listeners.clear(); + cleanupLobby(); + Manager.runSyncLater(() -> { PlayerDisguiseManager playerDisguiseManager = Managers.require(PlayerDisguiseManager.class); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/BossManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/BossManager.java index 11f37cceb..52f8c774e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/BossManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/BossManager.java @@ -4,35 +4,36 @@ import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.moba.Moba; -import nautilus.game.arcade.game.games.moba.boss.pumpkin.PumpkinBoss; import nautilus.game.arcade.game.games.moba.boss.wither.WitherBoss; import nautilus.game.arcade.game.games.moba.util.MobaUtil; import nautilus.game.arcade.world.WorldData; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; -import java.util.List; +import java.util.HashSet; import java.util.Map; +import java.util.Set; public class BossManager implements Listener { private final Moba _host; - private Map _teamBosses; - private PumpkinBoss _pumpkinBoss; + private final Set _bosses; + private final Map _teamBosses; private boolean _dummyBosses; public BossManager(Moba host) { _host = host; + _bosses = new HashSet<>(); _teamBosses = new HashMap<>(2); } - private void spawnBosses() + private void spawnTeamWithers() { if (_dummyBosses) { @@ -52,10 +53,6 @@ public class BossManager implements Listener _teamBosses.put(team, boss); } - // Pumpkin King - _pumpkinBoss = new PumpkinBoss(_host, worldData.GetDataLocs("BLACK").get(0)); - _pumpkinBoss.setup(); - _host.CreatureAllowOverride = false; } @@ -67,7 +64,7 @@ public class BossManager implements Listener return; } - spawnBosses(); + spawnTeamWithers(); } @EventHandler @@ -79,17 +76,19 @@ public class BossManager implements Listener } _teamBosses.forEach((team, witherBoss) -> witherBoss.cleanup()); + _bosses.forEach(MobaBoss::cleanup); + _bosses.clear(); + } - if (_pumpkinBoss != null) - { - _pumpkinBoss.cleanup(); - } + public void registerBoss(MobaBoss boss) + { + _bosses.add(boss); + boss.setup(); } public String getWitherDisplayString(GameTeam team) { WitherBoss boss = getWitherBoss(team); - return MobaUtil.getColour(boss.getHealthPercentage()) + "♚"; } @@ -98,20 +97,9 @@ public class BossManager implements Listener return _teamBosses.get(team); } - public List getBosses() + public Collection getWitherBosses() { - List bosses = new ArrayList<>(); - - if (_teamBosses != null) - { - bosses.addAll(_teamBosses.values()); - } - if (_pumpkinBoss != null) - { - bosses.add(_pumpkinBoss); - } - - return bosses; + return _teamBosses.values(); } public void setDummyBosses(boolean dummyBosses) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/MobaBoss.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/MobaBoss.java index e46cdffd7..7fc4bce66 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/MobaBoss.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/MobaBoss.java @@ -113,6 +113,11 @@ public abstract class MobaBoss implements Listener getAi().setEntity(_entity); } + public void registerBoss() + { + _host.getBossManager().registerBoss(this); + } + public abstract LivingEntity spawnEntity(); public abstract MobaAI getAi(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/pumpkin/PumpkinBoss.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/pumpkin/PumpkinBoss.java index 133a8277e..6cd5e0a22 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/pumpkin/PumpkinBoss.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/boss/pumpkin/PumpkinBoss.java @@ -113,7 +113,7 @@ public class PumpkinBoss extends MobaBoss getAi().setEntity(skeleton); UtilTextMiddle.display(C.cDRedB + "The Pumpkin King", "Has Awoken!", 10, 40, 10); - _host.Announce(F.main("Game", C.cRedB + "The Pumpkin King Has Awoken!"), false); + _host.Announce(F.main("Game", "The " + F.elem("Pumpkin King") + " has spawned! Killing him will give your team a buff!"), false); for (Player player : Bukkit.getOnlinePlayers()) { @@ -125,7 +125,8 @@ public class PumpkinBoss extends MobaBoss Block block = entry.getKey(); double setChance = entry.getValue(); - if (!UtilBlock.solid(block)|| block.getRelative(BlockFace.UP).getType() != Material.AIR || Math.random() > setChance) + if (!UtilBlock.solid(block) || block.getRelative(BlockFace.UP).getType() != Material.AIR || Math.random() > + setChance) { continue; } @@ -230,12 +231,7 @@ public class PumpkinBoss extends MobaBoss BuffManager buffManager = _host.getBuffManager(); for (Player teamMember : team.GetPlayers(true)) { - if (UtilPlayer.isSpectator(teamMember)) - { - continue; - } - - buffManager.apply(new BuffPumpkinKing(_host, teamMember)); + buffManager.apply(new BuffPumpkinKing(_host, teamMember, HELMET)); } } @@ -283,7 +279,7 @@ public class PumpkinBoss extends MobaBoss } else { - _entity.setHealth(Math.min(_entity.getHealth() + HEALTH_OUT_OF_COMBAT, _entity.getMaxHealth())); + MobaUtil.heal(_entity, null, HEALTH_OUT_OF_COMBAT); updateDisplay(); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/buffs/BuffPumpkinKing.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/buffs/BuffPumpkinKing.java index 13868ec67..ef68cd0c9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/buffs/BuffPumpkinKing.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/buff/buffs/BuffPumpkinKing.java @@ -12,6 +12,7 @@ import nautilus.game.arcade.game.games.moba.Moba; import nautilus.game.arcade.game.games.moba.buff.Buff; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment; import org.bukkit.Bukkit; +import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; @@ -29,13 +30,16 @@ public class BuffPumpkinKing extends Buff { private static final long DURATION = TimeUnit.MINUTES.toMillis(1); - private static final String DAMAGE_REASON = "Pumpkin King Buff"; + private static final String DAMAGE_REASON = "Boss Buff"; private static final double DAMAGE_FACTOR = 1.5; - private static final ItemStack HELMET = new ItemStack(Material.PUMPKIN); - public BuffPumpkinKing(Moba host, Player entity) + private final ItemStack _helmet; + + public BuffPumpkinKing(Moba host, Player entity, ItemStack helmet) { super(host, entity, DURATION); + + _helmet = helmet; } @Override @@ -44,7 +48,7 @@ public class BuffPumpkinKing extends Buff _entity.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 60 * 20, 1)); UtilParticle.PlayParticleToAll(ParticleType.LAVA, _entity.getLocation().add(0, 1, 0), 0.5F, 0.5F, 0.5F, 0.1F, 10, ViewDist.LONG); _entity.playSound(_entity.getLocation(), Sound.PORTAL_TRAVEL, 1, 0.5F); - _entity.sendMessage(F.main("Game", "You feel the power of the Pumpkin King flow through you. Your damage and regeneration are increased!")); + _entity.sendMessage(F.main("Game", "You feel a " + F.elem("Great Power") + " flow through you. Your " + F.elem("Damage") + " and " + F.elem("Regeneration") + " are increased!")); } @Override @@ -61,7 +65,7 @@ public class BuffPumpkinKing extends Buff return; } - sendFakeHelmet(_entity, HELMET); + sendFakeHelmet(_entity, _helmet); } @EventHandler(priority = EventPriority.HIGHEST) @@ -80,7 +84,7 @@ public class BuffPumpkinKing extends Buff return; } - UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, damagee.getLocation().add(0, 0.5, 0), 0.25F, 0.25F, 0.25F, 0.1F, 10, ViewDist.NORMAL); + damagee.getWorld().playEffect(damagee.getLocation().add(0, 0.5, 0), Effect.STEP_SOUND, Material.REDSTONE_BLOCK); event.AddMod(DAMAGE_REASON, DAMAGE_FACTOR); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/minion/MinionWave.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/minion/MinionWave.java index 2ec589c7e..0fb7e7f17 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/minion/MinionWave.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/minion/MinionWave.java @@ -28,6 +28,7 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -243,16 +244,9 @@ public class MinionWave implements Listener private Location targetWither(Minion minion) { - for (MobaBoss boss : _host.getBossManager().getBosses()) + for (WitherBoss boss : _host.getBossManager().getWitherBosses()) { - if (boss.isDead() || !(boss instanceof WitherBoss)) - { - continue; - } - - WitherBoss witherBoss = (WitherBoss) boss; - - if (witherBoss.getTeam().equals(_owner)) + if (boss.isDead() || boss.getTeam().equals(_owner)) { continue; } @@ -352,11 +346,11 @@ public class MinionWave implements Listener return; } - List bosses = _host.getBossManager().getBosses(); + Collection bosses = _host.getBossManager().getWitherBosses(); for (Minion minion : _minions) { - for (MobaBoss boss : bosses) + for (WitherBoss boss : bosses) { // Dead, not close enough if (boss.isDead() || MobaUtil.isTeamEntity(boss.getEntity(), _owner) || UtilMath.offsetSquared(minion.getEntity(), boss.getEntity()) > DAMAGE_RANGE_SQUARED) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaHeroesValleyMap.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaHeroesValleyMap.java new file mode 100644 index 000000000..1db64f3e8 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaHeroesValleyMap.java @@ -0,0 +1,18 @@ +package nautilus.game.arcade.game.games.moba.modes; + +import nautilus.game.arcade.game.games.moba.Moba; +import nautilus.game.arcade.game.games.moba.boss.pumpkin.PumpkinBoss; +import org.bukkit.Bukkit; + +public class MobaHeroesValleyMap extends MobaMap +{ + + public MobaHeroesValleyMap(Moba host) + { + super(host); + + new PumpkinBoss(host, host.WorldData.GetDataLocs("BLACK").get(0)) + .registerBoss(); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMap.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMap.java new file mode 100644 index 000000000..44cd32d00 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMap.java @@ -0,0 +1,15 @@ +package nautilus.game.arcade.game.games.moba.modes; + +import nautilus.game.arcade.game.games.moba.Moba; +import org.bukkit.event.Listener; + +public class MobaMap implements Listener +{ + + protected final Moba _host; + + public MobaMap(Moba host) + { + _host = host; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMapType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMapType.java new file mode 100644 index 000000000..cc5d177df --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMapType.java @@ -0,0 +1,42 @@ +package nautilus.game.arcade.game.games.moba.modes; + +import nautilus.game.arcade.game.games.moba.Moba; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; + +import java.lang.reflect.InvocationTargetException; + +public enum MobaMapType +{ + + HEROES_VALLEY("Heroes Valley", MobaHeroesValleyMap.class), + MONOCHROME("Monochrome", MobaMonochromeMap.class) + + ; + + private final String _name; + private final Class _clazz; + + MobaMapType(String name, Class clazz) + { + _name = name; + _clazz = clazz; + } + + public String getName() + { + return _name; + } + + public MobaMap createInstance(Moba host) + { + try + { + return _clazz.getConstructor(Moba.class).newInstance(host); + } + catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) + { + e.printStackTrace(); + return null; + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMonochromeMap.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMonochromeMap.java new file mode 100644 index 000000000..bdd4c3d0d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/modes/MobaMonochromeMap.java @@ -0,0 +1,225 @@ +package nautilus.game.arcade.game.games.moba.modes; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +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.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.utils.UtilVariant; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.moba.Moba; +import nautilus.game.arcade.game.games.moba.buff.BuffManager; +import nautilus.game.arcade.game.games.moba.buff.buffs.BuffPumpkinKing; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +public class MobaMonochromeMap extends MobaMap +{ + + private static final long START_TIME = TimeUnit.MINUTES.toMillis(5); + private static final long ACTIVE_TIME = TimeUnit.SECONDS.toMillis(30); + private static final ItemStack IN_HAND = new ItemStack(Material.STONE_SWORD); + private static final ItemStack BUFF_HELMET = new ItemBuilder(Material.SKULL_ITEM, (byte) 1).build(); + + private final Set _skeletons; + private final Map _killedSkeletons; + + private boolean _active; + private long _lastStart; + + public MobaMonochromeMap(Moba host) + { + super(host); + + _skeletons = new HashSet<>(); + _killedSkeletons = new HashMap<>(); + } + + @EventHandler + public void live(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Live) + { + return; + } + + _lastStart = System.currentTimeMillis(); + } + + @EventHandler + public void updateStart(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST || !_host.IsLive() || _active || !UtilTime.elapsed(_lastStart, START_TIME)) + { + return; + } + + _lastStart = System.currentTimeMillis(); + _active = true; + + UtilTextMiddle.display(C.cRedB + "Wither Skeletons", "Have Spawned!", 10, 40, 10); + _host.Announce(F.main("Game", F.elem("Wither Skeletons") + " have spawned! The team that kills the most within " + F.time("30 seconds") + " receives a buff!"), false); + + for (Player player : Bukkit.getOnlinePlayers()) + { + player.playSound(player.getLocation(), Sound.WITHER_SPAWN, 1, 0.4F); + } + + _host.CreatureAllowOverride = true; + + for (Location location : _host.WorldData.GetDataLocs("BLACK")) + { + Skeleton skeleton = UtilVariant.spawnWitherSkeleton(location); + skeleton.getEquipment().setItemInHand(IN_HAND); + skeleton.setCustomName(C.Bold + "Wither Skeleton"); + skeleton.setCustomNameVisible(true); + + _skeletons.add(skeleton); + } + + _host.CreatureAllowOverride = false; + + for (GameTeam team : _host.GetTeamList()) + { + _killedSkeletons.put(team, 0); + } + } + + @EventHandler + public void updateEnd(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST || !_host.IsLive() || !_active || !UtilTime.elapsed(_lastStart, ACTIVE_TIME)) + { + return; + } + + GameTeam red = _host.GetTeam(ChatColor.RED); + int redKills = _killedSkeletons.get(red); + GameTeam blue = _host.GetTeam(ChatColor.AQUA); + int blueKills = _killedSkeletons.get(blue); + List winners; + + // Draw + if (redKills == blueKills) + { + winners = Arrays.asList(red, blue); + } + // Red win + else if (redKills > blueKills) + { + winners = Collections.singletonList(red); + } + // Blue win + else + { + winners = Collections.singletonList(blue); + } + + if (winners.size() == 1) + { + GameTeam winner = winners.get(0); + + _host.Announce(F.main("Game", F.name(winner.GetFormattedName()) + " killed the most " + F.elem("Wither Skeletons") + ". They have been given the buff!"), false); + UtilTextMiddle.display("", winner.GetFormattedName() + C.cWhite + " killed the most " + F.elem("Wither Skeletons"), 10, 40, 10); + } + else + { + _host.Announce(F.main("Game", F.elem(C.Bold + "Draw") + "! No one was given the buff!"), false); + UtilTextMiddle.display("", C.cYellowB + "Draw" + C.cWhite + "! No one was given the buff!", 10, 40, 10); + cleanup(); + return; + } + + // Give the team members the buff + BuffManager buffManager = _host.getBuffManager(); + winners.forEach(team -> + { + for (Player teamMember : team.GetPlayers(true)) + { + buffManager.apply(new BuffPumpkinKing(_host, teamMember, BUFF_HELMET)); + } + }); + + cleanup(); + } + + private void cleanup() + { + _skeletons.forEach(entity -> + { + if (!entity.isDead()) + { + UtilParticle.PlayParticleToAll(ParticleType.CLOUD, entity.getLocation().add(0, 1.5, 0), 0.5F, 1, 0.5F, 0.001F, 15, ViewDist.LONG); + } + + entity.remove(); + }); + _skeletons.clear(); + _killedSkeletons.clear(); + + _active = false; + } + + @EventHandler + public void entityDeath(EntityDeathEvent event) + { + LivingEntity entity = event.getEntity(); + + if (_skeletons.remove(entity)) + { + Player player = entity.getKiller(); + + if (player == null) + { + return; + } + + GameTeam team = _host.GetTeam(player); + + if (team == null) + { + return; + } + + event.getDrops().clear(); + event.setDroppedExp(0); + _killedSkeletons.put(team, _killedSkeletons.get(team) + 1); + player.sendMessage(F.main("Game", "You killed a " + F.name("Wither Skeleton") + "!")); + } + } + + @EventHandler + public void entityCombust(EntityCombustEvent event) + { + if (_skeletons.contains(event.getEntity())) + { + event.setCancelled(true); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/overtime/OvertimeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/overtime/OvertimeManager.java index f22986f4c..3270cc7de 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/overtime/OvertimeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/overtime/OvertimeManager.java @@ -49,12 +49,9 @@ public class OvertimeManager implements Listener UtilTextMiddle.display(C.cRedB + "OVERTIME", "Victory or Death, Withers are moving to the center!"); _host.Announce(F.main("Game", "Victory or Death, Withers are moving to the center!"), false); - for (MobaBoss boss : _host.getBossManager().getBosses()) + for (WitherBoss boss : _host.getBossManager().getWitherBosses()) { - if (boss instanceof WitherBoss) - { - ((WitherBoss) boss).setDamageable(true); - } + boss.setDamageable(true); } for (Player player : Bukkit.getOnlinePlayers()) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/MobaLevelData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/MobaLevelData.java new file mode 100644 index 000000000..175d11907 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/MobaLevelData.java @@ -0,0 +1,48 @@ +package nautilus.game.arcade.game.games.moba.progression; + +public class MobaLevelData +{ + + private final int _exp; + private final int _level; + private final int _thisLevel; + private final int _nextLevel; + + public MobaLevelData(long exp) + { + _exp = (int) exp; + _level = MobaProgression.getLevel(exp); + _thisLevel = MobaProgression.getExpFor(_level); + _nextLevel = MobaProgression.getExpFor(_level + 1); + } + + public int getExp() + { + return _exp; + } + + public int getLevel() + { + return _level; + } + + public int getExpThisLevel() + { + return _thisLevel; + } + + public int getExpJustThisLevel() + { + return _nextLevel - _thisLevel; + } + + public int getExpReminder() + { + return _nextLevel - _exp; + } + + public double getPercentageComplete() + { + return (double) (_exp - _thisLevel) / (double) (getExpJustThisLevel()); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/MobaProgression.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/MobaProgression.java index 98fb784aa..f0f0f6182 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/MobaProgression.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/MobaProgression.java @@ -40,20 +40,18 @@ import java.util.concurrent.atomic.AtomicInteger; public class MobaProgression implements Listener { - private static final int[] EXP_LEVELS; private static final int EXP_PER_LEVEL = 1000; private static final int EXP_FACTOR = 3; public static final DecimalFormat FORMAT = new DecimalFormat("0.0"); - static + public static int getExpFor(int level) { - EXP_LEVELS = new int[100]; - int expRequired = EXP_PER_LEVEL; + return EXP_PER_LEVEL * (level - 1); + } - for (int level = 0; level < 100; level++) - { - EXP_LEVELS[level] = expRequired += EXP_PER_LEVEL; - } + public static int getLevel(long exp) + { + return (int) Math.floor(exp / EXP_PER_LEVEL); } private final Moba _host; @@ -84,7 +82,7 @@ public class MobaProgression implements Listener public void Execute(Player caller, String[] args) { MobaRole role = MobaRole.valueOf(args[0].toUpperCase()); - int exp = getExperience(Integer.parseInt(args[1])) - 1; + int exp = getExpFor(Integer.parseInt(args[1])) - 1; _host.getArcadeManager().GetStatsManager().setStat(caller, _host.GetName() + "." + role.getName() + ".ExpEarned", exp); caller.sendMessage(F.main("Debug", "Set your " + role.getChatColor() + role.getName() + C.cGray + " level to " + F.elem(getLevel(exp)) + ".")); } @@ -176,32 +174,12 @@ public class MobaProgression implements Listener _host.GetPlayers(true).forEach(this::rewardPlayer); } - public int getExperience(int level) - { - if (level > EXP_LEVELS.length) - { - return Integer.MAX_VALUE; - } - else if (level < 1) - { - return 0; - } - - return EXP_LEVELS[level - 1]; - } - public long getExperience(Player player, MobaRole role) { String stat = _host.GetName() + "." + role.getName() + ".ExpEarned"; return _host.getArcadeManager().GetStatsManager().Get(player).getStat(stat); } - public long getExperienceCurrentLevel(Player player, MobaRole role) - { - int level = getLevel(player, role); - return getExperience(level) - getExperience(level - 1); - } - public int getLevel(Player player, HeroKit kit) { return getLevel(player, kit.getRole()); @@ -212,28 +190,25 @@ public class MobaProgression implements Listener return getLevel(getExperience(player, role)); } - private int getLevel(long exp) - { - int i = 0; - - for (int expRequired : EXP_LEVELS) - { - i++; - if (expRequired > exp) - { - return i; - } - } - - return 1; - } - private void rewardPlayer(Player player) { MobaPlayer mobaPlayer = _host.getMobaData(player); + + if (mobaPlayer == null) + { + return; + } + MobaRole role = mobaPlayer.getRole(); String stat = _host.GetName() + "." + role.getName() + ".ExpEarned"; - long currentExp = _host.getArcadeManager().GetStatsManager().Get(player).getStat(stat); + // EXP before earning + long currentExp = getExperience(player, role); + // Level before earning + int currentLevel = getLevel(currentExp); + + player.sendMessage("currentExp = " + currentExp); + player.sendMessage("currentLevel = " + currentLevel); + AtomicInteger earnedExp = new AtomicInteger(); for (GemData data : _host.GetGems(player).values()) @@ -242,16 +217,16 @@ public class MobaProgression implements Listener } earnedExp.getAndAdd(earnedExp.get() * EXP_FACTOR); + MobaLevelData levelData = new MobaLevelData(currentExp + earnedExp.get()); - int level = getLevel(currentExp); - int newLevel = getLevel(currentExp + earnedExp.get()); - long expForThisLevel = getExperienceCurrentLevel(player, role); - AtomicBoolean levelUp = new AtomicBoolean(); + player.sendMessage("exp = " + levelData.getExp()); + player.sendMessage("level = " + levelData.getLevel()); + player.sendMessage("thisLevel = " + levelData.getExpThisLevel()); + player.sendMessage("justThisLevel = " + levelData.getExpJustThisLevel()); + player.sendMessage("reminder = " + levelData.getExpReminder()); + player.sendMessage("percentage = " + levelData.getPercentageComplete()); - if (newLevel > level) - { - levelUp.set(true); - } + AtomicBoolean levelUp = new AtomicBoolean(levelData.getLevel() > currentLevel); _host.getArcadeManager().GetStatsManager().incrementStat(player, stat, earnedExp.get()); @@ -262,8 +237,8 @@ public class MobaProgression implements Listener player.sendMessage(" " + role.getChatColor() + C.Bold + role.getName() + " Progression" + (levelUp.get() ? C.cGreenB + " LEVEL UP" : "")); player.sendMessage(""); - player.sendMessage(MobaUtil.getProgressBar(currentExp, currentExp + earnedExp.get(), expForThisLevel, 100) + " " + C.cGray + "+" + C.cGreen + earnedExp + C.cGray + "/" + C.cAqua + expForThisLevel); - player.sendMessage(C.cGreen + FORMAT.format((currentExp + earnedExp.get()) / (double) expForThisLevel * 100D) + C.cWhite + "% complete for Level " + level); + player.sendMessage(MobaUtil.getProgressBar(currentExp, levelData.getExp(), levelData.getExpThisLevel(), 100) + " " + C.cGray + "+" + C.cGreen + earnedExp + C.cGray + "/" + C.cAqua + levelData.getExpJustThisLevel()); + player.sendMessage(C.cGreen + FORMAT.format((levelData.getPercentageComplete() * 100D) + C.cWhite + "% complete for Level " + currentLevel)); player.sendMessage(""); player.sendMessage(ArcadeFormat.Line); @@ -272,7 +247,7 @@ public class MobaProgression implements Listener { for (HeroKit kit : _host.getKits()) { - if (!kit.getRole().equals(role) || kit.getUnlockLevel() != newLevel) + if (!kit.getRole().equals(role) || kit.getUnlockLevel() != levelData.getLevel()) { continue; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/ui/MobaRolePage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/ui/MobaRolePage.java index 04e19a0ad..4396a2c99 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/ui/MobaRolePage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/progression/ui/MobaRolePage.java @@ -14,6 +14,7 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.games.moba.Moba; import nautilus.game.arcade.game.games.moba.MobaRole; import nautilus.game.arcade.game.games.moba.kit.HeroKit; +import nautilus.game.arcade.game.games.moba.progression.MobaLevelData; import nautilus.game.arcade.game.games.moba.progression.MobaProgression; import nautilus.game.arcade.game.games.moba.progression.MobaUnlockAnimation; import org.bukkit.Material; @@ -49,11 +50,7 @@ public class MobaRolePage extends ShopPageBase @Override protected void buildPage() { - int level = _host.getProgression().getLevel(_player, _role); - long currentExp = _host.getProgression().getExperience(_player, _role); - long thisLevel = _host.getProgression().getExperienceCurrentLevel(_player, _role); - long toNextLevel = _host.getProgression().getExperience(level) - currentExp; - long levelExp = _host.getProgression().getExperience(level); + MobaLevelData levelData = new MobaLevelData(_host.getProgression().getExperience(_player, _role)); addButtonNoAction(13, new ItemBuilder(_role.getSkin().getSkull()) .setTitle(_role.getChatColor() + _role.getName()) @@ -62,8 +59,8 @@ public class MobaRolePage extends ShopPageBase "Every " + F.elem(10) + " levels you unlock a new", "hero within the " + F.name(_role.getName()) + " category.", "", - "Your Level: " + C.cGreen + level, - "Next Level: " + C.cGreen + toNextLevel + C.cGray + "/" + C.cGreen + thisLevel + C.cGray + " (" + C.cAqua + MobaProgression.FORMAT.format(100 - ((double) currentExp / (double) levelExp) * 100D) + C.cGray + "%)" + "Your Level: " + C.cGreen + levelData.getLevel(), + "Next Level: " + C.cGreen + levelData.getExpReminder() + C.cGray + "/" + C.cGreen + levelData.getExpJustThisLevel() + C.cGray + " (" + C.cAqua + MobaProgression.FORMAT.format(levelData.getPercentageComplete() * 100D) + C.cGray + "%)" ) .build());