Add achievements

This commit is contained in:
Sam 2017-07-13 15:38:56 +01:00
parent 59af31c6f8
commit e777293866
12 changed files with 457 additions and 28 deletions

View File

@ -1225,7 +1225,62 @@ public enum Achievement
new String[]{"Gem Hunters.ChestsOpened"},
new String[]{"+1 for each chest opened"},
new int[]{50,100,200,400,1000},
AchievementCategory.GEM_HUNTERS);
AchievementCategory.GEM_HUNTERS),
MOBA_GOLD_EARNED("Gold Farmer", 0,
new String[]{"Heroes of GWEN.GoldEarned"},
new String[]{"Earn Gold"},
new int[][] {new int[] {0,0,1000}, new int[] {0,0,5000}, new int[]{0,0,10000}, new int[]{0,0,25000}, new int[]{0,0,50000}},
new int[]{10000,50000,100000,250000,500000},
"I",
new String[] {"II","III","IV","V","X"},
AchievementCategory.MOBA),
MOBA_KILLS("Champion Slayer", 0,
new String[]{"Heroes of GWEN.Kills"},
new String[]{"Kill players"},
new int[][] {new int[] {0,0,1000}, new int[] {0,0,5000}, new int[]{0,0,10000}, new int[]{0,0,25000}, new int[]{0,0,50000}},
new int[]{100,250,500,1000,5000},
"I",
new String[] {"II","III","IV","V","X"},
AchievementCategory.MOBA),
MOBA_WINS_ASSASSIN("Assassin Victor", 0,
new String[]{"Heroes of GWEN.Assassin.Wins"},
new String[]{"Win Games as an Assassin"},
new int[][] {new int[] {0,0,1000}, new int[] {0,0,5000}, new int[]{0,0,10000}, new int[]{0,0,25000}, new int[]{0,0,50000}},
new int[]{10,50,100,250,500},
"I",
new String[] {"II","III","IV","V","X"},
AchievementCategory.MOBA),
MOBA_WINS_HUNTER("Hunter Victor", 0,
new String[]{"Heroes of GWEN.Hunter.Wins"},
new String[]{"Win Games as a Hunter"},
new int[][] {new int[] {0,0,1000}, new int[] {0,0,5000}, new int[]{0,0,10000}, new int[]{0,0,25000}, new int[]{0,0,50000}},
new int[]{10,50,100,250,500},
"I",
new String[] {"II","III","IV","V","X"},
AchievementCategory.MOBA),
MOBA_WINS_MAGE("Mage Victor", 0,
new String[]{"Heroes of GWEN.Mage.Wins"},
new String[]{"Win Games as a Mage"},
new int[][] {new int[] {0,0,1000}, new int[] {0,0,5000}, new int[]{0,0,10000}, new int[]{0,0,25000}, new int[]{0,0,50000}},
new int[]{10,50,100,250,500},
"I",
new String[] {"II","III","IV","V","X"},
AchievementCategory.MOBA),
MOBA_WINS_WARRIOR("Warrior Victor", 0,
new String[]{"Heroes of GWEN.Warrior.Wins"},
new String[]{"Win Games as a Warrior"},
new int[][] {new int[] {0,0,1000}, new int[] {0,0,5000}, new int[]{0,0,10000}, new int[]{0,0,25000}, new int[]{0,0,50000}},
new int[]{10,50,100,250,500},
"I",
new String[] {"II","III","IV","V","X"},
AchievementCategory.MOBA),
;
private String _name;
private String[] _desc;

View File

@ -220,7 +220,7 @@ public enum AchievementCategory
Material.EMERALD, 0, GameCategory.SURVIVAL, null, false, GameDisplay.GemHunters.getGameId()),
MOBA("Heroes of GWEN", null,
new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED, null, StatDisplay.fromGame("Gold Earned", GameDisplay.MOBA, "GoldEarned")},
new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED, null, StatDisplay.fromGame("Gold Earned", GameDisplay.MOBA, "GoldEarned")},
Material.PRISMARINE_SHARD, 0, GameCategory.CLASSICS, null, false, GameDisplay.MOBA.getGameId());
private String _name;

View File

