Implement first pass at config loading, /join, /leave commands, tab completion (broken)
This commit is contained in:
@@ -3,6 +3,7 @@ package gg.malloc.defense.engine;
|
||||
import gg.malloc.defense.model.Arena;
|
||||
import gg.malloc.defense.model.Game;
|
||||
import gg.malloc.defense.model.Spawner;
|
||||
import gg.malloc.defense.model.Waypoint;
|
||||
|
||||
import gg.malloc.defense.ui.BombCarrier;
|
||||
import gg.malloc.defense.ui.BossBars;
|
||||
@@ -60,9 +61,16 @@ public class GameRunner {
|
||||
|
||||
BossBars m_bars;
|
||||
|
||||
public GameRunner(Plugin plugin, Game game, Arena arena) {
|
||||
World m_world;
|
||||
|
||||
Location getLocation(Waypoint waypoint) {
|
||||
return new Location(m_world, waypoint.getX(), waypoint.getY(), waypoint.getZ());
|
||||
}
|
||||
|
||||
public GameRunner(Plugin plugin, Game game, Arena arena, World world) {
|
||||
m_plugin = plugin;
|
||||
m_game = game;
|
||||
m_world = world;
|
||||
m_arena = arena;
|
||||
m_stage = Stage.Idle;
|
||||
m_mobs = new MobManager();
|
||||
@@ -92,13 +100,13 @@ public class GameRunner {
|
||||
}, 20);
|
||||
|
||||
m_bombSmokeTask = new TickTask(m_plugin, () -> {
|
||||
Location targetLoc = m_arena.bombTarget().getLocation();
|
||||
m_arena.getWorld().spawnParticle(Particle.SMOKE_LARGE, targetLoc, 35, 4, 2, 4);
|
||||
m_arena.getWorld().spawnParticle(Particle.SMALL_FLAME, targetLoc, 30, 3, 2, 3);
|
||||
Location targetLoc = getLocation(m_arena.bombTarget());
|
||||
m_world.spawnParticle(Particle.SMOKE_LARGE, targetLoc, 35, 4, 2, 4);
|
||||
m_world.spawnParticle(Particle.SMALL_FLAME, targetLoc, 30, 3, 2, 3);
|
||||
}, 5);
|
||||
m_bombCrackleTask = new TickTask(m_plugin, () -> {
|
||||
Location targetLoc = m_arena.bombTarget().getLocation();
|
||||
m_arena.getWorld().playSound(targetLoc, Sound.BLOCK_CAMPFIRE_CRACKLE, SoundCategory.NEUTRAL, 1.0f, 1.0f);
|
||||
Location targetLoc = getLocation(m_arena.bombTarget());
|
||||
m_world.playSound(targetLoc, Sound.BLOCK_CAMPFIRE_CRACKLE, SoundCategory.NEUTRAL, 1.0f, 1.0f);
|
||||
}, 35);
|
||||
}
|
||||
|
||||
@@ -115,12 +123,12 @@ public class GameRunner {
|
||||
m_log.info("Target attacked!");
|
||||
entityEvt.getDamager().setGlowing(true);
|
||||
m_bombFuse.tickLit();
|
||||
m_arena.getWorld().playSound(m_arena.bombTarget().getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1.5f, 0.9f);
|
||||
m_world.playSound(getLocation(m_arena.bombTarget()), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1.5f, 0.9f);
|
||||
m_bars.update();
|
||||
if (m_bombFuse.isExploded()) {
|
||||
m_arena.getWorld().strikeLightningEffect(m_arena.bombTarget().getLocation());
|
||||
m_arena.getWorld().playSound(m_arena.bombTarget().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.NEUTRAL, 1.3f, 1.0f);
|
||||
m_arena.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, m_arena.bombTarget().getLocation(), 8, 5, 2, 5);
|
||||
m_world.strikeLightningEffect(getLocation(m_arena.bombTarget()));
|
||||
m_world.playSound(getLocation(m_arena.bombTarget()), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.NEUTRAL, 1.3f, 1.0f);
|
||||
m_world.spawnParticle(Particle.EXPLOSION_HUGE, getLocation(m_arena.bombTarget()), 8, 5, 2, 5);
|
||||
requestTransition(Stage.GameOver);
|
||||
m_bombSmokeTask.start();
|
||||
m_bombCrackleTask.start();
|
||||
@@ -150,7 +158,7 @@ public class GameRunner {
|
||||
m_waves.next();
|
||||
for(Player p : m_players.getPlayers()) {
|
||||
if (m_players.requestTransition(p, PlayerManager.State.Playing)) {
|
||||
p.teleport(m_arena.getWorld().getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
p.teleport(m_world.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
}
|
||||
m_players.setReady(p, false);
|
||||
}
|
||||
@@ -179,11 +187,11 @@ public class GameRunner {
|
||||
|
||||
private boolean enterPlaying() {
|
||||
m_log.info("Starting wave " + m_waves.currentWaveNum());
|
||||
m_mobs.spawnTarget(m_arena.bombTarget().getLocation());
|
||||
m_mobs.spawnTarget(getLocation(m_arena.bombTarget()));
|
||||
// TODO: Set helmet with custom model data
|
||||
for(Player p : m_players.getPlayers()) {
|
||||
if (m_players.requestTransition(p, PlayerManager.State.Playing)) {
|
||||
p.teleport(m_arena.getWorld().getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
p.teleport(m_world.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
}
|
||||
}
|
||||
m_countdownTask.stop();
|
||||
@@ -211,14 +219,14 @@ public class GameRunner {
|
||||
|
||||
private void spawnNextBatch() {
|
||||
broadcastMessage("Spawning batch " + m_waves.currentBatchNum());
|
||||
Spawner spawner = new GameSpawner(m_arena, m_mobs, m_players);
|
||||
Spawner spawner = new GameSpawner(m_world, m_arena, m_mobs, m_players);
|
||||
m_waves.currentWave().spawnBatch(spawner, m_waves.currentBatchNum());
|
||||
m_bars.update();
|
||||
}
|
||||
|
||||
private void handlePlayerDeath(Player player) {
|
||||
if (m_players.requestTransition(player, PlayerManager.State.Dead)) {
|
||||
m_arena.getWorld().strikeLightningEffect(player.getLocation());
|
||||
m_world.strikeLightningEffect(player.getLocation());
|
||||
if (!m_players.isAnyoneAlive()) {
|
||||
broadcastMessage("Everyone is dead :(");
|
||||
requestTransition(Stage.GameOver);
|
||||
@@ -273,7 +281,7 @@ public class GameRunner {
|
||||
private boolean validateTransition(Stage from, Stage to) {
|
||||
switch(from) {
|
||||
case Idle:
|
||||
return to == Stage.Warmup;
|
||||
return !m_players.isEmpty() && to == Stage.Warmup;
|
||||
case Warmup:
|
||||
return to == Stage.Playing || to == Stage.Idle || to == Stage.Countdown ;
|
||||
case Countdown:
|
||||
@@ -309,7 +317,7 @@ public class GameRunner {
|
||||
m_bars.addPlayer(p);
|
||||
if (m_stage == Stage.Idle || m_stage == Stage.Warmup) {
|
||||
if (m_players.requestTransition(p, PlayerManager.State.Playing)) {
|
||||
p.teleport(m_arena.getWorld().getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
p.teleport(m_world.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
}
|
||||
broadcastMessage(p.getName() + " has joined the game");
|
||||
if (m_stage == Stage.Idle) {
|
||||
@@ -337,8 +345,7 @@ public class GameRunner {
|
||||
}
|
||||
|
||||
void broadcastMessage(String string) {
|
||||
World world = m_arena.getWorld();
|
||||
for(Player p : world.getPlayers()) {
|
||||
for(Player p : m_world.getPlayers()) {
|
||||
p.sendMessage(string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package gg.malloc.defense.engine;
|
||||
|
||||
import gg.malloc.defense.model.Spawner;
|
||||
import gg.malloc.defense.model.Spawnpoint;
|
||||
import gg.malloc.defense.model.Waypoint;
|
||||
import gg.malloc.defense.model.Arena;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -20,8 +22,10 @@ public class GameSpawner implements Spawner {
|
||||
MobManager m_manager;
|
||||
PlayerManager m_players;
|
||||
int m_spawnIdx = 0;
|
||||
World m_world;
|
||||
|
||||
public GameSpawner(Arena arena, MobManager manager, PlayerManager players) {
|
||||
public GameSpawner(World world, Arena arena, MobManager manager, PlayerManager players) {
|
||||
m_world = world;
|
||||
m_arena = arena;
|
||||
m_manager = manager;
|
||||
m_players = players;
|
||||
@@ -38,10 +42,12 @@ public class GameSpawner implements Spawner {
|
||||
|
||||
@Override
|
||||
public LivingEntity spawnMob(EntityType type) {
|
||||
Spawnpoint[] spawnpoints = m_arena.spawnpoints();
|
||||
Waypoint[] spawnpoints = m_arena.spawnpoints();
|
||||
m_spawnIdx %= spawnpoints.length;
|
||||
//m_log.fine("Spawning " + type + " at " + spawnpoints[m_spawnIdx]);
|
||||
Entity newMob = m_arena.getWorld().spawnEntity(spawnpoints[m_spawnIdx].getLocation(), type);
|
||||
Waypoint thisSpawner = spawnpoints[m_spawnIdx];
|
||||
Location loc = new Location(m_world, thisSpawner.getX(), thisSpawner.getY(), thisSpawner.getZ());
|
||||
Entity newMob = m_world.spawnEntity(loc, type);
|
||||
LivingEntity livingMob = (LivingEntity)newMob;
|
||||
livingMob.setRemoveWhenFarAway(false);
|
||||
m_manager.addEntity(livingMob);
|
||||
|
||||
Reference in New Issue
Block a user