diff --git a/Modules/ClientOptionItem.cs b/Modules/ClientOptionItem.cs index f3f3a8441..70046b85e 100644 --- a/Modules/ClientOptionItem.cs +++ b/Modules/ClientOptionItem.cs @@ -51,9 +51,8 @@ public class ClientOptionItem UiElement[] selectableButtons = optionsMenuBehaviour.ControllerSelectable.ToArray(); PassiveButton leaveButton = null; PassiveButton returnButton = null; - for (int i = 0; i < selectableButtons.Length; i++) + foreach (var button in selectableButtons) { - var button = selectableButtons[i]; if (button == null) continue; if (button.name == "LeaveGameButton") diff --git a/Modules/CustomRoleSelector.cs b/Modules/CustomRoleSelector.cs index 5f5cee7fc..6285b170f 100644 --- a/Modules/CustomRoleSelector.cs +++ b/Modules/CustomRoleSelector.cs @@ -123,7 +123,7 @@ internal class CustomRoleSelector ImpOnList.Remove(select); rolesToAssign.Add(select); readyRoleNum++; - Logger.Info(select.ToString() + " Join the mole role waiting list (priority)", "CustomRoleSelector"); + Logger.Info(select.ToString() + " joins the mole role waiting list (priority)", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; if (readyRoleNum >= optImpNum) break; } @@ -136,7 +136,7 @@ internal class CustomRoleSelector ImpRateList.Remove(select); rolesToAssign.Add(select); readyRoleNum++; - Logger.Info(select.ToString() + " Add to the role waiting list", "CustomRoleSelector"); + Logger.Info(select.ToString() + " added to the role waiting list", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; if (readyRoleNum >= optImpNum) break; } @@ -150,7 +150,7 @@ internal class CustomRoleSelector rolesToAssign.Add(select); readyRoleNum++; readyNonNeutralKillingNum += select.GetCount(); - Logger.Info(select.ToString() + " 加入中立职业待选列表(优先)", "CustomRoleSelector"); + Logger.Info(select.ToString() + " added to neutral role candidate list (priority)", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; if (readyNonNeutralKillingNum >= optNonNeutralKillingNum) break; } @@ -165,7 +165,7 @@ internal class CustomRoleSelector rolesToAssign.Add(select); readyRoleNum++; readyNonNeutralKillingNum += select.GetCount(); - Logger.Info(select.ToString() + " 加入中立职业待选列表", "CustomRoleSelector"); + Logger.Info(select.ToString() + " added to neutral role waiting list", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; if (readyNonNeutralKillingNum >= optNonNeutralKillingNum) break; } @@ -179,7 +179,7 @@ internal class CustomRoleSelector rolesToAssign.Add(select); readyRoleNum++; readyNeutralKillingNum += select.GetCount(); - Logger.Info(select.ToString() + " 加入中立职业待选列表(优先)", "CustomRoleSelector"); + Logger.Info(select.ToString() + " added to neutral role candidate list (priority)", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; if (readyNeutralKillingNum >= optNeutralKillingNum) break; } @@ -194,7 +194,7 @@ internal class CustomRoleSelector rolesToAssign.Add(select); readyRoleNum++; readyNeutralKillingNum += select.GetCount(); - Logger.Info(select.ToString() + " 加入中立职业待选列表", "CustomRoleSelector"); + Logger.Info(select.ToString() + " added to neutral role waiting list", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; if (readyNeutralKillingNum >= optNeutralKillingNum) break; } @@ -234,7 +234,7 @@ internal class CustomRoleSelector roleOnList.Remove(select); rolesToAssign.Add(select); readyRoleNum++; - Logger.Info(select.ToString() + " 加入船员职业待选列表(优先)", "CustomRoleSelector"); + Logger.Info(select.ToString() + " joined the crew role waiting list (priority)", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; } // 优先职业不足以分配,开始分配启用的职业 @@ -246,7 +246,7 @@ internal class CustomRoleSelector roleRateList.Remove(select); rolesToAssign.Add(select); readyRoleNum++; - Logger.Info(select.ToString() + " 加入船员职业待选列表", "CustomRoleSelector"); + Logger.Info(select.ToString() + " joined the crew role waiting list", "CustomRoleSelector"); if (readyRoleNum >= playerCount) goto EndOfAssign; } } @@ -304,7 +304,7 @@ internal class CustomRoleSelector { rolesToAssign.Remove(dr.Value); rolesToAssign.Insert(dr.Key, dr.Value); - Logger.Info("职业列表提高优先:" + dr.Value, "Dev Role"); + Logger.Info("Occupation list improved priority:" + dr.Value, "Dev Role"); continue; } for (int i = 0; i < rolesToAssign.Count; i++) @@ -320,7 +320,7 @@ internal class CustomRoleSelector { rolesToAssign.RemoveAt(i); rolesToAssign.Insert(dr.Key, dr.Value); - Logger.Info("覆盖职业列表:" + i + " " + role.ToString() + " => " + dr.Value, "Dev Role"); + Logger.Info("Coverage occupation list:" + i + " " + role.ToString() + " => " + dr.Value, "Dev Role"); break; } } diff --git a/Modules/ErrorText.cs b/Modules/ErrorText.cs index 3db7f6e03..671b5f51f 100644 --- a/Modules/ErrorText.cs +++ b/Modules/ErrorText.cs @@ -89,9 +89,8 @@ public class ErrorText : MonoBehaviour { string text = string.Empty; int maxLevel = 0; - for (int i = 0; i < AllErrors.Count; i++) + foreach (ErrorData err in AllErrors.ToArray()) { - ErrorData err = AllErrors[i]; text += $"{err}: {err.Message}\n"; if (maxLevel < err.ErrorLevel) maxLevel = err.ErrorLevel; } diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index c1b8921f4..486abb2b7 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -363,12 +363,11 @@ static class ExtendedPlayerControl } public static string GetSubRoleName(this PlayerControl player, bool forUser = false) { - var SubRoles = Main.PlayerStates[player.PlayerId].SubRoles; + var SubRoles = Main.PlayerStates[player.PlayerId].SubRoles.ToArray(); if (!SubRoles.Any()) return string.Empty; var sb = new StringBuilder(); - for (int i = 0; i < SubRoles.Count; i++) + foreach (CustomRoles role in SubRoles) { - CustomRoles role = SubRoles[i]; if (role == CustomRoles.NotAssigned) continue; sb.Append($"{Utils.ColorString(Color.white, "\n")}{Utils.GetRoleName(role, forUser)}"); } @@ -1352,11 +1351,10 @@ static class ExtendedPlayerControl public static PlainShipRoom GetPlainShipRoom(this PlayerControl pc) { if (!pc.IsAlive() || Pelican.IsEaten(pc.PlayerId)) return null; - var Rooms = ShipStatus.Instance.AllRooms; + var Rooms = ShipStatus.Instance.AllRooms.ToArray(); if (Rooms == null) return null; - for (int i = 0; i < Rooms.Count; i++) + foreach (PlainShipRoom room in Rooms) { - PlainShipRoom room = Rooms[i]; if (!room.roomArea) continue; if (pc.Collider.IsTouching(room.roomArea)) return room; @@ -1369,11 +1367,10 @@ static class ExtendedPlayerControl foreach (PlayerControl pc in Main.AllAlivePlayerControls) { if (!pc.IsAlive() || Pelican.IsEaten(pc.PlayerId)) return null; - var Rooms = ShipStatus.Instance.AllRooms; + var Rooms = ShipStatus.Instance.AllRooms.ToArray(); if (Rooms == null) return null; - for (int i = 0; i < Rooms.Count; i++) + foreach (PlainShipRoom room in Rooms) { - PlainShipRoom room = Rooms[i]; if (!room.roomArea) continue; if (pc.Collider.IsTouching(room.roomArea)) { diff --git a/Modules/GameOptionsSender/GameOptionsSender.cs b/Modules/GameOptionsSender/GameOptionsSender.cs index 8f2d39895..1b89f98d5 100644 --- a/Modules/GameOptionsSender/GameOptionsSender.cs +++ b/Modules/GameOptionsSender/GameOptionsSender.cs @@ -17,9 +17,9 @@ public abstract class GameOptionsSender public static void SendAllGameOptions() { AllSenders.RemoveAll(s => s == null || !s.AmValid()); - for (int i = 0; i < AllSenders.Count; i++) + var array = AllSenders.ToArray(); + foreach (GameOptionsSender sender in array) { - GameOptionsSender sender = AllSenders[i]; if (sender.IsDirty) sender.SendGameOptions(); sender.IsDirty = false; } diff --git a/Modules/GameOptionsSender/PlayerGameOptionsSender.cs b/Modules/GameOptionsSender/PlayerGameOptionsSender.cs index 25c0b800a..ceca7bfbc 100644 --- a/Modules/GameOptionsSender/PlayerGameOptionsSender.cs +++ b/Modules/GameOptionsSender/PlayerGameOptionsSender.cs @@ -614,9 +614,9 @@ public class PlayerGameOptionsSender : GameOptionsSender Spiritcaller.ReduceVision(opt, player); - for (int i = 0; i < Main.PlayerStates[player.PlayerId].SubRoles.Count; i++) + var array = Main.PlayerStates[player.PlayerId].SubRoles.ToArray(); + foreach (CustomRoles subRole in array) { - CustomRoles subRole = Main.PlayerStates[player.PlayerId].SubRoles[i]; switch (subRole) { case CustomRoles.Watcher: diff --git a/Modules/GuessManager.cs b/Modules/GuessManager.cs index 5b7d06816..3ff067654 100644 --- a/Modules/GuessManager.cs +++ b/Modules/GuessManager.cs @@ -31,17 +31,17 @@ public static class GuessManager public static bool CheckCommand(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string str in comList) { if (exact) { - if (msg == "/" + comList[i]) return true; + if (msg == "/" + str) return true; } else { - if (msg.StartsWith("/" + comList[i])) + if (msg.StartsWith("/" + str)) { - msg = msg.Replace("/" + comList[i], string.Empty); + msg = msg.Replace("/" + str, string.Empty); return true; } } @@ -75,9 +75,9 @@ public static class GuessManager private static bool ComfirmIncludeMsg(string msg, string key) { var keys = key.Split('|'); - for (int i = 0; i < keys.Length; i++) + foreach (string str in keys) { - if (msg.Contains(keys[i])) return true; + if (msg.Contains(str)) return true; } return false; } @@ -660,9 +660,8 @@ public static class GuessManager voteArea.Overlay.color = Color.white; voteArea.XMark.gameObject.SetActive(true); voteArea.XMark.transform.localScale = Vector3.one; - for (int i = 0; i < meetingHud.playerStates.Count; i++) + foreach (PlayerVoteArea playerVoteArea in meetingHud.playerStates.ToArray()) { - PlayerVoteArea playerVoteArea = meetingHud.playerStates[i]; if (playerVoteArea.VotedFor != pc.PlayerId) continue; playerVoteArea.UnsetVote(); var voteAreaPlayer = Utils.GetPlayerById(playerVoteArea.TargetPlayerId); @@ -700,13 +699,14 @@ public static class GuessManager voteArea.Overlay.color = Color.white; voteArea.XMark.gameObject.SetActive(true); voteArea.XMark.transform.localScale = Vector3.one; - for (int i = 0; i < meetingHud.playerStates.Count; i++) + foreach (PlayerVoteArea playerVoteArea in meetingHud.playerStates) { - PlayerVoteArea playerVoteArea = meetingHud.playerStates[i]; - if (playerVoteArea.VotedFor != pc.PlayerId) continue; + if (playerVoteArea.VotedFor != pc.PlayerId) + continue; playerVoteArea.UnsetVote(); var voteAreaPlayer = Utils.GetPlayerById(playerVoteArea.TargetPlayerId); - if (!voteAreaPlayer.AmOwner) continue; + if (!voteAreaPlayer.AmOwner) + continue; meetingHud.ClearVote(); } } @@ -838,11 +838,11 @@ public static class GuessManager } public static void CreateGuesserButton(MeetingHud __instance) { - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; var pc = Utils.GetPlayerById(pva.TargetPlayerId); - if (pc == null || !pc.IsAlive()) continue; + if (pc == null || !pc.IsAlive()) + continue; GameObject template = pva.Buttons.transform.Find("CancelButton").gameObject; GameObject targetBox = UnityEngine.Object.Instantiate(template, pva.transform); targetBox.name = "ShootButton"; @@ -870,13 +870,21 @@ public static class GuessManager foreach (var RoleButton in RoleButtons) { int index = 0; - for (int i = 0; i < RoleButton.Value.Count; i++) + foreach (Transform RoleBtn in RoleButton.Value.ToArray()) { - Transform RoleBtn = RoleButton.Value[i]; - if (RoleBtn == null) continue; + if (RoleBtn == null) + continue; index++; - if (index <= (Page - 1) * 40) { RoleBtn.gameObject.SetActive(false); continue; } - if ((Page * 40) < index) { RoleBtn.gameObject.SetActive(false); continue; } + if (index <= (Page - 1) * 40) + { + RoleBtn.gameObject.SetActive(false); + continue; + } + if ((Page * 40) < index) + { + RoleBtn.gameObject.SetActive(false); + continue; + } RoleBtn.gameObject.SetActive(RoleButton.Key == Role); } } diff --git a/Modules/HashAuth.cs b/Modules/HashAuth.cs index fcf690dbe..a2bbf0e4a 100644 --- a/Modules/HashAuth.cs +++ b/Modules/HashAuth.cs @@ -40,9 +40,8 @@ public class HashAuth // 4.hashBytesを文字列化 var sb = new StringBuilder(); - for (int i = 0; i < hashBytes.Length; i++) + foreach (byte b in hashBytes) { - byte b = hashBytes[i]; sb.Append(b.ToString("x2")); //1byteずつ2桁の16進法表記に変換する } diff --git a/Modules/LateTask.cs b/Modules/LateTask.cs index 736e19fc9..97ab93b36 100644 --- a/Modules/LateTask.cs +++ b/Modules/LateTask.cs @@ -40,9 +40,8 @@ class LateTask public static void Update(float deltaTime) { var TasksToRemove = new List(); - for (int i = 0; i < Tasks.Count; i++) + foreach (var task in Tasks.ToArray()) { - var task = Tasks[i]; try { if (task.Run(deltaTime)) diff --git a/Modules/LocateArrow.cs b/Modules/LocateArrow.cs index 6280b31c7..1126474cb 100644 --- a/Modules/LocateArrow.cs +++ b/Modules/LocateArrow.cs @@ -63,9 +63,8 @@ static class LocateArrow { var arrowInfo = new ArrowInfo(seer, locate); var removeList = new List(LocateArrows.Keys.Where(k => k.Equals(arrowInfo))); - for (int i = 0; i < removeList.Count; i++) + foreach (ArrowInfo a in removeList.ToArray()) { - ArrowInfo a = removeList[i]; LocateArrows.Remove(a); } } @@ -76,9 +75,8 @@ static class LocateArrow public static void RemoveAllTarget(byte seer) { var removeList = new List(LocateArrows.Keys.Where(k => k.From == seer)); - for (int i = 0; i < removeList.Count; i++) + foreach (ArrowInfo arrowInfo in removeList.ToArray()) { - ArrowInfo arrowInfo = removeList[i]; LocateArrows.Remove(arrowInfo); } } @@ -112,9 +110,8 @@ static class LocateArrow if (!arrowList.Any()) return; var update = false; - for (int i = 0; i < arrowList.Count; i++) + foreach (ArrowInfo arrowInfo in arrowList.ToArray()) { - ArrowInfo arrowInfo = arrowList[i]; var loc = arrowInfo.To; if (seerIsDead) { diff --git a/Modules/MafiaRevengeManager.cs b/Modules/MafiaRevengeManager.cs index fa206a325..1d6e8ef6c 100644 --- a/Modules/MafiaRevengeManager.cs +++ b/Modules/MafiaRevengeManager.cs @@ -1,6 +1,7 @@ using HarmonyLib; using Hazel; using System; +using System.Linq; using TOHE.Modules; using UnityEngine; using static TOHE.Translator; @@ -148,9 +149,8 @@ public static class MafiaRevengeManager } public static void CreateJudgeButton(MeetingHud __instance) { - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; var pc = Utils.GetPlayerById(pva.TargetPlayerId); if (pc == null || !pc.IsAlive()) continue; GameObject template = pva.Buttons.transform.Find("CancelButton").gameObject; diff --git a/Modules/ModUpdater.cs b/Modules/ModUpdater.cs index 182c83015..f482e8e84 100644 --- a/Modules/ModUpdater.cs +++ b/Modules/ModUpdater.cs @@ -361,9 +361,9 @@ public class ModUpdater file.Close(); StringBuilder sb = new(); - for (int i = 0; i < retVal.Length; i++) + foreach (byte x in retVal) { - sb.Append(retVal[i].ToString("x2")); + sb.Append(x.ToString("x2")); } return sb.ToString(); } diff --git a/Modules/OptionBackup/OptionBackupData.cs b/Modules/OptionBackup/OptionBackupData.cs index 56da06777..989e476b0 100644 --- a/Modules/OptionBackup/OptionBackupData.cs +++ b/Modules/OptionBackup/OptionBackupData.cs @@ -47,18 +47,16 @@ public class OptionBackupData AllValues.Add(new UIntOptionBackupValue(UInt32OptionNames.Keywords, (uint)option.Keywords)); RoleTypes[] array = new RoleTypes[] { RoleTypes.Scientist, RoleTypes.Engineer, RoleTypes.GuardianAngel, RoleTypes.Shapeshifter }; - for (int i = 0; i < array.Length; i++) + foreach (RoleTypes role in array) { - RoleTypes role = array[i]; AllValues.Add(new RoleRateBackupValue(role, option.RoleOptions.GetNumPerGame(role), option.RoleOptions.GetChancePerGame(role))); } } public IGameOptions Restore(IGameOptions option) { - for (int i = 0; i < AllValues.Count; i++) + foreach (OptionBackupValue value in AllValues.ToArray()) { - OptionBackupValue value = AllValues[i]; value.Restore(option); } return option; diff --git a/Modules/OptionItem/OptionItem.cs b/Modules/OptionItem/OptionItem.cs index b261e76e8..648443a4c 100644 --- a/Modules/OptionItem/OptionItem.cs +++ b/Modules/OptionItem/OptionItem.cs @@ -231,9 +231,8 @@ public abstract class OptionItem { CurrentPreset = Math.Clamp(newPreset, 0, NumPresets - 1); - for (int i = 0; i < AllOptions.Count; i++) + foreach (OptionItem op in AllOptions.ToArray()) { - OptionItem op = AllOptions[i]; op.Refresh(); } diff --git a/Modules/OptionSaver.cs b/Modules/OptionSaver.cs index 2cb9555c8..2ee279791 100644 --- a/Modules/OptionSaver.cs +++ b/Modules/OptionSaver.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text.Json; namespace TOHE.Modules; @@ -44,9 +45,8 @@ public static class OptionSaver { Dictionary singleOptions = new(); Dictionary presetOptions = new(); - for (int i = 0; i < OptionItem.AllOptions.Count; i++) + foreach (OptionItem option in OptionItem.AllOptions.ToArray()) { - OptionItem option = OptionItem.AllOptions[i]; if (option.IsSingleValue) { if (!singleOptions.TryAdd(option.Id, option.SingleValue)) diff --git a/Modules/RPC.cs b/Modules/RPC.cs index 83cf2b7df..6d47de8bd 100644 --- a/Modules/RPC.cs +++ b/Modules/RPC.cs @@ -333,10 +333,9 @@ internal class RPCHandlerPatch Logger.Msg($"StartAmount: {startAmount} - LastAmount: {lastAmount} ({startAmount}/{lastAmount}) :--: ListOptionsCount: {countOptions} - AllOptions: {countAllOptions} ({countOptions}/{countAllOptions})", "SyncCustomSettings"); // Sync Settings - for (int optionNumber = 0; optionNumber < countOptions; optionNumber++) + foreach (var option in listOptions.ToArray()) { - var co = listOptions[optionNumber]; - co.SetValue(reader.ReadInt32()); + option.SetValue(reader.ReadPackedInt32()); } OptionShower.GetText(); @@ -843,10 +842,9 @@ internal static class RPC Logger.Msg($"StartAmount: {startAmount} - LastAmount: {lastAmount} ({startAmount}/{lastAmount}) :--: ListOptionsCount: {countListOptions} - AllOptions: {amountAllOptions} ({countListOptions}/{amountAllOptions})", "SyncCustomSettings"); // Sync Settings - for (var optionNumber = 0; optionNumber < countListOptions; optionNumber++) + foreach (var option in listOptions.ToArray()) { - var opt = listOptions[optionNumber]; - writer.Write(opt.GetValue()); + writer.WritePacked(option.GetValue()); } AmongUsClient.Instance.FinishRpcImmediately(writer); diff --git a/Modules/RetributionistRevengeManager.cs b/Modules/RetributionistRevengeManager.cs index f350c7e6f..a9d21d098 100644 --- a/Modules/RetributionistRevengeManager.cs +++ b/Modules/RetributionistRevengeManager.cs @@ -1,6 +1,7 @@ using HarmonyLib; using Hazel; using System; +using System.Linq; using TOHE.Modules; using UnityEngine; using static TOHE.Translator; @@ -169,9 +170,8 @@ public static class RetributionistRevengeManager } public static void CreateJudgeButton(MeetingHud __instance) { - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; var pc = Utils.GetPlayerById(pva.TargetPlayerId); if (pc == null || !pc.IsAlive()) continue; GameObject template = pva.Buttons.transform.Find("CancelButton").gameObject; diff --git a/Modules/TargetArrow.cs b/Modules/TargetArrow.cs index 1b1f7adb8..92ed27929 100644 --- a/Modules/TargetArrow.cs +++ b/Modules/TargetArrow.cs @@ -64,9 +64,8 @@ static class TargetArrow { var arrowInfo = new ArrowInfo(seer, target); var removeList = new List(TargetArrows.Keys.Where(k => k.Equals(arrowInfo))); - for (int i = 0; i < removeList.Count; i++) + foreach (ArrowInfo a in removeList.ToArray()) { - ArrowInfo a = removeList[i]; TargetArrows.Remove(a); } } @@ -77,9 +76,8 @@ static class TargetArrow public static void RemoveAllTarget(byte seer) { var removeList = new List(TargetArrows.Keys.Where(k => k.From == seer)); - for (int i = 0; i < removeList.Count; i++) + foreach (ArrowInfo arrowInfo in removeList.ToArray()) { - ArrowInfo arrowInfo = removeList[i]; TargetArrows.Remove(arrowInfo); } } @@ -113,9 +111,8 @@ static class TargetArrow if (!arrowList.Any()) return; var update = false; - for (int i = 0; i < arrowList.Count; i++) + foreach (ArrowInfo arrowInfo in arrowList.ToArray()) { - ArrowInfo arrowInfo = arrowList[i]; var targetId = arrowInfo.To; var target = Utils.GetPlayerById(targetId); if (seerIsDead || !target.IsAlive() && !seer.Is(CustomRoles.Spiritualist)) diff --git a/Modules/TemplateManager.cs b/Modules/TemplateManager.cs index d251a38a3..0dc5bb004 100644 --- a/Modules/TemplateManager.cs +++ b/Modules/TemplateManager.cs @@ -111,7 +111,7 @@ public static class TemplateManager HudManager.Instance.Chat.AddChat(PlayerControl.LocalPlayer, string.Format(GetString("Message.TemplateNotFoundHost"), str, tags.Join(delimiter: ", "))); else Utils.SendMessage(string.Format(GetString("Message.TemplateNotFoundClient"), str), playerId); } - else for (int i = 0; i < sendList.Count; i++) Utils.SendMessage(ApplyReplaceDictionary(sendList[i]), playerId); + else foreach (string x in sendList.ToArray()) Utils.SendMessage(ApplyReplaceDictionary(x), playerId); } private static string ApplyReplaceDictionary(string text) diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 93a44f46a..565c6d91b 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -597,9 +597,8 @@ public static class Utils break; } - for (int i = 0; i < States.SubRoles.Count; i++) + foreach (CustomRoles subRole in States.SubRoles.ToArray()) { - CustomRoles subRole = States.SubRoles[i]; switch (subRole) { case CustomRoles.Madmate: @@ -1435,9 +1434,8 @@ public static class Utils sb.Append("Role Summary:"); List cloneRoles = new(Main.PlayerStates.Keys); - for (int i = 0; i < Main.winnerList.Count; i++) + foreach (byte id in Main.winnerList.ToArray()) { - byte id = Main.winnerList[i]; if (EndGamePatch.SummaryText[id].Contains("")) continue; sb.Append($"\n★ ").Append(EndGamePatch.SummaryText[id]/*.RemoveHtmlTags()*/); cloneRoles.Remove(id); @@ -1445,44 +1443,40 @@ public static class Utils if (Options.CurrentGameMode == CustomGameMode.SoloKombat) { List<(int, byte)> list = new(); - for (int i = 0; i < cloneRoles.Count; i++) + foreach (byte id in cloneRoles.ToArray()) { - byte id = cloneRoles[i]; list.Add((SoloKombatManager.GetRankOfScore(id), id)); } list.Sort(); - for (int i1 = 0; i1 < list.Count; i1++) + foreach ((int, byte) id in list.ToArray()) { - (int, byte) id = list[i1]; sb.Append($"\n  ").Append(EndGamePatch.SummaryText[id.Item2]); } } else if (Options.CurrentGameMode == CustomGameMode.FFA) { List<(int, byte)> list = new(); - for (int i = 0; i < cloneRoles.Count; i++) + foreach (byte id in cloneRoles.ToArray()) { - byte id = cloneRoles[i]; list.Add((FFAManager.GetRankOfScore(id), id)); } list.Sort(); - for (int i1 = 0; i1 < list.Count; i1++) + foreach ((int, byte) id in list.ToArray()) { - (int, byte) id = list[i1]; sb.Append($"\n  ").Append(EndGamePatch.SummaryText[id.Item2]); } } else { - for (int i = 0; i < cloneRoles.Count; i++) + foreach (byte id in cloneRoles.ToArray()) { - byte id = cloneRoles[i]; - if (EndGamePatch.SummaryText[id].Contains("")) continue; - sb.Append($"\n  ").Append(EndGamePatch.SummaryText[id]/*.RemoveHtmlTags()*/); + if (EndGamePatch.SummaryText[id].Contains("")) + continue; + sb.Append($"\n  ").Append(EndGamePatch.SummaryText[id]); } } sb.Append(""); @@ -1519,13 +1513,12 @@ public static class Utils bool isLovers = false; if (intro) { - for (int i = 0; i < SubRoles.Count; i++) + foreach (CustomRoles role in SubRoles.ToArray()) { - CustomRoles role = SubRoles[i]; - if (role is CustomRoles.NotAssigned or CustomRoles.LastImpostor) SubRoles.Remove(SubRoles[i]); + if (role is CustomRoles.NotAssigned or CustomRoles.LastImpostor) SubRoles.Remove(role); if (role is CustomRoles.Lovers) { - SubRoles.Remove(SubRoles[i]); + SubRoles.Remove(role); isLovers = true; } } @@ -1561,12 +1554,10 @@ public static class Utils } else if (!summary) { - for (int i = 0; i < SubRoles.Count; i++) + foreach (CustomRoles role in SubRoles.ToArray()) { - CustomRoles role = SubRoles[i]; - if (role is CustomRoles.NotAssigned or CustomRoles.LastImpostor) continue; - //if (summary && role is CustomRoles.Madmate or CustomRoles.Charmed or CustomRoles.Recruit or CustomRoles.Admired or CustomRoles.Infected or CustomRoles.Contagious or CustomRoles.Soulless) continue; - + if (role is CustomRoles.NotAssigned or CustomRoles.LastImpostor) + continue; var RoleText = disableColor ? GetRoleName(role) : ColorString(GetRoleColor(role), GetRoleName(role)); sb.Append($"{ColorString(Color.gray, " + ")}{RoleText}"); } @@ -2884,9 +2875,8 @@ public static class Utils public static string WriteRandomHistgram(int[] nums, float scale = 1.0f) { int[] countData = new int[nums.Max() + 1]; - for (int i = 0; i < nums.Length; i++) + foreach (int num in nums) { - int num = nums[i]; if (0 <= num) countData[num]++; } StringBuilder sb = new(); diff --git a/Patches/AirShipElectricalDoors.cs b/Patches/AirShipElectricalDoors.cs index 5829c13ac..801b8ae06 100644 --- a/Patches/AirShipElectricalDoors.cs +++ b/Patches/AirShipElectricalDoors.cs @@ -48,9 +48,8 @@ class ElectricalDoorsInitializePatch var closedoors = string.Empty; bool isFirst = true; byte[] array = AirshipElectricalDoors.GetClosedDoors(); - for (int i = 0; i < array.Length; i++) + foreach (byte num in array) { - byte num = array[i]; if (isFirst) { isFirst = false; diff --git a/Patches/AnnouncementPatch.cs b/Patches/AnnouncementPatch.cs index 8a9bb841a..193708071 100644 --- a/Patches/AnnouncementPatch.cs +++ b/Patches/AnnouncementPatch.cs @@ -110,9 +110,8 @@ public class ModNewsHistory List FinalAllNews = new(); AllModNews.Do(n => FinalAllNews.Add(n.ToAnnouncement())); - for (int i = 0; i < aRange.Count; i++) + foreach (Announcement news in aRange.ToArray()) { - Announcement news = aRange[i]; if (!AllModNews.Any(x => x.Number == news.Number)) FinalAllNews.Add(news); } diff --git a/Patches/ChatCommandPatch.cs b/Patches/ChatCommandPatch.cs index fa1e6188c..ab10a96aa 100644 --- a/Patches/ChatCommandPatch.cs +++ b/Patches/ChatCommandPatch.cs @@ -234,9 +234,8 @@ internal class ChatCommands Utils.ShowChildrenSettings(Options.CustomRoleSpawnChances[role], ref sb, command: true); var txt = sb.ToString(); _ = sb.Clear().Append(txt.RemoveHtmlTags()); - for (int i = 0; i < Main.PlayerStates[lp.PlayerId].SubRoles.Count; i++) + foreach (CustomRoles subRole in Main.PlayerStates[lp.PlayerId].SubRoles.ToArray()) { - CustomRoles subRole = Main.PlayerStates[lp.PlayerId].SubRoles[i]; _ = sb.Append($"\n\n" + GetString($"{subRole}") + Utils.GetRoleMode(subRole) + GetString($"{subRole}InfoLong")); } Utils.SendMessage(sb.ToString(), lp.PlayerId); @@ -848,9 +847,8 @@ internal class ChatCommands Utils.ShowChildrenSettings(Options.CustomRoleSpawnChances[role], ref sb, command: true); var txt = sb.ToString(); _ = sb.Clear().Append(txt.RemoveHtmlTags()); - for (int i = 0; i < Main.PlayerStates[player.PlayerId].SubRoles.Count; i++) + foreach (CustomRoles subRole in Main.PlayerStates[player.PlayerId].SubRoles.ToArray()) { - CustomRoles subRole = Main.PlayerStates[player.PlayerId].SubRoles[i]; _ = sb.Append($"\n\n" + GetString($"{subRole}") + Utils.GetRoleMode(subRole) + GetString($"{subRole}InfoLong")); } Utils.SendMessage(sb.ToString(), player.PlayerId); diff --git a/Patches/ChatControlPatch.cs b/Patches/ChatControlPatch.cs index ba18c6a96..1a489683c 100644 --- a/Patches/ChatControlPatch.cs +++ b/Patches/ChatControlPatch.cs @@ -57,17 +57,17 @@ public class ChatManager public static bool CheckCommand(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string str in comList) { if (exact) { - if (msg == "/" + comList[i]) return true; + if (msg == "/" + str) return true; } else { - if (msg.StartsWith("/" + comList[i])) + if (msg.StartsWith("/" + str)) { - msg = msg.Replace("/" + comList[i], string.Empty); + msg = msg.Replace("/" + str, string.Empty); return true; } } @@ -77,9 +77,8 @@ public class ChatManager public static bool CheckName(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string com in comList) { - string com = comList[i]; if (exact) { if (msg.Contains(com)) @@ -162,9 +161,9 @@ public class ChatManager } } - for (int i = 0; i < filtered.Length; i++) + foreach (string str in filtered) { - var entryParts = chatHistory[i].Split(':'); + var entryParts = str.Split(':'); var senderId = entryParts[0].Trim(); var senderMessage = entryParts[1].Trim(); for (int j = 2; j < entryParts.Length; j++) diff --git a/Patches/GameOptionsMenuPatch.cs b/Patches/GameOptionsMenuPatch.cs index 4f9170109..f4f492265 100644 --- a/Patches/GameOptionsMenuPatch.cs +++ b/Patches/GameOptionsMenuPatch.cs @@ -27,9 +27,8 @@ public static class GameOptionsMenuPatch { public static void Postfix(GameOptionsMenu __instance) { - for (int i = 0; i < __instance.Children.Count; i++) + foreach (OptionBehaviour ob in __instance.Children.ToArray()) { - OptionBehaviour ob = __instance.Children[i]; switch (ob.Title) { case StringNames.GameVotingTime: @@ -93,9 +92,8 @@ public static class GameOptionsMenuPatch tohMenu.GetComponentsInChildren().Do(x => Object.Destroy(x.gameObject)); var scOptions = new List(); - for (int i1 = 0; i1 < OptionItem.AllOptions.Count; i1++) + foreach (OptionItem option in OptionItem.AllOptions.ToArray()) { - OptionItem option = OptionItem.AllOptions[i1]; if (option.Tab != (TabGroup)tab) continue; if (option.OptionBehaviour == null) { @@ -186,9 +184,8 @@ public class GameOptionsMenuUpdatePatch float numItems = __instance.Children.Length; var offset = 2.7f; - for (int i1 = 0; i1 < OptionItem.AllOptions.Count; i1++) + foreach (OptionItem option in OptionItem.AllOptions.ToArray()) { - OptionItem option = OptionItem.AllOptions[i1]; if ((TabGroup)tab != option.Tab) continue; if (option?.OptionBehaviour == null || option.OptionBehaviour.gameObject == null) continue; @@ -315,9 +312,8 @@ public static class RolesSettingsMenuPatch { public static void Postfix(RolesSettingsMenu __instance) { - for (int i = 0; i < __instance.Children.Count; i++) + foreach (OptionBehaviour ob in __instance.Children.ToArray()) { - OptionBehaviour ob = __instance.Children[i]; switch (ob.Title) { case StringNames.EngineerCooldown: diff --git a/Patches/HudPatch.cs b/Patches/HudPatch.cs index 09a990798..1b2c0a98e 100644 --- a/Patches/HudPatch.cs +++ b/Patches/HudPatch.cs @@ -665,19 +665,9 @@ class SetHudActivePatch } - for (int i = 0; i < Main.PlayerStates[player.PlayerId].SubRoles.Count; i++) + if (Main.PlayerStates[player.PlayerId].SubRoles.Contains(CustomRoles.Oblivious)) { - CustomRoles subRole = Main.PlayerStates[player.PlayerId].SubRoles[i]; - switch (subRole) - { - case CustomRoles.Oblivious: - __instance.ReportButton?.ToggleVisible(false); - break; - //case CustomRoles.Mare: - // if (!Utils.IsActive(SystemTypes.Electrical)) - // __instance.KillButton.ToggleVisible(false); - // break; - } + __instance.ReportButton?.ToggleVisible(false); } __instance.KillButton?.ToggleVisible(player.CanUseKillButton()); __instance.ImpostorVentButton?.ToggleVisible(player.CanUseImpostorVentButton()); @@ -749,9 +739,8 @@ class TaskPanelBehaviourPatch var lines = taskText.Split("\r\n\n")[0].Split("\r\n\n")[0].Split("\r\n"); StringBuilder sb = new(); - for (int i = 0; i < lines.Length; i++) + foreach (string eachLine in lines) { - string eachLine = lines[i]; var line = eachLine.Trim(); if ((line.StartsWith("") || line.StartsWith("")) && sb.Length < 1 && !line.Contains('(')) continue; sb.Append(line + "\r\n"); diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index 6123c51e4..37d41d052 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -47,9 +47,8 @@ class SetUpRoleTextPatch __instance.RoleBlurbText.color = Utils.GetRoleColor(role); __instance.RoleBlurbText.text = "" + PlayerControl.LocalPlayer.GetRoleInfo() + ""; } - for (int i = 0; i < Main.PlayerStates[PlayerControl.LocalPlayer.PlayerId].SubRoles.Count; i++) + foreach (CustomRoles subRole in Main.PlayerStates[PlayerControl.LocalPlayer.PlayerId].SubRoles.ToArray()) { - CustomRoles subRole = Main.PlayerStates[PlayerControl.LocalPlayer.PlayerId].SubRoles[i]; __instance.RoleBlurbText.text += "\n" + Utils.ColorString(Utils.GetRoleColor(subRole), GetString($"{subRole}Info")); } @@ -96,9 +95,8 @@ class CoBeginPatch var tmp = GameOptionsManager.Instance.CurrentGameOptions.ToHudString(GameData.Instance ? GameData.Instance.PlayerCount : 10).Split("\r\n").Skip(1); foreach (var t in tmp) logger.Info(t); logger.Info("------------Modded Settings------------"); - for (int i = 0; i < OptionItem.AllOptions.Count; i++) + foreach (OptionItem o in OptionItem.AllOptions.ToArray()) { - OptionItem o = OptionItem.AllOptions[i]; if (!o.IsHiddenOn(Options.CurrentGameMode) && (o.Parent == null ? !o.GetString().Equals("0%") : o.Parent.GetBool())) logger.Info($"{(o.Parent == null ? o.GetName(true, true).RemoveHtmlTags().PadRightV2(40) : $"┗ {o.GetName(true, true).RemoveHtmlTags()}".PadRightV2(41))}:{o.GetString().RemoveHtmlTags()}"); } diff --git a/Patches/MeetingHudPatch.cs b/Patches/MeetingHudPatch.cs index fb79d771f..caf6f72ac 100644 --- a/Patches/MeetingHudPatch.cs +++ b/Patches/MeetingHudPatch.cs @@ -30,9 +30,8 @@ class CheckForEndVotingPatch { List statesList = new(); MeetingHud.VoterState[] states; - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; if (pva == null) continue; PlayerControl pc = Utils.GetPlayerById(pva.TargetPlayerId); if (pc == null) continue; @@ -123,9 +122,8 @@ class CheckForEndVotingPatch else if (pc.GetCustomRole() == CustomRoles.Godfather) Main.GodfatherTarget = byte.MaxValue; } } - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea ps in __instance.playerStates.ToArray()) { - PlayerVoteArea ps = __instance.playerStates[i]; if (shouldSkip) break; //Meeting Skip with vote counting on keystroke (m + delete) // Non-dead players are not voting @@ -212,9 +210,8 @@ class CheckForEndVotingPatch PlayerVoteArea pva = new(); var meetingHud = MeetingHud.Instance; PlayerControl swap1 = null; - for (int i1 = 0; i1 < NiceSwapper.Vote.Count; i1++) + foreach (byte playerId in NiceSwapper.Vote.ToArray()) { - byte playerId = NiceSwapper.Vote[i1]; var player = Utils.GetPlayerById(playerId); if (player != null) { @@ -223,9 +220,8 @@ class CheckForEndVotingPatch } } PlayerControl swap2 = null; - for (int i1 = 0; i1 < NiceSwapper.VoteTwo.Count; i1++) + foreach (byte playerId in NiceSwapper.VoteTwo.ToArray()) { - byte playerId = NiceSwapper.VoteTwo[i1]; var player = Utils.GetPlayerById(playerId); if (player != null) { @@ -235,9 +231,8 @@ class CheckForEndVotingPatch } if (swap1 != null && swap2 != null) { - for (int i1 = 0; i1 < meetingHud.playerStates.Count; i1++) + foreach (PlayerVoteArea playerVoteArea in meetingHud.playerStates.ToArray()) { - PlayerVoteArea playerVoteArea = meetingHud.playerStates[i1]; if (playerVoteArea.VotedFor != swap1.PlayerId) continue; var voteAreaPlayer = Utils.GetPlayerById(playerVoteArea.TargetPlayerId); playerVoteArea.UnsetVote(); @@ -245,9 +240,8 @@ class CheckForEndVotingPatch playerVoteArea.VotedFor = swap2.PlayerId; NiceList1.Add(voteAreaPlayer.PlayerId); } - for (int i1 = 0; i1 < meetingHud.playerStates.Count; i1++) + foreach (PlayerVoteArea playerVoteArea in meetingHud.playerStates.ToArray()) { - PlayerVoteArea playerVoteArea = meetingHud.playerStates[i1]; if (playerVoteArea.VotedFor != swap2.PlayerId) continue; var voteAreaPlayer = Utils.GetPlayerById(playerVoteArea.TargetPlayerId); if (NiceList1.Contains(voteAreaPlayer.PlayerId)) continue; @@ -352,9 +346,8 @@ class CheckForEndVotingPatch break; case TieMode.All: var exileIds = VotingData.Where(x => x.Key < 15 && x.Value == max).Select(kvp => kvp.Key).ToArray(); - for (int i = 0; i < exileIds.Length; i++) + foreach (byte playerId in exileIds) { - byte playerId = exileIds[i]; Utils.GetPlayerById(playerId).SetRealKiller(null); } @@ -541,9 +534,8 @@ class CheckForEndVotingPatch public static void TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason deathReason, params byte[] playerIds) { var AddedIdList = new List(); - for (int i = 0; i < playerIds.Length; i++) + foreach (byte playerId in playerIds) { - byte playerId = playerIds[i]; if (Main.AfterMeetingDeathPlayers.TryAdd(playerId, deathReason)) AddedIdList.Add(playerId); } @@ -555,9 +547,8 @@ class CheckForEndVotingPatch Witch.OnCheckForEndVoting(deathReason, playerIds); HexMaster.OnCheckForEndVoting(deathReason, playerIds); Virus.OnCheckForEndVoting(deathReason, playerIds); - for (int i = 0; i < playerIds.Length; i++) + foreach (byte playerId in playerIds) { - byte playerId = playerIds[i]; // Baker.OnCheckForEndVoting(playerId); //Loversの後追い @@ -601,9 +592,8 @@ static class ExtendedMeetingHud Main.BrakarVoteFor = new(); Collector.CollectorVoteFor = new(); //| 投票された人 | 投票された回数 | - for (int i = 0; i < __instance.playerStates.Length; i++) + foreach (PlayerVoteArea ps in __instance.playerStates.ToArray()) { - PlayerVoteArea ps = __instance.playerStates[i];//该玩家面板里的所有会议中的玩家 if (ps == null) continue; if (ps.VotedFor is not 252 and not byte.MaxValue and not 254)//该玩家面板里是否投了该玩家 { @@ -686,9 +676,8 @@ class MeetingHudStartPatch Utils.ShowChildrenSettings(opt, ref sb, command: true); var txt = sb.ToString(); sb.Clear().Append(txt.RemoveHtmlTags()); - for (int i = 0; i < Main.PlayerStates[pc.PlayerId].SubRoles.Count; i++) + foreach (CustomRoles subRole in Main.PlayerStates[pc.PlayerId].SubRoles.ToArray()) { - CustomRoles subRole = Main.PlayerStates[pc.PlayerId].SubRoles[i]; sb.Append($"\n\n" + GetString($"{subRole}") + Utils.GetRoleMode(subRole) + GetString($"{subRole}InfoLong")); } @@ -717,9 +706,8 @@ class MeetingHudStartPatch foreach (var pc in Main.AllAlivePlayerControls.Where(x => x.Is(CustomRoles.Workaholic)).ToArray()) Main.WorkaholicAlive.Add(pc.PlayerId); List workaholicAliveList = new(); - for (int i = 0; i < Main.WorkaholicAlive.Count; i++) + foreach (byte whId in Main.WorkaholicAlive.ToArray()) { - byte whId = Main.WorkaholicAlive[i]; workaholicAliveList.Add(Main.AllPlayerNames[whId]); } @@ -732,9 +720,8 @@ class MeetingHudStartPatch foreach (var pc in Main.AllAlivePlayerControls.Where(x => x.Is(CustomRoles.Bait)).ToArray()) Main.BaitAlive.Add(pc.PlayerId); List baitAliveList = new(); - for (int i = 0; i < Main.BaitAlive.Count; i++) + foreach (byte whId in Main.BaitAlive.ToArray()) { - byte whId = Main.BaitAlive[i]; baitAliveList.Add(Main.AllPlayerNames[whId]); } @@ -742,18 +729,16 @@ class MeetingHudStartPatch AddMsg(string.Format(GetString("BaitAdviceAlive"), string.Join(separator, baitAliveList)), 255, Utils.ColorString(Utils.GetRoleColor(CustomRoles.Bait), GetString("BaitAliveTitle"))); } string MimicMsg = string.Empty; - for (int i1 = 0; i1 < Main.AllPlayerControls.Length; i1++) + foreach (PlayerControl pc in Main.AllPlayerControls) { - PlayerControl pc = Main.AllPlayerControls[i1]; //黑手党死后技能提示 if (pc.Is(CustomRoles.Mafia) && !pc.IsAlive()) AddMsg(GetString("MafiaDeadMsg"), pc.PlayerId); if (pc.Is(CustomRoles.Retributionist) && !pc.IsAlive()) AddMsg(GetString("RetributionistDeadMsg"), pc.PlayerId); //网红死亡消息提示 - for (int i = 0; i < Main.CyberStarDead.Count; i++) + foreach (byte csId in Main.CyberStarDead.ToArray()) { - byte csId = Main.CyberStarDead[i]; if (!Options.ImpKnowCyberStarDead.GetBool() && pc.GetCustomRole().IsImpostor()) continue; if (!Options.NeutralKnowCyberStarDead.GetBool() && pc.GetCustomRole().IsNeutral()) continue; AddMsg(string.Format(GetString("CyberStarDead"), Main.AllPlayerNames[csId]), pc.PlayerId, Utils.ColorString(Utils.GetRoleColor(CustomRoles.CyberStar), GetString("CyberStarNewsTitle"))); @@ -818,9 +803,8 @@ class MeetingHudStartPatch GuessManager.textTemplate = UnityEngine.Object.Instantiate(__instance.playerStates[0].NameText); GuessManager.textTemplate.enabled = false; - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; var pc = Utils.GetPlayerById(pva.TargetPlayerId); if (pc == null) continue; var RoleTextData = Utils.GetRoleText(PlayerControl.LocalPlayer.PlayerId, pc.PlayerId); @@ -923,9 +907,8 @@ class MeetingHudStartPatch }, 3f, "SetName To Chat"); } - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; if (pva == null) continue; PlayerControl seer = PlayerControl.LocalPlayer; PlayerControl target = Utils.GetPlayerById(pva.TargetPlayerId); @@ -1117,9 +1100,8 @@ class MeetingHudStartPatch } List list = seer.GetCustomSubRoles(); - for (int i1 = 0; i1 < list.Count; i1++) + foreach (CustomRoles SeerSubRole in list.ToArray()) { - CustomRoles SeerSubRole = list[i1]; switch (SeerSubRole) { case CustomRoles.Guesser: @@ -1130,9 +1112,8 @@ class MeetingHudStartPatch } List list1 = target.GetCustomSubRoles(); - for (int i1 = 0; i1 < list1.Count; i1++) + foreach (CustomRoles subRole in list1.ToArray()) { - CustomRoles subRole = list1[i1]; switch (subRole) { case CustomRoles.Lovers: @@ -1323,10 +1304,10 @@ class MeetingHudCastVotePatch PlayerVoteArea pva_src = null; PlayerVoteArea pva_target = null; bool isSkip = false; - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - if (__instance.playerStates[i].TargetPlayerId == srcPlayerId) pva_src = __instance.playerStates[i]; - if (__instance.playerStates[i].TargetPlayerId == suspectPlayerId) pva_target = __instance.playerStates[i]; + if (pva.TargetPlayerId == srcPlayerId) pva_src = pva; + if (pva.TargetPlayerId == suspectPlayerId) pva_target = pva; } if (pva_src == null) { diff --git a/Patches/OutroPatch.cs b/Patches/OutroPatch.cs index 909249a6c..8f6d8d3b4 100644 --- a/Patches/OutroPatch.cs +++ b/Patches/OutroPatch.cs @@ -56,9 +56,8 @@ class EndGamePatch Main.winnerNameList = new(); Main.winnerList = new(); - for (int i = 0; i < winner.Count; i++) + foreach (PlayerControl pc in winner.ToArray()) { - PlayerControl pc = winner[i]; if (CustomWinnerHolder.WinnerTeam is not CustomWinner.Draw && pc.Is(CustomRoles.GM)) continue; TempData.winners.Add(new WinningPlayerData(pc.Data)); @@ -244,9 +243,8 @@ class SetEverythingUpPatch StringBuilder sb = new($"{GetString("RoleSummaryText")}\n"); List cloneRoles = new(Main.PlayerStates.Keys); - for (int i = 0; i < Main.winnerList.Count; i++) + foreach (byte id in Main.winnerList.ToArray()) { - byte id = Main.winnerList[i]; if (EndGamePatch.SummaryText[id].Contains("")) continue; sb.Append($"\n").Append(EndGamePatch.SummaryText[id]); cloneRoles.Remove(id); @@ -254,9 +252,8 @@ class SetEverythingUpPatch if (Options.CurrentGameMode == CustomGameMode.SoloKombat) { List<(int, byte)> list = new(); - for (int i = 0; i < cloneRoles.Count; i++) + foreach (byte id in cloneRoles.ToArray()) { - byte id = cloneRoles[i]; list.Add((SoloKombatManager.GetRankOfScore(id), id)); } @@ -267,9 +264,8 @@ class SetEverythingUpPatch else if (Options.CurrentGameMode == CustomGameMode.FFA) { List<(int, byte)> list = new(); - for (int i = 0; i < cloneRoles.Count; i++) + foreach (byte id in cloneRoles.ToArray()) { - byte id = cloneRoles[i]; list.Add((FFAManager.GetRankOfScore(id), id)); } @@ -280,10 +276,10 @@ class SetEverythingUpPatch else { sb.Append($"\n"); - for (int i = 0; i < cloneRoles.Count; i++) + foreach (byte id in cloneRoles.ToArray()) { - byte id = cloneRoles[i]; - if (EndGamePatch.SummaryText[id].Contains("")) continue; + if (EndGamePatch.SummaryText[id].Contains("")) + continue; sb.Append('\n').Append(EndGamePatch.SummaryText[id]); } } diff --git a/Patches/PlayerContorolPatch.cs b/Patches/PlayerContorolPatch.cs index 96e1b60ec..8d49f3550 100644 --- a/Patches/PlayerContorolPatch.cs +++ b/Patches/PlayerContorolPatch.cs @@ -3018,21 +3018,16 @@ class FixedUpdatePatch if (!Main.LoversPlayers.Any()) return; if (Options.LoverSuicide.GetBool() && Main.isLoversDead == false) { - for (int i = 0; i < Main.LoversPlayers.Count; i++) + foreach (PlayerControl loversPlayer in Main.LoversPlayers.ToArray()) { - PlayerControl loversPlayer = Main.LoversPlayers[i]; - //生きていて死ぬ予定でなければスキップ - if (!loversPlayer.Data.IsDead && loversPlayer.PlayerId != deathId) continue; - + if (!loversPlayer.Data.IsDead && loversPlayer.PlayerId != deathId) + continue; Main.isLoversDead = true; for (int i1 = 0; i1 < Main.LoversPlayers.Count; i1++) { PlayerControl partnerPlayer = Main.LoversPlayers[i1]; - //本人ならスキップ - if (loversPlayer.PlayerId == partnerPlayer.PlayerId) continue; - - //残った恋人を全て殺す(2人以上可) - //生きていて死ぬ予定もない場合は心中 + if (loversPlayer.PlayerId == partnerPlayer.PlayerId) + continue; if (partnerPlayer.PlayerId != deathId && !partnerPlayer.Data.IsDead) { if (partnerPlayer.Is(CustomRoles.Lovers)) @@ -3447,10 +3442,9 @@ class CoEnterVentPatch CustomWinnerHolder.ResetAndSetWinner(CustomWinner.Revolutionist);//革命者胜利 GetDrawPlayerCount(__instance.myPlayer.PlayerId, out var x); CustomWinnerHolder.WinnerIds.Add(__instance.myPlayer.PlayerId); - for (int i = 0; i < x.Count; i++) + foreach (PlayerControl apc in x.ToArray()) { - PlayerControl apc = x[i]; - CustomWinnerHolder.WinnerIds.Add(apc.PlayerId);//胜利玩家 + CustomWinnerHolder.WinnerIds.Add(apc.PlayerId); } return true; diff --git a/Patches/ShipStatusPatch.cs b/Patches/ShipStatusPatch.cs index 2b0011c93..e75306db4 100644 --- a/Patches/ShipStatusPatch.cs +++ b/Patches/ShipStatusPatch.cs @@ -176,9 +176,8 @@ class RepairSystemPatch private static void CheckAndOpenDoors(ShipStatus __instance, int amount, params int[] DoorIds) { if (!DoorIds.Contains(amount)) return; - for (int i = 0; i < DoorIds.Length; i++) + foreach (int id in DoorIds) { - int id = DoorIds[i]; __instance.RpcUpdateSystem(SystemTypes.Doors, (byte)id); } } diff --git a/Patches/TaskAssignPatch.cs b/Patches/TaskAssignPatch.cs index 17089abd8..ac6d67d40 100644 --- a/Patches/TaskAssignPatch.cs +++ b/Patches/TaskAssignPatch.cs @@ -100,9 +100,8 @@ class AddTasksFromListPatch break; } } - for (int i = 0; i < disabledTasks.Count; i++) + foreach (NormalPlayerTask task in disabledTasks.ToArray()) { - NormalPlayerTask task = disabledTasks[i]; Logger.Msg("Deleted assigned task: " + task.TaskType.ToString(), "AddTask"); unusedTasks.Remove(task); } @@ -178,9 +177,8 @@ class RpcSetTasksPatch //割り当て可能なタスクのIDが入ったリスト //本来のRpcSetTasksの第二引数のクローン Il2CppSystem.Collections.Generic.List TasksList = new(); - for (int i1 = 0; i1 < taskTypeIds.Count; i1++) + foreach (byte num in taskTypeIds.ToArray()) { - byte num = taskTypeIds[i1]; TasksList.Add(num); } diff --git a/Patches/onGameStartedPatch.cs b/Patches/onGameStartedPatch.cs index 6908bbd82..698006939 100644 --- a/Patches/onGameStartedPatch.cs +++ b/Patches/onGameStartedPatch.cs @@ -414,9 +414,8 @@ internal class SelectRolesPatch try { List<(PlayerControl, RoleTypes)> newList = new(); - for (int i = 0; i < RpcSetRoleReplacer.StoragedData.Count; i++) + foreach ((PlayerControl, RoleTypes) sd in RpcSetRoleReplacer.StoragedData.ToArray()) { - (PlayerControl, RoleTypes) sd = RpcSetRoleReplacer.StoragedData[i]; var kp = RoleResult.FirstOrDefault(x => x.Key.PlayerId == sd.Item1.PlayerId); newList.Add((sd.Item1, kp.Value.GetRoleTypes())); if (sd.Item2 == kp.Value.GetRoleTypes()) @@ -487,9 +486,8 @@ internal class SelectRolesPatch } if (CustomRoles.Lovers.IsEnable() && (CustomRoles.FFF.IsEnable() ? -1 : rd.Next(1, 100)) <= Options.LoverSpawnChances.GetInt()) AssignLoversRolesFromList(); - for (int i = 0; i < AddonRolesList.Count; i++) + foreach (CustomRoles role in AddonRolesList.ToArray()) { - CustomRoles role = AddonRolesList[i]; if (rd.Next(1, 100) <= (Options.CustomAdtRoleSpawnRate.TryGetValue(role, out var sc) ? sc.GetFloat() : 0)) if (role.IsEnable()) AssignSubRoles(role); } @@ -499,9 +497,8 @@ internal class SelectRolesPatch { ExtendedPlayerControl.RpcSetCustomRole(pair.Key, pair.Value.MainRole); - for (int i = 0; i < pair.Value.SubRoles.Count; i++) + foreach (CustomRoles subRole in pair.Value.SubRoles.ToArray()) { - CustomRoles subRole = pair.Value.SubRoles[i]; ExtendedPlayerControl.RpcSetCustomRole(pair.Key, subRole); } } @@ -1195,9 +1192,8 @@ internal class SelectRolesPatch if (sender.Value.CurrentState != CustomRpcSender.State.InRootMessage) throw new InvalidOperationException("A CustomRpcSender had Invalid State."); - for (int i = 0; i < StoragedData.Count; i++) + foreach ((PlayerControl, RoleTypes) pair in StoragedData.ToArray()) { - (PlayerControl, RoleTypes) pair = StoragedData[i]; pair.Item1.SetRole(pair.Item2); sender.Value.AutoStartRpc(pair.Item1.NetId, (byte)RpcCalls.SetRole, Utils.GetPlayerById(sender.Key).GetClientId()) .Write((ushort)pair.Item2) diff --git a/Roles/Crewmate/Addict.cs b/Roles/Crewmate/Addict.cs index 9fe675c74..c9964d6cd 100644 --- a/Roles/Crewmate/Addict.cs +++ b/Roles/Crewmate/Addict.cs @@ -55,9 +55,8 @@ namespace TOHE.Roles.Crewmate public static void OnReportDeadBody() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte player in playerIdList.ToArray()) { - byte player = playerIdList[i]; SuicideTimer[player] = -10f; ImmortalTimer[player] = 420f; Main.AllPlayerSpeed[player] = DefaultSpeed; diff --git a/Roles/Crewmate/Bloodhound.cs b/Roles/Crewmate/Bloodhound.cs index b1ea79527..7e8adee0c 100644 --- a/Roles/Crewmate/Bloodhound.cs +++ b/Roles/Crewmate/Bloodhound.cs @@ -95,18 +95,16 @@ public static void Clear() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte apc in playerIdList.ToArray()) { - byte apc = playerIdList[i]; LocateArrow.RemoveAllTarget(apc); SendRPC(apc, false); } foreach (var bloodhound in BloodhoundTargets) { - for (int i = 0; i < bloodhound.Value.Count; i++) + foreach (byte target in bloodhound.Value.ToArray()) { - byte target = bloodhound.Value[i]; TargetArrow.Remove(bloodhound.Key, target); } @@ -118,11 +116,11 @@ { if (!ArrowsPointingToDeadBody.GetBool()) return; - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; var player = Utils.GetPlayerById(pc); - if (player == null || !player.IsAlive()) continue; + if (player == null || !player.IsAlive()) + continue; LocateArrow.Add(pc, target.transform.position); SendRPC(pc, true, target.transform.position); } @@ -168,9 +166,8 @@ if (BloodhoundTargets.ContainsKey(seer.PlayerId) && BloodhoundTargets[seer.PlayerId].Any()) { var arrows = string.Empty; - for (int i = 0; i < BloodhoundTargets[seer.PlayerId].Count; i++) + foreach (byte targetId in BloodhoundTargets[seer.PlayerId].ToArray()) { - byte targetId = BloodhoundTargets[seer.PlayerId][i]; var arrow = TargetArrow.GetArrows(seer, targetId); arrows += Utils.ColorString(seer.GetRoleColor(), arrow); } diff --git a/Roles/Crewmate/CopyCat.cs b/Roles/Crewmate/CopyCat.cs index bfa6b5f2d..6c306f166 100644 --- a/Roles/Crewmate/CopyCat.cs +++ b/Roles/Crewmate/CopyCat.cs @@ -68,21 +68,12 @@ public static class CopyCat public static void AfterMeetingTasks() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte player in playerIdList.ToArray()) { - byte player = playerIdList[i]; var pc = Utils.GetPlayerById(player); var role = pc.GetCustomRole(); - //////////// /*remove the settings for current role*/ ///////////////////// switch (role) { - //case CustomRoles.Addict: - // Addict.SuicideTimer.Remove(player); - // Addict.ImmortalTimer.Remove(player); - // break; - //case CustomRoles.Bloodhound: - // Bloodhound.BloodhoundTargets.Remove(player); - // break; case CustomRoles.ParityCop: ParityCop.MaxCheckLimit.Remove(player); ParityCop.RoundCheckLimit.Remove(player); @@ -111,9 +102,6 @@ public static class CopyCat case CustomRoles.Oracle: Oracle.CheckLimit.Remove(player); break; - //case CustomRoles.DovesOfNeace: - // Main.DovesOfNeaceNumOfUsed.Remove(player); - // break; case CustomRoles.Paranoia: Main.ParaUsedButtonCount.Remove(player); break; @@ -124,22 +112,6 @@ public static class CopyCat Snitch.IsExposed.Remove(player); Snitch.IsComplete.Remove(player); break; - //case CustomRoles.Spiritualist: - // Spiritualist.LastGhostArrowShowTime.Remove(player); - // Spiritualist.ShowGhostArrowUntil.Remove(player); - // break; - //case CustomRoles.Tracker: - // Tracker.TrackLimit.Remove(player); - // Tracker.TrackerTarget.Remove(player); - // break; - //case CustomRoles.Counterfeiter: - // Counterfeiter.SeelLimit.Remove(player); - // break; - //case CustomRoles.SwordsMan: - // if (!AmongUsClient.Instance.AmHost) break; - // if (!Main.ResetCamPlayerList.Contains(player)) - // Main.ResetCamPlayerList.Add(player); - // break; case CustomRoles.Sheriff: Sheriff.CurrentKillCooldown.Remove(player); Sheriff.ShotLimit.Remove(player); diff --git a/Roles/Crewmate/Enigma.cs b/Roles/Crewmate/Enigma.cs index c57ac2683..96dddc437 100644 --- a/Roles/Crewmate/Enigma.cs +++ b/Roles/Crewmate/Enigma.cs @@ -94,9 +94,8 @@ namespace TOHE.Roles.Crewmate string msg; var rd = IRandom.Instance; - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte playerId in playerIdList.ToArray()) { - byte playerId = playerIdList[i]; if (!EnigmaGetCluesWithoutReporting.GetBool() && playerId != player.PlayerId) continue; var enigmaPlayer = Utils.GetPlayerById(playerId); diff --git a/Roles/Crewmate/Judge.cs b/Roles/Crewmate/Judge.cs index 640a9fa3d..052c4f84b 100644 --- a/Roles/Crewmate/Judge.cs +++ b/Roles/Crewmate/Judge.cs @@ -58,10 +58,9 @@ public static class Judge public static bool IsEnable => playerIdList.Any(); public static void OnReportDeadBody() { - List list = TrialLimit.Keys.ToList(); - for (int i = 0; i < list.Count; i++) + byte[] list = TrialLimit.Keys.ToArray(); + foreach (byte pid in list) { - byte pid = list[i]; TrialLimit[pid] = TrialLimitPerMeeting.GetInt(); } } @@ -208,17 +207,17 @@ public static class Judge public static bool CheckCommand(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string str in comList) { if (exact) { - if (msg == "/" + comList[i]) return true; + if (msg == "/" + str) return true; } else { - if (msg.StartsWith("/" + comList[i])) + if (msg.StartsWith("/" + str)) { - msg = msg.Replace("/" + comList[i], string.Empty); + msg = msg.Replace("/" + str, string.Empty); return true; } } diff --git a/Roles/Crewmate/Medic.cs b/Roles/Crewmate/Medic.cs index 2a92d8949..f57c3c572 100644 --- a/Roles/Crewmate/Medic.cs +++ b/Roles/Crewmate/Medic.cs @@ -103,8 +103,8 @@ public static class Medic { MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetMedicalerProtectList, SendOption.Reliable, -1); writer.Write(ProtectList.Count); - for (int i = 0; i < ProtectList.Count; i++) - writer.Write(ProtectList[i]); + foreach (byte x in ProtectList.ToArray()) + writer.Write(x); AmongUsClient.Instance.FinishRpcImmediately(writer); } public static void ReceiveRPCForProtectList(MessageReader reader) @@ -198,14 +198,12 @@ public static class Medic if (ShieldDeactivationIsVisible.GetInt() == 1) { TempMarkProtected = byte.MaxValue; - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); } - for (int i = 0; i < ProtectList.Count; i++) + foreach (byte pc in ProtectList.ToArray()) { - byte pc = ProtectList[i]; Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); } } @@ -215,9 +213,8 @@ public static class Medic if (!target.Is(CustomRoles.Medic)) return; if (!ShieldDeactivatesWhenMedicDies.GetBool()) return; - for (int i = 0; i < ProtectList.Count; i++) + foreach (byte pc in ProtectList.ToArray()) { - byte pc = ProtectList[i]; Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); } Utils.NotifyRoles(SpecifySeer: target); diff --git a/Roles/Crewmate/Mediumshiper.cs b/Roles/Crewmate/Mediumshiper.cs index f64af1d02..1c3480e98 100644 --- a/Roles/Crewmate/Mediumshiper.cs +++ b/Roles/Crewmate/Mediumshiper.cs @@ -98,17 +98,17 @@ public static class Mediumshiper public static bool CheckCommond(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string str in comList) { if (exact) { - if (msg == "/" + comList[i]) return true; + if (msg == "/" + str) return true; } else { - if (msg.StartsWith("/" + comList[i])) + if (msg.StartsWith("/" + str)) { - msg = msg.Replace("/" + comList[i], string.Empty); + msg = msg.Replace("/" + str, string.Empty); return true; } } diff --git a/Roles/Crewmate/Monitor.cs b/Roles/Crewmate/Monitor.cs index 45899c695..6a7fb2a5b 100644 --- a/Roles/Crewmate/Monitor.cs +++ b/Roles/Crewmate/Monitor.cs @@ -120,12 +120,11 @@ internal class Monitor if (isChange) { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); } - foreach (PlayerControl pc in Main.AllPlayerControls) + foreach (PlayerControl pc in Main.AllAlivePlayerControls) { FixedUpdatePatch.Postfix(pc); } diff --git a/Roles/Crewmate/Mortician.cs b/Roles/Crewmate/Mortician.cs index 92b9b31a9..ae45834c3 100644 --- a/Roles/Crewmate/Mortician.cs +++ b/Roles/Crewmate/Mortician.cs @@ -71,9 +71,8 @@ public static class Mortician } lastPlayerName.TryAdd(target.PlayerId, minName); - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; var player = Utils.GetPlayerById(pc); if (player == null || !player.IsAlive()) continue; LocateArrow.Add(pc, target.transform.position); @@ -82,9 +81,8 @@ public static class Mortician } public static void OnReportDeadBody(PlayerControl pc, GameData.PlayerInfo target) { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte apc in playerIdList.ToArray()) { - byte apc = playerIdList[i]; LocateArrow.RemoveAllTarget(apc); SendRPC(apc, false); } diff --git a/Roles/Crewmate/NiceEraser.cs b/Roles/Crewmate/NiceEraser.cs index 337105384..76cbba49c 100644 --- a/Roles/Crewmate/NiceEraser.cs +++ b/Roles/Crewmate/NiceEraser.cs @@ -92,9 +92,8 @@ internal static class NiceEraser } public static void AfterMeetingTasks() { - for (int i = 0; i < PlayerToErase.Count; i++) + foreach (byte pc in PlayerToErase.ToArray()) { - byte pc = PlayerToErase[i]; var player = Utils.GetPlayerById(pc); if (player == null) continue; player.RpcSetCustomRole(CustomRolesHelper.GetErasedRole(player.GetCustomRole())); diff --git a/Roles/Crewmate/NiceSwapper.cs b/Roles/Crewmate/NiceSwapper.cs index 76b2d007d..bbfbdbb89 100644 --- a/Roles/Crewmate/NiceSwapper.cs +++ b/Roles/Crewmate/NiceSwapper.cs @@ -160,14 +160,12 @@ public static class NiceSwapper { PlayerControl player1 = new(); PlayerControl player2 = new(); - for (int i = 0; i < Vote.Count; i++) + foreach (byte swap1 in Vote.ToArray()) { - byte swap1 = Vote[i]; player1.PlayerId = swap1; } - for (int i = 0; i < Vote.Count; i++) + foreach (byte swap2 in Vote.ToArray()) { - byte swap2 = Vote[i]; player2.PlayerId = swap2; } } @@ -218,17 +216,17 @@ public static class NiceSwapper public static bool CheckCommond(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string str in comList) { if (exact) { - if (msg == "/" + comList[i]) return true; + if (msg == "/" + str) return true; } else { - if (msg.StartsWith("/" + comList[i])) + if (msg.StartsWith("/" + str)) { - msg = msg.Replace("/" + comList[i], string.Empty); + msg = msg.Replace("/" + str, string.Empty); return true; } } @@ -274,9 +272,8 @@ public static class NiceSwapper } public static void CreateSwapperButton(MeetingHud __instance) { - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; var pc = Utils.GetPlayerById(pva.TargetPlayerId); if (pc == null || !pc.IsAlive()) continue; GameObject template = pva.Buttons.transform.Find("CancelButton").gameObject; diff --git a/Roles/Crewmate/ParityCop.cs b/Roles/Crewmate/ParityCop.cs index 5e2dd55a5..d4d13b1bf 100644 --- a/Roles/Crewmate/ParityCop.cs +++ b/Roles/Crewmate/ParityCop.cs @@ -72,9 +72,8 @@ public static class ParityCop public static void OnReportDeadBody() { RoundCheckLimit.Clear(); - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; RoundCheckLimit.Add(pc, ParityCheckLimitPerMeeting.GetInt()); } } @@ -269,17 +268,17 @@ public static class ParityCop public static bool CheckCommand(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string str in comList) { if (exact) { - if (msg == "/" + comList[i]) return true; + if (msg == "/" + str) return true; } else { - if (msg.StartsWith("/" + comList[i])) + if (msg.StartsWith("/" + str)) { - msg = msg.Replace("/" + comList[i], string.Empty); + msg = msg.Replace("/" + str, string.Empty); return true; } } diff --git a/Roles/Crewmate/Psychic.cs b/Roles/Crewmate/Psychic.cs index c1e59f9d1..ef865f5b3 100644 --- a/Roles/Crewmate/Psychic.cs +++ b/Roles/Crewmate/Psychic.cs @@ -44,9 +44,8 @@ public static class Psychic { MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncPsychicRedList, SendOption.Reliable, -1); writer.Write(RedPlayer.Count); - for (int i = 0; i < RedPlayer.Count; i++) + foreach (byte pc in RedPlayer.ToArray()) { - byte pc = RedPlayer[i]; writer.Write(pc); } diff --git a/Roles/Crewmate/Sheriff.cs b/Roles/Crewmate/Sheriff.cs index 0ff6d2f8f..a1fb08848 100644 --- a/Roles/Crewmate/Sheriff.cs +++ b/Roles/Crewmate/Sheriff.cs @@ -150,27 +150,21 @@ public static class Sheriff var cRole = player.GetCustomRole(); var subRole = player.GetCustomSubRoles(); bool CanKill = false; - for (int i = 0; i < subRole.Count; i++) + foreach (CustomRoles SubRoleTarget in subRole.ToArray()) { - CustomRoles SubRoleTarget = subRole[i]; - if (SubRoleTarget == CustomRoles.Madmate) - CanKill = CanKillMadmate.GetBool(); - if (SubRoleTarget == CustomRoles.Charmed) - CanKill = CanKillCharmed.GetBool(); - if (SubRoleTarget == CustomRoles.Lovers) - CanKill = CanKillLovers.GetBool(); - if (SubRoleTarget == CustomRoles.Recruit) - CanKill = CanKillSidekicks.GetBool(); - if (SubRoleTarget == CustomRoles.Egoist) - CanKill = CanKillEgoists.GetBool(); - if (SubRoleTarget == CustomRoles.Infected) - CanKill = CanKillInfected.GetBool(); - if (SubRoleTarget == CustomRoles.Contagious) - CanKill = CanKillContagious.GetBool(); - if (SubRoleTarget == CustomRoles.Rascal) - CanKill = true; - if (SubRoleTarget == CustomRoles.Admired) - CanKill = false; + CanKill = SubRoleTarget switch + { + CustomRoles.Madmate => CanKillMadmate.GetBool(), + CustomRoles.Charmed => CanKillCharmed.GetBool(), + CustomRoles.Lovers => CanKillLovers.GetBool(), + CustomRoles.Recruit => CanKillSidekicks.GetBool(), + CustomRoles.Egoist => CanKillEgoists.GetBool(), + CustomRoles.Infected => CanKillInfected.GetBool(), + CustomRoles.Contagious => CanKillContagious.GetBool(), + CustomRoles.Rascal => true, + CustomRoles.Admired => false, + _ => false, + }; } diff --git a/Roles/Crewmate/Spiritualist.cs b/Roles/Crewmate/Spiritualist.cs index 475d6eed3..b763e7719 100644 --- a/Roles/Crewmate/Spiritualist.cs +++ b/Roles/Crewmate/Spiritualist.cs @@ -77,9 +77,8 @@ namespace TOHE.Roles.Crewmate public static void AfterMeetingTasks() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte spiritualist in playerIdList.ToArray()) { - byte spiritualist = playerIdList[i]; PlayerControl player = Main.AllPlayerControls.FirstOrDefault(a => a.PlayerId == spiritualist); if (!player.IsAlive()) { @@ -129,9 +128,8 @@ namespace TOHE.Roles.Crewmate public static void RemoveTarget() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte spiritualist in playerIdList.ToArray()) { - byte spiritualist = playerIdList[i]; TargetArrow.Remove(spiritualist, SpiritualistTarget); } diff --git a/Roles/Crewmate/TimeManager.cs b/Roles/Crewmate/TimeManager.cs index 08fe3b148..19a5abfaa 100644 --- a/Roles/Crewmate/TimeManager.cs +++ b/Roles/Crewmate/TimeManager.cs @@ -39,9 +39,8 @@ public static class TimeManager public static int TotalIncreasedMeetingTime() { int sec = 0; - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte playerId in playerIdList.ToArray()) { - byte playerId = playerIdList[i]; if (Utils.GetPlayerById(playerId).Is(CustomRoles.Madmate)) sec -= AdditionalTime(playerId); else sec += AdditionalTime(playerId); } diff --git a/Roles/Crewmate/Tracefinder.cs b/Roles/Crewmate/Tracefinder.cs index ad4d4507e..a273c3b30 100644 --- a/Roles/Crewmate/Tracefinder.cs +++ b/Roles/Crewmate/Tracefinder.cs @@ -69,9 +69,8 @@ public static class Tracefinder } public static void OnReportDeadBody(/*PlayerControl pc, GameData.PlayerInfo target*/) { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte apc in playerIdList.ToArray()) { - byte apc = playerIdList[i]; LocateArrow.RemoveAllTarget(apc); SendRPC(apc, false); } @@ -101,11 +100,11 @@ public static class Tracefinder _ = new LateTask(() => { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; var player = Utils.GetPlayerById(pc); - if (player == null || !player.IsAlive()) continue; + if (player == null || !player.IsAlive()) + continue; LocateArrow.Add(pc, target.transform.position); SendRPC(pc, true, target.transform.position); Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); diff --git a/Roles/Impostor/AntiAdminer.cs b/Roles/Impostor/AntiAdminer.cs index fdf771271..14d51b055 100644 --- a/Roles/Impostor/AntiAdminer.cs +++ b/Roles/Impostor/AntiAdminer.cs @@ -118,9 +118,8 @@ internal class AntiAdminer if (isChange) { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(pc)); } foreach (PlayerControl pc in Main.AllPlayerControls) diff --git a/Roles/Impostor/BallLightning.cs b/Roles/Impostor/BallLightning.cs index fdf46b960..d1e7c75fd 100644 --- a/Roles/Impostor/BallLightning.cs +++ b/Roles/Impostor/BallLightning.cs @@ -106,9 +106,8 @@ public static class BallLightning { if (!IsEnable || !GameStates.IsInTask) return; List deList = new(); - for (int i = 0; i < GhostPlayer.Count; i++) + foreach (byte ghost in GhostPlayer.ToArray()) { - byte ghost = GhostPlayer[i]; var gs = Utils.GetPlayerById(ghost); if (gs == null || !gs.IsAlive() || gs.Data.Disconnected) { @@ -134,9 +133,8 @@ public static class BallLightning if (deList.Any()) { GhostPlayer.RemoveAll(deList.Contains); - for (int i = 0; i < deList.Count; i++) + foreach (byte gs in deList.ToArray()) { - byte gs = deList[i]; SendRPC(gs); Utils.NotifyRoles(SpecifySeer: Utils.GetPlayerById(gs)); } @@ -146,11 +144,11 @@ public static class BallLightning { if (!(IsEnable || CustomRoles.BallLightning.IsEnable())) return; - for (int i = 0; i < GhostPlayer.Count; i++) + foreach (byte ghost in GhostPlayer.ToArray()) { - byte ghost = GhostPlayer[i]; var gs = Utils.GetPlayerById(ghost); - if (gs == null) continue; + if (gs == null) + continue; CheckForEndVotingPatch.TryAddAfterMeetingDeathPlayers(PlayerState.DeathReason.Quantization, gs.PlayerId); gs.SetRealKiller(RealKiller[gs.PlayerId]); Logger.Info($"{gs.GetNameWithRole().RemoveHtmlTags()} 作为量子幽灵参与会议,将在会议后死亡", "BallLightning"); diff --git a/Roles/Impostor/BountyHunter.cs b/Roles/Impostor/BountyHunter.cs index 5148b6c7d..7891e5621 100644 --- a/Roles/Impostor/BountyHunter.cs +++ b/Roles/Impostor/BountyHunter.cs @@ -190,12 +190,10 @@ public static class BountyHunter //public static void SetAbilityButtonText(HudManager __instance) => __instance.AbilityButton.OverrideText(GetString("BountyHunterChangeButtonText")); public static void AfterMeetingTasks() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte id in playerIdList.ToArray()) { - byte id = playerIdList[i]; if (!Main.PlayerStates[id].IsDead) { - //Utils.GetPlayerById(id)?.RpcResetAbilityCooldown(); ChangeTimer[id] = 0f; Timer = (int)TargetChangeTime; if (Utils.GetPlayerById(id).GetCustomRole() == CustomRoles.BountyHunter) diff --git a/Roles/Impostor/Councillor.cs b/Roles/Impostor/Councillor.cs index 8e9fe5412..43ed5d5ba 100644 --- a/Roles/Impostor/Councillor.cs +++ b/Roles/Impostor/Councillor.cs @@ -57,9 +57,8 @@ public static class Councillor public static void OnReportDeadBody() { MurderLimit.Clear(); - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; MurderLimit.Add(pc, MurderLimitPerMeeting.GetInt()); } } @@ -208,17 +207,17 @@ public static class Councillor public static bool CheckCommond(ref string msg, string command, bool exact = true) { var comList = command.Split('|'); - for (int i = 0; i < comList.Length; i++) + foreach (string str in comList) { if (exact) { - if (msg == "/" + comList[i]) return true; + if (msg == "/" + str) return true; } else { - if (msg.StartsWith("/" + comList[i])) + if (msg.StartsWith("/" + str)) { - msg = msg.Replace("/" + comList[i], string.Empty); + msg = msg.Replace("/" + str, string.Empty); return true; } } @@ -258,9 +257,8 @@ public static class Councillor } public static void CreateCouncillorButton(MeetingHud __instance) { - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; var pc = Utils.GetPlayerById(pva.TargetPlayerId); if (pc == null || !pc.IsAlive()) continue; GameObject template = pva.Buttons.transform.Find("CancelButton").gameObject; diff --git a/Roles/Impostor/Deathpact.cs b/Roles/Impostor/Deathpact.cs index c0e805474..29a2c8a4f 100644 --- a/Roles/Impostor/Deathpact.cs +++ b/Roles/Impostor/Deathpact.cs @@ -95,10 +95,8 @@ namespace TOHE.Roles.Impostor if (ReduceVisionWhileInPact.GetBool()) { - for (int i = 0; i < PlayersInDeathpact[pc.PlayerId].Count; i++) + foreach (PlayerControl player in PlayersInDeathpact[pc.PlayerId].ToArray()) { - PlayerControl player = PlayersInDeathpact[pc.PlayerId][i]; - foreach (var otherPlayerInPact in PlayersInDeathpact[pc.PlayerId].Where(a => a.PlayerId != player.PlayerId)) { otherPlayerInPact.MarkDirtySettings(); @@ -113,10 +111,8 @@ namespace TOHE.Roles.Impostor if (ShowArrowsToOtherPlayersInPact.GetBool()) { - for (int i = 0; i < PlayersInDeathpact[pc.PlayerId].Count; i++) + foreach (PlayerControl player in PlayersInDeathpact[pc.PlayerId].ToArray()) { - PlayerControl player = PlayersInDeathpact[pc.PlayerId][i]; - foreach (var otherPlayerInPact in PlayersInDeathpact[pc.PlayerId].Where(a => a.PlayerId != player.PlayerId)) { TargetArrow.Add(player.PlayerId, otherPlayerInPact.PlayerId); @@ -148,9 +144,8 @@ namespace TOHE.Roles.Impostor if (CheckCancelDeathpact(player)) return; if (DeathpactTime[player.PlayerId] < GetTimeStamp() && DeathpactTime[player.PlayerId] != 0) { - for (int i = 0; i < PlayersInDeathpact[player.PlayerId].Count; i++) + foreach (PlayerControl playerInDeathpact in PlayersInDeathpact[player.PlayerId].ToArray()) { - PlayerControl playerInDeathpact = PlayersInDeathpact[player.PlayerId][i]; KillPlayerInDeathpact(player, playerInDeathpact); } @@ -170,9 +165,8 @@ namespace TOHE.Roles.Impostor bool cancelDeathpact = true; - for (int i = 0; i < PlayersInDeathpact[deathpact.PlayerId].Count; i++) + foreach (PlayerControl player in PlayersInDeathpact[deathpact.PlayerId].ToArray()) { - PlayerControl player = PlayersInDeathpact[deathpact.PlayerId][i]; float range = NormalGameOptionsV07.KillDistances[Mathf.Clamp(player.Is(CustomRoles.Reach) ? 2 : Main.NormalOptions.KillDistance, 0, 2)] + 0.5f; foreach (var otherPlayerInPact in PlayersInDeathpact[deathpact.PlayerId].Where(a => a.PlayerId != player.PlayerId)) { @@ -267,9 +261,8 @@ namespace TOHE.Roles.Impostor { if (ShowArrowsToOtherPlayersInPact.GetBool()) { - for (int i = 0; i < PlayersInDeathpact[deathpact].Count; i++) + foreach (PlayerControl player in PlayersInDeathpact[deathpact].ToArray()) { - PlayerControl player = PlayersInDeathpact[deathpact][i]; foreach (var otherPlayerInPact in PlayersInDeathpact[deathpact].Where(a => a.PlayerId != player.PlayerId)) { TargetArrow.Remove(player.PlayerId, otherPlayerInPact.PlayerId); @@ -283,10 +276,8 @@ namespace TOHE.Roles.Impostor if (ReduceVisionWhileInPact.GetBool()) { - for (int i = 0; i < PlayersInDeathpact[deathpact].Count; i++) + foreach (PlayerControl player in PlayersInDeathpact[deathpact].ToArray()) { - PlayerControl player = PlayersInDeathpact[deathpact][i]; - foreach (var otherPlayerInPact in PlayersInDeathpact[deathpact].Where(a => a.PlayerId != player.PlayerId)) { otherPlayerInPact.MarkDirtySettings(); @@ -299,9 +290,8 @@ namespace TOHE.Roles.Impostor public static void OnReportDeadBody() { List list = ActiveDeathpacts.ToList(); - for (int i = 0; i < list.Count; i++) + foreach (byte deathpact in list.ToArray()) { - byte deathpact = list[i]; if (KillDeathpactPlayersOnMeeting.GetBool()) { var deathpactPlayer = Main.AllPlayerControls.FirstOrDefault(a => a.PlayerId == deathpact); @@ -309,14 +299,12 @@ namespace TOHE.Roles.Impostor { continue; } - for (int i1 = 0; i1 < PlayersInDeathpact[deathpact].Count; i1++) { PlayerControl player = PlayersInDeathpact[deathpact][i1]; KillPlayerInDeathpact(deathpactPlayer, player); } } - ClearDeathpact(deathpact); } } diff --git a/Roles/Impostor/Devourer.cs b/Roles/Impostor/Devourer.cs index 6bc24e842..24b489dae 100644 --- a/Roles/Impostor/Devourer.cs +++ b/Roles/Impostor/Devourer.cs @@ -91,17 +91,14 @@ namespace TOHE.Roles.Impostor public static void OnDevourerDied(byte Devourer) { - for (int i = 0; i < PlayerSkinsCosumed[Devourer].Count; i++) + foreach (byte player in PlayerSkinsCosumed[Devourer].ToArray()) { - byte player = PlayerSkinsCosumed[Devourer][i]; Camouflage.PlayerSkins[player] = OriginalPlayerSkins[player]; - if (!Camouflage.IsCamouflage) { - PlayerControl pc = - Main.AllAlivePlayerControls.FirstOrDefault(a => a.PlayerId == player); - if (pc == null) continue; - + PlayerControl pc = Main.AllAlivePlayerControls.FirstOrDefault(a => a.PlayerId == player); + if (pc == null) + continue; SetSkin(pc, OriginalPlayerSkins[player]); } } diff --git a/Roles/Impostor/Eraser.cs b/Roles/Impostor/Eraser.cs index a0968d895..d52e71bc4 100644 --- a/Roles/Impostor/Eraser.cs +++ b/Roles/Impostor/Eraser.cs @@ -138,11 +138,11 @@ internal static class Eraser } public static void AfterMeetingTasks() { - for (int i = 0; i < PlayerToErase.Count; i++) + foreach (byte pc in PlayerToErase.ToArray()) { - byte pc = PlayerToErase[i]; var player = Utils.GetPlayerById(pc); - if (player == null) continue; + if (player == null) + continue; player.RpcSetCustomRole(CustomRolesHelper.GetErasedRole(player.GetCustomRole())); NameNotifyManager.Notify(player, GetString("LostRoleByEraser")); Logger.Info($"{player.GetNameWithRole().RemoveHtmlTags()} 被擦除了", "Eraser"); diff --git a/Roles/Impostor/EvilTracker.cs b/Roles/Impostor/EvilTracker.cs index 7085b31d9..dcb0fb19b 100644 --- a/Roles/Impostor/EvilTracker.cs +++ b/Roles/Impostor/EvilTracker.cs @@ -127,9 +127,8 @@ public static class EvilTracker { SetTarget(); } - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte playerId in playerIdList.ToArray()) { - byte playerId = playerIdList[i]; var pc = Utils.GetPlayerById(playerId); var target = Utils.GetPlayerById(GetTargetId(playerId)); if (!pc.IsAlive() || !target.IsAlive()) @@ -147,11 +146,12 @@ public static class EvilTracker public static void SetTarget(byte trackerId = byte.MaxValue, byte targetId = byte.MaxValue) { if (trackerId == byte.MaxValue) // ターゲット再設定可能に - for (int i = 0; i < playerIdList.Count; i++) + { + foreach (byte playerId in playerIdList.ToArray()) { - byte playerId = playerIdList[i]; CanSetTarget[playerId] = true; } + } else if (targetId == byte.MaxValue) // ターゲット削除 Target[trackerId] = byte.MaxValue; else diff --git a/Roles/Impostor/FireWorks.cs b/Roles/Impostor/FireWorks.cs index 1c114d7f6..c5565cf8d 100644 --- a/Roles/Impostor/FireWorks.cs +++ b/Roles/Impostor/FireWorks.cs @@ -112,12 +112,10 @@ public static class FireWorks case FireWorksState.ReadyFire: Logger.Info("花火を爆破", "FireWorks"); bool suicide = false; - for (int i1 = 0; i1 < Main.AllAlivePlayerControls.Length; i1++) + foreach (PlayerControl target in Main.AllAlivePlayerControls) { - PlayerControl target = Main.AllAlivePlayerControls[i1]; - for (int i = 0; i < fireWorksPosition[pc.PlayerId].Count; i++) + foreach (Vector3 pos in fireWorksPosition[pc.PlayerId].ToArray()) { - Vector3 pos = fireWorksPosition[pc.PlayerId][i]; var dis = Vector2.Distance(pos, target.transform.position); if (dis > fireWorksRadius) continue; diff --git a/Roles/Impostor/Hacker.cs b/Roles/Impostor/Hacker.cs index 86e6e8045..031f052d5 100644 --- a/Roles/Impostor/Hacker.cs +++ b/Roles/Impostor/Hacker.cs @@ -87,9 +87,8 @@ public static class Hacker var targetId = byte.MaxValue; // 寻找骇客击杀的尸体 - for (int i = 0; i < DeadBodyList.Count; i++) + foreach (byte db in DeadBodyList.ToArray()) { - byte db = DeadBodyList[i]; var dp = Utils.GetPlayerById(db); if (dp == null || dp.GetRealKiller() == null) continue; if (dp.GetRealKiller().PlayerId == pc.PlayerId) targetId = db; diff --git a/Roles/Impostor/RiftMaker.cs b/Roles/Impostor/RiftMaker.cs index e6df45fd1..07e931a7a 100644 --- a/Roles/Impostor/RiftMaker.cs +++ b/Roles/Impostor/RiftMaker.cs @@ -62,9 +62,8 @@ namespace TOHE.Roles.Impostor bool isTP = false; Vector2 from = Marks[0]; - for (int i = 0; i < Marks.Count; i++) + foreach (Vector2 mark in Marks.ToArray()) { - Vector2 mark = Marks[i]; var dis = Vector2.Distance(mark, position); if (dis > 2f) continue; diff --git a/Roles/Impostor/Sapper.cs b/Roles/Impostor/Sapper.cs index 92278d247..387b9eec7 100644 --- a/Roles/Impostor/Sapper.cs +++ b/Roles/Impostor/Sapper.cs @@ -74,9 +74,8 @@ namespace TOHE.Roles.Impostor { bool b = false; var players = GetPlayersInRadius(Radius.GetFloat(), bomb.Key); - for (int i = 0; i < players.Count; i++) + foreach (PlayerControl tg in players.ToArray()) { - PlayerControl tg = players[i]; if (tg.PlayerId == pc.PlayerId) { b = true; @@ -100,10 +99,10 @@ namespace TOHE.Roles.Impostor } var sb = new StringBuilder(); - List list = Bombs.Values.ToList(); - for (int i = 0; i < list.Count; i++) + long[] list = Bombs.Values.ToArray(); + foreach (long x in list) { - sb.Append(string.Format(GetString("MagicianBombExlodesIn"), Delay.GetInt() - (GetTimeStamp() - list[i]) + 1)); + sb.Append(string.Format(GetString("MagicianBombExlodesIn"), Delay.GetInt() - (GetTimeStamp() - x) + 1)); } pc.Notify(sb.ToString()); } diff --git a/Roles/Impostor/SerialKiller.cs b/Roles/Impostor/SerialKiller.cs index 526747c39..0339073cb 100644 --- a/Roles/Impostor/SerialKiller.cs +++ b/Roles/Impostor/SerialKiller.cs @@ -99,9 +99,8 @@ public static class SerialKiller //} public static void AfterMeetingTasks() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte id in playerIdList.ToArray()) { - byte id = playerIdList[i]; if (!Main.PlayerStates[id].IsDead) { var pc = Utils.GetPlayerById(id); diff --git a/Roles/Impostor/Sniper.cs b/Roles/Impostor/Sniper.cs index 3ff8105e1..ef8fa501e 100644 --- a/Roles/Impostor/Sniper.cs +++ b/Roles/Impostor/Sniper.cs @@ -86,9 +86,8 @@ public static class Sniper writer.Write(playerId); var snList = shotNotify[playerId]; writer.Write(snList.Count); - for (int i = 0; i < snList.Count; i++) + foreach (byte sn in snList.ToArray()) { - byte sn = snList[i]; writer.Write(sn); } AmongUsClient.Instance.FinishRpcImmediately(writer); @@ -322,9 +321,8 @@ public static class Sniper else { //射撃音が聞こえるプレイヤー - for (int i = 0; i < PlayerIdList.Count; i++) + foreach (byte sniperId in PlayerIdList.ToArray()) { - byte sniperId = PlayerIdList[i]; var snList = shotNotify[sniperId]; if (snList.Any() && snList.Contains(seerId)) { diff --git a/Roles/Impostor/Stealth.cs b/Roles/Impostor/Stealth.cs index df73d528f..faed95fc6 100644 --- a/Roles/Impostor/Stealth.cs +++ b/Roles/Impostor/Stealth.cs @@ -137,9 +137,8 @@ namespace TOHE.Roles.Impostor if (!IsEnable) return; if (darkenedPlayers != null) { - for (int i = 0; i < darkenedPlayers.Length; i++) + foreach (PlayerControl player in darkenedPlayers) { - PlayerControl player = darkenedPlayers[i]; Main.PlayerStates[player.PlayerId].IsBlackOut = false; player.MarkDirtySettings(); } diff --git a/Roles/Impostor/TimeThief.cs b/Roles/Impostor/TimeThief.cs index 4c5ea9cee..0fd2ea7b7 100644 --- a/Roles/Impostor/TimeThief.cs +++ b/Roles/Impostor/TimeThief.cs @@ -41,9 +41,8 @@ public static class TimeThief public static int TotalDecreasedMeetingTime() { int sec = 0; - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte playerId in playerIdList.ToArray()) { - byte playerId = playerIdList[i]; sec -= StolenTime(playerId); } diff --git a/Roles/Impostor/Vampire.cs b/Roles/Impostor/Vampire.cs index a460233ba..ff6969931 100644 --- a/Roles/Impostor/Vampire.cs +++ b/Roles/Impostor/Vampire.cs @@ -81,9 +81,8 @@ public static class Vampire List targetList = new(BittenPlayers.Where(b => b.Value.VampireId == vampireID).Select(b => b.Key)); - for (int i = 0; i < targetList.Count; i++) + foreach (byte targetId in targetList.ToArray()) { - byte targetId = targetList[i]; var bitten = BittenPlayers[targetId]; if (bitten.KillTimer >= KillDelay) { diff --git a/Roles/Impostor/Witch.cs b/Roles/Impostor/Witch.cs index a1597d972..9c0496be4 100644 --- a/Roles/Impostor/Witch.cs +++ b/Roles/Impostor/Witch.cs @@ -117,9 +117,8 @@ public static class Witch } public static bool HaveSpelledPlayer() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte witch in playerIdList.ToArray()) { - byte witch = playerIdList[i]; if (SpelledPlayer[witch].Any()) { return true; @@ -130,9 +129,8 @@ public static class Witch } public static bool IsSpelled(byte target) { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte witch in playerIdList.ToArray()) { - byte witch = playerIdList[i]; if (SpelledPlayer[witch].Contains(target)) { return true; @@ -152,9 +150,8 @@ public static class Witch } public static void RemoveSpelledPlayer() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte witch in playerIdList.ToArray()) { - byte witch = playerIdList[i]; SpelledPlayer[witch].Clear(); SendRPC(true, witch); } @@ -183,9 +180,8 @@ public static class Witch public static void OnCheckForEndVoting(PlayerState.DeathReason deathReason, params byte[] exileIds) { if (!IsEnable || deathReason != PlayerState.DeathReason.Vote) return; - for (int i = 0; i < exileIds.Length; i++) + foreach (byte id in exileIds) { - byte id = exileIds[i]; if (SpelledPlayer.ContainsKey(id)) SpelledPlayer[id].Clear(); } diff --git a/Roles/Neutral/Bandit.cs b/Roles/Neutral/Bandit.cs index a6afa0047..5d2314334 100644 --- a/Roles/Neutral/Bandit.cs +++ b/Roles/Neutral/Bandit.cs @@ -87,7 +87,7 @@ public static class Bandit { if (!AmongUsClient.Instance.AmHost) return null; var AllSubRoles = Main.PlayerStates[Target.PlayerId].SubRoles; - for (int i = AllSubRoles.Count - 1; i >= 0; i--) + for (int i = 0; i < AllSubRoles.Count; i++) { var role = AllSubRoles[i]; if (role == CustomRoles.Cleansed || // making Bandit unable to steal Cleansed for obvious reasons. Although it can still be cleansed by cleanser. diff --git a/Roles/Neutral/Collector.cs b/Roles/Neutral/Collector.cs index 7f1db373f..889a48c75 100644 --- a/Roles/Neutral/Collector.cs +++ b/Roles/Neutral/Collector.cs @@ -81,9 +81,8 @@ public static class Collector public static void CollectAmount(Dictionary VotingData, MeetingHud __instance)//得到集票者收集到的票 { int VoteAmount; - for (int i = 0; i < __instance.playerStates.Count; i++) + foreach (PlayerVoteArea pva in __instance.playerStates.ToArray()) { - PlayerVoteArea pva = __instance.playerStates[i]; if (pva == null) continue; PlayerControl pc = Utils.GetPlayerById(pva.TargetPlayerId); if (pc == null) continue; diff --git a/Roles/Neutral/HexMaster.cs b/Roles/Neutral/HexMaster.cs index 3589db75c..f712d7653 100644 --- a/Roles/Neutral/HexMaster.cs +++ b/Roles/Neutral/HexMaster.cs @@ -126,9 +126,8 @@ public static class HexMaster } public static bool HaveHexedPlayer() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte hexmaster in playerIdList.ToArray()) { - byte hexmaster = playerIdList[i]; if (HexedPlayer[hexmaster].Any()) { return true; @@ -139,9 +138,8 @@ public static class HexMaster } public static bool IsHexed(byte target) { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte hexmaster in playerIdList) { - byte hexmaster = playerIdList[i]; if (HexedPlayer[hexmaster].Contains(target)) { return true; @@ -161,9 +159,8 @@ public static class HexMaster } public static void RemoveHexedPlayer() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte hexmaster in playerIdList.ToArray()) { - byte hexmaster = playerIdList[i]; HexedPlayer[hexmaster].Clear(); SendRPC(true, hexmaster); } @@ -192,9 +189,8 @@ public static class HexMaster public static void OnCheckForEndVoting(PlayerState.DeathReason deathReason, params byte[] exileIds) { if (!IsEnable || deathReason != PlayerState.DeathReason.Vote) return; - for (int i = 0; i < exileIds.Length; i++) + foreach (byte id in exileIds) { - byte id = exileIds[i]; if (HexedPlayer.ContainsKey(id)) HexedPlayer[id].Clear(); } diff --git a/Roles/Neutral/Magician.cs b/Roles/Neutral/Magician.cs index 6bb4726ef..d773cfe63 100644 --- a/Roles/Neutral/Magician.cs +++ b/Roles/Neutral/Magician.cs @@ -125,10 +125,9 @@ public static class Magician { case 1: // Slowness for everyone nearby if (TempSpeeds.Any()) RevertSpeedChanges(true); - var list = GetPlayersInRadius(SlownessRadius.GetFloat(), pc.transform.position); - for (int i = 0; i < list.Count; i++) + var list = GetPlayersInRadius(SlownessRadius.GetFloat(), pc.transform.position).ToArray(); + foreach (var x in list) { - var x = list[i]; if (x.PlayerId == pc.PlayerId || x == null) continue; TempSpeeds.TryAdd(x.PlayerId, Main.AllPlayerSpeed[x.PlayerId]); @@ -179,17 +178,17 @@ public static class Magician sniper.SetKillCooldown(time: Main.AllPlayerKillCooldown[sniper.PlayerId] + temp); targets.Remove(snipedTarget); - List list1 = targets.Keys.ToList(); - for (int i = 0; i < list1.Count; i++) + PlayerControl[] list1 = targets.Keys.ToArray(); + foreach (PlayerControl x in list1) { - NotifyRoles(SpecifySeer: list1[i]); + NotifyRoles(SpecifySeer: x); } _ = new LateTask( () => { - for (int i = 0; i < list1.Count; i++) + foreach (PlayerControl x in list1) { - NotifyRoles(SpecifySeer: list1[i]); + NotifyRoles(SpecifySeer: x); } }, 0.5f, "Sniper shot Notify" @@ -197,10 +196,9 @@ public static class Magician } break; case 6: // Blind everyone nearby - var players = GetPlayersInRadius(BlindRadius.GetFloat(), pc.transform.position); - for (int i = 0; i < players.Count; i++) + var players = GetPlayersInRadius(BlindRadius.GetFloat(), pc.transform.position).ToArray(); + foreach (PlayerControl x in players) { - PlayerControl x = players[i]; if (x.PlayerId == pc.PlayerId || x == null) continue; BlindPPL.TryAdd(x.PlayerId, GetTimeStamp()); @@ -265,9 +263,8 @@ public static class Magician bool isTP = false; Vector2 from = PortalMarks[0]; - for (int i = 0; i < PortalMarks.Count; i++) + foreach (Vector2 mark in PortalMarks.ToArray()) { - Vector2 mark = PortalMarks[i]; var dis = Vector2.Distance(mark, position); if (dis > 2f) continue; @@ -308,10 +305,9 @@ public static class Magician foreach (var bomb in Bombs.Where(bomb => bomb.Value + BombDelay.GetInt() < GetTimeStamp())) { bool b = false; - var players = GetPlayersInRadius(BombRadius.GetFloat(), bomb.Key); - for (int i = 0; i < players.Count; i++) + var players = GetPlayersInRadius(BombRadius.GetFloat(), bomb.Key).ToArray(); + foreach (PlayerControl tg in players) { - PlayerControl tg = players[i]; if (tg.PlayerId == pc.PlayerId) { b = true; @@ -335,10 +331,10 @@ public static class Magician } var sb = new StringBuilder(); - List list = Bombs.Values.ToList(); - for (int i = 0; i < list.Count; i++) + long[] list = Bombs.Values.ToArray(); + foreach (long x in list) { - sb.Append(string.Format(GetString("MagicianBombExlodesIn"), BombDelay.GetInt() - (GetTimeStamp() - list[i]) + 1)); + sb.Append(string.Format(GetString("MagicianBombExlodesIn"), BombDelay.GetInt() - (GetTimeStamp() - x) + 1)); } pc.Notify(sb.ToString()); } diff --git a/Roles/Neutral/Pelican.cs b/Roles/Neutral/Pelican.cs index be895bfdb..e69529cd4 100644 --- a/Roles/Neutral/Pelican.cs +++ b/Roles/Neutral/Pelican.cs @@ -47,9 +47,8 @@ public static class Pelican if (playerId != byte.MaxValue) { writer.Write(eatenList[playerId].Count); - for (int i = 0; i < eatenList[playerId].Count; i++) + foreach (byte el in eatenList[playerId].ToArray()) { - byte el = eatenList[playerId][i]; writer.Write(el); } } @@ -132,12 +131,12 @@ public static class Pelican { foreach (var pc in eatenList) { - for (int i = 0; i < pc.Value.Count; i++) + foreach (byte tar in pc.Value.ToArray()) { - byte tar = pc.Value[i]; var target = Utils.GetPlayerById(tar); var killer = Utils.GetPlayerById(pc.Key); - if (killer == null || target == null) continue; + if (killer == null || target == null) + continue; Main.AllPlayerSpeed[tar] = Main.AllPlayerSpeed[tar] - 0.5f + originalSpeed[tar]; ReportDeadBodyPatch.CanReport[tar] = true; target.RpcExileV2(); @@ -155,12 +154,12 @@ public static class Pelican public static void OnPelicanDied(byte pc) { if (!eatenList.ContainsKey(pc)) return; - for (int i = 0; i < eatenList[pc].Count; i++) + foreach (byte tar in eatenList[pc].ToArray()) { - byte tar = eatenList[pc][i]; var target = Utils.GetPlayerById(tar); var palyer = Utils.GetPlayerById(pc); - if (palyer == null || target == null) continue; + if (palyer == null || target == null) + continue; target.TP(palyer.GetTruePosition()); Main.AllPlayerSpeed[tar] = Main.AllPlayerSpeed[tar] - 0.5f + originalSpeed[tar]; ReportDeadBodyPatch.CanReport[tar] = true; @@ -190,14 +189,15 @@ public static class Pelican foreach (var pc in eatenList) { - for (int i = 0; i < pc.Value.Count; i++) + foreach (byte tar in pc.Value.ToArray()) { - byte tar = pc.Value[i]; var target = Utils.GetPlayerById(tar); - if (target == null) continue; + if (target == null) + continue; var pos = GetBlackRoomPS(); var dis = Vector2.Distance(pos, target.GetTruePosition()); - if (dis < 1f) continue; + if (dis < 1f) + continue; target.TP(pos); Utils.NotifyRoles(SpecifySeer: target); } diff --git a/Roles/Neutral/PlagueDoctor.cs b/Roles/Neutral/PlagueDoctor.cs index c73de1236..76c9896e0 100644 --- a/Roles/Neutral/PlagueDoctor.cs +++ b/Roles/Neutral/PlagueDoctor.cs @@ -194,9 +194,9 @@ namespace TOHE.Roles.Neutral { //If someone is infected CheckWin(); - for (int i = 0; i < updates.Count; i++) + foreach (PlayerControl x in updates.ToArray()) { - Utils.NotifyRoles(SpecifySeer: updates[i]); + Utils.NotifyRoles(SpecifySeer: x); } } } diff --git a/Roles/Neutral/Poisoner.cs b/Roles/Neutral/Poisoner.cs index 6db589698..13e2196fb 100644 --- a/Roles/Neutral/Poisoner.cs +++ b/Roles/Neutral/Poisoner.cs @@ -88,9 +88,8 @@ public static class Poisoner List targetList = new(PoisonedPlayers.Where(b => b.Value.PoisonerId == poisonerID).Select(b => b.Key)); - for (int i = 0; i < targetList.Count; i++) + foreach (byte targetId in targetList.ToArray()) { - byte targetId = targetList[i]; var poisonedPoisoner = PoisonedPlayers[targetId]; if (poisonedPoisoner.KillTimer >= KillDelay) { diff --git a/Roles/Neutral/Pursuer.cs b/Roles/Neutral/Pursuer.cs index 1cafc74a1..74320c890 100644 --- a/Roles/Neutral/Pursuer.cs +++ b/Roles/Neutral/Pursuer.cs @@ -106,9 +106,9 @@ public static class Pursuer { notActiveList.Clear(); foreach (var cl in clientList) - for (int i = 0; i < cl.Value.Count; i++) + { + foreach (byte pc in cl.Value.ToArray()) { - byte pc = cl.Value[i]; var target = Utils.GetPlayerById(pc); if (target == null || !target.IsAlive()) continue; var role = target.GetCustomRole(); @@ -124,5 +124,6 @@ public static class Pursuer Logger.Info($"赝品商 {killer.GetRealName()} 的客户 {target.GetRealName()} 因不带刀自杀", "Pursuer"); } } + } } } \ No newline at end of file diff --git a/Roles/Neutral/Reckless.cs b/Roles/Neutral/Reckless.cs index 6b263be20..e1eff5707 100644 --- a/Roles/Neutral/Reckless.cs +++ b/Roles/Neutral/Reckless.cs @@ -56,9 +56,8 @@ public static class Reckless } public static void OnReportDeadBody() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte id in playerIdList.ToArray()) { - byte id = playerIdList[i]; NowCooldown[Utils.GetPlayerById(id).PlayerId] = DefaultKillCooldown.GetFloat(); } } diff --git a/Roles/Neutral/Vulture.cs b/Roles/Neutral/Vulture.cs index d612f9dc5..4b1663ec7 100644 --- a/Roles/Neutral/Vulture.cs +++ b/Roles/Neutral/Vulture.cs @@ -91,18 +91,16 @@ public static class Vulture public static void Clear() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte apc in playerIdList.ToArray()) { - byte apc = playerIdList[i]; LocateArrow.RemoveAllTarget(apc); SendRPC(apc, false); } } public static void AfterMeetingTasks() { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte apc in playerIdList.ToArray()) { - byte apc = playerIdList[i]; var player = Utils.GetPlayerById(apc); if (player.IsAlive()) { @@ -138,9 +136,8 @@ public static class Vulture } } - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte pc in playerIdList.ToArray()) { - byte pc = playerIdList[i]; var player = Utils.GetPlayerById(pc); if (player == null || !player.IsAlive()) continue; LocateArrow.Add(pc, target.transform.position); @@ -155,9 +152,8 @@ public static class Vulture Logger.Msg($"target.object {target.Object}, is null? {target.Object == null}", "VultureNull"); if (target.Object != null) { - for (int i = 0; i < playerIdList.Count; i++) + foreach (byte apc in playerIdList.ToArray()) { - byte apc = playerIdList[i]; LocateArrow.Remove(apc, target.Object.transform.position); SendRPC(apc, false); }