Add Guns into Battle Royale

This commit is contained in:
Sam 2017-06-24 18:19:56 +01:00
parent c6a3001bae
commit 31533f29b7
8 changed files with 464 additions and 296 deletions

View File

@ -238,7 +238,11 @@ public enum GameType
MOBA(MobaClassic.class, GameDisplay.MOBA), MOBA(MobaClassic.class, GameDisplay.MOBA),
MOBATraining(MobaTraining.class, GameDisplay.MOBATraining), MOBATraining(MobaTraining.class, GameDisplay.MOBATraining),
BattleRoyale(BattleRoyaleSolo.class, GameDisplay.BattleRoyale), BattleRoyale(BattleRoyaleSolo.class, GameDisplay.BattleRoyale, new Pair[]
{
Pair.create(MinecraftVersion.Version1_8, "http://file.mineplex.com/ResStrikeGames18.zip"),
Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResStrikeGames19.zip")
}, false),
Event(EventGame.class, GameDisplay.Event, new GameType[]{ Event(EventGame.class, GameDisplay.Event, new GameType[]{
GameType.BaconBrawl, GameType.Barbarians, GameType.Bridge, GameType.Build, GameType.Build, GameType.BaconBrawl, GameType.Barbarians, GameType.Bridge, GameType.Build, GameType.Build,

View File

@ -12,6 +12,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -20,6 +21,9 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.minestrike.GunModule;
import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats;
import nautilus.game.arcade.game.modules.StrikeGamesModule;
import nautilus.game.arcade.game.modules.chest.ChestLootModule; import nautilus.game.arcade.game.modules.chest.ChestLootModule;
import nautilus.game.arcade.game.modules.chest.ChestLootPool; import nautilus.game.arcade.game.modules.chest.ChestLootPool;
import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.game.modules.compass.CompassModule;
@ -29,6 +33,8 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.WorldBorder; import org.bukkit.WorldBorder;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Chicken; import org.bukkit.entity.Chicken;
import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -59,12 +65,18 @@ public abstract class BattleRoyale extends Game
private final Map<Player, BattleRoyalePlayer> _playerData = new HashMap<>(70); private final Map<Player, BattleRoyalePlayer> _playerData = new HashMap<>(70);
protected GunModule _gunModule;
protected WorldBorder _border; protected WorldBorder _border;
private boolean _colouredMessage;
public BattleRoyale(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc) public BattleRoyale(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc)
{ {
super(manager, gameType, kits, gameDesc); super(manager, gameType, kits, gameDesc);
// TODO REMOVE THIS
TeleportsDisqualify = false;
PrepareTime = PREPARE_TIME; PrepareTime = PREPARE_TIME;
PrepareFreeze = false; PrepareFreeze = false;
Damage = false; Damage = false;
@ -74,6 +86,7 @@ public abstract class BattleRoyale extends Game
HungerSet = 20; HungerSet = 20;
DeathTeleport = false; DeathTeleport = false;
WorldChunkUnload = true; WorldChunkUnload = true;
GameTimeout = TimeUnit.MINUTES.toMillis(40);
ItemDrop = true; ItemDrop = true;
ItemPickup = true; ItemPickup = true;
@ -83,33 +96,81 @@ public abstract class BattleRoyale extends Game
InventoryOpenBlock = true; InventoryOpenBlock = true;
InventoryOpenChest = true; InventoryOpenChest = true;
new CompassModule() BlockBreakAllow.add(Material.GLASS.getId());
BlockBreakAllow.add(Material.STAINED_GLASS.getId());
BlockBreakAllow.add(Material.THIN_GLASS.getId());
BlockBreakAllow.add(Material.STAINED_GLASS_PANE.getId());
BlockBreakAllow.add(Material.LEAVES.getId());
_gunModule = new GunModule(this);
_gunModule.EnableCleaning = false;
_gunModule.EnableDrop = false;
_gunModule.EnablePickup = false;
_gunModule.BlockRegeneration = false;
_gunModule.EnableNormalArmor = true;
new StrikeGamesModule(_gunModule)
.register(this); .register(this);
new ChestLootModule() new CompassModule()
.registerChestType("Standard",
// Swords
new ChestLootPool()
.addItem(new ItemStack(Material.WOOD_SWORD))
.addItem(new ItemStack(Material.STONE_SWORD))
,
// Armour
new ChestLootPool()
.addItem(new ItemStack(Material.LEATHER_HELMET))
.addItem(new ItemStack(Material.LEATHER_CHESTPLATE))
.addItem(new ItemStack(Material.LEATHER_LEGGINGS))
.addItem(new ItemStack(Material.LEATHER_BOOTS))
)
.register(this); .register(this);
} }
@Override @Override
public void ParseData() public void ParseData()
{ {
ChestLootModule chestModule = getModule(ChestLootModule.class); new ChestLootModule()
.spawnNearbyDataPoints()
.registerChestType("Standard", WorldData.GetDataLocs("ORANGE"),
chestModule.setSpawnsForType("Standard", WorldData.GetDataLocs("ORANGE")); // Guns
new ChestLootPool()
.addItem(buildFromGun(GunStats.GLOCK_18))
.addItem(buildFromGun(GunStats.CZ75))
.addItem(buildFromGun(GunStats.DEAGLE))
.addItem(buildFromGun(GunStats.P250))
.addItem(buildFromGun(GunStats.P2000))
.addItem(buildFromGun(GunStats.AK47), 0.2)
.addItem(buildFromGun(GunStats.M4A4), 0.2)
.setProbability(0.4)
,
// Weapons
new ChestLootPool()
.addItem(new ItemStack(Material.WOOD_SWORD))
.addItem(new ItemStack(Material.STONE_SWORD), 0.3)
.setProbability(0.5)
,
// Armour
new ChestLootPool()
.addItem(new ItemStack(Material.LEATHER_HELMET))
.addItem(new ItemStack(Material.LEATHER_CHESTPLATE))
.addItem(new ItemStack(Material.LEATHER_LEGGINGS))
.addItem(new ItemStack(Material.LEATHER_BOOTS))
,
// Food
new ChestLootPool()
.addItem(new ItemStack(Material.RAW_FISH), 1, 3)
.addItem(new ItemStack(Material.RAW_BEEF), 1, 3)
.addItem(new ItemStack(Material.RAW_CHICKEN), 1, 3)
.addItem(new ItemStack(Material.MUTTON), 1, 3)
.addItem(new ItemStack(Material.MELON), 1, 3)
.addItem(new ItemStack(Material.BREAD), 1, 2, 0.4)
.addItem(new ItemStack(Material.COOKED_FISH), 0.2)
.addItem(new ItemStack(Material.COOKED_BEEF), 0.2)
.addItem(new ItemStack(Material.COOKED_CHICKEN), 0.2)
.addItem(new ItemStack(Material.COOKED_MUTTON), 0.2)
.addItem(new ItemStack(Material.COOKIE), 0.2)
,
// Misc
new ChestLootPool()
.addItem(new ItemStack(Material.STICK), 1, 2)
.setProbability(0.2)
)
.register(this);
WorldData.MinX = -MAX_CORD; WorldData.MinX = -MAX_CORD;
WorldData.MinZ = -MAX_CORD; WorldData.MinZ = -MAX_CORD;
@ -119,6 +180,13 @@ public abstract class BattleRoyale extends Game
_border = WorldData.World.getWorldBorder(); _border = WorldData.World.getWorldBorder();
} }
private ItemStack buildFromGun(GunStats gunStats)
{
return new ItemBuilder(gunStats.getSkin())
.setTitle(C.cWhiteB + gunStats.getName())
.build();
}
@EventHandler @EventHandler
public void prepare(GameStateChangeEvent event) public void prepare(GameStateChangeEvent event)
{ {
@ -229,6 +297,17 @@ public abstract class BattleRoyale extends Game
while (attempts++ < 20) while (attempts++ < 20)
{ {
Location location = UtilAlg.getRandomLocation(GetSpectatorLocation(), 200, 0, 200); Location location = UtilAlg.getRandomLocation(GetSpectatorLocation(), 200, 0, 200);
Block block = location.getBlock();
while (!UtilBlock.solid(block))
{
block = block.getRelative(BlockFace.DOWN);
}
if (block.isLiquid())
{
continue;
}
if (UtilBlock.airFoliage(UtilBlock.getHighest(location.getWorld(), location.getBlock()))) if (UtilBlock.airFoliage(UtilBlock.getHighest(location.getWorld(), location.getBlock())))
{ {
@ -266,6 +345,8 @@ public abstract class BattleRoyale extends Game
return; return;
} }
_colouredMessage = !_colouredMessage;
Iterator<Player> iterator = _playerData.keySet().iterator(); Iterator<Player> iterator = _playerData.keySet().iterator();
while (iterator.hasNext()) while (iterator.hasNext())
@ -287,27 +368,25 @@ public abstract class BattleRoyale extends Game
continue; continue;
} }
UtilTextBottom.display((player.getTicksLived() % 5 == 0 ? C.cGreenB : C.cWhiteB) + "PRESS YOUR SNEAK KEY TO DISMOUNT YOUR DRAGON", player); UtilTextBottom.display((_colouredMessage ? C.cGreenB : C.cWhiteB) + "PRESS YOUR SNEAK KEY TO DISMOUNT YOUR DRAGON", player);
if (dragon.getPassenger() == null || chicken.getPassenger() == null) if (dragon.getPassenger() == null || chicken.getPassenger() == null)
{ {
Recharge.Instance.useForce(player, "Fall Damage", TimeUnit.SECONDS.toMillis(10)); if (!UtilTime.elapsed(GetStateTime(), 4000))
UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, player.getLocation(), 5, 5, 5, 0.01F, 100, ViewDist.NORMAL); {
player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 1, 0.6F); player.sendMessage(F.main("Game", "Did you accidentally press sneak? Don't worry I'll put you back on your dragon."));
dragon.remove(); dragon.setPassenger(chicken);
chicken.remove(); chicken.setPassenger(player);
continue;
}
dismountDragon(player, royalePlayer);
iterator.remove(); iterator.remove();
} }
} }
if (!Damage && UtilTime.elapsed(GetStateTime(), MAX_DRAGON_TIME)) if (!Damage && UtilTime.elapsed(GetStateTime(), MAX_DRAGON_TIME))
{ {
_playerData.forEach((player, battleRoyalePlayer) -> _playerData.forEach(this::dismountDragon);
{
Recharge.Instance.useForce(player, "Fall Damage", TimeUnit.SECONDS.toMillis(10));
player.sendMessage(F.main("Game", "You were too slow!"));
battleRoyalePlayer.getDragon().remove();
battleRoyalePlayer.getChicken().remove();
});
_playerData.clear(); _playerData.clear();
Announce(C.cRedB + "Grace Period Over!", false); Announce(C.cRedB + "Grace Period Over!", false);
@ -323,6 +402,16 @@ public abstract class BattleRoyale extends Game
} }
} }
private void dismountDragon(Player player, BattleRoyalePlayer royalePlayer)
{
// Recharge this so that players won't take fall damage for the next 10 seconds
Recharge.Instance.useForce(player, "Fall Damage", TimeUnit.SECONDS.toMillis(10));
player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 1, 0.6F);
UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, player.getLocation(), 5, 5, 5, 0.01F, 100, ViewDist.NORMAL);
royalePlayer.getDragon().remove();
royalePlayer.getChicken().remove();
}
@EventHandler @EventHandler
public void fallDamage(CustomDamageEvent event) public void fallDamage(CustomDamageEvent event)
{ {
@ -344,4 +433,10 @@ public abstract class BattleRoyale extends Game
event.blockList().clear(); event.blockList().clear();
} }
} }
@EventHandler
public void damageToLevel(CustomDamageEvent event)
{
event.SetDamageToLevel(false);
}
} }

