diff --git a/GameMode/FFAManager.cs b/GameMode/FFAManager.cs index 0e36ba3f5..aefbe8328 100644 --- a/GameMode/FFAManager.cs +++ b/GameMode/FFAManager.cs @@ -93,8 +93,9 @@ internal static class FFAManager KBScore = new(); RoundTime = FFA_GameTime.GetInt() + 8; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; KBScore.TryAdd(pc.PlayerId, 0); } } @@ -155,7 +156,7 @@ internal static class FFAManager } catch { - return Main.AllPlayerControls.Count(); + return Main.AllPlayerControls.Count; } } public static string GetHudText() @@ -166,7 +167,7 @@ internal static class FFAManager { if (killer == null || target == null || Options.CurrentGameMode != CustomGameMode.FFA) return; if (target.inVent) return; - var totalalive = Main.AllAlivePlayerControls.Count(); + var totalalive = Main.AllAlivePlayerControls.Count; if (FFAShieldedList.TryGetValue(target.PlayerId, out var dur)) { killer.Notify(GetString("FFA_TargetIsShielded")); @@ -299,7 +300,7 @@ internal static class FFAManager { if (GameStates.IsMeeting) return string.Empty; if (target != null && seer.PlayerId != target.PlayerId) return string.Empty; - if (Main.AllAlivePlayerControls.Count() != 2) return string.Empty; + if (Main.AllAlivePlayerControls.Count != 2) return string.Empty; string arrows = string.Empty; PlayerControl otherPlayer = null; @@ -351,8 +352,9 @@ internal static class FFAManager List changePositionPlayers = new(); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (changePositionPlayers.Contains(pc.PlayerId) || !pc.IsAlive() || pc.onLadder || pc.inVent) continue; var filtered = Main.AllAlivePlayerControls.Where(a => @@ -381,8 +383,9 @@ internal static class FFAManager if (Main.NormalOptions.MapId == 4) return; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (pc == null) return; bool sync = false; diff --git a/GameMode/SoloKombatManager.cs b/GameMode/SoloKombatManager.cs index 81716e406..4b6994296 100644 --- a/GameMode/SoloKombatManager.cs +++ b/GameMode/SoloKombatManager.cs @@ -96,8 +96,9 @@ internal static class SoloKombatManager KBScore = new(); RoundTime = KB_GameTime.GetInt() + 8; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; PlayerHPMax.TryAdd(pc.PlayerId, KB_HPMax.GetFloat()); PlayerHP.TryAdd(pc.PlayerId, KB_HPMax.GetFloat()); PlayerHPReco.TryAdd(pc.PlayerId, KB_RecoverPerSecond.GetFloat()); @@ -209,7 +210,7 @@ internal static class SoloKombatManager } catch { - return Main.AllPlayerControls.Count(); + return Main.AllPlayerControls.Count; } } public static string GetHudText() diff --git a/Modules/AntiBlackout.cs b/Modules/AntiBlackout.cs index 16bca2746..2d762cd0c 100644 --- a/Modules/AntiBlackout.cs +++ b/Modules/AntiBlackout.cs @@ -44,8 +44,9 @@ public static class AntiBlackout { int numImpostors = 0; int numCrewmates = 0; - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (pc.Data.Role.IsImpostor) numImpostors++; else numCrewmates++; } diff --git a/Modules/Camouflague.cs b/Modules/Camouflague.cs index 77b6ed824..a2cb8dad2 100644 --- a/Modules/Camouflague.cs +++ b/Modules/Camouflague.cs @@ -85,14 +85,10 @@ public static class Camouflage if (oldIsCamouflage != IsCamouflage) { - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; RpcSetSkin(pc); - - if (!IsCamouflage) - { - pc.RpcRemovePet(); - } } Utils.NotifyRoles(); } diff --git a/Modules/CustomRoleSelector.cs b/Modules/CustomRoleSelector.cs index 1e7d8ef2a..7d6dd823d 100644 --- a/Modules/CustomRoleSelector.cs +++ b/Modules/CustomRoleSelector.cs @@ -16,7 +16,7 @@ internal class CustomRoleSelector // 开始职业抽取 RoleResult = new(); var rd = IRandom.Instance; - int playerCount = Main.AllAlivePlayerControls.Count(); + int playerCount = Main.AllAlivePlayerControls.Count; int optImpNum = Main.RealOptionsData.GetInt(Int32OptionNames.NumImpostors); int optNonNeutralKillingNum = 0; int optNeutralKillingNum = 0; @@ -60,15 +60,23 @@ internal class CustomRoleSelector if (Options.CurrentGameMode == CustomGameMode.SoloKombat) { RoleResult = new(); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) + { + PlayerControl pc = Main.AllAlivePlayerControls[i]; RoleResult.Add(pc, CustomRoles.KB_Normal); + } + return; } if (Options.CurrentGameMode == CustomGameMode.FFA) { RoleResult = new(); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) + { + PlayerControl pc = Main.AllAlivePlayerControls[i]; RoleResult.Add(pc, CustomRoles.Killer); + } + return; } @@ -320,7 +328,7 @@ internal class CustomRoleSelector } } - var AllPlayer = Main.AllAlivePlayerControls.ToList(); + var AllPlayer = Main.AllAlivePlayerControls; while (AllPlayer.Any() && rolesToAssign.Any()) { diff --git a/Modules/DisableDevice.cs b/Modules/DisableDevice.cs index 194970992..bd23ea883 100644 --- a/Modules/DisableDevice.cs +++ b/Modules/DisableDevice.cs @@ -45,8 +45,9 @@ class DisableDevice if (frame != 0) return; if (!DoDisable) return; - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; try { if (pc.IsModClient()) continue; diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index 2cace258f..ff0117034 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -118,8 +118,9 @@ static class ExtendedPlayerControl } public static void RpcSetNameEx(this PlayerControl player, string name) { - foreach (var seer in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl seer = Main.AllPlayerControls[i]; Main.LastNotifyNames[(player.PlayerId, seer.PlayerId)] = name; } HudManagerPatch.LastSetNameDesyncCount++; @@ -1325,8 +1326,9 @@ static class ExtendedPlayerControl public static Dictionary GetAllPlayerLocationsCount() { Dictionary playerRooms = new(); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i1 = 0; i1 < Main.AllAlivePlayerControls.Count; i1++) { + PlayerControl pc = Main.AllAlivePlayerControls[i1]; if (!pc.IsAlive() || Pelican.IsEaten(pc.PlayerId)) return null; var Rooms = ShipStatus.Instance.AllRooms; if (Rooms == null) return null; diff --git a/Modules/GuessManager.cs b/Modules/GuessManager.cs index e0c2d13ab..c395ef483 100644 --- a/Modules/GuessManager.cs +++ b/Modules/GuessManager.cs @@ -19,8 +19,9 @@ public static class GuessManager public static string GetFormatString() { string text = GetString("PlayerIdList"); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; string id = pc.PlayerId.ToString(); string name = pc.GetRealName(); text += $"\n{id} → {name}"; @@ -763,8 +764,8 @@ public static class GuessManager var rd = IRandom.Instance; string msg; string[] command = new string[] { "bet", "bt", "guess", "gs", "shoot", "st", "赌", "猜", "审判", "tl", "判", "审" }; - var x = Main.AllAlivePlayerControls.ToArray(); - var totalAlive = Main.AllAlivePlayerControls.Count(); + var x = Main.AllAlivePlayerControls; + var totalAlive = Main.AllAlivePlayerControls.Count; for (int i = 0; i < 20; i++) { //msg = "/"; diff --git a/Modules/MafiaRevengeManager.cs b/Modules/MafiaRevengeManager.cs index 7b9868217..ef2405616 100644 --- a/Modules/MafiaRevengeManager.cs +++ b/Modules/MafiaRevengeManager.cs @@ -32,8 +32,12 @@ public static class MafiaRevengeManager if (msg == "/rv") { string text = GetString("PlayerIdList"); - foreach (var npc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) + { + PlayerControl npc = Main.AllAlivePlayerControls[i]; text += "\n" + npc.PlayerId.ToString() + " → (" + npc.GetDisplayRoleName() + ") " + npc.GetRealName(); + } + Utils.SendMessage(text, pc.PlayerId); return true; } diff --git a/Modules/OptionItem/OptionItem.cs b/Modules/OptionItem/OptionItem.cs index dd0ffc43b..53320ee1e 100644 --- a/Modules/OptionItem/OptionItem.cs +++ b/Modules/OptionItem/OptionItem.cs @@ -242,7 +242,7 @@ public abstract class OptionItem public static void SyncAllOptions(int targetId = -1) { if ( - Main.AllPlayerControls.Count() <= 1 + Main.AllPlayerControls.Count <= 1 || AmongUsClient.Instance.AmHost == false || PlayerControl.LocalPlayer == null ) return; diff --git a/Modules/RetributionistRevengeManager.cs b/Modules/RetributionistRevengeManager.cs index 7fdfc679f..3ac5b394e 100644 --- a/Modules/RetributionistRevengeManager.cs +++ b/Modules/RetributionistRevengeManager.cs @@ -23,7 +23,7 @@ public static class RetributionistRevengeManager else pc.ShowPopUp(GetString("RetributionistKillDisable")); return true; } - int playerCount = Main.AllAlivePlayerControls.Count(); + int playerCount = Main.AllAlivePlayerControls.Count; { if (playerCount <= Options.MinimumPlayersAliveToRetri.GetInt()) { @@ -54,8 +54,12 @@ public static class RetributionistRevengeManager if (msg == "/ret") { string text = GetString("PlayerIdList"); - foreach (var npc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) + { + PlayerControl npc = Main.AllAlivePlayerControls[i]; text += "\n" + npc.PlayerId.ToString() + " → (" + npc.GetDisplayRoleName() + ") " + npc.GetRealName(); + } + Utils.SendMessage(text, pc.PlayerId); return true; } diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 0cadaea64..1eb95fe9d 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -73,8 +73,11 @@ public static class Utils } public static void TPAll(Vector2 location) { - foreach (PlayerControl pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) + { + PlayerControl pc = Main.AllAlivePlayerControls[i]; TP(pc.NetTransform, location); + } } public static void TP(CustomNetworkTransform nt, Vector2 location) @@ -195,8 +198,9 @@ public static class Utils public static void TargetDies(PlayerControl killer, PlayerControl target) { if (!target.Data.IsDead || GameStates.IsMeeting) return; - foreach (var seer in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl seer = Main.AllPlayerControls[i]; if (KillFlashCheck(killer, target, seer)) { seer.KillFlash(); @@ -296,7 +300,7 @@ public static class Utils } public static string GetRoleMode(CustomRoles role, bool parentheses = true) { - if (Options.HideGameSettings.GetBool() && Main.AllPlayerControls.Count() > 1) + if (Options.HideGameSettings.GetBool() && Main.AllPlayerControls.Count > 1) return string.Empty; string mode = role.GetMode() switch { @@ -1174,8 +1178,9 @@ public static class Utils public static List GetPlayersInRadius(float radius, Vector2 from) { var list = new List(); - foreach (var tg in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl tg = Main.AllAlivePlayerControls[i]; var dis = Vector2.Distance(from, tg.transform.position); if (Pelican.IsEaten(tg.PlayerId) || Medic.ProtectList.Contains(tg.PlayerId) || tg.inVent) continue; @@ -1760,8 +1765,9 @@ public static class Utils var taskState = GetPlayerById(Terrorist.PlayerId).GetPlayerTaskState(); if (taskState.IsTaskFinished && (!Main.PlayerStates[Terrorist.PlayerId].IsSuicide() || Options.CanTerroristSuicideWin.GetBool())) //タスクが完了で(自殺じゃない OR 自殺勝ちが許可)されていれば { - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (pc.Is(CustomRoles.Terrorist)) { if (Main.PlayerStates[pc.PlayerId].deathReason == PlayerState.DeathReason.Vote) @@ -2094,8 +2100,9 @@ public static class Utils seer.RpcSetNamePrivate(SelfName, true, force: NoCache); //seerが死んでいる場合など、必要なときのみ第二ループを実行する - foreach (var target in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) { + PlayerControl target = Main.AllPlayerControls[i1]; //targetがseer自身の場合は何もしない if (target.PlayerId == seer.PlayerId) continue; logger.Info("NotifyRoles-Loop2-" + target.GetNameWithRole().RemoveHtmlTags() + ":START"); @@ -2538,8 +2545,9 @@ public static class Utils //Pirate.AfterMeetingTask(); if (Options.UsePets.GetBool()) - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; switch (pc.GetCustomRole()) { case CustomRoles.Doormaster: @@ -2649,8 +2657,9 @@ public static class Utils if (GameStates.IsMeeting) { //网红死亡消息提示 - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (!Options.ImpKnowCyberStarDead.GetBool() && pc.GetCustomRole().IsImpostor()) continue; if (!Options.NeutralKnowCyberStarDead.GetBool() && pc.GetCustomRole().IsNeutral()) continue; SendMessage(string.Format(GetString("CyberStarDead"), target.GetRealName()), pc.PlayerId, ColorString(GetRoleColor(CustomRoles.CyberStar), GetString("CyberStarNewsTitle"))); @@ -2757,8 +2766,9 @@ public static class Utils { int doused = 0, all = 0; //学校で習った書き方 //多分この方がMain.isDousedでforeachするより他のアーソニストの分ループ数少なくて済む - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (pc.PlayerId == playerId) continue; //塗れない人は除外 (死んでたり切断済みだったり あとアーソニスト自身も) all++; @@ -2773,7 +2783,7 @@ public static class Utils { int draw = 0; int all = Options.RevolutionistDrawCount.GetInt(); - int max = Main.AllAlivePlayerControls.Count(); + int max = Main.AllAlivePlayerControls.Count; if (!Main.PlayerStates[playerId].IsDead) max--; winnerList = new(); if (all > max) all = max; @@ -2836,8 +2846,9 @@ public static class Utils if (Main.PlayerStates == null) return false; //マフィアを除いた生きているインポスターの人数 Number of Living Impostors excluding mafia int LivingImpostorsNum = 0; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; var role = pc.GetCustomRole(); if (role != CustomRoles.Mafia && role.IsImpostor()) LivingImpostorsNum++; } diff --git a/Patches/ChatCommandPatch.cs b/Patches/ChatCommandPatch.cs index 20a29a7a2..ae163cfb8 100644 --- a/Patches/ChatCommandPatch.cs +++ b/Patches/ChatCommandPatch.cs @@ -204,8 +204,9 @@ internal class ChatCommands if (GameStates.IsLobby || !Options.EnableKillerLeftCommand.GetBool()) break; int impnum = 0; int neutralnum = 0; - foreach (var players in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl players = Main.AllAlivePlayerControls[i]; if (Options.ShowImpRemainOnEject.GetBool()) { if (players.GetCustomRole().IsImpostor()) @@ -390,8 +391,9 @@ internal class ChatCommands Utils.SendMessage(GetString("Message.CanNotUseInLobby"), PlayerControl.LocalPlayer.PlayerId); break; } - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; pc.RpcSetNameEx(pc.GetRealName(isMeeting: true)); } ChatUpdatePatch.DoBlockChat = false; @@ -402,8 +404,12 @@ internal class ChatCommands case "/id": canceled = true; string msgText = GetString("PlayerIdList"); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) + { + PlayerControl pc = Main.AllPlayerControls[i]; msgText += "\n" + pc.PlayerId.ToString() + " → " + Main.AllPlayerNames[pc.PlayerId]; + } + Utils.SendMessage(msgText, PlayerControl.LocalPlayer.PlayerId); break; @@ -903,8 +909,12 @@ internal class ChatCommands if (Options.ApplyModeratorList.GetValue() == 0 || !IsPlayerModerator(player.FriendCode)) break; string msgText = GetString("PlayerIdList"); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) + { + PlayerControl pc = Main.AllPlayerControls[i]; msgText += "\n" + pc.PlayerId.ToString() + " → " + Main.AllPlayerNames[pc.PlayerId]; + } + Utils.SendMessage(msgText, player.PlayerId); break; case "/kick": @@ -989,8 +999,9 @@ internal class ChatCommands if (GameStates.IsLobby || !Options.EnableKillerLeftCommand.GetBool()) break; int impnum = 0; int neutralnum = 0; - foreach (var players in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl players = Main.AllAlivePlayerControls[i]; if (Options.ShowImpRemainOnEject.GetBool()) { if (players.GetCustomRole().IsImpostor()) diff --git a/Patches/ChatControlPatch.cs b/Patches/ChatControlPatch.cs index 46b3b06d7..93b70249b 100644 --- a/Patches/ChatControlPatch.cs +++ b/Patches/ChatControlPatch.cs @@ -147,8 +147,8 @@ public class ChatManager string msg = "."; List roles = Enum.GetValues(typeof(CustomRoles)).Cast().Where(x => x is not CustomRoles.KB_Normal and not CustomRoles.Killer).ToList(); string[] specialTexts = new string[] { "bet", "bt", "guess", "gs", "shoot", "st", "赌", "猜", "审判", "tl", "判", "审", "trial" }; - var totalAlive = Main.AllAlivePlayerControls.Count(); - var x = Main.AllAlivePlayerControls.ToArray(); + var totalAlive = Main.AllAlivePlayerControls.Count; + var x = Main.AllAlivePlayerControls; var filtered = chatHistory.Where(a => Utils.GetPlayerById(Convert.ToByte(((string[])a.Split(':'))[0].Trim())).IsAlive()).ToList(); diff --git a/Patches/CheckGameEndPatch.cs b/Patches/CheckGameEndPatch.cs index f1ffdbb3c..9d767d31b 100644 --- a/Patches/CheckGameEndPatch.cs +++ b/Patches/CheckGameEndPatch.cs @@ -109,8 +109,9 @@ class GameEndChecker } if (CustomWinnerHolder.WinnerTeam is not CustomWinner.Draw and not CustomWinner.None and not CustomWinner.Error) { - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; switch (pc.GetCustomRole()) { case CustomRoles.DarkHide when !pc.Data.IsDead && ((CustomWinnerHolder.WinnerTeam == CustomWinner.Impostor && !reason.Equals(GameOverReason.ImpostorBySabotage)) || CustomWinnerHolder.WinnerTeam == CustomWinner.DarkHide || (CustomWinnerHolder.WinnerTeam == CustomWinner.Crewmate && !reason.Equals(GameOverReason.HumansByTask) && DarkHide.IsWinKill[pc.PlayerId] == true && DarkHide.SnatchesWin.GetBool())): @@ -241,8 +242,9 @@ class GameEndChecker //Ruthless Romantic partner win condition if (RuthlessRomantic.IsEnable && (CustomWinnerHolder.WinnerIds.Contains(RuthlessRomantic.playerIdList[0]) || (Main.PlayerStates.TryGetValue(RuthlessRomantic.playerIdList[0], out var pz) && CustomWinnerHolder.WinnerRoles.Contains(pz.MainRole)))) - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (Romantic.BetPlayer.TryGetValue(pc.PlayerId, out var betTarget)) { CustomWinnerHolder.WinnerIds.Add(betTarget); @@ -260,9 +262,12 @@ class GameEndChecker //中立共同胜利 if (Options.NeutralWinTogether.GetBool() && CustomWinnerHolder.WinnerIds.Any(x => GetPlayerById(x) != null && GetPlayerById(x).GetCustomRole().IsNeutral())) { - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) + { + PlayerControl pc = Main.AllPlayerControls[i]; if (pc.GetCustomRole().IsNeutral() && !CustomWinnerHolder.WinnerIds.Contains(pc.PlayerId)) CustomWinnerHolder.WinnerIds.Add(pc.PlayerId); + } } else if (Options.NeutralRoleWinTogether.GetBool()) { @@ -270,9 +275,12 @@ class GameEndChecker { var pc = GetPlayerById(id); if (pc == null || !pc.GetCustomRole().IsNeutral()) continue; - foreach (var tar in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) + { + PlayerControl tar = Main.AllPlayerControls[i]; if (!CustomWinnerHolder.WinnerIds.Contains(tar.PlayerId) && tar.GetCustomRole() == pc.GetCustomRole()) CustomWinnerHolder.WinnerIds.Add(tar.PlayerId); + } } } } @@ -291,8 +299,9 @@ class GameEndChecker //ゴーストロール化 List ReviveRequiredPlayerIds = new(); var winner = CustomWinnerHolder.WinnerTeam; - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (winner == CustomWinner.Draw) { SetGhostRole(ToGhostImpostor: true); @@ -386,7 +395,7 @@ class GameEndChecker { reason = GameOverReason.ImpostorByKill; - if (CustomRolesHelper.RoleExist(CustomRoles.Sunnyboy) && Main.AllAlivePlayerControls.Count() > 1) return false; + if (CustomRolesHelper.RoleExist(CustomRoles.Sunnyboy) && Main.AllAlivePlayerControls.Count > 1) return false; int Imp = AlivePlayersCount(CountTypes.Impostor); int Crew = AlivePlayersCount(CountTypes.Crew); @@ -431,8 +440,9 @@ class GameEndChecker { (CustomRoles.Agitater, CustomWinner.Agitater), AlivePlayersCount(CountTypes.Agitater) }, }; - foreach (var x in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl x = Main.AllAlivePlayerControls[i]; if (x.GetCustomRole().IsImpostor() && x.Is(CustomRoles.DualPersonality)) Imp++; if (x.GetCustomRole().IsCrewmate() && x.Is(CustomRoles.DualPersonality)) Crew++; if (x.GetCustomRole().IsImpostor() && x.Is(CustomRoles.Admired) && x.Is(CustomRoles.DualPersonality)) Crew++; @@ -577,7 +587,7 @@ class GameEndChecker return true; } - else if (Main.AllAlivePlayerControls.Count() == 1) + else if (Main.AllAlivePlayerControls.Count == 1) { var winner = Main.AllAlivePlayerControls.FirstOrDefault(); diff --git a/Patches/ExilePatch.cs b/Patches/ExilePatch.cs index 050e54e31..5515c93f0 100644 --- a/Patches/ExilePatch.cs +++ b/Patches/ExilePatch.cs @@ -110,8 +110,9 @@ class ExileControllerWrapUpPatch if (NiceSwapper.Vote.Any() && NiceSwapper.VoteTwo.Any()) { - foreach (var swapper in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl swapper = Main.AllAlivePlayerControls[i]; if (swapper.Is(CustomRoles.NiceSwapper)) { NiceSwapper.NiceSwappermax[swapper.PlayerId]--; @@ -122,8 +123,9 @@ class ExileControllerWrapUpPatch } } - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; pc.ResetKillCooldown(); if (pc.Is(CustomRoles.Warlock)) diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index 53f1704a8..a0043e37f 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -66,19 +66,22 @@ class CoBeginPatch { var logger = Logger.Handler("Info"); logger.Info("------------Display Names------------"); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; logger.Info($"{(pc.AmOwner ? "[*]" : string.Empty),-3}{pc.PlayerId,-2}:{pc.name.PadRightV2(20)}:{pc.cosmetics.nameText.text} ({Palette.ColorNames[pc.Data.DefaultOutfit.ColorId].ToString().Replace("Color", string.Empty)})"); pc.cosmetics.nameText.text = pc.name; } logger.Info("------------Roles------------"); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; logger.Info($"{(pc.AmOwner ? "[*]" : string.Empty),-3}{pc.PlayerId,-2}:{pc?.Data?.PlayerName?.PadRightV2(20)}:{pc.GetAllRoleName().RemoveHtmlTags()}"); } logger.Info("------------Platforms------------"); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; try { var text = pc.AmOwner ? "[*]" : " "; @@ -105,7 +108,7 @@ class CoBeginPatch } logger.Info("-------------Other Information-------------"); - logger.Info($"Number of players: {Main.AllPlayerControls.Count()}"); + logger.Info($"Number of players: {Main.AllPlayerControls.Count}"); Main.AllPlayerControls.Do(x => Main.PlayerStates[x.PlayerId].InitTask(x)); GameData.Instance.RecomputeTaskCounts(); TaskState.InitialTotalTasks = GameData.Instance.TotalTasks; @@ -527,7 +530,7 @@ class IntroCutsceneDestroyPatch { try { - for (int i = 0; i < Main.AllPlayerControls.Count(); i++) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { var pc = Main.AllPlayerControls.ElementAt(i); if (pc.PlayerId == 0) continue; diff --git a/Patches/MeetingHudPatch.cs b/Patches/MeetingHudPatch.cs index 68b63e0c5..be7fd819d 100644 --- a/Patches/MeetingHudPatch.cs +++ b/Patches/MeetingHudPatch.cs @@ -429,8 +429,9 @@ class CheckForEndVotingPatch goto EndOfSession; } - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; var pc_role = pc.GetCustomRole(); if (pc_role.IsImpostor() && pc != exiledPlayer.Object) impnum++; @@ -580,8 +581,9 @@ class CheckForEndVotingPatch private static PlayerControl PickRevengeTarget(PlayerControl exiledplayer/*, PlayerState.DeathReason deathReason*/)//道連れ先選定 { List TargetList = new(); - foreach (var candidate in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl candidate = Main.AllAlivePlayerControls[i]; if (candidate == exiledplayer || Main.AfterMeetingDeathPlayers.ContainsKey(candidate.PlayerId)) continue; } if (TargetList == null || !TargetList.Any()) return null; @@ -736,8 +738,9 @@ class MeetingHudStartPatch AddMsg(string.Format(GetString("BaitAdviceAlive"), string.Join(separator, baitAliveList)), 255, Utils.ColorString(Utils.GetRoleColor(CustomRoles.Bait), GetString("BaitAliveTitle"))); } string MimicMsg = string.Empty; - foreach (var pc in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) { + PlayerControl pc = Main.AllPlayerControls[i1]; //黑手党死后技能提示 if (pc.Is(CustomRoles.Mafia) && !pc.IsAlive()) AddMsg(GetString("MafiaDeadMsg"), pc.PlayerId); @@ -908,8 +911,9 @@ class MeetingHudStartPatch { _ = _ = new LateTask(() => { - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; pc.RpcSetNameEx(pc.GetRealName(isMeeting: true)); } ChatUpdatePatch.DoBlockChat = false; diff --git a/Patches/OutroPatch.cs b/Patches/OutroPatch.cs index 7a7f35cd9..bfce2e254 100644 --- a/Patches/OutroPatch.cs +++ b/Patches/OutroPatch.cs @@ -44,8 +44,9 @@ class EndGamePatch //winnerListリセット TempData.winners = new Il2CppSystem.Collections.Generic.List(); var winner = new List(); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (CustomWinnerHolder.WinnerIds.Contains(pc.PlayerId)) winner.Add(pc); } foreach (var team in CustomWinnerHolder.WinnerRoles) diff --git a/Patches/PetActionsPatch.cs b/Patches/PetActionsPatch.cs index e0c880ed8..72817eb53 100644 --- a/Patches/PetActionsPatch.cs +++ b/Patches/PetActionsPatch.cs @@ -281,8 +281,9 @@ class ExternalRpcPetPatch //if (!pc.IsModClient()) pc.RpcGuardAndKill(pc); pc.Notify(GetString("TimeMasterOnGuard"), Options.TimeMasterSkillDuration.GetFloat()); Main.TimeMasterCD.TryAdd(pc.PlayerId, Utils.GetTimeStamp()); - foreach (var player in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl player = Main.AllPlayerControls[i]; if (Main.TimeMasterBackTrack.ContainsKey(player.PlayerId)) { var position = Main.TimeMasterBackTrack[player.PlayerId]; @@ -327,8 +328,9 @@ class ExternalRpcPetPatch UnityEngine.Vector2 cppos = cp.transform.position; System.Collections.Generic.Dictionary cpdistance = new(); float dis; - foreach (PlayerControl p in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl p = Main.AllAlivePlayerControls[i]; if (p.PlayerId == cp.PlayerId) continue; if (!Options.WarlockCanKillSelf.GetBool() && p.PlayerId == pc.PlayerId) continue; if (!Options.WarlockCanKillAllies.GetBool() && p.GetCustomRole().IsImpostor()) continue; @@ -426,8 +428,9 @@ class ExternalRpcPetPatch } Logger.Info("炸弹爆炸了", "Boom"); CustomSoundsManager.RPCPlayCustomSoundAll("Boom"); - foreach (var tg in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl tg = Main.AllPlayerControls[i]; if (!tg.IsModClient()) tg.KillFlash(); var pos = pc.transform.position; var dis = UnityEngine.Vector2.Distance(pos, tg.transform.position); @@ -443,8 +446,8 @@ class ExternalRpcPetPatch } _ = new LateTask(() => { - bool totalAlive = Main.AllAlivePlayerControls.Any(); - if (Options.BomberDiesInExplosion.GetBool() && totalAlive && !GameStates.IsEnded) + var totalAlive = Main.AllAlivePlayerControls.Count; + if (Options.BomberDiesInExplosion.GetBool() && totalAlive > 1 && !GameStates.IsEnded) { Main.PlayerStates[pc.PlayerId].deathReason = PlayerState.DeathReason.Bombed; pc.RpcMurderPlayerV3(pc); @@ -461,8 +464,9 @@ class ExternalRpcPetPatch } Logger.Info("炸弹爆炸了", "Boom"); CustomSoundsManager.RPCPlayCustomSoundAll("Boom"); - foreach (var tg in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl tg = Main.AllPlayerControls[i]; if (!tg.IsModClient()) tg.KillFlash(); var pos = pc.transform.position; var dis = UnityEngine.Vector2.Distance(pos, tg.transform.position); @@ -478,8 +482,8 @@ class ExternalRpcPetPatch } _ = new LateTask(() => { - bool totalAlive = Main.AllAlivePlayerControls.Any(); - if (totalAlive && !GameStates.IsEnded) + var totalAlive = Main.AllAlivePlayerControls.Count; + if (totalAlive > 1 && !GameStates.IsEnded) { Main.PlayerStates[pc.PlayerId].deathReason = PlayerState.DeathReason.Bombed; pc.RpcMurderPlayerV3(pc); diff --git a/Patches/PlayerContorolPatch.cs b/Patches/PlayerContorolPatch.cs index f89173368..a15f113dd 100644 --- a/Patches/PlayerContorolPatch.cs +++ b/Patches/PlayerContorolPatch.cs @@ -768,8 +768,9 @@ class CheckMurderPatch // } if (Main.ForCrusade.Contains(target.PlayerId)) { - foreach (var player in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl player = Main.AllPlayerControls[i]; if (player.Is(CustomRoles.Crusader) && player.IsAlive() && !killer.Is(CustomRoles.Pestilence) && !killer.Is(CustomRoles.Minimalism)) { player.RpcMurderPlayerV3(killer); @@ -861,8 +862,9 @@ class CheckMurderPatch if (Main.TimeMasterInProtect.ContainsKey(target.PlayerId) && killer.PlayerId != target.PlayerId) if (Main.TimeMasterInProtect[target.PlayerId] + Options.TimeMasterSkillDuration.GetInt() >= Utils.GetTimeStamp(DateTime.UtcNow)) { - foreach (var player in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl player = Main.AllPlayerControls[i]; if (!killer.Is(CustomRoles.Pestilence)) { if (Main.TimeMasterBackTrack.ContainsKey(player.PlayerId)) @@ -1103,7 +1105,7 @@ class MurderPlayerPatch Wildling.OnMurderPlayer(killer, target); break; case CustomRoles.Underdog: - int playerCount = Main.AllAlivePlayerControls.Count(); + int playerCount = Main.AllAlivePlayerControls.Count; if (playerCount < Options.UnderdogMaximumPlayersNeededToKill.GetInt()) Main.AllPlayerKillCooldown[killer.PlayerId] = Options.UnderdogKillCooldown.GetFloat(); else Main.AllPlayerKillCooldown[killer.PlayerId] = Options.UnderdogKillCooldownWithMorePlayersAlive.GetFloat(); @@ -1254,8 +1256,9 @@ class ShapeshiftPatch Vector2 cppos = cp.transform.position;//呪われた人の位置 Dictionary cpdistance = new(); float dis; - foreach (PlayerControl p in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl p = Main.AllAlivePlayerControls[i]; if (p.PlayerId == cp.PlayerId) continue; if (!Options.WarlockCanKillSelf.GetBool() && p.PlayerId == shapeshifter.PlayerId) continue; if (!Options.WarlockCanKillAllies.GetBool() && p.GetCustomRole().IsImpostor()) continue; @@ -1329,8 +1332,9 @@ class ShapeshiftPatch { Logger.Info("炸弹爆炸了", "Boom"); CustomSoundsManager.RPCPlayCustomSoundAll("Boom"); - foreach (var tg in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl tg = Main.AllPlayerControls[i]; if (!tg.IsModClient()) tg.KillFlash(); var pos = shapeshifter.transform.position; var dis = Vector2.Distance(pos, tg.transform.position); @@ -1346,7 +1350,7 @@ class ShapeshiftPatch } _ = new LateTask(() => { - var totalAlive = Main.AllAlivePlayerControls.Count(); + var totalAlive = Main.AllAlivePlayerControls.Count; if (Options.BomberDiesInExplosion.GetBool() && totalAlive > 1 && !GameStates.IsEnded) { Main.PlayerStates[shapeshifter.PlayerId].deathReason = PlayerState.DeathReason.Bombed; @@ -1366,8 +1370,9 @@ class ShapeshiftPatch { Logger.Info("炸弹爆炸了", "Boom"); CustomSoundsManager.RPCPlayCustomSoundAll("Boom"); - foreach (var tg in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl tg = Main.AllPlayerControls[i]; if (!tg.IsModClient()) tg.KillFlash(); var pos = shapeshifter.transform.position; var dis = Vector2.Distance(pos, tg.transform.position); @@ -1383,7 +1388,7 @@ class ShapeshiftPatch } _ = new LateTask(() => { - var totalAlive = Main.AllAlivePlayerControls.Count(); + var totalAlive = Main.AllAlivePlayerControls.Count; if (totalAlive > 1 && !GameStates.IsEnded) { Main.PlayerStates[shapeshifter.PlayerId].deathReason = PlayerState.DeathReason.Bombed; @@ -1808,8 +1813,9 @@ class ReportDeadBodyPatch if (Options.InhibitorCDAfterMeetings.GetFloat() != Options.InhibitorCD.GetFloat() || Options.SaboteurCD.GetFloat() != Options.SaboteurCDAfterMeetings.GetFloat()) { - foreach (var x in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl x = Main.AllAlivePlayerControls[i]; if (x.Is(CustomRoles.Inhibitor)) { Main.AllPlayerKillCooldown[x.PlayerId] = Options.InhibitorCDAfterMeetings.GetFloat(); @@ -2557,8 +2563,9 @@ class FixedUpdatePatch Vector2 puppeteerPos = player.transform.position;//PuppeteerListのKeyの位置 Dictionary targetDistance = new(); float dis; - foreach (var target in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl target = Main.AllAlivePlayerControls[i]; { if (target.PlayerId != player.PlayerId && !target.Is(CustomRoleTypes.Impostor) && !target.Is(CustomRoles.Pestilence)) { @@ -2603,8 +2610,9 @@ class FixedUpdatePatch Vector2 puppeteerPos = player.transform.position;//PuppeteerListのKeyの位置 Dictionary targetDistance = new(); float dis; - foreach (var target in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl target = Main.AllAlivePlayerControls[i]; if (target.PlayerId != player.PlayerId && !target.Is(CustomRoles.Pestilence)) { dis = Vector2.Distance(puppeteerPos, target.transform.position); @@ -2646,8 +2654,9 @@ class FixedUpdatePatch } if (GameStates.IsInGame && Main.RefixCooldownDelay <= 0) - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (pc.Is(CustomRoles.Vampire) || pc.Is(CustomRoles.Warlock) || pc.Is(CustomRoles.Assassin) || pc.Is(CustomRoles.Undertaker) || pc.Is(CustomRoles.Poisoner)) Main.AllPlayerKillCooldown[pc.PlayerId] = Options.DefaultKillCooldown * 2; } @@ -3280,8 +3289,9 @@ class EnterVentPatch //if (!pc.IsModClient()) pc.RpcGuardAndKill(pc); pc.Notify(GetString("TimeMasterOnGuard"), Options.TimeMasterSkillDuration.GetFloat()); Main.TimeMasterCD.TryAdd(pc.PlayerId, Utils.GetTimeStamp()); - foreach (var player in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl player = Main.AllPlayerControls[i]; if (Main.TimeMasterBackTrack.ContainsKey(player.PlayerId)) { var position = Main.TimeMasterBackTrack[player.PlayerId]; @@ -3312,7 +3322,7 @@ class CoEnterVentPatch { if (!AmongUsClient.Instance.AmHost) return true; - if (Options.CurrentGameMode == CustomGameMode.FFA && FFAManager.FFA_DisableVentingWhenTwoPlayersAlive.GetBool() && Main.AllAlivePlayerControls.Count() <= 2) + if (Options.CurrentGameMode == CustomGameMode.FFA && FFAManager.FFA_DisableVentingWhenTwoPlayersAlive.GetBool() && Main.AllAlivePlayerControls.Count <= 2) { var pc = __instance.myPlayer; if (pc.killTimer <= 0) @@ -3369,8 +3379,9 @@ class CoEnterVentPatch if (__instance.myPlayer.IsDouseDone()) { CustomSoundsManager.RPCPlayCustomSoundAll("Boom"); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (pc != __instance.myPlayer) { //生存者は焼殺 @@ -3380,7 +3391,12 @@ class CoEnterVentPatch Main.PlayerStates[pc.PlayerId].SetDead(); } } - foreach (var pc in Main.AllPlayerControls) pc.KillFlash(); + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) + { + PlayerControl pc = Main.AllPlayerControls[i1]; + pc.KillFlash(); + } + CustomWinnerHolder.ShiftWinnerAndSetWinner(CustomWinner.Arsonist); //焼殺で勝利した人も勝利させる CustomWinnerHolder.WinnerIds.Add(__instance.myPlayer.PlayerId); return true; @@ -3391,8 +3407,9 @@ class CoEnterVentPatch if (douseCount >= Options.ArsonistMinPlayersToIgnite.GetInt()) // Don't check for max, since the player would not be able to ignite at all if they somehow get more players doused than the max { if (douseCount > Options.ArsonistMaxPlayersToIgnite.GetInt()) Logger.Warn("Arsonist Ignited with more players doused than the maximum amount in the settings", "Arsonist Ignite"); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (!__instance.myPlayer.IsDousedPlayer(pc)) continue; pc.KillFlash(); pc.SetRealKiller(__instance.myPlayer); @@ -3400,7 +3417,7 @@ class CoEnterVentPatch pc.RpcMurderPlayerV3(pc); Main.PlayerStates[pc.PlayerId].SetDead(); } - var apc = Main.AllAlivePlayerControls.Count(); + var apc = Main.AllAlivePlayerControls.Count; if (apc == 1) { CustomWinnerHolder.ShiftWinnerAndSetWinner(CustomWinner.Arsonist); @@ -3591,8 +3608,9 @@ class PlayerControlSetRolePatch { var targetIsKiller = target.Is(CustomRoleTypes.Impostor) || Main.ResetCamPlayerList.Contains(target.PlayerId); var ghostRoles = new Dictionary(); - foreach (var seer in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl seer = Main.AllPlayerControls[i]; var self = seer.PlayerId == target.PlayerId; var seerIsKiller = seer.Is(CustomRoleTypes.Impostor) || Main.ResetCamPlayerList.Contains(seer.PlayerId); if (target.Is(CustomRoles.EvilSpirit)) diff --git a/Patches/onGameStartedPatch.cs b/Patches/onGameStartedPatch.cs index 6d5f61f82..a204001ad 100644 --- a/Patches/onGameStartedPatch.cs +++ b/Patches/onGameStartedPatch.cs @@ -154,16 +154,19 @@ internal class ChangeRoleSettings Logger.Error(msg, "CoStartGame"); } - foreach (var target in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { - foreach (var seer in Main.AllPlayerControls) + PlayerControl target = Main.AllPlayerControls[i]; + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) { + PlayerControl seer = Main.AllPlayerControls[i1]; var pair = (target.PlayerId, seer.PlayerId); Main.LastNotifyNames[pair] = target.name; } } - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; var colorId = pc.Data.DefaultOutfit.ColorId; if (AmongUsClient.Instance.AmHost && Options.FormatNameMode.GetInt() == 1) pc.RpcSetName(Palette.GetColorName(colorId)); Main.PlayerStates[pc.PlayerId] = new(pc.PlayerId); @@ -356,8 +359,9 @@ internal class SelectRolesPatch { //CustomRpcSenderとRpcSetRoleReplacerの初期化 Dictionary senders = new(); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; senders[pc.PlayerId] = new CustomRpcSender($"{pc.name}'s SetRole Sender", SendOption.Reliable, false) .StartMessage(pc.GetClientId()); } @@ -433,8 +437,9 @@ internal class SelectRolesPatch //Utils.ApplySuffix(); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; pc.Data.IsDead = false; //プレイヤーの死を解除する if (Main.PlayerStates[pc.PlayerId].MainRole != CustomRoles.NotAssigned) continue; //既にカスタム役職が割り当てられていればスキップ var role = CustomRoles.NotAssigned; @@ -494,12 +499,16 @@ internal class SelectRolesPatch { ExtendedPlayerControl.RpcSetCustomRole(pair.Key, pair.Value.MainRole); - foreach (var subRole in pair.Value.SubRoles) + for (int i = 0; i < pair.Value.SubRoles.Count; i++) + { + CustomRoles subRole = pair.Value.SubRoles[i]; ExtendedPlayerControl.RpcSetCustomRole(pair.Key, subRole); + } } - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (pc.Data.Role.Role == RoleTypes.Shapeshifter) Main.CheckShapeshift.Add(pc.PlayerId, false); switch (pc.GetCustomRole()) { @@ -554,16 +563,25 @@ internal class SelectRolesPatch SwordsMan.Add(pc.PlayerId); break; case CustomRoles.Arsonist: - foreach (var ar in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) + { + PlayerControl ar = Main.AllPlayerControls[i1]; Main.isDoused.Add((pc.PlayerId, ar.PlayerId), false); + } + break; case CustomRoles.Revolutionist: - foreach (var ar in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) + { + PlayerControl ar = Main.AllPlayerControls[i1]; Main.isDraw.Add((pc.PlayerId, ar.PlayerId), false); + } + break; case CustomRoles.Farseer: - foreach (var ar in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) { + PlayerControl ar = Main.AllPlayerControls[i1]; Main.isRevealed.Add((pc.PlayerId, ar.PlayerId), false); } Farseer.RandomRole.Add(pc.PlayerId, Farseer.GetRandomCrewRoleString()); @@ -971,8 +989,11 @@ internal class SelectRolesPatch HudManager.Instance.SetHudActive(true); List AllPlayers = new(); CustomRpcSender sender = CustomRpcSender.Create("SelectRoles Sender", SendOption.Reliable); - foreach (var pc in Main.AllPlayerControls) + for (int i2 = 0; i2 < Main.AllPlayerControls.Count; i2++) + { + PlayerControl pc = Main.AllPlayerControls[i2]; pc.ResetKillCooldown(); + } //役職の人数を戻す var roleOpt = Main.NormalOptions.roleOptions; @@ -1000,8 +1021,9 @@ internal class SelectRolesPatch } GameOptionsSender.AllSenders.Clear(); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; GameOptionsSender.AllSenders.Add( new PlayerGameOptionsSender(pc) ); @@ -1031,8 +1053,11 @@ internal class SelectRolesPatch var othersRole = player.PlayerId == hostId ? RoleTypes.Crewmate : RoleTypes.Scientist; //Desync役職視点 - foreach (var target in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) + { + PlayerControl target = Main.AllPlayerControls[i]; rolesMap[(player.PlayerId, target.PlayerId)] = player.PlayerId != target.PlayerId ? othersRole : selfRole; + } //他者視点 foreach (var seer in Main.AllPlayerControls.Where(x => player.PlayerId != x.PlayerId)) @@ -1047,11 +1072,13 @@ internal class SelectRolesPatch } public static void MakeDesyncSender(Dictionary senders, Dictionary<(byte, byte), RoleTypes> rolesMap) { - foreach (var seer in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl seer = Main.AllPlayerControls[i]; var sender = senders[seer.PlayerId]; - foreach (var target in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) { + PlayerControl target = Main.AllPlayerControls[i1]; if (rolesMap.TryGetValue((seer.PlayerId, target.PlayerId), out var role)) { sender.RpcSetRole(seer, role, target.GetClientId()); @@ -1127,8 +1154,9 @@ internal class SelectRolesPatch private static void AssignLoversRoles(int RawCount = -1) { var allPlayers = new List(); - foreach (var pc in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl pc = Main.AllPlayerControls[i]; if (pc.Is(CustomRoles.GM) || (pc.HasSubRole() && pc.GetCustomSubRoles().Count >= Options.NoLimitAddonsNumMax.GetInt()) //|| pc.Is(CustomRoles.Ntr) diff --git a/Roles/AddOns/Impostor/LastImpostor.cs b/Roles/AddOns/Impostor/LastImpostor.cs index b8bb651a0..79592e11d 100644 --- a/Roles/AddOns/Impostor/LastImpostor.cs +++ b/Roles/AddOns/Impostor/LastImpostor.cs @@ -29,8 +29,9 @@ public static class LastImpostor if (Options.CurrentGameMode == CustomGameMode.SoloKombat || Options.CurrentGameMode == CustomGameMode.FFA || !CustomRoles.LastImpostor.IsEnable() || Main.AliveImpostorCount != 1) return; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (CanBeLastImpostor(pc)) { pc.RpcSetCustomRole(CustomRoles.LastImpostor); diff --git a/Roles/Crewmate/Marshall.cs b/Roles/Crewmate/Marshall.cs index 0a5d890e9..6ecd6a06c 100644 --- a/Roles/Crewmate/Marshall.cs +++ b/Roles/Crewmate/Marshall.cs @@ -70,12 +70,12 @@ public static class Marshall if (!IsExposed[marshallId]) { - foreach (var target in Main.AllAlivePlayerControls) - { - // if (!IsMarshallTarget(target)) continue; + //foreach (var target in Main.AllAlivePlayerControls) + //{ + // // if (!IsMarshallTarget(target)) continue; - // TargetArrow.Add(target.PlayerId, snitchId); - } + // // TargetArrow.Add(target.PlayerId, snitchId); + //} IsExposed[marshallId] = true; } diff --git a/Roles/Crewmate/Monitor.cs b/Roles/Crewmate/Monitor.cs index 7b1a70e01..78cabb194 100644 --- a/Roles/Crewmate/Monitor.cs +++ b/Roles/Crewmate/Monitor.cs @@ -48,8 +48,9 @@ internal class Monitor Count--; if (Count > 0) return; Count = 5; bool Admin = false, Camera = false, DoorLog = false, Vital = false; - foreach (PlayerControl pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (Pelican.IsEaten(pc.PlayerId) || pc.inVent) continue; try { @@ -119,8 +120,11 @@ internal class Monitor byte pc = playerIdList[i]; Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); } - foreach (PlayerControl pc in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) + { + PlayerControl pc = Main.AllPlayerControls[i1]; FixedUpdatePatch.Postfix(pc); + } } } } \ No newline at end of file diff --git a/Roles/Crewmate/Mortician.cs b/Roles/Crewmate/Mortician.cs index 00fa9464a..4cd41fedf 100644 --- a/Roles/Crewmate/Mortician.cs +++ b/Roles/Crewmate/Mortician.cs @@ -59,8 +59,9 @@ public static class Mortician var pos = target.GetTruePosition(); float minDis = float.MaxValue; string minName = string.Empty; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (pc.PlayerId == target.PlayerId) continue; var dis = Vector2.Distance(pc.GetTruePosition(), pos); if (dis < minDis && dis < 1.5f) diff --git a/Roles/Crewmate/Snitch.cs b/Roles/Crewmate/Snitch.cs index 44d3c629b..c8528965a 100644 --- a/Roles/Crewmate/Snitch.cs +++ b/Roles/Crewmate/Snitch.cs @@ -86,8 +86,9 @@ public static class Snitch if (!IsExposed[snitchId] && snitchTask.RemainingTasksCount <= RemainingTasksToBeFound) { - foreach (var target in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl target = Main.AllAlivePlayerControls[i]; if (!IsSnitchTarget(target)) continue; TargetArrow.Add(target.PlayerId, snitchId); @@ -97,8 +98,9 @@ public static class Snitch if (IsComplete[snitchId] || !snitchTask.IsTaskFinished) return; - foreach (var target in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl target = Main.AllAlivePlayerControls[i]; if (!IsSnitchTarget(target)) continue; var targetId = target.PlayerId; diff --git a/Roles/Crewmate/Tracefinder.cs b/Roles/Crewmate/Tracefinder.cs index b58707791..363e470c7 100644 --- a/Roles/Crewmate/Tracefinder.cs +++ b/Roles/Crewmate/Tracefinder.cs @@ -83,8 +83,9 @@ public static class Tracefinder var pos = target.GetTruePosition(); float minDis = float.MaxValue; string minName = string.Empty; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (pc.PlayerId == target.PlayerId) continue; var dis = Vector2.Distance(pc.GetTruePosition(), pos); if (dis < minDis && dis < 1.5f) diff --git a/Roles/Impostor/AntiAdminer.cs b/Roles/Impostor/AntiAdminer.cs index e7383d6f0..17c2c8b2a 100644 --- a/Roles/Impostor/AntiAdminer.cs +++ b/Roles/Impostor/AntiAdminer.cs @@ -46,8 +46,9 @@ internal class AntiAdminer Count--; if (Count > 0) return; Count = 5; bool Admin = false, Camera = false, DoorLog = false, Vital = false; - foreach (PlayerControl pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (Pelican.IsEaten(pc.PlayerId) || pc.inVent || pc.GetCustomRole().IsImpostor()) continue; try { @@ -117,8 +118,11 @@ internal class AntiAdminer byte pc = playerIdList[i]; Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); } - foreach (PlayerControl pc in Main.AllPlayerControls) + for (int i1 = 0; i1 < Main.AllPlayerControls.Count; i1++) + { + PlayerControl pc = Main.AllPlayerControls[i1]; FixedUpdatePatch.Postfix(pc); + } } } } \ No newline at end of file diff --git a/Roles/Impostor/EvilTracker.cs b/Roles/Impostor/EvilTracker.cs index 6775c40b4..3c565c111 100644 --- a/Roles/Impostor/EvilTracker.cs +++ b/Roles/Impostor/EvilTracker.cs @@ -70,8 +70,9 @@ public static class EvilTracker CanSetTarget.Add(playerId, CurrentTargetMode != TargetMode.Never); //ImpostorsIdはEvilTracker内で共有 ImpostorsId[playerId] = new(); - foreach (var target in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl target = Main.AllAlivePlayerControls[i]; var targetId = target.PlayerId; if (targetId != playerId && target.Is(CustomRoleTypes.Impostor)) { diff --git a/Roles/Impostor/FireWorks.cs b/Roles/Impostor/FireWorks.cs index b48478bb6..6e826bbaa 100644 --- a/Roles/Impostor/FireWorks.cs +++ b/Roles/Impostor/FireWorks.cs @@ -113,8 +113,9 @@ public static class FireWorks case FireWorksState.ReadyFire: Logger.Info("花火を爆破", "FireWorks"); bool suicide = false; - foreach (var target in Main.AllAlivePlayerControls) + for (int i1 = 0; i1 < Main.AllAlivePlayerControls.Count; i1++) { + PlayerControl target = Main.AllAlivePlayerControls[i1]; for (int i = 0; i < fireWorksPosition[pc.PlayerId].Count; i++) { Vector3 pos = fireWorksPosition[pc.PlayerId][i]; @@ -137,7 +138,7 @@ public static class FireWorks } if (suicide) { - var totalAlive = Main.AllAlivePlayerControls.Count(); + var totalAlive = Main.AllAlivePlayerControls.Count; //自分が最後の生き残りの場合は勝利のために死なない if (totalAlive != 1) { diff --git a/Roles/Impostor/Sniper.cs b/Roles/Impostor/Sniper.cs index be4d6159e..2a42f2966 100644 --- a/Roles/Impostor/Sniper.cs +++ b/Roles/Impostor/Sniper.cs @@ -139,8 +139,9 @@ public static class Sniper //至近距離で外す対策に一歩後ろから判定を開始する snipePos -= dir; - foreach (var target in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl target = Main.AllAlivePlayerControls[i]; //自分には当たらない if (target.PlayerId == sniper.PlayerId) continue; //死んでいない対象の方角ベクトル作成 diff --git a/Roles/Impostor/Twister.cs b/Roles/Impostor/Twister.cs index 81ec67c07..9a39021fd 100644 --- a/Roles/Impostor/Twister.cs +++ b/Roles/Impostor/Twister.cs @@ -54,8 +54,9 @@ namespace TOHE.Roles.Impostor TwistLimit[shapeshifter.PlayerId] -= 1; var rd = IRandom.Instance; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (changePositionPlayers.Contains(pc.PlayerId) || Pelican.IsEaten(pc.PlayerId) || !pc.IsAlive() || pc.onLadder || pc.inVent || GameStates.IsMeeting) { continue; diff --git a/Roles/Impostor/Witch.cs b/Roles/Impostor/Witch.cs index 1e0ba9ee8..de2d36ebf 100644 --- a/Roles/Impostor/Witch.cs +++ b/Roles/Impostor/Witch.cs @@ -190,8 +190,9 @@ public static class Witch SpelledPlayer[id].Clear(); } var spelledIdList = new List(); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; var dic = SpelledPlayer.Where(x => x.Value.Contains(pc.PlayerId)); if (!dic.Any()) continue; var whichId = dic.FirstOrDefault().Key; diff --git a/Roles/Neutral/DarkHide.cs b/Roles/Neutral/DarkHide.cs index 82e404794..9d8426ff2 100644 --- a/Roles/Neutral/DarkHide.cs +++ b/Roles/Neutral/DarkHide.cs @@ -93,8 +93,9 @@ public static class DarkHide MessageExtensions.WriteNetObject(SabotageFixWriter, killer); AmongUsClient.Instance.FinishRpcImmediately(SabotageFixWriter); - foreach (var target in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl target = Main.AllPlayerControls[i]; if (target.PlayerId == killer.PlayerId || target.Data.Disconnected) continue; SabotageFixWriter = AmongUsClient.Instance.StartRpcImmediately(ShipStatus.Instance.NetId, (byte)RpcCalls.RepairSystem, SendOption.Reliable, target.GetClientId()); SabotageFixWriter.Write((byte)SystemTypes.Electrical); diff --git a/Roles/Neutral/Executioner.cs b/Roles/Neutral/Executioner.cs index ccfa3817c..60ff25950 100644 --- a/Roles/Neutral/Executioner.cs +++ b/Roles/Neutral/Executioner.cs @@ -68,8 +68,9 @@ public static class Executioner { List targetList = new(); var rand = IRandom.Instance; - foreach (var target in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl target = Main.AllPlayerControls[i]; if (playerId == target.PlayerId) continue; else if (!CanTargetImpostor.GetBool() && target.Is(CustomRoleTypes.Impostor)) continue; else if (!CanTargetNeutralKiller.GetBool() && target.IsNeutralKiller()) continue; diff --git a/Roles/Neutral/Gamer.cs b/Roles/Neutral/Gamer.cs index 9e32f3e01..950e42f32 100644 --- a/Roles/Neutral/Gamer.cs +++ b/Roles/Neutral/Gamer.cs @@ -49,8 +49,11 @@ public static class Gamer { playerIdList.Add(playerId); GamerHealth.TryAdd(playerId, SelfHealthMax.GetInt()); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) + { + PlayerControl pc = Main.AllAlivePlayerControls[i]; PlayerHealth.TryAdd(pc.PlayerId, HealthMax.GetInt()); + } if (!AmongUsClient.Instance.AmHost) return; if (!Main.ResetCamPlayerList.Contains(playerId)) diff --git a/Roles/Neutral/HexMaster.cs b/Roles/Neutral/HexMaster.cs index cb0ffb0a5..e367bfe3d 100644 --- a/Roles/Neutral/HexMaster.cs +++ b/Roles/Neutral/HexMaster.cs @@ -199,8 +199,9 @@ public static class HexMaster HexedPlayer[id].Clear(); } var hexedIdList = new List(); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; var dic = HexedPlayer.Where(x => x.Value.Contains(pc.PlayerId)); if (!dic.Any()) continue; var whichId = dic.FirstOrDefault().Key; diff --git a/Roles/Neutral/Lawyer.cs b/Roles/Neutral/Lawyer.cs index 680bffc86..3d0c3a102 100644 --- a/Roles/Neutral/Lawyer.cs +++ b/Roles/Neutral/Lawyer.cs @@ -71,8 +71,9 @@ public static class Lawyer { List targetList = new(); var rand = IRandom.Instance; - foreach (var target in Main.AllPlayerControls) + for (int i = 0; i < Main.AllPlayerControls.Count; i++) { + PlayerControl target = Main.AllPlayerControls[i]; if (playerId == target.PlayerId) continue; else if (!CanTargetImpostor.GetBool() && target.Is(CustomRoleTypes.Impostor)) continue; else if (!CanTargetNeutralKiller.GetBool() && target.IsNeutralKiller()) continue; diff --git a/Roles/Neutral/Magician.cs b/Roles/Neutral/Magician.cs index 983af7a17..63491fcf0 100644 --- a/Roles/Neutral/Magician.cs +++ b/Roles/Neutral/Magician.cs @@ -377,8 +377,9 @@ public static class Magician snipePos -= dir; - foreach (var target in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl target = Main.AllAlivePlayerControls[i]; if (target.PlayerId == sniper.PlayerId) continue; var target_pos = target.transform.position - snipePos; if (target_pos.magnitude < 1) continue; diff --git a/Roles/Neutral/PlagueBearer.cs b/Roles/Neutral/PlagueBearer.cs index 4d0a113c9..d25b1b37b 100644 --- a/Roles/Neutral/PlagueBearer.cs +++ b/Roles/Neutral/PlagueBearer.cs @@ -76,11 +76,11 @@ public static class PlagueBearer } public static (int, int) PlaguedPlayerCount(byte playerId) { - int plagued = 0, all = 0; //学校で習った書き方 - //多分この方がMain.isDousedでforeachするより他のアーソニストの分ループ数少なくて済む - foreach (var pc in Main.AllAlivePlayerControls) + int plagued = 0, all = 0; + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { - if (pc.PlayerId == playerId) continue; //塗れない人は除外 (死んでたり切断済みだったり あとアーソニスト自身も) + PlayerControl pc = Main.AllAlivePlayerControls[i]; + if (pc.PlayerId == playerId) continue; all++; if (isPlagued(playerId, pc.PlayerId)) diff --git a/Roles/Neutral/Postman.cs b/Roles/Neutral/Postman.cs index 783340501..9e6adf5de 100644 --- a/Roles/Neutral/Postman.cs +++ b/Roles/Neutral/Postman.cs @@ -53,8 +53,9 @@ public static class Postman { byte tempTarget = byte.MaxValue; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (wereTargets.Contains(pc.PlayerId)) continue; tempTarget = pc.PlayerId; break; diff --git a/Roles/Neutral/Virus.cs b/Roles/Neutral/Virus.cs index 3f8e6b7ea..f5caee96d 100644 --- a/Roles/Neutral/Virus.cs +++ b/Roles/Neutral/Virus.cs @@ -130,8 +130,9 @@ namespace TOHE.Roles.Neutral } var infectedIdList = new List(); - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; bool isInfected = InfectedPlayer.Contains(pc.PlayerId); if (!isInfected) continue; diff --git a/Roles/Neutral/Vulture.cs b/Roles/Neutral/Vulture.cs index 6685f9fa7..8773af52f 100644 --- a/Roles/Neutral/Vulture.cs +++ b/Roles/Neutral/Vulture.cs @@ -128,8 +128,9 @@ public static class Vulture var pos = target.GetTruePosition(); float minDis = float.MaxValue; - foreach (var pc in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl pc = Main.AllAlivePlayerControls[i]; if (pc.PlayerId == target.PlayerId) continue; var dis = Vector2.Distance(pc.GetTruePosition(), pos); if (dis < minDis && dis < 1.5f) diff --git a/Roles/Neutral/WeaponMaster.cs b/Roles/Neutral/WeaponMaster.cs index 2411a453e..eacb43c84 100644 --- a/Roles/Neutral/WeaponMaster.cs +++ b/Roles/Neutral/WeaponMaster.cs @@ -100,8 +100,9 @@ public static class WeaponMaster case 1: _ = new LateTask(() => { - foreach (var player in Main.AllAlivePlayerControls) + for (int i = 0; i < Main.AllAlivePlayerControls.Count; i++) { + PlayerControl player = Main.AllAlivePlayerControls[i]; if (Pelican.IsEaten(player.PlayerId)) continue; if (player == killer) continue; if (player.Is(CustomRoles.Pestilence) || Main.VeteranInProtect.ContainsKey(target.PlayerId)) continue; diff --git a/main.cs b/main.cs index 7abc9b556..eac636088 100644 --- a/main.cs +++ b/main.cs @@ -234,8 +234,8 @@ public class Main : BasePlugin public static byte GodfatherTarget = byte.MaxValue; - public static IEnumerable AllPlayerControls => PlayerControl.AllPlayerControls.ToArray().Where(p => p != null); - public static IEnumerable AllAlivePlayerControls => PlayerControl.AllPlayerControls.ToArray().Where(p => p != null && p.IsAlive() && !p.Data.Disconnected && !Pelican.IsEaten(p.PlayerId)); + public static List AllPlayerControls => PlayerControl.AllPlayerControls.ToArray().Where(p => p != null).ToList(); + public static List AllAlivePlayerControls => PlayerControl.AllPlayerControls.ToArray().Where(p => p != null && p.IsAlive() && !p.Data.Disconnected && !Pelican.IsEaten(p.PlayerId)).ToList(); public static Main Instance;