Achievement Module

Gem Booster/Achivement
This commit is contained in:
Chiss 2014-08-08 13:46:35 +10:00
parent 57cf3e4da6
commit 1a33dbb5ee
8 changed files with 326 additions and 81 deletions

View File

@ -0,0 +1,56 @@
package mineplex.core.achievement;
public enum Achievement
{
GEM_HUNTER("Gem Hunter", new String[] {"Global.GemsEarned"}, new int[] {10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000});
private String _name;
private String[] _stats;
private int[] _levels;
Achievement(String name, String[] stats, int[] levels)
{
_name = name;
_stats = stats;
_levels = levels;
}
public String getName()
{
return _name;
}
public String[] getStats()
{
return _stats;
}
public int[] getLevels()
{
return _levels;
}
public int getMaxLevel()
{
return _levels.length;
}
public AchivementData getLevelData(int exp)
{
for (int i=0 ; i<_levels.length ; i++)
{
int req = _levels[i];
//Has Experience, Level Up!
if (exp >= req)
{
exp -= req;
continue;
}
return new AchivementData(i, exp, req);
}
return new AchivementData(getMaxLevel(), -1, -1);
}
}

View File

@ -0,0 +1,65 @@
package mineplex.core.achievement;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.stats.StatsManager;
import mineplex.core.stats.event.StatChangeEvent;
public class AchievementManager extends MiniPlugin
{
private StatsManager _statsManager;
public AchievementManager(StatsManager statsManager)
{
super("Achievement Manager", statsManager.GetPlugin());
_statsManager = statsManager;
}
public AchivementData get(Player player, Achievement type)
{
return get(player.getName(), type);
}
public AchivementData get(String playerName, Achievement type)
{
int exp = 0;
for (String stat : type.getStats())
{
exp += _statsManager.Get(playerName).getStat(stat);
}
return type.getLevelData(exp);
}
@EventHandler
public void informLevelUp(StatChangeEvent event)
{
Player player = UtilPlayer.searchExact(event.getPlayerName());
if (player == null)
return;
for (Achievement type : Achievement.values())
{
for (String stat : type.getStats())
{
if (stat.equalsIgnoreCase(event.getStatName()))
{
if (type.getLevelData(event.getValueAfter()).getLevel() > type.getLevelData(event.getValueBefore()).getLevel())
{
UtilPlayer.message(player, F.main("Achievement",
"You leveled up " + F.elem(type.getName()) + " to " + F.elem("Level " + type.getLevelData(event.getValueAfter()).getLevel())));
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
}
}
}
}
}
}

View File

@ -0,0 +1,30 @@
package mineplex.core.achievement;
public class AchivementData
{
private int _level;
private int _expRemainder;
private int _expNextLevel;
public AchivementData(int level, int expRemainder, int expNextLevel)
{
_level = level;
_expRemainder = expRemainder;
_expNextLevel = expNextLevel;
}
public int getLevel()
{
return _level;
}
public int getExpRemainder()
{
return _expRemainder;
}
public int getExpNextLevel()
{
return _expNextLevel;
}
}

View File

@ -0,0 +1,61 @@
package mineplex.core.stats.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class StatChangeEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private String _player;
private String _table;
private String _statName;
private int _valueBefore;
private int _valueAfter;
public StatChangeEvent(String player, String table, String statName, int valueBefore, int valueAfter)
{
_player = player;
_table = table;
_statName = statName;
_valueBefore = valueBefore;
_valueAfter = valueAfter;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public String getPlayerName()
{
return _player;
}
public String getTable()
{
return _table;
}
public String getStatName()
{
return _statName;
}
public int getValueBefore()
{
return _valueBefore;
}
public int getValueAfter()
{
return _valueAfter;
}
}

View File

