From a854582a0d71a7e73cf9eccfc477fe932e45a2e1 Mon Sep 17 00:00:00 2001 From: PintTheDragon Date: Tue, 23 Jun 2020 00:56:17 -0700 Subject: [PATCH] Changed how spawning works --- Buddy.cs | 3 ++- Buddy.csproj | 1 + RoundRestartHandler.cs | 26 ++++++++++++++++++++++++++ RoundStartHandler.cs | 26 ++++++++++++++++---------- 4 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 RoundRestartHandler.cs diff --git a/Buddy.cs b/Buddy.cs index a43aa89..4548747 100644 --- a/Buddy.cs +++ b/Buddy.cs @@ -20,7 +20,7 @@ namespace PintBuddy id = "com.PintTheDragon.BuddyPlugin", configPrefix = "buddy", langFile = "buddyplugin", - version = "1.1.3", + version = "1.1.5", SmodMajor = 3, SmodMinor = 7, SmodRevision = 0 @@ -106,6 +106,7 @@ public override void Register() this.AddEventHandler(typeof(IEventHandlerRoundStart), new RoundStartHandler(this), Priority.Highest); this.AddEventHandler(typeof(IEventHandlerCallCommand), new CommandHandler(this), Priority.Normal); this.AddEventHandler(typeof(IEventHandlerPlayerJoin), new JoinHandler(this), Priority.Normal); + this.AddEventHandler(typeof(IEventHandlerRoundRestart), new RoundRestartHandler(this), Priority.Normal); this.prefixedMessage = BuddyMessage.Replace("$buddyCMD", "."+buddyCommand); this.invalidUsage = invalidUsage.Replace("$buddyCMD", "." + buddyCommand); } diff --git a/Buddy.csproj b/Buddy.csproj index d5d1887..7e2f8be 100644 --- a/Buddy.csproj +++ b/Buddy.csproj @@ -57,6 +57,7 @@ + diff --git a/RoundRestartHandler.cs b/RoundRestartHandler.cs new file mode 100644 index 0000000..2c428ed --- /dev/null +++ b/RoundRestartHandler.cs @@ -0,0 +1,26 @@ +using Smod2.API; +using Smod2.EventHandlers; +using Smod2.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PintBuddy +{ + class RoundRestartHandler : IEventHandlerRoundRestart + { + private Buddy buddyPlugin; + + public RoundRestartHandler(Buddy buddyPlugin) + { + this.buddyPlugin = buddyPlugin; + } + + public void OnRoundRestart(RoundRestartEvent ev) + { + buddyPlugin.buddies = new Dictionary(); + } + } +} diff --git a/RoundStartHandler.cs b/RoundStartHandler.cs index 18deb9b..70f699d 100644 --- a/RoundStartHandler.cs +++ b/RoundStartHandler.cs @@ -3,6 +3,7 @@ using Smod2.Events; using System; using System.Collections.Generic; +using System.Linq; namespace PintBuddy { @@ -19,12 +20,13 @@ public RoundStartHandler(Buddy buddyPlugin) public void OnRoundStart(RoundStartEvent ev) { - List players = ev.Server.GetPlayers(); + IEnumerable players = buddyPlugin.buddies.Values; + List doneIDs = new List(); //loop through all players - for(int i = 0; i < players.Count; i++) + for (int i = 0; i < players.Count(); i++) { - Player player = players[i]; + Player player = players.ElementAt(i); //check if player has a buddy if (buddyPlugin.buddies.ContainsKey(player.UserId)) { @@ -33,8 +35,9 @@ public void OnRoundStart(RoundStartEvent ev) Player buddy = null; buddyPlugin.buddies.TryGetValue(player.UserId, out buddy); if (buddy == null) continue; + if (doneIDs.Contains(player.UserId) || doneIDs.Contains(buddy.UserId)) continue; //take action if they have different roles - if(player.TeamRole.Role != buddy.TeamRole.Role && + if (player.TeamRole.Role != buddy.TeamRole.Role && /* massive check for scientist/guard combo */ !(!buddyPlugin.disallowGuardScientistCombo && ((player.TeamRole.Role == RoleType.FACILITY_GUARD && buddy.TeamRole.Role == RoleType.SCIENTIST) || (player.TeamRole.Role == RoleType.SCIENTIST && buddy.TeamRole.Role == RoleType.FACILITY_GUARD))) ) @@ -46,7 +49,8 @@ public void OnRoundStart(RoundStartEvent ev) if (buddyPlugin.forceExactRole) { buddy.ChangeRole(player.TeamRole.Role); - players = ev.Server.GetPlayers(); + doneIDs.Add(buddy.UserId); + doneIDs.Add(player.UserId); continue; } //if they are an scp, we need to remove another scp first @@ -54,16 +58,16 @@ public void OnRoundStart(RoundStartEvent ev) { //loop through every scp and swap the buddy with one of them Boolean setRole = false; - for (int y = 0; y < players.Count; y++) + foreach (Player player1 in ev.Server.GetPlayers()) { - Player player1 = players[y]; //check if the player is an scp if (player1.UserId != player.UserId && player1.UserId != buddy.UserId && !buddyPlugin.buddies.ContainsKey(player1.UserId) && player1.TeamRole.Team == TeamType.SCP) { //set the buddy to that player's role and set the player to classd buddy.ChangeRole(player1.TeamRole.Role); player1.ChangeRole(RoleType.CLASSD); - players = ev.Server.GetPlayers(); + doneIDs.Add(buddy.UserId); + doneIDs.Add(player.UserId); setRole = true; break; } @@ -73,13 +77,15 @@ public void OnRoundStart(RoundStartEvent ev) List roles = new List(tmpArr); roles.Remove(player.TeamRole.Role); buddy.ChangeRole(roles[rnd.Next(roles.Count)]); - players = ev.Server.GetPlayers(); + doneIDs.Add(buddy.UserId); + doneIDs.Add(player.UserId); } continue; } //if they are not an scp, we can just set them to the same role as their buddy buddy.ChangeRole(player.TeamRole.Role); - players = ev.Server.GetPlayers(); + doneIDs.Add(buddy.UserId); + doneIDs.Add(player.UserId); } } catch (ArgumentException e)