This commit is contained in:
Sam 2018-07-10 22:10:03 +01:00 committed by Alexander Meech
parent 4873ac7b74
commit aa1c53eb31
6 changed files with 432 additions and 653 deletions

View File

@ -116,8 +116,10 @@ public enum GameType implements Voteable
}, false), }, false),
DeathTag(DeathTag.class, GameDisplay.DeathTag), DeathTag(DeathTag.class, GameDisplay.DeathTag),
DragonEscape(DragonEscape.class, GameDisplay.DragonEscape), DragonEscape(DragonEscape.class, GameDisplay.DragonEscape),
Dragons(Dragons.class, GameDisplay.Dragons), Dragons(Dragons.class, new GameMode[]
DragonsTeams(DragonsTeams.class, GameDisplay.DragonsTeams), {
new GameMode(DragonsTeams.class, "Teams Mode")
}, GameDisplay.Dragons),
Draw(Draw.class, GameDisplay.Draw, new Pair[] Draw(Draw.class, GameDisplay.Draw, new Pair[]
{ {
//Pair.create(MinecraftVersion.ALL, "http://file.mineplex.com/ResDrawMyThing.zip") //Pair.create(MinecraftVersion.ALL, "http://file.mineplex.com/ResDrawMyThing.zip")

View File

@ -1,153 +0,0 @@
package nautilus.game.arcade.game.games.dragons;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
import org.bukkit.Location;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class DragonData
{
public Dragons Host;
public EnderDragon Dragon;
public Entity TargetEntity = null;
public Location Target = null;
public Location Location = null;
public float Pitch = 0;
public Vector Velocity = new Vector(0,0,0);
public double RangeBest = 1000;
public long RangeTime = 0;
public DragonData(Dragons host, EnderDragon dragon)
{
Host = host;
Dragon = dragon;
Velocity = dragon.getLocation().getDirection().setY(0).normalize();
Pitch = UtilAlg.GetPitch(dragon.getLocation().getDirection());
Location = dragon.getLocation();
}
public void Move()
{
Turn();
Location.add(Velocity);
Location.add(0, -Pitch, 0);
Location.setPitch(-1 * Pitch);
Location.setYaw(180 + UtilAlg.GetYaw(Velocity));
Dragon.teleport(Location);
}
private void Turn()
{
//Pitch
float desiredPitch = UtilAlg.GetPitch(UtilAlg.getTrajectory(Location, Target));
if (desiredPitch < Pitch) Pitch = (float)(Pitch - 0.05);
if (desiredPitch > Pitch) Pitch = (float)(Pitch + 0.05);
if (Pitch > 0.5) Pitch = 0.5f;
if (Pitch < -0.5) Pitch = -0.5f;
//Flat
Vector desired = UtilAlg.getTrajectory2d(Location, Target);
desired.subtract(UtilAlg.Normalize(new Vector(Velocity.getX(), 0, Velocity.getZ())));
desired.multiply(0.075);
Velocity.add(desired);
//Speed
UtilAlg.Normalize(Velocity);
}
public void Target()
{
if (TargetEntity != null)
{
if (!TargetEntity.isValid())
{
TargetEntity = null;
}
else
{
Target = TargetEntity.getLocation().subtract(0, 8, 0);
}
return;
}
if (Target == null)
{
TargetSky();
}
if (UtilMath.offset(Location, Target) < 4)
{
//Target Player
if (Target.getY() >= Host.GetSpectatorLocation().getY())
{
TargetPlayer();
}
//Target Sky
else
{
TargetSky();
}
}
TargetTimeout();
}
public void TargetTimeout()
{
if (UtilMath.offset(Location, Target)+1 < RangeBest)
{
RangeTime = System.currentTimeMillis();
RangeBest = UtilMath.offset(Location, Target);
}
else
{
if (UtilTime.elapsed(RangeTime, 10000))
{
TargetSky();
}
}
}
public void TargetSky()
{
RangeBest = 9000;
RangeTime = System.currentTimeMillis();
Target = Host.GetSpectatorLocation().clone().add(50 - UtilMath.r(100), 20 + UtilMath.r(30), 50 - UtilMath.r(100));
}
public void TargetPlayer()
{
RangeBest = 9000;
RangeTime = System.currentTimeMillis();
Player player = Host.GetPlayers(true).get(UtilMath.r(Host.GetPlayers(true).size()));
Target = player.getLocation();
Target.add(UtilAlg.getTrajectory(Location, Target).multiply(4));
}
public void HitByArrow()
{
TargetSky();
}
}

View File

@ -1,20 +1,23 @@
package nautilus.game.arcade.game.games.dragons; package nautilus.game.arcade.game.games.dragons;
import java.util.ArrayList; import java.util.HashSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import org.bukkit.EntityEffect; import org.bukkit.EntityEffect;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import com.mineplex.anticheat.checks.move.Glide; import com.mineplex.anticheat.checks.move.Glide;
import com.mineplex.anticheat.checks.move.HeadRoll; import com.mineplex.anticheat.checks.move.HeadRoll;
@ -25,7 +28,6 @@ import mineplex.core.antihack.AntiHack;
import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -33,8 +35,7 @@ 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.PlayerStateChangeEvent; import nautilus.game.arcade.events.PlayerDeathOutEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.SoloGame;
import nautilus.game.arcade.game.games.dragons.kits.KitCoward; import nautilus.game.arcade.game.games.dragons.kits.KitCoward;
import nautilus.game.arcade.game.games.dragons.kits.KitMarksman; import nautilus.game.arcade.game.games.dragons.kits.KitMarksman;
@ -48,33 +49,40 @@ import nautilus.game.arcade.stats.SparklezStatTracker;
public class Dragons extends SoloGame public class Dragons extends SoloGame
{ {
private HashMap<EnderDragon, DragonData> _dragons = new HashMap<EnderDragon, DragonData>();
private ArrayList<Location> _dragonSpawns = new ArrayList<Location>();
private PerkSparkler _sparkler = null; private static final String[] DESCRIPTION =
public Dragons(ArcadeManager manager)
{
super(manager, GameType.Dragons,
new Kit[]
{
new KitCoward(manager),
new KitMarksman(manager),
new KitPyrotechnic(manager)
},
new String[]
{ {
"You have angered the Dragons!", "You have angered the Dragons!",
"Survive as best you can!!!", "Survive as best you can!!!",
"Last player alive wins!" "Last player alive wins!"
}); };
private static final int MAX_DRAGONS = 5;
this.DamagePvP = false; private final Set<MineplexDragon> _dragons;
this.HungerSet = 20;
this.WorldWaterDamage = 4; private List<Location> _dragonSpawns;
this.PlayerGameMode = GameMode.ADVENTURE; private PerkSparkler _sparkler;
public Dragons(ArcadeManager manager)
{
this(manager, GameType.Dragons, DESCRIPTION);
}
public Dragons(ArcadeManager manager, GameType gameType, String[] description)
{
super(manager, gameType, new Kit[]
{
new KitCoward(manager),
new KitMarksman(manager),
new KitPyrotechnic(manager)
}, description);
_dragons = new HashSet<>(MAX_DRAGONS);
DamagePvP = false;
HungerSet = 20;
WorldWaterDamage = 4;
PlayerGameMode = GameMode.ADVENTURE;
registerStatTrackers( registerStatTrackers(
new SparklezStatTracker(this) new SparklezStatTracker(this)
@ -88,9 +96,6 @@ public class Dragons extends SoloGame
); );
new CompassModule() new CompassModule()
.setGiveCompass(true)
.setGiveCompassToSpecs(true)
.setGiveCompassToAlive(false)
.register(this); .register(this);
// Disable specific GWEN checks for this game // Disable specific GWEN checks for this game
@ -104,13 +109,6 @@ public class Dragons extends SoloGame
public void ParseData() public void ParseData()
{ {
_dragonSpawns = WorldData.GetDataLocs("RED"); _dragonSpawns = WorldData.GetDataLocs("RED");
}
@EventHandler
public void SparklerAttract(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (_sparkler == null) if (_sparkler == null)
{ {
@ -120,34 +118,155 @@ public class Dragons extends SoloGame
{ {
if (perk instanceof PerkSparkler) if (perk instanceof PerkSparkler)
{ {
_sparkler = (PerkSparkler)perk; _sparkler = (PerkSparkler) perk;
} }
} }
} }
} }
}
@EventHandler
public void dragonSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC_05 || !IsLive())
{
return;
}
_dragons.removeIf(dragon -> !dragon.getEntity().isValid());
if (_dragons.size() < MAX_DRAGONS)
{
CreatureAllowOverride = true;
Location location = UtilAlg.Random(_dragonSpawns);
if (location == null)
{
return;
}
EnderDragon dragon = location.getWorld().spawn(location, EnderDragon.class);
UtilEnt.vegetate(dragon);
location.getWorld().playSound(location, Sound.ENDERDRAGON_GROWL, 20f, 1f);
_dragons.add(new MineplexDragon(this, dragon));
CreatureAllowOverride = false;
}
}
@EventHandler
public void dragonTarget(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST || !IsLive())
{
return;
}
_dragons.forEach(MineplexDragon::updateTarget);
for (Item item : _sparkler.GetItems()) for (Item item : _sparkler.GetItems())
{ {
if (item.getLocation().getY() < 4 || item.getLocation().getBlock().isLiquid()) Location location = item.getLocation();
if (location.getY() < 4 || location.getBlock().isLiquid())
{
continue; continue;
for (DragonData data : _dragons.values())
{
if (UtilMath.offset(data.Location, item.getLocation()) < 48)
{
data.TargetEntity = item;
} }
_dragons.forEach(dragon -> dragon.targetSparkler(location));
}
}
@EventHandler
public void dragonTarget(EntityTargetEvent event)
{
if (!IsLive())
{
return;
}
event.setCancelled(true);
}
@EventHandler
public void dragonArrowDamage(CustomDamageEvent event)
{
if (event.GetProjectile() == null)
{
return;
}
for (MineplexDragon dragon : _dragons)
{
if (dragon.getEntity().equals(event.GetDamageeEntity()))
{
dragon.targetSky();
return;
} }
} }
} }
private void giveSurvivedGems(Player player) @EventHandler
public void knockback(CustomDamageEvent event)
{
if (event.IsCancelled())
{
return;
}
Entity damager = event.GetDamagerEntity(true);
Player damagee = event.GetDamageePlayer();
if (damagee == null || damager == null)
{
return;
}
event.SetCancelled("Dragon");
event.SetKnockback(false);
damagee.playEffect(EntityEffect.HURT);
UtilAction.velocity(damagee, UtilAlg.getTrajectory(damager, damagee), 1, false, 0, 0.6, 2, true);
}
@EventHandler
public void fallDamage(CustomDamageEvent event)
{
if (event.IsCancelled() || event.GetCause() != DamageCause.FALL)
{
return;
}
event.AddMod(GetName(), "Fall Reduction", -1, false);
}
@EventHandler(priority = EventPriority.LOW)
public void itemSpawn(ItemSpawnEvent event)
{
if (event.getEntity().getItemStack().getType() == Material.EMERALD)
{
return;
}
event.setCancelled(true);
}
@EventHandler
public void playerOut(PlayerDeathOutEvent event)
{
giveSurvivedGems(event.GetPlayer());
}
protected void giveSurvivedGems(Player player)
{ {
long time = (System.currentTimeMillis() - GetStateTime()); long time = (System.currentTimeMillis() - GetStateTime());
double gems = time/10000d; double gems = time / 10000d;
String reason = "Survived for " + UtilTime.MakeStr(time); String reason = "Survived for " + UtilTime.MakeStr(time);
this.AddGems(player, gems, reason, false, false); AddGems(player, gems, reason, false, false);
} }
@Override @Override
@ -158,144 +277,4 @@ public class Dragons extends SoloGame
super.AnnounceEnd(places); super.AnnounceEnd(places);
} }
@EventHandler
public void Death(PlayerStateChangeEvent event)
{
if (event.GetState() != PlayerState.OUT)
{
return;
}
giveSurvivedGems(event.GetPlayer());
}
@EventHandler
public void DragonSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
return;
if (GetState() != GameState.Live)
return;
Iterator<EnderDragon> dragonIterator = _dragons.keySet().iterator();
while (dragonIterator.hasNext())
{
EnderDragon ent = dragonIterator.next();
if (!ent.isValid())
{
dragonIterator.remove();
ent.remove();
}
}
if (_dragons.size() < 7)
{
CreatureAllowOverride = true;
EnderDragon ent = GetSpectatorLocation().getWorld().spawn(_dragonSpawns.get(0), EnderDragon.class);
UtilEnt.vegetate(ent);
CreatureAllowOverride = false;
ent.getWorld().playSound(ent.getLocation(), Sound.ENDERDRAGON_GROWL, 20f, 1f);
_dragons.put(ent, new DragonData(this, ent));
}
}
@EventHandler
public void DragonLocation(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (GetState() != GameState.Live)
return;
//Dragon Update!
for (DragonData data : _dragons.values())
{
data.Target();
data.Move();
}
}
@EventHandler
public void DragonTargetCancel(EntityTargetEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void DragonArrowDamage(CustomDamageEvent event)
{
if (event.GetProjectile() == null)
return;
if (!_dragons.containsKey(event.GetDamageeEntity()))
return;
_dragons.get(event.GetDamageeEntity()).HitByArrow();
}
@EventHandler
public void Knockback(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
Player damagee = event.GetDamageePlayer();
if (damagee == null) return;
if (event.GetDamagerEntity(true) == null)
return;
event.SetCancelled("Dragon");
event.AddMod("Dragon", "Damage Reduction", -1 * (event.GetDamageInitial()-1), false);
event.SetKnockback(false);
damagee.playEffect(EntityEffect.HURT);
UtilAction.velocity(damagee, UtilAlg.getTrajectory(event.GetDamagerEntity(true), damagee), 1, false, 0, 0.6, 2, true);
}
@EventHandler
public void FallDamage(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
if (event.GetCause() == DamageCause.FALL)
event.AddMod("Fall Reduction", "Fall Reduction", -1, false);
}
/*
@EventHandler
public void DragonKnockback(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (DragonData data : _dragons.values())
{
UtilParticle.PlayParticle(ParticleType.FIREWORKS_SPARK, data.Dragon.getLocation(), 0f, 0f, 0f, 0, 1);
for (Player player : GetPlayers(true))
{
if (!Recharge.Instance.use(player, "Dragon Hit", 500, false, false))
continue;
if (UtilMath.offset(player, data.Dragon) < 6)
{
UtilAction.velocity(player, UtilAlg.getTrajectory(data.Dragon, player), 1, false, 0, 0.6, 2, true);
player.damage(1);
}
}
}
}
*/
} }

