2014-09-18 06:25:39 +02:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Color;
|
|
|
|
import org.bukkit.FireworkEffect;
|
|
|
|
import org.bukkit.Material;
|
2014-09-19 10:01:38 +02:00
|
|
|
import org.bukkit.Sound;
|
2014-09-18 06:25:39 +02:00
|
|
|
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.PlayerCommandPreprocessEvent;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2014-09-24 07:46:55 +02:00
|
|
|
import mineplex.core.common.Rank;
|
2014-09-18 21:35:59 +02:00
|
|
|
import mineplex.core.common.util.C;
|
|
|
|
import mineplex.core.common.util.F;
|
2014-10-03 02:49:26 +02:00
|
|
|
import mineplex.core.common.util.UtilAlg;
|
2014-09-18 21:35:59 +02:00
|
|
|
import mineplex.core.common.util.UtilFirework;
|
2014-09-19 10:01:38 +02:00
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2014-09-18 21:35:59 +02:00
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.core.common.util.UtilTitle;
|
2014-09-19 04:03:46 +02:00
|
|
|
import mineplex.core.pet.PetManager;
|
2014-09-18 21:35:59 +02:00
|
|
|
import mineplex.core.reward.Reward;
|
|
|
|
import mineplex.core.reward.RewardData;
|
|
|
|
import mineplex.core.reward.RewardManager;
|
|
|
|
import mineplex.core.reward.RewardRarity;
|
|
|
|
import mineplex.core.reward.rewards.InventoryReward;
|
|
|
|
import nautilus.game.arcade.ArcadeManager;
|
|
|
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
|
|
|
import nautilus.game.arcade.game.Game.GameState;
|
|
|
|
|
2014-09-18 06:25:39 +02:00
|
|
|
public class GameLootManager implements Listener
|
|
|
|
{
|
|
|
|
private ArcadeManager Manager;
|
|
|
|
|
|
|
|
private RewardManager _rewardManager;
|
|
|
|
|
|
|
|
private HashSet<Player> _players = new HashSet<Player>();
|
|
|
|
|
|
|
|
private long _startTime = 0;
|
|
|
|
|
2014-09-19 04:03:46 +02:00
|
|
|
public GameLootManager(ArcadeManager manager, PetManager petManager)
|
2014-09-18 06:25:39 +02:00
|
|
|
{
|
|
|
|
Manager = manager;
|
|
|
|
|
|
|
|
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
|
|
|
|
|
2014-09-19 04:03:46 +02:00
|
|
|
_rewardManager = new RewardManager(Manager.GetDonation(), Manager.getInventoryManager(), petManager,
|
2014-09-18 09:05:56 +02:00
|
|
|
100, 300,
|
2014-09-18 06:36:22 +02:00
|
|
|
750, 1500,
|
|
|
|
2000, 3000,
|
|
|
|
10000, 20000,
|
|
|
|
false);
|
2014-09-18 06:25:39 +02:00
|
|
|
|
|
|
|
//Chest
|
2014-09-18 21:35:59 +02:00
|
|
|
_rewardManager.addReward(new InventoryReward(_rewardManager, Manager.getInventoryManager(), "Treasure Chest", "Treasure Chest", 1, 1,
|
2014-10-03 02:49:26 +02:00
|
|
|
new ItemStack(Material.CHEST), RewardRarity.COMMON, 4));
|
2014-09-18 06:25:39 +02:00
|
|
|
|
|
|
|
//Key
|
2014-09-18 21:35:59 +02:00
|
|
|
_rewardManager.addReward(new InventoryReward(_rewardManager, Manager.getInventoryManager(), "Treasure Key", "Treasure Key", 1, 1,
|
2014-10-03 02:49:26 +02:00
|
|
|
new ItemStack(Material.DIAMOND), RewardRarity.UNCOMMON, 1000));
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void registerPlayers(GameStateChangeEvent event)
|
|
|
|
{
|
2014-10-03 02:49:26 +02:00
|
|
|
if (!Manager.IsRewardItems())
|
2014-09-18 06:25:39 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetState() != GameState.Live)
|
|
|
|
return;
|
|
|
|
|
2014-10-03 02:49:26 +02:00
|
|
|
_players.clear();
|
|
|
|
|
|
|
|
int requirement = (int)((double)event.GetGame().Manager.GetPlayerFull() * 0.5d);
|
|
|
|
|
|
|
|
event.GetGame().CanGiveLoot = (double)event.GetGame().GetPlayers(true).size() >= requirement;
|
|
|
|
|
|
|
|
if (!event.GetGame().CanGiveLoot)
|
|
|
|
{
|
|
|
|
event.GetGame().Announce(C.Bold + "Game Loot Disabled. Requires " + requirement + " Players.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-18 06:25:39 +02:00
|
|
|
for (Player player : event.GetGame().GetPlayers(true))
|
|
|
|
_players.add(player);
|
|
|
|
|
|
|
|
_startTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void unregisterPlayer(PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
_players.remove(event.getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void giveLoot(final GameStateChangeEvent event)
|
|
|
|
{
|
2014-09-18 09:05:56 +02:00
|
|
|
if (!Manager.IsRewardItems())
|
2014-09-18 06:25:39 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetState() != GameState.Dead)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.GetPlugin(), new Runnable()
|
|
|
|
{
|
|
|
|
public void run()
|
|
|
|
{
|
2014-10-03 02:49:26 +02:00
|
|
|
int rewardsGiven = 0;
|
|
|
|
|
2014-09-18 06:25:39 +02:00
|
|
|
for (Player player : _players)
|
|
|
|
{
|
2014-10-03 02:49:26 +02:00
|
|
|
if (giveReward(player, false))
|
|
|
|
rewardsGiven++;
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
2014-09-18 09:05:56 +02:00
|
|
|
|
2014-10-03 02:49:26 +02:00
|
|
|
if (rewardsGiven == 0 && !_players.isEmpty())
|
|
|
|
{
|
|
|
|
giveReward(UtilAlg.Random(_players), true);
|
|
|
|
}
|
|
|
|
|
2014-09-18 09:05:56 +02:00
|
|
|
_players.clear();
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
|
|
|
}, 240);
|
|
|
|
//Delay after Achievements
|
|
|
|
}
|
|
|
|
|
2014-10-03 02:49:26 +02:00
|
|
|
public boolean giveReward(Player player, boolean force)
|
2014-09-18 06:25:39 +02:00
|
|
|
{
|
2014-10-03 02:49:26 +02:00
|
|
|
if (!force)
|
2014-09-24 07:46:55 +02:00
|
|
|
{
|
2014-10-03 02:49:26 +02:00
|
|
|
double chance = Math.min(0.5, 0.1 + (System.currentTimeMillis() - _startTime)/3600000d);
|
|
|
|
|
|
|
|
if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA))
|
2014-09-24 07:46:55 +02:00
|
|
|
{
|
2014-10-03 02:49:26 +02:00
|
|
|
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
|
|
|
|
{
|
|
|
|
chance *= 1.4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chance *= 1.2;
|
|
|
|
}
|
2014-09-24 07:46:55 +02:00
|
|
|
}
|
2014-10-03 02:49:26 +02:00
|
|
|
|
|
|
|
if (Math.random() > chance)
|
|
|
|
return false;
|
2014-09-24 07:46:55 +02:00
|
|
|
}
|
2014-09-18 06:25:39 +02:00
|
|
|
|
2014-09-18 21:35:59 +02:00
|
|
|
Reward reward = _rewardManager.nextReward(player, null, false, false);
|
2014-09-18 06:25:39 +02:00
|
|
|
|
2014-09-18 21:35:59 +02:00
|
|
|
RewardData rewardData = reward.giveReward("GameLoot", player);
|
2014-09-18 06:25:39 +02:00
|
|
|
|
2014-09-18 21:35:59 +02:00
|
|
|
String outputName = reward.getRarity().getColor() + rewardData.getFriendlyName();
|
2014-09-18 06:25:39 +02:00
|
|
|
|
2014-09-19 10:01:38 +02:00
|
|
|
String rarityName = "";
|
|
|
|
if (reward.getRarity() != RewardRarity.COMMON)
|
|
|
|
rarityName = " " + reward.getRarity().getColor() + reward.getRarity().getName();
|
|
|
|
|
2014-09-18 09:05:56 +02:00
|
|
|
//Log
|
2014-09-19 10:01:38 +02:00
|
|
|
System.out.println(F.name(player.getName()) + " found" + rarityName + " " + outputName);
|
2014-09-18 09:05:56 +02:00
|
|
|
|
2014-09-18 06:25:39 +02:00
|
|
|
//Self Display
|
2014-09-19 10:01:38 +02:00
|
|
|
UtilTitle.display(C.cGreen + "Game Loot", "You found " + outputName, 20, 120, 20, player);
|
|
|
|
//if (reward.getRarity() == RewardRarity.COMMON)
|
|
|
|
// UtilPlayer.message(player, F.main("Loot", "You found " + rarityName + outputName));
|
2014-09-18 06:25:39 +02:00
|
|
|
|
|
|
|
Random _random = new Random();
|
|
|
|
|
|
|
|
//Announce
|
2014-09-19 10:01:38 +02:00
|
|
|
//if (reward.getRarity() != RewardRarity.COMMON)
|
2014-09-18 06:25:39 +02:00
|
|
|
{
|
2014-09-19 10:01:38 +02:00
|
|
|
Bukkit.broadcastMessage(F.main("Loot", F.name(player.getName()) + " found" + rarityName + " " + outputName));
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Effect
|
|
|
|
if (reward.getRarity() == RewardRarity.UNCOMMON)
|
|
|
|
{
|
|
|
|
FireworkEffect effect = FireworkEffect.builder().withColor(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255)))
|
|
|
|
.withFade(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255)))
|
|
|
|
.with(FireworkEffect.Type.STAR)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
UtilFirework.playFirework(player.getEyeLocation(), effect);
|
|
|
|
}
|
|
|
|
else if (reward.getRarity() == RewardRarity.RARE)
|
|
|
|
{
|
|
|
|
FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BALL).withColor(Color.YELLOW).withFade(Color.WHITE).build();
|
|
|
|
UtilFirework.playFirework(player.getEyeLocation(), effect);
|
2014-09-19 10:01:38 +02:00
|
|
|
|
|
|
|
player.getWorld().playSound(player.getEyeLocation().add(0.5, 0.5, 0.5), Sound.WITHER_SPAWN, 5F, 1.2F);
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
|
|
|
else if (reward.getRarity() == RewardRarity.LEGENDARY)
|
|
|
|
{
|
|
|
|
FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLACK).build();
|
|
|
|
UtilFirework.playFirework(player.getEyeLocation(), effect);
|
2014-09-19 10:01:38 +02:00
|
|
|
|
|
|
|
player.getWorld().playSound(player.getEyeLocation().add(0.5, 0.5, 0.5), Sound.ENDERDRAGON_DEATH, 10F, 2.0F);
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
2014-10-03 02:49:26 +02:00
|
|
|
|
|
|
|
return true;
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void command(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
if (!event.getPlayer().isOp())
|
|
|
|
return;
|
|
|
|
|
|
|
|
//TODO Remove
|
|
|
|
if (event.getMessage().startsWith("/lootdebug"))
|
|
|
|
{
|
|
|
|
event.getPlayer().sendMessage(C.cGreen + C.Bold + "Loot Debug...");
|
2014-10-03 02:49:26 +02:00
|
|
|
giveReward(event.getPlayer(), true);
|
2014-09-19 10:01:38 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2014-09-18 06:25:39 +02:00
|
|
|
}
|
|
|
|
}
|