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;
|
2015-06-27 04:38:04 +02:00
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
2014-11-07 09:20:15 +01:00
|
|
|
|
2015-06-27 04:38:04 +02:00
|
|
|
import mineplex.core.common.util.NautHashMap;
|
2014-11-07 09:20:15 +01:00
|
|
|
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
|
|
|
|
2015-06-27 04:38:04 +02:00
|
|
|
private NautHashMap<String, Long> _playerQuitTime = new NautHashMap<String, Long>();
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-06-27 04:38:04 +02:00
|
|
|
@EventHandler
|
|
|
|
public void onPlayerQuit(PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
_playerQuitTime.put(event.getPlayer().getName(), System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
2014-11-07 09:20:15 +01:00
|
|
|
@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
|
2015-05-11 21:10:51 +02:00
|
|
|
double gemExp = 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);
|
|
|
|
|
2015-05-11 21:10:51 +02:00
|
|
|
gemExp += (int)gem.Gems;
|
2014-11-09 00:06:04 +01:00
|
|
|
}
|
2015-05-14 05:27:33 +02:00
|
|
|
gemExp = Math.min(gemExp, 250) * 6;
|
2014-11-07 09:20:15 +01:00
|
|
|
|
2015-05-11 21:10:51 +02:00
|
|
|
//Game Time = 1 Exp per 3 Seconds
|
2015-06-27 04:38:04 +02:00
|
|
|
long time = System.currentTimeMillis();
|
2015-06-27 12:39:05 +02:00
|
|
|
|
2015-06-27 04:38:04 +02:00
|
|
|
//Exp Until They Quit
|
2015-06-27 12:39:05 +02:00
|
|
|
if (!player.isOnline())
|
|
|
|
{
|
|
|
|
if (_playerQuitTime.containsKey(player.getName()))
|
|
|
|
{
|
|
|
|
time = _playerQuitTime.get(player.getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time = _startTime;
|
|
|
|
}
|
|
|
|
}
|
2015-06-27 04:38:04 +02:00
|
|
|
|
|
|
|
double timeExp = (time - _startTime)/1500d;
|
2014-11-09 00:33:50 +01:00
|
|
|
|
|
|
|
//Mult
|
|
|
|
double mult = 1;
|
2015-05-11 21:10:51 +02:00
|
|
|
if (winners.contains(player))
|
|
|
|
mult = 1.5;
|
2014-11-09 00:33:50 +01:00
|
|
|
|
2015-05-11 21:10:51 +02:00
|
|
|
//Exp
|
|
|
|
int expGained = (int)((timeExp + gemExp)*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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|