public void Interval( SchedulerTask task ) { //check to stop Interval if ( _world.gameMode != GameMode.ZombieSurvival || _world == null ) { _world = null; task.Stop(); return; } if ( !_started ) { if ( startTime != null && ( DateTime.Now - startTime ).TotalMinutes > 1 ) { /*if (_world.Players.Length < 3){ _world.Players.Message("&WThe game failed to start: 2 or more players need to be in the world"); Stop(null); return; }*/ ShufflePlayerPositions(); _started = true; RandomPick(); lastChecked = DateTime.Now; return; } } //calculate humans _humanCount = _world.Players.Where( p => p.iName != _zomb ).Count(); //check if zombies have won already if ( _started ) { if ( _humanCount == 1 && _world.Players.Count() == 1 ) { _world.Players.Message( "&WThe Zombies have failed to infect everyone... &9HUMANS WIN!" ); Stop( null ); return; } if ( _humanCount == 0 ) { _world.Players.Message( "&WThe Humans have failed to survive... &9ZOMBIES WIN!" ); Stop( null ); return; } } //check if 5mins is up and all zombies have failed if ( _started && startTime != null && ( DateTime.Now - startTime ).TotalMinutes > 6 ) { _world.Players.Message( "&WThe Zombies have failed to infect everyone... &9HUMANS WIN!" ); Stop( null ); return; } //if no one has won, notify players of their status every 31s if ( lastChecked != null && ( DateTime.Now - lastChecked ).TotalSeconds > 30 ) { _world.Players.Message( "&WThere are {0} humans", _humanCount.ToString() ); foreach ( Player p in _world.Players ) { if ( p.iName == _zomb ) p.Message( "&8You are " + _zomb ); else p.Message( "&8You are a Human" ); } lastChecked = DateTime.Now; } }
public void Interval(SchedulerTask task) { //check to stop Interval if (_world == null) { task.Stop(); return; } if (_world.gameMode != GameMode.PropHunt) { _world = null; task.Stop(); return; } if ((DateTime.Now - LastChecked).TotalSeconds > 29.9 && TimeLeft < TimeLimit) { _world.Players.Message("&WThere are currently {0} block(s) and {1} seeker(s) left on {2}.", _world.Players.Count() - _world.Players.Count(player => player.IsPropHuntSeeker), _world.Players.Count(player => player.IsPropHuntSeeker), _world.ClassyName); _world.Players.Message("&WThere are {0} seconds left.", TimeLeft); LastChecked = DateTime.Now; } CheckScore(); }
void StopTasks() { lock ( taskLock ) { if (updateTask != null) { updateTask.Stop(); updateTask = null; } if (saveTask != null) { saveTask.Stop(); saveTask = null; } } }
public static void RevertGame() //Reset game bools/stats and stop timers { _world.gameMode = GameMode.NULL; task_.Stop(); isOn = false; instance = null; _world = null; foreach (Player p in ZombiePlayers) { p.iName = p.Name; p.Model = "steve"; p.IsInfected = false; p.Info.DisplayedName = p.Oldname; p.IsPlayingZombieSurvival = false; p.Message("You are no longer playing zombie survival."); } }
public static void RevertGame() //Reset game bools/stats and stop timers { task_.Stop(); world_.gameMode = GameMode.NULL; isOn = false; instance = null; started = false; if (world_.gunPhysics) { world_.DisableGunPhysics(Player.Console, true); } world_ = null; redScore = 0; blueScore = 0; redTeamCount = 0; blueTeamCount = 0; RevertNames(); }
internal void StopTasks() { lock ( taskLock ) { if (updateTask != null) { updateTask.Stop(); updateTask = null; } if (saveTask != null) { saveTask.Stop(); saveTask = null; } if (backupTask != null) { backupTask.Stop(); backupTask = null; } } }
//Voting public void TakeVote() { //Actual voting if (!_votingRestarting) { World[] voteWorlds = PropHuntWorlds.OrderBy(x => RandWorld.Next()) .Take(3) .ToArray(); World1 = voteWorlds[0]; World2 = voteWorlds[1]; World3 = voteWorlds[2]; //Stop the game before voting _task.Stop(); _checkIdlesTask.Stop(); Player.Moving -= PlayerMovingHandler; if (PropHuntPlayers != null) { lock (PropHuntPlayers.ToList()) { foreach (Player p in PropHuntPlayers.ToList()) { RevertPlayer(p); } } } } if (_votingRestarting) { _votingRestarting = false; } Server.Players.Message("&S--------------------------------------------------------------"); Server.Players.Message("&SVote for the next map!"); Server.Players.Message("&S/Vote &c1&S for {0}&S, &c2&S for {1}&S, and &c3&S for {2}", World1.ClassyName, World2.ClassyName, World3.ClassyName); Server.Players.Message("&S--------------------------------------------------------------"); Scheduler.NewTask(task => VoteCheck()) .RunOnce(TimeSpan.FromSeconds(60)); VoteIsOn = true; }
void Stop(bool aborted) { try { if (!Directory.Exists("./Timers")) { Directory.CreateDirectory("./Timers"); } if (File.Exists("./Timers/" + TimerFilename(this))) { File.Delete("./Timers/" + TimerFilename(this)); } } catch (Exception ex) { Player.Console.Message("Timer Deleter Has Crashed: {0}", ex); } Aborted = aborted; IsRunning = false; task.Stop(); RemoveTimerFromList(this); RaiseStoppedEvent(this); }
public static void Stop(Player p) //for stopping the game early { //unhook moving event Player.Moving -= PlayerMoving; world_.Hax = true; foreach (Player pl in world_.Players) { pl.JoinWorld(world_, WorldChangeReason.Rejoin); } if (p != null && world_ != null) { world_.Players.Message("{0}&S stopped the game of CTF early on world {1}", p.ClassyName, world_.ClassyName); } RevertGame(); if (!delayTask.IsStopped)//if stop is called when the delayTask is still going, stop the delayTask { delayTask.Stop(); } return; }
public static void Stop(Player p) //for stopping the game early { world_.Hax = true; foreach (Player pl in world_.Players) { pl.JoinWorld(world_, WorldChangeReason.Rejoin); } if (p != null && world_ != null) { world_.Players.Message("{0}&S stopped the game of Team Deathmatch early on world {1}", p.ClassyName, world_.ClassyName); } if (world_.Players.Count() > 1) { DisplayScoreBoard(); } RevertGame(); if (!delayTask.IsStopped)//if stop is called when the delayTask is still going, stop the delayTask { delayTask.Stop(); } return; }
public static void Interval(SchedulerTask task) { //check to stop Interval if (world_ == null) { task.Stop(); return; } if (world_.gameMode != GameMode.TeamDeathMatch) { task.Stop(); world_ = null; return; } //remove announcement after 5 seconds if ((DateTime.Now - announced).TotalSeconds >= 5) { foreach (Player p in world_.Players) { if (p.usesCPE) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcement, simply send a color code and call it a day } } } if (!started) { if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { world_.Players.Message("&WTeam DeathMatch&s requires at least 2 people to play."); return; } if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay) { foreach (Player p in world_.Players) { if (!manualTeams) { assignTeams(p); //assigns teams (who knew?) } if (p.Info.isOnRedTeam) { p.TeleportTo(TeamDeathMatch.redSpawn); } //teleport players to the team spawn if (p.Info.isOnBlueTeam) { p.TeleportTo(TeamDeathMatch.blueSpawn); } if (!p.GunMode) { p.GunMode = true; //turns on gunMode automatically if not already on GunGlassTimer timer = new GunGlassTimer(p); timer.Start(); } if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden) { p.Info.IsHidden = false; Player.RaisePlayerHideChangedEvent(p); } //send an announcement p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!")); if (p.usesCPE) { //set player's health p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); //set game score p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: 0,&1 Blue&f: 0")); } } started = true; //the game has officially started isOn = true; if (!world_.gunPhysics) { world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on } lastChecked = DateTime.Now; //used for intervals announced = DateTime.Now; //set when the announcement was launched return; } } //check if one of the teams have won if (redScore >= scoreLimit || blueScore >= scoreLimit) { Stop(null); return; } if (blueScore == scoreLimit && redScore == scoreLimit) //if they somehow manage to tie which I am pretty sure is impossible { world_.Players.Message("The teams tied at {0}!", redScore); Stop(null); return; } //check if time is up if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime)) { if (redScore != blueScore) { Stop(null); return; } if (redScore == blueScore) { world_.Players.Message("&fThe teams tied {0} to {1}!", blueScore, redScore); Stop(null); return; } if (world_.Players.Count() <= 1) { Stop(null); return; } } if (started && (DateTime.Now - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left { int redCount = world_.Players.Where(p => p.Info.isOnRedTeam).ToArray().Count(); int blueCount = world_.Players.Where(p => p.Info.isOnBlueTeam).ToArray().Count(); if (blueCount < 1 || redCount < 1) { if (blueTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!"); } Stop(null); return; } if (redTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!"); } Stop(null); return; } else { Stop(null); return; } } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds)); //Keep the players updated about the score if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 29.8 && timeLeft <= timeLimit) { if (redScore > blueScore) { world_.Players.Message("&fThe &cRed Team&f is winning {0} to {1}.", redScore, blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore < blueScore) { world_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", blueScore, redScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore == blueScore) { world_.Players.Message("&fThe teams are tied at {0}!", blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } lastChecked = DateTime.Now; } if (timeLeft == 10) { world_.Players.Message("&WOnly 10 seconds left!"); } }
public static void Interval(SchedulerTask task) { //check to stop Interval if (world_ == null) { task.Stop(); return; } if (world_.gameMode != GameMode.FFA) //bug checking { task.Stop(); world_ = null; return; } //remove announcement after 5 seconds if ((DateTime.Now - announced).TotalSeconds >= 5) { foreach (Player p in world_.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcement, simply send a color code and call it a day } } } if (!started)//first time running the interval { if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { world_.Players.Message("&WFFA&s requires at least 2 people to play."); task.Stop(); return; } if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay) { foreach (Player p in world_.Players) { int x = rand.Next(2, world_.Map.Width); int y = rand.Next(2, world_.Map.Length); int z1 = 0; for (int z = world_.Map.Height - 1; z > 0; z--) { if (world_.Map.GetBlock(x, y, z) != Block.Air) { z1 = z + 3; break; } } p.TeleportTo(new Position(x, y, z1 + 2).ToVector3I().ToPlayerCoords()); //teleport players to a random position InitializePlayer(p); if (!p.GunMode) { p.GunMode = true; //turns on gunMode automatically if not already on GunGlassTimer timer = new GunGlassTimer(p); timer.Start(); } if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden) { p.Info.IsHidden = false; Player.RaisePlayerHideChangedEvent(p); } //send an announcement p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!")); //set player health p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); //set leader p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&eCurrent Leader&f: None")); } started = true; //the game has officially started if (!world_.gunPhysics) { world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on } lastChecked = DateTime.Now; //used for intervals announced = DateTime.Now; //set when the announcement was launched return; } } //check if one of the players has won foreach (Player p in world_.Players) { if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= timeDelay && p.Info.gameKillsFFA >= scoreLimit) { Stop(p); return; } } //check if time is up if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime)) { Player winner = GetScoreList()[0]; if (world_.Players.Count() < 2) { Stop(winner); return; } Stop(winner); return; } if (started && (DateTime.Now - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left { if (world_.Players.Count() < 2) { Player[] players = world_.Players; Stop(players[0]); return; } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).ToSeconds())); //Keep the players updated about the score if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 29.9 && timeLeft <= timeLimit) { Player leader = GetScoreList()[0]; //leader is the top of the score list Player secondPlace = GetScoreList()[1]; //second place is - well, second place XD if (isOn() && leader.Info.gameKillsFFA != secondPlace.Info.gameKillsFFA) { world_.Players.Message("{0}&f is winning &c{1} &fto &c{2}", leader.ClassyName, leader.Info.gameKillsFFA, secondPlace.Info.gameKillsFFA); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (leader.Info.gameKillsFFA == secondPlace.Info.gameKillsFFA) { world_.Players.Message("{1}&f and {2}&f are tied at &c{0}!", leader.Info.gameKillsFFA, leader.ClassyName, secondPlace.ClassyName); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } lastChecked = DateTime.Now; } if (timeLeft < 10.1) { world_.Players.Message("&WOnly 10 seconds left!"); } }
public static void Interval(SchedulerTask task) { //check to stop Interval if (TDMworld_.gameMode != GameMode.TeamDeathMatch || TDMworld_ == null) { TDMworld_ = null; task.Stop(); return; } if (!started) { if (TDMworld_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { TDMworld_.Players.Message("&WTeam Death Match&s requires at least 2 people to play."); return; } if (startTime != null && (DateTime.UtcNow - startTime).TotalSeconds > timeDelay) { TDMworld_.Players.Message("&WType &a/Team [red/blue]&w to join a team and begin!"); started = true; //the game has officially started isOn = true; if (!TDMworld_.gunPhysics) { TDMworld_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on } lastChecked = DateTime.UtcNow; //used for intervals return; } //check if one of the teams have won if (redScore >= scoreLimit) { TDMworld_.Players.Message("&fThe &cRed Team&f has won {1} to {0}!", blueScore, redScore); Stop(null); return; } if (blueScore >= scoreLimit) { TDMworld_.Players.Message("&fThe &1Blue Team&f has won {1} to {0}!", redScore, blueScore); Stop(null); return; } if (blueScore == scoreLimit && redScore == scoreLimit) //if they somehow manage to tie which I am pretty sure is impossible { TDMworld_.Players.Message("&fThe teams have tied!"); Stop(null); return; } //check if time is up (delay time + start time) if (started && startTime != null && (DateTime.UtcNow - startTime).TotalSeconds >= (timeDelay + timeLimit)) { if (redScore > blueScore) { TDMworld_.Players.Message("&fThe &cRed Team&f has won {0} to {1}.", redScore, blueScore); Stop(null); return; } if (redScore < blueScore) { TDMworld_.Players.Message("&fThe &1Blue Team&f has won {0} to {1}.", blueScore, redScore); Stop(null); return; } if (redScore == blueScore) { TDMworld_.Players.Message("&fThe teams tied {0} to {1}!", blueScore, redScore); Stop(null); return; } if (TDMworld_.Players.Count() <= 1) { Stop(null); return; } } if (started && (DateTime.UtcNow - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left { int redCount = TDMworld_.Players.Where(p => p.Info.isOnRedTeam).ToArray().Count(); int blueCount = TDMworld_.Players.Where(p => p.Info.isOnBlueTeam).ToArray().Count(); if (blueCount < 1 || redCount < 1) { if (blueTeamCount == 0) { if (TDMworld_.Players.Count() >= 1) { TDMworld_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!"); } Stop(null); return; } if (redTeamCount == 0) { if (TDMworld_.Players.Count() >= 1) { TDMworld_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!"); } Stop(null); return; } else { Stop(null); return; } } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.UtcNow - startTime).TotalSeconds)); //Keep the players updated about the score if (lastChecked != null && (DateTime.UtcNow - lastChecked).TotalSeconds > 29.9 && timeLeft <= timeLimit) { if (redScore > blueScore) { TDMworld_.Players.Message("&fThe &cRed Team&f is winning {0} to {1}.", redScore, blueScore); TDMworld_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore < blueScore) { TDMworld_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", blueScore, redScore); TDMworld_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore == blueScore) { TDMworld_.Players.Message("&fThe teams are tied at {0}!", blueScore); TDMworld_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } lastChecked = DateTime.UtcNow; } if (timeLeft == 10) { TDMworld_.Players.Message("&WOnly 10 seconds left!"); } } }
public void Interval(SchedulerTask task) { //check to stop Interval if (_world.gameMode != GameMode.ZombieSurvival || _world == null) { _world = null; task.Stop(); return; } if (!isOn) { if (_world.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { /*if (!ConfigKey.IsNormal.Enabled()) * { * return; * } * else * { * _world.Players.Message("&WZombie Survival&s requires at least 4 people to play."); * return; * }*/ } if (startTime != null && (DateTime.UtcNow - startTime).TotalSeconds > timeDelay) { foreach (Player p in _world.Players) { int x = rand.Next(2, _world.Map.Width); int y = rand.Next(2, _world.Map.Length); int z1 = 0; for (int z = _world.Map.Height - 1; z > 0; z--) { if (_world.Map.GetBlock(x, y, z) != Block.Air) { z1 = z + 3; break; } } p.TeleportTo(new Position(x, y, z1 + 2).ToVector3I().ToPlayerCoords()); //teleport players to a random position beginGame(p); chooseInfected(); } isOn = true; lastChecked = DateTime.UtcNow; //used for intervals return; } } if (isOn && (DateTime.UtcNow - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left { if (_world.Players.Count(player => player.IsInfected) == _world.Players.Count()) { ZombiesWin(); return; } if (_world.Players.Count(player => player.IsInfected) == 0 && _world.Players.Count() > 0) { HumansWin(); return; } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds)); if (lastChecked != null && (DateTime.UtcNow - lastChecked).TotalSeconds > 29.9 && timeLeft <= timeLimit) { _world.Players.Message("There are currently {0} human(s) and {1} zombie(s) left on {2}", _world.Players.Count() - _world.Players.Count(player => player.IsInfected), _world.Players.Count(player => player.IsInfected), _world.ClassyName); } }
public void Stop() { IsRunning = false; task.Stop(); RemoveTimerFromList(this); }
public static void Interval(SchedulerTask task) { //check to stop Interval if (world_ == null) { task.Stop(); return; } if (world_.gameMode != GameMode.TeamDeathMatch) { task.Stop(); world_ = null; return; } //remove announcement after 5 seconds if ((DateTime.Now - announced).TotalSeconds >= 5) { foreach (Player p in world_.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcement, simply send a color code and call it a day } } } if (!started) { if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { world_.Players.Message("&WTeam DeathMatch&s requires at least 2 people to play."); return; } if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay) { foreach (Player p in world_.Players) { if (!manualTeams) { assignTeams(p); //assigns teams (who knew?) } if (p.Info.isOnRedTeam) { p.TeleportTo(TeamDeathMatch.redSpawn); } //teleport players to the team spawn if (p.Info.isOnBlueTeam) { p.TeleportTo(TeamDeathMatch.blueSpawn); } if (!p.GunMode) { p.GunMode = true; //turns on gunMode automatically if not already on GunGlassTimer timer = new GunGlassTimer(p); timer.Start(); } if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden) { p.Info.IsHidden = false; Player.RaisePlayerHideChangedEvent(p); } //send an announcement p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!")); if (p.ClassiCube && Heartbeat.ClassiCube()) { //set player's health p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); //set game score p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: 0,&1 Blue&f: 0")); } } started = true; //the game has officially started isOn = true; if (!world_.gunPhysics) { world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on } lastChecked = DateTime.Now; //used for intervals announced = DateTime.Now; //set when the announcement was launched return; } } //check if one of the teams have won if (redScore >= scoreLimit || blueScore >= scoreLimit) { Stop(null); return; } if (blueScore == scoreLimit && redScore == scoreLimit) //if they somehow manage to tie which I am pretty sure is impossible { world_.Players.Message("The teams tied at {0}!", redScore); Stop(null); return; } //check if time is up if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime)) { if (redScore != blueScore) { Stop(null); return; } if (redScore == blueScore) { world_.Players.Message("&fThe teams tied {0} to {1}!", blueScore, redScore); Stop(null); return; } if (world_.Players.Count() <= 1) { Stop(null); return; } } if (started && (DateTime.Now - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left { int redCount = world_.Players.Where(p => p.Info.isOnRedTeam).ToArray().Count(); int blueCount = world_.Players.Where(p => p.Info.isOnBlueTeam).ToArray().Count(); if (blueCount < 1 || redCount < 1) { if (blueTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!"); } Stop(null); return; } if (redTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!"); } Stop(null); return; } else { Stop(null); return; } } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds)); //Keep the players updated about the score if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 29.8 && timeLeft <= timeLimit) { if (redScore > blueScore) { world_.Players.Message("&fThe &cRed Team&f is winning {0} to {1}.", redScore, blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore < blueScore) { world_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", blueScore, redScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore == blueScore) { world_.Players.Message("&fThe teams are tied at {0}!", blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } lastChecked = DateTime.Now; } if (timeLeft == 10) { world_.Players.Message("&WOnly 10 seconds left!"); } }
public static void Interval(SchedulerTask task) { //check to stop Interval if (world_ == null) { task.Stop(); return; } if (world_.gameMode != GameMode.CaptureTheFlag) { task.Stop(); world_ = null; return; } //remove announcements after 5 seconds if (announced != DateTime.MaxValue && (DateTime.Now - announced).TotalSeconds >= 5) { foreach (Player p in world_.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcements, simply send a color code and call it a day } } announced = DateTime.MaxValue; } //remove dodge after 1m foreach (Player p in world_.Players) { if (p.Info.canDodge) { if (p.Info.dodgeTime != DateTime.MaxValue && (DateTime.Now - p.Info.dodgeTime).TotalSeconds >= 60) { p.Info.canDodge = false; p.Info.dodgeTime = DateTime.MaxValue; world_.Players.Message(p.Name + " is no longer able to dodge."); } } } //remove strengthen after 1m foreach (Player p in world_.Players) { if (p.Info.strengthened) { if (p.Info.strengthTime != DateTime.MaxValue && (DateTime.Now - p.Info.strengthTime).TotalSeconds >= 60) { p.Info.strengthened = false; p.Info.strengthTime = DateTime.MaxValue; world_.Players.Message(p.Name + " is no longer dealing 2x damage."); } } } //remove Blades of Fury after 1m if ((BlueBOFdebuff != DateTime.MaxValue && (DateTime.Now - BlueBOFdebuff).TotalSeconds >= 60)) { foreach (Player p in world_.Players) { if (p.Info.CTFBlueTeam) { p.Info.stabDisarmed = false; } else { p.Info.stabAnywhere = false; } } BlueBOFdebuff = DateTime.MaxValue; world_.Players.Message("Blades of Fury has ended."); } if ((RedBOFdebuff != DateTime.MaxValue && (DateTime.Now - RedBOFdebuff).TotalSeconds >= 60)) { foreach (Player p in world_.Players) { if (p.Info.CTFRedTeam) { p.Info.stabDisarmed = false; } else { p.Info.stabAnywhere = false; } } RedBOFdebuff = DateTime.MaxValue; world_.Players.Message("Blades of Fury has ended."); } //remove disarm after 30s if ((RedDisarmed != DateTime.MaxValue && (DateTime.Now - RedDisarmed).TotalSeconds >= 30)) { foreach (Player p in world_.Players) { if (p.Info.CTFRedTeam) { p.GunMode = true; p.Info.gunDisarmed = false; } } RedDisarmed = DateTime.MaxValue; world_.Players.Message("The Disarm Spell has ended."); } if ((BlueDisarmed != DateTime.MaxValue && (DateTime.Now - BlueDisarmed).TotalSeconds >= 30)) { foreach (Player p in world_.Players) { if (p.Info.CTFBlueTeam) { p.GunMode = true; p.Info.gunDisarmed = false; } } BlueDisarmed = DateTime.MaxValue; world_.Players.Message("The Disarm Spell has ended."); } if (!started) { //create a player moving event Player.Moving += PlayerMoving; if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { world_.Players.Message("&WCTF&s requires at least 2 people to play."); return; } //once timedelay is up, we start if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay) { if (!world_.gunPhysics) { world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on } foreach (Player p in world_.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { //loop through each block ID for (int i = 1; i < 65; i++) { //allow player to break glass block in order to shoot gun, disallow all other blocks except flags if (i.Equals(20)) { p.Send(PacketWriter.MakeSetBlockPermissions((byte)20, false, true)); } else if (i.Equals(21)) { p.Send(PacketWriter.MakeSetBlockPermissions((byte)21, false, true)); } else if (i.Equals(29)) { p.Send(PacketWriter.MakeSetBlockPermissions((byte)29, false, true)); } else { p.Send(PacketWriter.MakeSetBlockPermissions((byte)i, false, false)); } } } assignTeams(p); if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden) { p.Info.IsHidden = false; Player.RaisePlayerHideChangedEvent(p); } if (p.Info.CTFRedTeam) { p.TeleportTo(world_.redCTFSpawn.ToPlayerCoords()); } if (p.Info.CTFBlueTeam) { p.TeleportTo(world_.blueCTFSpawn.ToPlayerCoords()); } p.GunMode = true; GunGlassTimer timer = new GunGlassTimer(p); timer.Start(); //send an announcement (Will be sent as a normal message to non classicube players) p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!")); if (p.ClassiCube && Heartbeat.ClassiCube()) { //set player health p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); //set game score p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: 0,&1 Blue&f: 0")); } } //check that the flags haven't been misplaced during startup if (world_.Map.GetBlock(world_.redFlag) != Block.Red) { world_.Map.QueueUpdate(new BlockUpdate(null, world_.redFlag, Block.Red)); } if (world_.Map.GetBlock(world_.blueFlag) != Block.Blue) { world_.Map.QueueUpdate(new BlockUpdate(null, world_.blueFlag, Block.Blue)); } started = true; //the game has officially started isOn = true; lastChecked = DateTime.Now; //used for intervals announced = DateTime.Now; return; } } //update blue team and red team counts redTeamCount = ( from red in world_.Players where red.Info.CTFRedTeam select red ).Count(); blueTeamCount = ( from blue in world_.Players where blue.Info.CTFBlueTeam select blue ).Count(); //Announce flag holder if (String.IsNullOrEmpty(redFlagHolder)) { foreach (Player p in world_.Players) { if (p.Info.hasRedFlag && redFlagHolder == null) { world_.Players.Message(p.Name + " has stolen the Red flag!"); redFlagHolder = p.Name; } } } //update flagholder else { redFlagHolder = null; foreach (Player p in world_.Players) { if (p.Info.hasRedFlag) { redFlagHolder = p.Name; } } } if (String.IsNullOrEmpty(blueFlagHolder)) { foreach (Player p in world_.Players) { if (p.Info.hasBlueFlag && blueFlagHolder == null) { world_.Players.Message(p.Name + " has stolen the Blue flag!"); blueFlagHolder = p.Name; } } } //update flagholder else { blueFlagHolder = null; foreach (Player p in world_.Players) { if (p.Info.hasBlueFlag) { blueFlagHolder = p.Name; } } } //Check victory conditions if (blueScore == 5) { world_.Players.Message("&fThe blue team has won {0} to {1}!", blueScore, redScore); Stop(null); return; } if (redScore == 5) { world_.Players.Message("&fThe red team has won {1} to {0}!", blueScore, redScore); Stop(null); return; } //if time is up if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime)) { if (redScore > blueScore) { world_.Players.Message("&fThe &cRed&f Team won {0} to {1}!", redScore, blueScore); Stop(null); return; } if (redScore < blueScore) { world_.Players.Message("&fThe &1Blue&f Team won {0} to {1}!", blueScore, redScore); Stop(null); return; } if (redScore == blueScore) { world_.Players.Message("&fThe teams tied {0} to {0}!", blueScore); Stop(null); return; } if (world_.Players.Count() <= 1) { Stop(null); return; } } //Check for forfeits if (started && (DateTime.Now - lastChecked).TotalSeconds > 10) { if (blueTeamCount < 1 || redTeamCount < 1) { if (blueTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!"); } Stop(null); return; } if (redTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!"); } Stop(null); return; } //lol, everyone left else { Stop(null); return; } } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds)); //Keep the players updated about the score if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 29.8 && timeLeft <= timeLimit) { if (redScore > blueScore) { world_.Players.Message("&fThe &cRed Team&f is winning {0} to {1}.", redScore, blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore < blueScore) { world_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", blueScore, redScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore == blueScore) { world_.Players.Message("&fThe teams are tied at {0}!", blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } lastChecked = DateTime.Now; } if (timeLeft == 10) { world_.Players.Message("&WOnly 10 seconds left!"); } }
public void Interval(SchedulerTask task) { //check to stop Interval if (_world.gameMode != GameMode.ZombieSurvival|| _world == null) { _world = null; task.Stop(); return; } if (!isOn) { if (_world.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { if (!ConfigKey.IsNormal.Enabled()) { return; } else { _world.Players.Message("&WZombie Survival&s requires at least 4 people to play."); return; } } if (startTime != null && (DateTime.UtcNow - startTime).TotalSeconds > timeDelay) { foreach (Player p in _world.Players) { int x = rand.Next(2, _world.Map.Width); int y = rand.Next(2, _world.Map.Length); int z1 = 0; for (int z = _world.Map.Height - 1; z > 0; z--) { if (_world.Map.GetBlock(x, y, z) != Block.Air) { z1 = z + 3; break; } } p.TeleportTo(new Position(x, y, z1 + 2).ToVector3I().ToPlayerCoords()); //teleport players to a random position beginGame(p); chooseInfected(); } isOn = true; lastChecked = DateTime.UtcNow; //used for intervals return; } } if (isOn && (DateTime.UtcNow - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left { if (_world.Players.Count(player => player.Info.isInfected) == _world.Players.Count()) { ZombiesWin(); return; } if (_world.Players.Count(player => player.Info.isInfected) == 0 && _world.Players.Count() > 0) { HumansWin(); return; } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds)); if (lastChecked != null && (DateTime.UtcNow - lastChecked).TotalSeconds > 29.9 && timeLeft <= timeLimit) { _world.Players.Message("There are currently {0} human(s) and {1} zombie(s) left on {2}", _world.Players.Count() - _world.Players.Count(player => player.Info.isInfected), _world.Players.Count(player => player.Info.isInfected), _world.ClassyName); } }
public static void Interval(SchedulerTask task) { //check to stop Interval if (_world.gameMode != GameMode.ZombieSurvival || _world == null) { _world = null; task.Stop(); return; } if (!_started) { if (startTime != null && (DateTime.Now - startTime).TotalMinutes > 1) { /*if (_world.Players.Length < 3){ _world.Players.Message("&WThe game failed to start: 2 or more players need to be in the world"); Stop(null); return; }*/ foreach (Player p in _world.Players) { int x = rand.Next(2, _world.Map.Width); int y = rand.Next(2, _world.Map.Length); int z1 = 0; for (int z = _world.Map.Height - 1; z > 0; z--) { if (_world.Map.GetBlock(x, y, z) != Block.Air) { z1 = z + 3; break; } } p.TeleportTo(new Position(x, y, z1 + 2).ToVector3I().ToPlayerCoords()); } _started = true; RandomPick(); lastChecked = DateTime.Now; return; } } //calculate humans _humanCount = _world.Players.Where(p => p.iName != _zomb).Count(); //check if zombies have won already if (_humanCount == 0) { _world.Players.Message("&WThe Humans have failed to survive... &9ZOMBIES WIN!"); Stop(null); return; } //check if 5mins is up and all zombies have failed if (_started && startTime != null && (DateTime.Now - startTime).TotalMinutes > 6) { _world.Players.Message("&WThe Zombies have failed to infect everyone... &9HUMANS WIN!"); Stop(null); return; } //if no one has won, notify players of their status every 31s if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 30) { _world.Players.Message("&WThere are {0} humans", _humanCount.ToString()); foreach (Player p in _world.Players) { if (p.iName == _zomb) p.Message("&8You are " + _zomb); else p.Message("&8You are a Human"); } lastChecked = DateTime.Now; } }
/// <summary> /// Repeating task, checks things /// </summary> /// <param name="task">Task in question</param> public void Interval(SchedulerTask task) { //check to stop Interval if (_world.gameMode != GameMode.ZombieSurvival || _world == null) { _world = null; task.Stop(); return; } if (!_started) { if (startTime != null && (DateTime.UtcNow - startTime).TotalMinutes > 1) { /*if (_world.Players.Length < 3){ * _world.Players.Message("&WThe game failed to start: 2 or more players need to be in the world"); * Stop(null); * return; * }*/ ShufflePlayerPositions(); _started = true; RandomPick(); lastChecked = DateTime.UtcNow; return; } } //calculate humans _humanCount = _world.Players.Where(p => p.iName != _zomb).Count(); //check if zombies have won already if (_started) { if (_humanCount == 1 && _world.Players.Count() == 1) { _world.Players.Message("&WThe Zombies have failed to infect everyone... &9HUMANS WIN!"); Stop(null); return; } if (_humanCount == 0) { _world.Players.Message("&WThe Humans have failed to survive... &9ZOMBIES WIN!"); Stop(null); return; } } //check if 5mins is up and all zombies have failed if (_started && startTime != null && (DateTime.UtcNow - startTime).TotalMinutes >= 5) { _world.Players.Message("&WThe Zombies have failed to infect everyone... &9HUMANS WIN!"); Stop(null); return; } //if no one has won, notify players of their status every ~30s if (lastChecked != null && (DateTime.UtcNow - lastChecked).TotalSeconds >= 30) { _world.Players.Message("&WThere are {0} humans", _humanCount.ToString()); foreach (Player p in _world.Players) { if (p.iName == _zomb) { p.Message("&8You are " + _zomb); } else { p.Message("&8You are a Human"); } } lastChecked = DateTime.UtcNow; } }
private void StartFeed( SchedulerTask task ) { if ( !started ) { task.Stop(); return; } if ( !done ) return; try { done = false; RemoveText(); if ( ChangeMessage ) { switch ( direction ) { case Direction.one: case Direction.two: EndPos.X = FinishPos.X; break; case Direction.three: case Direction.four: EndPos.Y = FinishPos.Y; break; } PickNewMessage(); ChangeMessage = false; } switch ( direction ) { case Direction.one: EndPos.X -= 7; break; case Direction.two: EndPos.X += 7; break; case Direction.three: EndPos.Y -= 7; break; case Direction.four: EndPos.Y += 7; break; } Render( Sentence ); } catch ( Exception e ) { Logger.Log( LogType.Error, e.ToString() ); } }
public static void Interval(SchedulerTask task) { //check to stop Interval if (world_ == null) { task.Stop(); return; } if (world_.gameMode != GameMode.FFA) //bug checking { task.Stop(); world_ = null; return; } //remove announcement after 5 seconds if ((DateTime.UtcNow - announced).TotalSeconds >= 5) { foreach (Player p in world_.Players) { if (p.SupportsMessageTypes) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcement, simply send a color code and call it a day } } } if (!started) //first time running the interval { if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { world_.Players.Message("&WFFA&s requires at least 2 people to play."); task.Stop(); return; } if (startTime != null && (DateTime.UtcNow - startTime).TotalSeconds > timeDelay) { foreach (Player p in world_.Players) { int x = rand.Next(2, world_.Map.Width); int y = rand.Next(2, world_.Map.Length); int z1 = 0; for (int z = world_.Map.Height - 1; z > 0; z--) { if (world_.Map.GetBlock(x, y, z) != Block.Air) { z1 = z + 3; break; } } p.TeleportTo(new Position(x, y, z1 + 2).ToVector3I().ToPlayerCoords()); //teleport players to a random position InitializePlayer(p); if (!p.GunMode) { p.GunMode = true; //turns on gunMode automatically if not already on GunGlassTimer timer = new GunGlassTimer(p); timer.Start(); } if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden) { p.Info.IsHidden = false; Player.RaisePlayerHideChangedEvent(p); } //send an announcement p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!")); //set player health p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); //set leader p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&eCurrent Leader&f: None")); } started = true; //the game has officially started if (!world_.gunPhysics) { world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on } lastChecked = DateTime.UtcNow; //used for intervals announced = DateTime.UtcNow; //set when the announcement was launched return; } } //check if one of the players has won foreach (Player p in world_.Players) { if (started && startTime != null && (DateTime.UtcNow - startTime).TotalSeconds >= timeDelay && p.Info.gameKillsFFA >= scoreLimit) { Stop(p); return; } } //check if time is up if (started && startTime != null && (DateTime.UtcNow - startTime).TotalSeconds >= (totalTime)) { Player winner = GetScoreList()[0]; if (world_.Players.Count() < 2) { Stop(winner); return; } Stop(winner); return; } if (started && (DateTime.UtcNow - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left { if (world_.Players.Count() < 2) { Player[] players = world_.Players; Stop(players[0]); return; } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.UtcNow - startTime).ToSeconds())); //Keep the players updated about the score if (lastChecked != null && (DateTime.UtcNow - lastChecked).TotalSeconds > 29.9 && timeLeft <= timeLimit) { Player leader = GetScoreList()[0]; //leader is the top of the score list Player secondPlace = GetScoreList()[1]; //second place is - well, second place XD if (isOn() && leader.Info.gameKillsFFA != secondPlace.Info.gameKillsFFA) { world_.Players.Message("{0}&f is winning &c{1} &fto &c{2}", leader.ClassyName, leader.Info.gameKillsFFA, secondPlace.Info.gameKillsFFA); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (leader.Info.gameKillsFFA == secondPlace.Info.gameKillsFFA) { world_.Players.Message("{1}&f and {2}&f are tied at &c{0}!", leader.Info.gameKillsFFA, leader.ClassyName, secondPlace.ClassyName); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } lastChecked = DateTime.UtcNow; } if (timeLeft < 10.1) { world_.Players.Message("&WOnly 10 seconds left!"); } }
public static void Interval(SchedulerTask task) { //check to stop Interval if (world_ == null) { task.Stop(); return; } if (world_.gameMode != GameMode.CaptureTheFlag) { task.Stop(); world_ = null; return; } //remove announcements after 5 seconds if (announced != DateTime.MaxValue && (DateTime.Now - announced).TotalSeconds >= 5) { foreach (Player p in world_.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f"));//super hacky way to remove announcements, simply send a color code and call it a day } } announced = DateTime.MaxValue; } //remove dodge after 1m foreach (Player p in world_.Players) { if (p.Info.canDodge) { if (p.Info.dodgeTime != DateTime.MaxValue && (DateTime.Now - p.Info.dodgeTime).TotalSeconds >= 60) { p.Info.canDodge = false; p.Info.dodgeTime = DateTime.MaxValue; world_.Players.Message(p.Name + " is no longer able to dodge."); } } } //remove strengthen after 1m foreach (Player p in world_.Players) { if (p.Info.strengthened) { if (p.Info.strengthTime != DateTime.MaxValue && (DateTime.Now - p.Info.strengthTime).TotalSeconds >= 60) { p.Info.strengthened = false; p.Info.strengthTime = DateTime.MaxValue; world_.Players.Message(p.Name + " is no longer dealing 2x damage."); } } } //remove Blades of Fury after 1m if ((BlueBOFdebuff != DateTime.MaxValue && (DateTime.Now - BlueBOFdebuff).TotalSeconds >= 60)) { foreach (Player p in world_.Players) { if (p.Info.CTFBlueTeam) { p.Info.stabDisarmed = false; } else { p.Info.stabAnywhere = false; } } BlueBOFdebuff = DateTime.MaxValue; world_.Players.Message("Blades of Fury has ended."); } if ((RedBOFdebuff != DateTime.MaxValue && (DateTime.Now - RedBOFdebuff).TotalSeconds >= 60)) { foreach (Player p in world_.Players) { if (p.Info.CTFRedTeam) { p.Info.stabDisarmed = false; } else { p.Info.stabAnywhere = false; } } RedBOFdebuff = DateTime.MaxValue; world_.Players.Message("Blades of Fury has ended."); } //remove disarm after 30s if ((RedDisarmed != DateTime.MaxValue && (DateTime.Now - RedDisarmed).TotalSeconds >= 30)) { foreach (Player p in world_.Players) { if (p.Info.CTFRedTeam) { p.GunMode = true; p.Info.gunDisarmed = false; } } RedDisarmed = DateTime.MaxValue; world_.Players.Message("The Disarm Spell has ended."); } if ((BlueDisarmed != DateTime.MaxValue && (DateTime.Now - BlueDisarmed).TotalSeconds >= 30)) { foreach (Player p in world_.Players) { if (p.Info.CTFBlueTeam) { p.GunMode = true; p.Info.gunDisarmed = false; } } BlueDisarmed = DateTime.MaxValue; world_.Players.Message("The Disarm Spell has ended."); } if (!started) { //create a player moving event Player.Moving += PlayerMoving; if (world_.Players.Count() < 2) //in case players leave the world or disconnect during the start delay { world_.Players.Message("&WCTF&s requires at least 2 people to play."); return; } //once timedelay is up, we start if (startTime != null && (DateTime.Now - startTime).TotalSeconds > timeDelay) { if (!world_.gunPhysics) { world_.EnableGunPhysics(Player.Console, true); //enables gun physics if they are not already on } foreach (Player p in world_.Players) { if (p.ClassiCube && Heartbeat.ClassiCube()) { //loop through each block ID for (int i = 1; i < 65; i++) { //allow player to break glass block in order to shoot gun, disallow all other blocks except flags if (i.Equals(20)) { p.Send(PacketWriter.MakeSetBlockPermissions((byte)20, false, true)); } else if (i.Equals(21)) { p.Send(PacketWriter.MakeSetBlockPermissions((byte)21, false, true)); } else if (i.Equals(29)) { p.Send(PacketWriter.MakeSetBlockPermissions((byte)29, false, true)); } else { p.Send(PacketWriter.MakeSetBlockPermissions((byte)i, false, false)); } } } assignTeams(p); if (p.Info.IsHidden) //unhides players automatically if hidden (cannot shoot guns while hidden) { p.Info.IsHidden = false; Player.RaisePlayerHideChangedEvent(p); } if (p.Info.CTFRedTeam) { p.TeleportTo(world_.redCTFSpawn.ToPlayerCoords()); } if (p.Info.CTFBlueTeam) { p.TeleportTo(world_.blueCTFSpawn.ToPlayerCoords()); } p.GunMode = true; GunGlassTimer timer = new GunGlassTimer(p); timer.Start(); //send an announcement (Will be sent as a normal message to non classicube players) p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&cLet the Games Begin!")); if (p.ClassiCube && Heartbeat.ClassiCube()) { //set player health p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f[&a--------&f]")); //set game score p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&cRed&f: 0,&1 Blue&f: 0")); } } //check that the flags haven't been misplaced during startup if (world_.Map.GetBlock(world_.redFlag) != Block.Red) { world_.Map.QueueUpdate(new BlockUpdate(null, world_.redFlag, Block.Red)); } if (world_.Map.GetBlock(world_.blueFlag) != Block.Blue) { world_.Map.QueueUpdate(new BlockUpdate(null, world_.blueFlag, Block.Blue)); } started = true; //the game has officially started isOn = true; lastChecked = DateTime.Now; //used for intervals announced = DateTime.Now; return; } } //update blue team and red team counts redTeamCount = ( from red in world_.Players where red.Info.CTFRedTeam select red ).Count(); blueTeamCount = ( from blue in world_.Players where blue.Info.CTFBlueTeam select blue ).Count(); //Announce flag holder if (String.IsNullOrEmpty(redFlagHolder)) { foreach (Player p in world_.Players) { if (p.Info.hasRedFlag && redFlagHolder == null) { world_.Players.Message(p.Name + " has stolen the Red flag!"); redFlagHolder = p.Name; } } } //update flagholder else { redFlagHolder = null; foreach(Player p in world_.Players) { if (p.Info.hasRedFlag) { redFlagHolder = p.Name; } } } if (String.IsNullOrEmpty(blueFlagHolder)) { foreach (Player p in world_.Players) { if (p.Info.hasBlueFlag && blueFlagHolder == null) { world_.Players.Message(p.Name + " has stolen the Blue flag!"); blueFlagHolder = p.Name; } } } //update flagholder else { blueFlagHolder = null; foreach (Player p in world_.Players) { if (p.Info.hasBlueFlag) { blueFlagHolder = p.Name; } } } //Check victory conditions if (blueScore == 5) { world_.Players.Message("&fThe blue team has won {0} to {1}!", blueScore, redScore); Stop(null); return; } if (redScore == 5) { world_.Players.Message("&fThe red team has won {1} to {0}!", blueScore, redScore); Stop(null); return; } //if time is up if (started && startTime != null && (DateTime.Now - startTime).TotalSeconds >= (totalTime)) { if (redScore > blueScore) { world_.Players.Message("&fThe &cRed&f Team won {0} to {1}!", redScore, blueScore); Stop(null); return; } if (redScore < blueScore) { world_.Players.Message("&fThe &1Blue&f Team won {0} to {1}!", blueScore, redScore); Stop(null); return; } if (redScore == blueScore) { world_.Players.Message("&fThe teams tied {0} to {0}!", blueScore); Stop(null); return; } if (world_.Players.Count() <= 1) { Stop(null); return; } } //Check for forfeits if (started && (DateTime.Now - lastChecked).TotalSeconds > 10) { if (blueTeamCount < 1 || redTeamCount < 1) { if (blueTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&1Blue Team &fhas forfeited the game. &cRed Team &fwins!"); } Stop(null); return; } if (redTeamCount == 0) { if (world_.Players.Count() >= 1) { world_.Players.Message("&cRed Team &fhas forfeited the game. &1Blue Team &fwins!"); } Stop(null); return; } //lol, everyone left else { Stop(null); return; } } } timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds)); //Keep the players updated about the score if (lastChecked != null && (DateTime.Now - lastChecked).TotalSeconds > 29.8 && timeLeft <= timeLimit) { if (redScore > blueScore) { world_.Players.Message("&fThe &cRed Team&f is winning {0} to {1}.", redScore, blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore < blueScore) { world_.Players.Message("&fThe &1Blue Team&f is winning {0} to {1}.", blueScore, redScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } if (redScore == blueScore) { world_.Players.Message("&fThe teams are tied at {0}!", blueScore); world_.Players.Message("&fThere are &W{0}&f seconds left in the game.", timeLeft); } lastChecked = DateTime.Now; } if (timeLeft == 10) { world_.Players.Message("&WOnly 10 seconds left!"); } }
static void MainLoop() { while (!Server.IsShuttingDown) { DateTime ticksNow = DateTime.UtcNow; SchedulerTask[] taskListCache = taskCache; for (int i = 0; i < taskListCache.Length && !Server.IsShuttingDown; i++) { SchedulerTask task = taskListCache[i]; if (task.IsStopped || task.NextTime > ticksNow) { continue; } if (task.IsRecurring && task.AdjustForExecutionTime) { task.NextTime += task.Interval; } if (task.IsBackground) { lock ( BackgroundTaskQueueLock ) { BackgroundTasks.Enqueue(task); } } else { task.IsExecuting = true; #if DEBUG_SCHEDULER FireEvent(TaskExecuting, task); #endif #if DEBUG task.Callback(task); task.IsExecuting = false; #else try { task.Callback(task); } catch (Exception ex) { Logger.LogAndReportCrash("Exception thrown by ScheduledTask callback", "fCraft", ex, false); } finally { task.IsExecuting = false; } #endif #if DEBUG_SCHEDULER FireEvent(TaskExecuted, task); #endif } if (!task.IsRecurring || task.MaxRepeats == 1) { task.Stop(); continue; } task.MaxRepeats--; ticksNow = DateTime.UtcNow; if (!task.AdjustForExecutionTime) { task.NextTime = ticksNow.Add(task.Interval); } } Thread.Sleep(10); } }
public void Stop() { _task.Stop(); Logger.Log(LogType.Error, "&WPropHunt is stopped."); }