2014-11-07 09:20:15 +01:00
|
|
|
package nautilus.game.arcade.stats;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
|
|
|
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
|
|
|
import nautilus.game.arcade.game.Game;
|
|
|
|
import nautilus.game.arcade.game.GemData;
|
|
|
|
|
|
|
|
public class ExperienceStatTracker extends StatTracker<Game>
|
|
|
|
{
|
2014-11-09 04:43:06 +01:00
|
|
|
private long _startTime = -1;
|
2014-11-07 09:20:15 +01:00
|
|
|
|
|
|
|
public ExperienceStatTracker(Game game)
|
|
|
|
{
|
|
|
|
super(game);
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onGameStart(GameStateChangeEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetState() == Game.GameState.Live)
|
|
|
|
_startTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
|
|
|
public void onGameEnd(GameStateChangeEvent event)
|
|
|
|
{
|
|
|
|
if (!event.GetGame().Manager.IsRewardStats() || !event.GetGame().Manager.IsRewardAchievements())
|
|
|
|
return;
|
|
|
|
|
2014-11-09 04:43:06 +01:00
|
|
|
if (_startTime == -1)
|
|
|
|
return;
|
|
|
|
|
2014-11-07 09:20:15 +01:00
|
|
|
if (event.GetState() == Game.GameState.End)
|
|
|
|
{
|
|
|
|
List<Player> winners = getGame().getWinners();
|
|
|
|
|
|
|
|
if (winners != null)
|
|
|
|
{
|
2014-11-09 00:33:50 +01:00
|
|
|
for (Player player : event.GetGame().GetPlayers(false))
|
2014-11-07 09:20:15 +01:00
|
|
|
{
|
|
|
|
//Tally Gems
|
|
|
|
double gems = 0;
|
2014-11-09 00:06:04 +01:00
|
|
|
for (String reason : event.GetGame().GetGems(player).keySet())
|
|
|
|
{
|
|
|
|
if (reason.toLowerCase().contains("participation"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
GemData gem = event.GetGame().GetGems(player).get(reason);
|
|
|
|
|
2014-11-07 09:20:15 +01:00
|
|
|
gems += (int)gem.Gems;
|
2014-11-09 00:06:04 +01:00
|
|
|
}
|
|
|
|
|
2014-11-07 22:56:30 +01:00
|
|
|
gems = Math.min(gems, 250);
|
2014-11-07 09:20:15 +01:00
|
|
|
|
|
|
|
//Game Time
|
2014-11-07 12:10:41 +01:00
|
|
|
double time = (System.currentTimeMillis() - _startTime)/60000d;
|
2014-11-09 00:33:50 +01:00
|
|
|
|
|
|
|
//Mult
|
|
|
|
double mult = 1;
|
|
|
|
if (!winners.contains(player))
|
|
|
|
mult = 0.25;
|
|
|
|
|
2014-11-07 09:20:15 +01:00
|
|
|
//Exp
|
2014-11-09 00:33:50 +01:00
|
|
|
int expGained = (int)(time*gems*mult);
|
2014-11-07 09:20:15 +01:00
|
|
|
|
|
|
|
//Record Global and per Game
|
|
|
|
addStat(player, "ExpEarned", expGained, false, true);
|
|
|
|
addStat(player, "ExpEarned", expGained, false, false);
|
|
|
|
}
|
|
|
|
}
|
2014-11-09 04:43:06 +01:00
|
|
|
|
|
|
|
_startTime = -1;
|
2014-11-07 09:20:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|