Implement in-game sidebars
This commit is contained in:
		@@ -1,10 +1,12 @@
 | 
			
		||||
package gg.malloc.defense.engine;
 | 
			
		||||
 | 
			
		||||
public class BombFuse {
 | 
			
		||||
import gg.malloc.defense.model.Progress;
 | 
			
		||||
 | 
			
		||||
public class BombFuse implements Progress {
 | 
			
		||||
  int m_bombFuseCount = 0;
 | 
			
		||||
  int m_bombFuseTarget = 10;
 | 
			
		||||
 | 
			
		||||
  public double getProgress() {
 | 
			
		||||
  public double toDouble() {
 | 
			
		||||
    return Math.max(0.0, Math.min(1.0, (double)m_bombFuseCount / (double)m_bombFuseTarget));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -27,4 +29,12 @@ public class BombFuse {
 | 
			
		||||
  public void tickDecay() {
 | 
			
		||||
    m_bombFuseCount -= 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public int value() {
 | 
			
		||||
    return m_bombFuseCount;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public int maximum() {
 | 
			
		||||
    return m_bombFuseTarget;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,9 +10,9 @@ import net.md_5.bungee.api.chat.ClickEvent;
 | 
			
		||||
import net.md_5.bungee.api.ChatColor;
 | 
			
		||||
import net.md_5.bungee.api.chat.ComponentBuilder;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.ui.BombCarrier;
 | 
			
		||||
import gg.malloc.defense.ui.BossBars;
 | 
			
		||||
import gg.malloc.defense.ui.Items;
 | 
			
		||||
import gg.malloc.defense.ui.Sidebars;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.Plugin;
 | 
			
		||||
 | 
			
		||||
@@ -24,7 +24,6 @@ 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;
 | 
			
		||||
@@ -34,15 +33,13 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
			
		||||
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.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 {
 | 
			
		||||
  GameState m_state;
 | 
			
		||||
 | 
			
		||||
  Arena m_arena;
 | 
			
		||||
  Game m_game;
 | 
			
		||||
  Stage m_stage;
 | 
			
		||||
@@ -71,6 +68,7 @@ public class GameRunner {
 | 
			
		||||
  TickTask m_bombCrackleTask;
 | 
			
		||||
 | 
			
		||||
  BossBars m_bars;
 | 
			
		||||
  Sidebars m_sidebars;
 | 
			
		||||
 | 
			
		||||
  World m_world;
 | 
			
		||||
 | 
			
		||||
@@ -106,13 +104,19 @@ public class GameRunner {
 | 
			
		||||
    m_waves = new WaveManager(m_game);
 | 
			
		||||
    m_players = new PlayerManager();
 | 
			
		||||
    m_bombFuse = new BombFuse();
 | 
			
		||||
    m_bars = new BossBars(this, m_game, m_waves, m_players, m_bombFuse, m_mobs);
 | 
			
		||||
 | 
			
		||||
    m_state = new GameState(this, m_waves, m_game, m_mobs, m_bombFuse, m_players);
 | 
			
		||||
 | 
			
		||||
    m_bars = new BossBars(m_state);
 | 
			
		||||
    m_sidebars = new Sidebars(m_state, m_plugin.getServer().getScoreboardManager());
 | 
			
		||||
 | 
			
		||||
    m_log = m_plugin.getLogger();
 | 
			
		||||
 | 
			
		||||
    m_fuseTask = new TickTask(m_plugin, () -> {
 | 
			
		||||
      if (m_bombFuse.isLit()) {
 | 
			
		||||
        m_bombFuse.tickDecay();
 | 
			
		||||
        m_bars.update();
 | 
			
		||||
        m_sidebars.update();
 | 
			
		||||
      }
 | 
			
		||||
    }, 80);
 | 
			
		||||
 | 
			
		||||
@@ -128,6 +132,7 @@ public class GameRunner {
 | 
			
		||||
        m_warmupCountdown--;
 | 
			
		||||
        m_bars.setCountdownProgress((double)m_warmupCountdown / 10.0);
 | 
			
		||||
        m_bars.update();
 | 
			
		||||
        m_sidebars.update();
 | 
			
		||||
      }
 | 
			
		||||
    }, 20);
 | 
			
		||||
 | 
			
		||||
@@ -147,6 +152,7 @@ public class GameRunner {
 | 
			
		||||
        m_gameEndCountdown--;
 | 
			
		||||
        m_bars.setCountdownProgress((double)m_gameEndCountdown / 60.0);
 | 
			
		||||
        m_bars.update();
 | 
			
		||||
        m_sidebars.update();
 | 
			
		||||
      }
 | 
			
		||||
    }, 20);
 | 
			
		||||
 | 
			
		||||
@@ -159,6 +165,8 @@ public class GameRunner {
 | 
			
		||||
      Location targetLoc = getLocation(m_arena.bombTarget());
 | 
			
		||||
      m_world.playSound(targetLoc, Sound.BLOCK_CAMPFIRE_CRACKLE, SoundCategory.NEUTRAL, 1.0f, 1.0f);
 | 
			
		||||
    }, 35);
 | 
			
		||||
 | 
			
		||||
    validateGameRules();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int m_warmupCountdown = 0;
 | 
			
		||||
@@ -177,6 +185,7 @@ public class GameRunner {
 | 
			
		||||
      m_bombFuse.tickLit();
 | 
			
		||||
      m_world.playSound(getLocation(m_arena.bombTarget()), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1.5f, 0.9f);
 | 
			
		||||
      m_bars.update();
 | 
			
		||||
      m_sidebars.update();
 | 
			
		||||
      if (m_bombFuse.isExploded()) {
 | 
			
		||||
        m_world.strikeLightningEffect(getLocation(m_arena.bombTarget()));
 | 
			
		||||
        m_world.playSound(getLocation(m_arena.bombTarget()), Sound.ENTITY_GENERIC_EXPLODE, SoundCategory.NEUTRAL, 1.3f, 1.0f);
 | 
			
		||||
@@ -269,6 +278,7 @@ public class GameRunner {
 | 
			
		||||
      m_players.setReady(p, isReady);
 | 
			
		||||
    }
 | 
			
		||||
    m_bars.update();
 | 
			
		||||
    m_sidebars.update();
 | 
			
		||||
    if (m_players.isEveryoneReady()) {
 | 
			
		||||
      requestTransition(Stage.Countdown);
 | 
			
		||||
    }
 | 
			
		||||
@@ -314,6 +324,7 @@ public class GameRunner {
 | 
			
		||||
    Spawner spawner = new GameSpawner(m_world, m_arena, m_mobs);
 | 
			
		||||
    m_waves.currentWave().spawnBatch(spawner, m_waves.currentBatchNum());
 | 
			
		||||
    m_bars.update();
 | 
			
		||||
    m_sidebars.update();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void handlePlayerDeath(Player player) {
 | 
			
		||||
@@ -345,6 +356,7 @@ public class GameRunner {
 | 
			
		||||
        m_world.dropItem(entity.getLocation(), coins);
 | 
			
		||||
      }
 | 
			
		||||
      m_bars.update();
 | 
			
		||||
      m_sidebars.update();
 | 
			
		||||
      if (m_mobs.remainingMobs() <= 3) {
 | 
			
		||||
        m_log.info("Starting next batch!");
 | 
			
		||||
        if (m_waves.isLastBatch()) {
 | 
			
		||||
@@ -411,6 +423,7 @@ public class GameRunner {
 | 
			
		||||
      m_log.info("Game transition: " + m_stage + " -> " + stage);
 | 
			
		||||
      m_stage = stage;
 | 
			
		||||
      m_bars.update();
 | 
			
		||||
      m_sidebars.update();
 | 
			
		||||
      for(Player p : m_players.getPlayers()) {
 | 
			
		||||
        sendStageTitle(p);
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										43
									
								
								src/main/java/gg/malloc/defense/engine/GameState.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/main/java/gg/malloc/defense/engine/GameState.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,43 @@
 | 
			
		||||
package gg.malloc.defense.engine;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.model.Game;
 | 
			
		||||
import gg.malloc.defense.model.Progress;
 | 
			
		||||
import gg.malloc.defense.model.State;
 | 
			
		||||
 | 
			
		||||
public class GameState implements State {
 | 
			
		||||
  GameRunner m_runner;
 | 
			
		||||
  WaveManager m_waves;
 | 
			
		||||
  Game m_game;
 | 
			
		||||
  MobManager m_mobs;
 | 
			
		||||
  BombFuse m_fuse;
 | 
			
		||||
  PlayerManager m_players;
 | 
			
		||||
 | 
			
		||||
  public GameState(GameRunner runner, WaveManager waves, Game game, MobManager mobs, BombFuse fuse, PlayerManager players) {
 | 
			
		||||
    m_runner = runner;
 | 
			
		||||
    m_waves = waves;
 | 
			
		||||
    m_game = game;
 | 
			
		||||
    m_mobs = mobs;
 | 
			
		||||
    m_fuse = fuse;
 | 
			
		||||
    m_players = players;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public GameRunner.Stage getStage() {
 | 
			
		||||
    return m_runner.getStage();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Progress fuseProgress() {
 | 
			
		||||
    return m_fuse;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Progress waveProgress() {
 | 
			
		||||
    return m_waves.asProgress();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Progress mobProgress() {
 | 
			
		||||
    return m_mobs;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public Progress playerReadyProgress() {
 | 
			
		||||
    return m_players.readyProgress();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -17,11 +17,12 @@ import org.bukkit.event.entity.EntityTargetEvent;
 | 
			
		||||
import org.bukkit.inventory.EntityEquipment;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.model.Game;
 | 
			
		||||
import gg.malloc.defense.model.Progress;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.ui.BombCarrier;
 | 
			
		||||
import gg.malloc.defense.ui.Items;
 | 
			
		||||
 | 
			
		||||
public class MobManager {
 | 
			
		||||
public class MobManager implements Progress {
 | 
			
		||||
  LivingEntity m_bombTarget;
 | 
			
		||||
  HashSet<Mob> m_livingMobs = new HashSet<>();
 | 
			
		||||
  HashSet<Mob> m_bombCarriers = new HashSet<>();
 | 
			
		||||
@@ -33,6 +34,16 @@ public class MobManager {
 | 
			
		||||
    PlayerHarassment
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int value() {
 | 
			
		||||
    return m_killedMobs;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public int maximum() {
 | 
			
		||||
    return m_createdMobs;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int m_createdMobs = 0;
 | 
			
		||||
  int m_killedMobs = 0;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,10 @@ import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.GameMode;
 | 
			
		||||
import org.bukkit.attribute.Attribute;
 | 
			
		||||
import org.bukkit.event.player.PlayerTeleportEvent;
 | 
			
		||||
import org.bukkit.scoreboard.ScoreboardManager;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.ui.Sidebar;
 | 
			
		||||
import gg.malloc.defense.model.Progress;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
@@ -90,14 +94,14 @@ public class PlayerManager {
 | 
			
		||||
    m_playerReadyStates.put(player, ready);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public double readyProgress() {
 | 
			
		||||
  public Progress readyProgress() {
 | 
			
		||||
    int readyNum = 0;
 | 
			
		||||
    for(boolean b : m_playerReadyStates.values()) {
 | 
			
		||||
      if (b) {
 | 
			
		||||
        readyNum += 1;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return (double)readyNum / (double)m_playerReadyStates.size();
 | 
			
		||||
    return new StaticProgress(readyNum, m_playerReadyStates.size());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isEveryoneReady() {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								src/main/java/gg/malloc/defense/engine/StaticProgress.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/main/java/gg/malloc/defense/engine/StaticProgress.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
package gg.malloc.defense.engine;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.model.Progress;
 | 
			
		||||
 | 
			
		||||
public class StaticProgress implements Progress {
 | 
			
		||||
  int m_value;
 | 
			
		||||
  int m_maximum;
 | 
			
		||||
 | 
			
		||||
  public StaticProgress(int value, int maximum) {
 | 
			
		||||
    m_value = value;
 | 
			
		||||
    m_maximum = maximum;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public int value() {
 | 
			
		||||
    return m_value;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public int maximum() {
 | 
			
		||||
    return m_maximum;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -2,6 +2,7 @@ package gg.malloc.defense.engine;
 | 
			
		||||
 | 
			
		||||
import gg.malloc.defense.model.Wave;
 | 
			
		||||
import gg.malloc.defense.model.Game;
 | 
			
		||||
import gg.malloc.defense.model.Progress;
 | 
			
		||||
 | 
			
		||||
public class WaveManager {
 | 
			
		||||
  int m_currentWaveNum = 0;
 | 
			
		||||
@@ -9,6 +10,10 @@ public class WaveManager {
 | 
			
		||||
  Wave m_currentWave = null;
 | 
			
		||||
  Game m_game;
 | 
			
		||||
 | 
			
		||||
  public Progress asProgress() {
 | 
			
		||||
    return new StaticProgress(m_currentWaveNum, m_game.getWaveCount());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public WaveManager(Game game) {
 | 
			
		||||
    m_game = game;
 | 
			
		||||
  }
 | 
			
		||||
@@ -31,10 +36,6 @@ public class WaveManager {
 | 
			
		||||
    return m_currentBatch;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public double progress() {
 | 
			
		||||
    return (double)m_currentWaveNum / (double)m_game.getWaveCount();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public boolean isLastWave() {
 | 
			
		||||
    return m_currentWaveNum >= m_game.getWaveCount();
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user