Merge branches 'pregametutorial' and 'william-gladiators' of ssh://184.154.0.242:25565/min/mineplex into william-gladiators

This commit is contained in:
William Burns 2015-12-07 23:20:21 +00:00
commit 43192317ad
9 changed files with 790 additions and 0 deletions

View File

@ -72,6 +72,7 @@ import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
@ -301,6 +302,8 @@ public abstract class Game implements Listener
public boolean DeadBodiesQuit = true;
public boolean DeadBodiesDeath = true;
public int DeadBodiesExpire = -1;
public boolean EnableTutorials = false;
public boolean FixSpawnFacing = true;
@ -1723,4 +1726,6 @@ public abstract class Game implements Listener
}
}
}
public void addTutorials(){}
}

View File

@ -14,6 +14,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
@ -58,6 +59,8 @@ public class GameTeam
private String _name;
private String _displayName;
private ChatColor _color;
private GameTutorial _tutorial;
private HashMap<Player, PlayerState> _players = new HashMap<Player, PlayerState>();
@ -444,4 +447,15 @@ public class GameTeam
return _places;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
public void setTutorial(GameTutorial tutorial)
{
_tutorial = tutorial;
}
}

View File

@ -0,0 +1,252 @@
package nautilus.game.arcade.gametutorial;
import java.util.HashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.gametutorial.events.GameTutorialEndEvent;
import nautilus.game.arcade.gametutorial.events.GameTutorialPhaseEvent;
import nautilus.game.arcade.gametutorial.events.GameTutorialStartEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public abstract class GameTutorial
{
public ArcadeManager Manager;
private TutorialPhase[] _phases;
private GameTeam _team;
private HashMap<Player, Location> _players;
private TutorialPhase _currentPhase;
private boolean _hasEnded;
private boolean _hasStarted;
private int _tick;
private long _started;
public boolean SetTutorialPositions = true;
public boolean TeleportOnEnd = true;
public boolean RunTasksSync = true;
public boolean PlayTutorialSounds = false;
public boolean ShowPrepareTimer = false;
public long TimeBetweenPhase = 0;
public long StartAfterTutorial = 5000;
public GameTutorial(ArcadeManager manager, TutorialPhase[] phases)
{
Manager = manager;
_phases = phases;
_players = new HashMap<>();
}
final public void start()
{
_hasStarted = true;
_tick = 0;
for(TutorialPhase phase : _phases)
phase.setTutorial(this);
//Manager.GetGame().PrepareTime = 60000;
Manager.GetChat().Silence(60000, false);
_started = System.currentTimeMillis();
Manager.getPluginManager().callEvent(new GameTutorialStartEvent(this));
onStart();
preparePlayers();
_currentPhase = getNextPhase();
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
nextPhase(true);
}
}, 40);
_currentPhase.teleport();
}
protected void nextPhase(boolean phaseOne)
{
TutorialPhase from = _currentPhase;
if(!phaseOne)
_currentPhase = getNextPhase();
if(_currentPhase == null)
{
onEnd();
_hasEnded = true;
endTutorial();
final GameTutorial tutorial = this;
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
Manager.getPluginManager().callEvent(new GameTutorialEndEvent(tutorial));
}
}, 5);
}
else
{
Manager.GetChat().Silence(70000, false);
onPhaseChange(_currentPhase);
Manager.getPluginManager().callEvent(new GameTutorialPhaseEvent(this, from, _currentPhase));
_currentPhase.start(phaseOne);
}
}
public void setTeam(GameTeam team)
{
_team = team;
}
private void endTutorial()
{
for(final Player player : _players.keySet())
{
//VisibilityManager.Instance.setVisibility(player, true, UtilServer.getPlayers());
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
for(Player player : Manager.GetGame().GetPlayers(true))
{
for(Player other : Manager.GetGame().GetPlayers(true))
{
player.showPlayer(other);
}
}
player.setAllowFlight(false);
player.setFlying(false);
}
}, 5);
if(TeleportOnEnd)
{
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
_team.SpawnTeleport();
}
}, 5);
}
}
Manager.GetChat().Silence(StartAfterTutorial, false);
Manager.GetGame().PrepareTime = (System.currentTimeMillis() - Manager.GetGame().GetStateTime()) + StartAfterTutorial;
}
protected TutorialPhase getNextPhase()
{
for(TutorialPhase phase : _phases)
{
if(_currentPhase == null && phase.ID() == 1)
{
return phase;
}
else if(_currentPhase != null && _currentPhase.ID() + 1 == phase.ID())
{
return phase;
}
}
return null;
}
private void preparePlayers()
{
for(Player player : UtilServer.getPlayers())
{
int i = 0;
if(Manager.GetGame().GetTeam(player) == _team)
{
_players.put(player, Manager.GetGame().GetTeam(player).GetSpawns().get(i));
player.setAllowFlight(true);
player.setFlying(true);
// VisibilityManager.Instance.setVisibility(player, false, UtilServer.getPlayers());
i++;
}
}
}
public TutorialPhase getPhase(int index)
{
for(TutorialPhase phase : _phases)
{
if(phase.ID() == index)
return phase;
}
return null;
}
public boolean hasEnded()
{
return _hasEnded;
}
public boolean hasStarted()
{
return _hasStarted;
}
public HashMap<Player, Location> getPlayers()
{
return _players;
}
public GameTeam getTeam()
{
return _team;
}
public void onTick(int tick){}
public void onStart(){}
public void onPhaseChange(TutorialPhase phase){}
public void onEnd(){}
public int tick()
{
if(!_hasEnded && hasStarted())
{
for(Player player : UtilServer.getPlayers())
{
for(Player other : _players.keySet())
{
player.hidePlayer(other);
}
}
}
_tick++;
return _tick;
}
public TutorialPhase[] getPhases()
{
return _phases;
}
public long getTutorialStart()
{
return _started;
}
public long getRunning()
{
return System.currentTimeMillis() - _started;
}
public long getPhaseTime()
{
return _currentPhase.getPhaseTime();
}
}