View File

@ -1,81 +1,41 @@
package nautilus.game.arcade.game.games.dragons; package nautilus.game.arcade.game.games.dragons;
import java.util.ArrayList; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.bukkit.EntityEffect; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilTime;
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.PlayerStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.dragons.kits.*;
import nautilus.game.arcade.game.modules.TeamArmorModule; import nautilus.game.arcade.game.modules.TeamArmorModule;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.PerkSparkler;
import nautilus.game.arcade.managers.chat.ChatStatData;
public class DragonsTeams extends TeamGame public class DragonsTeams extends Dragons
{ {
private HashMap<EnderDragon, DragonTeamsData> _dragons = new HashMap<EnderDragon, DragonTeamsData>();
private ArrayList<Location> _dragonSpawns = new ArrayList<Location>();
private ArrayList<String> _lastScoreboard = new ArrayList<String>(); private final Map<GameTeam, Integer> _scores;
private HashMap<GameTeam, Integer> _teamScore = new HashMap<GameTeam, Integer>();
private PerkSparkler _sparkler = null;
public DragonsTeams(ArcadeManager manager) public DragonsTeams(ArcadeManager manager)
{ {
super(manager, GameType.DragonsTeams, super(manager, GameType.Dragons, new String[]
new Kit[]
{
new KitCoward(manager),
new KitMarksman(manager),
new KitPyrotechnic(manager)
},
new String[]
{ {
"You have angered the Dragons!", "You have angered the Dragons!",
"Survive as best you can!!!", "Survive as best you can!!!",
"Team with longest time survived wins!" "Team with longest time survived wins!"
}); });
this.DamagePvP = false; _scores = new HashMap<>();
this.HungerSet = 20;
this.WorldWaterDamage = 4;
this.PrepareFreeze = false;
registerChatStats(
Deaths,
DamageTaken,
BlankLine,
new ChatStatData("kit", "Kit", true)
);
new TeamArmorModule() new TeamArmorModule()
.giveTeamArmor() .giveTeamArmor()
@ -84,208 +44,74 @@ public class DragonsTeams extends TeamGame
} }
@Override @Override
public void ParseData() @EventHandler
public void CustomTeamGeneration(GameStateChangeEvent event)
{ {
_dragonSpawns = WorldData.GetDataLocs("RED"); if (event.GetState() != GameState.Recruit)
{
return;
}
GameTeam team = GetTeamList().get(0);
GetTeamList().clear();
List<Location> spawns = team.GetSpawns();
AddTeam(new GameTeam(this, "Red", ChatColor.RED, spawns));
AddTeam(new GameTeam(this, "Yellow", ChatColor.YELLOW, spawns));
AddTeam(new GameTeam(this, "Green", ChatColor.GREEN, spawns));
AddTeam(new GameTeam(this, "Blue", ChatColor.AQUA, spawns));
} }
@EventHandler @EventHandler
public void SparklerAttract(UpdateEvent event) public void prepare(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
{ {
if (event.getType() != UpdateType.TICK)
return; return;
if (_sparkler == null)
{
for (Kit kit : GetKits())
{
for (Perk perk : kit.GetPerks())
{
if (perk instanceof PerkSparkler)
{
_sparkler = (PerkSparkler)perk;
}
}
}
} }
for (Item item : _sparkler.GetItems()) GetTeamList().forEach(team -> _scores.put(team, 0));
{
for (DragonTeamsData data : _dragons.values())
{
if (UtilMath.offset(data.Location, item.getLocation()) < 48)
{
data.TargetEntity = item;
}
}
}
}
private void giveSurvivedGems(Player player)
{
long time = (System.currentTimeMillis() - GetStateTime());
double gems = time/10000d;
String reason = "Survived for " + UtilTime.MakeStr(time);
this.AddGems(player, gems, reason, false, false);
}
@Override
public void AnnounceEnd(List<Player> places)
{
// Give the winner gems for surviving the latest
giveSurvivedGems(places.get(0));
super.AnnounceEnd(places);
} }
@EventHandler @EventHandler
public void Death(PlayerStateChangeEvent event) public void updateScores(UpdateEvent event)
{ {
if (event.GetState() != PlayerState.OUT) if (event.getType() != UpdateType.SEC || !IsLive())
{ {
return; return;
} }
giveSurvivedGems(event.GetPlayer()); for (GameTeam team : GetTeamList())
{
List<Player> alive = team.GetPlayers(true);
if (alive.isEmpty())
{
continue;
} }
@EventHandler _scores.put(team, _scores.get(team) + alive.size());
public void DragonSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
return;
if (GetState() != GameState.Live)
return;
Iterator<EnderDragon> dragonIterator = _dragons.keySet().iterator();
while (dragonIterator.hasNext())
{
EnderDragon ent = dragonIterator.next();
if (!ent.isValid())
{
dragonIterator.remove();
ent.remove();
} }
} }
if (_dragons.size() < 7)
{
CreatureAllowOverride = true;
EnderDragon ent = GetSpectatorLocation().getWorld().spawn(_dragonSpawns.get(0), EnderDragon.class);
UtilEnt.vegetate(ent);
CreatureAllowOverride = false;
ent.getWorld().playSound(ent.getLocation(), Sound.ENDERDRAGON_GROWL, 20f, 1f);
_dragons.put(ent, new DragonTeamsData(this, ent));
}
}
@EventHandler
public void DragonLocation(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (GetState() != GameState.Live)
return;
//Dragon Update!
for (DragonTeamsData data : _dragons.values())
{
data.Target();
data.Move();
}
}
@EventHandler
public void DragonTargetCancel(EntityTargetEvent event)
{
event.setCancelled(true);
}
@EventHandler
public void DragonArrowDamage(CustomDamageEvent event)
{
if (event.GetProjectile() == null)
return;
if (!_dragons.containsKey(event.GetDamageeEntity()))
return;
_dragons.get(event.GetDamageeEntity()).HitByArrow();
}
@EventHandler
public void Knockback(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
Player damagee = event.GetDamageePlayer();
if (damagee == null) return;
if (event.GetDamagerEntity(true) == null)
return;
event.SetCancelled("Dragon");
event.AddMod("Dragon", "Damage Reduction", -1 * (event.GetDamageInitial()-1), false);
event.SetKnockback(false);
damagee.playEffect(EntityEffect.HURT);
UtilAction.velocity(damagee, UtilAlg.getTrajectory(event.GetDamagerEntity(true), damagee), 1, false, 0, 0.6, 2, true);
}
@EventHandler
public void FallDamage(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
if (event.GetCause() == DamageCause.FALL)
event.AddMod("Fall Reduction", "Fall Reduction", -1, false);
}
@Override @Override
@EventHandler @EventHandler
public void ScoreboardUpdate(UpdateEvent event) public void ScoreboardUpdate(UpdateEvent event)
{ {
if (event.getType() != UpdateType.SEC) if (event.getType() != UpdateType.SEC || !InProgress())
{
return; return;
if (IsLive())
for (GameTeam team : GetTeamList())
{
if (!_teamScore.containsKey(team))
_teamScore.put(team, 0);
if (team.IsTeamAlive())
_teamScore.put(team, _teamScore.get(team) + team.GetPlayers(true).size());
} }
WriteScoreboard();
}
private void WriteScoreboard()
{
//Wipe Last
Scoreboard.reset();
for (GameTeam team : _teamScore.keySet())
{
//Time
int seconds = _teamScore.get(team);
Scoreboard.writeNewLine(); Scoreboard.writeNewLine();
Scoreboard.write(team.GetColor() + team.GetName());
Scoreboard.write(team.GetColor() + "" + seconds + " Seconds"); _scores.forEach((team, score) ->
} {
Scoreboard.write(team.GetFormattedName());
Scoreboard.write(score + " Points");
Scoreboard.writeNewLine();
});
Scoreboard.draw(); Scoreboard.draw();
} }
@ -294,52 +120,62 @@ public class DragonsTeams extends TeamGame
public void EndCheck() public void EndCheck()
{ {
if (!IsLive()) if (!IsLive())
{
return; return;
}
ArrayList<GameTeam> teamsAlive = new ArrayList<GameTeam>(); for (GameTeam team : _scores.keySet())
for (GameTeam team : this.GetTeamList())
if (team.GetPlayers(true).size() > 0)
teamsAlive.add(team);
if (teamsAlive.size() <= 0)
{ {
//Get Winner if (team.IsTeamAlive())
GameTeam winner = null;
int bestTime = 0;
for (GameTeam team : _teamScore.keySet())
{ {
if (winner == null || _teamScore.get(team) > bestTime) return;
{
winner = team;
bestTime = _teamScore.get(team);
} }
} }
//Announce List<GameTeam> placements = _scores.entrySet().stream()
if (winner != null) // Reversed natural ordering
.sorted((o1, o2) -> o2.getValue().compareTo(o1.getValue()))
.map(Entry::getKey)
.collect(Collectors.toList());
if (placements.isEmpty())
{ {
AnnounceEnd(winner); return;
this.SetCustomWinLine("Survived " + bestTime + " Seconds!");
} }
GetPlayers(true).forEach(this::giveSurvivedGems);
for (GameTeam team : GetTeamList()) AnnounceEnd(placements.get(0));
{
if (WinnerTeam != null && team.equals(WinnerTeam))
{
for (Player player : team.GetPlayers(false))
AddGems(player, 10, "Winning Team", false, false);
}
for (Player player : team.GetPlayers(false))
if (player.isOnline())
AddGems(player, 10, "Participation", false, false);
}
//End
SetState(GameState.End); SetState(GameState.End);
} }
@Override
public List<Player> getWinners()
{
if (WinnerTeam == null)
{
return Collections.emptyList();
}
return WinnerTeam.GetPlayers(true);
}
@Override
public List<Player> getLosers()
{
if (WinnerTeam == null)
{
return Collections.emptyList();
}
List<Player> losers = GetPlayers(false);
losers.removeAll(getWinners());
return losers;
}
@Override
public String GetMode()
{
return "Teams Mode";
} }
} }

