Bomb Lobbers again

This commit is contained in:
Sam 2018-04-30 21:32:52 +01:00 committed by Alexander Meech
parent 30dcfdb660
commit f495405b49
3 changed files with 181 additions and 216 deletions

View File

@ -1,11 +1,28 @@
package nautilus.game.arcade.game.games.lobbers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
@ -24,7 +41,7 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.CombatComponent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
@ -46,74 +63,52 @@ import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.managers.chat.ChatStatData;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
public class BombLobbers extends TeamGame implements IThrown
{
/**
* @author Mysticate
* Created in July, 2015
*/
private NautHashMap<GameTeam, Location> _averageSpawns = new NautHashMap<GameTeam, Location>();
private NautHashMap<TNTPrimed, BombToken> _tnt = new NautHashMap<TNTPrimed, BombToken>();
private NautHashMap<Player, Double> _kills = new NautHashMap<Player, Double>();
private static final String[] DESCRIPTION =
{
"Fight against your enemies using",
"the power of " + C.cRed + "Explosives!",
C.cGreen + "Left-Click" + C.Reset + " TNT to throw at your enemy.",
C.cYellow + "Last Team" + " alive wins!"
};
private final Map<GameTeam, Location> _averageSpawns = new HashMap<>();
private final Map<TNTPrimed, BombToken> _tnt = new HashMap<>();
private final Map<Player, Double> _kills = new HashMap<>();
@SuppressWarnings("unchecked")
public BombLobbers(ArcadeManager manager)
{
super(manager, GameType.Lobbers,
new Kit[]
{
super(manager, GameType.Lobbers, new Kit[]
{
new KitJumper(manager),
new KitArmorer(manager),
new KitPitcher(manager),
new KitWaller(manager)
},
new String[]
{
"Fight against your enemies using",
"the power of explosives!",
"Left click TNT to throw at your enemy.",
"Last team alive wins!"
});
}, DESCRIPTION);
DamageFall = true;
DamageEvP = true;
WorldWaterDamage = 5;
PrepareFreeze = false;
InventoryOpenChest = false;
InventoryOpenBlock = false;
ItemDrop = false;
BlockPlace = false;
Manager.GetExplosion().SetLiquidDamage(false);
HungerSet = 20;
WorldTimeSet = 6000;
registerStatTrackers(
new Tracker6Kill(this),
new TrackerBlastProof(this),
@ -141,24 +136,26 @@ public class BombLobbers extends TeamGame implements IThrown
.giveHotbarItem()
.register(this);
}
@EventHandler
public void setTime(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
{
return;
}
if (WorldData.MapName.equalsIgnoreCase("Intergalactic"))
{
WorldTimeSet = 18000;
}
}
public void addKill(Player player)
{
_kills.put(player, _kills.containsKey(player) ? _kills.get(player) + 1 : 1);
}
public double getKills(Player player)
{
if (_kills.containsKey(player))
@ -171,35 +168,35 @@ public class BombLobbers extends TeamGame implements IThrown
return 0;
}
}
@EventHandler
public void onKill(CombatDeathEvent event)
{
if (!IsLive())
return;
Player dead = UtilPlayer.searchExact(((Player) event.GetEvent().getEntity()).getName());
Player dead = UtilPlayer.searchExact(event.GetEvent().getEntity().getName());
if (!IsAlive(dead))
return;
for (CombatComponent damager : event.GetLog().GetAttackers())
{
Player killer = UtilPlayer.searchExact(damager.GetName());
if (killer == null || !killer.isOnline())
continue;
if (IsAlive(killer))
{
if (event.GetLog().GetKiller() == damager)
{
{
addKill(killer);
}
}
}
}
@EventHandler
public void loadTeamLocations(GameStateChangeEvent event)
{
@ -211,7 +208,7 @@ public class BombLobbers extends TeamGame implements IThrown
}
}
}
@EventHandler
public void disableFlying(GameStateChangeEvent event)
{
@ -220,101 +217,89 @@ public class BombLobbers extends TeamGame implements IThrown
player.setAllowFlight(false);
}
}
@EventHandler
public void throwTNT(PlayerInteractEvent event)
{
if (event.getAction() == Action.PHYSICAL)
return;
if (!IsLive())
if (event.getAction() == Action.PHYSICAL || !IsLive())
{
return;
}
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
if (!IsAlive(player))
if (!IsAlive(player) || itemStack == null || itemStack.getType() == Material.TNT)
{
return;
}
if (!UtilInv.IsItem(player.getItemInHand(), Material.TNT, (byte) 0))
return;
event.setCancelled(true);
UtilInv.remove(player, Material.TNT, (byte) 0, 1);
UtilInv.Update(player);
player.updateInventory();
TNTPrimed tnt = (TNTPrimed) player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class);
TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class);
tnt.setMetadata("owner", new FixedMetadataValue(Manager.getPlugin(), player.getUniqueId()));
tnt.setFuseTicks(60);
UtilAction.velocity(tnt, player.getLocation().getDirection(), 2.0D, false, 0.0D, 0.1D, 10.0D, false);
ArrayList<Player> canHit = new ArrayList<Player>();
List<Player> canHit = new ArrayList<>();
for (Player pos : GetPlayers(true))
{
if (GetTeam(player).HasPlayer(pos))
{
continue;
}
canHit.add(pos);
}
Manager.GetProjectile().AddThrow(tnt, player, this, -1L, true, true, false, true, .2F, canHit);
Manager.getPlugin().getServer().getPluginManager().callEvent(new TNTThrowEvent(player, tnt));
_tnt.put(tnt, new BombToken(player));
AddGems(player, 0.5, "TNT Thrown", true, true);
}
public Player getThrower(TNTPrimed tnt)
{
if (_tnt.get(tnt) == null)
return null;
return UtilPlayer.searchExact(_tnt.get(tnt).Thrower);
BombToken token = _tnt.get(tnt);
return token == null ? null : UtilPlayer.searchExact(_tnt.get(tnt).Thrower);
}
@EventHandler
public void onTNTExplode(ExplosionPrimeEvent event)
{
if (!IsLive())
return;
if (!(event.getEntity() instanceof TNTPrimed))
if (!IsLive() || !(event.getEntity() instanceof TNTPrimed))
{
return;
}
TNTPrimed tnt = (TNTPrimed) event.getEntity();
if (!_tnt.containsKey(tnt))
{
return;
}
Player thrower = UtilPlayer.searchExact(_tnt.get(tnt).Thrower);
if (thrower == null)
if (thrower == null || GetTeam(thrower).equals(getSide(tnt.getLocation())))
{
event.setCancelled(true);
tnt.remove();
_tnt.remove(tnt);
event.getEntity().remove();
return;
}
if (GetTeam(thrower) == getSide(tnt.getLocation()))
{
event.setCancelled(true);
_tnt.remove(tnt);
event.getEntity().remove();
return;
}
TNTPreExplodeEvent preExplode = new TNTPreExplodeEvent(thrower, tnt);
Manager.getPlugin().getServer().getPluginManager().callEvent(preExplode);
UtilServer.CallEvent(preExplode);
if (preExplode.isCancelled())
{
event.setCancelled(true);
@ -327,41 +312,38 @@ public class BombLobbers extends TeamGame implements IThrown
Manager.GetCondition().Factory().Explosion("Throwing TNT", other, thrower, 50, 0.1, false, false);
}
}
_tnt.remove(tnt);
}
@EventHandler
public void updateTNT(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
if (event.getType() != UpdateType.TICK || !IsLive())
{
return;
if (!IsLive())
return;
NautHashMap<TNTPrimed, BombToken> toAdd = new NautHashMap<TNTPrimed, BombToken>();
}
Map<TNTPrimed, BombToken> toAdd = new HashMap<>();
Iterator<Entry<TNTPrimed, BombToken>> iterator = _tnt.entrySet().iterator();
while (iterator.hasNext())
{
Entry<TNTPrimed, BombToken> tnt = iterator.next();
if (tnt.getKey() == null)
if (tnt.getKey() == null || !tnt.getKey().isValid())
{
continue;
if (!tnt.getKey().isValid())
continue;
}
BombToken token = tnt.getValue();
Player thrower = UtilPlayer.searchExact(token.Thrower);
if (thrower == null)
if (thrower == null || !IsPlaying(thrower))
{
continue;
if (!IsPlaying(thrower))
continue;
}
if (!token.Primed)
{
if (tnt.getKey().getFuseTicks() <= 20)
@ -373,48 +355,45 @@ public class BombLobbers extends TeamGame implements IThrown
newTNT.setFuseTicks(60);
Manager.GetProjectile().AddThrow(newTNT, thrower, this, -1L, true, true, false, true, .2F);
tnt.getKey().remove();
iterator.remove();
toAdd.put(newTNT, token);
}
}
}
//Prevent concurrent modification thigns
for (Entry<TNTPrimed, BombToken> entry : toAdd.entrySet())
{
_tnt.put(entry.getKey(), entry.getValue());
}
}
@EventHandler
public void blockCollision(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
if (event.getType() != UpdateType.TICK || !IsLive())
{
return;
if (!IsLive())
return;
}
for (Entry<TNTPrimed, BombToken> tnt : _tnt.entrySet())
{
if (tnt.getKey() == null)
if (tnt.getKey() == null || !tnt.getKey().isValid())
{
continue;
if (!tnt.getKey().isValid())
continue;
}
BombToken token = tnt.getValue();
Player thrower = UtilPlayer.searchExact(token.Thrower);
if (thrower == null)
if (thrower == null || !IsPlaying(thrower))
{
continue;
if (!IsPlaying(thrower))
continue;
}
if (!token.Primed)
{
//8+ insta explode
@ -422,7 +401,6 @@ public class BombLobbers extends TeamGame implements IThrown
{
token.Primed = true;
tnt.getKey().setFuseTicks(0);
continue;
}
else if (UtilTime.elapsed(token.Created, 3000))
{
@ -443,37 +421,33 @@ public class BombLobbers extends TeamGame implements IThrown
@EventHandler
public void updateParticles(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
if (event.getType() != UpdateType.TICK || !IsLive())
{
return;
if (!IsLive())
return;
}
for (Entry<TNTPrimed, BombToken> tnt : _tnt.entrySet())
{
if (tnt.getKey() == null)
if (tnt.getKey() == null || !tnt.getKey().isValid() || UtilEnt.isGrounded(tnt.getKey()) || tnt.getKey().isOnGround())
{
continue;
if (!tnt.getKey().isValid())
continue;
if (UtilEnt.isGrounded(tnt.getKey()) || tnt.getKey().isOnGround())
continue;
}
BombToken token = tnt.getValue();
Player thrower = UtilPlayer.searchExact(token.Thrower);
if (thrower == null)
{
continue;
if (!IsPlaying(thrower))
continue;
}
GameTeam team = GetTeam(thrower);
if (team == null)
{
continue;
}
//A is current
//B is previous
token.B = token.A;
@ -481,69 +455,66 @@ public class BombLobbers extends TeamGame implements IThrown
if (token.A == null || token.B == null)
continue;
//Adapted from static lazer code
double curRange = 0;
double distance = Math.abs(token.A.distance(token.B));
while (curRange <= distance)
{
Location newTarget = token.B.add(UtilAlg.getTrajectory(token.B, token.A).multiply(curRange));
// Location newTarget = player.getEyeLocation().add(player.getLocation().getDirection().multiply(curRange));
//Progress Forwards
curRange += 0.2;
if (team.GetColor() == ChatColor.AQUA)
{
for (int i = 0 ; i < 2 ; i++)
for (int i = 0; i < 2; i++)
UtilParticle.PlayParticle(ParticleType.RED_DUST, newTarget.clone().add(0.0, 0.5, 0.0), -1, 1, 1, 1, 0,
ViewDist.NORMAL, UtilServer.getPlayers());
}
else
{
for (int i = 0 ; i < 2 ; i++)
for (int i = 0; i < 2; i++)
UtilParticle.PlayParticle(ParticleType.RED_DUST, newTarget.clone().add(0.0, 0.5, 0.0), 0, 0, 0, 0, 1,
ViewDist.NORMAL, UtilServer.getPlayers());
}
//UtilParticle.PlayParticle(ParticleType.RED_DUST, newTarget.clone().add(0.0, 0.6, 0.0), team.GetColorBase().getRed(), team.GetColorBase().getGreen(), team.GetColorBase().getBlue(), 1, 0, ViewDist.LONG, UtilServer.getPlayers());
}
}
}
@EventHandler
public void preventCheating(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
if (event.getType() != UpdateType.SEC || !IsLive())
{
return;
if (!IsLive())
return;
}
for (Player player : GetPlayers(true))
{
if (GetTeam(player) != getSide(player.getLocation()))
if (GetTeam(player).equals(getSide(player.getLocation())))
{
player.damage(500);
UtilPlayer.message(player, F.main("Game", "You were killed for trying to cheat!"));
Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, 500, false, true, true, GetName(), "Cheating");
}
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void damageBlocks(ExplosionEvent event)
{
if (!Manager.GetGame().IsLive())
if (!IsLive())
{
return;
}
Iterator<Block> iterator = event.GetBlocks().iterator();
while (iterator.hasNext())
{
Block block = iterator.next();
//Stone
if (block.getType() == Material.STONE)
{
@ -557,18 +528,20 @@ public class BombLobbers extends TeamGame implements IThrown
{
block.setData((byte) 2);
iterator.remove();
continue;
}
}
}
private GameTeam getSide(Location entityLoc)
{
Location nearest = UtilAlg.findClosest(entityLoc, new ArrayList<Location>(_averageSpawns.values()));
{
Location nearest = UtilAlg.findClosest(entityLoc, _averageSpawns.values());
for (Entry<GameTeam, Location> entry : _averageSpawns.entrySet())
{
if (entry.getValue().equals(nearest))
{
return entry.getKey();
}
}
return null;
}
@ -578,7 +551,7 @@ public class BombLobbers extends TeamGame implements IThrown
{
if (!(data.getThrown() instanceof TNTPrimed))
return;
if (!(data.getThrower() instanceof Player))
return;
@ -587,40 +560,28 @@ public class BombLobbers extends TeamGame implements IThrown
if (GetTeam((Player) target) == GetTeam((Player) data.getThrower()))
return;
data.getThrown().setVelocity(new Vector());
if (target != null)
UtilAction.velocity(target, UtilAlg.getTrajectory2d(data.getThrown().getLocation(), target.getLocation()), .2, false, 0, 0.2, .4, true);
UtilAction.velocity(target, UtilAlg.getTrajectory2d(data.getThrown().getLocation(), target.getLocation()), .2, false, 0, 0.2, .4, true);
Manager.GetDamage().NewDamageEvent(target, data.getThrower(), null, DamageCause.PROJECTILE, 10.0, false, false, false, "Throwing TNT", "Throwing TNT Direct Hit");
AddGems((Player) data.getThrower(), 4.0, "Direct Hit", true, true);
}
@Override
public void Idle(ProjectileUser data)
{
}
@Override
public void Expire(ProjectileUser data)
{
}
@Override
public void ChunkUnload(ProjectileUser data)
{
data.getThrown().remove();
}
public void knockbackIncrease(CustomDamageEvent event)
{
if (event.GetCause() != DamageCause.ENTITY_EXPLOSION && event.GetCause() != DamageCause.BLOCK_EXPLOSION)
return;
event.AddKnockback("Explosion", 1.7D);
}
}

View File

@ -15,6 +15,7 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.lobbers.kits.perks.PerkCraftman;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkDoubleJump;
import nautilus.game.arcade.kit.perks.PerkDummy;
public class KitArmorer extends Kit
@ -22,6 +23,7 @@ public class KitArmorer extends Kit
private static final Perk[] PERKS =
{
new PerkDoubleJump("Double Jump", 1.2, 1.2, false),
new PerkDummy("Armorer", Collections.singletonList(C.cGray + "Receive " + C.cYellow + "Full Gold Armor").toArray(new String[1])),
new PerkCraftman(),
};

View File

@ -13,12 +13,14 @@ import nautilus.game.arcade.game.games.lobbers.kits.perks.PerkCraftman;
import nautilus.game.arcade.game.games.lobbers.kits.perks.PerkWaller;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkDoubleJump;
public class KitWaller extends Kit
{
private static final Perk[] PERKS =
{
new PerkDoubleJump("Double Jump", 1.2, 1.2, false),
new PerkWaller(),
new PerkCraftman()
};