2013-08-27 17:14:08 +02:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2014-08-08 05:46:35 +02:00
|
|
|
import mineplex.core.achievement.Achievement;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.common.util.C;
|
2014-08-08 05:46:35 +02:00
|
|
|
import mineplex.core.common.util.Callback;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.common.util.F;
|
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.minecraft.game.core.combat.CombatComponent;
|
|
|
|
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
|
|
|
|
import nautilus.game.arcade.ArcadeFormat;
|
|
|
|
import nautilus.game.arcade.ArcadeManager;
|
2013-09-11 04:22:55 +02:00
|
|
|
import nautilus.game.arcade.GameType;
|
2013-08-27 17:14:08 +02:00
|
|
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
|
|
|
import nautilus.game.arcade.events.PlayerStateChangeEvent;
|
|
|
|
import nautilus.game.arcade.game.Game;
|
|
|
|
import nautilus.game.arcade.game.GemData;
|
|
|
|
import nautilus.game.arcade.game.Game.GameState;
|
|
|
|
import nautilus.game.arcade.game.GameTeam.PlayerState;
|
|
|
|
|
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
|
|
|
|
public class GameGemManager implements Listener
|
|
|
|
{
|
|
|
|
ArcadeManager Manager;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2014-05-06 18:06:39 +02:00
|
|
|
boolean DoubleGem = false;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
public GameGemManager(ArcadeManager manager)
|
|
|
|
{
|
|
|
|
Manager = manager;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void PlayerKillAward(CombatDeathEvent event)
|
|
|
|
{
|
2014-05-02 06:35:41 +02:00
|
|
|
if (Manager.IsTournamentServer())
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Game game = Manager.GetGame();
|
|
|
|
if (game == null) return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (!(event.GetEvent().getEntity() instanceof Player))
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Player killed = (Player)event.GetEvent().getEntity();
|
|
|
|
|
|
|
|
if (event.GetLog().GetKiller() != null)
|
|
|
|
{
|
|
|
|
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
|
|
|
|
|
|
|
|
if (killer != null && !killer.equals(killed))
|
|
|
|
{
|
|
|
|
//Kill
|
|
|
|
game.AddGems(killer, game.GetKillsGems(killer, killed, false), "Kills", true);
|
|
|
|
|
|
|
|
//First Kill
|
|
|
|
if (game.FirstKill)
|
|
|
|
{
|
|
|
|
game.AddGems(killer, 10, "First Blood", false);
|
|
|
|
|
|
|
|
game.FirstKill = false;
|
|
|
|
|
|
|
|
game.Announce(F.main("Game", Manager.GetColor(killer) + killer.getName() + " drew first blood!"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CombatComponent log : event.GetLog().GetAttackers())
|
|
|
|
{
|
|
|
|
if (event.GetLog().GetKiller() != null && log.equals(event.GetLog().GetKiller()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Player assist = UtilPlayer.searchExact(log.GetName());
|
|
|
|
|
|
|
|
//Assist
|
|
|
|
if (assist != null)
|
|
|
|
game.AddGems(assist, game.GetKillsGems(assist, killed, true), "Kill Assists", true);
|
|
|
|
}
|
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
@EventHandler
|
|
|
|
public void PlayerQuit(PlayerQuitEvent event)
|
|
|
|
{
|
2014-05-02 06:35:41 +02:00
|
|
|
if (Manager.IsTournamentServer())
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
Game game = Manager.GetGame();
|
|
|
|
if (game == null) return;
|
|
|
|
|
|
|
|
RewardGems(game, event.getPlayer(), true);
|
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void PlayerStateChange(PlayerStateChangeEvent event)
|
|
|
|
{
|
2014-05-02 06:35:41 +02:00
|
|
|
if (Manager.IsTournamentServer())
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (event.GetState() != PlayerState.OUT)
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-11-02 05:42:37 +01:00
|
|
|
if (event.GetGame().GetType() == GameType.Paintball)
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
RewardGems(event.GetGame(), event.GetPlayer(), false);
|
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2014-08-08 09:05:11 +02:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2013-08-27 17:14:08 +02:00
|
|
|
public void GameStateChange(GameStateChangeEvent event)
|
|
|
|
{
|
2014-05-02 06:35:41 +02:00
|
|
|
if (Manager.IsTournamentServer())
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (event.GetState() != GameState.Dead)
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
for (Player player : UtilServer.getPlayers())
|
|
|
|
RewardGems(event.GetGame(), player, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RewardGems(Game game, Player player, boolean give)
|
|
|
|
{
|
2014-05-02 06:35:41 +02:00
|
|
|
if (Manager.IsTournamentServer())
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
//Inform Gems
|
|
|
|
AnnounceGems(game, player, game.GetPlayerGems().get(player), give);
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
//Give Gems
|
|
|
|
if (give)
|
2013-10-18 09:46:06 +02:00
|
|
|
GiveGems(game, player, game.GetPlayerGems().remove(player), game.GemMultiplier);
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-10-18 09:46:06 +02:00
|
|
|
public void GiveGems(Game game, Player player, HashMap<String,GemData> gems, double gameMult)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2014-05-02 06:35:41 +02:00
|
|
|
if (Manager.IsTournamentServer())
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (gems == null)
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
|
|
|
int earned = 0;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
for (GemData data : gems.values())
|
2014-08-08 05:46:35 +02:00
|
|
|
earned += (int)data.Gems;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2014-08-08 05:46:35 +02:00
|
|
|
if (earned <= 0)
|
|
|
|
earned = 1;
|
|
|
|
|
|
|
|
earned = (int) (earned * gameMult);
|
|
|
|
|
|
|
|
int total = earned;
|
|
|
|
|
|
|
|
//Gem Boooster
|
|
|
|
total += (int)(earned * game.GetGemBoostAmount());
|
|
|
|
|
|
|
|
//Gem Finder
|
2014-08-12 03:23:53 +02:00
|
|
|
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GLOBAL_GEM_HUNTER).getLevel();
|
|
|
|
if (gemFinder > 0)
|
2014-08-08 05:46:35 +02:00
|
|
|
{
|
2014-08-12 03:23:53 +02:00
|
|
|
total += (int)(earned * (gemFinder * 0.25));
|
2014-08-08 05:46:35 +02:00
|
|
|
}
|
2014-08-12 03:23:53 +02:00
|
|
|
|
2014-03-01 00:35:06 +01:00
|
|
|
if (DoubleGem)
|
2014-08-08 05:46:35 +02:00
|
|
|
total += earned;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2013-10-18 09:46:06 +02:00
|
|
|
Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), total);
|
2014-08-10 10:36:18 +02:00
|
|
|
|
2014-08-08 05:46:35 +02:00
|
|
|
//Stats
|
|
|
|
Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total);
|
|
|
|
Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", total);
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2014-08-10 10:36:18 +02:00
|
|
|
|
2014-08-08 09:05:11 +02:00
|
|
|
public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2014-05-02 06:35:41 +02:00
|
|
|
if (Manager.IsTournamentServer())
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
if (gems == null)
|
|
|
|
return;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
|
|
|
|
|
|
|
|
UtilPlayer.message(player, "");
|
|
|
|
UtilPlayer.message(player, ArcadeFormat.Line);
|
|
|
|
|
2014-08-08 09:05:11 +02:00
|
|
|
UtilPlayer.message(player, "§f§lGems Earned");
|
2013-08-27 17:14:08 +02:00
|
|
|
UtilPlayer.message(player, "");
|
2014-08-10 10:36:18 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
int earnedGems = 0;
|
|
|
|
|
|
|
|
for (String type : gems.keySet())
|
|
|
|
{
|
|
|
|
int gemCount = (int)gems.get(type).Gems;
|
|
|
|
if (gemCount <= 0)
|
|
|
|
gemCount = 1;
|
|
|
|
|
|
|
|
earnedGems += gemCount;
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
int amount = gems.get(type).Amount;
|
|
|
|
String amountStr = "";
|
|
|
|
if (amount > 0)
|
|
|
|
amountStr = amount + " ";
|
|
|
|
|
2013-10-14 01:29:20 +02:00
|
|
|
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int)(gemCount * game.GemMultiplier) + " Gems") + " for " + F.elem(amountStr + type));
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-09-21 05:53:12 +02:00
|
|
|
earnedGems = (int) (earnedGems * game.GemMultiplier);
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2014-08-08 05:46:35 +02:00
|
|
|
int totalGems = earnedGems;
|
|
|
|
|
|
|
|
//Gem Booster
|
|
|
|
if (game.GetGemBoostAmount() > 0)
|
2013-12-24 09:14:40 +01:00
|
|
|
{
|
2014-08-08 09:05:11 +02:00
|
|
|
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int)(earnedGems*game.GetGemBoostAmount()) + " Gems") + " for " +
|
|
|
|
F.elem(game.GemBoosters.size() + " Gem Boosters " + C.cGreen + "+" + (int)(game.GetGemBoostAmount()*100) + "%"));
|
2014-08-08 05:46:35 +02:00
|
|
|
|
|
|
|
totalGems += earnedGems * game.GetGemBoostAmount();
|
2013-12-24 09:14:40 +01:00
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
|
|
|
//Gem Finder
|
2014-08-12 03:23:53 +02:00
|
|
|
int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GLOBAL_GEM_HUNTER).getLevel();
|
|
|
|
if (gemFinder > 0)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2014-08-12 03:23:53 +02:00
|
|
|
UtilPlayer.message(player, F.elem(C.cGreen + "+" + ((int)(earnedGems*(gemFinder * 0.25)) + " Gems") + " for " +
|
|
|
|
F.elem("Gem Hunter " + gemFinder + C.cGreen + " +" + (gemFinder*25) + "%")));
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2014-08-12 03:23:53 +02:00
|
|
|
totalGems += earnedGems * (gemFinder * 0.25);
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2014-03-01 00:35:06 +01:00
|
|
|
//Double Gem
|
|
|
|
if (DoubleGem)
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems) + " Gems") + " for " + F.elem(C.cDGreen + "Double Gem Weekend"));
|
2014-08-08 05:46:35 +02:00
|
|
|
|
|
|
|
totalGems += earnedGems;
|
2014-03-01 00:35:06 +01:00
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-12-24 09:14:40 +01:00
|
|
|
//Inform
|
2013-08-27 17:14:08 +02:00
|
|
|
UtilPlayer.message(player, "");
|
|
|
|
if (give)
|
|
|
|
{
|
2014-05-26 01:42:39 +02:00
|
|
|
UtilPlayer.message(player, F.elem(C.cWhite + "§lYou now have " +
|
2014-08-08 05:46:35 +02:00
|
|
|
C.cGreen + C.Bold + (Manager.GetDonation().Get(player.getName()).GetGems() + totalGems) + " Gems"));
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-26 01:42:39 +02:00
|
|
|
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."));
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
UtilPlayer.message(player, ArcadeFormat.Line);
|
|
|
|
}
|
2014-08-08 05:46:35 +02:00
|
|
|
|
2014-08-10 10:36:18 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|