@ -41,11 +41,16 @@ public class GameStatisticsManager extends MiniPlugin
}
else
{
_repository.getMapId(mapId ->
{
_gameMaps.put(mapName, mapId);
callback.accept(mapId);
}, gameType.getGameId(), mapName);
runAsync(() ->
_repository.getMapId(mapId ->
{
_gameMaps.put(mapName, mapId);
if (callback != null)
{
runSync(() -> callback.accept(mapId));
}
}, gameType.getGameId(), mapName));
}
}

View File

@ -23,8 +23,8 @@ public class GameStatisticsRepository extends RepositoryBase
{
private static final String INSERT_MAP = "INSERT INTO gameMaps (gameType,mapName) VALUES (?,?)";
private static final String GET_MAP_BY_ID = "SELECT * FROM gameMaps WHERE mapName=?";
private static final String SAVE_GAME = "INSERT INTO gameStatistics (region,gameId,map,startTime,endTime) VALUES (?,?,?,?,?)";
private static final String GET_MAP_BY_ID = "SELECT mapId FROM gameMaps WHERE mapName=?";
private static final String SAVE_GAME = "INSERT INTO gameStatistics (region,gameType,map,startTime,endTime) VALUES (?,?,?,?,?)";
private static final String SAVE_STAT = "INSERT INTO gamePlayerStatistics VALUES (?,?,?,?);";
private static final String GET_BY_ID = "SELECT * FROM gameStatistics WHERE gameId=?";
private static final String SQL_REGEX = "\\?";
@ -45,7 +45,7 @@ public class GameStatisticsRepository extends RepositoryBase
{
if (resultSet.next())
{
callback.accept(resultSet.getInt(0));
callback.accept(resultSet.getInt(1));
}
else
{

View File

@ -15,6 +15,7 @@ import mineplex.core.imagemap.objects.PlayerMapBoard;
import mineplex.core.leaderboard.Leaderboard;
import mineplex.core.leaderboard.LeaderboardManager;
import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType;
import mineplex.core.stats.event.StatChangeEvent;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
@ -45,6 +46,7 @@ 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.overtime.OvertimeManager;
import nautilus.game.arcade.game.games.moba.progression.MobaProgression;
import nautilus.game.arcade.game.games.moba.shop.MobaShop;
import nautilus.game.arcade.game.games.moba.structure.point.CapturePointManager;
import nautilus.game.arcade.game.games.moba.structure.tower.TowerManager;
@ -101,6 +103,7 @@ public class Moba extends TeamGame
protected final TowerManager _tower;
protected final CapturePointManager _capturePoint;
protected final MinionManager _minion;
private final MobaProgression _progression;
private final ImageMapManager _mapManager = Managers.require(ImageMapManager.class);
private PlayerMapBoard _board;
private MapBoardSelector _selector;
@ -137,6 +140,7 @@ public class Moba extends TeamGame
_buffs = registerManager(new BuffManager());
_arrowKb = registerManager(new ArrowKBManager(this));
_minion = registerManager(new MinionManager(this));
_progression = registerManager(new MobaProgression(this));
registerManager(new HPManager(this));
registerManager(new MobaDamageManager(this));
registerManager(new MobaFountain(this));
@ -239,7 +243,9 @@ public class Moba extends TeamGame
leaderboard.registerLeaderboard("TOP_HOG_GOLD", new Leaderboard("Top Gold Earned", goldPair, new String[]{GetName() + ".GoldEarned"}, LeaderboardSQLType.ALL, location, 10));
}
_board = _mapManager.createPlayerBoard(lobbyCustomLocs.get("HERO_VIEWER").get(0).clone().add(0, 1, 0), BlockFace.EAST, 7, 4, ITEM_IMAGES);
_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));
}
@ -267,7 +273,7 @@ public class Moba extends TeamGame
// Cleanup tutorial boards
_mapManager.cleanupBoard(_board);
_selector.cleanup();
_progression.removeRoleViewers();
}
@EventHandler

View File

