public static void GunHandler(Player player, Command cmd) { if (player.GunMode) { player.GunMode = false; try { foreach (Vector3I block in player.GunCache.Values) { player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, player.WorldMap.GetBlock(block))); Vector3I removed; player.GunCache.TryRemove(block.ToString(), out removed); } if (player.bluePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.bluePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.blueOld[i])); i++; } } player.blueOld.Clear(); player.bluePortal.Clear(); } if (player.orangePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.orangePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.orangeOld[i])); i++; } } player.orangeOld.Clear(); player.orangePortal.Clear(); } player.Message("&SGunMode deactivated"); } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } } else { if (!player.World.gunPhysics) { player.Message("&WGun physics are disabled on this world"); return; } player.GunMode = true; GunGlassTimer timer = new GunGlassTimer(player); timer.Start(); player.Message("&SGunMode activated. Fire at will!"); } }
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 GunHandler(Player player, Command cmd) { //to prevent players from doing /gun during a TDM game that arent actually playing in if (player.World.gameMode == GameMode.TeamDeathMatch && !player.Info.isPlayingTD) { player.Message("Players who are not playing Team DeathMatch can only spectate."); return; } if (player.Info.isPlayingCTF && player.Info.gunDisarmed) { player.Message("You are currently disarmed. You cannot use a gun until the disarm powerup has worn off."); return; } if (player.GunMode) { player.GunMode = false; try { foreach (Vector3I block in player.GunCache.Values) { player.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, player.WorldMap.GetBlock(block))); Vector3I removed; player.GunCache.TryRemove(block.ToString(), out removed); } if (player.bluePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.bluePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.blueOld[i])); i++; } } player.blueOld.Clear(); player.bluePortal.Clear(); } if (player.orangePortal.Count > 0) { int i = 0; foreach (Vector3I block in player.orangePortal) { if (player.WorldMap != null && player.World.IsLoaded) { player.WorldMap.QueueUpdate(new BlockUpdate(null, block, player.orangeOld[i])); i++; } } player.orangeOld.Clear(); player.orangePortal.Clear(); } player.Message("&SGunMode deactivated"); } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } } else { if (!player.World.gunPhysics) { player.Message("&WGun physics are disabled on this world"); return; } player.GunMode = true; GunGlassTimer timer = new GunGlassTimer(player); timer.Start(); player.Message("&SGunMode activated. Fire at will!"); } }
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 (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 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!"); } }