View File

@ -0,0 +1,125 @@
package nautilus.game.arcade.game.games.dragons;
import net.minecraft.server.v1_8_R3.EntityEnderDragon;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderDragon;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
public class MineplexDragon
{
private static final int MAX_SPARKLER_DISTANCE = 48 * 48;
private final Dragons _host;
private final EnderDragon _entity;
MineplexDragon(Dragons host, EnderDragon entity)
{
_host = host;
_entity = entity;
targetSky();
}
void updateTarget()
{
Location location = _entity.getLocation(), spectatorLocation = _host.GetSpectatorLocation();
// Too low (target fell into void?).
if (location.getY() < 10)
{
targetSky();
return;
}
// Not near target.
if (UtilMath.offsetSquared(location, getTarget()) > 36)
{
return;
}
// Too high.
if (location.getY() > spectatorLocation.getY())
{
targetPlayer();
}
// In the middle.
else
{
targetSky();
}
}
void targetPlayer()
{
Player player = UtilAlg.Random(_host.GetPlayers(true));
// No alive player found.
if (player == null)
{
targetSky();
}
else
{
setTargetEntity(player);
}
}
void targetSky()
{
setTargetLocation(_host.GetSpectatorLocation().clone().add(UtilMath.rRange(-50, 50), UtilMath.rRange(20, 40), UtilMath.rRange(-50, 50)));
}
void targetSparkler(Location location)
{
// Too far from sparkler to see
if (UtilMath.offsetSquared(location, _entity.getLocation()) > MAX_SPARKLER_DISTANCE)
{
return;
}
setTargetLocation(location);
}
private void setTargetLocation(Location location)
{
getHandle().setTargetBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
private void setTargetEntity(Entity entity)
{
getHandle().setTargetEntity(((CraftEntity) entity).getHandle());
}
private Location getTarget()
{
EntityEnderDragon dragon = getHandle();
if (dragon.target != null)
{
return new Location(_entity.getWorld(), dragon.target.locX, dragon.target.locY, dragon.target.locZ);
}
else
{
// a = targetX, b = targetY, c = targetZ
return new Location(_entity.getWorld(), dragon.a, dragon.b, dragon.c);
}
}
private EntityEnderDragon getHandle()
{
return ((CraftEnderDragon) _entity).getHandle();
}
public EnderDragon getEntity()
{
return _entity;
}
}

View File

@ -18,11 +18,7 @@ import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
@ -211,12 +207,6 @@ public class NewGameLobbyManager extends LobbyManager
return; return;
} }
WORLD.getEntities().stream()
.filter(entity -> !(entity instanceof Player) && !(entity instanceof ArmorStand) && !(entity instanceof Item))
.filter(entity -> entity.isCustomNameVisible() && entity.getCustomName() != null)
.filter(entity -> !getTeams().containsKey(entity))
.forEach(Entity::remove);
List<Kit> kitList = Lists.newArrayList(game.GetKits()).stream() List<Kit> kitList = Lists.newArrayList(game.GetKits()).stream()
.filter(kit -> !(kit instanceof NullKit)) .filter(kit -> !(kit instanceof NullKit))
.filter(kit -> kit.GetAvailability() != KitAvailability.Hide) .filter(kit -> kit.GetAvailability() != KitAvailability.Hide)
@ -536,7 +526,7 @@ public class NewGameLobbyManager extends LobbyManager
Location amp = _singleLocs.get(DataLoc.AMP.name()); Location amp = _singleLocs.get(DataLoc.AMP.name());
if (amp != null) if (amp != null)
{ {
amp.setYaw(getYawToSpawn(missions, false)); amp.setYaw(getYawToSpawn(amp, false));
setAmpStand(amp); setAmpStand(amp);
} }
} }