Colors, basic mob AI categories, end world hunger, UX buffs
This commit is contained in:
		@@ -19,9 +19,12 @@ import gg.malloc.defense.Plugin;
 | 
			
		||||
import java.util.logging.Logger;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.GameRule;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.Particle;
 | 
			
		||||
import org.bukkit.Sound;
 | 
			
		||||
import org.bukkit.SoundCategory;
 | 
			
		||||
@@ -32,11 +35,11 @@ import org.bukkit.event.entity.EntityTargetEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerTeleportEvent;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.attribute.Attribute;
 | 
			
		||||
import org.bukkit.attribute.AttributeModifier;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.entity.Projectile;
 | 
			
		||||
import org.bukkit.attribute.Attribute;
 | 
			
		||||
import org.bukkit.attribute.AttributeModifier;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
public class GameRunner {
 | 
			
		||||
@@ -75,6 +78,24 @@ public class GameRunner {
 | 
			
		||||
    return new Location(m_world, waypoint.getX(), waypoint.getY(), waypoint.getZ());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void validateGameRule(GameRule rule, boolean value) {
 | 
			
		||||
    if (!m_world.getGameRuleValue(rule).equals(value)) {
 | 
			
		||||
      m_log.warning("Game rule " + rule + " is not " + value);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void validateGameRules() {
 | 
			
		||||
    validateGameRule(GameRule.DO_MOB_LOOT, false);
 | 
			
		||||
    validateGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false);
 | 
			
		||||
    validateGameRule(GameRule.DISABLE_RAIDS, true);
 | 
			
		||||
    validateGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
 | 
			
		||||
    validateGameRule(GameRule.DO_ENTITY_DROPS, false);
 | 
			
		||||
    validateGameRule(GameRule.DO_FIRE_TICK, false);
 | 
			
		||||
    validateGameRule(GameRule.DO_INSOMNIA, false);
 | 
			
		||||
    validateGameRule(GameRule.DO_WEATHER_CYCLE, false);
 | 
			
		||||
    validateGameRule(GameRule.SPECTATORS_GENERATE_CHUNKS, false);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public GameRunner(Plugin plugin, Game game, Arena arena, World world) {
 | 
			
		||||
    m_plugin = plugin;
 | 
			
		||||
    m_game = game;
 | 
			
		||||
@@ -124,15 +145,15 @@ public class GameRunner {
 | 
			
		||||
          .create();
 | 
			
		||||
        broadcastMessage(message);
 | 
			
		||||
        m_gameEndCountdown--;
 | 
			
		||||
        m_bars.setCountdownProgress((double)m_gameEndCountdown / 30.0);
 | 
			
		||||
        m_bars.setCountdownProgress((double)m_gameEndCountdown / 60.0);
 | 
			
		||||
        m_bars.update();
 | 
			
		||||
      }
 | 
			
		||||
    }, 20);
 | 
			
		||||
 | 
			
		||||
    m_bombSmokeTask = new TickTask(m_plugin, () -> {
 | 
			
		||||
      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);
 | 
			
		||||
      m_world.spawnParticle(Particle.SMOKE_LARGE, targetLoc, 135, 4, 2, 4, 1);
 | 
			
		||||
      m_world.spawnParticle(Particle.SMALL_FLAME, targetLoc, 130, 3, 2, 3, 1);
 | 
			
		||||
    }, 5);
 | 
			
		||||
    m_bombCrackleTask = new TickTask(m_plugin, () -> {
 | 
			
		||||
      Location targetLoc = getLocation(m_arena.bombTarget());
 | 
			
		||||
@@ -149,7 +170,7 @@ public class GameRunner {
 | 
			
		||||
 | 
			
		||||
  public void handleEntityDamage(EntityDamageEvent evt) {
 | 
			
		||||
    m_mobs.handleEntityDamage(evt);
 | 
			
		||||
    if (m_mobs.bombWasHit()) {
 | 
			
		||||
    if (m_mobs.bombWasHit() && !m_bombFuse.isExploded()) {
 | 
			
		||||
      EntityDamageByEntityEvent entityEvt = (EntityDamageByEntityEvent)evt;
 | 
			
		||||
      m_log.info("Target attacked!");
 | 
			
		||||
      entityEvt.getDamager().setGlowing(true);
 | 
			
		||||
@@ -175,9 +196,14 @@ public class GameRunner {
 | 
			
		||||
        if (entityEvt.getDamager() instanceof Player) {
 | 
			
		||||
          evt.setCancelled(true);
 | 
			
		||||
          return;
 | 
			
		||||
        } else if (entityEvt.getDamager() instanceof Projectile) {
 | 
			
		||||
          Projectile asProjectile = (Projectile)entityEvt.getDamager();
 | 
			
		||||
          if (asProjectile.getShooter()  instanceof Player) {
 | 
			
		||||
            evt.setCancelled(true);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      if (m_players.contains(player) && player.getHealth() - evt.getFinalDamage() <= 0) {
 | 
			
		||||
      if (m_players.contains(player) && player.getHealth() - evt.getFinalDamage() <= 0 && m_stage == Stage.Playing) {
 | 
			
		||||
        evt.setCancelled(true);
 | 
			
		||||
        handlePlayerDeath(player);
 | 
			
		||||
      }
 | 
			
		||||
@@ -197,6 +223,10 @@ public class GameRunner {
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Collection<Player> getPlayers() {
 | 
			
		||||
    return m_players.getPlayers();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private boolean enterWarmup() {
 | 
			
		||||
    m_waves.next();
 | 
			
		||||
    for(Player p : m_players.getPlayers()) {
 | 
			
		||||
@@ -204,12 +234,13 @@ public class GameRunner {
 | 
			
		||||
          p.teleport(m_world.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
 | 
			
		||||
        }
 | 
			
		||||
        m_players.setReady(p, false);
 | 
			
		||||
        m_players.healPlayer(p);
 | 
			
		||||
    }
 | 
			
		||||
    BaseComponent[] message = new ComponentBuilder()
 | 
			
		||||
      .append("Click").color(ChatColor.LIGHT_PURPLE)
 | 
			
		||||
      .append("[Here]").color(ChatColor.GOLD)
 | 
			
		||||
      .append(" [Here] ").color(ChatColor.GOLD).bold(true)
 | 
			
		||||
      .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/malloc-defense:ready"))
 | 
			
		||||
      .append(" when ready.").color(ChatColor.LIGHT_PURPLE)
 | 
			
		||||
      .append("when ready.").color(ChatColor.LIGHT_PURPLE)
 | 
			
		||||
      .create();
 | 
			
		||||
    broadcastMessage(message);
 | 
			
		||||
    m_mobs.clear();
 | 
			
		||||
@@ -233,11 +264,11 @@ public class GameRunner {
 | 
			
		||||
          .append(p.getName()).bold(true)
 | 
			
		||||
          .append(" is ready!").color(ChatColor.AQUA).italic(true)
 | 
			
		||||
          .create();
 | 
			
		||||
        broadcastMessage(message);
 | 
			
		||||
      }
 | 
			
		||||
      m_players.setReady(p, isReady);
 | 
			
		||||
    }
 | 
			
		||||
    m_bars.update();
 | 
			
		||||
    broadcastMessage(message);
 | 
			
		||||
    if (m_players.isEveryoneReady()) {
 | 
			
		||||
      requestTransition(Stage.Countdown);
 | 
			
		||||
    }
 | 
			
		||||
@@ -270,7 +301,7 @@ public class GameRunner {
 | 
			
		||||
    m_lobbyReturnTask.start();
 | 
			
		||||
    m_countdownTask.stop();
 | 
			
		||||
    m_fuseTask.stop();
 | 
			
		||||
    m_mobs.clear();
 | 
			
		||||
    //m_mobs.clear();
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -280,7 +311,7 @@ public class GameRunner {
 | 
			
		||||
 | 
			
		||||
  private void spawnNextBatch() {
 | 
			
		||||
    m_log.info("Spawning batch " + m_waves.currentBatchNum());
 | 
			
		||||
    Spawner spawner = new GameSpawner(m_world, m_arena, m_mobs, m_players);
 | 
			
		||||
    Spawner spawner = new GameSpawner(m_world, m_arena, m_mobs);
 | 
			
		||||
    m_waves.currentWave().spawnBatch(spawner, m_waves.currentBatchNum());
 | 
			
		||||
    m_bars.update();
 | 
			
		||||
  }
 | 
			
		||||
@@ -305,9 +336,9 @@ public class GameRunner {
 | 
			
		||||
  public void handleEntityDeath(Entity entity) {
 | 
			
		||||
    boolean wasCarrier = m_mobs.isBombCarrier(entity);
 | 
			
		||||
    if (m_mobs.killMob(entity)) {
 | 
			
		||||
      int coinsToDrop = 300;
 | 
			
		||||
      int coinsToDrop = 60;
 | 
			
		||||
      while(coinsToDrop > 0) {
 | 
			
		||||
        int droppedCoins = Math.min(coinsToDrop, 64);
 | 
			
		||||
        int droppedCoins = Math.min(coinsToDrop, 5);
 | 
			
		||||
        ItemStack coins = Items.makeCoins();
 | 
			
		||||
        coins.setAmount(droppedCoins);
 | 
			
		||||
        coinsToDrop -= 64;
 | 
			
		||||
@@ -360,9 +391,9 @@ public class GameRunner {
 | 
			
		||||
      case Idle:
 | 
			
		||||
        return !m_players.isEmpty() && to == Stage.Warmup;
 | 
			
		||||
      case Warmup:
 | 
			
		||||
        return to == Stage.Playing || to == Stage.Idle || to == Stage.Countdown;
 | 
			
		||||
        return to == Stage.Playing || to == Stage.Idle || to == Stage.Countdown || to == Stage.GameOver;
 | 
			
		||||
      case Countdown:
 | 
			
		||||
        return to == Stage.Playing || to == Stage.Idle || to == Stage.Warmup;
 | 
			
		||||
        return to == Stage.Playing || to == Stage.Idle || to == Stage.Warmup || to == Stage.GameOver;
 | 
			
		||||
      case Playing:
 | 
			
		||||
        return to == Stage.Warmup || to == Stage.GameOver || to == Stage.Idle;
 | 
			
		||||
      case GameOver:
 | 
			
		||||
@@ -392,13 +423,13 @@ public class GameRunner {
 | 
			
		||||
  void sendStageTitle(Player p) {
 | 
			
		||||
    switch(m_stage) {
 | 
			
		||||
      case Warmup:
 | 
			
		||||
        p.sendTitle("Warmup", "Prepare yourself for wave " + m_waves.currentWaveNum(), 10, 70, 20);
 | 
			
		||||
        p.sendTitle(ChatColor.YELLOW.toString() + "Warmup", ChatColor.LIGHT_PURPLE.toString() + "Prepare yourself for wave " + m_waves.currentWaveNum());
 | 
			
		||||
        break;
 | 
			
		||||
      case Playing:
 | 
			
		||||
        p.sendTitle("Wave " + m_waves.currentWaveNum(), "", 10, 70, 20);
 | 
			
		||||
        p.sendTitle(ChatColor.AQUA.toString()  + "Wave " + m_waves.currentWaveNum(), "");
 | 
			
		||||
        break;
 | 
			
		||||
      case GameOver:
 | 
			
		||||
        p.sendTitle("Game over!", "", 10, 70, 20);
 | 
			
		||||
        p.sendTitle(ChatColor.RED.toString() + "Game over!", "");
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -406,6 +437,7 @@ public class GameRunner {
 | 
			
		||||
    if (m_players.contains(p)) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    p.getInventory().clear();
 | 
			
		||||
    m_players.addPlayer(p);
 | 
			
		||||
    m_bars.addPlayer(p);
 | 
			
		||||
    if (m_stage == Stage.Idle || m_stage == Stage.Warmup) {
 | 
			
		||||
@@ -414,7 +446,7 @@ public class GameRunner {
 | 
			
		||||
      }
 | 
			
		||||
      BaseComponent[] message = new ComponentBuilder()
 | 
			
		||||
        .append(p.getName()).bold(true)
 | 
			
		||||
        .append("Has joined the game").color(ChatColor.AQUA)
 | 
			
		||||
        .append(" has joined the game").color(ChatColor.AQUA)
 | 
			
		||||
        .create();
 | 
			
		||||
      broadcastMessage(message);
 | 
			
		||||
      sendStageTitle(p);
 | 
			
		||||
@@ -425,6 +457,7 @@ public class GameRunner {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void removePlayer(Player p) {
 | 
			
		||||
    p.getInventory().clear();
 | 
			
		||||
    m_bars.removePlayer(p);
 | 
			
		||||
    m_players.removePlayer(p);
 | 
			
		||||
    if (m_players.isEmpty()) {
 | 
			
		||||
@@ -444,7 +477,7 @@ public class GameRunner {
 | 
			
		||||
 | 
			
		||||
  void broadcastTitle(String title, String subtitle) {
 | 
			
		||||
    for(Player p : m_players.getPlayers()) {
 | 
			
		||||
      p.sendTitle(title, subtitle, 10, 70, 20);
 | 
			
		||||
      p.sendTitle(title, subtitle);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -20,38 +20,39 @@ import org.bukkit.attribute.AttributeModifier;
 | 
			
		||||
public class GameSpawner implements Spawner {
 | 
			
		||||
  Arena m_arena;
 | 
			
		||||
  MobManager m_manager;
 | 
			
		||||
  PlayerManager m_players;
 | 
			
		||||
  int m_spawnIdx = 0;
 | 
			
		||||
  World m_world;
 | 
			
		||||
 | 
			
		||||
  public GameSpawner(World world, Arena arena, MobManager manager, PlayerManager players) {
 | 
			
		||||
  public GameSpawner(World world, Arena arena, MobManager manager) {
 | 
			
		||||
    m_world = world;
 | 
			
		||||
    m_arena = arena;
 | 
			
		||||
    m_manager = manager;
 | 
			
		||||
    m_players = players;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public LivingEntity spawnBombCarrier(EntityType type) {
 | 
			
		||||
    if (m_manager.bombCount() == 0) {
 | 
			
		||||
      return m_manager.addBombCarrier(spawnMob(type));
 | 
			
		||||
      return m_manager.addBombCarrier(spawnMob(type, MobManager.Goal.BombCarrier));
 | 
			
		||||
    } else {
 | 
			
		||||
      return spawnMob(type);
 | 
			
		||||
      return spawnMob(type, MobManager.Goal.BombCarrier);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public LivingEntity spawnMob(EntityType type) {
 | 
			
		||||
    return spawnMob(type, MobManager.Goal.PlayerHarassment);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Mob spawnMob(EntityType type, MobManager.Goal goal) {
 | 
			
		||||
    Waypoint[] spawnpoints = m_arena.spawnpoints();
 | 
			
		||||
    m_spawnIdx %= spawnpoints.length;
 | 
			
		||||
    //m_log.fine("Spawning " + type + " at " + spawnpoints[m_spawnIdx]);
 | 
			
		||||
    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);
 | 
			
		||||
    Mob newMob = (Mob)m_world.spawnEntity(loc, type);
 | 
			
		||||
    newMob.setRemoveWhenFarAway(false);
 | 
			
		||||
    m_manager.addEntity(newMob, goal);
 | 
			
		||||
    m_spawnIdx += 1;
 | 
			
		||||
    return livingMob;
 | 
			
		||||
    return newMob;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,25 +1,37 @@
 | 
			
		||||
package gg.malloc.defense.engine;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.ArmorStand;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.GameMode;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.entity.Mob;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityTargetEvent;
 | 
			
		||||
import org.bukkit.inventory.EntityEquipment;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.model.Game;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.ui.BombCarrier;
 | 
			
		||||
import gg.malloc.defense.ui.Items;
 | 
			
		||||
 | 
			
		||||
public class MobManager {
 | 
			
		||||
  HashSet<LivingEntity> m_livingMobs = new HashSet<>();
 | 
			
		||||
  HashSet<LivingEntity> m_bombCarriers = new HashSet<>();
 | 
			
		||||
  LivingEntity m_bombTarget;
 | 
			
		||||
  HashSet<Mob> m_livingMobs = new HashSet<>();
 | 
			
		||||
  HashSet<Mob> m_bombCarriers = new HashSet<>();
 | 
			
		||||
  HashSet<LivingEntity> m_droppedBombs = new HashSet<>();
 | 
			
		||||
  HashMap<Mob, Goal> m_mobGoals = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
  public enum Goal {
 | 
			
		||||
    BombCarrier,
 | 
			
		||||
    PlayerHarassment
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int m_createdMobs = 0;
 | 
			
		||||
  int m_killedMobs = 0;
 | 
			
		||||
@@ -44,7 +56,7 @@ public class MobManager {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void clear() {
 | 
			
		||||
    for(LivingEntity e : m_livingMobs) {
 | 
			
		||||
    for(Mob e : m_livingMobs) {
 | 
			
		||||
      e.remove();
 | 
			
		||||
    }
 | 
			
		||||
    for(LivingEntity e : m_droppedBombs) {
 | 
			
		||||
@@ -77,14 +89,76 @@ public class MobManager {
 | 
			
		||||
    return (double)m_killedMobs / (double)m_createdMobs;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void addEntity(LivingEntity entity) {
 | 
			
		||||
    m_livingMobs.add(entity);
 | 
			
		||||
    Mob asMob = (Mob)entity;
 | 
			
		||||
    if (m_droppedBombs.size() > 0) {
 | 
			
		||||
      asMob.setTarget(m_droppedBombs.iterator().next());
 | 
			
		||||
    } else {
 | 
			
		||||
      asMob.setTarget(m_bombTarget);
 | 
			
		||||
  Player getNearestPlayer(Location location) {
 | 
			
		||||
    Player nearestPlayer = null;
 | 
			
		||||
    for(Player p : location.getWorld().getPlayers()) {
 | 
			
		||||
      if (p.getGameMode() == GameMode.SPECTATOR) {
 | 
			
		||||
        continue;
 | 
			
		||||
      } else if (nearestPlayer == null) {
 | 
			
		||||
        nearestPlayer = p;
 | 
			
		||||
      } else if (location.distance(p.getLocation()) < location.distance(nearestPlayer.getLocation())) {
 | 
			
		||||
        nearestPlayer = p;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return nearestPlayer;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  LivingEntity getNearestBombObjective(Location location) {
 | 
			
		||||
    LivingEntity nearest = null;
 | 
			
		||||
    if (m_droppedBombs.size() > 0) {
 | 
			
		||||
      for(LivingEntity ent : m_droppedBombs) {
 | 
			
		||||
        if (nearest == null) {
 | 
			
		||||
          nearest = ent;
 | 
			
		||||
        } else if (location.distance(ent.getLocation()) < location.distance(nearest.getLocation())) {
 | 
			
		||||
          nearest = ent;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } else if (m_bombCarriers.size() > 0) {
 | 
			
		||||
      for(LivingEntity ent : m_bombCarriers) {
 | 
			
		||||
        if (nearest == null) {
 | 
			
		||||
          nearest = ent;
 | 
			
		||||
        } else if (location.distance(ent.getLocation()) < location.distance(nearest.getLocation())) {
 | 
			
		||||
          nearest = ent;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (nearest == null) {
 | 
			
		||||
      nearest = m_bombTarget;
 | 
			
		||||
    }
 | 
			
		||||
    return nearest;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  Player getBiggestPlayerThreat(Location location) {
 | 
			
		||||
    Entity mostImportantObjective = getNearestBombObjective(location);
 | 
			
		||||
    return getNearestPlayer(mostImportantObjective.getLocation());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  LivingEntity getMobTarget(Mob mob) {
 | 
			
		||||
    switch(m_mobGoals.get(mob)) {
 | 
			
		||||
      case PlayerHarassment:
 | 
			
		||||
        if (mob.getTarget() instanceof Player) {
 | 
			
		||||
          return mob.getTarget();
 | 
			
		||||
        } else {
 | 
			
		||||
          Player nearestThreat = getBiggestPlayerThreat(mob.getLocation());
 | 
			
		||||
          return nearestThreat;
 | 
			
		||||
        }
 | 
			
		||||
      case BombCarrier:
 | 
			
		||||
        if (m_bombCarriers.contains(mob)) {
 | 
			
		||||
          return m_bombTarget;
 | 
			
		||||
        } else if (m_droppedBombs.size() > 0) {
 | 
			
		||||
          return m_droppedBombs.iterator().next();
 | 
			
		||||
        } else {
 | 
			
		||||
          return getBiggestPlayerThreat(mob.getLocation());
 | 
			
		||||
        }
 | 
			
		||||
      default:
 | 
			
		||||
        return m_bombTarget;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void addEntity(Mob entity, Goal goal) {
 | 
			
		||||
    m_livingMobs.add(entity);
 | 
			
		||||
    m_mobGoals.put(entity, goal);
 | 
			
		||||
    entity.setTarget(getMobTarget(entity));
 | 
			
		||||
    m_createdMobs += 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -92,13 +166,13 @@ public class MobManager {
 | 
			
		||||
    return m_bombCarriers.size() + m_droppedBombs.size();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public LivingEntity addBombCarrier(LivingEntity entity) {
 | 
			
		||||
  public Mob addBombCarrier(Mob entity) {
 | 
			
		||||
    m_bombCarriers.add(entity);
 | 
			
		||||
    ((Mob)entity).setTarget(m_bombTarget);
 | 
			
		||||
    return new BombCarrier(entity).inHand();
 | 
			
		||||
    entity.setTarget(m_bombTarget);
 | 
			
		||||
    return (Mob)(new BombCarrier(entity).inHand());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void removeBombCarrier(LivingEntity entity) {
 | 
			
		||||
  public void removeBombCarrier(Mob entity) {
 | 
			
		||||
    m_bombCarriers.remove(entity);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -109,13 +183,13 @@ public class MobManager {
 | 
			
		||||
  public LivingEntity dropBomb(Location location) {
 | 
			
		||||
    ArmorStand droppedBomb = (ArmorStand)(new BombCarrier((LivingEntity)location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND)).onHead());
 | 
			
		||||
    droppedBomb.setCustomName("The Bomb");
 | 
			
		||||
    droppedBomb.setVisible(true);
 | 
			
		||||
    droppedBomb.setVisible(false);
 | 
			
		||||
    droppedBomb.setCustomNameVisible(true);
 | 
			
		||||
    droppedBomb.setGlowing(true);
 | 
			
		||||
    m_droppedBombs.add(droppedBomb);
 | 
			
		||||
    for(LivingEntity ent : m_livingMobs) {
 | 
			
		||||
    for(Mob ent : m_livingMobs) {
 | 
			
		||||
      if (!m_bombCarriers.contains(ent)) {
 | 
			
		||||
        ((Mob)ent).setTarget(droppedBomb);
 | 
			
		||||
        ent.setTarget(getMobTarget(ent));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return droppedBomb;
 | 
			
		||||
@@ -143,11 +217,9 @@ public class MobManager {
 | 
			
		||||
      if (m_livingMobs.contains(entityEvt.getDamager())) {
 | 
			
		||||
        evt.getEntity().remove();
 | 
			
		||||
        m_droppedBombs.remove(evt.getEntity());
 | 
			
		||||
        addBombCarrier((LivingEntity)entityEvt.getDamager());
 | 
			
		||||
        for(LivingEntity ent : m_livingMobs) {
 | 
			
		||||
          if (!m_bombCarriers.contains(ent)) {
 | 
			
		||||
            ((Mob)ent).setTarget(m_bombTarget);
 | 
			
		||||
          }
 | 
			
		||||
        addBombCarrier((Mob)entityEvt.getDamager());
 | 
			
		||||
        for(Mob ent : m_livingMobs) {
 | 
			
		||||
          ent.setTarget(getMobTarget(ent));
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } else if (m_livingMobs.contains(evt.getEntity())) {
 | 
			
		||||
@@ -155,28 +227,22 @@ public class MobManager {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  LivingEntity m_bombTarget;
 | 
			
		||||
 | 
			
		||||
  public LivingEntity spawnTarget(Location location) {
 | 
			
		||||
    assert(m_bombTarget == null);
 | 
			
		||||
    m_bombTarget = (LivingEntity)location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
 | 
			
		||||
    ArmorStand bombStand = (ArmorStand)m_bombTarget;
 | 
			
		||||
    bombStand.setCustomName("Bomb Target");
 | 
			
		||||
    bombStand.setVisible(true);
 | 
			
		||||
    bombStand.setVisible(false);
 | 
			
		||||
    bombStand.setCustomNameVisible(true);
 | 
			
		||||
    bombStand.setGlowing(true);
 | 
			
		||||
    EntityEquipment equipment = bombStand.getEquipment();
 | 
			
		||||
    equipment.setHelmet(Items.makeBombTarget());
 | 
			
		||||
    return m_bombTarget;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void handleEntityRetarget(EntityTargetEvent evt) {
 | 
			
		||||
    if (m_livingMobs.contains(evt.getEntity())) {
 | 
			
		||||
      if (m_bombCarriers.contains(evt.getEntity())) {
 | 
			
		||||
        evt.setTarget(m_bombTarget);
 | 
			
		||||
      } if (m_droppedBombs.size() > 0) {
 | 
			
		||||
        evt.setTarget(m_droppedBombs.iterator().next());
 | 
			
		||||
      } else if (evt.getReason() == EntityTargetEvent.TargetReason.FORGOT_TARGET) {
 | 
			
		||||
        evt.setTarget(m_bombTarget);
 | 
			
		||||
      }
 | 
			
		||||
      evt.setTarget(getMobTarget((Mob)evt.getEntity()));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -57,12 +57,16 @@ public class PlayerManager {
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void healPlayer(Player player) {
 | 
			
		||||
    player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
 | 
			
		||||
    player.setFoodLevel(40);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Respawn player
 | 
			
		||||
  public boolean enterPlaying(Player player) {
 | 
			
		||||
    //m_log.fine("Respawning player " + player);
 | 
			
		||||
    player.setGameMode(Bukkit.getDefaultGameMode());
 | 
			
		||||
    player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
 | 
			
		||||
    player.setFoodLevel(20);
 | 
			
		||||
    healPlayer(player);
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -107,6 +111,7 @@ public class PlayerManager {
 | 
			
		||||
 | 
			
		||||
  public boolean removePlayer(Player player) {
 | 
			
		||||
    //m_log.info("Removing player " + player); 
 | 
			
		||||
    healPlayer(player);
 | 
			
		||||
    requestTransition(player, State.Idle);
 | 
			
		||||
    m_playerStates.remove(player);
 | 
			
		||||
    m_playerReadyStates.remove(player);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user