@ -254,11 +254,15 @@ public class MobaClassic extends Moba
for (Player player : otherTeam.GetPlayers(true))
{
MobaPlayer mobaPlayer = getMobaData(player);
AddStat(player, mobaPlayer.getRole().getName() + ".Wins", 1, true, false);
AddGems(player, 20, "Winning", false, false);
}
AnnounceEnd(otherTeam);
SetState(GameState.End);
return;
}
}
}

View File

@ -1,26 +1,29 @@
package nautilus.game.arcade.game.games.moba;
import mineplex.core.common.skin.SkinData;
import org.bukkit.ChatColor;
import org.bukkit.Color;
public enum MobaRole
{
ASSASSIN("Assassin", Color.GRAY, ChatColor.GRAY),
HUNTER("Hunter", Color.LIME, ChatColor.GREEN),
MAGE("Mage", Color.PURPLE, ChatColor.DARK_PURPLE),
WARRIOR("Warrior", Color.YELLOW, ChatColor.GOLD),
ASSASSIN("Assassin", Color.GRAY, ChatColor.GRAY, SkinData.HATTORI),
HUNTER("Hunter", Color.LIME, ChatColor.GREEN, SkinData.DEVON),
MAGE("Mage", Color.PURPLE, ChatColor.DARK_PURPLE, SkinData.ANATH),
WARRIOR("Warrior", Color.YELLOW, ChatColor.GOLD, SkinData.DANA),
;
private final String _name;
private final Color _color;
private final ChatColor _chatColor;
private final SkinData _skinData;
MobaRole(String name, Color color, ChatColor chatColor)
MobaRole(String name, Color color, ChatColor chatColor, SkinData skinData)
{
_name = name;
_color = color;
_chatColor = chatColor;
_skinData = skinData;
}
public String getName()
@ -37,4 +40,9 @@ public enum MobaRole
{
return _chatColor;
}
public SkinData getSkin()
{
return _skinData;
}
}

View File