View File

@ -1,7 +1,6 @@
package nautilus.game.arcade.game.games.battleroyale; package nautilus.game.arcade.game.games.battleroyale;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
@ -11,6 +10,7 @@ import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.moba.kit.KitPlayer; import nautilus.game.arcade.game.games.moba.kit.KitPlayer;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -70,8 +70,9 @@ public class BattleRoyaleSolo extends BattleRoyale
Scoreboard.writeNewLine(); Scoreboard.writeNewLine();
int size = (int) _border.getSize(); int size = (int) _border.getSize();
Location center = _border.getCenter();
Scoreboard.write(C.cRedB + "World Border"); Scoreboard.write(C.cRedB + "World Border");
Scoreboard.write(UtilWorld.locToStrClean(_border.getCenter())); Scoreboard.write("(" + center.getBlockX() + ", " + center.getBlockZ() + ")");
Scoreboard.write(size + " Blocks Wide"); Scoreboard.write(size + " Blocks Wide");
Scoreboard.draw(); Scoreboard.draw();

View File

@ -1,31 +1,5 @@
package nautilus.game.arcade.game.games.survivalgames.modes; package nautilus.game.arcade.game.games.survivalgames.modes;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
@ -36,29 +10,28 @@ import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.loot.RandomItem; import mineplex.core.loot.RandomItem;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType; import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.minestrike.GunModule; import nautilus.game.arcade.game.games.minestrike.GunModule;
import nautilus.game.arcade.game.games.minestrike.items.StrikeItemType;
import nautilus.game.arcade.game.games.minestrike.items.grenades.FlashBang;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade;
import nautilus.game.arcade.game.games.minestrike.items.grenades.HighExplosive;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Incendiary;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Molotov;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Smoke;
import nautilus.game.arcade.game.games.minestrike.items.guns.Gun;
import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats; import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats;
import nautilus.game.arcade.game.games.minestrike.items.guns.GunType;
import nautilus.game.arcade.game.games.minestrike.items.guns.Shotgun;
import nautilus.game.arcade.game.games.survivalgames.SoloSurvivalGames; import nautilus.game.arcade.game.games.survivalgames.SoloSurvivalGames;
import nautilus.game.arcade.game.games.survivalgames.SupplyChestOpenEvent; import nautilus.game.arcade.game.games.survivalgames.SupplyChestOpenEvent;
import nautilus.game.arcade.game.games.survivalgames.kit.KitLooter; import nautilus.game.arcade.game.games.survivalgames.kit.KitLooter;
import nautilus.game.arcade.game.games.survivalgames.modes.kit.KitPlayer; import nautilus.game.arcade.game.games.survivalgames.modes.kit.KitPlayer;
import nautilus.game.arcade.game.modules.StrikeGamesModule;
import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Kit;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/** /**
* StrikeGames * StrikeGames
@ -68,13 +41,9 @@ import nautilus.game.arcade.kit.Kit;
public class StrikeGames extends SoloSurvivalGames public class StrikeGames extends SoloSurvivalGames
{ {
private GunModule _gunModule;
private long _peacePhase; private long _peacePhase;
private boolean _peace = false; private boolean _peace = false;
private HashMap<Player, ItemStack> _helmets;
public StrikeGames(ArcadeManager manager) public StrikeGames(ArcadeManager manager)
{ {
super(manager, new Kit[] super(manager, new Kit[]
@ -84,18 +53,19 @@ public class StrikeGames extends SoloSurvivalGames
Damage = false; Damage = false;
_helmets = new HashMap<>();
_peacePhase = 20000; _peacePhase = 20000;
HungerSet = 20; HungerSet = 20;
_gunModule = new GunModule(this); GunModule gunModule = new GunModule(this);
_gunModule.EnableCleaning = false; gunModule.EnableCleaning = false;
_gunModule.EnableDrop = false; gunModule.EnableDrop = false;
_gunModule.EnablePickup = false; gunModule.EnablePickup = false;
_gunModule.BlockRegeneration = false; gunModule.BlockRegeneration = false;
_gunModule.EnableNormalArmor = true; gunModule.EnableNormalArmor = true;
new StrikeGamesModule(gunModule)
.register(this);
} }
@EventHandler @EventHandler
@ -119,20 +89,6 @@ public class StrikeGames extends SoloSurvivalGames
Damage = true; Damage = true;
} }
@EventHandler
public void eatingGrenades(PlayerItemConsumeEvent event)
{
if (event.getItem().getType() == Material.POTATO_ITEM
|| event.getItem().getType() == Material.CARROT_ITEM
|| event.getItem().getType() == Material.APPLE
|| event.getItem().getType() == Material.PORK
|| event.getItem().getType() == Material.GRILLED_PORK)
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void DeathmatchDamage(UpdateEvent event) public void DeathmatchDamage(UpdateEvent event)
{ {
@ -163,39 +119,6 @@ public class StrikeGames extends SoloSurvivalGames
Announce(F.main("Game", "A Peace Phase of " + F.time((_peacePhase/1000) + "") + " seconds has started!")); Announce(F.main("Game", "A Peace Phase of " + F.time((_peacePhase/1000) + "") + " seconds has started!"));
} }
@EventHandler(priority=EventPriority.HIGHEST)
public void addHelmet(PlayerToggleSneakEvent event)
{
if (!IsLive())
return;
if (!IsAlive(event.getPlayer()))
return;
if (_gunModule.getScoped().containsKey(event.getPlayer()))
return;
if (event.getPlayer().getInventory().getHelmet() != null)
_helmets.put(event.getPlayer(), event.getPlayer().getInventory().getHelmet());
}
@EventHandler(priority=EventPriority.HIGHEST)
public void pumpkinDrop(PlayerDeathEvent event)
{
Iterator<ItemStack> itemIterator = event.getDrops().iterator();
while (itemIterator.hasNext())
{
ItemStack item = itemIterator.next();
if (item.getType() == Material.PUMPKIN
|| item.getType() == Material.PUMPKIN_STEM)
{
itemIterator.remove();
}
}
if (_helmets.containsKey(event.getEntity()))
event.getDrops().add(_helmets.get(event.getEntity()));
}
@EventHandler @EventHandler
public void disableCrafting(PlayerInteractEvent event) public void disableCrafting(PlayerInteractEvent event)
{ {
@ -206,13 +129,6 @@ public class StrikeGames extends SoloSurvivalGames
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler
public void weaponEnchantment(EnchantItemEvent event)
{
if (!UtilItem.isArmor(event.getItem()))
event.setCancelled(true);
}
public void setupLoot() public void setupLoot()
{ {
// Weapons // Weapons
@ -414,131 +330,6 @@ public class StrikeGames extends SoloSurvivalGames
getSupplyBlocks().remove(block); getSupplyBlocks().remove(block);
} }
@EventHandler
public void addEquipment(InventoryClickEvent event)
{
if (event.getCurrentItem() == null)
return;
if (!(event.getWhoClicked() instanceof Player))
return;
Player player = (Player) event.getWhoClicked();
if (!(event.getClickedInventory() instanceof PlayerInventory))
{
ItemStack stack = event.getCurrentItem();
for (GunStats stat : GunStats.values())
{
if (stat.getSkin() == stack.getType())
{
Gun gun = null;
if (stat.getGunType() == GunType.SHOTGUN)
{
gun = new Shotgun(stat, _gunModule);
}
else
{
gun = new Gun(stat, _gunModule);
}
gun.setStack(stack);
gun.updateWeaponName(player, null, false);
gun.addID();
_gunModule.registerGun(gun, player);
return;
}
}
Grenade grenade = null;
if (stack.getType() == Material.APPLE)
{
grenade = new HighExplosive();
}
else if (stack.getType() == Material.CARROT_ITEM)
{
grenade = new FlashBang();
}
else if (stack.getType() == Material.POTATO_ITEM)
{
grenade = new Smoke();
}
else if (stack.getType() == Material.PORK)
{
grenade = new Incendiary();
}
else if (stack.getType() == Material.GRILLED_PORK)
{
grenade = new Molotov();
}
if (grenade != null)
{
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(grenade.getName());
stack.setItemMeta(meta);
grenade.setStack(stack);
_gunModule.registerGrenade(grenade, player);
}
}
}
@EventHandler
public void triggerPickup(PlayerPickupItemEvent event)
{
if (!InProgress())
return;
if (!IsAlive(event.getPlayer()))
return;
//Guns
Gun gun = _gunModule.getDroppedGuns().get(event.getItem());
if (gun != null)
{
_gunModule.deregisterDroppedGun(gun);
_gunModule.registerGun(gun, event.getPlayer());
gun.setStack(event.getItem().getItemStack());
}
//Grenades
Grenade grenade = _gunModule.getDroppedGrenades().get(event.getItem());
if (grenade != null)
{
_gunModule.deregisterDroppedGrenade(grenade);
_gunModule.registerGrenade(grenade, event.getPlayer());
grenade.setStack(event.getItem().getItemStack());
}
}
@EventHandler
public void triggerDrop(PlayerDropItemEvent event)
{
if (!InProgress())
return;
//Guns
Gun gun = _gunModule.getGunInHand(event.getPlayer(), event.getItemDrop().getItemStack());
if (gun != null)
{
gun.drop(_gunModule, event.getPlayer(), false, false);
event.getItemDrop().remove();
event.getPlayer().setItemInHand(null);
return;
}
//Grenades
Grenade grenade = _gunModule.getGrenadeInHand(event.getPlayer(), event.getItemDrop().getItemStack());
if (grenade != null)
{
grenade.drop(_gunModule, event.getPlayer(), false, false);
event.getItemDrop().remove();
event.getPlayer().setItemInHand(null);
return;
}
}
@EventHandler @EventHandler
@Override @Override
public void ItemSpawn(ItemSpawnEvent event) public void ItemSpawn(ItemSpawnEvent event)

View File

@ -0,0 +1,220 @@
package nautilus.game.arcade.game.modules;
import mineplex.core.common.util.UtilItem;
import nautilus.game.arcade.game.games.minestrike.GunModule;
import nautilus.game.arcade.game.games.minestrike.items.grenades.FlashBang;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Grenade;
import nautilus.game.arcade.game.games.minestrike.items.grenades.HighExplosive;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Incendiary;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Molotov;
import nautilus.game.arcade.game.games.minestrike.items.grenades.Smoke;
import nautilus.game.arcade.game.games.minestrike.items.guns.Gun;
import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats;
import nautilus.game.arcade.game.games.minestrike.items.guns.GunType;
import nautilus.game.arcade.game.games.minestrike.items.guns.Shotgun;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.Map;
public class StrikeGamesModule extends Module
{
private final Map<Player, ItemStack> _helmets;
private final GunModule _gunModule;
public StrikeGamesModule(GunModule gunModule)
{
_gunModule = gunModule;
_helmets = new HashMap<>();
}
@EventHandler
public void eatingGrenades(PlayerItemConsumeEvent event)
{
Material material = event.getItem().getType();
switch (material)
{
case POTATO_ITEM:
case CARROT_ITEM:
case APPLE:
case PORK:
case GRILLED_PORK:
event.setCancelled(true);
break;
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void addHelmet(PlayerToggleSneakEvent event)
{
Player player = event.getPlayer();
ItemStack helmet = player.getInventory().getHelmet();
if (!getGame().IsLive() || !getGame().IsAlive(player) || _gunModule.getScoped().containsKey(player) || helmet == null)
{
return;
}
_helmets.put(event.getPlayer(), helmet);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void pumpkinDrop(PlayerDeathEvent event)
{
Player player = event.getEntity();
event.getDrops().removeIf(item -> item.getType() == Material.PUMPKIN || item.getType() == Material.PUMPKIN_STEM);
if (_helmets.containsKey(player))
{
event.getDrops().add(_helmets.get(player));
}
}
@EventHandler
public void weaponEnchantment(EnchantItemEvent event)
{
if (!UtilItem.isArmor(event.getItem()))
{
event.setCancelled(true);
}
}
@EventHandler
public void addEquipment(InventoryClickEvent event)
{
if (event.getCurrentItem() == null || !(event.getWhoClicked() instanceof Player) || event.getClickedInventory() instanceof PlayerInventory)
{
return;
}
Player player = (Player) event.getWhoClicked();
ItemStack stack = event.getCurrentItem();
for (GunStats stat : GunStats.values())
{
if (stat.getSkin() == stack.getType())
{
Gun gun;
if (stat.getGunType() == GunType.SHOTGUN)
{
gun = new Shotgun(stat, _gunModule);
}
else
{
gun = new Gun(stat, _gunModule);
}
gun.setStack(stack);
gun.updateWeaponName(player, null, false);
gun.addID();
_gunModule.registerGun(gun, player);
return;
}
}
Grenade grenade = null;
switch (stack.getType())
{
case APPLE:
grenade = new HighExplosive();
break;
case CARROT_ITEM:
grenade = new FlashBang();
break;
case POTATO_ITEM:
grenade = new Smoke();
break;
case PORK:
grenade = new Incendiary();
break;
case GRILLED_PORK:
grenade = new Molotov();
break;
}
if (grenade == null)
{
return;
}
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(grenade.getName());
stack.setItemMeta(meta);
grenade.setStack(stack);
_gunModule.registerGrenade(grenade, player);
}
@EventHandler
public void triggerPickup(PlayerPickupItemEvent event)
{
if (!getGame().InProgress() || !getGame().IsAlive(event.getPlayer()))
{
return;
}
//Guns
Gun gun = _gunModule.getDroppedGuns().get(event.getItem());
if (gun != null)
{
_gunModule.deregisterDroppedGun(gun);
_gunModule.registerGun(gun, event.getPlayer());
gun.setStack(event.getItem().getItemStack());
}
//Grenades
Grenade grenade = _gunModule.getDroppedGrenades().get(event.getItem());
if (grenade != null)
{
_gunModule.deregisterDroppedGrenade(grenade);
_gunModule.registerGrenade(grenade, event.getPlayer());
grenade.setStack(event.getItem().getItemStack());
}
}
@EventHandler
public void triggerDrop(PlayerDropItemEvent event)
{
if (!getGame().InProgress())
{
return;
}
Player player = event.getPlayer();
ItemStack itemStack = event.getItemDrop().getItemStack();
//Guns
Gun gun = _gunModule.getGunInHand(player, itemStack);
if (gun != null)
{
gun.drop(_gunModule, player, false, false);
event.getItemDrop().remove();
player.setItemInHand(null);
return;
}
//Grenades
Grenade grenade = _gunModule.getGrenadeInHand(player, itemStack);
if (grenade != null)
{
grenade.drop(_gunModule, player, false, false);
event.getItemDrop().remove();
player.setItemInHand(null);
}
}
}

View File

@ -1,5 +1,6 @@
package nautilus.game.arcade.game.modules.chest; package nautilus.game.arcade.game.modules.chest;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
@ -44,6 +45,8 @@ public class ChestLootModule extends Module
private long _destroyAfterOpened; private long _destroyAfterOpened;
private boolean _autoRotateChests = true; private boolean _autoRotateChests = true;
private boolean _spawnNearby;
private int _spawnNearbyRadius = 8;
public ChestLootModule() public ChestLootModule()
{ {
@ -51,27 +54,14 @@ public class ChestLootModule extends Module
_chests = new HashMap<>(); _chests = new HashMap<>();
} }
public ChestLootModule registerChestType(String name, ChestLootPool... pools) public ChestLootModule registerChestType(String name, List<Location> chestLocations, ChestLootPool... pools)
{ {
return registerChestType(name, 1, pools); return registerChestType(name, chestLocations, 1, pools);
} }
public ChestLootModule registerChestType(String name, double spawnChance, ChestLootPool... pools) public ChestLootModule registerChestType(String name, List<Location> chestLocations, double spawnChance, ChestLootPool... pools)
{ {
_chestTypes.add(new ChestType(name, spawnChance, pools)); _chestTypes.add(new ChestType(name, chestLocations, spawnChance, pools));
return this;
}
public ChestLootModule setSpawnsForType(String typeName, List<Location> locations)
{
for (ChestType type : _chestTypes)
{
if (type.Name.equals(typeName))
{
type.ChestSpawns = locations;
}
}
return this; return this;
} }
@ -87,6 +77,19 @@ public class ChestLootModule extends Module
return this; return this;
} }
public ChestLootModule spawnNearbyDataPoints()
{
_spawnNearby = true;
return this;
}
public ChestLootModule spawnNearbyDataPoints(int radius)
{
_spawnNearby = true;
_spawnNearbyRadius = radius;
return this;
}
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void populateChests(GameStateChangeEvent event) public void populateChests(GameStateChangeEvent event)
{ {
@ -109,6 +112,19 @@ public class ChestLootModule extends Module
if (chestType.SpawnChance == 1 || Math.random() < chestType.SpawnChance) if (chestType.SpawnChance == 1 || Math.random() < chestType.SpawnChance)
{ {
Block block = location.getBlock(); Block block = location.getBlock();
if (_spawnNearby)
{
Location nearby = getNearbyLocation(location);
if (nearby == null)
{
continue;
}
block = nearby.getBlock();
}
block.setType(Material.CHEST); block.setType(Material.CHEST);
if (_autoRotateChests) if (_autoRotateChests)
@ -144,12 +160,7 @@ public class ChestLootModule extends Module
ChestMetadata metadata = getFromBlock(block); ChestMetadata metadata = getFromBlock(block);
if (metadata == null) if (metadata == null || metadata.Opened)
{
return;
}
if (metadata.Opened)
{ {
return; return;
} }
@ -220,6 +231,30 @@ public class ChestLootModule extends Module
return 0; return 0;
} }
private Location getNearbyLocation(Location center)
{
int attempts = 0;
while (attempts++ < 20)
{
Location newLocation = UtilAlg.getRandomLocation(center, _spawnNearbyRadius, 1, _spawnNearbyRadius);
if (isSuitable(newLocation.getBlock()))
{
return newLocation;
}
}
return null;
}
private boolean isSuitable(Block block)
{
Block up = block.getRelative(BlockFace.UP);
Block down = block.getRelative(BlockFace.DOWN);
return block.getType() == Material.AIR && up.getType() == Material.AIR && down.getType() != Material.AIR && !UtilBlock.liquid(down) && !UtilBlock.liquid(up) && !UtilBlock.liquid(block);
}
private class ChestMetadata private class ChestMetadata
{ {
@ -236,25 +271,29 @@ public class ChestLootModule extends Module
void populateChest(Chest chest) void populateChest(Chest chest)
{ {
for (ChestLootPool pool : Type.Pool) for (ChestLootPool pool : Type.Pools)
{
if (pool.getProbability() == 1 || Math.random() < pool.getProbability())
{ {
pool.populateChest(chest); pool.populateChest(chest);
} }
} }
} }
}
public class ChestType private class ChestType
{ {
String Name; String Name;
double SpawnChance; double SpawnChance;
List<ChestLootPool> Pool; List<ChestLootPool> Pools;
List<Location> ChestSpawns; List<Location> ChestSpawns;
public ChestType(String name, double spawnChance, ChestLootPool... pools) ChestType(String name, List<Location> chestLocations, double spawnChance, ChestLootPool... pools)
{ {
Name = name; Name = name;
SpawnChance = spawnChance; SpawnChance = spawnChance;
Pool = Arrays.asList(pools); Pools = Arrays.asList(pools);
ChestSpawns = chestLocations;
} }
} }

View File

@ -14,12 +14,14 @@ public class ChestLootPool
private List<ChestLootItem> _items; private List<ChestLootItem> _items;
private int _minimumPerChest; private int _minimumPerChest;
private int _maximumPerChest; private int _maximumPerChest;
private double _rarity;
public ChestLootPool() public ChestLootPool()
{ {
_items = new ArrayList<>(); _items = new ArrayList<>();
_minimumPerChest = 1; _minimumPerChest = 1;
_maximumPerChest = 1; _maximumPerChest = 1;
_rarity = 1;
} }
public ChestLootPool addItem(ItemStack itemStack) public ChestLootPool addItem(ItemStack itemStack)
@ -50,6 +52,12 @@ public class ChestLootPool
return this; return this;
} }
public ChestLootPool setProbability(double probability)
{
_rarity = probability;
return this;
}
public void populateChest(Chest chest) public void populateChest(Chest chest)
{ {
Inventory inventory = chest.getBlockInventory(); Inventory inventory = chest.getBlockInventory();
@ -91,4 +99,9 @@ public class ChestLootPool
return null; return null;
} }
public double getProbability()
{
return _rarity;
}
} }

View File

@ -1096,11 +1096,16 @@ public class GameFlagManager implements Listener
return; return;
} }
if (game.WorldWaterDamage <= 0 && !game.WorldData.GetCustomLocs("WATER_DAMAGE").isEmpty()) if (game.WorldWaterDamage <= 0)
{
if (!game.WorldData.GetCustomLocs("WATER_DAMAGE").isEmpty())
{ {
game.WorldWaterDamage = 4; game.WorldWaterDamage = 4;
} }
return;
}
for (Player player : game.GetPlayers(true)) for (Player player : game.GetPlayers(true))
{ {
if (!Recharge.Instance.use(player, "Water Damage", 500, false, false)) if (!Recharge.Instance.use(player, "Water Damage", 500, false, false))