@ -52,6 +52,7 @@ import mineplex.minecraft.game.core.fire.Fire;
import mineplex.core.MiniPlugin;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.antistack.AntiStack;
import mineplex.core.blockrestore.BlockRestore;
@ -102,10 +103,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private GameGemManager _gameGemManager;
private GameManager _gameManager;
private GameLobbyManager _gameLobbyManager;
private GameStatsManager _gameStatsManager;
private GameWorldManager _gameWorldManager;
private ServerStatusManager _serverStatusManager;
private AchievementManager _achievementManager;
private StatsManager _statsManager;
private ClassManager _classManager;
private SkillFactory _skillFactory;
@ -197,7 +198,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_eloManager = new EloManager(_plugin);
}
// _statsManager = new StatsManager(plugin);
_statsManager = new StatsManager(plugin);
_achievementManager = new AchievementManager(_statsManager);
_portal = portal;
@ -215,7 +217,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_gameLobbyManager = new GameLobbyManager(this, packetHandler);
new GameFlagManager(this);
new GamePlayerManager(this);
_gameStatsManager = new GameStatsManager(this);
_gameWorldManager = new GameWorldManager(this);
_miscManager = new MiscManager(this);
new IdleManager(this);
@ -242,6 +243,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return GetServerConfig().GameList;
}
public AchievementManager GetAchievement()
{
return _achievementManager;
}
public AntiStack GetAntiStack()
{
@ -333,11 +339,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _arcadeShop;
}
public GameStatsManager GetStats()
{
return _gameStatsManager;
}
public GameCreationManager GetGameCreationManager()
{
return _gameCreationManager;

View File

@ -207,6 +207,8 @@ public abstract class Game implements Listener
public boolean EloRanking = false;
public int EloStart = 1000;
public ArrayList<String> GemBoosters = new ArrayList<String>();
public Game(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc)
{
@ -1040,4 +1042,33 @@ public abstract class Game implements Listener
{
SetState(GameState.End);
}
public void AddGemBooster(Player player)
{
if (GemBoosters.size() >= 4)
{
UtilPlayer.message(player, F.main("Game", "Games cannot have more than " + F.elem("4 Gem Boosters")) + ".");
return;
}
if (GemBoosters.contains(player.getName()))
{
UtilPlayer.message(player, F.main("Game", "You can only use " + F.elem("1 Gem Booster")) + " per game.");
return;
}
Announce(F.elem(player.getName()) + " used a " + F.elem("Gem Booster") + " for " + F.elem("+" + (100-(GemBoosters.size()*25)) + "% Gems") + "!");
GemBoosters.add(player.getName());
}
public double GetGemBoostAmount()
{
if (GemBoosters.size() == 1) return 1;
if (GemBoosters.size() == 2) return 1.75;
if (GemBoosters.size() == 3) return 2.25;
if (GemBoosters.size() == 4) return 2.5;
return 0;
}
}

View File

@ -2,8 +2,9 @@ package nautilus.game.arcade.managers;
import java.util.HashMap;
import mineplex.core.common.Rank;
import mineplex.core.achievement.Achievement;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -29,13 +30,13 @@ import org.bukkit.event.player.PlayerQuitEvent;
public class GameGemManager implements Listener
{
ArcadeManager Manager;
boolean DoubleGem = false;
public GameGemManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
@ -44,13 +45,13 @@ public class GameGemManager implements Listener
{
if (Manager.IsTournamentServer())
return;
Game game = Manager.GetGame();
if (game == null) return;
if (!(event.GetEvent().getEntity() instanceof Player))
return;
Player killed = (Player)event.GetEvent().getEntity();
if (event.GetLog().GetKiller() != null)
@ -86,43 +87,43 @@ public class GameGemManager implements Listener
game.AddGems(assist, game.GetKillsGems(assist, killed, true), "Kill Assists", true);
}
}
@EventHandler
public void PlayerQuit(PlayerQuitEvent event)
{
if (Manager.IsTournamentServer())
return;
Game game = Manager.GetGame();
if (game == null) return;
RewardGems(game, event.getPlayer(), true);
}
@EventHandler(priority = EventPriority.MONITOR)
public void PlayerStateChange(PlayerStateChangeEvent event)
{
if (Manager.IsTournamentServer())
return;
if (event.GetState() != PlayerState.OUT)
return;
if (event.GetGame().GetType() == GameType.Paintball)
return;
RewardGems(event.GetGame(), event.GetPlayer(), false);
}
@EventHandler
public void GameStateChange(GameStateChangeEvent event)
{
if (Manager.IsTournamentServer())
return;
if (event.GetState() != GameState.Dead)
return;
for (Player player : UtilServer.getPlayers())
RewardGems(event.GetGame(), player, true);
}
@ -131,55 +132,63 @@ public class GameGemManager implements Listener
{
if (Manager.IsTournamentServer())
return;
//Inform Gems
AnnounceGems(game, player, game.GetPlayerGems().get(player), give);
//Give Gems
if (give)
GiveGems(game, player, game.GetPlayerGems().remove(player), game.GemMultiplier);
}
public void GiveGems(Game game, Player player, HashMap<String,GemData> gems, double gameMult)
{
if (Manager.IsTournamentServer())
return;
if (gems == null)
return;
int total = 0;
int earned = 0;
for (GemData data : gems.values())
total += (int)data.Gems;
earned += (int)data.Gems;
if (total <= 0)
total = 1;
if (earned <= 0)
earned = 1;
earned = (int) (earned * gameMult);
int total = earned;
//Gem Boooster
total += (int)(earned * game.GetGemBoostAmount());
//Gem Finder
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel();
if (gemFinder > 0)
{
total += (int)(earned * (gemFinder * 0.25));
}
/*
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
total = total * 3;
else if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA) || Manager.GetDonation().Get(player.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA"))
total = total * 2;
*/
if (DoubleGem)
total = total * 2;
total = (int) (total * gameMult);
total += earned;
Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), total);
//Stats
Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total);
Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", total);
}
public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give)
{
if (Manager.IsTournamentServer())
return;
if (gems == null)
return;
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
UtilPlayer.message(player, "");
@ -197,7 +206,7 @@ public class GameGemManager implements Listener
gemCount = 1;
earnedGems += gemCount;
int amount = gems.get(type).Amount;
String amountStr = "";
if (amount > 0)
@ -205,43 +214,54 @@ public class GameGemManager implements Listener
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int)(gemCount * game.GemMultiplier) + " Gems") + " for " + F.elem(amountStr + type));
}
earnedGems = (int) (earnedGems * game.GemMultiplier);
//Hero / Ultra Boost
/*
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
int totalGems = earnedGems;
//Gem Booster
if (game.GetGemBoostAmount() > 0)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*2) + " Gems") + " for " + F.elem(C.cPurple + "Hero Rank 3x Gems"));
earnedGems = earnedGems * 3;
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*game.GetGemBoostAmount()) + " Gems") + " for " +
F.elem(game.GemBoosters.size() + " Gem Booster " + C.cGreen + "+" + (int)(game.GetGemBoostAmount()*100)));
totalGems += earnedGems * game.GetGemBoostAmount();
}
else if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA) || Manager.GetDonation().Get(player.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA"))
//Gem Finder
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GEM_HUNTER).getLevel();
if (gemFinder > 0)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + earnedGems + " Gems") + " for " + F.elem(C.cAqua + "Ultra Rank 2x Gems"));
earnedGems = earnedGems * 2;
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*(gemFinder * 0.25) + " Gems") + " for " +
F.elem("Gem Finder " + gemFinder + " (+" + (gemFinder*25) + "%)")));
totalGems += earnedGems * (gemFinder * 0.25);
}
*/
//Double Gem
if (DoubleGem)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems) + " Gems") + " for " + F.elem(C.cDGreen + "Double Gem Weekend"));
earnedGems = earnedGems * 2;
totalGems += earnedGems;
}
//Inform
UtilPlayer.message(player, "");
if (give)
{
UtilPlayer.message(player, F.elem(C.cWhite + "§lYou now have " +
C.cGreen + C.Bold + (Manager.GetDonation().Get(player.getName()).GetGems() + earnedGems) + " Gems"));
C.cGreen + C.Bold + (Manager.GetDonation().Get(player.getName()).GetGems() + totalGems) + " Gems"));
}
else
{
UtilPlayer.message(player, F.elem(C.cWhite + "§lGame is still in progress..."));
UtilPlayer.message(player, F.elem(C.cWhite + "§lYou may earn more " + C.cGreen + C.Bold + "Gems" + C.cWhite + C.Bold + " when its completed."));
}
UtilPlayer.message(player, ArcadeFormat.Line);
}
}

View File

@ -1,19 +0,0 @@
package nautilus.game.arcade.managers;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.event.Listener;
public class GameStatsManager implements Listener
{
ArcadeManager Manager;
public GameStatsManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
}