View File

@ -0,0 +1,237 @@
package nautilus.game.arcade.gametutorial;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilTextMiddle;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public abstract class TutorialPhase
{
public abstract int ID();
private GameTutorial _tutorial;
private TutorialText[] _text;
private Location _location;
private Location _target;
private boolean _hasEnded;
private long _started;
private TutorialText _currentText;
public TutorialPhase(TutorialText[] text)
{
_text = text;
}
final public void start(boolean phaseOne)
{
_hasEnded = false;
_started = System.currentTimeMillis();
onStart();
if(!phaseOne)
{
teleport();
}
displayText();
}
final public void teleport()
{
if(!getTutorial().SetTutorialPositions)
return;
if(_location != null && _target != null)
{
prepareLocations();
updatePlayers();
}
}
private void prepareLocations()
{
Vector vector = new Vector(_target.getBlockX() - _location.getBlockX(), _target.getBlockY() - _location.getBlockY(), _target.getBlockZ() - _location.getBlockZ());
float pitch = UtilAlg.GetPitch(vector);
float yaw = UtilAlg.GetYaw(vector);
_location.setPitch(pitch);
_location.setYaw(yaw);
}
private void updatePlayers()
{
new Thread(new Runnable()
{
@Override
public void run()
{
while(!_hasEnded && !getTutorial().hasEnded())
{
_tutorial.Manager.runSync(new Runnable()
{
@Override
public void run()
{
if(!_hasEnded && !getTutorial().hasEnded())
{
for(Player player : _tutorial.getPlayers().keySet())
{
player.setAllowFlight(true);
player.setFlying(true);
player.teleport(_location);
}
}
}
});
try
{
Thread.sleep(50);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}).start();
}
public void displayText()
{
new Thread(new Runnable()
{
@Override
public void run()
{
while(true)
{
TutorialText text = getNextMessage();
if(text == null)
{
_tutorial.Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
_hasEnded = true;
onEnd();
_tutorial.nextPhase(false);
}
}, getTutorial().TimeBetweenPhase);
break;
}
else
{
Player[] players = new Player[_tutorial.getPlayers().keySet().size()];
int i = 0;
for(Player player : _tutorial.getPlayers().keySet())
{
if(_tutorial.PlayTutorialSounds)
{
if(text.getSound() != null)
player.playSound(player.getLocation(), text.getSound(), 2f, 2f);
}
players[i] = player;
i++;
}
displayMessage(text);
UtilTextMiddle.display("", text.getText(), 0, text.getStayTime(), 0, players);
try
{
Thread.sleep(text.getStayTime() * 50);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}).start();
}
private void displayMessage(final TutorialText text)
{
if(_tutorial.RunTasksSync)
{
_tutorial.Manager.runSync(new Runnable()
{
@Override
public void run()
{
onMessageDisplay(text);
}
});
}
else
{
onMessageDisplay(text);
}
}
protected TutorialText getNextMessage()
{
for(TutorialText text : _text)
{
if(_currentText == null && text.ID() == 1)
{
_currentText = text;
return text;
}
else if(_currentText != null && _currentText.ID() + 1 == text.ID())
{
_currentText = text;
return text;
}
}
return null;
}
public TutorialText[] getText()
{
return _text;
}
public Location getLocation()
{
return _location;
}
public void setTutorial(GameTutorial tutorial)
{
_tutorial = tutorial;
}
public void setLocation(Location location)
{
_location = location;
}
public void setTarget(Location target)
{
_target = target;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
public Location getTarget()
{
return _target;
}
public long getPhaseTime()
{
return _started;
}
public void onStart(){}
public void onMessageDisplay(TutorialText text){}
public void onEnd(){}
}

View File

@ -0,0 +1,62 @@
package nautilus.game.arcade.gametutorial;
import org.bukkit.Sound;
public class TutorialText
{
private String _text;
private int _stayTime;
private int _id;
private Sound _sound;
public TutorialText(String text, int stayTime, int id, Sound sound)
{
_text = text;
_id = id;
_stayTime = stayTime;
_sound = sound;
}
public TutorialText(String text, int id)
{
this(text, (int) (Math.round(1.5 * text.length()) + 25), id, Sound.NOTE_PLING);
}
public TutorialText(String text, int id, Sound sound)
{
this(text, (int) (Math.round(1.5 * text.length()) + 25), id, sound);
}
public TutorialText(String text, int stayTime, int id)
{
this(text, stayTime, id, Sound.NOTE_PLING);
}
public String getText()
{
return _text;
}
public int ID()
{
return _id;
}
public Sound getSound()
{
return _sound;
}
public int getStayTime()
{
return _stayTime;
}
public void setText(String text)
{
_text = text;
}
}

View File

@ -0,0 +1,32 @@
package nautilus.game.arcade.gametutorial.events;
import nautilus.game.arcade.gametutorial.GameTutorial;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GameTutorialEndEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private GameTutorial _tutorial;
public GameTutorialEndEvent(GameTutorial tutorial)
{
_tutorial = tutorial;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
}

View File

@ -0,0 +1,49 @@
package nautilus.game.arcade.gametutorial.events;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.gametutorial.TutorialPhase;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GameTutorialPhaseEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private GameTutorial _tutorial;
private TutorialPhase _from;
private TutorialPhase _to;
public GameTutorialPhaseEvent(GameTutorial tutorial, TutorialPhase from, TutorialPhase to)
{
_tutorial = tutorial;
_from = from;
_to = to;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
public TutorialPhase getFrom()
{
return _from;
}
public TutorialPhase getTo()
{
return _to;
}
}

View File

@ -0,0 +1,32 @@
package nautilus.game.arcade.gametutorial.events;
import nautilus.game.arcade.gametutorial.GameTutorial;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GameTutorialStartEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private GameTutorial _tutorial;
public GameTutorialStartEvent(GameTutorial tutorial)
{
_tutorial = tutorial;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
}

View File

@ -34,6 +34,9 @@ import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.uhc.UHC;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.gametutorial.TutorialPhase;
import nautilus.game.arcade.gametutorial.TutorialText;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -186,6 +189,75 @@ public class GameManager implements Listener
}
}
public boolean isInTutorial(boolean checkForTimer)
{
if (Manager.GetGame() == null || Manager.GetGame().GetState() != GameState.Prepare)
return false;
Game game = Manager.GetGame();
boolean tutorialSet = false;
for(GameTeam team : game.GetTeamList())
{
if(team.getTutorial() != null)
tutorialSet = true;
}
if(!tutorialSet)
{
game.addTutorials();
}
boolean finished = true;
if(game.EnableTutorials)
{
for(Player player : UtilServer.getPlayers())
{
if(player.getWorld() == Manager.GetLobby().GetSpawn().getWorld())
return true;
}
long prepTime = 0;
for(GameTeam team : game.GetTeamList())
{
long timeUsage = 0;
if(team.getTutorial() != null)
{
if(!team.getTutorial().hasStarted())
{
team.getTutorial().setTeam(team);
team.getTutorial().start();
timeUsage = team.getTutorial().StartAfterTutorial;
timeUsage = timeUsage + (team.getTutorial().TimeBetweenPhase * team.getTutorial().getPhases().length);
for(TutorialPhase phase : team.getTutorial().getPhases())
{
for(TutorialText text : phase.getText())
{
timeUsage = timeUsage + (text.getStayTime() * 50);
}
}
}
if(!team.getTutorial().hasEnded())
{
finished = false;
}
if(checkForTimer)
{
if(team.getTutorial().ShowPrepareTimer)
finished = false;
else
finished = true;
}
}
if(prepTime <= timeUsage)
prepTime = timeUsage;
}
if(prepTime > 0)
Manager.GetGame().PrepareTime = prepTime;
if(!finished)
return true;
}
return false;
}
@EventHandler
public void DisplayPrepareTime(UpdateEvent event)
{
@ -196,6 +268,9 @@ public class GameManager implements Listener
return;
Game game = Manager.GetGame();
if(isInTutorial(true))
return;
double percentage = (double) (System.currentTimeMillis() - game.GetStateTime()) / game.PrepareTime;
@ -203,6 +278,35 @@ public class GameManager implements Listener
UtilTextBottom.displayProgress("Game Start", percentage,
UtilTime.MakeStr(Math.max(0, game.PrepareTime - (System.currentTimeMillis() - game.GetStateTime()))), player);
}
@EventHandler
public void updateGameTutorials(UpdateEvent event)
{
if(event.getType() != UpdateType.TICK)
return;
Game game = Manager.GetGame();
if(game == null)
return;
if(game.GetState() != GameState.Prepare)
return;
if(game.EnableTutorials)
{
for(GameTeam team : game.GetTeamList())
{
if(team.getTutorial() != null)
{
if(!team.getTutorial().hasEnded() && team.getTutorial().hasStarted())
{
team.getTutorial().onTick(team.getTutorial().tick());
}
}
}
}
}
@EventHandler
public void StateUpdate(UpdateEvent event)
@ -250,6 +354,9 @@ public class GameManager implements Listener
}
else if (game.GetState() == GameState.Prepare)
{
if(isInTutorial(false))
return;
if (game.CanStartPrepareCountdown())
{
if (UtilTime.elapsed(game.GetStateTime(), game.PrepareTime))