@ -43,6 +43,11 @@ import java.util.concurrent.atomic.AtomicInteger;
public class PrepareSelection implements Listener, IPacketHandler
{
public static ItemStack buildColouredStack(Material material, MobaRole role)
{
return new ItemBuilder(material).setColor(role.getColor()).build();
}
private final Moba _host;
private final Map<ClientArmorStand, MobaRole> _roleStands = new HashMap<>();
private final Map<ClientArmorStand, HeroKit> _kitStands = new HashMap<>();
@ -76,8 +81,6 @@ public class PrepareSelection implements Listener, IPacketHandler
Location average = UtilAlg.getAverageLocation(team.GetSpawns());
Player[] players = team.GetPlayers(true).toArray(new Player[0]);
ItemStack head = new ItemBuilder(Material.SKULL_ITEM, (byte) 3).build();
UtilServer.runSyncLater(() ->
{
for (Player player : team.GetPlayers(true))
@ -99,7 +102,7 @@ public class PrepareSelection implements Listener, IPacketHandler
stand.setCustomNameVisible(true);
stand.setCustomName(C.cGreenB + role.getName() + C.cGray + " - " + C.cGreenB + "AVAILABLE");
stand.setArms(true);
stand.setHelmet(head);
stand.setHelmet(role.getSkin().getSkull());
stand.setChestplate(buildColouredStack(Material.LEATHER_CHESTPLATE, role));
stand.setLeggings(buildColouredStack(Material.LEATHER_LEGGINGS, role));
stand.setBoots(buildColouredStack(Material.LEATHER_BOOTS, role));
@ -176,11 +179,6 @@ public class PrepareSelection implements Listener, IPacketHandler
return location.clone().add(0, 1, 0);
}
private ItemStack buildColouredStack(Material material, MobaRole role)
{
return new ItemBuilder(material).setColor(role.getColor()).build();
}
private void removePodiums()
{
_host.getLocationStartsWith("KIT").forEach((key, location) -> location.getBlock().setType(Material.AIR));

View File

@ -0,0 +1,251 @@
package nautilus.game.arcade.game.games.moba.progression;
import mineplex.core.common.Rank;
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.UtilServer;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.DebugCommand;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GemData;
import nautilus.game.arcade.game.games.moba.Moba;
import nautilus.game.arcade.game.games.moba.MobaPlayer;
import nautilus.game.arcade.game.games.moba.MobaRole;
import nautilus.game.arcade.game.games.moba.prepare.PrepareSelection;
import nautilus.game.arcade.game.games.moba.progression.ui.MobaRoleShop;
import nautilus.game.arcade.game.games.moba.util.MobaUtil;
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.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
public class MobaProgression implements Listener
{
private static final int[] EXP_LEVELS;
private static final DecimalFormat FORMAT = new DecimalFormat("0.0");
static
{
EXP_LEVELS = new int[100];
int expRequired = 0;
for (int level = 0; level < 10; level++)
{
EXP_LEVELS[level] = expRequired += 2000;
}
for (int level = 10; level < 20; level++)
{
EXP_LEVELS[level] = expRequired += 4000;
}
for (int level = 20; level < 40; level++)
{
EXP_LEVELS[level] = expRequired += 8000;
}
for (int level = 40; level < 60; level++)
{
EXP_LEVELS[level] = expRequired += 16000;
}
for (int level = 60; level < 80; level++)
{
EXP_LEVELS[level] = expRequired += 32000;
}
for (int level = 80; level < 100; level++)
{
EXP_LEVELS[level] = expRequired += 64000;
}
}
private final Moba _host;
private final Map<ArmorStand, MobaRole> _roleViewers;
private final MobaRoleShop _roleShop;
public MobaProgression(Moba host)
{
_host = host;
_roleViewers = new HashMap<>();
_roleShop = new MobaRoleShop(host.getArcadeManager());
host.registerDebugCommand(new DebugCommand("fakeexp", Rank.DEVELOPER)
{
@Override
public void Execute(Player caller, String[] args)
{
int exp = Integer.parseInt(args[0]);
_host.GetGems(caller).put("Fake Exp", new GemData(exp, false));
caller.sendMessage(F.main("Debug", "Gave you " + F.elem(exp) + " fake exp."));
}
});
}
public void spawnRoleViewers(Map<String, List<Location>> lobbyLocations)
{
Location center = lobbyLocations.get("SPAWN").get(0);
for (MobaRole role : MobaRole.values())
{
List<Location> locations = lobbyLocations.get(role.name());
if (locations == null || locations.isEmpty())
{
continue;
}
Location location = locations.get(0).clone();
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, center)));
ArmorStand stand = location.getWorld().spawn(location, ArmorStand.class);
UtilEnt.vegetate(stand);
UtilEnt.ghost(stand, true, false);
stand.setCustomName(C.cGreenB + role.getName());
stand.setCustomNameVisible(true);
stand.setArms(true);
stand.setBasePlate(false);
stand.setHelmet(role.getSkin().getSkull());
stand.setChestplate(PrepareSelection.buildColouredStack(Material.LEATHER_CHESTPLATE, role));
stand.setLeggings(PrepareSelection.buildColouredStack(Material.LEATHER_LEGGINGS, role));
stand.setBoots(PrepareSelection.buildColouredStack(Material.LEATHER_BOOTS, role));
_roleViewers.put(stand, role);
}
}
public void removeRoleViewers()
{
for (ArmorStand stand : _roleViewers.keySet())
{
stand.remove();
}
_roleViewers.clear();
}
@EventHandler
public void onClick(CustomDamageEvent event)
{
onClick(event.GetDamagerEntity(true), event.GetDamageeEntity());
}
@EventHandler
public void onClick(PlayerInteractAtEntityEvent event)
{
onClick(event.getPlayer(), event.getRightClicked());
}
private void onClick(Entity clicker, Entity clicked)
{
if (clicker == null || !(clicker instanceof Player) || !_roleViewers.containsKey(clicked))
{
return;
}
Player player = (Player) clicker;
MobaRole role = _roleViewers.get(clicked);
if (role == null)
{
return;
}
_roleShop.openShop(player, role);
}
@EventHandler
public void end(GameStateChangeEvent event)
{
if (event.GetState() != GameState.End || !_host.getArcadeManager().IsRewardStats())
{
return;
}
_host.GetPlayers(true).forEach(this::rewardPlayer);
}
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);
MobaRole role = mobaPlayer.getRole();
String stat = _host.GetName() + "." + role.getName() + "." + "ExpEarned";
long currentExp = _host.getArcadeManager().GetStatsManager().Get(player).getStat(stat);
AtomicInteger earnedExp = new AtomicInteger();
for (GemData data : _host.GetGems(player).values())
{
earnedExp.getAndAdd((int) data.Gems);
}
int level = getLevel(currentExp);
int newLevel = getLevel(currentExp + earnedExp.get());
int expForThisLevel = EXP_LEVELS[level - 1];
AtomicBoolean levelUp = new AtomicBoolean();
if (newLevel > level)
{
levelUp.set(true);
}
_host.getArcadeManager().GetStatsManager().incrementStat(player, stat, earnedExp.get());
UtilServer.runSyncLater(() ->
{
player.sendMessage(ArcadeFormat.Line);
player.sendMessage("");
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("");
player.sendMessage(ArcadeFormat.Line);
if (levelUp.get())
{
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
}
else
{
player.playSound(player.getLocation(), Sound.CLICK, 1, 1);
}
}, 60);
}
}

