public static int TpToSpawnPoint() { try { bool Team1Player = false; bool Team2Player = false; for (int i = 0; i < C3Mod.C3Players.Count; i++) { if ((C3Mod.C3Players[i].Team == 3 && Main.player[C3Mod.C3Players[i].Index].team != C3Mod.C3Config.TeamColor1)) { TShock.Players[C3Mod.C3Players[i].Index].SetTeam(C3Mod.C3Config.TeamColor1); } else if (C3Mod.C3Players[i].Team == 4 && Main.player[C3Mod.C3Players[i].Index].team != C3Mod.C3Config.TeamColor2) { TShock.Players[C3Mod.C3Players[i].Index].SetTeam(C3Mod.C3Config.TeamColor2); } if (C3Mod.C3Players[i].Team == 3) { Team1Player = true; C3Mod.C3Players[i].TSPlayer.TpLock = false; if (C3Mod.C3Players[i].TSPlayer.X / 16 != DuelSpawns[0].X || C3Mod.C3Players[i].TSPlayer.Y / 16 + 3 != DuelSpawns[0].Y) { TShock.Players[C3Mod.C3Players[i].Index].Teleport((int)DuelSpawns[0].X * 16, (int)DuelSpawns[0].Y * 16); } if (C3Mod.C3Config.TPLockEnabled) { C3Mod.C3Players[i].TSPlayer.TpLock = true; } } else if (C3Mod.C3Players[i].Team == 4) { Team2Player = true; C3Mod.C3Players[i].TSPlayer.TpLock = false; if (C3Mod.C3Players[i].TSPlayer.X / 16 != DuelSpawns[1].X || C3Mod.C3Players[i].TSPlayer.Y / 16 + 3 != DuelSpawns[1].Y) { TShock.Players[C3Mod.C3Players[i].Index].Teleport((int)DuelSpawns[1].X * 16, (int)DuelSpawns[1].Y * 16); } if (C3Mod.C3Config.TPLockEnabled) { C3Mod.C3Players[i].TSPlayer.TpLock = true; } } } if (!Team1Player || !Team2Player) { C3Tools.BroadcastMessageToGametype("1v1", "Ending game, because the opponent left!", Color.DarkCyan); DuelRunning = false; DuelCountdown = false; DuelSpawns = new Vector2[2]; return(0); } return(1); } catch { return(0); } }
public static void ApoLost(C3Player player, int reason) { switch (reason) { case 0: { C3Tools.BroadcastMessageToGametype("apoc", "You lost! All died!", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "The Apocalypse failed, because all are dead! Wimps!", Color.Cyan); break; } case 1: { C3Tools.BroadcastMessageToGametype("apoc", "Lost! Idiots! Your not fast enough!", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "The Apocalypse was not defeated in time! Wimps!", Color.Cyan); break; } } TpToSpawns(false); C3Tools.ResetGameType("apoc"); Running = false; Intermission = false; StartCount = 3; //NEW CODE TO EXPAND THE APOCAYLPSE MonsterApocalypseIntermissionTimeCache = C3Mod.C3Config.MonsterApocalypseIntermissionTime; //NEW CODE TO EXPAND THE APOCAYLPSE List <C3Player> Players = new List <C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "apoc") { Players.Add(player); } } C3Events.GameEnd(new List <C3Player>(), Players, "apoc", 0, Wave); }
public static void ApoLost(C3Player player, int reason) { switch (reason) { case 0: { C3Tools.BroadcastMessageToGametype("apoc", "You lost! All died!", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "The Apocalypse failed, because all are dead! Wimps!", Color.Cyan); break; } case 1: { C3Tools.BroadcastMessageToGametype("apoc", "Lost! Idiots! Your not fast enough!", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "The Apocalypse was not defeated in time! Wimps!", Color.Cyan); break; } } TpToSpawns(false); C3Tools.ResetGameType("apoc"); Running = false; Intermission = false; StartCount = 3; //NEW CODE TO EXPAND THE APOCAYLPSE MonsterApocalypseIntermissionTimeCache = C3Mod.C3Config.MonsterApocalypseIntermissionTime; //NEW CODE TO EXPAND THE APOCAYLPSE List<C3Player> Players = new List<C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "apoc") { Players.Add(player); } } C3Events.GameEnd(new List<C3Player>(), Players, "apoc", 0, Wave); }
public static void OnUpdate() { lock (C3Mod.C3Players) { if (C3Mod.VoteRunning && C3Mod.VoteType == "ctf") { int VotedPlayers = 0; int TotalPlayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "" || player.GameType == "ctf") { TotalPlayers++; } if (player.GameType == "ctf") { VotedPlayers++; } } if (VotedPlayers == TotalPlayers) { C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag passed, Teleporting to start positions", Color.DarkCyan); C3Mod.VoteRunning = false; C3Mod.VoteType = ""; CTF.Team2FlagCarrier = null; CTF.Team1FlagCarrier = null; CTF.Team2Score = 0; CTF.Team1Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; CTF.TpToSpawn(); CTF.countDownTick = DateTime.UtcNow; CTF.CTFGameCountdown = true; return; } double tick = (DateTime.UtcNow - voteCountDown).TotalMilliseconds; if (tick > (C3Mod.C3Config.VoteNotifyInterval * 1000) && VoteCount > 0) { if (VoteCount != 1 && VoteCount < (C3Mod.C3Config.VoteTime / C3Mod.C3Config.VoteNotifyInterval)) { C3Tools.BroadcastMessageToGametype("ctf", "Vote still in progress, please be patient", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "Vote to play Capture the Flag in progress, type /join to join the lobby", Color.Cyan); } VoteCount--; voteCountDown = DateTime.UtcNow; } else if (VoteCount == 0) { C3Mod.VoteRunning = false; int team1players = 0; int team2players = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.Team == 1) { team1players++; } else if (player.Team == 2) { team2players++; } } if (team1players >= C3Mod.C3Config.VoteMinimumPerTeam && team2players >= C3Mod.C3Config.VoteMinimumPerTeam) { C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag passed, Teleporting to start positions", Color.DarkCyan); CTF.Team2FlagCarrier = null; CTF.Team1FlagCarrier = null; CTF.Team2Score = 0; CTF.Team1Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; CTF.TpToSpawn(); CTF.countDownTick = DateTime.UtcNow; CTF.CTFGameCountdown = true; } else { C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag failed, Not enough players", Color.DarkCyan); } } } if (CTFGameCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToSpawn() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("ctf", "Capture...The...Flag!!!", Color.Cyan); StartCount = 5; CTFGameCountdown = false; CTFGameRunning = true; } else { C3Tools.BroadcastMessageToGametype("ctf", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("ctf"); return; } } } if (CTFGameRunning) { int team1players = 0; int team2players = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "ctf") { if (!player.TSPlayer.TpLock) { if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } if (player.Team == 1) { team1players++; } else if (player.Team == 2) { team2players++; } if ((player.Team == 1 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor1)) { TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor1); } if ((player.Team == 2 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor2)) { TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor2); } if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) { player.Dead = true; } else { if (player.Dead) { player.Dead = false; player.TSPlayer.TpLock = false; if (player.Team == 1) { TShock.Players[player.Index].Teleport((int)spawnPoints[0].X, (int)spawnPoints[0].Y); } else if (player.Team == 2) { TShock.Players[player.Index].Teleport((int)spawnPoints[1].X, (int)spawnPoints[1].Y); } NetMessage.SendData(4, -1, player.Index, player.PlayerName, player.Index, 0f, 0f, 0f, 0); if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } } //Grab flag if (!player.Dead) { if (player.Team == 1 && Team1FlagCarrier == null) { if ((int)player.tileX >= flagPoints[1].X - 2 && (int)player.tileX <= flagPoints[1].X + 2 && (int)player.tileY == (int)(flagPoints[1].Y - 3)) { Team1FlagCarrier = player; switch (C3Mod.C3Config.TeamColor1) { case 1: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.LightYellow); break; } } C3Events.FlagGrabbed(player, "ctf"); } } if (player.Team == 2 && Team2FlagCarrier == null) { if ((int)player.tileX >= flagPoints[0].X - 2 && (int)player.tileX <= flagPoints[0].X + 2 && (int)player.tileY == (int)(flagPoints[0].Y - 3)) { Team2FlagCarrier = player; switch (C3Mod.C3Config.TeamColor2) { case 1: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.LightYellow); break; } } C3Events.FlagGrabbed(player, "ctf"); } } } } } if (team1players == 0 || team2players == 0) { C3Tools.BroadcastMessageToGametype("ctf", "Capture the Flag stopped, Not enough players to continue", Color.DarkCyan); CTFGameRunning = false; TpToSpawns(false); C3Tools.ResetGameType("ctf"); flagPoints = new Vector2[2]; spawnPoints = new Vector2[2]; return; } //Check on flag carriers if (Team2FlagCarrier != null) { //Make them drop the flag if (Team2FlagCarrier.TerrariaDead) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Dropped the flag!", Color.LightBlue); Team2FlagCarrier = null; } //Capture the flag else { if ((int)Team2FlagCarrier.tileX >= flagPoints[1].X - 2 && (int)Team2FlagCarrier.tileX <= flagPoints[1].X + 2 && (int)Team2FlagCarrier.tileY == (int)(flagPoints[1].Y - 3)) { Team2Score++; switch (C3Mod.C3Config.TeamColor2) { case 1: { if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Red - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Green", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Red - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Blue", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Red - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Yellow", Color.OrangeRed); } break; } case 2: { if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Green - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Red", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Green - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Blue", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Green - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Yellow", Color.LightGreen); } break; } case 3: { if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Blue - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Red", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Blue - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Green", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Blue - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Yellow", Color.LightBlue); } break; } case 4: { if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Yellow - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Red", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Yellow - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Green", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + ": Scores! Yellow - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Blue", Color.LightYellow); } break; } } C3Events.FlagCapture(Team2FlagCarrier, "ctf", "Team2", Team2Score, Team1Score); Team2FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) { Team1FlagCarrier = null; TpToSpawn(); } if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) { Team1FlagCarrier = null; CTFGameRunning = false; CTFGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } if (Team1FlagCarrier != null) { if (Team1FlagCarrier.TerrariaDead) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Dropped the flag!", Color.OrangeRed); Team1FlagCarrier = null; } else { if ((int)Team1FlagCarrier.tileX >= flagPoints[0].X - 2 && (int)Team1FlagCarrier.tileX <= flagPoints[0].X + 2 && (int)Team1FlagCarrier.tileY == (int)(flagPoints[0].Y - 3)) { Team1Score++; switch (C3Mod.C3Config.TeamColor1) { case 1: { if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Red - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Green", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Red - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Blue", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Red - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Yellow", Color.OrangeRed); } break; } case 2: { if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Green - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Red", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Green - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Blue", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Green - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Yellow", Color.LightGreen); } break; } case 3: { if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Blue - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Red", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Blue - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Green", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Blue - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Yellow", Color.LightBlue); } break; } case 4: { if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Yellow - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Red", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Yellow - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Green", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + ": Scores! Yellow - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Blue", Color.LightYellow); } break; } } C3Events.FlagCapture(Team1FlagCarrier, "ctf", "Team1", Team1Score, Team2Score); Team1FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) { Team2FlagCarrier = null; TpToSpawn(); } if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) { Team2FlagCarrier = null; CTFGameRunning = false; CTFGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } if (Team2Score == C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("ctf", "RED TEAM WINS!", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("ctf", "GREEN TEAM WINS!", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("ctf", "BLUE TEAM WINS!", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("ctf", "YELLOW TEAM WINS!", Color.LightYellow); } List <C3Player> LostPlayers = new List <C3Player>(); List <C3Player> WonPlayers = new List <C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "ctf") { if (player1.Team == 2) { WonPlayers.Add(player1); } if (player1.Team == 1) { LostPlayers.Add(player1); } } } C3Events.GameEnd(WonPlayers, LostPlayers, "ctf", Team2Score, Team1Score); TpToSpawns(false); C3Tools.ResetGameType("ctf"); flagPoints = new Vector2[2]; spawnPoints = new Vector2[2]; return; } if (Team1Score == C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("ctf", "RED TEAM WINS!", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("ctf", "GREEN TEAM WINS!", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("ctf", "BLUE TEAM WINS!", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("ctf", "YELLOW TEAM WINS!", Color.LightYellow); } List <C3Player> LostPlayers = new List <C3Player>(); List <C3Player> WonPlayers = new List <C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "ctf") { if (player1.Team == 1) { WonPlayers.Add(player1); } if (player1.Team == 2) { LostPlayers.Add(player1); } } } C3Events.GameEnd(WonPlayers, LostPlayers, "ctf", Team1Score, Team2Score); TpToSpawns(false); C3Tools.ResetGameType("ctf"); flagPoints = new Vector2[2]; spawnPoints = new Vector2[2]; return; } } }
public static void OnUpdate() { lock (C3Mod.C3Players) { if (C3Mod.VoteRunning && C3Mod.VoteType == "oneflag") { int VotedPlayers = 0; int TotalPlayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "" || player.GameType == "oneflag") TotalPlayers++; if (player.GameType == "oneflag") VotedPlayers++; } if (VotedPlayers == TotalPlayers) { C3Tools.BroadcastMessageToGametype("oneflag", "Vote to play One Flag CTF passed, Teleporting to start positions", Color.DarkCyan); C3Mod.VoteRunning = false; C3Mod.VoteType = ""; FlagCarrier = null; Team1Score = 0; Team2Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; TpToOneFlagSpawns(); countDownTick = DateTime.UtcNow; OneFlagGameCountdown = true; return; } double tick = (DateTime.UtcNow - voteCountDown).TotalMilliseconds; if (tick > (C3Mod.C3Config.VoteNotifyInterval * 1000) && VoteCount > 0) { if (VoteCount != 1 && VoteCount < (C3Mod.C3Config.VoteTime / C3Mod.C3Config.VoteNotifyInterval)) { C3Tools.BroadcastMessageToGametype("oneflag", "Vote still in progress, please be patient", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "Vote to play One Flag CTF in progress, type /join to join the lobby", Color.Cyan); } VoteCount--; voteCountDown = DateTime.UtcNow; } else if (VoteCount == 0) { C3Mod.VoteRunning = false; int redteamplayers = 0; int blueteamplayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.Team == 5) redteamplayers++; else if (player.Team == 6) blueteamplayers++; } if (redteamplayers >= C3Mod.C3Config.VoteMinimumPerTeam && blueteamplayers >= C3Mod.C3Config.VoteMinimumPerTeam) { C3Tools.BroadcastMessageToGametype("oneflag", "Vote to play One Flag CTF passed, Teleporting to start positions", Color.DarkCyan); FlagCarrier = null; Team1Score = 0; Team2Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; TpToOneFlagSpawns(); countDownTick = DateTime.UtcNow; OneFlagGameCountdown = true; } else C3Tools.BroadcastMessageToGametype("oneflag", "Vote to play One Flag CTF failed, Not enough players", Color.DarkCyan); } } if (OneFlagGameCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToOneFlagSpawns() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("oneflag", "Capture...The...Flag!!!", Color.Cyan); StartCount = 5; OneFlagGameCountdown = false; OneFlagGameRunning = true; } else { C3Tools.BroadcastMessageToGametype("oneflag", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("oneflag"); return; } } } if (OneFlagGameRunning) { int team1players = 0; int team2players = 0; lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "oneflag") { if (!player.TSPlayer.TpLock) if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } if (player.Team == 5) team1players++; else if (player.Team == 6) team2players++; if ((player.Team == 5 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor1)) TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor1); else if (player.Team == 6 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor2) TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor2); if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int) PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) player.Dead = true; else { if (player.Dead) { player.Dead = false; player.TSPlayer.TpLock = false; if (player.Team == 5) TShock.Players[player.Index].Teleport((int) SpawnPoint[0].X, (int) SpawnPoint[0].Y); else if (player.Team == 6) TShock.Players[player.Index].Teleport((int) SpawnPoint[1].X, (int) SpawnPoint[1].Y); NetMessage.SendData(4, -1, player.Index, player.PlayerName, player.Index, 0f, 0f, 0f, 0); if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } } //Grab flag if (!player.Dead) { if (FlagCarrier == null) { if ((int) player.tileX <= (int) FlagPoint.X + 2 && (int) player.tileX >= (int) FlagPoint.X - 2 && (int) player.tileY == (int) FlagPoint.Y - 3) { FlagCarrier = player; if (player.Team == 5) { switch (C3Mod.C3Config.TeamColor1) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightYellow); break; } } } else if (player.Team == 6) switch (C3Mod.C3Config.TeamColor2) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightYellow); break; } } C3Events.FlagGrabbed(FlagCarrier, "oneflag"); } } } } } } if (team1players == 0 || team2players == 0) { C3Tools.BroadcastMessageToGametype("oneflag", "One Flag CTF stopped, Not enough players to continue", Color.DarkCyan); OneFlagGameRunning = false; SendToSpawn(false); C3Tools.ResetGameType("oneflag"); return; } //Check on flag carrier if (FlagCarrier != null) { //Make them drop the flag if (Main.player[FlagCarrier.Index].dead) { if (FlagCarrier.Team == 5) switch (C3Mod.C3Config.TeamColor1) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightYellow); break; } } else if (FlagCarrier.Team == 6) switch (C3Mod.C3Config.TeamColor2) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightYellow); break; } } FlagCarrier = null; } //Capture the flag else { if (FlagCarrier.Team == 5) { if ((int)FlagCarrier.tileX <= (int)SpawnPoint[0].X + 2 && (int)FlagCarrier.tileX >= (int)SpawnPoint[0].X - 2 && (int)FlagCarrier.tileY == (int)SpawnPoint[0].Y - 3) { Team1Score++; switch (C3Mod.C3Config.TeamColor1) { case 1: { if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Red - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Green", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Red - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Blue", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Red - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Yellow", Color.OrangeRed); break; } case 2: { if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Green - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Red", Color.LightGreen); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Green - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Blue", Color.LightGreen); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Green - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Yellow", Color.LightGreen); break; } case 3: { if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Blue - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Red", Color.LightBlue); else if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Blue - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Green", Color.LightBlue); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Blue - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Yellow", Color.LightBlue); break; } case 4: { if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Yellow - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Red", Color.LightYellow); else if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Yellow - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Green", Color.LightYellow); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Yellow - " + Team1Score.ToString() + " --- " + Team2Score.ToString() + " - Blue", Color.LightYellow); break; } } C3Events.FlagCapture(FlagCarrier, "oneflag", "Team1", Team1Score, Team2Score); FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) TpToOneFlagSpawns(); if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; OneFlagGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } else if (FlagCarrier.Team == 6) { if ((int)FlagCarrier.tileX <= (int)SpawnPoint[1].X + 2 && (int)FlagCarrier.tileX >= (int)SpawnPoint[1].X - 2 && (int)FlagCarrier.tileY == (int)SpawnPoint[1].Y - 3) { Team2Score++; switch (C3Mod.C3Config.TeamColor2) { case 1: { if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Red - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Green", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Red - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Blue", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Red - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Yellow", Color.OrangeRed); break; } case 2: { if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Green - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Red", Color.LightGreen); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Green - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Blue", Color.LightGreen); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Green - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Yellow", Color.LightGreen); break; } case 3: { if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Blue - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Red", Color.LightBlue); else if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Blue - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Green", Color.LightBlue); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Blue - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Yellow", Color.LightBlue); break; } case 4: { if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Yellow - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Red", Color.LightYellow); else if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Yellow - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Green", Color.LightYellow); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + ": Scores! Yellow - " + Team2Score.ToString() + " --- " + Team1Score.ToString() + " - Blue", Color.LightYellow); break; } } C3Events.FlagCapture(FlagCarrier, "oneflag", "Team2", Team2Score, Team1Score); FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) TpToOneFlagSpawns(); if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; OneFlagGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } if (Team1Score == C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("ctf", "RED TEAM WINS!", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("ctf", "GREEN TEAM WINS!", Color.LightGreen); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("ctf", "BLUE TEAM WINS!", Color.LightBlue); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("ctf", "YELLOW TEAM WINS!", Color.LightYellow); List<C3Player> LostPlayers = new List<C3Player>(); List<C3Player> WonPlayers = new List<C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "oneflag") { if (player1.Team == 6) WonPlayers.Add(player1); if (player1.Team == 5) LostPlayers.Add(player1); } } C3Events.GameEnd(WonPlayers, LostPlayers, "oneflag", Team2Score, Team1Score); SendToSpawn(false); C3Tools.ResetGameType("oneflag"); OneFlagCTF.FlagPoint = new Vector2(); OneFlagCTF.SpawnPoint = new Vector2[2]; return; } if (Team2Score == C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("ctf", "RED TEAM WINS!", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("ctf", "GREEN TEAM WINS!", Color.LightGreen); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("ctf", "BLUE TEAM WINS!", Color.LightBlue); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("ctf", "YELLOW TEAM WINS!", Color.LightYellow); List<C3Player> LostPlayers = new List<C3Player>(); List<C3Player> WonPlayers = new List<C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "oneflag") { if (player1.Team == 5) WonPlayers.Add(player1); if (player1.Team == 6) LostPlayers.Add(player1); } } C3Events.GameEnd(WonPlayers, LostPlayers, "oneflag", Team1Score, Team2Score); SendToSpawn(false); C3Tools.ResetGameType("oneflag"); OneFlagCTF.FlagPoint = new Vector2(); OneFlagCTF.SpawnPoint = new Vector2[2]; return; } } } }
public static void OnUpdate(GameTime gameTime) { lock (C3Mod.C3Players) { if (C3Mod.VoteRunning && C3Mod.VoteType == "ctf") { int VotedPlayers = 0; int TotalPlayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "" || player.GameType == "ctf") TotalPlayers++; if (player.GameType == "ctf") VotedPlayers++; } if (VotedPlayers == TotalPlayers) { C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag passed, Teleporting to start positions", Color.DarkCyan); C3Mod.VoteRunning = false; C3Mod.VoteType = ""; CTF.BlueTeamFlagCarrier = null; CTF.RedTeamFlagCarrier = null; CTF.BlueTeamScore = 0; CTF.RedTeamScore = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; CTF.TpToFlag(); CTF.countDownTick = DateTime.UtcNow; CTF.CTFGameCountdown = true; return; } double tick = (DateTime.UtcNow - voteCountDown).TotalMilliseconds; if (tick > (C3Mod.C3Config.VoteNotifyInterval * 1000) && VoteCount > 0) { if (VoteCount != 1 && VoteCount < (C3Mod.C3Config.VoteTime / C3Mod.C3Config.VoteNotifyInterval)) { C3Tools.BroadcastMessageToGametype("ctf", "Vote still in progress, please be patient", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "Vote to play Capture the Flag in progress, type /join to join the lobby", Color.Cyan); } VoteCount--; voteCountDown = DateTime.UtcNow; } else if (VoteCount == 0) { C3Mod.VoteRunning = false; int redteamplayers = 0; int blueteamplayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.Team == 1) redteamplayers++; else if (player.Team == 2) blueteamplayers++; } if (redteamplayers >= C3Mod.C3Config.VoteCTFPlayersMinimumPerTeam && blueteamplayers >= C3Mod.C3Config.VoteCTFPlayersMinimumPerTeam) { C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag passed, Teleporting to start positions", Color.DarkCyan); CTF.BlueTeamFlagCarrier = null; CTF.RedTeamFlagCarrier = null; CTF.BlueTeamScore = 0; CTF.RedTeamScore = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; CTF.TpToFlag(); CTF.countDownTick = DateTime.UtcNow; CTF.CTFGameCountdown = true; } else C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag failed, Not enough players", Color.DarkCyan); } } if (CTFGameCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToFlag() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("ctf", "Capture...The...Flag!!!", Color.Cyan); StartCount = 5; CTFGameCountdown = false; CTFGameRunning = true; } else { C3Tools.BroadcastMessageToGametype("ctf", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("ctf"); return; } } } if (CTFGameRunning) { int redteamplayers = 0; int blueteamplayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "ctf") { if (!player.TSPlayer.TpLock) if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } if (player.Team == 1) redteamplayers++; else if (player.Team == 2) blueteamplayers++; if ((player.Team == 1 && Main.player[player.Index].team != 1)) TShock.Players[player.Index].SetTeam(1); else if (player.Team == 2 && Main.player[player.Index].team != 3) TShock.Players[player.Index].SetTeam(3); if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) player.Dead = true; else { if (player.Dead) { player.Dead = false; player.TSPlayer.TpLock = false; if (player.Team == 1) TShock.Players[player.Index].Teleport((int)flagPoints[0].X, (int)flagPoints[0].Y); else if (player.Team == 2) TShock.Players[player.Index].Teleport((int)flagPoints[1].X, (int)flagPoints[1].Y); if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } } //Grab flag if (!player.Dead) { if (player.Team == 1 && RedTeamFlagCarrier == null) { if ((int)player.tileX >= flagPoints[1].X - 2 && (int)player.tileX <= flagPoints[1].X + 2 && (int)player.tileY == (int)(flagPoints[1].Y - 3)) { RedTeamFlagCarrier = player; C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.OrangeRed); } } if (player.Team == 2 && BlueTeamFlagCarrier == null) { if ((int)player.tileX >= flagPoints[0].X - 2 && (int)player.tileX <= flagPoints[0].X + 2 && (int)player.tileY == (int)(flagPoints[0].Y - 3)) { BlueTeamFlagCarrier = player; C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index].name + " has the flag!", Color.LightBlue); } } } } } if (redteamplayers == 0 || blueteamplayers == 0) { C3Tools.BroadcastMessageToGametype("ctf", "Capture the Flag stopped, Not enough players to continue", Color.DarkCyan); CTFGameRunning = false; TpToSpawns(false); C3Tools.ResetGameType("ctf"); return; } //Check on flag carriers if (BlueTeamFlagCarrier != null) { //Make them drop the flag if (BlueTeamFlagCarrier.TerrariaDead) { C3Tools.BroadcastMessageToGametype("ctf", BlueTeamFlagCarrier.PlayerName + ": Dropped the flag!", Color.LightBlue); BlueTeamFlagCarrier = null; } //Capture the flag else { if ((int)BlueTeamFlagCarrier.tileX >= flagPoints[1].X - 2 && (int)BlueTeamFlagCarrier.tileX <= flagPoints[1].X + 2 && (int)BlueTeamFlagCarrier.tileY == (int)(flagPoints[1].Y - 3)) { BlueTeamScore++; BlueTeamFlagCarrier.Flags++; C3Tools.BroadcastMessageToGametype("ctf", BlueTeamFlagCarrier.PlayerName + ": Scores! Blue - " + BlueTeamScore.ToString() + " --- " + RedTeamScore.ToString() + " - Red", Color.LightBlue); RedTeamFlagCarrier = null; BlueTeamFlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && BlueTeamScore != C3Mod.C3Config.CTFScoreLimit) TpToFlag(); if (C3Mod.C3Config.ReCountdownOnFlagCapture && BlueTeamScore != C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; CTFGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = Tools.GetItemById(58); Item star = Tools.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } if (RedTeamFlagCarrier != null) { if (RedTeamFlagCarrier.TerrariaDead) { C3Tools.BroadcastMessageToGametype("ctf", RedTeamFlagCarrier.PlayerName + ": Dropped the flag!", Color.OrangeRed); RedTeamFlagCarrier = null; } else { if ((int)RedTeamFlagCarrier.tileX >= flagPoints[0].X - 2 && (int)RedTeamFlagCarrier.tileX <= flagPoints[0].X + 2 && (int)RedTeamFlagCarrier.tileY == (int)(flagPoints[0].Y - 3)) { RedTeamScore++; RedTeamFlagCarrier.Flags++; C3Tools.BroadcastMessageToGametype("ctf", RedTeamFlagCarrier.PlayerName + ": Scores! Red - " + RedTeamScore.ToString() + " --- " + BlueTeamScore.ToString() + " - Blue", Color.OrangeRed); RedTeamFlagCarrier = null; BlueTeamFlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && RedTeamScore != C3Mod.C3Config.CTFScoreLimit) TpToFlag(); if (C3Mod.C3Config.ReCountdownOnFlagCapture && RedTeamScore != C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; CTFGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = Tools.GetItemById(58); Item star = Tools.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } if (BlueTeamScore == C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; C3Tools.BroadcastMessageToGametype("ctf", "BLUE TEAM WINS!", Color.LightBlue); //C3Tools.BroadcastMessageToGametype("", "Blue team wins in a CTF and earn " + (BlueTeamScore * 0.2 + 0.5) + " RCoins!", Color.LightBlue); foreach (C3Player player in C3Mod.C3Players) { if (player.Team == 1) { TShock.Users.SetRCoins(player.PlayerName, (RedTeamScore * 0.1 + player.Flags * 0.2)); player.SendMessage("Your consolation prize is: " + (RedTeamScore * 0.1) + " RCoins!", Color.Green); if (player.Flags > 0) { player.SendMessage("Your extra prize for flags is: " + (player.Flags * 0.2) + " RCoins!", Color.Yellow); } } if (player.Team == 2) { TShock.Users.SetRCoins(player.PlayerName, (BlueTeamScore * 0.1 + player.Flags * 0.2 + 0.5)); player.SendMessage("Your award is: " + (BlueTeamScore * 0.1 + 0.5) + " RCoins!", Color.Green); if (player.Flags > 0) { player.SendMessage("Your extra prize for flags is: " + (player.Flags * 0.2) + " RCoins!", Color.Yellow); } } } TpToSpawns(false); C3Tools.ResetGameType("ctf"); return; } if (RedTeamScore == C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; C3Tools.BroadcastMessageToGametype("ctf", "RED TEAM WINS!", Color.OrangeRed); //C3Tools.BroadcastMessageToGametype("", "RED team wins in a CTF and earn " + (RedTeamScore * 0.2 + 0.5) + " RCoins!", Color.OrangeRed); foreach (C3Player player in C3Mod.C3Players) { if (player.Team == 2) { TShock.Users.SetRCoins(player.PlayerName, (BlueTeamScore * 0.1) + (player.Flags * 0.2)); player.SendMessage("Your consolation prize is: " + (BlueTeamScore * 0.1) + " RCoins!", Color.Green); if (player.Flags > 0) { player.SendMessage("Your extra prize for flags is: " + (player.Flags * 0.2) + " RCoins!", Color.Yellow); } } if (player.Team == 1) { TShock.Users.SetRCoins(player.PlayerName, (RedTeamScore * 0.1 + player.Flags * 0.2 + 0.5)); player.SendMessage("Your award is: " + (RedTeamScore * 0.1 + 0.5) + " RCoins!", Color.Green); if (player.Flags > 0) { player.SendMessage("Your extra prize for flags is: " + (player.Flags * 0.2) + " RCoins!", Color.Yellow); } } } TpToSpawns(false); C3Tools.ResetGameType("ctf"); return; } } }
public static void OnUpdate(EventArgs args) { lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.Challenging != null) { double tick = (DateTime.UtcNow - player.ChallengeTick).TotalMilliseconds; if (tick > (C3Mod.C3Config.DuelNotifyInterval * 1000)) { if (player.ChallengeNotifyCount != 1) { player.Challenging.SendMessage("You have been challenged to a duel by: " + player.PlayerName + " in Arena: " + Arenas[player.Challenging.ChallengeArena - 1].Name, Color.Cyan); player.Challenging.SendMessage("Type /accept to accept this challenge!", Color.Cyan); } player.ChallengeNotifyCount--; player.ChallengeTick = DateTime.UtcNow; } else if (player.ChallengeNotifyCount == 0) { player.Challenging.SendMessage("Challenge by: " + player.PlayerName + " timed out!", Color.Cyan); player.SendMessage(player.Challenging.PlayerName + ": Did not answer your challenge in the required amount of time!", Color.DarkCyan); player.Challenging = null; player.ChallengeNotifyCount = 5; } } } } if (DuelCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToSpawnPoint() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("1v1", "Fight!!!", Color.Cyan); StartCount = 5; DuelCountdown = false; DuelRunning = true; } else { C3Tools.BroadcastMessageToGametype("1v1", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("1v1"); return; } } } if (DuelRunning) { int Team1PlayerCount = 0; int Team2PlayerCount = 0; lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "1v1") { if (!player.TSPlayer.TpLock) if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } if (player.Team == 3) Team1PlayerCount++; else if (player.Team == 4) Team2PlayerCount++; if ((player.Team == 3 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor1)) TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor1); else if (player.Team == 4 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor2) TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor2); if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) { if (player.Team == 3) { Team2PlayerScore++; if (Team2PlayerScore != C3Mod.C3Config.DuelScoreLimit) { C3Tools.BroadcastMessageToGametype("1v1", Team2Player.PlayerName + " Scores!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " (" + Team1PlayerScore + ") - (" + Team2PlayerScore + ") " + Team2Player.PlayerName, Color.DarkCyan); TpToSpawnPoint(); DuelRunning = false; DuelCountdown = true; Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player players in C3Mod.C3Players) { if (players.GameType == "1v1") { players.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); players.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } else if (player.Team == 4) { Team1PlayerScore++; if (Team1PlayerScore != C3Mod.C3Config.DuelScoreLimit) { C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " Scores!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " (" + Team1PlayerScore + ") - (" + Team2PlayerScore + ") " + Team2Player.PlayerName, Color.DarkCyan); TpToSpawnPoint(); DuelRunning = false; DuelCountdown = true; Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player players in C3Mod.C3Players) { if (players.GameType == "1v1") { players.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); players.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } } if (Team1PlayerCount == 0 || Team2PlayerCount == 0) { C3Tools.BroadcastMessageToGametype("1v1", "Ending game because the opponent left!", Color.DarkCyan); DuelRunning = false; TpToSpawns(false); C3Tools.ResetGameType("1v1"); Team1Player = null; Team2Player = null; DuelSpawns = new Vector2[2]; return; } if (Team2PlayerScore == C3Mod.C3Config.DuelScoreLimit) { DuelRunning = false; C3Tools.BroadcastMessageToGametype("1v1", Team2Player.PlayerName + " won!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("", Team2Player.PlayerName + " defeated " + Team1Player.PlayerName + " in a duel!", Color.DarkCyan); List<C3Player> LostPlayers = new List<C3Player>(); List<C3Player> WonPlayers = new List<C3Player>(); WonPlayers.Add(Team2Player); LostPlayers.Add(Team1Player); C3Events.GameEnd(WonPlayers, LostPlayers, "1v1", Team2Player.FFAScore, Team1Player.FFAScore); TpToSpawns(false); C3Tools.ResetGameType("1v1"); Team1Player = null; Team2Player = null; DuelSpawns = new Vector2[2]; return; } if (Team1PlayerScore == C3Mod.C3Config.DuelScoreLimit) { DuelRunning = false; C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " won!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("", Team1Player.PlayerName + " defeated " + Team2Player.PlayerName + " in a duel!", Color.DarkCyan); List<C3Player> LostPlayers = new List<C3Player>(); List<C3Player> WonPlayers = new List<C3Player>(); WonPlayers.Add(Team1Player); LostPlayers.Add(Team2Player); C3Events.GameEnd(WonPlayers, LostPlayers, "1v1", Team1Player.FFAScore, Team2Player.FFAScore); TpToSpawns(false); C3Tools.ResetGameType("1v1"); Team1Player = null; Team2Player = null; DuelSpawns = new Vector2[2]; return; } } }
public static int TpToSpawnPoint() { try { bool Team1Player = false; bool Team2Player = false; for (int i = 0; i < C3Mod.C3Players.Count; i++) { if ((C3Mod.C3Players[i].Team == 3 && Main.player[C3Mod.C3Players[i].Index].team != C3Mod.C3Config.TeamColor1)) TShock.Players[C3Mod.C3Players[i].Index].SetTeam(C3Mod.C3Config.TeamColor1); else if (C3Mod.C3Players[i].Team == 4 && Main.player[C3Mod.C3Players[i].Index].team != C3Mod.C3Config.TeamColor2) TShock.Players[C3Mod.C3Players[i].Index].SetTeam(C3Mod.C3Config.TeamColor2); if (C3Mod.C3Players[i].Team == 3) { Team1Player = true; C3Mod.C3Players[i].TSPlayer.TpLock = false; if (C3Mod.C3Players[i].TSPlayer.X / 16 != DuelSpawns[0].X || C3Mod.C3Players[i].TSPlayer.Y / 16 + 3 != DuelSpawns[0].Y) { TShock.Players[C3Mod.C3Players[i].Index].Teleport((int)DuelSpawns[0].X * 16, (int)DuelSpawns[0].Y * 16); } if (C3Mod.C3Config.TPLockEnabled) { C3Mod.C3Players[i].TSPlayer.TpLock = true; } } else if (C3Mod.C3Players[i].Team == 4) { Team2Player = true; C3Mod.C3Players[i].TSPlayer.TpLock = false; if (C3Mod.C3Players[i].TSPlayer.X / 16 != DuelSpawns[1].X || C3Mod.C3Players[i].TSPlayer.Y / 16 + 3 != DuelSpawns[1].Y) { TShock.Players[C3Mod.C3Players[i].Index].Teleport((int)DuelSpawns[1].X * 16, (int)DuelSpawns[1].Y * 16); } if (C3Mod.C3Config.TPLockEnabled) { C3Mod.C3Players[i].TSPlayer.TpLock = true; } } } if (!Team1Player || !Team2Player) { C3Tools.BroadcastMessageToGametype("1v1", "Ending game, because the opponent left!", Color.DarkCyan); DuelRunning = false; DuelCountdown = false; DuelSpawns = new Vector2[2]; return 0; } return 1; } catch { return 0; } }
public static void OnUpdate(EventArgs args) { lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.Challenging != null) { double tick = (DateTime.UtcNow - player.ChallengeTick).TotalMilliseconds; if (tick > (C3Mod.C3Config.DuelNotifyInterval * 1000)) { if (player.ChallengeNotifyCount != 1) { player.Challenging.SendMessage("You have been challenged to a duel by: " + player.PlayerName + " in Arena: " + Arenas[player.Challenging.ChallengeArena - 1].Name, Color.Cyan); player.Challenging.SendMessage("Type /accept to accept this challenge!", Color.Cyan); } player.ChallengeNotifyCount--; player.ChallengeTick = DateTime.UtcNow; } else if (player.ChallengeNotifyCount == 0) { player.Challenging.SendMessage("Challenge by: " + player.PlayerName + " timed out!", Color.Cyan); player.SendMessage(player.Challenging.PlayerName + ": Did not answer your challenge in the required amount of time!", Color.DarkCyan); player.Challenging = null; player.ChallengeNotifyCount = 5; } } } } if (DuelCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToSpawnPoint() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("1v1", "Fight!!!", Color.Cyan); StartCount = 5; DuelCountdown = false; DuelRunning = true; } else { C3Tools.BroadcastMessageToGametype("1v1", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("1v1"); return; } } } if (DuelRunning) { int Team1PlayerCount = 0; int Team2PlayerCount = 0; lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "1v1") { if (!player.TSPlayer.TpLock) { if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } if (player.Team == 3) { Team1PlayerCount++; } else if (player.Team == 4) { Team2PlayerCount++; } if ((player.Team == 3 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor1)) { TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor1); } else if (player.Team == 4 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor2) { TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor2); } if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) { if (player.Team == 3) { Team2PlayerScore++; if (Team2PlayerScore != C3Mod.C3Config.DuelScoreLimit) { C3Tools.BroadcastMessageToGametype("1v1", Team2Player.PlayerName + " Scores!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " (" + Team1PlayerScore + ") - (" + Team2PlayerScore + ") " + Team2Player.PlayerName, Color.DarkCyan); TpToSpawnPoint(); DuelRunning = false; DuelCountdown = true; Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player players in C3Mod.C3Players) { if (players.GameType == "1v1") { players.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); players.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } else if (player.Team == 4) { Team1PlayerScore++; if (Team1PlayerScore != C3Mod.C3Config.DuelScoreLimit) { C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " Scores!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " (" + Team1PlayerScore + ") - (" + Team2PlayerScore + ") " + Team2Player.PlayerName, Color.DarkCyan); TpToSpawnPoint(); DuelRunning = false; DuelCountdown = true; Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player players in C3Mod.C3Players) { if (players.GameType == "1v1") { players.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); players.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } } if (Team1PlayerCount == 0 || Team2PlayerCount == 0) { C3Tools.BroadcastMessageToGametype("1v1", "Ending game because the opponent left!", Color.DarkCyan); DuelRunning = false; TpToSpawns(false); C3Tools.ResetGameType("1v1"); Team1Player = null; Team2Player = null; DuelSpawns = new Vector2[2]; return; } if (Team2PlayerScore == C3Mod.C3Config.DuelScoreLimit) { DuelRunning = false; C3Tools.BroadcastMessageToGametype("1v1", Team2Player.PlayerName + " won!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("", Team2Player.PlayerName + " defeated " + Team1Player.PlayerName + " in a duel!", Color.DarkCyan); List <C3Player> LostPlayers = new List <C3Player>(); List <C3Player> WonPlayers = new List <C3Player>(); WonPlayers.Add(Team2Player); LostPlayers.Add(Team1Player); C3Events.GameEnd(WonPlayers, LostPlayers, "1v1", Team2Player.FFAScore, Team1Player.FFAScore); TpToSpawns(false); C3Tools.ResetGameType("1v1"); Team1Player = null; Team2Player = null; DuelSpawns = new Vector2[2]; return; } if (Team1PlayerScore == C3Mod.C3Config.DuelScoreLimit) { DuelRunning = false; C3Tools.BroadcastMessageToGametype("1v1", Team1Player.PlayerName + " won!", Color.DarkCyan); C3Tools.BroadcastMessageToGametype("", Team1Player.PlayerName + " defeated " + Team2Player.PlayerName + " in a duel!", Color.DarkCyan); List <C3Player> LostPlayers = new List <C3Player>(); List <C3Player> WonPlayers = new List <C3Player>(); WonPlayers.Add(Team1Player); LostPlayers.Add(Team2Player); C3Events.GameEnd(WonPlayers, LostPlayers, "1v1", Team1Player.FFAScore, Team2Player.FFAScore); TpToSpawns(false); C3Tools.ResetGameType("1v1"); Team1Player = null; Team2Player = null; DuelSpawns = new Vector2[2]; return; } } }
public static void OnUpdate(EventArgs args) { lock (C3Mod.C3Players) { if (C3Mod.VoteRunning && C3Mod.VoteType == "oneflag") { int VotedPlayers = 0; int TotalPlayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "" || player.GameType == "oneflag") { TotalPlayers++; } if (player.GameType == "oneflag") { VotedPlayers++; } } if (VotedPlayers == TotalPlayers) { C3Tools.BroadcastMessageToGametype("oneflag", "Vote to play Capture One Flag passed! Teleporting to start positions!", Color.DarkCyan); C3Mod.VoteRunning = false; C3Mod.VoteType = ""; FlagCarrier = null; Team1Score = 0; Team2Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; TpToOneFlagSpawns(); countDownTick = DateTime.UtcNow; OneFlagGameCountdown = true; return; } double tick = (DateTime.UtcNow - voteCountDown).TotalMilliseconds; if (tick > (C3Mod.C3Config.VoteNotifyInterval * 1000) && VoteCount > 0) { if (VoteCount != 1 && VoteCount < (C3Mod.C3Config.VoteTime / C3Mod.C3Config.VoteNotifyInterval)) { C3Tools.BroadcastMessageToGametype("oneflag", "Vote still in progress, please be patient!", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "Vote to play Capture One Flag in progress, type /join to join the lobby!", Color.Cyan); } VoteCount--; voteCountDown = DateTime.UtcNow; } else if (VoteCount == 0) { C3Mod.VoteRunning = false; int redteamplayers = 0; int blueteamplayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.Team == 5) { redteamplayers++; } else if (player.Team == 6) { blueteamplayers++; } } if (redteamplayers >= C3Mod.C3Config.VoteMinimumPerTeam && blueteamplayers >= C3Mod.C3Config.VoteMinimumPerTeam) { C3Tools.BroadcastMessageToGametype("oneflag", "Vote to play Capture One Flag passed! Teleporting to start positions!", Color.DarkCyan); FlagCarrier = null; Team1Score = 0; Team2Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; TpToOneFlagSpawns(); countDownTick = DateTime.UtcNow; OneFlagGameCountdown = true; } else { C3Tools.BroadcastMessageToGametype("oneflag", "Vote to play Capture One Flag failed. Not enough players!", Color.DarkCyan); } } } if (OneFlagGameCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToOneFlagSpawns() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("oneflag", "Capture the flag!!!", Color.Cyan); StartCount = 5; OneFlagGameCountdown = false; OneFlagGameRunning = true; } else { C3Tools.BroadcastMessageToGametype("oneflag", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("oneflag"); return; } } } if (OneFlagGameRunning) { int team1players = 0; int team2players = 0; lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "oneflag") { if (!player.TSPlayer.TpLock) { if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } if (player.Team == 5) { team1players++; } else if (player.Team == 6) { team2players++; } if ((player.Team == 5 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor1)) { TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor1); } else if (player.Team == 6 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor2) { TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor2); } if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) { player.Dead = true; } else { if (player.Dead) { player.Dead = false; player.TSPlayer.TpLock = false; if (player.Team == 5) { TShock.Players[player.Index].Teleport((int)SpawnPoint[0].X * 16, (int)SpawnPoint[0].Y * 16); } else if (player.Team == 6) { TShock.Players[player.Index].Teleport((int)SpawnPoint[1].X * 16, (int)SpawnPoint[1].Y * 16); } NetMessage.SendData(4, -1, player.Index, player.PlayerName, player.Index, 0f, 0f, 0f, 0); if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } } //Grab flag if (!player.Dead) { if (FlagCarrier == null) { if ((int)player.tileX <= (int)FlagPoint.X + 2 && (int)player.tileX >= (int)FlagPoint.X - 2 && (int)player.tileY == (int)FlagPoint.Y - 3) { FlagCarrier = player; if (player.Team == 5) { switch (C3Mod.C3Config.TeamColor1) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightYellow); break; } } } else if (player.Team == 6) { switch (C3Mod.C3Config.TeamColor2) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", Main.player[player.Index] .name + " has the flag!", Color.LightYellow); break; } } } C3Events.FlagGrabbed(FlagCarrier, "oneflag"); } } } } } } if (team1players == 0 || team2players == 0) { C3Tools.BroadcastMessageToGametype("oneflag", "Ending game, because not enough players to continue!", Color.DarkCyan); OneFlagGameRunning = false; SendToSpawn(false); C3Tools.ResetGameType("oneflag"); return; } //Check on flag carrier if (FlagCarrier != null) { //Make them drop the flag if (Main.player[FlagCarrier.Index].dead) { if (FlagCarrier.Team == 5) { switch (C3Mod.C3Config.TeamColor1) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightYellow); break; } } } else if (FlagCarrier.Team == 6) { switch (C3Mod.C3Config.TeamColor2) { case 1: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " dropped the flag!", Color.LightYellow); break; } } } FlagCarrier = null; } //Capture the flag else { if (FlagCarrier.Team == 5) { if ((int)FlagCarrier.tileX <= (int)SpawnPoint[0].X + 2 && (int)FlagCarrier.tileX >= (int)SpawnPoint[0].X - 2 && (int)FlagCarrier.tileY == (int)SpawnPoint[0].Y - 3) { Team1Score++; switch (C3Mod.C3Config.TeamColor1) { case 1: { if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Red (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Green", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Red (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Blue", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Red (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Yellow", Color.OrangeRed); } break; } case 2: { if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Green (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Red", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Green (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Blue", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Green (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Yellow", Color.LightGreen); } break; } case 3: { if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Blue (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Red", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Blue (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Green", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Blue (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Yellow", Color.LightBlue); } break; } case 4: { if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Yellow (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Red", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Yellow (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Green", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Yellow (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Blue", Color.LightYellow); } break; } } C3Events.FlagCapture(FlagCarrier, "oneflag", "Team1", Team1Score, Team2Score); FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) { TpToOneFlagSpawns(); } if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; OneFlagGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } else if (FlagCarrier.Team == 6) { if ((int)FlagCarrier.tileX <= (int)SpawnPoint[1].X + 2 && (int)FlagCarrier.tileX >= (int)SpawnPoint[1].X - 2 && (int)FlagCarrier.tileY == (int)SpawnPoint[1].Y - 3) { Team2Score++; switch (C3Mod.C3Config.TeamColor2) { case 1: { if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Red (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Green", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Red (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Blue", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Red (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Yellow", Color.OrangeRed); } break; } case 2: { if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Green (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Red", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Green (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Blue", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Green (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Yellow", Color.LightGreen); } break; } case 3: { if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Blue (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Red", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Blue (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Green", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Blue (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Yellow", Color.LightBlue); } break; } case 4: { if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Yellow (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Red", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Yellow (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Green", Color.LightYellow); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("oneflag", FlagCarrier.PlayerName + " Scores! Yellow (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Blue", Color.LightYellow); } break; } } C3Events.FlagCapture(FlagCarrier, "oneflag", "Team2", Team2Score, Team1Score); FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) { TpToOneFlagSpawns(); } if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; OneFlagGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } if (Team1Score == C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; if (C3Mod.C3Config.TeamColor2 == 1) { C3Tools.BroadcastMessageToGametype("ctf", "Red Team wins!", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor2 == 2) { C3Tools.BroadcastMessageToGametype("ctf", "Green Team wins!", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor2 == 3) { C3Tools.BroadcastMessageToGametype("ctf", "Blue Team wins!", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor2 == 4) { C3Tools.BroadcastMessageToGametype("ctf", "Yellow Team wins!", Color.LightYellow); } List <C3Player> LostPlayers = new List <C3Player>(); List <C3Player> WonPlayers = new List <C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "oneflag") { if (player1.Team == 6) { WonPlayers.Add(player1); } if (player1.Team == 5) { LostPlayers.Add(player1); } } } C3Events.GameEnd(WonPlayers, LostPlayers, "oneflag", Team2Score, Team1Score); SendToSpawn(false); C3Tools.ResetGameType("oneflag"); OneFlagCTF.FlagPoint = new Vector2(); OneFlagCTF.SpawnPoint = new Vector2[2]; return; } if (Team2Score == C3Mod.C3Config.CTFScoreLimit) { OneFlagGameRunning = false; if (C3Mod.C3Config.TeamColor1 == 1) { C3Tools.BroadcastMessageToGametype("ctf", "Red Team wins!", Color.OrangeRed); } else if (C3Mod.C3Config.TeamColor1 == 2) { C3Tools.BroadcastMessageToGametype("ctf", "Green Team wins!", Color.LightGreen); } else if (C3Mod.C3Config.TeamColor1 == 3) { C3Tools.BroadcastMessageToGametype("ctf", "Blue Team wins!", Color.LightBlue); } else if (C3Mod.C3Config.TeamColor1 == 4) { C3Tools.BroadcastMessageToGametype("ctf", "Yellow Team wins!", Color.LightYellow); } List <C3Player> LostPlayers = new List <C3Player>(); List <C3Player> WonPlayers = new List <C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "oneflag") { if (player1.Team == 5) { WonPlayers.Add(player1); } if (player1.Team == 6) { LostPlayers.Add(player1); } } } C3Events.GameEnd(WonPlayers, LostPlayers, "oneflag", Team1Score, Team2Score); SendToSpawn(false); C3Tools.ResetGameType("oneflag"); OneFlagCTF.FlagPoint = new Vector2(); OneFlagCTF.SpawnPoint = new Vector2[2]; return; } } } }
public static void OnUpdate(EventArgs args) { lock (C3Mod.C3Players) { if (C3Mod.VoteRunning && C3Mod.VoteType == "ctf") { int VotedPlayers = 0; int TotalPlayers = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "" || player.GameType == "ctf") TotalPlayers++; if (player.GameType == "ctf") VotedPlayers++; } if (VotedPlayers == TotalPlayers) { C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag passed! Teleporting to start positions!", Color.DarkCyan); C3Mod.VoteRunning = false; C3Mod.VoteType = ""; CTF.Team2FlagCarrier = null; CTF.Team1FlagCarrier = null; CTF.Team2Score = 0; CTF.Team1Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; CTF.TpToSpawn(); CTF.countDownTick = DateTime.UtcNow; CTF.CTFGameCountdown = true; return; } double tick = (DateTime.UtcNow - voteCountDown).TotalMilliseconds; if (tick > (C3Mod.C3Config.VoteNotifyInterval * 1000) && VoteCount > 0) { if (VoteCount != 1 && VoteCount < (C3Mod.C3Config.VoteTime / C3Mod.C3Config.VoteNotifyInterval)) { C3Tools.BroadcastMessageToGametype("ctf", "Vote still in progress, please be patient!", Color.Cyan); C3Tools.BroadcastMessageToGametype("", "Vote to play Capture the Flag in progress, type /join to join the lobby!", Color.Cyan); } VoteCount--; voteCountDown = DateTime.UtcNow; } else if (VoteCount == 0) { C3Mod.VoteRunning = false; int team1players = 0; int team2players = 0; foreach (C3Player player in C3Mod.C3Players) { if (player.Team == 1) team1players++; else if (player.Team == 2) team2players++; } if (team1players >= C3Mod.C3Config.VoteMinimumPerTeam && team2players >= C3Mod.C3Config.VoteMinimumPerTeam) { C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag passed, Teleporting to start position!", Color.DarkCyan); CTF.Team2FlagCarrier = null; CTF.Team1FlagCarrier = null; CTF.Team2Score = 0; CTF.Team1Score = 0; bool[] playersDead = new bool[Main.maxNetPlayers]; CTF.TpToSpawn(); CTF.countDownTick = DateTime.UtcNow; CTF.CTFGameCountdown = true; } else C3Tools.BroadcastMessageToGametype("ctf", "Vote to play Capture the Flag failed. Not enough players!", Color.DarkCyan); } } if (CTFGameCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToSpawn() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("ctf", "Capture...The...Flag!!!", Color.Cyan); StartCount = 5; CTFGameCountdown = false; CTFGameRunning = true; } else { C3Tools.BroadcastMessageToGametype("ctf", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("ctf"); return; } } } if (CTFGameRunning) { int team1players = 0; int team2players = 0; lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "ctf") { if (!player.TSPlayer.TpLock) if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } if (player.Team == 1) team1players++; else if (player.Team == 2) team2players++; if ((player.Team == 1 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor1)) TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor1); if ((player.Team == 2 && Main.player[player.Index].team != C3Mod.C3Config.TeamColor2)) TShock.Players[player.Index].SetTeam(C3Mod.C3Config.TeamColor2); if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) player.Dead = true; else { if (player.Dead) { player.Dead = false; player.TSPlayer.TpLock = false; if (player.Team == 1) TShock.Players[player.Index].Teleport((int)spawnPoints[0].X * 16, (int)spawnPoints[0].Y * 16); else if (player.Team == 2) TShock.Players[player.Index].Teleport((int)spawnPoints[1].X * 16, (int)spawnPoints[1].Y * 16); NetMessage.SendData(4, -1, player.Index, player.PlayerName, player.Index, 0f, 0f, 0f, 0); if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } } } //Grab flag if (!player.Dead) { if (player.Team == 1 && Team1FlagCarrier == null) { if ((int)player.tileX >= flagPoints[1].X - 2 && (int)player.tileX <= flagPoints[1].X + 2 && (int)player.tileY == (int)(flagPoints[1].Y - 3)) { Team1FlagCarrier = player; switch (C3Mod.C3Config.TeamColor1) { case 1: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.LightYellow); break; } } C3Events.FlagGrabbed(player, "ctf"); } } if (player.Team == 2 && Team2FlagCarrier == null) { if ((int)player.tileX >= flagPoints[0].X - 2 && (int)player.tileX <= flagPoints[0].X + 2 && (int)player.tileY == (int)(flagPoints[0].Y - 3)) { Team2FlagCarrier = player; switch (C3Mod.C3Config.TeamColor2) { case 1: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.OrangeRed); break; } case 2: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.LightGreen); break; } case 3: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.LightBlue); break; } case 4: { C3Tools.BroadcastMessageToGametype("ctf", Main.player[player.Index]. name + " has the flag!", Color.LightYellow); break; } } C3Events.FlagGrabbed(player, "ctf"); } } } } } } if (team1players == 0 || team2players == 0) { C3Tools.BroadcastMessageToGametype("ctf", "Ending game, because not enough players to continue!", Color.DarkCyan); CTFGameRunning = false; TpToSpawns(false); C3Tools.ResetGameType("ctf"); flagPoints = new Vector2[2]; spawnPoints = new Vector2[2]; return; } //Check on flag carriers if (Team2FlagCarrier != null) { //Make them drop the flag if (Team2FlagCarrier.TerrariaDead) { C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " dropped the flag!", Color.LightBlue); Team2FlagCarrier = null; } //Capture the flag else { if ((int)Team2FlagCarrier.tileX >= flagPoints[1].X - 2 && (int)Team2FlagCarrier.tileX <= flagPoints[1].X + 2 && (int)Team2FlagCarrier.tileY == (int)(flagPoints[1].Y - 3)) { Team2Score++; switch (C3Mod.C3Config.TeamColor2) { case 1: { if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Red (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Green", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Red (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Blue", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Red (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Yellow", Color.OrangeRed); break; } case 2: { if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Green (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Red", Color.LightGreen); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Green (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Blue", Color.LightGreen); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Green (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Yellow", Color.LightGreen); break; } case 3: { if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Blue (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Red", Color.LightBlue); else if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Blue (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Green", Color.LightBlue); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Blue (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Yellow", Color.LightBlue); break; } case 4: { if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Yellow (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Red", Color.LightYellow); else if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Yellow (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Green", Color.LightYellow); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("ctf", Team2FlagCarrier.PlayerName + " Scores! Yellow (" + Team2Score.ToString() + ") - (" + Team1Score.ToString() + ") Blue", Color.LightYellow); break; } } C3Events.FlagCapture(Team2FlagCarrier, "ctf", "Team2", Team2Score, Team1Score); Team2FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) { Team1FlagCarrier = null; TpToSpawn(); } if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team2Score != C3Mod.C3Config.CTFScoreLimit) { Team1FlagCarrier = null; CTFGameRunning = false; CTFGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } if (Team1FlagCarrier != null) { if (Team1FlagCarrier.TerrariaDead) { C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " dropped the flag!", Color.OrangeRed); Team1FlagCarrier = null; } else { if ((int)Team1FlagCarrier.tileX >= flagPoints[0].X - 2 && (int)Team1FlagCarrier.tileX <= flagPoints[0].X + 2 && (int)Team1FlagCarrier.tileY == (int)(flagPoints[0].Y - 3)) { Team1Score++; switch (C3Mod.C3Config.TeamColor1) { case 1: { if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Red (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Green", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Red (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Blue", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Red (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Yellow", Color.OrangeRed); break; } case 2: { if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Green (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Red", Color.LightGreen); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Green (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Blue", Color.LightGreen); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Green (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Yellow", Color.LightGreen); break; } case 3: { if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Blue (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Red", Color.LightBlue); else if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Blue (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Green", Color.LightBlue); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Blue (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Yellow", Color.LightBlue); break; } case 4: { if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Yellow (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Red", Color.LightYellow); else if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Yellow (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Green", Color.LightYellow); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("ctf", Team1FlagCarrier.PlayerName + " Scores! Yellow (" + Team1Score.ToString() + ") - (" + Team2Score.ToString() + ") Blue", Color.LightYellow); break; } } C3Events.FlagCapture(Team1FlagCarrier, "ctf", "Team1", Team1Score, Team2Score); Team1FlagCarrier = null; if (C3Mod.C3Config.RespawnPlayersOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) { Team2FlagCarrier = null; TpToSpawn(); } if (C3Mod.C3Config.ReCountdownOnFlagCapture && Team1Score != C3Mod.C3Config.CTFScoreLimit) { Team2FlagCarrier = null; CTFGameRunning = false; CTFGameCountdown = true; } if (C3Mod.C3Config.HealPlayersOnFlagCapture) { Item heart = TShock.Utils.GetItemById(58); Item star = TShock.Utils.GetItemById(184); foreach (C3Player player in C3Mod.C3Players) { if (player.GameType == "ctf") { player.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); player.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } if (Team2Score == C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; if (C3Mod.C3Config.TeamColor2 == 1) C3Tools.BroadcastMessageToGametype("ctf", "Red Team wins!", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor2 == 2) C3Tools.BroadcastMessageToGametype("ctf", "Green Team wins!", Color.LightGreen); else if (C3Mod.C3Config.TeamColor2 == 3) C3Tools.BroadcastMessageToGametype("ctf", "Blue Team wins!", Color.LightBlue); else if (C3Mod.C3Config.TeamColor2 == 4) C3Tools.BroadcastMessageToGametype("ctf", "Yellow Team wins!", Color.LightYellow); List<C3Player> LostPlayers = new List<C3Player>(); List<C3Player> WonPlayers = new List<C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "ctf") { if (player1.Team == 2) WonPlayers.Add(player1); if (player1.Team == 1) LostPlayers.Add(player1); } } C3Events.GameEnd(WonPlayers, LostPlayers, "ctf", Team2Score, Team1Score); TpToSpawns(false); C3Tools.ResetGameType("ctf"); flagPoints = new Vector2[2]; spawnPoints = new Vector2[2]; return; } if (Team1Score == C3Mod.C3Config.CTFScoreLimit) { CTFGameRunning = false; if (C3Mod.C3Config.TeamColor1 == 1) C3Tools.BroadcastMessageToGametype("ctf", "Red Team wins!", Color.OrangeRed); else if (C3Mod.C3Config.TeamColor1 == 2) C3Tools.BroadcastMessageToGametype("ctf", "Green Team wins!", Color.LightGreen); else if (C3Mod.C3Config.TeamColor1 == 3) C3Tools.BroadcastMessageToGametype("ctf", "Blue Team wins!", Color.LightBlue); else if (C3Mod.C3Config.TeamColor1 == 4) C3Tools.BroadcastMessageToGametype("ctf", "Yellow Team wins!", Color.LightYellow); List<C3Player> LostPlayers = new List<C3Player>(); List<C3Player> WonPlayers = new List<C3Player>(); foreach (C3Player player1 in C3Mod.C3Players) { if (player1.GameType == "ctf") { if (player1.Team == 1) WonPlayers.Add(player1); if (player1.Team == 2) LostPlayers.Add(player1); } } C3Events.GameEnd(WonPlayers, LostPlayers, "ctf", Team1Score, Team2Score); TpToSpawns(false); C3Tools.ResetGameType("ctf"); flagPoints = new Vector2[2]; spawnPoints = new Vector2[2]; return; } } }
public static void OnUpdate(GameTime gameTime) { lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.Challenging != null) { double tick = (DateTime.UtcNow - player.ChallengeTick).TotalMilliseconds; if (tick > (C3Mod.C3Config.DuelNotifyInterval * 1000)) { if (player.ChallengeNotifyCount != 1) { player.Challenging.SendMessage("You have been challenged to a duel by: " + player.PlayerName, Color.Cyan); player.Challenging.SendMessage("Type /accept to accept this challenge!", Color.Cyan); } player.ChallengeNotifyCount--; player.ChallengeTick = DateTime.UtcNow; } else if (player.ChallengeNotifyCount == 0) { player.Challenging.SendMessage("Challenge by: " + player.PlayerName + " timed out", Color.Cyan); player.SendMessage(player.Challenging.PlayerName + ": Did not answer your challenge in the required amount of time", Color.DarkCyan); player.Challenging = null; player.ChallengeNotifyCount = 5; } } } } if (DuelCountdown) { double tick = (DateTime.UtcNow - countDownTick).TotalMilliseconds; if (tick > 1000 && StartCount > -1) { if (TpToSpawnPoint() > 0) { if (StartCount == 0) { C3Tools.BroadcastMessageToGametype("1v1", "Fight!!!", Color.Cyan); StartCount = 5; DuelCountdown = false; DuelRunning = true; } else { C3Tools.BroadcastMessageToGametype("1v1", "Game starting in " + StartCount.ToString() + "...", Color.Cyan); countDownTick = DateTime.UtcNow; StartCount--; } } else { StartCount = 5; C3Tools.ResetGameType("1v1"); return; } } } if (DuelRunning) { int RedTeamPlayer = 0; int BlueTeamPlayer = 0; lock (C3Mod.C3Players) { foreach (C3Player player in C3Mod.C3Players) { if (player.TSPlayer == null) { C3Mod.C3Players.Remove(player); break; } if (player.GameType == "1v1") { if (!player.TSPlayer.TpLock) if (C3Mod.C3Config.TPLockEnabled) { player.TSPlayer.TpLock = true; } if (player.Team == 3) RedTeamPlayer++; else if (player.Team == 4) BlueTeamPlayer++; if ((player.Team == 3 && Main.player[player.Index].team != 1)) TShock.Players[player.Index].SetTeam(1); else if (player.Team == 4 && Main.player[player.Index].team != 3) TShock.Players[player.Index].SetTeam(3); if (!Main.player[player.Index].hostile) { Main.player[player.Index].hostile = true; NetMessage.SendData((int)PacketTypes.TogglePvp, -1, -1, "", player.Index, 0f, 0f, 0f); } //Respawn on flag if (Main.player[player.Index].dead) { if (player.Team == 3) { BluePlayerScore++; if (BluePlayerScore != C3Mod.C3Config.DuelScoreLimit) { C3Tools.BroadcastMessageToGametype("1v1", BluePlayer.PlayerName + ": Scores!", Color.DarkCyan); TpToSpawnPoint(); DuelRunning = false; DuelCountdown = true; Item heart = Tools.GetItemById(58); Item star = Tools.GetItemById(184); foreach (C3Player players in C3Mod.C3Players) { if (players.GameType == "1v1") { players.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); players.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } else if (player.Team == 4) { RedPlayerScore++; if (RedPlayerScore != C3Mod.C3Config.DuelScoreLimit) { C3Tools.BroadcastMessageToGametype("1v1", RedPlayer.PlayerName + ": Scores!", Color.DarkCyan); TpToSpawnPoint(); DuelRunning = false; DuelCountdown = true; Item heart = Tools.GetItemById(58); Item star = Tools.GetItemById(184); foreach (C3Player players in C3Mod.C3Players) { if (players.GameType == "1v1") { players.GiveItem(heart.type, heart.name, heart.width, heart.height, 20); players.GiveItem(star.type, star.name, star.width, star.height, 20); } } } } } } } } if (RedTeamPlayer == 0 || BlueTeamPlayer == 0) { C3Tools.BroadcastMessageToGametype("1v1", "Opponent left, ending game", Color.DarkCyan); DuelRunning = false; TpToSpawns(false); C3Tools.ResetGameType("1v1"); RedPlayer = null; BluePlayer = null; return; } if (BluePlayerScore == C3Mod.C3Config.DuelScoreLimit) { DuelRunning = false; TShock.Users.SetRCoins(BluePlayer.PlayerName, (BluePlayerScore * 0.2 + 0.5)); TShock.Users.SetRCoins(RedPlayer.PlayerName, RedPlayerScore * 0.1); C3Tools.BroadcastMessageToGametype("1v1", BluePlayer.PlayerName + ": WINS!", Color.LightBlue); C3Tools.BroadcastMessageToGametype("", BluePlayer.PlayerName + ": Beat " + RedPlayer.PlayerName + " in a duel and earn " + (BluePlayerScore * 0.2 + 0.5) + " RCoins!", Color.LightBlue); RedPlayer.SendMessage("Your consolation prize is: " + (RedPlayerScore * 0.1) + " RCoins!", Color.Green); BluePlayer.SendMessage("Your award is: " + (RedPlayerScore * 0.2) + " RCoins!", Color.Green); TpToSpawns(false); C3Tools.ResetGameType("1v1"); RedPlayer = null; BluePlayer = null; return; } if (RedPlayerScore == C3Mod.C3Config.DuelScoreLimit) { DuelRunning = false; TShock.Users.SetRCoins(RedPlayer.PlayerName, (RedPlayerScore * 0.2 + 0.5)); TShock.Users.SetRCoins(BluePlayer.PlayerName, RedPlayerScore * 0.1); C3Tools.BroadcastMessageToGametype("1v1", RedPlayer.PlayerName + ": WINS!", Color.OrangeRed); C3Tools.BroadcastMessageToGametype("", RedPlayer.PlayerName + ": Beat " + BluePlayer.PlayerName + " in a duel and earn " + (BluePlayerScore * 0.2 + 0.5) + " RCoins!", Color.OrangeRed); BluePlayer.SendMessage("Your consolation prize is: " + (BluePlayerScore * 0.1) + " RCoins!", Color.Green); RedPlayer.SendMessage("Your award is: " + (RedPlayerScore * 0.2) + " RCoins!", Color.Green); TpToSpawns(false); C3Tools.ResetGameType("1v1"); RedPlayer = null; BluePlayer = null; return; } } }