67 lines
1.6 KiB
Java
67 lines
1.6 KiB
Java
|
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>
|
||
|
{
|
||
|
private long _startTime;
|
||
|
|
||
|
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;
|
||
|
|
||
|
if (event.GetState() == Game.GameState.End)
|
||
|
{
|
||
|
List<Player> winners = getGame().getWinners();
|
||
|
|
||
|
if (winners != null)
|
||
|
{
|
||
|
for (Player player : event.GetGame().GetPlayers(false))
|
||
|
{
|
||
|
//Tally Gems
|
||
|
double gems = 0;
|
||
|
for (GemData gem : event.GetGame().GetGems(player).values())
|
||
|
gems += (int)gem.Gems;
|
||
|
|
||
|
//Game Time
|
||
|
double time = (int) ((System.currentTimeMillis() - _startTime)/60000d);
|
||
|
|
||
|
//Mult
|
||
|
double mult = 1;
|
||
|
if (!winners.contains(player))
|
||
|
mult = 0.5;
|
||
|
|
||
|
//Exp
|
||
|
int expGained = (int)(time*gems*mult);
|
||
|
|
||
|
//Record Global and per Game
|
||
|
addStat(player, "ExpEarned", expGained, false, true);
|
||
|
addStat(player, "ExpEarned", expGained, false, false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|