View File

@ -0,0 +1,42 @@
package nautilus.game.arcade.game.games.moba.progression.ui;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.UtilUI;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.moba.MobaRole;
import org.bukkit.entity.Player;
public class MobaRolePage extends ShopPageBase<ArcadeManager, MobaRoleShop>
{
private static final int SIZE = 45;
private static final int[] MAPPINGS = UtilUI.getIndicesFor(4, 3);
private final MobaRole _role;
public MobaRolePage(ArcadeManager plugin, MobaRoleShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, MobaRole role)
{
super(plugin, shop, clientManager, donationManager, role.getName(), player, SIZE);
_role = role;
buildPage();
}
@Override
protected void buildPage()
{
addButtonNoAction(13, new ItemBuilder(_role.getSkin().getSkull())
.setTitle(_role.getChatColor() + _role.getName())
.addLore("", "Every 10 levels you unlock a new", "hero within the " + _role.getName() + " category.")
.build());
// for (int slot : MAPPINGS)
// {
// addButton(slot, );
// }
}
}

View File

@ -0,0 +1,28 @@
package nautilus.game.arcade.game.games.moba.progression.ui;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.moba.MobaRole;
import org.bukkit.entity.Player;
public class MobaRoleShop extends ShopBase<ArcadeManager>
{
public MobaRoleShop(ArcadeManager plugin)
{
super(plugin, plugin.GetClients(), plugin.GetDonation(), "Moba Heroes");
}
public void openShop(Player player, MobaRole role)
{
openPageForPlayer(player, new MobaRolePage(getPlugin(), this, getClientManager(), getDonationManager(), player, role));
}
@Override
protected ShopPageBase<ArcadeManager, ? extends ShopBase<ArcadeManager>> buildPagesFor(Player player)
{
return null;
}
}

View File

@ -137,16 +137,21 @@ public class MobaUtil
}
public static String getHealthBar(LivingEntity entity, double newHealth, int bars)
{
return getProgressBar(newHealth, entity.getMaxHealth(), bars);
}
public static String getProgressBar(double value, double max, int bars)
{
StringBuilder out = new StringBuilder();
double health = newHealth / entity.getMaxHealth();
String colour = getColour(health);
double progress = value / max;
String colour = getColour(progress);
for (int i = 0; i < bars; i++)
{
double cur = i * (1D / (double) bars);
if (cur < health)
if (cur < progress)
{
out.append(colour).append("|");
}
@ -159,6 +164,33 @@ public class MobaUtil
return out.toString();
}
public static String getProgressBar(double valueA, double valueB, double max, int bars)
{
StringBuilder out = new StringBuilder();
double progressA = valueA / max;
double progressB = valueB / max;
for (int i = 0; i < bars; i++)
{
double cur = i * (1D / (double) bars);
if (cur < progressA)
{
out.append(C.cAqua).append("|");
}
else if (cur < progressB)
{
out.append(C.cGreen).append("|");
}
else
{
out.append(C.cGrayB).append("|");
}
}
return out.toString();
}
public static String getColour(double percentage)
{
if (percentage < 0.25)