Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/SmashKit.java

229 lines
5.6 KiB
Java
Raw Normal View History

2013-08-29 08:20:36 +02:00
package nautilus.game.arcade.kit;
import java.util.Collection;
import java.util.Iterator;
2013-08-29 08:20:36 +02:00
import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
2013-08-29 08:20:36 +02:00
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.event.UpdateEvent;
2013-08-29 08:20:36 +02:00
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
2013-08-29 08:20:36 +02:00
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
2013-08-29 08:20:36 +02:00
import org.bukkit.inventory.ItemStack;
public abstract class SmashKit extends Kit
{
private NautHashMap<Player, Long> _superActive = new NautHashMap<Player, Long>();
private int _superCharges = 1;
private String _superName;
private long _superDuration;
private Sound _superSound;
2013-08-29 08:20:36 +02:00
public SmashKit(ArcadeManager manager, String name,
KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks,
EntityType entityType, ItemStack itemInHand,
String superName, long superDuration, Sound superSound)
2013-08-29 08:20:36 +02:00
{
super(manager, name, kitAvailability, 3000, kitDesc, kitPerks, entityType, itemInHand);
_superName = superName;
_superDuration = superDuration;
_superSound = superSound;
2013-08-29 08:20:36 +02:00
}
2014-08-04 06:31:55 +02:00
public SmashKit(ArcadeManager manager, String name,
KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks,
EntityType entityType, ItemStack itemInHand,
String superName, long superDuration, Sound superSound)
2014-08-04 06:31:55 +02:00
{
super(manager, name, kitAvailability, cost, kitDesc, kitPerks, entityType, itemInHand);
_superName = superName;
_superDuration = superDuration;
_superSound = superSound;
2014-08-04 06:31:55 +02:00
}
@Override
2013-08-29 08:20:36 +02:00
public void DisplayDesc(Player player)
{
for (int i=0 ; i<3 ; i++)
UtilPlayer.message(player, "");
2013-08-29 08:20:36 +02:00
UtilPlayer.message(player, ArcadeFormat.Line);
UtilPlayer.message(player, "§aKit - §f§l" + GetName());
2013-08-29 08:20:36 +02:00
//Desc
for (String line : GetDesc())
{
UtilPlayer.message(player, C.cGray + " " + line);
}
//Perk Descs
for (Perk perk : GetPerks())
{
if (!perk.IsVisible())
continue;
2013-08-29 08:20:36 +02:00
for (String line : perk.GetDesc())
{
UtilPlayer.message(player, C.cGray + " " + line);
}
}
2013-08-29 08:20:36 +02:00
UtilPlayer.message(player, ArcadeFormat.Line);
}
@EventHandler
public void triggerSuper(PlayerInteractEvent event)
{
2015-01-30 01:08:23 +01:00
if (!Manager.GetGame().IsLive())
return;
if (!HasKit(event.getPlayer()))
return;
if (!UtilGear.isMat(event.getItem(), Material.NETHER_STAR))
return;
2015-01-30 01:08:23 +01:00
if (!Recharge.Instance.use(event.getPlayer(), _superName, 500, true, false))
return;
UtilInv.remove(event.getPlayer(), Material.NETHER_STAR, (byte)0, 1);
activateSuper(event.getPlayer());
//Inform + Effect
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), _superSound, 20f, 1f);
2015-01-30 01:08:23 +01:00
if (Recharge.Instance.use(event.getPlayer(), _superName + " Announce", 20000, false, false))
{
Manager.GetGame().Announce(C.Bold + event.getPlayer().getName() + " activated " + C.cGreen + C.Bold + _superName + ChatColor.RESET + C.Bold + "!");
UtilTextMiddle.display("Smash Crystal", event.getPlayer().getName() + " used " + C.cGreen + _superName, 5, 50, 5, UtilServer.getPlayers());
}
}
@EventHandler
public void expireSuper(UpdateEvent event)
{
Iterator<Player> superIter = _superActive.keySet().iterator();
while (superIter.hasNext())
{
Player player = superIter.next();
if (System.currentTimeMillis() > _superActive.get(player))
{
superIter.remove();
deactivateSuper(player);
}
}
}
@EventHandler
public void deathSuper(PlayerDeathEvent event)
{
2015-01-30 01:08:23 +01:00
if (_superActive.remove(event.getEntity()) != null)
deactivateSuper(event.getEntity());
}
public void activateSuper(Player player)
{
//Duration Super
if (_superDuration > 0)
{
_superActive.put(player, System.currentTimeMillis() + _superDuration);
Recharge.Instance.recharge(player, _superName);
Recharge.Instance.use(player, _superName, _superDuration, false, false);
Recharge.Instance.setDisplayForce(player, _superName, true);
Recharge.Instance.setCountdown(player, _superName, true);
}
//Disable Perks for Duration
for (Perk perk : GetPerks())
if (perk instanceof SmashPerk)
((SmashPerk)perk).addSuperActive(player);
2015-01-30 01:08:23 +01:00
//Items
giveSuperItems(player);
//Custom
activateSuperCustom(player);
//Deactivate if instant
if (_superDuration <= 0)
{
deactivateSuper(player);
}
}
public void activateSuperCustom(Player player)
{
//Null Default
}
public void deactivateSuper(Player player)
{
//Perks
for (Perk perk : GetPerks())
if (perk instanceof SmashPerk)
((SmashPerk)perk).removeSuperActive(player);
2015-01-30 01:08:23 +01:00
//Items
giveCoreItems(player);
//Custom
deactivateSuperCustom(player);
}
public void deactivateSuperCustom(Player player)
{
//Null Default
}
public Collection<Player> getSuperActive()
{
return _superActive.keySet();
}
public boolean isSuperActive(Player player)
{
return _superActive.containsKey(player);
}
public String getSuperName()
{
return _superName;
}
public int getSuperCharges()
{
return _superCharges;
}
public void setSuperCharges(int charges)
{
_superCharges = charges;
}
2015-01-30 01:08:23 +01:00
public abstract void giveCoreItems(Player player);
public abstract void giveSuperItems(Player player);
2013-08-29 08:20:36 +02:00
}