More alien stuff
This commit is contained in:
parent
10258d66b8
commit
bd52e63dc3
@ -56,7 +56,7 @@ public class LineParticle
|
||||
|
||||
if (_direction == null)
|
||||
{
|
||||
direction = UtilAlg.getTrajectory(start, end).normalize();
|
||||
_direction = UtilAlg.getTrajectory(start, end).normalize();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public enum GameDisplay
|
||||
|
||||
StrikeGames("Strike Games", Material.DIAMOND_LEGGINGS, (byte) 0, GameCategory.SURVIVAL, 66, false),
|
||||
|
||||
AlienInvasion("Alien Invaison", Material.ENDER_STONE, (byte) 0, GameCategory.EVENT, 69, false),
|
||||
AlienInvasion("Alien Invasion", Material.ENDER_STONE, (byte) 0, GameCategory.EVENT, 69, false),
|
||||
|
||||
Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999, false),
|
||||
|
||||
|
@ -1,11 +1,30 @@
|
||||
package nautilus.game.arcade.game.games.alieninvasion;
|
||||
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.SoloGame;
|
||||
import nautilus.game.arcade.game.games.alieninvasion.kit.KitPlayer;
|
||||
import nautilus.game.arcade.game.games.dragonescape.DragonScore;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class AlienInvasion extends SoloGame
|
||||
{
|
||||
@ -15,8 +34,245 @@ public class AlienInvasion extends SoloGame
|
||||
"Add this soon"
|
||||
};
|
||||
|
||||
private final List<BeamSource> _sources = new ArrayList<>(5);
|
||||
private final List<Location> _targets = new ArrayList<>();
|
||||
private final ArrayList<Location> _path = new ArrayList<>();
|
||||
|
||||
private int _lastBeamId;
|
||||
private long _lastBeam;
|
||||
|
||||
private final List<DragonScore> _score = new ArrayList<>(16);
|
||||
|
||||
public AlienInvasion(ArcadeManager manager)
|
||||
{
|
||||
super(manager, GameType.AlienInvasion, new Kit[]{}, DESCRIPTION, );
|
||||
super(manager, GameType.AlienInvasion, new Kit[]{new KitPlayer(manager)}, DESCRIPTION);
|
||||
|
||||
WorldTimeSet = 18000;
|
||||
DamagePvP = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void ScoreboardUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST || !IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Scoreboard.writeNewLine();
|
||||
|
||||
AtomicInteger index = new AtomicInteger(0);
|
||||
List<DragonScore> scores = new ArrayList<>(_score);
|
||||
Collections.reverse(scores);
|
||||
|
||||
Scoreboard.writeGroup(scores.subList(0, Math.min(16, scores.size())), score ->
|
||||
{
|
||||
ChatColor col = IsAlive(score.Player) ? ChatColor.GREEN : ChatColor.RED;
|
||||
return Pair.create(col + score.Player.getName(), index.incrementAndGet());
|
||||
}, true);
|
||||
|
||||
Scoreboard.writeNewLine();
|
||||
|
||||
Scoreboard.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ParseData()
|
||||
{
|
||||
// Setup all Beam Sources
|
||||
List<Location> sources = WorldData.GetDataLocs("LIME");
|
||||
|
||||
for (Location location : sources)
|
||||
{
|
||||
_sources.add(new BeamSource(location));
|
||||
}
|
||||
|
||||
Location start = WorldData.GetDataLocs("RED").get(0);
|
||||
Location last = start;
|
||||
List<Location> targets = WorldData.GetDataLocs("BLACK");
|
||||
ArrayList<Location> path = new ArrayList<>();
|
||||
path.addAll(targets);
|
||||
path.addAll(WorldData.GetDataLocs("BROWN"));
|
||||
|
||||
while (!path.isEmpty())
|
||||
{
|
||||
Location closestPath = UtilAlg.findClosest(last, path);
|
||||
|
||||
if (targets.contains(closestPath))
|
||||
{
|
||||
_targets.add(closestPath);
|
||||
}
|
||||
|
||||
_path.add(closestPath);
|
||||
path.remove(closestPath);
|
||||
last = closestPath;
|
||||
}
|
||||
|
||||
int id = 0;
|
||||
|
||||
for (Location pathPoint : _path)
|
||||
{
|
||||
BeamSource source = getClosestSource(pathPoint);
|
||||
|
||||
source.addBeam(Manager, id++, pathPoint);
|
||||
}
|
||||
}
|
||||
|
||||
private BeamSource getClosestSource(Location location)
|
||||
{
|
||||
BeamSource best = null;
|
||||
double bestDist = Double.MAX_VALUE;
|
||||
|
||||
for (BeamSource source : _sources)
|
||||
{
|
||||
double dist = UtilMath.offsetSquared(source.getSource(), location);
|
||||
|
||||
if (best == null || dist < bestDist)
|
||||
{
|
||||
best = source;
|
||||
bestDist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void live(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() != GameState.Live)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : GetPlayers(true))
|
||||
{
|
||||
_score.add(new DragonScore(player, 0));
|
||||
}
|
||||
|
||||
_lastBeam = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateBeam(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST || !IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Beam beam = getSuitableBeam();
|
||||
|
||||
if (beam == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastBeam = System.currentTimeMillis();
|
||||
_lastBeamId++;
|
||||
|
||||
Manager.runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (beam.update())
|
||||
{
|
||||
for (DragonScore score : _score)
|
||||
{
|
||||
if (score.Score <= _lastBeamId)
|
||||
{
|
||||
Manager.GetDamage().NewDamageEvent(score.Player, null, null, DamageCause.CUSTOM, 9999, false, true, false, GetName(), "Phaser");
|
||||
}
|
||||
}
|
||||
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 0, 2);
|
||||
}
|
||||
|
||||
private Beam getSuitableBeam()
|
||||
{
|
||||
if (!UtilTime.elapsed(_lastBeam, 5000))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (BeamSource beamSource : _sources)
|
||||
{
|
||||
Beam beam = beamSource.getFromId(_lastBeamId);
|
||||
|
||||
if (beam != null)
|
||||
{
|
||||
return beam;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updatePlayerTracker(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FASTEST || !IsLive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : GetPlayers(true))
|
||||
{
|
||||
DragonScore score = getScore(player);
|
||||
double currentScore = score.Score;
|
||||
int newScore = 0;
|
||||
Location location = UtilAlg.findClosest(player.getLocation(), _path);
|
||||
|
||||
if (UtilMath.offsetSquared(player.getLocation(), location) > 100)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _path.size(); i++)
|
||||
{
|
||||
Location a = _path.get(i);
|
||||
|
||||
if (location.equals(a))
|
||||
{
|
||||
newScore = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (newScore > currentScore)
|
||||
{
|
||||
Bukkit.broadcastMessage(player.getName() + "=" + newScore);
|
||||
score.Score = newScore;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void EndCheck()
|
||||
{
|
||||
for (DragonScore score : _score)
|
||||
{
|
||||
if (score.Score == _path.size() - 1)
|
||||
{
|
||||
SetState(GameState.End);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DragonScore getScore(Player player)
|
||||
{
|
||||
for (DragonScore score : _score)
|
||||
{
|
||||
if (score.Player.equals(player))
|
||||
{
|
||||
return score;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package nautilus.game.arcade.game.games.alieninvasion;
|
||||
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.particles.effects.LineParticle;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
public class Beam extends LineParticle
|
||||
{
|
||||
|
||||
private static final int EXPLOSION_RADIUS = 15;
|
||||
private static final int BEAM_BLOCK_TIME = 1500;
|
||||
|
||||
private final ArcadeManager _manager;
|
||||
private final Location _target;
|
||||
private final int _id;
|
||||
|
||||
public Beam(ArcadeManager manager, int id, BeamSource source, Location target)
|
||||
{
|
||||
super(source.getSource(), target, null, 1, Integer.MAX_VALUE, null, ParticleType.FIREWORKS_SPARK, UtilServer.getPlayers());
|
||||
|
||||
_manager = manager;
|
||||
_id = id;
|
||||
_target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update()
|
||||
{
|
||||
super.update();
|
||||
Location last = getLastLocation();
|
||||
boolean hit = UtilMath.offset(last, _target) < 5;
|
||||
|
||||
if (hit)
|
||||
{
|
||||
_manager.GetExplosion().BlockExplosion(UtilBlock.getInRadius(last, EXPLOSION_RADIUS).keySet(), last, false);
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, last, 4, 1, 4, 0.5F, 10, ViewDist.LONG);
|
||||
}
|
||||
else
|
||||
{
|
||||
last.getWorld().playSound(last, Sound.ZOMBIE_REMEDY, 2f, 0.75f);
|
||||
_manager.GetBlockRestore().add(last.getBlock(), Material.SEA_LANTERN.getId(), (byte) 0, BEAM_BLOCK_TIME);
|
||||
}
|
||||
|
||||
return hit;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package nautilus.game.arcade.game.games.alieninvasion;
|
||||
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BeamSource
|
||||
{
|
||||
|
||||
private final Location _source;
|
||||
private final List<Beam> _beams;
|
||||
|
||||
BeamSource(Location source)
|
||||
{
|
||||
_source = source;
|
||||
_beams = new ArrayList<>(5);
|
||||
}
|
||||
|
||||
public void addBeam(ArcadeManager manager, int id, Location target)
|
||||
{
|
||||
_beams.add(new Beam(manager, id, this, target));
|
||||
}
|
||||
|
||||
public Location getSource()
|
||||
{
|
||||
return _source;
|
||||
}
|
||||
|
||||
public Beam getFromId(int id)
|
||||
{
|
||||
for (Beam beam : _beams)
|
||||
{
|
||||
if (beam.getId() == id)
|
||||
{
|
||||
return beam;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package nautilus.game.arcade.game.games.alieninvasion.kit;
|
||||
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import nautilus.game.arcade.kit.KitAvailability;
|
||||
import nautilus.game.arcade.kit.Perk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class KitPlayer extends Kit
|
||||
{
|
||||
|
||||
private static final String[] DESCRIPTION = {
|
||||
""
|
||||
};
|
||||
|
||||
private static final Perk[] PERKS = {
|
||||
|
||||
};
|
||||
|
||||
private static final ItemStack IN_HAND = new ItemStack(Material.ENDER_STONE);
|
||||
|
||||
public KitPlayer(ArcadeManager manager)
|
||||
{
|
||||
super(manager, "Player", KitAvailability.Free, DESCRIPTION, PERKS, EntityType.SKELETON, IN_HAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void GiveItems(Player player)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user