diff --git a/ExtremeRoles.Test/ExtremeRoles.Test.csproj b/ExtremeRoles.Test/ExtremeRoles.Test.csproj index 69ab0bea7..d2061e293 100644 --- a/ExtremeRoles.Test/ExtremeRoles.Test.csproj +++ b/ExtremeRoles.Test/ExtremeRoles.Test.csproj @@ -22,7 +22,7 @@ - + diff --git a/ExtremeRoles.Test/GameTestRunner.cs b/ExtremeRoles.Test/GameTestRunner.cs index 01275b53d..8b04a6171 100644 --- a/ExtremeRoles.Test/GameTestRunner.cs +++ b/ExtremeRoles.Test/GameTestRunner.cs @@ -19,6 +19,7 @@ using ExtremeRoles.GameMode.Option.ShipGlobal; using UnityResource = UnityEngine.Resources; +using ExtremeRoles.Module.CustomOption; namespace ExtremeRoles.Test; @@ -33,7 +34,7 @@ public override void Run() GameMudderEndTestingBehaviour.Instance.Logger = this.Log; GameMudderEndTestingBehaviour.Instance.StartCoroutine( GameMudderEndTestingBehaviour.Instance.Run( - new("Random", 3), + new("Random", 256), new("IRoleAbilityRole", 5, [ ExtremeRoleId.Carpenter, @@ -62,7 +63,9 @@ public override void Run() () => { GameUtility.UpdateExROption( - new((int)GlobalOption.IsSameNeutralSameWin, 1)); + OptionTab.General, + (int)ShipGlobalOptionCategory.NeutralWinOption, + new RequireOption((int)NeutralWinOption.IsSame, 1)); }), new("NeutralWin", 100, [ @@ -73,7 +76,9 @@ public override void Run() () => { GameUtility.UpdateExROption( - new((int)GlobalOption.IsSameNeutralSameWin, 1)); + OptionTab.General, + (int)ShipGlobalOptionCategory.NeutralWinOption, + new RequireOption((int)NeutralWinOption.IsSame, 1)); GameUtility.UpdateAmongUsOption( new RequireOption( Int32OptionNames.NumImpostors, 0)); @@ -82,7 +87,9 @@ public override void Run() () => { GameUtility.UpdateExROption( - new((int)GlobalOption.IsSameNeutralSameWin, 0)); + OptionTab.General, + (int)ShipGlobalOptionCategory.NeutralWinOption, + new RequireOption((int)NeutralWinOption.IsSame, 1)); GameUtility.UpdateAmongUsOption( new RequireOption( Int32OptionNames.NumImpostors, 3)); @@ -149,16 +156,21 @@ private IEnumerator runTestCase(GameTestRunner.TestCase testCase) if (this.count > waitCount) { - this.Logger.LogInfo("Wait for 30s"); + this.Logger.LogInfo("Wait for 10s"); GC.Collect(); Resources.Loader.ResetCache(); yield return UnityResource.UnloadUnusedAssets(); - yield return new WaitForSeconds(30.0f); + yield return new WaitForSeconds(10.0f); this.count = 0; } yield return GameUtility.StartGame(this.Logger); + while (IntroCutscene.Instance != null) + { + yield return new WaitForSeconds(10.0f); + } + while (GameUtility.IsContinue) { var player = CachedPlayerControl.AllPlayerControls.OrderBy(x => RandomGenerator.Instance.Next()).First(); diff --git a/ExtremeRoles.Test/Helper/GameUtility.cs b/ExtremeRoles.Test/Helper/GameUtility.cs index 63304789b..96eaa6bf9 100644 --- a/ExtremeRoles.Test/Helper/GameUtility.cs +++ b/ExtremeRoles.Test/Helper/GameUtility.cs @@ -6,13 +6,12 @@ using UnityEngine; using BepInEx.Logging; using AmongUs.GameOptions; - -using ExtremeRoles.GameMode.RoleSelector; using ExtremeRoles.Helper; -using ExtremeRoles.Module.CustomOption; using ExtremeRoles.Roles; using ExtremeRoles.Roles.API; +using ExtremeRoles.Module.CustomOption; + namespace ExtremeRoles.Test.Helper; public sealed record RequireOption(T OptionId, W Velue) @@ -29,8 +28,13 @@ public static class GameUtility public static void ChangePresetTo(int newPreset) { - OptionManager.Instance.GetIOption(0).UpdateSelection(newPreset); - OptionManager.Instance.SwitchPreset(newPreset); + var mng = OptionManager.Instance; + if (!mng.TryGetCategory(OptionTab.General, (int)OptionCreator.CommonOption.PresetOption, out var presetCate)) + { + return; + } + var option = presetCate.Get(0); + mng.Update(presetCate, option, newPreset); } public static IEnumerator StartGame(ManualLogSource logger) @@ -64,22 +68,34 @@ public static void PrepereGameWithRandom(ManualLogSource logger) { logger.LogInfo("Update Option...."); // オプションを適当にアプデ - foreach (var opt in OptionManager.Instance.GetAllIOption()) + var mng = OptionManager.Instance; + foreach (var tab in Enum.GetValues()) { - if (opt.Id == 0) { continue; } - - int newIndex = RandomGenerator.Instance.Next(0, opt.ValueCount); - string name = opt.Name; - - if (name.Contains(RoleCommonOption.AssignWeight.ToString())) + if (!mng.TryGetTab(tab, out var tabObj)) { - newIndex = 5; + continue; } - else if (name.Contains(RoleCommonOption.SpawnRate.ToString())) + + foreach (var cate in tabObj.Category) { - newIndex = 0; + if (cate.Id == 0) { continue; } + + foreach (var opt in cate.Options) + { + int newIndex = RandomGenerator.Instance.Next(0, opt.Range); + string name = opt.Info.Name; + + if (name.Contains(RoleCommonOption.AssignWeight.ToString())) + { + newIndex = 5; + } + else if (name.Contains(RoleCommonOption.SpawnRate.ToString())) + { + newIndex = 0; + } + mng.Update(cate, opt, newIndex); + } } - opt.UpdateSelection(newIndex); } disableXion(); @@ -103,38 +119,51 @@ public static void PrepereGameWithRole(ManualLogSource logger, HashSet()) { - if (opt.Id == 0) { continue; } - - int length = opt.ValueCount; - int newIndex = RandomGenerator.Instance.Next(0, length); - string name = opt.Name; - - if ( - ids.Any(x => name.Contains(x.ToString())) && - ( - name.Contains(RoleCommonOption.SpawnRate.ToString()) || - name.Contains(RoleCommonOption.AssignWeight.ToString()) - )) - { - newIndex = length - 1; - } - else if ( - ids.Any(x => name.Contains(x.ToString())) && - name.Contains(RoleCommonOption.RoleNum.ToString())) + if (!mng.TryGetTab(tab, out var tabObj)) { - newIndex = RandomGenerator.Instance.Next(1, ((15 - 3) / ids.Count)); + continue; } - else if (name.Contains(RoleCommonOption.AssignWeight.ToString())) - { - newIndex = 5; - } - else if (name.Contains(RoleCommonOption.SpawnRate.ToString())) + + foreach (var cate in tabObj.Category) { - newIndex = 0; + if (cate.Id == 0) { continue; } + + foreach (var opt in cate.Options) + { + int length = opt.Range; + int newIndex = RandomGenerator.Instance.Next(0, length); + string name = opt.Info.Name; + + if ( + ids.Any(x => name.Contains(x.ToString())) && + ( + name.Contains(RoleCommonOption.SpawnRate.ToString()) || + name.Contains(RoleCommonOption.AssignWeight.ToString()) + )) + { + newIndex = length - 1; + } + else if ( + ids.Any(x => name.Contains(x.ToString())) && + name.Contains(RoleCommonOption.RoleNum.ToString())) + { + newIndex = RandomGenerator.Instance.Next(1, ((15 - 3) / ids.Count)); + } + else if (name.Contains(RoleCommonOption.AssignWeight.ToString())) + { + newIndex = 5; + } + else if (name.Contains(RoleCommonOption.SpawnRate.ToString())) + { + newIndex = 0; + } + mng.Update(cate, opt, newIndex); + } } - opt.UpdateSelection(newIndex); } disableXion(); @@ -149,11 +178,12 @@ public static void PrepereGameWithRole(ManualLogSource logger, HashSet option) + public static void UpdateExROption(OptionTab tab, int categoryId, in RequireOption option) { - OptionManager.Instance.GetIOption( - option.OptionId).UpdateSelection( - option.Velue); + if (OptionManager.Instance.TryGetCategory(tab, categoryId, out var category)) + { + OptionManager.Instance.Update(category, option.OptionId, option.Velue); + } } public static void UpdateAmongUsOption(in RequireOption option) @@ -180,23 +210,38 @@ public static void UpdateAmongUsOption(in RequireOption private static void disableXion() { - OptionManager.Instance.GetIOption( - (int)RoleGlobalOption.UseXion).UpdateSelection(0); + if (OptionManager.Instance.TryGetCategory( + OptionTab.General, + ExtremeRoleManager.GetRoleGroupId(ExtremeRoleId.Xion), + out var category)) + { + OptionManager.Instance.Update(category, 0, 0); + } } private static void enableRandomNormalRole(ManualLogSource logger) { SingleRoleBase role = RandomRoleProvider.GetNormalRole(); - int optionId = role.GetRoleOptionId(RoleCommonOption.SpawnRate); - OptionManager.Instance.GetIOption(optionId).UpdateSelection( - OptionCreator.SpawnRate.Length - 1); + + if (OptionManager.Instance.TryGetCategory( + role.Tab, + ExtremeRoleManager.GetRoleGroupId(role.Id), + out var category)) + { + OptionManager.Instance.Update(category, (int)RoleCommonOption.SpawnRate, 9); + } logger.LogInfo($"Enable:{role.Id}"); } private static void enableRandomCombRole(ManualLogSource logger) { - CombinationRoleManagerBase role = RandomRoleProvider.GetCombRole(); - int optionId = role.GetRoleOptionId(RoleCommonOption.SpawnRate); - OptionManager.Instance.GetIOption(optionId).UpdateSelection(1); + CombinationRoleType role = (CombinationRoleType)RandomRoleProvider.GetCombRole(); + if (OptionManager.Instance.TryGetCategory( + OptionTab.Combination, + ExtremeRoleManager.GetCombRoleGroupId(role), + out var category)) + { + OptionManager.Instance.Update(category, (int)RoleCommonOption.SpawnRate, 9); + } logger.LogInfo($"Enable:{role}"); } } diff --git a/ExtremeRoles.Test/Helper/RandomRoleProvider.cs b/ExtremeRoles.Test/Helper/RandomRoleProvider.cs index d4da3e2d4..8bc2d9584 100644 --- a/ExtremeRoles.Test/Helper/RandomRoleProvider.cs +++ b/ExtremeRoles.Test/Helper/RandomRoleProvider.cs @@ -9,6 +9,6 @@ public static class RandomRoleProvider { public static SingleRoleBase GetNormalRole() => ExtremeRoleManager.NormalRole.Values.OrderBy(x => RandomGenerator.Instance.Next()).First(); - public static CombinationRoleManagerBase GetCombRole() - => ExtremeRoleManager.CombRole.Values.OrderBy(x => RandomGenerator.Instance.Next()).First(); + public static byte GetCombRole() + => ExtremeRoleManager.CombRole.Keys.OrderBy(x => RandomGenerator.Instance.Next()).First(); } diff --git a/ExtremeRoles.Test/OptionRunner.cs b/ExtremeRoles.Test/OptionRunner.cs index e8889c052..87ead4771 100644 --- a/ExtremeRoles.Test/OptionRunner.cs +++ b/ExtremeRoles.Test/OptionRunner.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.GameMode.Option.ShipGlobal; using ExtremeRoles.GhostRoles; -using ExtremeRoles.Module.CustomOption; using ExtremeRoles.Roles; +using ExtremeRoles.Roles.API; namespace ExtremeRoles.Test; @@ -42,26 +44,35 @@ public override void Run() this.Log.LogInfo($"Load.GhostRole.Iteration.{i}"); loadGhostRole(); - - this.Log.LogInfo($"Load.HudString.Iteration.{i}"); - this.hudString(); } } private void updateRandom() { - foreach (var opt in OptionManager.Instance.GetAllIOption()) + var mng = OptionManager.Instance; + foreach (var tab in Enum.GetValues()) { - if (opt.Id == 0) { continue; } - - int newIndex = RandomGenerator.Instance.Next(0, opt.ValueCount); - try + if (!mng.TryGetTab(tab, out var tabObj)) { - opt.UpdateSelection(newIndex); + continue; } - catch (Exception ex) + + foreach (var cate in tabObj.Category) { - this.Log.LogError($"{opt.Name} : {newIndex} {ex.Message}"); + if (cate.Id == 0) { continue; } + + foreach (var opt in cate.Options) + { + int newIndex = RandomGenerator.Instance.Next(0, opt.Range); + try + { + mng.UpdateToStep(cate, opt, newIndex); + } + catch (Exception ex) + { + this.Log.LogError($"{opt.Info.Name} : {newIndex} {ex.Message}"); + } + } } } } @@ -158,22 +169,4 @@ private void loadGhostRole() } } } - private void hudString() - { - foreach (var opt in OptionManager.Instance.GetAllIOption()) - { - try - { - string hudStr = opt.ToHudString(); - if (!opt.Enabled && !opt.IsHidden && string.IsNullOrEmpty(hudStr)) - { - throw new Exception("Invalid HudString"); - } - } - catch (Exception ex) - { - this.Log.LogError($"{opt.Name} {ex.Message}"); - } - } - } } diff --git a/ExtremeRoles.Test/Patch/RoleManagerPatch.cs b/ExtremeRoles.Test/Patch/RoleManagerPatch.cs index 8c92d6178..d5b1bb177 100644 --- a/ExtremeRoles.Test/Patch/RoleManagerPatch.cs +++ b/ExtremeRoles.Test/Patch/RoleManagerPatch.cs @@ -9,7 +9,7 @@ namespace ExtremeRoles.Test.Patches.Manager; [HarmonyPatch(typeof(RoleManager), nameof(RoleManager.SelectRoles))] public static class RoleManagerSelectRolesPatch { - + [HarmonyPriority(Priority.First)] public static void Prefix() { if (!GameMudderEndTestingBehaviour.Enable) { return; } @@ -24,7 +24,7 @@ public static void Prefix() int adjustedNumImpostors = currentOption.GetAdjustedNumImpostors(allPlayer.Count); - var il2CppListPlayer = new Il2CppSystem.Collections.Generic.List(); + var il2CppListPlayer = new Il2CppSystem.Collections.Generic.List(); foreach (PlayerControl player in allPlayer) { diff --git a/ExtremeRoles.sln b/ExtremeRoles.sln index 17b4063b7..309ef1688 100644 --- a/ExtremeRoles.sln +++ b/ExtremeRoles.sln @@ -14,7 +14,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExtremeBepInExInstaller", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExtremeVoiceEngine", "ExtremeVoiceEngine\ExtremeVoiceEngine.csproj", "{2A0828AD-9A1F-4E07-BD5F-E3CFDF6773B2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtremeRoles.Test", "ExtremeRoles.Test\ExtremeRoles.Test.csproj", "{F845C15F-674A-4F12-9B3D-699804ECBF63}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExtremeRoles.Test", "ExtremeRoles.Test\ExtremeRoles.Test.csproj", "{F845C15F-674A-4F12-9B3D-699804ECBF63}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ExtremeRoles/Compat/CompatModManager.cs b/ExtremeRoles/Compat/CompatModManager.cs index 8d04a7c4b..d057f0536 100644 --- a/ExtremeRoles/Compat/CompatModManager.cs +++ b/ExtremeRoles/Compat/CompatModManager.cs @@ -11,7 +11,8 @@ using ExtremeRoles.Compat.Interface; using ExtremeRoles.Compat.ModIntegrator; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.SequentialOptionFactory; + + namespace ExtremeRoles.Compat; @@ -98,16 +99,17 @@ private CompatModManager() internal void CreateIntegrateOption(int startId) { - var optionFactory = new OptionFactory(startId); - foreach (var (mod, index) in this.loadedMod.Values.Select((value, index) => (value, index))) { - optionFactory.NamePrefix = mod.Name; - mod.CreateIntegrateOption(optionFactory); + using (var factory = OptionManager.CreateSequentialOptionCategory( + startId + index, mod.Name)) + { + mod.CreateIntegrateOption(factory); + } } this.startOptionId = startId; - this.endOptionId = optionFactory.EndId; + this.endOptionId = startId + this.loadedMod.Count - 1; } internal string GetIntegrateOptionHudString() @@ -115,12 +117,11 @@ internal string GetIntegrateOptionHudString() StringBuilder builder = new StringBuilder(); for (int id = this.startOptionId; id <= this.endOptionId; ++id) { - var option = OptionManager.Instance.GetIOption(id); - string optionStr = option.ToHudString(); - if (optionStr != string.Empty) + if (!OptionManager.Instance.TryGetCategory(OptionTab.General, id, out var cate)) { - builder.AppendLine(optionStr); + continue; } + cate.AddHudString(builder); } return builder.ToString().Trim('\r', '\n'); } diff --git a/ExtremeRoles/Compat/Interface/IMapMod.cs b/ExtremeRoles/Compat/Interface/IMapMod.cs index 4286b4038..c765773b1 100644 --- a/ExtremeRoles/Compat/Interface/IMapMod.cs +++ b/ExtremeRoles/Compat/Interface/IMapMod.cs @@ -31,13 +31,13 @@ public interface IMapMod public bool IsCustomCalculateLightRadius { get; } public void Awake(ShipStatus map); public void Destroy(); - public float CalculateLightRadius(GameData.PlayerInfo player, bool neutral, bool neutralImpostor); - public float CalculateLightRadius(GameData.PlayerInfo player, float visionMod, bool applayVisionEffects = true); + public float CalculateLightRadius(NetworkedPlayerInfo player, bool neutral, bool neutralImpostor); + public float CalculateLightRadius(NetworkedPlayerInfo player, float visionMod, bool applayVisionEffects = true); public bool IsCustomSabotageNow(); public bool IsCustomSabotageTask(TaskTypes saboTask); public bool IsCustomVentUse(Vent vent); public (float, bool, bool) IsCustomVentUseResult( - Vent vent, GameData.PlayerInfo player, bool isVentUse); + Vent vent, NetworkedPlayerInfo player, bool isVentUse); public void RpcRepairCustomSabotage(); public void RpcRepairCustomSabotage(TaskTypes saboTask); public void RepairCustomSabotage(); diff --git a/ExtremeRoles/Compat/ModIntegrator/ModIntegratorBase.cs b/ExtremeRoles/Compat/ModIntegrator/ModIntegratorBase.cs index 174a93250..147cd5278 100644 --- a/ExtremeRoles/Compat/ModIntegrator/ModIntegratorBase.cs +++ b/ExtremeRoles/Compat/ModIntegrator/ModIntegratorBase.cs @@ -5,7 +5,7 @@ using BepInEx.Unity.IL2CPP; using HarmonyLib; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.SequentialOptionFactory; +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.SequentialOptionCategoryFactory; namespace ExtremeRoles.Compat.ModIntegrator; diff --git a/ExtremeRoles/Compat/ModIntegrator/SubmergedMap.cs b/ExtremeRoles/Compat/ModIntegrator/SubmergedMap.cs index 780e37c96..7d8fa57c4 100644 --- a/ExtremeRoles/Compat/ModIntegrator/SubmergedMap.cs +++ b/ExtremeRoles/Compat/ModIntegrator/SubmergedMap.cs @@ -13,14 +13,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Extension.Il2Cpp; -using ExtremeRoles.Module.CustomOption.Factories; using ExtremeRoles.Compat.Interface; using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; using UnityObject = UnityEngine.Object; -using ExtremeRoles.GameMode.Option.ShipGlobal; + +using ExtremeRoles.Module.CustomOption.Implemented; +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.SequentialOptionCategoryFactory; #nullable enable @@ -74,7 +75,7 @@ public enum ElevatorSelection public ShipStatus.MapType MapType => (ShipStatus.MapType)MapId; public bool CanPlaceCamera => false; public bool IsCustomCalculateLightRadius => true; - public SpawnSetting Spawn => (SpawnSetting)this.enableSubMergedRandomSpawn.GetValue(); + public SpawnSetting Spawn => (SpawnSetting)this.enableSubMergedRandomSpawn.Value; public TaskTypes RetrieveOxygenMask; @@ -169,15 +170,17 @@ public void Awake(ShipStatus map) replaceDoorMinigame(); } - public override void CreateIntegrateOption(SequentialOptionFactory factory) + public override void CreateIntegrateOption(OptionFactory factory) { // どうせ作っても5個程度なので参照を持つようにする 8byte * 5 = 40byte程度 - this.elevatorOption = factory.CreateSelectionOption(SubmergedOption.EnableElevator, isHeader: true); + this.elevatorOption = factory.CreateSelectionOption(SubmergedOption.EnableElevator); this.replaceDoorMinigameOption = factory.CreateBoolOption(SubmergedOption.ReplaceDoorMinigame, false); + /* var randomSpawnOpt = OptionManager.Instance.Get((int)GlobalOption.EnableSpecialSetting); this.enableSubMergedRandomSpawn = factory.CreateSelectionOption( SubmergedOption.SubmergedSpawnSetting, randomSpawnOpt, invert: true); + */ } public void Destroy() @@ -190,7 +193,7 @@ public void Destroy() curOption.SetFloat(FloatOptionNames.ImpostorLightMod, impostorVision); } - public float CalculateLightRadius(GameData.PlayerInfo player, bool neutral, bool neutralImpostor) + public float CalculateLightRadius(NetworkedPlayerInfo player, bool neutral, bool neutralImpostor) { object? value = calculateLightRadiusMethod.Invoke( this.submarineStatus, new object?[] { null, neutral, neutralImpostor }); @@ -198,7 +201,7 @@ public float CalculateLightRadius(GameData.PlayerInfo player, bool neutral, bool } public float CalculateLightRadius( - GameData.PlayerInfo player, float visionMod, bool applayVisionEffects = true) + NetworkedPlayerInfo player, float visionMod, bool applayVisionEffects = true) { // サブマージドの視界計算のロジックは「クルーだと停電効果受ける、インポスターだと受けないので」 // 1. まずはデフォルトの視界をMOD側で用意した視界の広さにリプレイス @@ -234,7 +237,7 @@ public void ChangeFloor(PlayerControl player, int floor) MonoBehaviour? floorHandler = getFloorHandler(player); if (floorHandler == null) { return; } - object[] args = new object[] { floor == 1 }; + object[] args = [ floor == 1 ]; this.rpcRequestChangeFloorMethod.Invoke(floorHandler, args); this.registerFloorOverrideMethod.Invoke(floorHandler, args); @@ -362,7 +365,7 @@ public bool IsCustomVentUse(Vent vent) } public (float, bool, bool) IsCustomVentUseResult( - Vent vent, GameData.PlayerInfo player, bool isVentUse) + Vent vent, NetworkedPlayerInfo player, bool isVentUse) { object? valueObj = inTransitionField.GetValue(null); @@ -540,7 +543,7 @@ protected override void PatchAll(Harmony harmony) #pragma warning restore CS8604 // このコメントに沿って関数調整:https://github.com/SubmergedAmongUs/Submerged/issues/123#issuecomment-1783889792 - GameData.PlayerInfo? info = null; + NetworkedPlayerInfo? info = null; bool tie = false; Type exileControllerPatches = ClassType.First( t => t.Name == "ExileControllerPatches"); @@ -611,7 +614,7 @@ protected override void PatchAll(Harmony harmony) private void disableElevator() { - var useElevator = (ElevatorSelection)this.elevatorOption.GetValue(); + var useElevator = (ElevatorSelection)this.elevatorOption.Value; switch (useElevator) { @@ -649,7 +652,7 @@ private void disableElevator() private void replaceDoorMinigame() { - if (!this.replaceDoorMinigameOption.GetValue() || CachedShipStatus.Instance == null) + if (!this.replaceDoorMinigameOption.Value || CachedShipStatus.Instance == null) { return; } object? transformValue = this.submarineStatusReference.GetValue(this.submarineStatus); diff --git a/ExtremeRoles/Compat/Patches/SubmergedPatch.cs b/ExtremeRoles/Compat/Patches/SubmergedPatch.cs index 24a7202f9..1c9b019ce 100644 --- a/ExtremeRoles/Compat/Patches/SubmergedPatch.cs +++ b/ExtremeRoles/Compat/Patches/SubmergedPatch.cs @@ -20,7 +20,7 @@ namespace ExtremeRoles.Compat.Patches; public static class ExileControllerPatchesPatch { - public static bool ExileController_BeginPrefix(ExileController __instance, GameData.PlayerInfo exiled, bool tie) + public static bool ExileController_BeginPrefix(ExileController __instance, NetworkedPlayerInfo exiled, bool tie) { return ExtremeRoles.Patches.Controller.ExileControllerBeginePatch.PrefixRun(__instance, exiled, tie); } @@ -111,8 +111,7 @@ public static void Postfix(object __instance) var spawnOpt = ExtremeGameModeManager.Instance.ShipOption.Spawn; // ランダムスポーンが有効かつ自動選択がオフだけ処理飛ばす - if (spawnOpt == null || - (spawnOpt.EnableSpecialSetting && submergedMod!.Spawn is SpawnPoint.DefaultSpawn && !spawnOpt.IsAutoSelectRandom)) { return; } + if (spawnOpt.EnableSpecialSetting && submergedMod!.Spawn is SpawnPoint.DefaultSpawn && !spawnOpt.IsAutoSelectRandom) { return; } submarineSpawnInSystemTimer.SetValue(__instance, 0.0f); } @@ -213,7 +212,7 @@ public static void Prefix(ref bool upperSelected) var spawnOpt = ExtremeGameModeManager.Instance.ShipOption.Spawn; var spawnPoint = submergedMod!.Spawn; - if (spawnOpt == null || spawnPoint is SpawnPoint.DefaultSpawn) + if (spawnPoint is SpawnPoint.DefaultSpawn) { return; } diff --git a/ExtremeRoles/CustomRegion.cs b/ExtremeRoles/CustomRegion.cs index 13f356bfc..9252cfb43 100644 --- a/ExtremeRoles/CustomRegion.cs +++ b/ExtremeRoles/CustomRegion.cs @@ -3,6 +3,8 @@ using ExtremeRoles.Extension.Manager; using ExtremeRoles.Module; + + namespace ExtremeRoles; public static class CustomRegion diff --git a/ExtremeRoles/Extension/CategoryHeaderMaskedExtension.cs b/ExtremeRoles/Extension/CategoryHeaderMaskedExtension.cs new file mode 100644 index 000000000..68255dca6 --- /dev/null +++ b/ExtremeRoles/Extension/CategoryHeaderMaskedExtension.cs @@ -0,0 +1,12 @@ +namespace ExtremeRoles.Extension.Option; + +public static class CategoryHeaderMaskedExtension +{ + public static void ReplaceExRText(this CategoryHeaderMasked masked, string txt, int maskLayer) + { + masked.Title.text = txt; + masked.Background.material.SetInt(PlayerMaterial.MaskLayer, maskLayer); + masked.Title.fontMaterial.SetFloat("_StencilComp", 3f); + masked.Title.fontMaterial.SetFloat("_Stencil", maskLayer); + } +} diff --git a/ExtremeRoles/Extension/EnumExtension.cs b/ExtremeRoles/Extension/EnumExtension.cs new file mode 100644 index 000000000..5e713b501 --- /dev/null +++ b/ExtremeRoles/Extension/EnumExtension.cs @@ -0,0 +1,13 @@ +using System; +using System.Runtime.CompilerServices; + +namespace ExtremeRoles.Extension; + +public static class EnumExtension +{ + public static int FastInt(this T value) where T : Enum + { + int result = Unsafe.As(ref value); + return result; + } +} diff --git a/ExtremeRoles/Extension/Il2CppExtension.cs b/ExtremeRoles/Extension/Il2CppExtension.cs index 7a51baed4..f6d97d301 100644 --- a/ExtremeRoles/Extension/Il2CppExtension.cs +++ b/ExtremeRoles/Extension/Il2CppExtension.cs @@ -6,6 +6,7 @@ using Il2CppInterop.Runtime.InteropTypes; using Il2CppType = Il2CppSystem.Type; +using System.Diagnostics.CodeAnalysis; #nullable enable @@ -21,7 +22,8 @@ public static class Il2CppExtension .MakeGenericMethod(type) .Invoke(self, Array.Empty()); } - public static bool IsTryCast(this Il2CppObjectBase? self, out T? obj) where T : Il2CppObjectBase + + public static bool IsTryCast(this Il2CppObjectBase? self, [NotNullWhen(true)] out T? obj) where T : Il2CppObjectBase { if (self == null) { diff --git a/ExtremeRoles/Extension/MinigameExtension.cs b/ExtremeRoles/Extension/MinigameExtension.cs index b1a0b0bb9..c16821521 100644 --- a/ExtremeRoles/Extension/MinigameExtension.cs +++ b/ExtremeRoles/Extension/MinigameExtension.cs @@ -61,7 +61,7 @@ public static void AbstractClose(this Minigame game) ExtremeRolesPlugin.Logger.LogInfo($"Closing ExR minigame {game.GetType().Name}"); IAnalyticsReporter analytics = FastDestroyableSingleton.Instance.Analytics; - GameData.PlayerInfo data = PlayerControl.LocalPlayer.Data; + NetworkedPlayerInfo data = PlayerControl.LocalPlayer.Data; TaskTypes taskType = game.TaskType; float num = Time.realtimeSinceStartup - game.timeOpened; PlayerTask myTask = game.MyTask; diff --git a/ExtremeRoles/ExtremeRoles.csproj b/ExtremeRoles/ExtremeRoles.csproj index ff1bd33f0..b6b25eb15 100644 --- a/ExtremeRoles/ExtremeRoles.csproj +++ b/ExtremeRoles/ExtremeRoles.csproj @@ -3,9 +3,9 @@ net6.0 latest 7 - 10.1.1.1 - - Recovery + + 11.0.0 + AmongUsv20240618 Extreme Roles for Advanced user yukieiji Debug;Release @@ -25,7 +25,7 @@ - + diff --git a/ExtremeRoles/ExtremeRolesPlugin.cs b/ExtremeRoles/ExtremeRolesPlugin.cs index ad5bae202..2b0f7aefc 100644 --- a/ExtremeRoles/ExtremeRolesPlugin.cs +++ b/ExtremeRoles/ExtremeRolesPlugin.cs @@ -31,10 +31,10 @@ public partial class ExtremeRolesPlugin : BasePlugin { public Harmony Harmony { get; } = new Harmony(Id); - public static ExtremeRolesPlugin Instance; - public static ExtremeShipStatus ShipState; + public static ExtremeRolesPlugin Instance { get; private set; } + public static ExtremeShipStatus ShipState { get; private set; } - internal static BepInEx.Logging.ManualLogSource Logger; + internal static BepInEx.Logging.ManualLogSource Logger; public static ConfigEntry DebugMode { get; private set; } public static ConfigEntry IgnoreOverrideConsoleDisable { get; private set; } diff --git a/ExtremeRoles/GameMode/ExtremeGameModeManager.cs b/ExtremeRoles/GameMode/ExtremeGameModeManager.cs index 4db863d2d..a9c816a4e 100644 --- a/ExtremeRoles/GameMode/ExtremeGameModeManager.cs +++ b/ExtremeRoles/GameMode/ExtremeGameModeManager.cs @@ -5,6 +5,10 @@ using ExtremeRoles.GameMode.Option.ShipGlobal; using ExtremeRoles.GameMode.RoleSelector; + + +using ExtremeRoles.Roles; + // TODO: setプロパティ => initにする namespace ExtremeRoles.GameMode; @@ -53,8 +57,7 @@ public void Load() { Instance.ShipOption.Load(); - isXionActive = OptionManager.Instance.GetValue( - (int)RoleGlobalOption.UseXion); + isXionActive = IRoleSelector.RawXionUse; } public IIntroRunner GetIntroRunner() diff --git a/ExtremeRoles/GameMode/IntroRunner/ClassicIntroRunner.cs b/ExtremeRoles/GameMode/IntroRunner/ClassicIntroRunner.cs index 37b97276c..cf25589a0 100644 --- a/ExtremeRoles/GameMode/IntroRunner/ClassicIntroRunner.cs +++ b/ExtremeRoles/GameMode/IntroRunner/ClassicIntroRunner.cs @@ -23,8 +23,8 @@ public IEnumerator CoRunModeIntro( instance.ImpostorTitle.gameObject.SetActive(false); Il2CppSystem.Collections.Generic.List teamToShow = IntroCutscene.SelectTeamToShow( - (Il2CppSystem.Func)( - (GameData.PlayerInfo pcd) => + (Il2CppSystem.Func)( + (NetworkedPlayerInfo pcd) => !localPlayer.Data.Role.IsImpostor || pcd.Role.TeamType == localPlayer.Data.Role.TeamType )); diff --git a/ExtremeRoles/GameMode/IntroRunner/HideNSeekIntroRunner.cs b/ExtremeRoles/GameMode/IntroRunner/HideNSeekIntroRunner.cs index d183939ef..7d0f573c8 100644 --- a/ExtremeRoles/GameMode/IntroRunner/HideNSeekIntroRunner.cs +++ b/ExtremeRoles/GameMode/IntroRunner/HideNSeekIntroRunner.cs @@ -40,8 +40,8 @@ public IEnumerator CoRunModeIntro( } var teams = IntroCutscene.SelectTeamToShow( - (Il2CppSystem.Func)( - (GameData.PlayerInfo pcd) => + (Il2CppSystem.Func)( + (NetworkedPlayerInfo pcd) => localPlayer.Data.Role.IsImpostor != pcd.Role.IsImpostor )); if (teams == null || teams.Count < 1) diff --git a/ExtremeRoles/GameMode/IntroRunner/IIntroRunner.cs b/ExtremeRoles/GameMode/IntroRunner/IIntroRunner.cs index 1f5eeff94..9bc2b61dd 100644 --- a/ExtremeRoles/GameMode/IntroRunner/IIntroRunner.cs +++ b/ExtremeRoles/GameMode/IntroRunner/IIntroRunner.cs @@ -3,8 +3,6 @@ using AmongUs.GameOptions; using UnityEngine; -using ExtremeRoles.GameMode.Option.MapModule; - using ExtremeRoles.Helper; using ExtremeRoles.Module.RoleAssign; @@ -20,6 +18,9 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.GameMode.Option.ShipGlobal; + +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; + namespace ExtremeRoles.GameMode.IntroRunner; #nullable enable @@ -141,7 +142,7 @@ private static void prepareXion() continue; } - GameData.PlayerInfo playerInfo = player.Data; + NetworkedPlayerInfo playerInfo = player.Data; var (_, totalTask) = GameSystem.GetTaskInfo(playerInfo); if (totalTask != 0) diff --git a/ExtremeRoles/GameMode/Option/MapModule/AdminOption.cs b/ExtremeRoles/GameMode/Option/MapModule/AdminOption.cs deleted file mode 100644 index 2c5e00c3f..000000000 --- a/ExtremeRoles/GameMode/Option/MapModule/AdminOption.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace ExtremeRoles.GameMode.Option.MapModule -{ - public enum AirShipAdminMode - { - ModeBoth, - ModeCockpitOnly, - ModeArchiveOnly - } - - public sealed class AdminOption - { - public bool Disable { get; set; } = false; - public AirShipAdminMode AirShipEnable { get; set; } = AirShipAdminMode.ModeBoth; - public bool EnableAdminLimit { get; set; } = false; - public float AdminLimitTime { get; set; } = float.MaxValue; - } -} diff --git a/ExtremeRoles/GameMode/Option/MapModule/SecurityOption.cs b/ExtremeRoles/GameMode/Option/MapModule/SecurityOption.cs deleted file mode 100644 index 8503860fb..000000000 --- a/ExtremeRoles/GameMode/Option/MapModule/SecurityOption.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace ExtremeRoles.GameMode.Option.MapModule -{ - public sealed class SecurityOption - { - public bool Disable { get; set; } = false; - public bool EnableSecurityLimit { get; set; } = false; - public float SecurityLimitTime { get; set; } = float.MaxValue; - } -} diff --git a/ExtremeRoles/GameMode/Option/MapModule/VitalOption.cs b/ExtremeRoles/GameMode/Option/MapModule/VitalOption.cs deleted file mode 100644 index 68b1ac099..000000000 --- a/ExtremeRoles/GameMode/Option/MapModule/VitalOption.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace ExtremeRoles.GameMode.Option.MapModule -{ - public sealed class VitalOption - { - public bool Disable { get; set; } = false; - public bool EnableVitalLimit { get; set; } = false; - public float VitalLimitTime { get; set; } = 0.0f; - } -} diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/ClassicGameModeShipGlobalOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/ClassicGameModeShipGlobalOption.cs index 1c48a8c29..c9afb8af4 100644 --- a/ExtremeRoles/GameMode/Option/ShipGlobal/ClassicGameModeShipGlobalOption.cs +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/ClassicGameModeShipGlobalOption.cs @@ -1,13 +1,15 @@ using System; using System.Collections.Generic; - -using ExtremeRoles.GameMode.Option.MapModule; +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub; +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; +using ExtremeRoles.Module.CustomOption.OLDS; namespace ExtremeRoles.GameMode.Option.ShipGlobal; public sealed class ClassicGameModeShipGlobalOption : IShipGlobalOption { - public bool IsEnableImpostorVent => true; + + public bool IsEnableImpostorVent => true; public bool CanUseHorseMode => true; public bool IsBreakEmergencyButton => false; @@ -15,139 +17,68 @@ public sealed class ClassicGameModeShipGlobalOption : IShipGlobalOption public bool IsRandomMap { get; private set; } - public int MaxMeetingCount { get; private set; } - - public bool IsChangeVoteAreaButtonSortArg { get; private set; } - public bool IsFixedVoteAreaPlayerLevel { get; private set; } - public bool IsBlockSkipInMeeting { get; private set; } - public bool DisableSelfVote { get; private set; } public ConfirmExilMode ExilMode { get; private set; } public bool IsConfirmRole { get; private set; } - public bool DisableVent { get; private set; } - public bool EngineerUseImpostorVent { get; private set; } - public bool CanKillVentInPlayer { get; private set; } - public VentAnimationMode VentAnimationMode { get; private set; } - public bool IsAllowParallelMedbayScan { get; private set; } + public VentConsoleOption Vent { get; private set; } + public SpawnOption Spawn { get; private set; } - public AdminOption Admin { get; private set; } - public SecurityOption Security { get; private set; } - public VitalOption Vital { get; private set; } + public AdminDeviceOption Admin { get; private set; } + public DeviceOption Security { get; private set; } + public DeviceOption Vital { get; private set; } + public GhostRoleOption GhostRole { get; private set; } + public MeetingHudOption Meeting { get; private set; } - public bool DisableTaskWinWhenNoneTaskCrew { get; private set; } + public bool DisableTaskWinWhenNoneTaskCrew { get; private set; } public bool DisableTaskWin { get; private set; } public bool IsSameNeutralSameWin { get; private set; } public bool DisableNeutralSpecialForceEnd { get; private set; } - public bool IsAssignNeutralToVanillaCrewGhostRole { get; private set; } - public bool IsRemoveAngleIcon { get; private set; } - public bool IsBlockGAAbilityReport { get; private set; } - public void Load() { - MaxMeetingCount = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.NumMeating); - - IsRandomMap = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.RandomMap); - - IsChangeVoteAreaButtonSortArg = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.ChangeMeetingVoteAreaSort); - IsFixedVoteAreaPlayerLevel = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.FixedMeetingPlayerLevel); - IsBlockSkipInMeeting = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableSkipInEmergencyMeeting); - DisableSelfVote = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableSelfVote); - ExilMode = (ConfirmExilMode)IShipGlobalOption.GetCommonOptionValue( - GlobalOption.ConfirmExilMode); - IsConfirmRole = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsConfirmRole); - - DisableVent = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableVent); - EngineerUseImpostorVent = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EngineerUseImpostorVent); - CanKillVentInPlayer = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.CanKillVentInPlayer); - this.VentAnimationMode = (VentAnimationMode)IShipGlobalOption.GetCommonOptionValue( - GlobalOption.VentAnimationModeInVison); - - IsAllowParallelMedbayScan = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.ParallelMedBayScans); - - Spawn = new SpawnOption() - { - EnableSpecialSetting = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableSpecialSetting), - Skeld = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.SkeldRandomSpawn), - MiraHq = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.MiraHqRandomSpawn), - Polus = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.PolusRandomSpawn), - AirShip = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.AirShipRandomSpawn), - Fungle = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.FungleRandomSpawn), - IsAutoSelectRandom = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsAutoSelectRandomSpawn), - }; - - ChangeForceWallCheck = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsFixWallHaskTask); - - Admin = new AdminOption() - { - Disable = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsRemoveAdmin), - AirShipEnable = (AirShipAdminMode)IShipGlobalOption.GetCommonOptionValue( - GlobalOption.AirShipEnableAdmin), - EnableAdminLimit = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableAdminLimit), - AdminLimitTime = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.AdminLimitTime), - }; - Vital = new VitalOption() - { - Disable = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsRemoveVital), - EnableVitalLimit = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableVitalLimit), - VitalLimitTime = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.VitalLimitTime), - }; - Security = new SecurityOption() - { - Disable = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsRemoveSecurity), - EnableSecurityLimit = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableSecurityLimit), - SecurityLimitTime = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.SecurityLimitTime), - }; - - DisableTaskWinWhenNoneTaskCrew = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableTaskWinWhenNoneTaskCrew); - DisableTaskWin = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableTaskWin); - IsSameNeutralSameWin = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsSameNeutralSameWin); - DisableNeutralSpecialForceEnd = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableNeutralSpecialForceEnd); - - IsAssignNeutralToVanillaCrewGhostRole = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsAssignNeutralToVanillaCrewGhostRole); - IsRemoveAngleIcon = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsRemoveAngleIcon); - IsBlockGAAbilityReport = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsBlockGAAbilityReport); - } + this.Meeting = new MeetingHudOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.MeetingOption)); + + var exiledCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.ExiledOption); + ExilMode = (ConfirmExilMode)exiledCate.GetValue((int)ExiledOption.ConfirmExilMode); + IsConfirmRole = exiledCate.GetValue((int)ExiledOption.IsConfirmRole); + this.Vent = new VentConsoleOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.VentOption)); + + Spawn = new SpawnOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.RandomSpawnOption)); + + Admin = new AdminDeviceOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.AdminOption)); + Vital = new DeviceOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.VitalOption)); + Security = new DeviceOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.SecurityOption)); + + var taskWinCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.TaskWinOption); + DisableTaskWinWhenNoneTaskCrew = taskWinCate.GetValue((int)TaskWinOption.DisableWhenNoneTaskCrew); + DisableTaskWin = taskWinCate.GetValue((int)TaskWinOption.DisableAll); + + var neutralWinCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.NeutralWinOption); + IsSameNeutralSameWin = neutralWinCate.GetValue((int)NeutralWinOption.IsSame); + DisableNeutralSpecialForceEnd = neutralWinCate.GetValue((int)NeutralWinOption.DisableSpecialEnd); + + GhostRole = new GhostRoleOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.GhostRoleGlobalOption)); + + var taskCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.TaskOption); + ChangeForceWallCheck = taskCate.GetValue((int)TaskOption.IsFixWallHaskTask); + IsAllowParallelMedbayScan = taskCate.GetValue((int)TaskOption.ParallelMedBayScans); + + var randomMapCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.RandomMapOption); + IsRandomMap = randomMapCate.GetValue((int)RandomMap.Enable); + } + /* public IEnumerable UseOptionId() { foreach (GlobalOption id in Enum.GetValues(typeof(GlobalOption))) @@ -157,4 +88,5 @@ public IEnumerable UseOptionId() } public bool IsValidOption(int id) => Enum.IsDefined(typeof(GlobalOption), id); + */ } diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/HideNSeekModeShipGlobalOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/HideNSeekModeShipGlobalOption.cs index bd3b094ec..6f3129a3b 100644 --- a/ExtremeRoles/GameMode/Option/ShipGlobal/HideNSeekModeShipGlobalOption.cs +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/HideNSeekModeShipGlobalOption.cs @@ -1,7 +1,7 @@ using System.Text; using System.Collections.Generic; - -using ExtremeRoles.GameMode.Option.MapModule; +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub; namespace ExtremeRoles.GameMode.Option.ShipGlobal; @@ -14,41 +14,29 @@ public sealed class HideNSeekModeShipGlobalOption : IShipGlobalOption public bool IsRandomMap { get; private set; } public bool ChangeForceWallCheck { get; private set; } - public bool DisableVent { get; private set; } - public VentAnimationMode VentAnimationMode { get; private set; } - public bool IsAllowParallelMedbayScan { get; private set; } public bool IsSameNeutralSameWin { get; private set; } public bool DisableNeutralSpecialForceEnd { get; private set; } - public AdminOption Admin { get; private set; } - public SecurityOption Security { get; private set; } - public VitalOption Vital { get; private set; } - + public AdminDeviceOption Admin { get; private set; } + public DeviceOption Security { get; private set; } + public DeviceOption Vital { get; private set; } public SpawnOption Spawn { get; private set; } - public int MaxMeetingCount => 0; - - public bool IsChangeVoteAreaButtonSortArg => false; - public bool IsFixedVoteAreaPlayerLevel => false; - public bool IsBlockSkipInMeeting => false; - public bool DisableSelfVote => false; - - public ConfirmExilMode ExilMode => ConfirmExilMode.Impostor; + public ConfirmExilMode ExilMode => ConfirmExilMode.Impostor; public bool IsConfirmRole => false; - public bool EngineerUseImpostorVent => false; - public bool CanKillVentInPlayer => false; - public bool DisableTaskWinWhenNoneTaskCrew => false; public bool DisableTaskWin => false; - public bool IsAssignNeutralToVanillaCrewGhostRole => false; - public bool IsRemoveAngleIcon => false; - public bool IsBlockGAAbilityReport => false; - public bool IsBreakEmergencyButton => true; + public VentConsoleOption Vent { get; private set; } + + public MeetingHudOption Meeting { get; } = new(); + public GhostRoleOption GhostRole { get; } = new(); + + /* private HashSet useOption = [ GlobalOption.DisableVent, @@ -80,74 +68,38 @@ public sealed class HideNSeekModeShipGlobalOption : IShipGlobalOption // GlobalOption.EnableHorseMode ]; + */ public void Load() { - DisableVent = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableVent); - this.VentAnimationMode = (VentAnimationMode)IShipGlobalOption.GetCommonOptionValue( - GlobalOption.VentAnimationModeInVison); - - ChangeForceWallCheck = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsFixWallHaskTask); - - Spawn = new SpawnOption() - { - EnableSpecialSetting = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableSpecialSetting), - Skeld = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.SkeldRandomSpawn), - MiraHq = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.MiraHqRandomSpawn), - Polus = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.PolusRandomSpawn), - AirShip = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.AirShipRandomSpawn), - Fungle = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.FungleRandomSpawn), - IsAutoSelectRandom = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsAutoSelectRandomSpawn), - }; - - IsRandomMap = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.RandomMap); - - Admin = new AdminOption() - { - Disable = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsRemoveAdmin), - AirShipEnable = (AirShipAdminMode)IShipGlobalOption.GetCommonOptionValue( - GlobalOption.AirShipEnableAdmin), - EnableAdminLimit = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableAdminLimit), - AdminLimitTime = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.AdminLimitTime), - }; - Vital = new VitalOption() - { - Disable = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsRemoveVital), - EnableVitalLimit = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableVitalLimit), - VitalLimitTime = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.VitalLimitTime), - }; - Security = new SecurityOption() - { - Disable = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsRemoveSecurity), - EnableSecurityLimit = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.EnableSecurityLimit), - SecurityLimitTime = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.SecurityLimitTime), - }; - - IsSameNeutralSameWin = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.IsSameNeutralSameWin); - DisableNeutralSpecialForceEnd = IShipGlobalOption.GetCommonOptionValue( - GlobalOption.DisableNeutralSpecialForceEnd); - } - + var vent = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.VentOption); + this.Vent = new VentConsoleOption( + vent.GetValue((int)VentOption.Disable), + false, false, + (VentAnimationMode)vent.GetValue((int)VentOption.AnimationModeInVison)); + + Spawn = new SpawnOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.RandomSpawnOption)); + + Admin = new AdminDeviceOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.AdminOption)); + Vital = new DeviceOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.VitalOption)); + Security = new DeviceOption( + IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.SecurityOption)); + + var neutralWinCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.NeutralWinOption); + IsSameNeutralSameWin = neutralWinCate.GetValue((int)NeutralWinOption.IsSame); + DisableNeutralSpecialForceEnd = neutralWinCate.GetValue((int)NeutralWinOption.DisableSpecialEnd); + + var taskCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.TaskOption); + ChangeForceWallCheck = taskCate.GetValue((int)TaskOption.IsFixWallHaskTask); + IsAllowParallelMedbayScan = taskCate.GetValue((int)TaskOption.ParallelMedBayScans); + + var randomMapCate = IShipGlobalOption.GetOptionCategory(ShipGlobalOptionCategory.RandomMapOption); + IsRandomMap = randomMapCate.GetValue((int)RandomMap.Enable); + } + /* public bool IsValidOption(int id) => this.useOption.Contains((GlobalOption)id); public IEnumerable UseOptionId() @@ -157,4 +109,5 @@ public IEnumerable UseOptionId() yield return id; } } + */ } diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/IShipGlobalOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/IShipGlobalOption.cs index 1df057825..aa8e4a645 100644 --- a/ExtremeRoles/GameMode/Option/ShipGlobal/IShipGlobalOption.cs +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/IShipGlobalOption.cs @@ -4,28 +4,38 @@ using ExtremeRoles.Extension.Strings; using ExtremeRoles.Patches.Option; -using ExtremeRoles.GameMode.Option.MapModule; -using static ExtremeRoles.Module.CustomOption.Factories.SimpleFactory; + + +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub; +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; namespace ExtremeRoles.GameMode.Option.ShipGlobal; -public enum GlobalOption : int +public enum ShipGlobalOptionCategory : int { - NumMeating = 50, - ChangeMeetingVoteAreaSort, - FixedMeetingPlayerLevel, - DisableSkipInEmergencyMeeting, - DisableSelfVote, - - ConfirmExilMode, - IsConfirmRole, + MeetingOption = 10, + ExiledOption, + VentOption, + TaskOption, + RandomSpawnOption, + AdminOption, + SecurityOption, + VitalOption, + RandomMapOption, + TaskWinOption, + NeutralWinOption, + GhostRoleGlobalOption +} - DisableVent, - EngineerUseImpostorVent, - CanKillVentInPlayer, - VentAnimationModeInVison, +public enum ExiledOption : int +{ + ConfirmExilMode, + IsConfirmRole, +} +public enum TaskOption : int +{ ParallelMedBayScans, IsFixWallHaskTask, @@ -33,57 +43,38 @@ public enum GlobalOption : int ShowerTask, DevelopPhotosTask, DivertPowerTask, +} - EnableSpecialSetting, - SkeldRandomSpawn, - MiraHqRandomSpawn, - PolusRandomSpawn, - AirShipRandomSpawn, - FungleRandomSpawn, - - IsAutoSelectRandomSpawn, - - IsRemoveAdmin, - AirShipEnableAdmin, - EnableAdminLimit, - AdminLimitTime, - - IsRemoveSecurity, - EnableSecurityLimit, - SecurityLimitTime, - - IsRemoveVital, - EnableVitalLimit, - VitalLimitTime, - - RandomMap, - - DisableTaskWinWhenNoneTaskCrew, - DisableTaskWin, - IsSameNeutralSameWin, - DisableNeutralSpecialForceEnd, +public enum RandomMap : int +{ + Enable, +} - IsAssignNeutralToVanillaCrewGhostRole, - IsRemoveAngleIcon, - IsBlockGAAbilityReport, +public enum TaskWinOption : int +{ + DisableWhenNoneTaskCrew, + DisableAll, +} - // ウマングアスを一時的もしくは恒久的に無効化 - // EnableHorseMode +public enum NeutralWinOption : int +{ + IsSame, + DisableSpecialEnd, } -public enum ConfirmExilMode +public enum GhostRoleGlobalOption : int { - Impostor, - Crewmate, - Neutral, - AllTeam + IsAssignNeutralToVanillaCrewGhostRole, + IsRemoveAngleIcon, + IsBlockGAAbilityReport, } -public enum VentAnimationMode +public enum ConfirmExilMode { - VanillaAnimation, - DonotWallHack, - DonotOutVison, + Impostor, + Crewmate, + Neutral, + AllTeam } public readonly record struct MapModuleDisableFlag( @@ -94,30 +85,20 @@ public readonly record struct MapModuleDisableFlag( public interface IShipGlobalOption { - public bool IsEnableImpostorVent { get; } + public bool IsEnableImpostorVent { get; } public bool IsRandomMap { get; } - public int MaxMeetingCount { get; } - public bool IsBreakEmergencyButton { get; } public bool CanUseHorseMode { get; } - public bool IsChangeVoteAreaButtonSortArg { get; } - public bool IsFixedVoteAreaPlayerLevel { get; } - public bool IsBlockSkipInMeeting { get; } - public bool DisableSelfVote { get; } - public ConfirmExilMode ExilMode { get; } public bool IsConfirmRole { get; } - public bool DisableVent { get; } - public bool EngineerUseImpostorVent { get; } - public bool CanKillVentInPlayer { get; } - public VentAnimationMode VentAnimationMode { get; } - + public VentConsoleOption Vent { get; } public SpawnOption Spawn { get; } + public bool IsAllowParallelMedbayScan { get; } public bool ChangeForceWallCheck { get; } @@ -140,18 +121,19 @@ public IReadOnlySet ChangeTask get { var fixTask = new HashSet(); - for (int i = (int)GlobalOption.GarbageTask; i <= (int)GlobalOption.DivertPowerTask; ++i) - { - var opt = (GlobalOption)i; - if (GetCommonOptionValue(opt)) + var cate = GetOptionCategory(ShipGlobalOptionCategory.TaskOption); + + for (int i = (int)TaskOption.GarbageTask; i <= (int)TaskOption.DivertPowerTask; ++i) + { + if (cate.GetValue(i)) { - var fixTaskType = opt switch + var fixTaskType = (TaskOption)i switch { - GlobalOption.GarbageTask => TaskTypes.EmptyGarbage, - GlobalOption.ShowerTask => TaskTypes.FixShower, - GlobalOption.DevelopPhotosTask => TaskTypes.DevelopPhotos, - GlobalOption.DivertPowerTask => TaskTypes.DivertPower, + TaskOption.GarbageTask => TaskTypes.EmptyGarbage, + TaskOption.ShowerTask => TaskTypes.FixShower, + TaskOption.DevelopPhotosTask => TaskTypes.DevelopPhotos, + TaskOption.DivertPowerTask => TaskTypes.DivertPower, _ => throw new KeyNotFoundException() }; fixTask.Add(fixTaskType); @@ -161,24 +143,23 @@ public IReadOnlySet ChangeTask } } - public AdminOption Admin { get; } - public SecurityOption Security { get; } - public VitalOption Vital { get; } + public MeetingHudOption Meeting { get; } + public AdminDeviceOption Admin { get; } + public DeviceOption Security { get; } + public DeviceOption Vital { get; } public bool DisableTaskWinWhenNoneTaskCrew { get; } public bool DisableTaskWin { get; } public bool IsSameNeutralSameWin { get; } public bool DisableNeutralSpecialForceEnd { get; } - public bool IsAssignNeutralToVanillaCrewGhostRole { get; } - public bool IsRemoveAngleIcon { get; } - public bool IsBlockGAAbilityReport { get; } + public GhostRoleOption GhostRole { get; } public void Load(); - + /* public bool IsValidOption(int id); - public IEnumerable UseOptionId(); - + // public IEnumerable UseOptionId(); + /* public void AddHudString(in List allStr) { int lineCounter = 0; @@ -204,94 +185,87 @@ public void AddHudString(in List allStr) } allStr.Add(builder.ToString()); } + */ - public static void Create() + public static void Create() { - CreateIntOption(GlobalOption.NumMeating, 10, 0, 100, 1, isHeader: true); - CreateBoolOption(GlobalOption.ChangeMeetingVoteAreaSort, false); - CreateBoolOption(GlobalOption.FixedMeetingPlayerLevel, false); - CreateBoolOption(GlobalOption.DisableSkipInEmergencyMeeting, false); - CreateBoolOption(GlobalOption.DisableSelfVote, false); - - var confirmOpt = CreateSelectionOption( - GlobalOption.ConfirmExilMode, isHeader: true); - confirmOpt.AddToggleOptionCheckHook(StringNames.GameConfirmImpostor); - var confirmRoleOpt = CreateBoolOption(GlobalOption.IsConfirmRole, false); - confirmRoleOpt.AddToggleOptionCheckHook(StringNames.GameConfirmImpostor); - - var ventOption = CreateBoolOption(GlobalOption.DisableVent, false, isHeader: true); - CreateBoolOption(GlobalOption.CanKillVentInPlayer, false, ventOption, invert: true); - CreateBoolOption(GlobalOption.EngineerUseImpostorVent, false, ventOption, invert: true); - CreateSelectionOption(GlobalOption.VentAnimationModeInVison, parent: ventOption, invert: true); - - CreateBoolOption(GlobalOption.ParallelMedBayScans, false, isHeader: true); - - var fixTaskOpt = CreateBoolOption(GlobalOption.IsFixWallHaskTask, false); - for (int i = (int)GlobalOption.GarbageTask; i <= (int)GlobalOption.DivertPowerTask; ++i) + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.MeetingOption)) + { + MeetingHudOption.Create(factory); + } + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.ExiledOption)) { - CreateBoolOption((GlobalOption)i, false, parent: fixTaskOpt); + var confirmOpt = factory.CreateSelectionOption(ExiledOption.ConfirmExilMode); + // confirmOpt.AddToggleOptionCheckHook(StringNames.GameConfirmImpostor); + var confirmRoleOpt = factory.CreateBoolOption(ExiledOption.IsConfirmRole, false); + // confirmRoleOpt.AddToggleOptionCheckHook(StringNames.GameConfirmImpostor); + } + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.VentOption)) + { + VentConsoleOption.Create(factory); + } + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.TaskOption)) + { + factory.CreateBoolOption(TaskOption.ParallelMedBayScans, false); + + var fixTaskOpt = factory.CreateBoolOption(TaskOption.IsFixWallHaskTask, false); + for (int i = (int)TaskOption.GarbageTask; i <= (int)TaskOption.DivertPowerTask; ++i) + { + factory.CreateBoolOption((TaskOption)i, false, parent: fixTaskOpt); + } + } + + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.RandomSpawnOption)) + { + SpawnOption.Create(factory); + } + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.AdminOption)) + { + AdminDeviceOption.Create(factory); + } + createMapObjectOptions(ShipGlobalOptionCategory.SecurityOption); + createMapObjectOptions(ShipGlobalOptionCategory.VitalOption); + + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.RandomMapOption)) + { + factory.CreateBoolOption(RandomMap.Enable, false); + } + + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.TaskWinOption)) + { + var taskDisableOpt = factory.CreateBoolOption(TaskWinOption.DisableWhenNoneTaskCrew, false); + factory.CreateBoolOption(TaskWinOption.DisableAll, false, taskDisableOpt); } + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.NeutralWinOption)) + { + factory.CreateBoolOption(NeutralWinOption.IsSame, true); + factory.CreateBoolOption(NeutralWinOption.DisableSpecialEnd, false); + } - var randomSpawnOpt = CreateBoolOption(GlobalOption.EnableSpecialSetting , true); - CreateBoolOption(GlobalOption.SkeldRandomSpawn , false, randomSpawnOpt, invert: true); - CreateBoolOption(GlobalOption.MiraHqRandomSpawn , false, randomSpawnOpt, invert: true); - CreateBoolOption(GlobalOption.PolusRandomSpawn , false, randomSpawnOpt, invert: true); - CreateBoolOption(GlobalOption.AirShipRandomSpawn, true , randomSpawnOpt, invert: true); - CreateBoolOption(GlobalOption.FungleRandomSpawn , false, randomSpawnOpt, invert: true); - - CreateBoolOption(GlobalOption.IsAutoSelectRandomSpawn, false, randomSpawnOpt, invert: true); - - var adminOpt = CreateBoolOption(GlobalOption.IsRemoveAdmin, false, isHeader: true); - CreateSelectionOption( - GlobalOption.AirShipEnableAdmin, adminOpt, invert: true); - var adminLimitOpt = CreateBoolOption(GlobalOption.EnableAdminLimit, false, adminOpt, invert: true); - CreateFloatOption( - GlobalOption.AdminLimitTime, - 30.0f, 5.0f, 120.0f, 0.5f, adminLimitOpt, - format: OptionUnit.Second, - invert: true, - enableCheckOption: adminLimitOpt); - - var secOpt = CreateBoolOption(GlobalOption.IsRemoveSecurity, false, isHeader: true); - var secLimitOpt = CreateBoolOption(GlobalOption.EnableSecurityLimit, false, secOpt, invert: true); - CreateFloatOption( - GlobalOption.SecurityLimitTime, - 30.0f, 5.0f, 120.0f, 0.5f, secLimitOpt, - format: OptionUnit.Second, - invert: true, - enableCheckOption: secLimitOpt); - - var vitalOpt = CreateBoolOption(GlobalOption.IsRemoveVital, false, isHeader: true); - var vitalLimitOpt = CreateBoolOption(GlobalOption.EnableVitalLimit, false, vitalOpt, invert: true); - CreateFloatOption( - GlobalOption.VitalLimitTime, - 30.0f, 5.0f, 120.0f, 0.5f, vitalLimitOpt, - format: OptionUnit.Second, - invert: true, - enableCheckOption: vitalLimitOpt); - - CreateBoolOption(GlobalOption.RandomMap, false, isHeader: true); - - var taskDisableOpt = CreateBoolOption(GlobalOption.DisableTaskWinWhenNoneTaskCrew, false, isHeader: true); - CreateBoolOption(GlobalOption.DisableTaskWin, false, taskDisableOpt); - - CreateBoolOption(GlobalOption.IsSameNeutralSameWin, true, isHeader: true); - CreateBoolOption(GlobalOption.DisableNeutralSpecialForceEnd, false); - - CreateBoolOption(GlobalOption.IsAssignNeutralToVanillaCrewGhostRole, true, isHeader: true); - CreateBoolOption(GlobalOption.IsRemoveAngleIcon, false); - CreateBoolOption(GlobalOption.IsBlockGAAbilityReport, false); + using (var factory = OptionManager.CreateOptionCategory(ShipGlobalOptionCategory.GhostRoleGlobalOption)) + { + GhostRoleOption.Create(factory); + } // ウマングアスを一時的もしくは恒久的に無効化 // CreateBoolOption(GlobalOption.EnableHorseMode, false, isHeader: true, isHidden: true); } - public static T GetCommonOptionValue(GlobalOption optionKey) - where T : - struct, IComparable, IConvertible, - IComparable, IEquatable - { - return OptionManager.Instance.GetValue((int)optionKey); - } + private static void createMapObjectOptions(ShipGlobalOptionCategory category) + { + using (var factory = OptionManager.CreateOptionCategory(category)) + { + IDeviceOption.Create(factory); + } + } + + protected static OptionCategory GetOptionCategory(ShipGlobalOptionCategory category) + { + if (!OptionManager.Instance.TryGetCategory(OptionTab.General, (int)category, out var cate)) + { + throw new ArgumentException(category.ToString()); + } + return cate; + } } diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/SpawnOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/SpawnOption.cs deleted file mode 100644 index 0d094328a..000000000 --- a/ExtremeRoles/GameMode/Option/ShipGlobal/SpawnOption.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace ExtremeRoles.GameMode.Option.ShipGlobal; - -public sealed class SpawnOption -{ - public bool EnableSpecialSetting { get; init; } = true; - - public bool Skeld { get; init; } = false; - public bool MiraHq { get; init; } = false; - public bool Polus { get; init; } = false; - public bool AirShip { get; init; } = true; - public bool Fungle { get; init; } = false; - - public bool IsAutoSelectRandom { get; init; } = false; -} diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/GhostRoleOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/GhostRoleOption.cs new file mode 100644 index 000000000..c8839e3a9 --- /dev/null +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/GhostRoleOption.cs @@ -0,0 +1,18 @@ + +using ExtremeRoles.Module.CustomOption.Factory; + +namespace ExtremeRoles.GameMode.Option.ShipGlobal.Sub; + +public readonly struct GhostRoleOption(in OptionCategory category) +{ + public readonly bool IsAssignNeutralToVanillaCrewGhostRole = category.GetValue((int)GhostRoleGlobalOption.IsAssignNeutralToVanillaCrewGhostRole); + public readonly bool IsRemoveAngleIcon = category.GetValue((int)GhostRoleGlobalOption.IsRemoveAngleIcon); + public readonly bool IsBlockGAAbilityReport = category.GetValue((int)GhostRoleGlobalOption.IsBlockGAAbilityReport); + + public static void Create(in OptionCategoryFactory factory) + { + factory.CreateBoolOption(GhostRoleGlobalOption.IsAssignNeutralToVanillaCrewGhostRole, true); + factory.CreateBoolOption(GhostRoleGlobalOption.IsRemoveAngleIcon, false); + factory.CreateBoolOption(GhostRoleGlobalOption.IsBlockGAAbilityReport, false); + } +} diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/AdminDeviceOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/AdminDeviceOption.cs new file mode 100644 index 000000000..d2988f61d --- /dev/null +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/AdminDeviceOption.cs @@ -0,0 +1,42 @@ + +using ExtremeRoles.Module.CustomOption.Factory; + +namespace ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; + +public enum AirShipAdminMode +{ + ModeBoth, + ModeCockpitOnly, + ModeArchiveOnly +} + +public enum AdminSpecialOption : int +{ + AirShipEnable = 5 +} + +public readonly struct AdminDeviceOption : IDeviceOption +{ + public readonly AirShipAdminMode AirShipEnable; + + public bool Disable { get; } + public bool EnableLimit { get; } + public float LimitTime { get; } + + public AdminDeviceOption(in OptionCategory cate) + { + AirShipEnable = (AirShipAdminMode)cate.GetValue((int)AdminSpecialOption.AirShipEnable); + + var device = new DeviceOption(cate); + Disable = device.Disable; + EnableLimit = device.EnableLimit; + LimitTime = device.LimitTime; + } + public static void Create(in OptionCategoryFactory factory) + { + var removeOpt = IDeviceOption.Create(factory); + + factory.CreateSelectionOption( + AdminSpecialOption.AirShipEnable, removeOpt, invert: true); + } +} diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/DeviceOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/DeviceOption.cs new file mode 100644 index 000000000..0a1e94f21 --- /dev/null +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/DeviceOption.cs @@ -0,0 +1,41 @@ + +using ExtremeRoles.Module.CustomOption.Factory; + + +using ExtremeRoles.Module.CustomOption.Interfaces; + +namespace ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; + +public enum DeviceOptionType +{ + IsRemove, + EnableLimit, + LimitTime, +} + +public interface IDeviceOption +{ + public bool Disable { get; } + public bool EnableLimit { get; } + public float LimitTime { get; } + + public static IOption Create(in OptionCategoryFactory factory) + { + var removeOpt = factory.CreateBoolOption(DeviceOptionType.IsRemove, false); + var enableLimit = factory.CreateBoolOption(DeviceOptionType.EnableLimit, false, removeOpt); + factory.CreateFloatOption( + DeviceOptionType.LimitTime, + 30.0f, 5.0f, 120.0f, 0.5f, + removeOpt, + format: OptionUnit.Second); + + return removeOpt; + } +} + +public readonly struct DeviceOption(in OptionCategory category) : IDeviceOption +{ + public bool Disable { get; } = category.GetValue((int)DeviceOptionType.IsRemove); + public bool EnableLimit { get; } = category.GetValue((int)DeviceOptionType.EnableLimit); + public float LimitTime { get; } = category.GetValue((int)DeviceOptionType.LimitTime); +} diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/VentConsoleOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/VentConsoleOption.cs new file mode 100644 index 000000000..22a435ac6 --- /dev/null +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MapModule/VentConsoleOption.cs @@ -0,0 +1,47 @@ + +using ExtremeRoles.Module.CustomOption.Factory; + +namespace ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; + +public enum VentAnimationMode +{ + VanillaAnimation, + DonotWallHack, + DonotOutVison, +} + +public enum VentOption : int +{ + Disable, + EngineerUseImpostor, + CanKillInPlayer, + AnimationModeInVison, +} + +public readonly struct VentConsoleOption( + bool disable, + bool engineerUseImpostorVent, + bool canKillVentInPlayer, + VentAnimationMode ventAnimation) +{ + public readonly bool Disable = disable; + public readonly bool EngineerUseImpostorVent = engineerUseImpostorVent; + public readonly bool CanKillVentInPlayer = canKillVentInPlayer; + public readonly VentAnimationMode AnimationMode = ventAnimation; + + public VentConsoleOption(in OptionCategory category) : this( + category.GetValue((int)VentOption.Disable), + category.GetValue((int)VentOption.EngineerUseImpostor), + category.GetValue((int)VentOption.CanKillInPlayer), + (VentAnimationMode)category.GetValue((int)VentOption.AnimationModeInVison)) + { } + + public static void Create(in OptionCategoryFactory factory) + { + var ventOption = factory.CreateBoolOption(VentOption.Disable, false); + + factory.CreateBoolOption(VentOption.CanKillInPlayer, false, ventOption, invert: true); + factory.CreateBoolOption(VentOption.EngineerUseImpostor, false, ventOption, invert: true); + factory.CreateSelectionOption(VentOption.AnimationModeInVison, parent: ventOption, invert: true); + } +} diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MeetingOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MeetingOption.cs new file mode 100644 index 000000000..0d5baf0a5 --- /dev/null +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/MeetingOption.cs @@ -0,0 +1,49 @@ + +using ExtremeRoles.Module.CustomOption.Factory; + +namespace ExtremeRoles.GameMode.Option.ShipGlobal.Sub; + +public enum MeetingOption : int +{ + UseRaiseHand, + NumMeating, + ChangeMeetingVoteAreaSort, + FixedMeetingPlayerLevel, + DisableSkipInEmergencyMeeting, + DisableSelfVote, +} + +public readonly struct MeetingHudOption +{ + public readonly int MaxMeetingCount; + public readonly bool UseRaiseHand; + public readonly bool IsChangeVoteAreaButtonSortArg; + public readonly bool IsFixedVoteAreaPlayerLevel; + public readonly bool IsBlockSkipInMeeting; + public readonly bool DisableSelfVote; + + public MeetingHudOption() + { + this.MaxMeetingCount = 0; + this.UseRaiseHand = false; + } + public MeetingHudOption(in OptionCategory category) + { + this.MaxMeetingCount = category.GetValue((int)MeetingOption.NumMeating); + this.UseRaiseHand = category.GetValue((int)MeetingOption.UseRaiseHand); + this.IsChangeVoteAreaButtonSortArg = category.GetValue((int)MeetingOption.ChangeMeetingVoteAreaSort); + this.IsFixedVoteAreaPlayerLevel = category.GetValue((int)MeetingOption.FixedMeetingPlayerLevel); + this.IsBlockSkipInMeeting = category.GetValue((int)MeetingOption.DisableSkipInEmergencyMeeting); + this.DisableSelfVote = category.GetValue((int)MeetingOption.DisableSelfVote); + } + + public static void Create(in OptionCategoryFactory factory) + { + factory.CreateBoolOption(MeetingOption.UseRaiseHand, false); + factory.CreateIntOption(MeetingOption.NumMeating, 10, 0, 100, 1); + factory.CreateBoolOption(MeetingOption.ChangeMeetingVoteAreaSort, false); + factory.CreateBoolOption(MeetingOption.FixedMeetingPlayerLevel, false); + factory.CreateBoolOption(MeetingOption.DisableSkipInEmergencyMeeting, false); + factory.CreateBoolOption(MeetingOption.DisableSelfVote, false); + } +} diff --git a/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/SpawnOption.cs b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/SpawnOption.cs new file mode 100644 index 000000000..400655516 --- /dev/null +++ b/ExtremeRoles/GameMode/Option/ShipGlobal/Sub/SpawnOption.cs @@ -0,0 +1,42 @@ + +using ExtremeRoles.Module.CustomOption.Factory; + +namespace ExtremeRoles.GameMode.Option.ShipGlobal.Sub; + +public enum RandomSpawnOption : int +{ + Enable, + Skeld, + MiraHq, + Polus, + AirShip, + Fungle, + + IsAutoSelect, +} + +public readonly struct SpawnOption(in OptionCategory cate) +{ + public readonly bool EnableSpecialSetting = cate.GetValue((int)RandomSpawnOption.Enable); + + public readonly bool Skeld = cate.GetValue((int)RandomSpawnOption.Skeld); + public readonly bool MiraHq = cate.GetValue((int)RandomSpawnOption.MiraHq); + public readonly bool Polus = cate.GetValue((int)RandomSpawnOption.Polus); + public readonly bool AirShip = cate.GetValue((int)RandomSpawnOption.AirShip); + public readonly bool Fungle = cate.GetValue((int)RandomSpawnOption.Fungle); + + public readonly bool IsAutoSelectRandom = cate.GetValue((int)RandomSpawnOption.IsAutoSelect); + + + public static void Create(in OptionCategoryFactory factory) + { + var randomSpawnOpt = factory.CreateBoolOption(RandomSpawnOption.Enable, true); + factory.CreateBoolOption(RandomSpawnOption.Skeld, false, randomSpawnOpt, invert: true); + factory.CreateBoolOption(RandomSpawnOption.MiraHq, false, randomSpawnOpt, invert: true); + factory.CreateBoolOption(RandomSpawnOption.Polus, false, randomSpawnOpt, invert: true); + factory.CreateBoolOption(RandomSpawnOption.AirShip, true, randomSpawnOpt, invert: true); + factory.CreateBoolOption(RandomSpawnOption.Fungle, false, randomSpawnOpt, invert: true); + + factory.CreateBoolOption(RandomSpawnOption.IsAutoSelect, false, randomSpawnOpt, invert: true); + } +} diff --git a/ExtremeRoles/GameMode/RoleSelector/ClassicGameModeRoleSelector.cs b/ExtremeRoles/GameMode/RoleSelector/ClassicGameModeRoleSelector.cs index fa97006b7..096fa3b87 100644 --- a/ExtremeRoles/GameMode/RoleSelector/ClassicGameModeRoleSelector.cs +++ b/ExtremeRoles/GameMode/RoleSelector/ClassicGameModeRoleSelector.cs @@ -4,6 +4,8 @@ using ExtremeRoles.Roles; using ExtremeRoles.Roles.API; + + namespace ExtremeRoles.GameMode.RoleSelector; public sealed class ClassicGameModeRoleSelector : IRoleSelector @@ -45,46 +47,29 @@ public IEnumerable UseGhostRoleId } } - private readonly HashSet useNormalRoleSpawnOption = new HashSet(); - private readonly HashSet useCombRoleSpawnOption = new HashSet(); - private readonly HashSet useGhostRoleSpawnOption = new HashSet(); + private readonly HashSet roleCategoryGroup = new HashSet(); public ClassicGameModeRoleSelector() { foreach (ExtremeRoleId roleId in getUseNormalRoleId()) { - var role = ExtremeRoleManager.NormalRole[(int)roleId]; - this.useNormalRoleSpawnOption.Add( - role.GetRoleOptionId(RoleCommonOption.SpawnRate)); + this.roleCategoryGroup.Add( + ExtremeRoleManager.GetRoleGroupId(roleId)); } foreach (CombinationRoleType roleId in getUseCombRoleType()) { - var role = ExtremeRoleManager.CombRole[(byte)roleId]; - this.useCombRoleSpawnOption.Add( - role.GetRoleOptionId(RoleCommonOption.SpawnRate)); - } + this.roleCategoryGroup.Add( + ExtremeRoleManager.GetCombRoleGroupId(roleId)); + } foreach (ExtremeGhostRoleId roleId in getUseGhostRoleId()) { - var role = ExtremeGhostRoleManager.AllGhostRole[roleId]; - this.useGhostRoleSpawnOption.Add( - role.GetRoleOptionId(RoleCommonOption.SpawnRate)); - } + this.roleCategoryGroup.Add( + ExtremeGhostRoleManager.GetRoleGroupId(roleId)); + } } - public bool IsValidRoleOption(IOptionInfo option) - { - while (option.Parent != null) - { - option = option.Parent; - } - - int id = option.Id; - - return - this.useNormalRoleSpawnOption.Contains(id) || - this.useCombRoleSpawnOption.Contains(id) || - this.useGhostRoleSpawnOption.Contains(id); - } + public bool IsValidCategory(int categoryId) + => this.roleCategoryGroup.Contains(categoryId); private static ExtremeRoleId[] getUseNormalRoleId() => [ diff --git a/ExtremeRoles/GameMode/RoleSelector/HideNSeekGameModeRoleSelector.cs b/ExtremeRoles/GameMode/RoleSelector/HideNSeekGameModeRoleSelector.cs index 9788cbaab..575718cef 100644 --- a/ExtremeRoles/GameMode/RoleSelector/HideNSeekGameModeRoleSelector.cs +++ b/ExtremeRoles/GameMode/RoleSelector/HideNSeekGameModeRoleSelector.cs @@ -2,7 +2,6 @@ using ExtremeRoles.GhostRoles; using ExtremeRoles.Roles; -using ExtremeRoles.Roles.API; namespace ExtremeRoles.GameMode.RoleSelector; @@ -42,30 +41,21 @@ public IEnumerable UseGhostRoleId } } - private readonly HashSet useNormalRoleSpawnOption = new HashSet(); + private readonly HashSet roleCategoryGroup = new HashSet(); - public HideNSeekGameModeRoleSelector() + public HideNSeekGameModeRoleSelector() { foreach (ExtremeRoleId id in getUseNormalId()) - { - this.useNormalRoleSpawnOption.Add( - ExtremeRoleManager.NormalRole[(int)id].GetRoleOptionId(RoleCommonOption.SpawnRate)); - } + { + this.roleCategoryGroup.Add( + ExtremeRoleManager.GetRoleGroupId(id)); + } } - public bool IsValidRoleOption(IOptionInfo option) - { - while (option.Parent != null) - { - option = option.Parent; - } - - int id = option.Id; - - return this.useNormalRoleSpawnOption.Contains(id); - } + public bool IsValidCategory(int categoryId) + => this.roleCategoryGroup.Contains(categoryId); - private static ExtremeRoleId[] getUseNormalId() => + private static ExtremeRoleId[] getUseNormalId() => [ ExtremeRoleId.SpecialCrew, ExtremeRoleId.Neet, diff --git a/ExtremeRoles/GameMode/RoleSelector/IRoleSelector.cs b/ExtremeRoles/GameMode/RoleSelector/IRoleSelector.cs index 6fccd3e97..9967a8433 100644 --- a/ExtremeRoles/GameMode/RoleSelector/IRoleSelector.cs +++ b/ExtremeRoles/GameMode/RoleSelector/IRoleSelector.cs @@ -7,27 +7,31 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; using ExtremeRoles.Roles; -using ExtremeRoles.Module.CustomOption.Factories; + + +using ExtremeRoles.Module.CustomOption.Factory; namespace ExtremeRoles.GameMode.RoleSelector; -public enum RoleGlobalOption : int +public enum RoleSpawnOption : int +{ + MinCrewmate = 0, + MaxCrewmate, + MinNeutral, + MaxNeutral, + MinImpostor, + MaxImpostor, +} + +public enum SpawnOptionCategory : int +{ + RoleSpawnCategory = 5, + GhostRoleSpawnCategory, +} + +public enum XionOption : int { - MinCrewmateRoles = 10, - MaxCrewmateRoles, - MinNeutralRoles, - MaxNeutralRoles, - MinImpostorRoles, - MaxImpostorRoles, - - MinCrewmateGhostRoles, - MaxCrewmateGhostRoles, - MinNeutralGhostRoles, - MaxNeutralGhostRoles, - MinImpostorGhostRoles, - MaxImpostorGhostRoles, - - UseXion, + UseXion, } public interface IRoleSelector @@ -43,70 +47,63 @@ public interface IRoleSelector private static Color defaultOptionColor => new Color(204f / 255f, 204f / 255f, 0, 1f); - public bool IsValidGlobalRoleOptionId(RoleGlobalOption optionId) - => Enum.IsDefined(typeof(RoleGlobalOption), optionId); + public bool IsValidGlobalRoleOptionId(RoleSpawnOption optionId) + => Enum.IsDefined(typeof(RoleSpawnOption), optionId); + + public static bool RawXionUse => OptionManager.Instance.TryGetCategory( + OptionTab.General, + ExtremeRoleManager.GetRoleGroupId(ExtremeRoleId.Xion), + out var cate) && + cate.GetValue((int)XionOption.UseXion); - public bool IsValidRoleOption(IOptionInfo option); + public bool IsValidCategory(int categoryId); public static void CreateRoleGlobalOption() { - var roleOptionFactory = new ColorSyncFactory(defaultOptionColor); - - createExtremeRoleGlobalSpawnOption(roleOptionFactory); - createExtremeGhostRoleGlobalSpawnOption(roleOptionFactory); - - roleOptionFactory.CreateBoolOption( - RoleGlobalOption.UseXion, false, - isHeader:true, color: ColorPalette.XionBlue); - } - - private static void createExtremeRoleGlobalSpawnOption(ColorSyncFactory factory) + using (var roleOptionFactory = OptionManager.CreateOptionCategory( + SpawnOptionCategory.RoleSpawnCategory, + color: defaultOptionColor)) + { + createExtremeRoleRoleSpawnOption(roleOptionFactory); + } + + using (var roleOptionFactory = OptionManager.CreateOptionCategory( + SpawnOptionCategory.GhostRoleSpawnCategory, + color: defaultOptionColor)) + { + createExtremeRoleRoleSpawnOption(roleOptionFactory); + } + using (var xionCategory = OptionManager.CreateOptionCategory( + ExtremeRoleManager.GetRoleGroupId(ExtremeRoleId.Xion), + ExtremeRoleId.Xion.ToString(), + color: ColorPalette.XionBlue)) + { + xionCategory.CreateBoolOption( + XionOption.UseXion, false); + } + } + + private static void createExtremeRoleRoleSpawnOption(OptionCategoryFactory factory) { factory.CreateIntOption( - RoleGlobalOption.MinCrewmateRoles, - 0, 0, (GameSystem.VanillaMaxPlayerNum - 1) * 2, 1, - isHeader: true); + RoleSpawnOption.MinCrewmate, + 0, 0, (GameSystem.VanillaMaxPlayerNum - 1) * 2, 1); factory.CreateIntOption( - RoleGlobalOption.MaxCrewmateRoles, + RoleSpawnOption.MaxCrewmate, 0, 0, (GameSystem.VanillaMaxPlayerNum - 1) * 2, 1); factory.CreateIntOption( - RoleGlobalOption.MinNeutralRoles, + RoleSpawnOption.MinNeutral, 0, 0, (GameSystem.VanillaMaxPlayerNum - 2) * 2, 1); factory.CreateIntOption( - RoleGlobalOption.MaxNeutralRoles, + RoleSpawnOption.MaxNeutral, 0, 0, (GameSystem.VanillaMaxPlayerNum - 2) * 2, 1); factory.CreateIntOption( - RoleGlobalOption.MinImpostorRoles, + RoleSpawnOption.MinImpostor, 0, 0, GameSystem.MaxImposterNum * 2, 1); factory.CreateIntOption( - RoleGlobalOption.MaxImpostorRoles, + RoleSpawnOption.MaxImpostor, 0, 0, GameSystem.MaxImposterNum * 2, 1); } - - private static void createExtremeGhostRoleGlobalSpawnOption(ColorSyncFactory factory) - { - factory.CreateIntOption( - RoleGlobalOption.MinCrewmateGhostRoles, - 0, 0, GameSystem.VanillaMaxPlayerNum - 1, 1, - isHeader: true); - factory.CreateIntOption( - RoleGlobalOption.MaxCrewmateGhostRoles, - 0, 0, GameSystem.VanillaMaxPlayerNum - 1, 1); - - factory.CreateIntOption( - RoleGlobalOption.MinNeutralGhostRoles, - 0, 0, GameSystem.VanillaMaxPlayerNum - 2, 1); - factory.CreateIntOption( - RoleGlobalOption.MaxNeutralGhostRoles, - 0, 0, GameSystem.VanillaMaxPlayerNum - 2, 1); - - factory.CreateIntOption( - RoleGlobalOption.MinImpostorGhostRoles, - 0, 0, GameSystem.MaxImposterNum, 1); - factory.CreateIntOption( - RoleGlobalOption.MaxImpostorGhostRoles, - 0, 0, GameSystem.MaxImposterNum, 1); - } } diff --git a/ExtremeRoles/GhostRoles/API/GhostRoleBase.cs b/ExtremeRoles/GhostRoles/API/GhostRoleBase.cs index f0503885d..6fa6a9b64 100644 --- a/ExtremeRoles/GhostRoles/API/GhostRoleBase.cs +++ b/ExtremeRoles/GhostRoles/API/GhostRoleBase.cs @@ -9,7 +9,13 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; + + + +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Roles; +using ExtremeRoles.GhostRoles.API.Interface; namespace ExtremeRoles.GhostRoles.API; @@ -27,7 +33,6 @@ public abstract class GhostRoleBase public ExtremeRoleType Team { get; protected set; } public ExtremeGhostRoleId Id { get; protected set; } - public int OptionIdOffset { get; protected set; } public int GameControlId { get; protected set; } public string Name { get; protected set; } @@ -35,10 +40,25 @@ public abstract class GhostRoleBase public Module.ExtremeAbilityButton? Button { get; protected set; } - private OptionTab tab = OptionTab.General; + protected readonly OptionTab Tab = OptionTab.General; private int controlId; - public GhostRoleBase( + public IOptionLoader Loader + { + get + { + if (!OptionManager.Instance.TryGetCategory( + this.Tab, + ExtremeGhostRoleManager.GetRoleGroupId(this.Id), + out var cate)) + { + throw new ArgumentException("Can't find category"); + } + return cate; + } + } + + public GhostRoleBase( bool hasTask, ExtremeRoleType team, ExtremeGhostRoleId id, @@ -57,19 +77,19 @@ public GhostRoleBase( switch (team) { case ExtremeRoleType.Crewmate: - this.tab = OptionTab.GhostCrewmate; + this.Tab = OptionTab.GhostCrewmate; break; case ExtremeRoleType.Impostor: - this.tab = OptionTab.GhostImpostor; + this.Tab = OptionTab.GhostImpostor; break; case ExtremeRoleType.Neutral: - this.tab = OptionTab.GhostNeutral; + this.Tab = OptionTab.GhostNeutral; break; } } else { - this.tab = tab; + this.Tab = tab; } } @@ -78,6 +98,12 @@ public virtual GhostRoleBase Clone() GhostRoleBase copy = (GhostRoleBase)this.MemberwiseClone(); Color baseColor = this.Color; + if (this is ICombination combRole && + copy is ICombination copyComb) + { + copyComb.OffsetInfo = combRole.OffsetInfo; + } + copy.Color = new Color( baseColor.r, baseColor.g, @@ -87,28 +113,18 @@ public virtual GhostRoleBase Clone() return copy; } - public void CreateRoleAllOption(int optionIdOffset) + public void CreateRoleAllOption() { - this.OptionIdOffset = optionIdOffset; - var parentOps = createOptionFactory(optionIdOffset); + using var parentOps = createOptionFactory(); CreateSpecificOption(parentOps); } public void CreateRoleSpecificOption( - OptionFactory factory, int optionIdOffset) + OptionFactory factory) { - this.OptionIdOffset = optionIdOffset; CreateSpecificOption(factory); } - public int GetRoleOptionId(T option) where T : struct, IConvertible - { - EnumCheck(option); - return GetRoleOptionId(Convert.ToInt32(option)); - } - - public int GetRoleOptionId(int option) => this.OptionIdOffset + option; - public bool IsCrewmate() => this.Team == ExtremeRoleType.Crewmate; public bool IsImpostor() => this.Team == ExtremeRoleType.Impostor; @@ -188,46 +204,45 @@ protected void ButtonInit() { if (this.Button == null) { return; } - var allOps = OptionManager.Instance; + var loader = this.Loader; this.Button.Behavior.SetCoolTime( - allOps.GetValue(this.GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime))); + loader.GetValue(RoleAbilityCommonOption.AbilityCoolTime)); - if (allOps.TryGet( - this.GetRoleOptionId( - RoleAbilityCommonOption.AbilityActiveTime), out var activeTimeOtion) && + if (loader.TryGetValueOption( + RoleAbilityCommonOption.AbilityActiveTime, out var activeTimeOtion) && activeTimeOtion is not null) { - this.Button.Behavior.SetActiveTime(activeTimeOtion.GetValue()); + this.Button.Behavior.SetActiveTime(activeTimeOtion.Value); } if (this.Button.Behavior is AbilityCountBehavior behavior && - allOps.TryGet( - this.GetRoleOptionId( - RoleAbilityCommonOption.AbilityCount), + loader.TryGetValueOption( + RoleAbilityCommonOption.AbilityCount, out var countOption) && countOption is not null) { - behavior.SetAbilityCount(countOption.GetValue()); + behavior.SetAbilityCount(countOption.Value); } this.Button.OnMeetingEnd(); } - protected bool isReportAbility() => OptionManager.Instance.GetValue( - this.GetRoleOptionId(GhostRoleOption.IsReportAbility)); + protected bool isReportAbility() => this.Loader.GetValue(GhostRoleOption.IsReportAbility); - private OptionFactory createOptionFactory(int offset) + private OptionFactory createOptionFactory() { - var factory = new OptionFactory(offset, this.Name, this.tab); - factory.CreateSelectionOption( + var factory = OptionManager.CreateAutoParentSetOptionCategory( + ExtremeGhostRoleManager.GetRoleGroupId(this.Id), + this.Name, this.Tab, this.Color); + factory.Create0To100Percentage10StepOption( RoleCommonOption.SpawnRate, - OptionCreator.SpawnRate, null, true, - color: this.Color); + ignorePrefix: true); int spawnNum = this.IsImpostor() ? GameSystem.MaxImposterNum : GameSystem.VanillaMaxPlayerNum - 1; factory.CreateIntOption( RoleCommonOption.RoleNum, - 1, 1, spawnNum, 1); + 1, 1, spawnNum, 1, + ignorePrefix: true); factory.CreateIntOption(RoleCommonOption.AssignWeight, 500, 1, 1000, 1, ignorePrefix: true); diff --git a/ExtremeRoles/GhostRoles/API/Interface/ICombination.cs b/ExtremeRoles/GhostRoles/API/Interface/ICombination.cs new file mode 100644 index 000000000..ed44ee363 --- /dev/null +++ b/ExtremeRoles/GhostRoles/API/Interface/ICombination.cs @@ -0,0 +1,12 @@ + +using ExtremeRoles.Roles.API; + +#nullable enable + +namespace ExtremeRoles.GhostRoles.API.Interface; + +public interface ICombination +{ + public MultiAssignRoleBase.OptionOffsetInfo? OffsetInfo { get; set; } + public OptionLoadWrapper WrappedCategory { get; } +} diff --git a/ExtremeRoles/GhostRoles/API/Interface/IGhostRoleWinable.cs b/ExtremeRoles/GhostRoles/API/Interface/IGhostRoleWinable.cs index 008ea4894..5da235a3f 100644 --- a/ExtremeRoles/GhostRoles/API/Interface/IGhostRoleWinable.cs +++ b/ExtremeRoles/GhostRoles/API/Interface/IGhostRoleWinable.cs @@ -4,6 +4,6 @@ public interface IGhostRoleWinable { public bool IsWin( GameOverReason reason, - GameData.PlayerInfo ghostRolePlayer); + NetworkedPlayerInfo ghostRolePlayer); } } diff --git a/ExtremeRoles/GhostRoles/Crewmate/Faunus.cs b/ExtremeRoles/GhostRoles/Crewmate/Faunus.cs index 71de0df56..bee24e4b6 100644 --- a/ExtremeRoles/GhostRoles/Crewmate/Faunus.cs +++ b/ExtremeRoles/GhostRoles/Crewmate/Faunus.cs @@ -16,7 +16,7 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Compat; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; #nullable enable diff --git a/ExtremeRoles/GhostRoles/Crewmate/Poltergeist.cs b/ExtremeRoles/GhostRoles/Crewmate/Poltergeist.cs index 20032ed88..a515da0d0 100644 --- a/ExtremeRoles/GhostRoles/Crewmate/Poltergeist.cs +++ b/ExtremeRoles/GhostRoles/Crewmate/Poltergeist.cs @@ -11,7 +11,9 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.Performance; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; + + +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; namespace ExtremeRoles.GhostRoles.Crewmate; @@ -27,7 +29,7 @@ public enum Option private float range; private DeadBody? carringBody; - private GameData.PlayerInfo? targetBody; + private NetworkedPlayerInfo? targetBody; public Poltergeist() : base( true, @@ -110,8 +112,7 @@ public override void CreateAbility() public override void Initialize() { - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(Option.Range)); + this.range = this.Loader.GetValue(Option.Range); } protected override void OnMeetingEndHook() diff --git a/ExtremeRoles/GhostRoles/Crewmate/Shutter.cs b/ExtremeRoles/GhostRoles/Crewmate/Shutter.cs index 1cdd7ab5c..b1477844c 100644 --- a/ExtremeRoles/GhostRoles/Crewmate/Shutter.cs +++ b/ExtremeRoles/GhostRoles/Crewmate/Shutter.cs @@ -15,7 +15,9 @@ using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; + + +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; using static ExtremeRoles.Roles.Solo.Crewmate.Photographer; @@ -205,11 +207,11 @@ public override void CreateAbility() public override void Initialize() { + var loader = this.Loader; + this.photoCreater = new GhostPhotoCamera( - OptionManager.Instance.GetValue( - GetRoleOptionId(ShutterOption.PhotoRange)), - OptionManager.Instance.GetValue( - GetRoleOptionId(ShutterOption.RightPlayerNameRate))); + loader.GetValue(ShutterOption.PhotoRange), + loader.GetValue(ShutterOption.RightPlayerNameRate)); } protected override void OnMeetingEndHook() diff --git a/ExtremeRoles/GhostRoles/ExtremeGhostRoleManager.cs b/ExtremeRoles/GhostRoles/ExtremeGhostRoleManager.cs index 2ee3c6459..8fa65ef3d 100644 --- a/ExtremeRoles/GhostRoles/ExtremeGhostRoleManager.cs +++ b/ExtremeRoles/GhostRoles/ExtremeGhostRoleManager.cs @@ -52,7 +52,7 @@ public enum AbilityType : byte public static class ExtremeGhostRoleManager { private const int ghostRoleOptionId = 25; - private const int idOffset = 128; + public const int IdOffset = 512; public static Dictionary GameRole = new Dictionary(); @@ -75,11 +75,16 @@ public static readonly Dictionary< RoleTypes.GuardianAngel, }; - public static void AssignGhostRoleToPlayer(PlayerControl player) + private const int roleIdOffset = 512; + + public static int GetRoleGroupId(ExtremeGhostRoleId roleId) + => roleIdOffset + (int)roleId; + + public static void AssignGhostRoleToPlayer(PlayerControl player) { RoleTypes roleType = player.Data.Role.Role; SingleRoleBase baseRole = ExtremeRoleManager.GameRole[player.PlayerId]; - int controlId = baseRole.GameControlId + idOffset; + int controlId = baseRole.GameControlId + IdOffset; if (vanillaGhostRole.Contains(roleType)) { @@ -142,21 +147,12 @@ public static void AssignGhostRoleToPlayer(PlayerControl player) } } - public static void CreateGhostRoleOption(int optionIdOffset) + public static void CreateGhostRoleOption() { - if (AllGhostRole.Count == 0) { return; }; - - IEnumerable roles = AllGhostRole.Values; - - int roleOptionOffset = 0; - - foreach (var item in roles.Select( - (Value, Index) => new { Value, Index })) - { - roleOptionOffset = optionIdOffset + (ghostRoleOptionId * item.Index); - item.Value.CreateRoleAllOption(roleOptionOffset); - } - + foreach (var ghost in AllGhostRole.Values) + { + ghost.CreateRoleAllOption(); + } } public static GhostRoleBase GetLocalPlayerGhostRole() diff --git a/ExtremeRoles/GhostRoles/Impostor/Igniter.cs b/ExtremeRoles/GhostRoles/Impostor/Igniter.cs index ce00678af..3dee8802b 100644 --- a/ExtremeRoles/GhostRoles/Impostor/Igniter.cs +++ b/ExtremeRoles/GhostRoles/Impostor/Igniter.cs @@ -8,7 +8,9 @@ using ExtremeRoles.Roles.API.Extension.State; using ExtremeRoles.Performance; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; + + +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; #nullable enable @@ -33,7 +35,7 @@ public Igniter() : base( Palette.ImpostorRed) { } - public static bool TryComputeVison(GameData.PlayerInfo player, out float vison) + public static bool TryComputeVison(NetworkedPlayerInfo player, out float vison) { vison = float.MaxValue; SingleRoleBase role = ExtremeRoleManager.GameRole[player.PlayerId]; @@ -95,10 +97,9 @@ public override void CreateAbility() public override void Initialize() { - isEffectImp = OptionManager.Instance.GetValue( - GetRoleOptionId(IgniterOption.IsEffectImpostor)); - isEffectNeut = OptionManager.Instance.GetValue( - GetRoleOptionId(IgniterOption.IsEffectNeutral)); + var loader = this.Loader; + isEffectImp = loader.GetValue(IgniterOption.IsEffectImpostor); + isEffectNeut = loader.GetValue(IgniterOption.IsEffectNeutral); } protected override void OnMeetingEndHook() diff --git a/ExtremeRoles/GhostRoles/Impostor/SaboEvil.cs b/ExtremeRoles/GhostRoles/Impostor/SaboEvil.cs index 5d408c74c..733aa4bc0 100644 --- a/ExtremeRoles/GhostRoles/Impostor/SaboEvil.cs +++ b/ExtremeRoles/GhostRoles/Impostor/SaboEvil.cs @@ -6,7 +6,7 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.Performance; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; #nullable enable diff --git a/ExtremeRoles/GhostRoles/Impostor/Ventgeist.cs b/ExtremeRoles/GhostRoles/Impostor/Ventgeist.cs index 882a1474d..8a5c7c565 100644 --- a/ExtremeRoles/GhostRoles/Impostor/Ventgeist.cs +++ b/ExtremeRoles/GhostRoles/Impostor/Ventgeist.cs @@ -9,9 +9,11 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.Performance; + + #nullable enable -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; using ExtremeRoles.Extension.VentModule; namespace ExtremeRoles.GhostRoles.Impostor; @@ -56,8 +58,7 @@ public override void CreateAbility() public override void Initialize() { - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(Option.Range)); + this.range = this.Loader.GetValue(Option.Range); } protected override void OnMeetingEndHook() diff --git a/ExtremeRoles/GhostRoles/Neutral/Foras.cs b/ExtremeRoles/GhostRoles/Neutral/Foras.cs index d08d49876..e1a30468f 100644 --- a/ExtremeRoles/GhostRoles/Neutral/Foras.cs +++ b/ExtremeRoles/GhostRoles/Neutral/Foras.cs @@ -14,7 +14,9 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; + + +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; namespace ExtremeRoles.GhostRoles.Neutal; @@ -86,8 +88,8 @@ private static void showArrow(byte forasPlayerId, byte arrowTargetPlayerId) foras.arrowControler.SetTarget(arrowTargetPlayer.gameObject); foras.arrowControler.SetDelayActiveTimer(foras.delayTime); foras.arrowControler.SetHideTimer( - OptionManager.Instance.GetValue(foras.GetRoleOptionId( - RoleAbilityCommonOption.AbilityActiveTime))); + foras.Loader.GetValue( + RoleAbilityCommonOption.AbilityActiveTime)); foras.arrowControler.gameObject.SetActive(true); } } @@ -125,12 +127,10 @@ public override void CreateAbility() public override void Initialize() { - this.delayTime = OptionManager.Instance.GetValue( - GetRoleOptionId(ForasOption.DelayTime)); - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(ForasOption.Range)); - this.rate = OptionManager.Instance.GetValue( - GetRoleOptionId(ForasOption.MissingTargetRate)); + var loader = this.Loader; + this.delayTime = loader.GetValue(ForasOption.DelayTime); + this.range = loader.GetValue(ForasOption.Range); + this.rate = loader.GetValue(ForasOption.MissingTargetRate); } protected override void OnMeetingEndHook() diff --git a/ExtremeRoles/GhostRoles/VanillaGhostRoleWrapper.cs b/ExtremeRoles/GhostRoles/VanillaGhostRoleWrapper.cs index 409b6c341..87d332eac 100644 --- a/ExtremeRoles/GhostRoles/VanillaGhostRoleWrapper.cs +++ b/ExtremeRoles/GhostRoles/VanillaGhostRoleWrapper.cs @@ -4,7 +4,7 @@ using AmongUs.GameOptions; using ExtremeRoles.GhostRoles.API; -using ExtremeRoles.Module.CustomOption.Factories; +using ExtremeRoles.Module.CustomOption.Factory; namespace ExtremeRoles.GhostRoles; @@ -16,7 +16,7 @@ public VanillaGhostRoleWrapper( RoleTypes vanillaRoleId) : base( true, Roles.API.ExtremeRoleType.Crewmate, ExtremeGhostRoleId.VanillaRole, - "", UnityEngine.Color.white) + "", Color.white) { this.vanillaRoleId = vanillaRoleId; this.Name = vanillaRoleId.ToString(); @@ -83,7 +83,7 @@ public override void Initialize() return; } - protected override void CreateSpecificOption(AutoParentSetFactory factory) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { throw new System.Exception("Don't call this class method!!"); } diff --git a/ExtremeRoles/Helper/GameSystem.cs b/ExtremeRoles/Helper/GameSystem.cs index f5b32008a..c4028c776 100644 --- a/ExtremeRoles/Helper/GameSystem.cs +++ b/ExtremeRoles/Helper/GameSystem.cs @@ -13,9 +13,12 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Compat; +using Il2CppInterop.Runtime.InteropTypes.Arrays; + using UnityObject = UnityEngine.Object; using UseButtonDict = Il2CppSystem.Collections.Generic.Dictionary; + #nullable enable namespace ExtremeRoles.Helper; @@ -135,7 +138,7 @@ public static ShipStatus GetShipObj(byte mapId) } public static (int, int) GetTaskInfo( - GameData.PlayerInfo playerInfo) + NetworkedPlayerInfo playerInfo) { int TotalTasks = 0; int CompletedTasks = 0; @@ -188,7 +191,7 @@ public static int GetRandomLongTask() return taskIndex[index]; } - public static int GetRandomNormalTaskId() + public static int GetRandomShortTaskId() { if (CachedShipStatus.Instance == null) { return byte.MaxValue; } @@ -263,12 +266,10 @@ public static void ReplaceToNewTask(byte playerId, int index, int taskIndex) if (SetPlayerNewTask(ref player, taskId, (uint)index)) { - player.Data.Tasks[index] = new GameData.TaskInfo( + player.Data.Tasks[index] = new NetworkedPlayerInfo.TaskInfo( taskId, (uint)index); player.Data.Tasks[index].Id = (uint)index; - - GameData.Instance.SetDirtyBit( - 1U << (int)player.PlayerId); + player.Data.MarkDirty(); } } @@ -383,7 +384,7 @@ public static void ForceRepairrSpecialSabotage(SystemTypes sabSystem) } public static void SetTask( - GameData.PlayerInfo playerInfo, + NetworkedPlayerInfo playerInfo, int taskIndex) { NormalPlayerTask task = CachedShipStatus.Instance.GetTaskById((byte)taskIndex); @@ -391,7 +392,7 @@ public static void SetTask( PlayerControl player = playerInfo.Object; int index = playerInfo.Tasks.Count; - playerInfo.Tasks.Add(new GameData.TaskInfo((byte)taskIndex, (uint)index)); + playerInfo.Tasks.Add(new ((byte)taskIndex, (uint)index)); playerInfo.Tasks[index].Id = (uint)index; task.Id = (uint)index; @@ -473,12 +474,14 @@ public static void ShareVersion() public static void SpawnDummyPlayer(string name = "") { - PlayerControl playerControl = UnityEngine.Object.Instantiate( - AmongUsClient.Instance.PlayerPrefab); + PlayerControl playerControl = UnityObject.Instantiate( + AmongUsClient.Instance.PlayerPrefab); playerControl.PlayerId = (byte)GameData.Instance.GetAvailableId(); - GameData.Instance.AddPlayer(playerControl); - AmongUsClient.Instance.Spawn(playerControl, -2, InnerNet.SpawnFlags.None); + var dummyData = GameData.Instance.AddDummy(playerControl); + AmongUsClient.Instance.Spawn(dummyData); + AmongUsClient.Instance.Spawn(playerControl); + playerControl.isDummy = true; var hatMng = FastDestroyableSingleton.Instance; var rng = RandomGenerator.GetTempGenerator(); @@ -500,13 +503,15 @@ public static void SpawnDummyPlayer(string name = "") playerControl.SetPet(hatMng.allPets[pet].ProdId, color); playerControl.SetVisor(hatMng.allVisors[visor].ProdId, color); playerControl.SetSkin(hatMng.allSkins[skin].ProdId, color); - GameData.Instance.RpcSetTasks(playerControl.PlayerId, Array.Empty()); - } + + dummyData.PlayerId = playerControl.PlayerId; + dummyData.RpcSetTasks(new Il2CppStructArray(0)); + } private static List getTaskIndex( NormalPlayerTask[] tasks) { - List index = new List(); + List index = new List(tasks.Length); for (int i = 0; i < tasks.Length; ++i) { if (!ignoreTask.Contains(tasks[i].TaskType)) diff --git a/ExtremeRoles/Helper/Logging.cs b/ExtremeRoles/Helper/Logging.cs index 50c636664..91c3aaa59 100644 --- a/ExtremeRoles/Helper/Logging.cs +++ b/ExtremeRoles/Helper/Logging.cs @@ -8,6 +8,8 @@ using UnityEngine; + + namespace ExtremeRoles.Helper; public static class Logging diff --git a/ExtremeRoles/Helper/Player.cs b/ExtremeRoles/Helper/Player.cs index d7c0c0344..dcf9f5d1a 100644 --- a/ExtremeRoles/Helper/Player.cs +++ b/ExtremeRoles/Helper/Player.cs @@ -200,7 +200,7 @@ public static List GetAllPlayerInRange( Vector2 truePosition = sourcePlayer.GetTruePosition(); - foreach (GameData.PlayerInfo playerInfo in + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (isValidPlayer(role, sourcePlayer, playerInfo)) @@ -242,14 +242,13 @@ public static float GetPlayerTaskGage(PlayerControl player) return GetPlayerTaskGage(player.Data); } - public static float GetPlayerTaskGage(GameData.PlayerInfo player) + public static float GetPlayerTaskGage(NetworkedPlayerInfo player) { int taskNum = 0; int compNum = 0; - foreach (GameData.TaskInfo task in player.Tasks.GetFastEnumerator()) + foreach (var task in player.Tasks.GetFastEnumerator()) { - ++taskNum; if (task.Complete) @@ -262,7 +261,7 @@ public static float GetPlayerTaskGage(GameData.PlayerInfo player) } - public static GameData.PlayerInfo GetDeadBodyInfo(float range) + public static NetworkedPlayerInfo GetDeadBodyInfo(float range) { Vector2 playerPos = CachedPlayerControl.LocalPlayer.PlayerControl.GetTruePosition(); @@ -452,7 +451,7 @@ private static bool isHit( private static bool isValidPlayer( SingleRoleBase role, PlayerControl sourcePlayer, - GameData.PlayerInfo targetPlayer) + NetworkedPlayerInfo targetPlayer) { return ( targetPlayer != null && diff --git a/ExtremeRoles/Module/AbilityFactory/GhostRoleAbilityFactory.cs b/ExtremeRoles/Module/AbilityFactory/GhostRoleAbilityFactory.cs index 64304a6d1..99a77ed1f 100644 --- a/ExtremeRoles/Module/AbilityFactory/GhostRoleAbilityFactory.cs +++ b/ExtremeRoles/Module/AbilityFactory/GhostRoleAbilityFactory.cs @@ -9,7 +9,9 @@ using ExtremeRoles.Module.ButtonAutoActivator; using ExtremeRoles.Performance; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; + + +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; namespace ExtremeRoles.Module.AbilityFactory; diff --git a/ExtremeRoles/Module/ApiHandler/PlayerInfoData.cs b/ExtremeRoles/Module/ApiHandler/PlayerInfoData.cs index 47ca551b2..bc7120438 100644 --- a/ExtremeRoles/Module/ApiHandler/PlayerInfoData.cs +++ b/ExtremeRoles/Module/ApiHandler/PlayerInfoData.cs @@ -14,7 +14,7 @@ public readonly record struct ColorInfo(int RGBA, byte R, byte G, byte B, byte A public readonly record struct PlayerColorInfo(int ColorId, StringNames ColorNameId, ColorInfo MainColor, ColorInfo ShadowColor) { - public static PlayerColorInfo Create(GameData.PlayerOutfit outfit) + public static PlayerColorInfo Create(NetworkedPlayerInfo.PlayerOutfit outfit) { int colorId = outfit.ColorId; StringNames colorName = Palette.ColorNames[colorId]; @@ -30,7 +30,7 @@ public readonly record struct PlayerCosmicInfo( string HatId, string VisorId, string SkinId, string PetId, string NamePlateId) { - public static PlayerCosmicInfo Create(GameData.PlayerOutfit outfit) + public static PlayerCosmicInfo Create(NetworkedPlayerInfo.PlayerOutfit outfit) => new PlayerCosmicInfo( PlayerColorInfo.Create(outfit), outfit.HatId, diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/AbilityPart.cs b/ExtremeRoles/Module/CustomMonoBehaviour/AbilityPart.cs index 6ba8a8651..0b84aabd9 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/AbilityPart.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/AbilityPart.cs @@ -73,7 +73,7 @@ public void SetHideArrowDistance(float newDistance) } public float CanUse( - GameData.PlayerInfo pc, out bool canUse, out bool couldUse) + NetworkedPlayerInfo pc, out bool canUse, out bool couldUse) { float num = Vector2.Distance( pc.Object.GetTruePosition(), diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/BaitDalayReporter.cs b/ExtremeRoles/Module/CustomMonoBehaviour/BaitDalayReporter.cs index f147af279..30cdf858b 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/BaitDalayReporter.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/BaitDalayReporter.cs @@ -55,7 +55,7 @@ public void FixedUpdate() public void StartReportTimer( Color color, - GameData.PlayerInfo target, + NetworkedPlayerInfo target, float timer = 0.0f) { this.rend.enabled = true; @@ -92,7 +92,7 @@ public void StartReportTimer( } [HideFromIl2Cpp] - private IEnumerator delayReport(float targetTime, GameData.PlayerInfo target) + private IEnumerator delayReport(float targetTime, NetworkedPlayerInfo target) { if (this.text == null) { @@ -118,7 +118,7 @@ private IEnumerator delayReport(float targetTime, GameData.PlayerInfo target) reportTarget(target); } - private static void reportTarget(GameData.PlayerInfo target) + private static void reportTarget(NetworkedPlayerInfo target) { CachedPlayerControl.LocalPlayer.PlayerControl.CmdReportDeadBody(target); } diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeConsole.cs b/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeConsole.cs index 0c333de06..ca44e36e8 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeConsole.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeConsole.cs @@ -19,7 +19,7 @@ public interface IBehavior public bool IsCheckWall { get; } - public bool CanUse(GameData.PlayerInfo pc); + public bool CanUse(NetworkedPlayerInfo pc); public void Use(); } @@ -55,7 +55,7 @@ public void SetOutline(bool on, bool mainTarget) */ } - public float CanUse(GameData.PlayerInfo pc, out bool canUse, out bool couldUse) + public float CanUse(NetworkedPlayerInfo pc, out bool canUse, out bool couldUse) { canUse = false; couldUse = false; @@ -121,7 +121,7 @@ public void Awake() this.Image = rend; } - public override float CanUse(GameData.PlayerInfo pc, out bool canUse, out bool couldUse) + public override float CanUse(NetworkedPlayerInfo pc, out bool canUse, out bool couldUse) { canUse = false; couldUse = false; diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeGameSettingMenu.cs b/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeGameSettingMenu.cs new file mode 100644 index 000000000..75aeb1995 --- /dev/null +++ b/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeGameSettingMenu.cs @@ -0,0 +1,236 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using UnityEngine; + +using Il2CppInterop.Runtime.Attributes; + +using ExtremeRoles.Extension.UnityEvents; +using ExtremeRoles.Module.CustomMonoBehaviour.View; +using ExtremeRoles.Helper; + + +#nullable enable + +namespace ExtremeRoles.Module.CustomMonoBehaviour; + +[Il2CppRegister] +public sealed class ExtremeGameSettingMenu(IntPtr ptr) : MonoBehaviour(ptr) +{ + private readonly Dictionary allMenu = new(8); + private readonly Dictionary allButton = new(8); + + private GameSettingMenu? menu; + + public sealed class Initializer : IDisposable + { + private const float yScale = 0.85f; + + public PassiveButton NewTagButton + { + get + { + var newButton = Instantiate(this.buttonPrefab); + + newButton.transform.SetParent(this.buttonPrefab.transform.parent); + newButton.transform.localPosition = this.buttonPrefab.transform.localPosition; + newButton.transform.localScale = new Vector3(0.35f, 0.7f, 1.0f); + rescaleText(newButton, 0.7f, 0.4f); + + if (newButton.buttonText.TryGetComponent(out var text)) + { + Destroy(text); + } + + return newButton; + } + } + + public ExtremeGameOptionsMenuView NewMenu + { + get + { + var newMenu = Instantiate(this.tagPrefab); + newMenu.transform.SetParent(this.tagPrefab.transform.parent); + newMenu.transform.localPosition = this.tagPrefab.transform.localPosition; + return newMenu.gameObject.AddComponent(); + } + } + public GameSettingMenu Menu { get; } + public Vector3 FirstButtonPos { get; } = new Vector3(-3.875f, -2.5f, -2.0f); + + private readonly PassiveButton buttonPrefab; + public readonly GameOptionsMenu tagPrefab; + + public Initializer(GameSettingMenu menu) + { + + this.Menu = menu; + /* まずは画像とか文章を変える */ + var whatIsThis = menu.MenuDescriptionText.transform.parent.transform; + whatIsThis.localPosition = new Vector3(-0.5f, 2.0f, -1.0f); + + var infoImage = whatIsThis.GetChild(0); + infoImage.localPosition = new Vector3(-2.0f, 0.25f, -1.0f); + if (infoImage.TryGetComponent(out var spriteRenderer)) + { + spriteRenderer.flipX = true; + } + + /* ボタン部分調整 */ + var buttonGroup = menu.GamePresetsButton.transform.parent; + buttonGroup.localPosition = new Vector3(0.0f, 1.37f, -1.0f); + buttonGroup.localScale = new Vector3(1.0f, 0.85f, 1.0f); + + rescaleText(menu.GamePresetsButton, yScale); + rescaleText(menu.GameSettingsButton, yScale); + rescaleText(menu.RoleSettingsButton, yScale); + + this.buttonPrefab = Instantiate(menu.GameSettingsButton); + this.buttonPrefab.transform.SetParent(menu.GameSettingsButton.transform.parent); + this.buttonPrefab.transform.localPosition = this.FirstButtonPos; + this.buttonPrefab.transform.localScale = new Vector3(0.4f, 0.8f, 1.0f); + rescaleText(this.buttonPrefab, 0.8f, 0.4f); + this.buttonPrefab.OnClick.RemoveAllListeners(); + this.buttonPrefab.OnMouseOver.RemoveAllListeners(); + + + this.tagPrefab = Instantiate(menu.GameSettingsTab); + this.tagPrefab.transform.SetParent(menu.GameSettingsTab.transform.parent); + this.tagPrefab.transform.localPosition = menu.GameSettingsTab.transform.localPosition; + } + + private static void rescaleText(in PassiveButton button, in float xScale, float yScale = 1.0f) + { + var scale = button.buttonText.transform.localScale; + button.buttonText.transform.localScale = new Vector3(scale.x * xScale, scale.y * yScale, scale.z); + } + + + public void Dispose() + { + Destroy(this.buttonPrefab.gameObject); + Destroy(this.tagPrefab.gameObject); + } + } + + [HideFromIl2Cpp] + public void Initialize(in Initializer initialize) + { + this.menu = initialize.Menu; + + var firstPos = initialize.FirstButtonPos; + int xIndex = 0; + int yIndex = 0; + + foreach (var (tab, tabContainer) in OptionManager.Instance) + { + var menu = initialize.NewMenu; + var button = initialize.NewTagButton; + + menu.AllCategory = tabContainer.Category.ToArray(); + + button.gameObject.name = $"{tab}Button"; + button.ChangeButtonText(Translation.GetString(string.Format( + "ExtremeRoles_{0}Settings", tab))); + var text = button.buttonText; + text.transform.localScale = new Vector3(1.3f, 1.1f, 1.0f); + text.transform.localPosition = new Vector3(-0.5f, 0.0f, -1.0f); + text.fontSize = text.fontSizeMin = text.fontSizeMax = 2.0f; + + menu.gameObject.name = $"{tab}Menu"; + + button.transform.localPosition = new Vector3( + firstPos.x + xIndex * 1.5f, + firstPos.y - yIndex * 0.5f, + firstPos.z); + xIndex++; + if (xIndex == 2) + { + xIndex = 0; + yIndex++; + } + + button.OnClick.AddListener(() => + { + this.SwitchTab(tab, false); + }); + button.OnMouseOver.AddListener(() => + { + this.SwitchTab(tab, true); + }); + + this.allMenu.Add(tab, menu); + this.allButton.Add(tab, button); + }; + } + + public void SwitchTab(OptionTab tab, bool isPreviewOnly) + { + if (!this.allMenu.TryGetValue(tab, out var targetMenu) || + !this.allButton.TryGetValue(tab, out var targetButton)) + { + return; + } + + if (this.menu != null) + { + if (previewIfCond(isPreviewOnly)) + { + this.menu.GamePresetsButton.SelectButton(false); + this.menu.GameSettingsButton.SelectButton(false); + this.menu.RoleSettingsButton.SelectButton(false); + + this.menu.PresetsTab.gameObject.SetActive(false); + this.menu.GameSettingsTab.gameObject.SetActive(false); + this.menu.RoleSettingsTab.gameObject.SetActive(false); + + foreach (var menu in this.allMenu.Values) + { + menu.gameObject.SetActive(false); + } + + this.menu.MenuDescriptionText.text = + Translation.GetString($"ExR_{tab}SettingsDescription"); + + unselectButton(); + targetMenu.gameObject.SetActive(true); + } + + if (isPreviewOnly) + { + this.menu.ToggleLeftSideDarkener(false); + this.menu.ToggleRightSideDarkener(true); + return; + } + this.menu.ToggleLeftSideDarkener(true); + this.menu.ToggleRightSideDarkener(false); + } + + targetButton.SelectButton(true); + targetMenu.Open(); + } + public void SwitchTabPrefix(bool previewOnly) + { + if (previewIfCond(previewOnly)) + { + unselectButton(); + foreach (var menu in this.allMenu.Values) + { + menu.gameObject.SetActive(false); + } + } + } + + private void unselectButton() + { + foreach (var button in this.allButton.Values) + { + button.SelectButton(false); + } + } + + private static bool previewIfCond(bool isPreviewOnly) + => (isPreviewOnly && Controller.currentTouchType == Controller.TouchType.Joystick) || !isPreviewOnly; +} diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeOptionMenu.cs b/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeOptionMenu.cs deleted file mode 100644 index 8b3f5bebc..000000000 --- a/ExtremeRoles/Module/CustomMonoBehaviour/ExtremeOptionMenu.cs +++ /dev/null @@ -1,251 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -using AmongUs.GameOptions; - -using UnityEngine; -using UnityEngine.Events; - -using Il2CppInterop.Runtime.Attributes; - -using ExtremeRoles.Helper; -using ExtremeRoles.Extension.UnityEvents; -using ExtremeRoles.Resources; -using ExtremeRoles.Compat; -using ExtremeRoles.GameMode; -using ExtremeRoles.GameMode.RoleSelector; -using ExtremeRoles.GameMode.Option.ShipGlobal; -using ExtremeRoles.Module.CustomMonoBehaviour.UIPart; -using ExtremeRoles.Module.RoleAssign; - -namespace ExtremeRoles.Module.CustomMonoBehaviour; - -[Il2CppRegister] -public sealed class ExtremeOptionMenu : MonoBehaviour -{ - private Dictionary allMenu = new Dictionary(); - - private SimpleButton button; - private GameSettingMenu menu; - private GameObject settingMenuTemplate; - private GameObject tabTemplate; - - private const string templateName = "menuTemplate"; - - public ExtremeOptionMenu(IntPtr ptr) : base(ptr) { } - - public void Awake() - { - this.allMenu.Clear(); - - this.menu = base.gameObject.GetComponent(); - - // ForceEnable Tabs for fixing HideNSeekOptions turnoff tabs - this.menu.Tabs.SetActive(true); - - createRoleAssignFilterButton(); - - setupTemplate(); - setupOptionMenu(); - - recreateTabButtonFunction(); - retransformTabButton(); - } - - public void OnDisable() - { - this.menu.RegularGameSettings.SetActive(false); - this.menu.RolesSettings.gameObject.SetActive(false); - this.menu.HideNSeekSettings.SetActive(false); - - this.menu.GameSettingsHightlight.enabled = false; - this.menu.RolesSettingsHightlight.enabled = false; - - foreach (OptionMenuTab menu in this.allMenu.Values) - { - menu.SetActive(false); - } - } - - private void createRoleAssignFilterButton() - { - this.button = Loader.CreateSimpleButton(this.menu.transform); - this.button.Layer = this.menu.gameObject.layer; - this.button.Scale = new Vector3(0.625f, 0.3f, 1.0f); - this.button.gameObject.transform.localPosition = new Vector3(2.25f, 1.775f); - this.button.Text.text = Translation.GetString("RoleAssignFilter"); - this.button.Text.fontSize = - this.button.Text.fontSizeMax = - this.button.Text.fontSizeMin = 1.9f; - this.button.ClickedEvent.AddListener( - () => - { - RoleAssignFilter.Instance.OpenEditor(base.gameObject); - }); - } - - private OptionMenuTab createMenu(OptionTab tab, StringOption optionTemplate) - { - OptionMenuTab menu = OptionMenuTab.Create(tab, this.settingMenuTemplate); - menu.CreateTabButton(this.tabTemplate, this.menu.Tabs); - menu.SetOptionTemplate(optionTemplate); - - return menu; - } - - [HideFromIl2Cpp] - private void reconstructButton( - GameObject tabButtonObject, Action newAction) - { - PassiveButton button = tabButtonObject.GetComponentInChildren(); - button.OnClick.RemoveAllPersistentAndListeners(); - button.OnClick.AddListener( - () => - { - - this.button.gameObject.SetActive(true); - - this.menu.RegularGameSettings.SetActive(false); - this.menu.RolesSettings.gameObject.SetActive(false); - this.menu.HideNSeekSettings.SetActive(false); - - this.menu.GameSettingsHightlight.enabled = false; - this.menu.RolesSettingsHightlight.enabled = false; - - foreach (OptionMenuTab menu in this.allMenu.Values) - { - menu.SetActive(false); - } - }); - button.OnClick.AddListener(newAction); - } - - public void recreateTabButtonFunction() - { - // 基本ゲーム設定 - switch (ExtremeGameModeManager.Instance.CurrentGameMode) - { - case GameModes.Normal: - case GameModes.NormalFools: - reconstructButton( - this.tabTemplate, - () => - { - this.menu.RegularGameSettings.SetActive(true); - this.menu.GameSettingsHightlight.enabled = true; - }); - - reconstructButton( - this.menu.Tabs.transform.FindChild("RoleTab").gameObject, - () => - { - this.button.gameObject.SetActive(false); - this.menu.RolesSettings.gameObject.SetActive(true); - this.menu.RolesSettingsHightlight.enabled = true; - }); - break; - case GameModes.HideNSeek: - case GameModes.SeekFools: - reconstructButton( - this.tabTemplate, - () => - { - this.menu.HideNSeekSettings.SetActive(true); - this.menu.GameSettingsHightlight.enabled = true; - }); - this.menu.Tabs.transform.FindChild("RoleTab").gameObject.SetActive(false); - break; - default: - break; - }; - - foreach (OptionMenuTab menu in this.allMenu.Values) - { - reconstructButton( - menu.Tab, - () => - { - menu.SetActive(true); - }); - } - } - - private void retransformTabButton() - { - AspectSpacer spacer = this.menu.Tabs.GetComponent(); - spacer.xSpacing = 0.77f; - // ワイドアスペクト解像度対応処理(なんでここ無効になってんだ・・・・) - spacer.spaceWiderAspectRatios = true; - spacer.OnEnable(); - - this.menu.Tabs.transform.localPosition = new Vector3(-0.465f, 0.0f, 0.0f); - } - - private void setupTemplate() - { - this.tabTemplate = this.menu.Tabs.transform.FindChild("GameTab").gameObject; - GameObject gameSettingTemplateBase = base.transform.FindChild("Game Settings").gameObject; - this.settingMenuTemplate = createOptionMenuTemplate(gameSettingTemplateBase); - } - - private void setupOptionMenu() - { - var transform = this.menu.AllItems.FirstOrDefault( - x => - { - StringOption strOption = x.GetComponent(); - return strOption != null; - - }); - var stringOptionTemplate = transform.GetComponent(); - if (!stringOptionTemplate) { return; } - - foreach (OptionTab tab in Enum.GetValues(typeof(OptionTab))) - { - this.allMenu.Add(tab, createMenu(tab, stringOptionTemplate)); - } - - var exGmM = ExtremeGameModeManager.Instance; - var shipOption = exGmM.ShipOption; - var roleSelector = exGmM.RoleSelector; - - foreach (var (id, option) in OptionManager.Instance.GetKeyValueAllIOptions()) - { - OptionTab tab = option.Tab; - - if (Enum.IsDefined(typeof(OptionCreator.CommonOptionKey), id) || - roleSelector.IsValidGlobalRoleOptionId((RoleGlobalOption)id) || - tab switch - { - OptionTab.General => - shipOption.IsValidOption(id) || - CompatModManager.Instance.IsIntegrateOption(id), - _ => roleSelector.IsValidRoleOption(option), - }) - { - this.allMenu[tab].AddOption(option); - } - } - } - - private static GameObject createOptionMenuTemplate(GameObject templateBase) - { - GameObject template = Instantiate( - templateBase, templateBase.transform.parent); - GameOptionsMenu menu = template.transform.FindChild( - "GameGroup").FindChild("SliderInner").GetComponent(); - - foreach (OptionBehaviour option in menu.GetComponentsInChildren()) - { - Destroy(option.gameObject); - } - - menu.Children = Array.Empty(); - - template.name = templateName; - template.SetActive(false); - - return template; - } -} diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/FinalSummary.cs b/ExtremeRoles/Module/CustomMonoBehaviour/FinalSummary.cs index dad16bfa2..e5fa6effd 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/FinalSummary.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/FinalSummary.cs @@ -261,7 +261,7 @@ public struct PlayerSummary public PlayerStatus StatusInfo { get; init; } public static PlayerSummary Create( - GameData.PlayerInfo playerInfo, + NetworkedPlayerInfo playerInfo, SingleRoleBase role, GhostRoleBase ghostRole, ExtremeGameResult.TaskInfo taskInfo) diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/GuessBehaviour.cs b/ExtremeRoles/Module/CustomMonoBehaviour/GuessBehaviour.cs index 7a20b6913..2e9b261fb 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/GuessBehaviour.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/GuessBehaviour.cs @@ -25,6 +25,8 @@ public struct RoleInfo RoleTypes.Crewmate, RoleTypes.Scientist, RoleTypes.Engineer, + RoleTypes.Noisemaker, + RoleTypes.Tracker, }; public string GetRoleName() @@ -135,8 +137,13 @@ public string GetRoleName() public void SetTarget(byte playerId) { + var info = GameData.Instance.GetPlayerById(playerId); + if (info == null) + { + return; + } this.playerId = playerId; - this.playerName = GameData.Instance.GetPlayerById(playerId)?.DefaultOutfit.PlayerName; + this.playerName = info.DefaultOutfit.PlayerName; } } } diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/Minigames/ExtremeSpawnSelectorMinigame.cs b/ExtremeRoles/Module/CustomMonoBehaviour/Minigames/ExtremeSpawnSelectorMinigame.cs index 0fba4f1aa..b9a9fad97 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/Minigames/ExtremeSpawnSelectorMinigame.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/Minigames/ExtremeSpawnSelectorMinigame.cs @@ -124,11 +124,11 @@ public override void Begin(PlayerTask? task) if (GameManager.Instance != null && GameManager.Instance.IsNormal()) { - foreach (GameData.PlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (playerInfo != null && playerInfo.Object != null && - playerInfo.Object.TryGetComponent(out DummyBehaviour dummy) && + playerInfo.Object.TryGetComponent(out var dummy) && !dummy.enabled && !playerInfo.Disconnected) { diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/OptionMenuTab.cs b/ExtremeRoles/Module/CustomMonoBehaviour/OptionMenuTab.cs deleted file mode 100644 index 893d0aa85..000000000 --- a/ExtremeRoles/Module/CustomMonoBehaviour/OptionMenuTab.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -using UnityEngine; -using TMPro; - -using Il2CppInterop.Runtime.Attributes; - -using ExtremeRoles.Resources; - -namespace ExtremeRoles.Module.CustomMonoBehaviour; - -[Il2CppRegister] -public sealed class OptionMenuTab : MonoBehaviour -{ - public const string StringOptionName = "ExROptionId_"; - public GameObject Tab { get; private set; } - - private SpriteRenderer tabHighLight; - private GameOptionsMenu menuBody; - private TextMeshPro tabName; - private Scroller scroller; - private StringOption template; - - private OptionTab tabType; - private List useOption = new List(); - - private Memory> childrenBody; - - private float blockTimer = -10.0f; - - private const float posOffsetInit = 2.75f; - private const string menuNameTemplate = "ExtremeRoles_{0}Settings"; - - public OptionMenuTab(IntPtr ptr) : base(ptr) { } - - public static OptionMenuTab Create(OptionTab tab, GameObject template) - { - GameObject obj = Instantiate( - template, template.transform.parent); - - OptionMenuTab menu = obj.AddComponent(); - Transform gameGroupTrans = obj.transform.FindChild("GameGroup"); - - menu.menuBody = gameGroupTrans.FindChild("SliderInner").GetComponent(); - menu.scroller = gameGroupTrans.GetComponent(); - menu.tabType = tab; - menu.useOption.Clear(); - menu.tabName = gameGroupTrans.FindChild("Text").GetComponent(); - - string name = string.Format(menuNameTemplate, tab.ToString()); - - obj.name = name; - menu.menuBody.name = $"{name}_menu"; - - // どうも中身を消してるテンプレートから作ってるのに生き残りが居るらしい - foreach (OptionBehaviour option in menu.menuBody.GetComponentsInChildren()) - { - Destroy(option.gameObject); - } - menu.menuBody.Children = Array.Empty(); - - return menu; - } - - public void OnEnable() - { - if (this.menuBody.Children.Length != 0) { return; } - - this.menuBody.Children = new OptionBehaviour[this.useOption.Count]; - - for (int index = 0; index < this.menuBody.Children.Length; ++index) - { - IOptionInfo option = this.useOption[index]; - - if (option.Body != null) { continue; } - - StringOption stringOption = Instantiate( - this.template, this.menuBody.transform); - stringOption.OnValueChanged = new Action((o) => { }); - stringOption.TitleText.text = option.GetTranslatedName(); - stringOption.Value = stringOption.oldValue = option.CurSelection; - stringOption.ValueText.text = option.GetTranslatedValue(); - stringOption.gameObject.name = $"{StringOptionName}{option.Id}"; - stringOption.gameObject.SetActive(true); - - this.menuBody.Children[index] = stringOption; - option.SetOptionBehaviour(stringOption); - - this.blockTimer = 1.0f; - } - - this.childrenBody = this.useOption.Zip(this.menuBody.Children, ValueTuple.Create).ToArray(); - } - - public void Start() - { - this.tabName.SetText( - Helper.Translation.GetString(this.gameObject.name)); - } - - public void FixedUpdate() - { - - this.blockTimer += Time.fixedDeltaTime; - int itemLength = this.menuBody.Children.Length; - - if (itemLength == 0 || this.blockTimer < 0.1f) { return; } - - this.blockTimer = 0.0f; - - float itemOffset = (float)itemLength; - float posOffset = posOffsetInit; - - foreach (var (option, optionBody) in this.childrenBody.Span) - { - if (optionBody == null) { continue; } - - bool enabled = option.IsActive(); - - optionBody.gameObject.SetActive(enabled); - - if (enabled) - { - bool isHeader = option.IsHeader; - posOffset -= isHeader ? 0.75f : 0.5f; - optionBody.transform.localPosition = new Vector3( - optionBody.transform.localPosition.x, posOffset, - optionBody.transform.localPosition.z); - - if (isHeader) - { - itemOffset += 0.5f; - } - } - else - { - itemOffset--; - } - } - - this.scroller.ContentYBounds.max = -4.0f + itemOffset * 0.5f; - } - - [HideFromIl2Cpp] - public void AddOption(IOptionInfo option) - { - this.useOption.Add(option); - } - - public void CreateTabButton(GameObject template, GameObject parent) - { - GameObject tabParent = Instantiate(template, parent.transform); - tabParent.name = $"{this.tabType}_Tab"; - - // Tabの構造はGameTab => ColorButton(こいつだけ)なので一個だけ取得 - Transform colorButtonTrans = tabParent.transform.GetChild(0); - - this.Tab = colorButtonTrans.gameObject; - this.tabHighLight = colorButtonTrans.FindChild( - "Tab Background").GetComponentInChildren(); - - colorButtonTrans.FindChild("Icon").GetComponent().sprite = - Loader.CreateSpriteFromResources( - string.Format(Path.TabImagePathFormat, this.tabType), 150f); - this.tabHighLight.enabled = false; - } - - public void SetActive(bool activate) - { - this.gameObject.SetActive(activate); - this.tabHighLight.enabled = activate; - } - public void SetOptionTemplate(StringOption option) - { - this.template = option; - } -} diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/Portal.cs b/ExtremeRoles/Module/CustomMonoBehaviour/Portal.cs index 07a109caa..cb5da15bb 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/Portal.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/Portal.cs @@ -79,7 +79,7 @@ public void SetTarget(Vector2 pos) } public float CanUse( - GameData.PlayerInfo pc, out bool canUse, out bool couldUse) + NetworkedPlayerInfo pc, out bool canUse, out bool couldUse) { float num = this.linkPortal && this.timer <= 0.0f ? Vector2.Distance( diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/TeleporterPortalPart.cs b/ExtremeRoles/Module/CustomMonoBehaviour/TeleporterPortalPart.cs index 39aae17c5..10c4f5c8b 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/TeleporterPortalPart.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/TeleporterPortalPart.cs @@ -54,7 +54,7 @@ public void Awake() } public float CanUse( - GameData.PlayerInfo pc, out bool canUse, out bool couldUse) + NetworkedPlayerInfo pc, out bool canUse, out bool couldUse) { if (!tryGetTeleporter(out var _)) { diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/TimeParts.cs b/ExtremeRoles/Module/CustomMonoBehaviour/TimeParts.cs index 3b438ea2a..d285b1b62 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/TimeParts.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/TimeParts.cs @@ -61,7 +61,7 @@ public void Awake() } public float CanUse( - GameData.PlayerInfo pc, out bool canUse, out bool couldUse) + NetworkedPlayerInfo pc, out bool canUse, out bool couldUse) { float num = !this.used ? Vector2.Distance( pc.Object.GetTruePosition(), diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/TorchBehavior.cs b/ExtremeRoles/Module/CustomMonoBehaviour/TorchBehavior.cs index dcd2ef7fa..008900c45 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/TorchBehavior.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/TorchBehavior.cs @@ -73,7 +73,7 @@ public void OnDestroy() } public float CanUse( - GameData.PlayerInfo pc, out bool canUse, out bool couldUse) + NetworkedPlayerInfo pc, out bool canUse, out bool couldUse) { float num = Vector2.Distance( pc.Object.GetTruePosition(), diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/View/AddRoleMenuView.cs b/ExtremeRoles/Module/CustomMonoBehaviour/View/AddRoleMenuView.cs index 70f5a63c7..c651ad1a6 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/View/AddRoleMenuView.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/View/AddRoleMenuView.cs @@ -28,7 +28,7 @@ public sealed class AddRoleMenuView : MonoBehaviour private ButtonWrapper buttonPrefab; private GridLayoutGroup layout; - private Dictionary allButton; + private readonly Dictionary allButton = new (); public AddRoleMenuView(IntPtr ptr) : base(ptr) { } #pragma warning restore CS8618 @@ -62,11 +62,12 @@ public void UpdateView( { if (this.layout.rectChildren.Count == 0) { - this.allButton = new Dictionary(); + this.allButton.Clear(); // メニューを作る foreach (int id in model.Id) { - this.allButton.Add(id, Instantiate(this.buttonPrefab, this.layout.transform)); + var button = Instantiate(this.buttonPrefab, this.layout.transform); + this.allButton.Add(id, button); } } diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeGameOptionsMenuView.cs b/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeGameOptionsMenuView.cs new file mode 100644 index 000000000..be701d243 --- /dev/null +++ b/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeGameOptionsMenuView.cs @@ -0,0 +1,317 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using UnityEngine; + +using Il2CppUiElementList = Il2CppSystem.Collections.Generic.List; + +using Il2CppInterop.Runtime.Attributes; + +using ExtremeRoles.Extension.UnityEvents; +using ExtremeRoles.Extension.Option; +using ExtremeRoles.GameMode; +using ExtremeRoles.Module.CustomOption.View; +using ExtremeRoles.Module.CustomMonoBehaviour.UIPart; +using ExtremeRoles.Helper; +using ExtremeRoles.Module.RoleAssign; +using ExtremeRoles.Resources; + +#nullable enable + +namespace ExtremeRoles.Module.CustomMonoBehaviour.View; + +[Il2CppRegister] +public sealed class ExtremeGameOptionsMenuView(IntPtr ptr) : MonoBehaviour(ptr) +{ + [HideFromIl2Cpp] + public OptionCategory[]? AllCategory { private get; set; } + + private readonly List> optionGroupViewObject = new(); + private readonly Il2CppUiElementList allUiElement = new(); + private const float initY = 2.0f; + + private Scroller? scroller; + private UiElement? backButton; + private UiElement? firstButton; + + private Transform? settingsContainer; + private CategoryHeaderMasked? categoryHeaderOrigin; + private ExtremeOptionView? optionPrefab; + private SimpleButton? button; + + private Collider2D? buttonClickMask; + private const float blockTime = 0.25f; + private float blockTimer = blockTime; + + public void Awake() + { + if (!base.TryGetComponent(out var menu)) + { + return; + } + menu.MaskBg.material.SetInt(PlayerMaterial.MaskLayer, 20); + menu.MaskArea.material.SetInt(PlayerMaterial.MaskLayer, 20); + + this.scroller = menu.scrollBar; + this.backButton = menu.BackButton; + this.settingsContainer = menu.settingsContainer; + this.categoryHeaderOrigin = menu.categoryHeaderOrigin; + + this.optionPrefab = Instantiate(menu.stringOptionOrigin).gameObject.AddComponent(); + this.optionPrefab.gameObject.SetActive(false); + + this.buttonClickMask = menu.ButtonClickMask; + + Destroy(menu.MapPicker.gameObject); + foreach (var child in menu.Children) + { + Destroy(child.gameObject); + } + var allCate = menu.settingsContainer.GetComponentsInChildren(); + foreach (var cate in allCate) + { + Destroy(cate.gameObject); + } + menu.Children.Clear(); + Destroy(menu); + + this.button = Loader.CreateSimpleButton(menu.transform); + this.button.Layer = menu.gameObject.layer; + this.button.Scale = new Vector3(0.625f, 0.3f, 1.0f); + this.button.gameObject.transform.localPosition = new Vector3(4.0f, 0.575f); + this.button.Text.text = Translation.GetString("RoleAssignFilter"); + this.button.Text.fontSize = + this.button.Text.fontSizeMax = + this.button.Text.fontSizeMin = 1.9f; + this.button.ClickedEvent.AddListener( + () => + { + RoleAssignFilter.Instance.OpenEditor( + base.transform.parent.parent.gameObject); + }); + } + + public void FixedUpdate() + { + if (this.AllCategory is null) + { + return; + } + + if (this.blockTimer >= 0.0f) + { + this.blockTimer -= Time.fixedDeltaTime; + return; + } + + this.resetTimer(); + bool isRefresh = false; + foreach (var cat in this.AllCategory) + { + isRefresh = isRefresh || cat.IsDirty; + cat.IsDirty = false; + } + if (isRefresh) + { + this.Refresh(); + } + } + + public void Refresh() + { + if (this.scroller == null || + this.AllCategory is null || + this.AllCategory.Length == 0) + { + return; + } + + float yPos = initY; + foreach (var (catego, groupViewObj) in Enumerable.Zip(this.AllCategory, this.optionGroupViewObject)) + { + if (!( + catego.Tab is OptionTab.General || + ExtremeGameModeManager.Instance.RoleSelector.IsValidCategory(catego.Id) + )) + { + continue; + } + + + var categoObj = groupViewObj.Category; + if (catego.Color.HasValue) + { + categoObj.Background.color = catego.Color.Value; + } + categoObj.transform.localPosition = new Vector3(-0.903f, yPos, -2f); + categoObj.ReplaceExRText(catego.TransedName, 20); + + yPos -= 0.63f; + + foreach (var (option, optionObj) in Enumerable.Zip(catego.Options, groupViewObj.Options)) + { + bool isActive = option.IsActiveAndEnable; + + optionObj.gameObject.SetActive(isActive); + if (!isActive) + { + continue; + } + + optionObj.transform.localPosition = new Vector3(1.25f, yPos, -2f); + optionObj.Refresh(); + yPos -= 0.45f; + } + } + this.scroller.SetYBoundsMax(-yPos - 1.65f); + } + + public void OnEnable() + { + if (this.optionGroupViewObject.Count == 0) + { + var allOpt = this.initializeOption(); + this.initializeUiElement(); + this.initializeControllerNavigation(allOpt); + } + this.Refresh(); + } + + public void OnDisable() + { + ControllerManager.Instance.CloseOverlayMenu(base.name); + } + + public void Open() + { + ControllerManager.Instance.OpenOverlayMenu(base.name, this.backButton, this.firstButton, this.allUiElement, false); + } + + [HideFromIl2Cpp] + private IReadOnlyList initializeOption() + { + var result = new List(); + if (this.categoryHeaderOrigin == null || + this.optionPrefab == null || + this.AllCategory is null) + { + return result; + } + + this.optionGroupViewObject.Capacity = this.AllCategory.Length; + foreach (var catego in this.AllCategory) + { + var categoryHeaderMasked = Instantiate( + this.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, + this.settingsContainer); + categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f; + + var optionGroupViewObject = new OptionGroupViewObject( + categoryHeaderMasked, catego.Count); + + foreach (var option in catego.Options) + { + var opt = Instantiate( + this.optionPrefab, Vector3.zero, Quaternion.identity, this.settingsContainer); + opt.SetClickMask(this.buttonClickMask); + opt.SetMaterialLayer(20); + + opt.OptionModel = option; + opt.OptionCategoryModel = catego; + + optionGroupViewObject.Options.Add(opt); + result.Add(opt); + } + this.optionGroupViewObject.Add(optionGroupViewObject); + } + + return result; + } + + private void initializeUiElement() + { + if (this.scroller == null) + { + return; + } + + var arr = this.scroller.GetComponentsInChildren(); + foreach (var element in arr) + { + this.allUiElement.Add(element); + } + this.firstButton = this.allUiElement[0]; + } + + [HideFromIl2Cpp] + private void initializeControllerNavigation(in IReadOnlyList allOpt) + { + for (int i = 0; i < allOpt.Count; i++) + { + OptionBehaviour optionBehaviour = allOpt[i]; + if (!optionBehaviour.gameObject.activeSelf) + { + continue; + } + UiElement[]? array = null; + UiElement[]? array2 = null; + if (i - 1 >= 0) + { + array = allOpt[i - 1].GetComponentsInChildren(true); + } + if (i + 1 < allOpt.Count) + { + array2 = allOpt[i + 1].GetComponentsInChildren(true); + } + UiElement[] componentsInChildren = optionBehaviour.GetComponentsInChildren(true); + for (int j = 0; j < componentsInChildren.Length; j++) + { + var nav = componentsInChildren[j].ControllerNav; + nav.mode = ControllerNavigation.Mode.Explicit; + if (array != null && array.Length != 0) + { + if (i == 1) + { + nav.selectOnUp = array[0]; + } + else if (j < array.Length) + { + nav.selectOnUp = array[j]; + } + else + { + nav.selectOnUp = array[0]; + } + } + else + { + nav.selectOnUp = null; + } + if (array2 != null && array2.Length != 0) + { + if (i == 0) + { + nav.selectOnDown = array2[0]; + } + else if (j < array2.Length) + { + nav.selectOnDown = array2[j]; + } + else + { + nav.selectOnDown = array2[0]; + } + } + else + { + nav.selectOnDown = null; + } + } + } + } + private void resetTimer() + { + this.blockTimer = blockTime; + } +} diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeLobbyViewSettingsTabView.cs b/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeLobbyViewSettingsTabView.cs new file mode 100644 index 000000000..496a8dc59 --- /dev/null +++ b/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeLobbyViewSettingsTabView.cs @@ -0,0 +1,283 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using UnityEngine; + +using ExtremeRoles.Extension.Option; +using ExtremeRoles.Extension.UnityEvents; +using ExtremeRoles.Helper; +using ExtremeRoles.Module.CustomOption.View; +using ExtremeRoles.GameMode; +using Il2CppInterop.Runtime.Attributes; + + +#nullable enable +namespace ExtremeRoles.Module.CustomMonoBehaviour.View; + +[Il2CppRegister] +public sealed class ExtremeLobbyViewSettingsTabView(IntPtr ptr) : MonoBehaviour(ptr) +{ + private LobbyViewSettingsPane? vanillaSettings; + + private const float initPos = 1.44f; + private readonly List> optionGroupViewObject = new(); + private readonly Dictionary allButton = new(8); + + private const float blockTime = 0.25f; + private float blockTimer = blockTime; + private OptionTab curTab; + + public void Awake() + { + if (!gameObject.TryGetComponent(out var lobby)) + { + return; + } + + vanillaSettings = lobby; + vanillaSettings.gameModeText.transform.localPosition = new Vector3(-4.0f, 3.5f, -2.0f); + + var taskButton = vanillaSettings.taskTabButton; + + taskButton.gameObject.SetActive(true); + + List allButton = [ taskButton ]; + + if (vanillaSettings.rolesTabButton.gameObject.activeSelf) + { + allButton.Add(vanillaSettings.rolesTabButton); + } + + foreach (var tab in Enum.GetValues()) + { + var newButton = Instantiate(taskButton, taskButton.transform.parent); + if (newButton.buttonText.TryGetComponent(out var tmp)) + { + Destroy(tmp); + } + newButton.ChangeButtonText(Translation.GetString(string.Format( + "ExtremeRoles_{0}Settings", tab))); + newButton.OnClick.RemoveAllListeners(); + newButton.OnClick.AddListener(() => + { + this.changeExRTab(tab); + }); + + this.allButton.Add(tab, newButton); + allButton.Add(newButton); + } + + int x = -1; + int y = -1; + + foreach (var (index, button) in allButton.Select((value, index) => (index, value))) + { + if (index % 5 == 0) + { + ++y; + x = 0; + } + else + { + ++x; + } + + button.transform.localScale = new Vector3(0.65f, 1.35f, 1.0f); + button.buttonText.transform.localPosition = new Vector3(-0.85f, 0.05f, -2.0f); + button.buttonText.transform.localScale = new Vector3(1.5f, 0.75f, 1.0f); + button.transform.localPosition = new Vector3( + -5.75f + (x * 2.5f), + 2.6f - (y * 1.1f), + 0.0f); + + } + } + + public void FixedUpdate() + { + if (!( + this.allButton.TryGetValue(this.curTab, out var button) && + button != null && + button.selected + )) + { + return; + } + + if (blockTimer >= 0.0f || + !OptionManager.Instance.TryGetTab(this.curTab, out var container)) + { + blockTimer -= Time.fixedDeltaTime; + return; + } + + resetTimer(); + bool isRefresh = false; + foreach (var cat in container.Category) + { + isRefresh = isRefresh || cat.IsDirty; + cat.IsDirty = false; + } + if (isRefresh) + { + updateTextAndPos(this.curTab); + } + } + + public void ChangeTabPostfix() + { + foreach (var button in this.allButton.Values) + { + button.SelectButton(false); + } + } + + [HideFromIl2Cpp] + private void changeExRTab(OptionTab tab) + { + if (vanillaSettings == null) + { + return; + } + + vanillaSettings.rolesTabButton.SelectButton(false); + vanillaSettings.taskTabButton.SelectButton(false); + + foreach (var button in this.allButton.Values) + { + button.SelectButton(false); + } + + if (!( + this.allButton.TryGetValue(tab, out var targetButton) && + targetButton != null && + OptionManager.Instance.TryGetTab(tab, out var container) + )) + { + return; + } + + targetButton.SelectButton(true); + + foreach (var obj in vanillaSettings.settingsInfo) + { + Destroy(obj); + } + + vanillaSettings.settingsInfo.Clear(); + optionGroupViewObject.Clear(); + optionGroupViewObject.Capacity = container.Count; + + foreach (var group in container.Category) + { + var categoryHeaderMasked = Instantiate( + vanillaSettings.categoryHeaderOrigin); + categoryHeaderMasked.transform.SetParent( + vanillaSettings.settingsContainer); + categoryHeaderMasked.transform.localScale = Vector3.one; + vanillaSettings.settingsInfo.Add(categoryHeaderMasked.gameObject); + + var groupViewObj = new OptionGroupViewObject( + categoryHeaderMasked, group.Count); + foreach (var option in group.Options) + { + ViewSettingsInfoPanel viewSettingsInfoPanel = Instantiate( + vanillaSettings.infoPanelOrigin); + viewSettingsInfoPanel.transform.SetParent( + vanillaSettings.settingsContainer); + viewSettingsInfoPanel.transform.localScale = Vector3.one; + vanillaSettings.settingsInfo.Add(viewSettingsInfoPanel.gameObject); + + groupViewObj.Options.Add(viewSettingsInfoPanel); + } + optionGroupViewObject.Add(groupViewObj); + } + + updateTextAndPos(tab); + + this.curTab = tab; + } + + [HideFromIl2Cpp] + private void updateTextAndPos(OptionTab tab) + { + if (vanillaSettings == null || + !OptionManager.Instance.TryGetTab(tab, out var container)) + { + return; + } + + float yPos = initPos; + + foreach (var (catego, optionGroupView) in container.Category.Zip(optionGroupViewObject)) + { + if (!( + tab is OptionTab.General || + ExtremeGameModeManager.Instance.RoleSelector.IsValidCategory(catego.Id) + )) + { + continue; + } + + var category = optionGroupView.Category; + if (catego.Color.HasValue) + { + category.Background.color = catego.Color.Value; + } + category.transform.localPosition = new Vector3(-9.77f, yPos, -2f); + category.ReplaceExRText(catego.TransedName, 61); + + yPos -= 0.85f; + + int activeIndex = 0; + foreach (var (option, optionView) in catego.Options.Zip(optionGroupView.Options)) + { + bool isActive = option.IsActiveAndEnable; + + optionView.gameObject.SetActive(isActive); + if (!isActive) + { + continue; + } + setInfo(optionView, option.Title, option.ValueString); + float x; + if (activeIndex % 2 == 0) + { + x = -8.95f; + if (activeIndex > 0) + { + yPos -= 0.59f; + } + } + else + { + x = -3f; + } + ++activeIndex; + optionView.transform.localPosition = new Vector3(x, yPos, -2f); + } + yPos -= 0.59f; + } + + vanillaSettings.scrollBar.SetYBoundsMax(-yPos); + vanillaSettings.scrollBar.ScrollToTop(); + } + + private static void setInfo( + ViewSettingsInfoPanel panel, + string text, + string valueString) + { + panel.titleText.text = text; + panel.settingText.text = valueString; + panel.disabledBackground.gameObject.SetActive(false); + panel.background.gameObject.SetActive(true); + panel.SetMaskLayer(61); + } + + private void resetTimer() + { + blockTimer = blockTime; + } +} diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeOptionView.cs b/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeOptionView.cs new file mode 100644 index 000000000..0552f6d1d --- /dev/null +++ b/ExtremeRoles/Module/CustomMonoBehaviour/View/ExtremeOptionView.cs @@ -0,0 +1,113 @@ +using System; + +using TMPro; +using UnityEngine; +using Il2CppInterop.Runtime.Attributes; + +using ExtremeRoles.Extension.UnityEvents; +using ExtremeRoles.Module.CustomOption.Interfaces; + +#nullable enable + +namespace ExtremeRoles.Module.CustomMonoBehaviour.View; + +[Il2CppRegister] +public sealed class ExtremeOptionView(IntPtr ptr) : OptionBehaviour(ptr) +{ + private TextMeshPro? titleText; + private TextMeshPro? valueText; + + [HideFromIl2Cpp] + public IOption? OptionModel { private get; set; } + + [HideFromIl2Cpp] + public OptionCategory? OptionCategoryModel { private get; set; } + + public void Awake() + { + if (!base.TryGetComponent(out var opt)) + { + return; + } + + this.titleText = opt.TitleText; + var curSizeDelt = this.titleText.rectTransform.sizeDelta; + this.titleText.rectTransform.sizeDelta = new Vector2(4.25f, curSizeDelt.y); + var curTextpos = this.titleText.transform.localPosition; + this.titleText.transform.localPosition = new Vector3(-1.8f, curTextpos.y, curTextpos.z); + + this.valueText = opt.ValueText; + + if (base.transform.Find("MinusButton (1)").TryGetComponent(out var minus)) + { + minus.OnClick.RemoveAllListeners(); + minus.OnClick.AddListener(this.Decrease); + } + if (base.transform.Find("PlusButton (1)").TryGetComponent(out var plus)) + { + plus.OnClick.RemoveAllListeners(); + plus.OnClick.AddListener(this.Increase); + } + + var imgTrans = base.transform.Find("LabelBackground"); + var curPos = imgTrans.localPosition; + imgTrans.localPosition = new Vector3(-1.915f, curPos.y, curPos.z); + var curScale = imgTrans.localScale; + imgTrans.localScale = new Vector3(1.5f, curScale.y, curScale.z); + + + Destroy(opt); + } + + public void Decrease() + { + if (OptionModel is null || + OptionCategoryModel is null) + { + return; + } + OptionManager.Instance.UpdateToStep(OptionCategoryModel, OptionModel, -1); + } + public void Increase() + { + if (OptionModel is null || + OptionCategoryModel is null) + { + return; + } + OptionManager.Instance.UpdateToStep(OptionCategoryModel, OptionModel, 1); + } + + public void SetMaterialLayer(int maskLayer) + { + var rends = base.GetComponentsInChildren(true); + foreach (var rend in rends) + { + rend.material.SetInt(PlayerMaterial.MaskLayer, maskLayer); + } + + var textMeshPros = base.GetComponentsInChildren(true); + foreach (TextMeshPro textMeshPro in textMeshPros) + { + textMeshPro.fontMaterial.SetFloat("_StencilComp", 3f); + textMeshPro.fontMaterial.SetFloat("_Stencil", maskLayer); + } + } + + public void Refresh() + { + if (this.OptionModel is null) + { + return; + } + + if (this.titleText != null) + { + this.titleText.text = this.OptionModel.Title; + } + if (this.valueText != null) + { + this.valueText.text = this.OptionModel.ValueString; + } + } +} \ No newline at end of file diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/View/InfoOverlayView.cs b/ExtremeRoles/Module/CustomMonoBehaviour/View/InfoOverlayView.cs index 6e98d4bc5..e18ff215f 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/View/InfoOverlayView.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/View/InfoOverlayView.cs @@ -36,7 +36,7 @@ public sealed class InfoOverlayView : MonoBehaviour private ButtonWrapper button; #pragma warning restore CS8618 - private SortedDictionary menu = + private readonly SortedDictionary menu = new SortedDictionary(); public void Awake() diff --git a/ExtremeRoles/Module/CustomMonoBehaviour/VoteAreaInfo.cs b/ExtremeRoles/Module/CustomMonoBehaviour/VoteAreaInfo.cs index 786fea81d..2b5981dbc 100644 --- a/ExtremeRoles/Module/CustomMonoBehaviour/VoteAreaInfo.cs +++ b/ExtremeRoles/Module/CustomMonoBehaviour/VoteAreaInfo.cs @@ -13,6 +13,8 @@ using Il2CppInterop.Runtime.Attributes; + + using CommomSystem = ExtremeRoles.Roles.API.Systems.Common; namespace ExtremeRoles.Module.CustomMonoBehaviour; @@ -137,7 +139,7 @@ private void setTag(SingleRoleBase role) [Il2CppRegister] public sealed class OtherPlayerVoteAreaInfo : VoteAreaInfo { - private GameData.PlayerInfo votePlayerInfo; + private NetworkedPlayerInfo votePlayerInfo; public OtherPlayerVoteAreaInfo(IntPtr ptr) : base(ptr) { } diff --git a/ExtremeRoles/Module/CustomOption/ConfigBinder.cs b/ExtremeRoles/Module/CustomOption/ConfigBinder.cs new file mode 100644 index 000000000..6855f678c --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/ConfigBinder.cs @@ -0,0 +1,34 @@ +using BepInEx.Configuration; + +namespace ExtremeRoles.Module.CustomOption; + +public sealed class ConfigBinder +{ + public int DefaultValue { get; } + public int Value + { + get => config.Value; + set + { + config.Value = value; + } + } + + private ConfigEntry config; + + public ConfigBinder(string name, int @default) + { + DefaultValue = @default; + + config = GetOrCreateConfig(name); + } + + public void Rebind() + { + string key = config.Definition.Key; + config = GetOrCreateConfig(key); + } + private ConfigEntry GetOrCreateConfig(string key) + => ExtremeRolesPlugin.Instance.Config.Bind( + OptionManager.Instance.ConfigPreset, key, DefaultValue); +} diff --git a/ExtremeRoles/Module/CustomOption/Enums.cs b/ExtremeRoles/Module/CustomOption/Enums.cs new file mode 100644 index 000000000..c3e4138ee --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Enums.cs @@ -0,0 +1,29 @@ +namespace ExtremeRoles.Module.CustomOption; + +public enum OptionTab : byte +{ + General, + Combination, + + Crewmate, + GhostCrewmate, + + Impostor, + GhostImpostor, + + Neutral, + GhostNeutral, +} + +public enum OptionUnit : byte +{ + None, + Preset, + Second, + Minute, + Shot, + Multiplier, + Percentage, + ScrewNum, + VoteNum, +} diff --git a/ExtremeRoles/Module/CustomOption/Factory/AutoParentSetOptionCategoryFactory.cs b/ExtremeRoles/Module/CustomOption/Factory/AutoParentSetOptionCategoryFactory.cs new file mode 100644 index 000000000..5b8eb8a6b --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Factory/AutoParentSetOptionCategoryFactory.cs @@ -0,0 +1,281 @@ +using System; + +using UnityEngine; + + + + +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Module.CustomOption.Implemented; +using ExtremeRoles.Roles.API; + + + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Factory; + +public sealed class AutoParentSetOptionCategoryFactory( + in OptionCategoryFactory factory, + in IOption? parent = null) : IDisposable +{ + private IOption? parent = parent; + private readonly OptionCategoryFactory internalFactory = factory; + + public int IdOffset + { + set + { + this.internalFactory.IdOffset = value; + } + } + public string OptionPrefix + { + set + { + this.internalFactory.OptionPrefix = value; + } + } + + public IOption Get(int id) + => this.internalFactory.Get(id); + public IValueOption Get(int id) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.internalFactory.Get(id); + + public BoolCustomOption CreateBoolOption( + T option, + bool defaultValue, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + BoolCustomOption newOption = this.internalFactory.CreateBoolOption( + option, + defaultValue, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public FloatCustomOption CreateBoolOption( + T option, + float defaultValue, + float min, float max, float step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + FloatCustomOption newOption = this.internalFactory.CreateFloatOption( + option, + defaultValue, + min, max, step, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public FloatCustomOption CreateFloatOption( + T option, + float defaultValue, + float min, float max, float step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + FloatCustomOption newOption = this.internalFactory.CreateFloatOption( + option, + defaultValue, + min, max, step, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public FloatDynamicCustomOption CreateFloatDynamicOption( + T option, + float defaultValue, + float min, float step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + float tempMaxValue = 0.0f, + bool ignorePrefix = false) where T : struct, IConvertible + { + FloatDynamicCustomOption newOption = this.internalFactory.CreateFloatDynamicOption( + option, + defaultValue, + min, step, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + tempMaxValue, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public IntCustomOption CreateIntOption( + T option, + int defaultValue, + int min, int max, int step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + IntCustomOption newOption = this.internalFactory.CreateIntOption( + option, + defaultValue, + min, max, step, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public IntDynamicCustomOption CreateIntDynamicOption( + T option, + int defaultValue, + int min, int step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + int tempMaxValue = 0, + bool ignorePrefix = false) where T : struct, IConvertible + { + IntDynamicCustomOption newOption = this.internalFactory.CreateIntDynamicOption( + option, + defaultValue, + min, step, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + tempMaxValue, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public SelectionCustomOption CreateSelectionOption( + T option, + string[] selections, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + SelectionCustomOption newOption = this.internalFactory.CreateSelectionOption( + option, + selections, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public SelectionCustomOption CreateSelectionOption( + T option, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) + where T : struct, IConvertible + where W : struct, Enum + { + SelectionCustomOption newOption = this.internalFactory.CreateSelectionOption( + option, + parent is null ? this.parent : parent, + isHidden, + format, + invert, + ignorePrefix); + + if (this.parent is null) + { + this.parent = newOption; + } + return newOption; + } + + public IntCustomOption Create0To100Percentage10StepOption( + T option, + IOption? parent = null, + bool isHidden = false, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + => CreateIntOption( + option, + 0, 0, 100, 10, + parent, + isHidden, + OptionUnit.Percentage, + invert, + ignorePrefix); + + public void Dispose() + { + this.internalFactory.Dispose(); + } +} diff --git a/ExtremeRoles/Module/CustomOption/Factory/OptionCategoryFactory.cs b/ExtremeRoles/Module/CustomOption/Factory/OptionCategoryFactory.cs new file mode 100644 index 000000000..f09b89084 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Factory/OptionCategoryFactory.cs @@ -0,0 +1,267 @@ +using ExtremeRoles.Helper; + +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; + +using UnityEngine; + + + + +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Module.CustomOption.Implemented; + + + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Factory; + +public class OptionCategoryFactory( + string name, + int groupId, + in Action action, + OptionTab tab = OptionTab.General, + in Color? color = null) : IDisposable +{ + public string Name { get; set; } = name; + public string OptionPrefix { protected get; set; } = name; + + public OptionTab Tab { get; } = tab; + public int IdOffset { protected get; set; } = 0; + protected readonly Regex NameCleaner = new Regex(@"(\|)|(<.*?>)|(\\n)", RegexOptions.Compiled); + + private readonly Color? color = color; + private readonly int groupid = groupId; + private readonly Action registerOption = action; + private readonly OptionPack optionPack = new OptionPack(); + + public IOption Get(int id) + => this.optionPack.Get(id); + public IValueOption Get(int id) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.optionPack.Get(id); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public BoolCustomOption CreateBoolOption( + T option, + bool defaultValue, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + int optionId = GetOptionId(option); + string name = GetOptionName(option, ignorePrefix); + + var opt = new BoolCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public FloatCustomOption CreateFloatOption( + T option, + float defaultValue, + float min, float max, float step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + int optionId = GetOptionId(option); + string name = GetOptionName(option, ignorePrefix); + + var opt = new FloatCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, min, max, step, + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public FloatDynamicCustomOption CreateFloatDynamicOption( + T option, + float defaultValue, + float min, float step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + float tempMaxValue = 0.0f, + bool ignorePrefix = false) where T : struct, IConvertible + { + int optionId = GetOptionId(option); + string name = GetOptionName(option, ignorePrefix); + + var opt = new FloatDynamicCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, min, step, + OptionRelationFactory.Create(parent, invert), + tempMaxValue); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IntCustomOption CreateIntOption( + T option, + int defaultValue, + int min, int max, int step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + int optionId = GetOptionId(option); + string name = GetOptionName(option, ignorePrefix); + + var opt = new IntCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, min, max, step, + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IntDynamicCustomOption CreateIntDynamicOption( + T option, + int defaultValue, + int min, int step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + int tempMaxValue = 0, + bool ignorePrefix = false) where T : struct, IConvertible + { + int optionId = GetOptionId(option); + string name = GetOptionName(option, ignorePrefix); + + var opt = new IntDynamicCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, min, step, + OptionRelationFactory.Create(parent, invert), + tempMaxValue); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectionCustomOption CreateSelectionOption( + T option, + string[] selections, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) where T : struct, IConvertible + { + int optionId = GetOptionId(option); + string name = GetOptionName(option, ignorePrefix); + + var opt = new SelectionCustomOption( + new OptionInfo(optionId, name, format, isHidden), + selections, + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectionCustomOption CreateSelectionOption( + T option, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) + where T : struct, IConvertible + where W : struct, Enum + { + int optionId = GetOptionId(option); + string name = GetOptionName(option, ignorePrefix); + + var opt = SelectionCustomOption.CreateFromEnum( + new OptionInfo(optionId, name, format, isHidden), + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + protected void AddOption( + int id, + IValueOption option) where SelectionType : + struct, IComparable, IConvertible, + IComparable, IEquatable + { + optionPack.AddOption(id, option); + } + + public int GetOptionId(T option) where T : struct, IConvertible + { + enumCheck(option); + return Convert.ToInt32(option) + IdOffset; + } + + protected string GetOptionName(T option, bool ignorePrefix = false) where T : struct, IConvertible + { + string cleanedName = this.NameCleaner.Replace(this.OptionPrefix, string.Empty).Trim(); + + return ignorePrefix ? $"|{cleanedName}|{option}" : $"{cleanedName}{option}"; + } + + protected static string GetColoredOptionName(T option, Color? color) where T : struct, IConvertible + { + string? optionName = option.ToString(); + if (string.IsNullOrEmpty(optionName)) + { + throw new ArgumentException("Can't convert string"); + } + return !color.HasValue ? optionName : Design.ColoedString(color.Value, optionName); + } + + protected static IEnumerable GetEnumString() + { + foreach (object enumValue in Enum.GetValues(typeof(T))) + { + string? valuse = enumValue.ToString(); + if (string.IsNullOrEmpty(valuse)) { continue; } + + yield return valuse; + } + } + + private static void enumCheck(T isEnum) where T : struct, IConvertible + { + if (!typeof(int).IsAssignableFrom(Enum.GetUnderlyingType(typeof(T)))) + { + throw new ArgumentException(nameof(T)); + } + } + + public void Dispose() + { + var newGroup = new OptionCategory(this.Tab, groupid, this.Name, this.optionPack, this.color); + this.registerOption(Tab, newGroup); + } +} diff --git a/ExtremeRoles/Module/CustomOption/Factory/OptionRelationFactory.cs b/ExtremeRoles/Module/CustomOption/Factory/OptionRelationFactory.cs new file mode 100644 index 000000000..856ed983c --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Factory/OptionRelationFactory.cs @@ -0,0 +1,32 @@ +using System; + +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Module.CustomOption.Implemented; + + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Factory; + +public static class OptionRelationFactory +{ + public static IOptionRelation Create(IOption? parent = null, bool invert=false) + { + if (parent is null && invert) + { + throw new ArgumentException("Invalided Parent"); + } + else if (parent is null) + { + return new DefaultRelation(); + } + else if (invert) + { + return new OptionRelationWithInvertParent(parent); + } + else + { + return new OptionRelationWithParent(parent); + } + } +} diff --git a/ExtremeRoles/Module/CustomOption/Factory/SequentialOptionCategoryFactory.cs b/ExtremeRoles/Module/CustomOption/Factory/SequentialOptionCategoryFactory.cs new file mode 100644 index 000000000..947467fa8 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Factory/SequentialOptionCategoryFactory.cs @@ -0,0 +1,184 @@ +using ExtremeRoles.Helper; + +using System; +using System.Linq; +using System.Runtime.CompilerServices; + +using UnityEngine; + + + + +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Module.CustomOption.Implemented; + + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Factory; + +public sealed class SequentialOptionCategoryFactory( + string name, + int groupId, + in Action action, + OptionTab tab = OptionTab.General, + in Color? color = null) : + OptionCategoryFactory(name, groupId, action, tab, color) +{ + public int StartId => 0; + public int EndId => this.Offset - 1; + + public int Offset { private get; set; } = 0; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public BoolCustomOption CreateBoolOption( + object option, + bool defaultValue, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) + { + int optionId = getOptionIdAndUpdate(); + string name = getOptionName(option, ignorePrefix); + + var opt = new BoolCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public FloatDynamicCustomOption CreateFloatDynamicOption( + object option, + float defaultValue, + float min, float step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + float tempMaxValue = 0.0f, + bool ignorePrefix = false) + { + int optionId = getOptionIdAndUpdate(); + string name = getOptionName(option, ignorePrefix); + + var opt = new FloatDynamicCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, min, step, + OptionRelationFactory.Create(parent, invert), + tempMaxValue); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IntCustomOption CreateIntOption( + object option, + int defaultValue, + int min, int max, int step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) + { + int optionId = getOptionIdAndUpdate(); + string name = getOptionName(option, ignorePrefix); + + var opt = new IntCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, min, max, step, + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public IntDynamicCustomOption CreateIntDynamicOption( + object option, + int defaultValue, + int min, int step, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + int tempMaxValue = 0, + bool ignorePrefix = false) + { + int optionId = getOptionIdAndUpdate(); + string name = getOptionName(option, ignorePrefix); + + var opt = new IntDynamicCustomOption( + new OptionInfo(optionId, name, format, isHidden), + defaultValue, min, step, + OptionRelationFactory.Create(parent, invert), + tempMaxValue); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectionCustomOption CreateSelectionOption( + object option, + string[] selections, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) + { + int optionId = getOptionIdAndUpdate(); + string name = getOptionName(option, ignorePrefix); + + var opt = new SelectionCustomOption( + new OptionInfo(optionId, name, format, isHidden), + selections, + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SelectionCustomOption CreateSelectionOption( + object option, + IOption? parent = null, + bool isHidden = false, + OptionUnit format = OptionUnit.None, + bool invert = false, + bool ignorePrefix = false) + where W : struct, Enum + { + int optionId = getOptionIdAndUpdate(); + string name = getOptionName(option, ignorePrefix); + + var opt = SelectionCustomOption.CreateFromEnum( + new OptionInfo(optionId, name, format, isHidden), + OptionRelationFactory.Create(parent, invert)); + + this.AddOption(optionId, opt); + return opt; + } + + private string getOptionName(object option, bool ignorePrefix = false) + { + string cleanedName = this.NameCleaner.Replace(this.Name, string.Empty).Trim(); + + return ignorePrefix ? $"|{cleanedName}|{option}" : $"{cleanedName}{option}"; + } + + private int getOptionIdAndUpdate() + { + int optionId = this.Offset + this.IdOffset; + this.Offset++; + return optionId; + } +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/BoolOption.cs b/ExtremeRoles/Module/CustomOption/Implemented/BoolOption.cs new file mode 100644 index 000000000..918b9f4de --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/BoolOption.cs @@ -0,0 +1,16 @@ +using ExtremeRoles.Module.CustomOption.Interfaces; + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public sealed class BoolCustomOption : CustomOptionBase +{ + public BoolCustomOption( + IOptionInfo info, + bool defaultValue, + IOptionRelation relation) : base( + info, new OptionRange(["optionOff", "optionOn"]), + relation, defaultValue ? "optionOn" : "optionOff") + { } + + public override bool Value => OptionRange.Selection > 0; +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/FloatOption.cs b/ExtremeRoles/Module/CustomOption/Implemented/FloatOption.cs new file mode 100644 index 000000000..2ebf6af0e --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/FloatOption.cs @@ -0,0 +1,49 @@ +using ExtremeRoles.Module.CustomOption.Interfaces; + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public sealed class FloatCustomOption : CustomOptionBase +{ + public FloatCustomOption( + IOptionInfo info, + float defaultValue, + float min, float max, float step, + IOptionRelation relation) : base( + info, OptionRange.Create(min, max, step), + relation, defaultValue) + { } + + public override float Value => OptionRange.Value; +} + +public sealed class FloatDynamicCustomOption : CustomOptionBase, IDynamismOption +{ + private float step; + public FloatDynamicCustomOption( + IOptionInfo info, + float defaultValue, + float min, float step, + IOptionRelation relation, + float tempMaxValue = 0.0f) : base( + info, OptionRange.Create( + min, CreateMaxValue(min, step, defaultValue, tempMaxValue), step), + relation, defaultValue) + { + this.step = step; + } + + public override float Value => OptionRange.Value; + + public void Update(float newValue) + { + var newRange = OptionRange.Create( + OptionRange.Min, newValue, step); + OptionRange = newRange; + Selection = OptionRange.Selection; + } + + private static float CreateMaxValue(float min, float step, float defaultValue, float tempMaxValue) + => tempMaxValue == 0.0f ? + min + step < defaultValue ? defaultValue : min + step : + tempMaxValue; +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/IntOption.cs b/ExtremeRoles/Module/CustomOption/Implemented/IntOption.cs new file mode 100644 index 000000000..801a65db1 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/IntOption.cs @@ -0,0 +1,64 @@ +using BepInEx.Configuration; + +using ExtremeRoles.Module.CustomOption.Interfaces; + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public sealed class IntCustomOption : CustomOptionBase, IDynamismOption +{ + private int maxValue; + private readonly int minValue; + private readonly int step; + + public IntCustomOption( + IOptionInfo info, + int defaultValue, + int min, int max, int step, + IOptionRelation relation) : base( + info, OptionRange.Create(min, max, step), + relation, defaultValue) + { + this.maxValue = this.OptionRange.Max; + this.minValue = this.OptionRange.Min; + this.step = step; + } + public void Update(int newValue) + { + int newMaxValue = this.maxValue / newValue; + var newRange = OptionRange.Create(OptionRange.Min, newMaxValue, step); + OptionRange = newRange; + Selection = OptionRange.Selection; + } + + public override int Value => OptionRange.Value; +} + +public sealed class IntDynamicCustomOption : CustomOptionBase, IDynamismOption +{ + private readonly int step; + public IntDynamicCustomOption( + IOptionInfo info, + int defaultValue, + int min, int step, + IOptionRelation relation, + int tempMaxValue = 0) : base( + info, OptionRange.Create(min, CreateMaxValue(min, step, defaultValue, tempMaxValue), step), + relation, defaultValue) + { + this.step = step; + } + + public override int Value => OptionRange.Value; + + + public void Update(int newValue) + { + var newRange = OptionRange.Create(OptionRange.Min, newValue, step); + OptionRange = newRange; + Selection = OptionRange.Selection; + } + private static int CreateMaxValue(int min, int step, int defaultValue, int tempMaxValue) + => tempMaxValue == 0 ? + min + step < defaultValue ? defaultValue : min + step : + tempMaxValue; +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/OptionBase.cs b/ExtremeRoles/Module/CustomOption/Implemented/OptionBase.cs new file mode 100644 index 000000000..e8fd38edc --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/OptionBase.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text; + + + +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Helper; + + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public abstract class CustomOptionBase : + IValueOption + where OutType : + struct, IComparable, IConvertible, + IComparable, IEquatable + where SelectionType : + notnull, IComparable, IConvertible, + IComparable, IEquatable +{ + public abstract OutType Value { get; } + public IOptionInfo Info { get; init; } + + public IOptionRelation Relation { get; init; } + + public bool IsEnable => OptionRange.Selection != config.DefaultValue; + + public bool IsActiveAndEnable + { + get + { + if (Info.IsHidden) + { + return false; + } + + if (Relation is not IOptionParent hasParent) + { + return true; + } + return hasParent.IsChainEnable; + } + } + + public string Title => Translation.GetString(Info.Name); + + public string ValueString + { + get + { + string? value = OptionRange.Value.ToString(); + if (string.IsNullOrEmpty(value)) + { + value = "NOT_SUPPORT"; + } + if (typeof(SelectionType) == typeof(string)) + { + value = Translation.GetString(value); + } + string format = this.Info.Format; + return string.IsNullOrEmpty(format) ? + value : string.Format(Translation.GetString(format), value); + } + } + + public int Range => OptionRange.Range; + + public int Selection + { + get => OptionRange.Selection; + + set + { + OptionRange.Selection = value; + + foreach (var withUdate in withUpdate) + { + withUdate.Update(Value); + } + + var amongUs = AmongUsClient.Instance; + if (amongUs != null && + amongUs.AmHost) + { + config.Value = OptionRange.Selection; + } + } + } + + private readonly ConfigBinder config; + protected IOptionRange OptionRange; + private readonly List> withUpdate = new List>(); + + public CustomOptionBase( + IOptionInfo info, + IOptionRange range, + IOptionRelation relation, + SelectionType defaultValue) + { + Info = info; + OptionRange = range; + Relation = relation; + + int defaultIndex = OptionRange.GetIndex(defaultValue); + + if (relation is IOptionParent parentRelation) + { + parentRelation.Parent.Relation.Children.Add(this); + } + config = new ConfigBinder(Info.CodeRemovedName, defaultIndex); + + OptionRange.Selection = config.Value; + + ExtremeRolesPlugin.Logger.LogInfo($"---- Create new Option ----\n{this}\n--------"); + } + + public override string ToString() + { + var builder = new StringBuilder(); + builder + .AppendLine(Info.ToString()) + .Append(OptionRange.ToString()); + return builder.ToString(); + } + + public void AddWithUpdate(IDynamismOption option) + { + withUpdate.Add(option); + option.Update(Value); + } + + public void SwitchPreset() + { + config.Rebind(); + Selection = config.Value; + } +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/OptionInfo.cs b/ExtremeRoles/Module/CustomOption/Implemented/OptionInfo.cs new file mode 100644 index 000000000..a2968d2ec --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/OptionInfo.cs @@ -0,0 +1,29 @@ +using System.Text.RegularExpressions; + + + +using ExtremeRoles.Module.CustomOption.Interfaces; + + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public sealed class OptionInfo( + int id, string name, + OptionUnit format = OptionUnit.None, + bool hidden = false) : IOptionInfo +{ + public int Id { get; } = id; + public string Name { get; } = name; + + public string CodeRemovedName => nameCleaner.Replace(Name, string.Empty); + public string Format { get; } = format == OptionUnit.None ? string.Empty : format.ToString(); + + public bool IsHidden { get; } = hidden; + + public override string ToString() + => $"Name:{Name}, Format:{Format} -- ({Id})"; + + private static readonly Regex nameCleaner = new Regex(@"(\|)|(<.*?>)|(\\n)", RegexOptions.Compiled); +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/OptionRange.cs b/ExtremeRoles/Module/CustomOption/Implemented/OptionRange.cs new file mode 100644 index 000000000..ff8b46b6f --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/OptionRange.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +using ExtremeRoles.Module.CustomOption.Interfaces; + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public class OptionRange(T[] option) : IOptionRange + where T : + notnull, IComparable, IConvertible, + IComparable, IEquatable +{ + public T Value => _option[Selection]; + public T Min => _option[0]; + public T Max => _option[Range - 1]; + + public int Range => _option.Length; + + public int Selection + { + get => _selection; + set + { + int length = Range; + int clampedNewValue = Mathf.Clamp( + (value + length) % length, + 0, length - 1); + + _selection = clampedNewValue; + } + } + private readonly T[] _option = option; + private int _selection = 0; + + private OptionRange(IEnumerable range) : this(range.ToArray()) + { } + + public int GetIndex(T value) + { + int index = Array.IndexOf(_option, value); + return Math.Max(0, index); + } + + public override string ToString() + => $"Cur:{Value} (Min:{Min}, Max:{Max}, Selected Index:{Selection})"; + + public static OptionRange Create(int min, int max, int step) + { + var range = GetIntRange(min, max, step); + return new OptionRange(range); + } + public static OptionRange Create(float min, float max, float step) + { + var range = GetFloatRange(min, max, step); + return new OptionRange(range); + } + public static OptionRange Create() where W : struct, Enum + { + var range = GetEnumString(); + return new OptionRange(range); + } + + private static IEnumerable GetEnumString() where W : struct, Enum + { + foreach (W enumValue in Enum.GetValues()) + { + string? valuse = enumValue.ToString(); + if (string.IsNullOrEmpty(valuse)) { continue; } + + yield return valuse; + } + } + + private static IEnumerable GetIntRange(int min, int max, int step) + { + for (int s = min; s <= max; s += step) + { + yield return s; + } + } + + private static IEnumerable GetFloatRange(float min, float max, float step) + { + decimal dStep = new decimal(step); + decimal dMin = new decimal(min); + decimal dMax = new decimal(max); + + for (decimal s = dMin; s <= dMax; s += dStep) + { + yield return (float)decimal.ToDouble(s); + } + } +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/OptionRelation.cs b/ExtremeRoles/Module/CustomOption/Implemented/OptionRelation.cs new file mode 100644 index 000000000..07f08a682 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/OptionRelation.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; + +using ExtremeRoles.Module.CustomOption.Interfaces; + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public sealed class DefaultRelation() : IOptionRelation +{ + public List Children { get; } = new List(); +} + +public sealed class OptionRelationWithParent(IOption parent) : IOptionRelation, IOptionParent +{ + public List Children { get; } = new List(); + public IOption Parent { get; } = parent; + + public bool IsChainEnable + { + get + { + IOption? parent = Parent; + bool active = true; + + while (parent != null && active) + { + active = parent.IsEnable; + parent = + parent.Relation is IOptionParent hasParent ? + hasParent.Parent : null; + } + return active; + } + } +} + +public sealed class OptionRelationWithInvertParent(IOption parent) : IOptionRelation, IOptionParent +{ + public List Children { get; } = new List(); + public IOption Parent { get; } = parent; + + public bool IsChainEnable + { + get + { + IOption? parent = Parent; + bool active = true; + + while (parent != null && active) + { + bool parentEnable = parent.IsEnable; + active = Parent != parent ? parentEnable : !parentEnable; + parent = + parent.Relation is IOptionParent hasParent ? + hasParent.Parent : null; + } + return active; + } + } +} diff --git a/ExtremeRoles/Module/CustomOption/Implemented/SelectionOption.cs b/ExtremeRoles/Module/CustomOption/Implemented/SelectionOption.cs new file mode 100644 index 000000000..e0c0853cb --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Implemented/SelectionOption.cs @@ -0,0 +1,45 @@ +using System; + +using ExtremeRoles.Module.CustomOption.Interfaces; + +namespace ExtremeRoles.Module.CustomOption.Implemented; + +public sealed class SelectionCustomOption : CustomOptionBase +{ + public SelectionCustomOption( + IOptionInfo info, + OptionRange range, + IOptionRelation relation, + string defaultValue = "") : base( + info, range, + relation, defaultValue) + { } + + public SelectionCustomOption( + IOptionInfo info, + string[] range, + IOptionRelation relation, + string defaultValue = "") : base( + info, new OptionRange(range), + relation, defaultValue) + { } + + public SelectionCustomOption( + IOptionInfo info, + string[] range, + int defaultIndex, + IOptionRelation relation) : base( + info, new OptionRange(range), + relation, range[defaultIndex]) + { } + + public static SelectionCustomOption CreateFromEnum( + IOptionInfo info, IOptionRelation relation, + string defaultValue = "") where T : struct, Enum + { + var range = OptionRange.Create(); + return new SelectionCustomOption(info, range, relation, defaultValue); + } + + public override int Value => OptionRange.Selection; +} diff --git a/ExtremeRoles/Module/CustomOption/Interfaces/IDynamismOption.cs b/ExtremeRoles/Module/CustomOption/Interfaces/IDynamismOption.cs new file mode 100644 index 000000000..7a313fb07 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Interfaces/IDynamismOption.cs @@ -0,0 +1,6 @@ +namespace ExtremeRoles.Module.CustomOption.Interfaces; + +public interface IDynamismOption +{ + public void Update(T value); +} diff --git a/ExtremeRoles/Module/CustomOption/Interfaces/IOption.cs b/ExtremeRoles/Module/CustomOption/Interfaces/IOption.cs new file mode 100644 index 000000000..61a5ff2de --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Interfaces/IOption.cs @@ -0,0 +1,19 @@ + +namespace ExtremeRoles.Module.CustomOption.Interfaces; + +public interface IOption +{ + public IOptionInfo Info { get; } + public IOptionRelation Relation { get; } + + public string Title { get; } + public string ValueString { get; } + + public int Range { get; } + public int Selection { get; set; } + + public bool IsEnable { get; } + public bool IsActiveAndEnable { get; } + + public void SwitchPreset(); +} diff --git a/ExtremeRoles/Module/CustomOption/Interfaces/IOptionInfo.cs b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionInfo.cs new file mode 100644 index 000000000..c493a8f2d --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionInfo.cs @@ -0,0 +1,16 @@ + +namespace ExtremeRoles.Module.CustomOption.Interfaces; + +public interface IOptionInfo +{ + public int Id { get; } + public string Name { get; } + + public string CodeRemovedName { get; } + + public string Format { get; } + + public bool IsHidden { get; } + + public string ToString(); +} diff --git a/ExtremeRoles/Module/CustomOption/Interfaces/IOptionLoader.cs b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionLoader.cs new file mode 100644 index 000000000..0601b35bb --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionLoader.cs @@ -0,0 +1,36 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption.Interfaces; + +public interface IOptionLoader +{ + public bool TryGet(int id, [NotNullWhen(true)] out IOption? option); + public IOption Get(T id) where T : Enum; + + public bool TryGetValueOption(W id, [NotNullWhen(true)] out IValueOption? option) + where W : Enum + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable; + + public bool TryGetValueOption(int id, [NotNullWhen(true)] out IValueOption? option) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable; + + public IValueOption GetValueOption(W id) + where W : Enum + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable; + public IValueOption GetValueOption(int id) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable; + + public T GetValue(W id) where W : Enum; + public T GetValue(int id); +} diff --git a/ExtremeRoles/Module/CustomOption/Interfaces/IOptionRange.cs b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionRange.cs new file mode 100644 index 000000000..c17811008 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionRange.cs @@ -0,0 +1,21 @@ +using System; + +namespace ExtremeRoles.Module.CustomOption.Interfaces; + +public interface IOptionRange + where SelectionType : + notnull, IComparable, IConvertible, + IComparable, IEquatable +{ + public SelectionType Value { get; } + public SelectionType Min { get; } + public SelectionType Max { get; } + + public int Range { get; } + + public int Selection { get; set; } + + public int GetIndex(SelectionType value); + + public string ToString(); +} diff --git a/ExtremeRoles/Module/CustomOption/Interfaces/IOptionRelation.cs b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionRelation.cs new file mode 100644 index 000000000..667361f06 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Interfaces/IOptionRelation.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace ExtremeRoles.Module.CustomOption.Interfaces; + +public interface IOptionRelation +{ + public List Children { get; } +} + +public interface IOptionParent +{ + public IOption Parent { get; } + public bool IsChainEnable { get; } +} diff --git a/ExtremeRoles/Module/CustomOption/Interfaces/IValueOption.cs b/ExtremeRoles/Module/CustomOption/Interfaces/IValueOption.cs new file mode 100644 index 000000000..f27d9a99f --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/Interfaces/IValueOption.cs @@ -0,0 +1,12 @@ +using System; + +namespace ExtremeRoles.Module.CustomOption.Interfaces; + +public interface IValueOption : IOption + where ValueType : + struct, IComparable, IConvertible, + IComparable, IEquatable +{ + public ValueType Value { get; } + public void AddWithUpdate(IDynamismOption option); +} diff --git a/ExtremeRoles/Module/CustomOption/ModOptionMenu.cs b/ExtremeRoles/Module/CustomOption/ModOptionMenu.cs index 1ac4e6ddc..07d982d27 100644 --- a/ExtremeRoles/Module/CustomOption/ModOptionMenu.cs +++ b/ExtremeRoles/Module/CustomOption/ModOptionMenu.cs @@ -26,12 +26,12 @@ namespace ExtremeRoles.Module.CustomOption; public sealed class ModOptionMenu { public bool IsReCreate => - this.modOptionButton == null || - this.popUp == null || - this.creditText == null || - this.titleText == null || - this.menuButtons.Any(x => x == null) || - this.csvButton.Any(x => x.IsReCreate); + modOptionButton == null || + popUp == null || + creditText == null || + titleText == null || + menuButtons.Any(x => x == null) || + csvButton.Any(x => x.IsReCreate); public enum MenuButton : byte { @@ -50,7 +50,7 @@ private readonly record struct ButtonActionBuilder( private sealed class PopupActionButton { - public bool IsReCreate => this.popUp == null || this.button == null; + public bool IsReCreate => popUp == null || button == null; private readonly GenericPopup? popUp; private readonly ToggleButtonBehaviour? button; @@ -67,73 +67,73 @@ public PopupActionButton( { this.key = key; this.onClick = onClick; - this.button = UnityObject.Instantiate( + button = UnityObject.Instantiate( prefab, parent); - this.button.transform.localPosition = pos; - this.button.Text.enableWordWrapping = false; - this.button.Background.color = color; - this.button.Text.fontSizeMin = - this.button.Text.fontSizeMax = 2.2f; - this.button.Text.transform.SetLocalZ(0.0f); - - var passiveButton = this.button.GetComponent(); + button.transform.localPosition = pos; + button.Text.enableWordWrapping = false; + button.Background.color = color; + button.Text.fontSizeMin = + button.Text.fontSizeMax = 2.2f; + button.Text.transform.SetLocalZ(0.0f); + + var passiveButton = button.GetComponent(); passiveButton.gameObject.SetActive(true); passiveButton.OnClick.RemoveAllPersistentAndListeners(); passiveButton.OnClick.AddListener(this.excute); - this.popUp = UnityObject.Instantiate( + popUp = UnityObject.Instantiate( Prefab.Prop, passiveButton.transform); - this.popUp.transform.localPosition = new Vector3(-pos.x, -pos.y, -10.0f); - this.popUp.TextAreaTMP.fontSize *= 0.75f; - this.popUp.TextAreaTMP.enableAutoSizing = false; + popUp.transform.localPosition = new Vector3(-pos.x, -pos.y, -10.0f); + popUp.TextAreaTMP.fontSize *= 0.75f; + popUp.TextAreaTMP.enableAutoSizing = false; } public void UpdateTranslation(string postfix) { - if (this.button != null) + if (button != null) { - this.button.Text.text = Translation.GetString( - $"{this.key}{postfix}"); + button.Text.text = Translation.GetString( + $"{key}{postfix}"); } } private void excute() { - if (this.popUp == null) { return; } + if (popUp == null) { return; } - foreach (var sr in this.popUp.GetComponentsInChildren()) + foreach (var sr in popUp.GetComponentsInChildren()) { sr.sortingOrder = 8; } - foreach (var mr in this.popUp.GetComponentsInChildren()) + foreach (var mr in popUp.GetComponentsInChildren()) { mr.sortingOrder = 9; } string info = Translation.GetString( - $"{this.key}PleaseWait"); - this.popUp.Show(info); // Show originally + $"{key}PleaseWait"); + popUp.Show(info); // Show originally bool result = onClick.Invoke(); string transKey = result ? - $"{this.key}Success" : $"{this.key}Error"; + $"{key}Success" : $"{key}Error"; info = Translation.GetString(transKey); - this.popUp.StartCoroutine( + popUp.StartCoroutine( Effects.Lerp(0.01f, new Action((p) => { setPopupText(info); }))); } private void setPopupText(string message) { - if (this.popUp == null) + if (popUp == null) { return; } - if (this.popUp.TextAreaTMP != null) + if (popUp.TextAreaTMP != null) { - this.popUp.TextAreaTMP.text = message; + popUp.TextAreaTMP.text = message; } } } @@ -152,39 +152,39 @@ private void setPopupText(string message) public ModOptionMenu(in OptionsMenuBehaviour optionMenu) { - this.popUp = createCustomMenu(optionMenu); + popUp = createCustomMenu(optionMenu); var buttonPrefab = createButtonPrefab(optionMenu); - this.menuButtons = initializeCustomMenu(buttonPrefab); - this.csvButton = initializeCsvLogic(buttonPrefab); - this.modOptionButton = initializeModButton(buttonPrefab, optionMenu); + menuButtons = initializeCustomMenu(buttonPrefab); + csvButton = initializeCsvLogic(buttonPrefab); + modOptionButton = initializeModButton(buttonPrefab, optionMenu); - this.creditText = initializeCreditText(); - this.titleText = initializeMenuTitle(); - this.popUp.SetActive(false); + creditText = initializeCreditText(); + titleText = initializeMenuTitle(); + popUp.SetActive(false); } public void Hide() { - if (this.popUp != null) + if (popUp != null) { - this.popUp.SetActive(false); + popUp.SetActive(false); } } public void UpdateTranslation() { - if (this.modOptionButton != null) + if (modOptionButton != null) { - this.modOptionButton.Text.text = Translation.GetString( + modOptionButton.Text.text = Translation.GetString( "modOptionText"); } - if (this.titleText != null) + if (titleText != null) { - this.titleText.text = Translation.GetString("moreOptionText"); + titleText.text = Translation.GetString("moreOptionText"); } - foreach (var button in this.menuButtons) + foreach (var button in menuButtons) { if (button != null) { @@ -192,7 +192,7 @@ public void UpdateTranslation() button.name); } } - foreach (var button in this.csvButton) + foreach (var button in csvButton) { button.UpdateTranslation("Csv"); } @@ -201,9 +201,9 @@ public void UpdateTranslation() private void updateCreditText() { - if (this.creditText == null) { return; } + if (creditText == null) { return; } - this.creditText.transform.localPosition = new Vector3(0.0f, -2.0f); + creditText.transform.localPosition = new Vector3(0.0f, -2.0f); StringBuilder showTextBuilder = new StringBuilder(); @@ -222,20 +222,20 @@ private void updateCreditText() if (DataManager.Settings.Language.CurrentLanguage != SupportedLangs.Japanese) { - this.creditText.transform.localPosition = new Vector3(0.0f, -1.895f); + creditText.transform.localPosition = new Vector3(0.0f, -1.895f); showTextBuilder .Append($"") .Append(Translation.GetString("langTranslate")) .Append(Translation.GetString("translatorMember")); } - this.creditText.text = showTextBuilder.ToString(); + creditText.text = showTextBuilder.ToString(); } private TextMeshPro initializeCreditText() { var text = UnityObject.Instantiate( - Prefab.Text, this.popUp!.transform); + Prefab.Text, popUp!.transform); text.name = "credit"; text.fontSize = text.fontSizeMin = text.fontSizeMax = 2.0f; text.font = UnityObject.Instantiate(Prefab.Text.font); @@ -248,7 +248,7 @@ private TextMeshPro initializeCreditText() private TextMeshPro initializeMenuTitle() { var title = UnityObject.Instantiate( - Prefab.Text, this.popUp!.transform); + Prefab.Text, popUp!.transform); title.GetComponent().localPosition = Vector3.up * 2.3f; title.gameObject.SetActive(true); title.fontSize = title.fontSizeMin = title.fontSizeMax = 3.25f; @@ -270,9 +270,9 @@ private ToggleButtonBehaviour initializeModButton(in ToggleButtonBehaviour prefa passiveButton.OnClick.RemoveAllPersistentAndListeners(); passiveButton.OnClick.AddListener(() => { - if (this.popUp == null) { return; } - this.popUp.SetActive(false); - this.popUp.SetActive(true); + if (popUp == null) { return; } + popUp.SetActive(false); + popUp.SetActive(true); }); return button; } @@ -283,12 +283,12 @@ private IReadOnlyList initializeCsvLogic( { new PopupActionButton( "import", - prefab, this.popUp!.transform, + prefab, popUp!.transform, Color.green, new Vector3(-1.35f, -0.9f), CustomOptionCsvProcessor.Import), new PopupActionButton( "export", - prefab, this.popUp!.transform, + prefab, popUp!.transform, Palette.ImpostorRed, new Vector3(1.35f, -0.9f), CustomOptionCsvProcessor.Export), }; @@ -308,7 +308,7 @@ private IReadOnlyList initializeCustomMenu( int index = (int)menuType; var button = UnityObject.Instantiate( - prefab, this.popUp!.transform); + prefab, popUp!.transform); button.transform.position = Vector3.zero; button.transform.localPosition = new Vector3( index % 2 == 0 ? -1.17f : 1.17f, @@ -379,10 +379,10 @@ private ButtonActionBuilder createButtonActionBuilder( PublicBeta.Instance.Enable, () => { - if (this.confirmMenu != null) + if (confirmMenu != null) { - UnityObject.Destroy(this.confirmMenu); - this.confirmMenu = null; + UnityObject.Destroy(confirmMenu); + confirmMenu = null; } var beta = PublicBeta.Instance; @@ -392,7 +392,7 @@ private ButtonActionBuilder createButtonActionBuilder( string targetStr = Translation.GetString( target ? "EnableKey" : "DisableKey"); - this.confirmMenu = Prefab.CreateConfirmMenu( + confirmMenu = Prefab.CreateConfirmMenu( () => { beta.SwitchMode(); @@ -414,14 +414,14 @@ private ButtonActionBuilder createButtonActionBuilder( string.Format(showText, targetStr)); }, StringNames.Accept); - this.confirmMenu.transform.SetParent(this.popUp!.transform); - this.confirmMenu.transform.localPosition = pos; + confirmMenu.transform.SetParent(popUp!.transform); + confirmMenu.transform.localPosition = pos; string func = TranslationControllerExtension.GetString( BetaContentManager.TransKey); string warnText = Translation.GetString("PublicBetaWarning"); - this.confirmMenu.Show( + confirmMenu.Show( $"{string.Format(warnText, targetStr)}\n{func}"); button.onState = target; diff --git a/ExtremeRoles/Module/CustomOption/OLDS/CommonOptionKey.cs b/ExtremeRoles/Module/CustomOption/OLDS/CommonOptionKey.cs new file mode 100644 index 000000000..c2acbc74b --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/OLDS/CommonOptionKey.cs @@ -0,0 +1,11 @@ +namespace ExtremeRoles.Module.CustomOption.OLDS; + +public enum CommonOptionKey : int +{ + PresetSelection = 0, + + UseRaiseHand, + + UseStrongRandomGen, + UsePrngAlgorithm, +} \ No newline at end of file diff --git a/ExtremeRoles/Module/CustomOption/OLDS/GlobalOption.cs b/ExtremeRoles/Module/CustomOption/OLDS/GlobalOption.cs new file mode 100644 index 000000000..c2c84d2eb --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/OLDS/GlobalOption.cs @@ -0,0 +1,62 @@ +namespace ExtremeRoles.Module.CustomOption.OLDS; + +public enum GlobalOption : int +{ + NumMeating = 50, + ChangeMeetingVoteAreaSort, + FixedMeetingPlayerLevel, + DisableSkipInEmergencyMeeting, + DisableSelfVote, + + ConfirmExilMode, + IsConfirmRole, + + DisableVent, + EngineerUseImpostorVent, + CanKillVentInPlayer, + VentAnimationModeInVison, + + ParallelMedBayScans, + + IsFixWallHaskTask, + GarbageTask, + ShowerTask, + DevelopPhotosTask, + DivertPowerTask, + + EnableSpecialSetting, + SkeldRandomSpawn, + MiraHqRandomSpawn, + PolusRandomSpawn, + AirShipRandomSpawn, + FungleRandomSpawn, + + IsAutoSelectRandomSpawn, + + IsRemoveAdmin, + AirShipEnableAdmin, + EnableAdminLimit, + AdminLimitTime, + + IsRemoveSecurity, + EnableSecurityLimit, + SecurityLimitTime, + + IsRemoveVital, + EnableVitalLimit, + VitalLimitTime, + + RandomMap, + + DisableTaskWinWhenNoneTaskCrew, + DisableTaskWin, + IsSameNeutralSameWin, + DisableNeutralSpecialForceEnd, + + IsAssignNeutralToVanillaCrewGhostRole, + IsRemoveAngleIcon, + IsBlockGAAbilityReport, + + // ウマングアスを一時的もしくは恒久的に無効化 + // EnableHorseMode +} diff --git a/ExtremeRoles/Module/CustomOption/BoolOption.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/BoolOption.cs similarity index 90% rename from ExtremeRoles/Module/CustomOption/BoolOption.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/BoolOption.cs index e93b2d34b..4fc427e1b 100644 --- a/ExtremeRoles/Module/CustomOption/BoolOption.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/BoolOption.cs @@ -1,4 +1,4 @@ -namespace ExtremeRoles.Module.CustomOption; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented; public sealed class BoolCustomOption : CustomOptionBase { diff --git a/ExtremeRoles/Module/CustomOption/Factories/AutoParentSetFactory.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/AutoParentSetFactory.cs similarity index 86% rename from ExtremeRoles/Module/CustomOption/Factories/AutoParentSetFactory.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/AutoParentSetFactory.cs index 97af7966a..6b7d9bdd8 100644 --- a/ExtremeRoles/Module/CustomOption/Factories/AutoParentSetFactory.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/AutoParentSetFactory.cs @@ -4,7 +4,7 @@ #nullable enable -namespace ExtremeRoles.Module.CustomOption.Factories; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented.Factories; public sealed class AutoParentSetFactory { @@ -15,16 +15,16 @@ public int IdOffset { set { - this.internalFactory.IdOffset = value; + internalFactory.IdOffset = value; } } public string NamePrefix { - get => this.internalFactory.NamePrefix; + get => internalFactory.NamePrefix; set { - this.internalFactory.NamePrefix = value; + internalFactory.NamePrefix = value; } } @@ -35,7 +35,7 @@ public AutoParentSetFactory( IOptionInfo? parent = null) { this.parent = parent; - this.internalFactory = new SimpleFactory(idOffset, namePrefix, tab); + internalFactory = new SimpleFactory(idOffset, namePrefix, tab); } public FloatCustomOption CreateBoolOption( @@ -51,7 +51,7 @@ public FloatCustomOption CreateBoolOption( Color? color = null, bool ignorePrefix = false) where T : struct, IConvertible { - FloatCustomOption newOption = this.internalFactory.CreateFloatOption( + FloatCustomOption newOption = internalFactory.CreateFloatOption( option, defaultValue, min, max, step, @@ -84,7 +84,7 @@ public FloatCustomOption CreateFloatOption( Color? color = null, bool ignorePrefix = false) where T : struct, IConvertible { - FloatCustomOption newOption = this.internalFactory.CreateFloatOption( + FloatCustomOption newOption = internalFactory.CreateFloatOption( option, defaultValue, min, max, step, @@ -118,7 +118,7 @@ public FloatDynamicCustomOption CreateFloatDynamicOption( float tempMaxValue = 0.0f, bool ignorePrefix = false) where T : struct, IConvertible { - FloatDynamicCustomOption newOption = this.internalFactory.CreateFloatDynamicOption( + FloatDynamicCustomOption newOption = internalFactory.CreateFloatDynamicOption( option, defaultValue, min, step, @@ -152,7 +152,7 @@ public IntCustomOption CreateIntOption( Color? color = null, bool ignorePrefix = false) where T : struct, IConvertible { - IntCustomOption newOption = this.internalFactory.CreateIntOption( + IntCustomOption newOption = internalFactory.CreateIntOption( option, defaultValue, min, max, step, @@ -186,7 +186,7 @@ public IntDynamicCustomOption CreateIntDynamicOption( int tempMaxValue = 0, bool ignorePrefix = false) where T : struct, IConvertible { - IntDynamicCustomOption newOption = this.internalFactory.CreateIntDynamicOption( + IntDynamicCustomOption newOption = internalFactory.CreateIntDynamicOption( option, defaultValue, min, step, @@ -219,7 +219,7 @@ public BoolCustomOption CreateBoolOption( Color? color = null, bool ignorePrefix = false) where T : struct, IConvertible { - BoolCustomOption newOption = this.internalFactory.CreateBoolOption( + BoolCustomOption newOption = internalFactory.CreateBoolOption( option, defaultValue, parent is null ? this.parent : parent, @@ -250,7 +250,7 @@ public SelectionCustomOption CreateSelectionOption( Color? color = null, bool ignorePrefix = false) where T : struct, IConvertible { - SelectionCustomOption newOption = this.internalFactory.CreateSelectionOption( + SelectionCustomOption newOption = internalFactory.CreateSelectionOption( option, selections, parent is null ? this.parent : parent, @@ -282,7 +282,7 @@ public SelectionCustomOption CreateSelectionOption( where T : struct, IConvertible where W : struct, IConvertible { - SelectionCustomOption newOption = this.internalFactory.CreateSelectionOption( + SelectionCustomOption newOption = internalFactory.CreateSelectionOption( option, parent is null ? this.parent : parent, isHeader, diff --git a/ExtremeRoles/Module/CustomOption/Factories/ColorSyncFactory.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/ColorSyncFactory.cs similarity index 86% rename from ExtremeRoles/Module/CustomOption/Factories/ColorSyncFactory.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/ColorSyncFactory.cs index 1871f1973..c90863117 100644 --- a/ExtremeRoles/Module/CustomOption/Factories/ColorSyncFactory.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/ColorSyncFactory.cs @@ -6,7 +6,7 @@ #nullable enable -namespace ExtremeRoles.Module.CustomOption.Factories; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented.Factories; public sealed class ColorSyncFactory : SimpleFactory { @@ -35,11 +35,11 @@ public FloatCustomOption CreateFloatOption( where T : struct, IConvertible => new FloatCustomOption( GetOptionId(option), - GetOptionName(option, this.color), + GetOptionName(option, color), defaultValue, min, max, step, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public FloatDynamicCustomOption CreateFloatDynamicOption( @@ -56,12 +56,12 @@ public FloatDynamicCustomOption CreateFloatDynamicOption( where T : struct, IConvertible => new FloatDynamicCustomOption( GetOptionId(option), - GetOptionName(option, this.color), + GetOptionName(option, color), defaultValue, min, step, parent, isHeader, isHidden, format, invert, enableCheckOption, - this.Tab, tempMaxValue); + Tab, tempMaxValue); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IntCustomOption CreateIntOption( @@ -77,11 +77,11 @@ public IntCustomOption CreateIntOption( where T : struct, IConvertible => new IntCustomOption( GetOptionId(option), - GetOptionName(option, this.color), + GetOptionName(option, color), defaultValue, min, max, step, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IntDynamicCustomOption CreateIntDynamicOption( @@ -98,12 +98,12 @@ public IntDynamicCustomOption CreateIntDynamicOption( where T : struct, IConvertible => new IntDynamicCustomOption( GetOptionId(option), - GetOptionName(option, this.color), + GetOptionName(option, color), defaultValue, min, step, parent, isHeader, isHidden, format, invert, enableCheckOption, - this.Tab, tempMaxValue); + Tab, tempMaxValue); [MethodImpl(MethodImplOptions.AggressiveInlining)] public BoolCustomOption CreateBoolOption( @@ -118,10 +118,10 @@ public BoolCustomOption CreateBoolOption( where T : struct, IConvertible => new BoolCustomOption( GetOptionId(option), - GetOptionName(option, this.color), + GetOptionName(option, color), defaultValue, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectionCustomOption CreateSelectionOption( @@ -136,10 +136,10 @@ public SelectionCustomOption CreateSelectionOption( where T : struct, IConvertible => new SelectionCustomOption( GetOptionId(option), - GetOptionName(option, this.color), + GetOptionName(option, color), selections, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectionCustomOption CreateSelectionOption( @@ -154,8 +154,8 @@ public SelectionCustomOption CreateSelectionOption( where W : struct, IConvertible => new SelectionCustomOption( GetOptionId(option), - GetOptionName(option, this.color), + GetOptionName(option, color), GetEnumString().ToArray(), parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); } diff --git a/ExtremeRoles/Module/CustomOption/Factories/SequentialFactory.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/SequentialFactory.cs similarity index 88% rename from ExtremeRoles/Module/CustomOption/Factories/SequentialFactory.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/SequentialFactory.cs index 2c8852d35..2914874b5 100644 --- a/ExtremeRoles/Module/CustomOption/Factories/SequentialFactory.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/SequentialFactory.cs @@ -6,15 +6,17 @@ using ExtremeRoles.Helper; + + #nullable enable -namespace ExtremeRoles.Module.CustomOption.Factories; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented.Factories; public class SequentialOptionFactory : SimpleFactory { public int StartId => GetOptionId(0); - public int EndId => GetOptionId(this.Offset - 1); + public int EndId => GetOptionId(Offset - 1); public int Offset { private get; set; } @@ -23,7 +25,7 @@ public SequentialOptionFactory( string namePrefix = "", OptionTab tab = OptionTab.General) : base(idOffset, namePrefix, tab) { - this.Offset = 0; + Offset = 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -45,7 +47,7 @@ public FloatCustomOption CreateFloatOption( defaultValue, min, max, step, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public FloatDynamicCustomOption CreateFloatDynamicOption( @@ -68,7 +70,7 @@ public FloatDynamicCustomOption CreateFloatDynamicOption( min, step, parent, isHeader, isHidden, format, invert, enableCheckOption, - this.Tab, tempMaxValue); + Tab, tempMaxValue); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IntCustomOption CreateIntOption( @@ -89,7 +91,7 @@ public IntCustomOption CreateIntOption( defaultValue, min, max, step, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IntDynamicCustomOption CreateIntDynamicOption( @@ -112,7 +114,7 @@ public IntDynamicCustomOption CreateIntDynamicOption( min, step, parent, isHeader, isHidden, format, invert, enableCheckOption, - this.Tab, tempMaxValue); + Tab, tempMaxValue); [MethodImpl(MethodImplOptions.AggressiveInlining)] public BoolCustomOption CreateBoolOption( @@ -131,7 +133,7 @@ public BoolCustomOption CreateBoolOption( getOptionName(option, color, ignorePrefix), defaultValue, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectionCustomOption CreateSelectionOption( @@ -150,7 +152,7 @@ public SelectionCustomOption CreateSelectionOption( getOptionName(option, color, ignorePrefix), selections, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectionCustomOption CreateSelectionOption( @@ -169,18 +171,18 @@ public SelectionCustomOption CreateSelectionOption( getOptionName(option, color, ignorePrefix), GetEnumString().ToArray(), parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); private string getOptionName(object option, Color? color, bool ignorePrefix = false) { - string optionName = ignorePrefix ? $"|{this.NamePrefix}|{option}" : $"{this.NamePrefix}{option}"; + string optionName = ignorePrefix ? $"|{NamePrefix}|{option}" : $"{NamePrefix}{option}"; return !color.HasValue ? optionName : Design.ColoedString(color.Value, optionName); } private int getOptionIdAndUpdate() { - int optionId = GetOptionId(this.Offset); - this.Offset++; + int optionId = GetOptionId(Offset); + Offset++; return optionId; } } diff --git a/ExtremeRoles/Module/CustomOption/Factories/SimpleFactory.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/SimpleFactory.cs similarity index 93% rename from ExtremeRoles/Module/CustomOption/Factories/SimpleFactory.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/SimpleFactory.cs index b95a04282..9bc16e75a 100644 --- a/ExtremeRoles/Module/CustomOption/Factories/SimpleFactory.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/Factories/SimpleFactory.cs @@ -7,9 +7,10 @@ using ExtremeRoles.Helper; + #nullable enable -namespace ExtremeRoles.Module.CustomOption.Factories; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented.Factories; public class SimpleFactory { @@ -23,9 +24,9 @@ public SimpleFactory( string namePrefix = "", OptionTab tab = OptionTab.General) { - this.IdOffset = idOffset; - this.NamePrefix = namePrefix; - this.Tab = tab; + IdOffset = idOffset; + NamePrefix = namePrefix; + Tab = tab; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -147,7 +148,7 @@ public FloatCustomOption CreateFloatOption( defaultValue, min, max, step, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public FloatDynamicCustomOption CreateFloatDynamicOption( @@ -170,7 +171,7 @@ public FloatDynamicCustomOption CreateFloatDynamicOption( min, step, parent, isHeader, isHidden, format, invert, enableCheckOption, - this.Tab, tempMaxValue); + Tab, tempMaxValue); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IntCustomOption CreateIntOption( @@ -191,7 +192,7 @@ public IntCustomOption CreateIntOption( defaultValue, min, max, step, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IntDynamicCustomOption CreateIntDynamicOption( @@ -214,7 +215,7 @@ public IntDynamicCustomOption CreateIntDynamicOption( min, step, parent, isHeader, isHidden, format, invert, enableCheckOption, - this.Tab, tempMaxValue); + Tab, tempMaxValue); [MethodImpl(MethodImplOptions.AggressiveInlining)] public BoolCustomOption CreateBoolOption( @@ -233,7 +234,7 @@ public BoolCustomOption CreateBoolOption( GetOptionName(option, color, ignorePrefix), defaultValue, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectionCustomOption CreateSelectionOption( @@ -252,7 +253,7 @@ public SelectionCustomOption CreateSelectionOption( GetOptionName(option, color, ignorePrefix), selections, parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); [MethodImpl(MethodImplOptions.AggressiveInlining)] public SelectionCustomOption CreateSelectionOption( @@ -272,7 +273,7 @@ public SelectionCustomOption CreateSelectionOption( GetOptionName(option, color, ignorePrefix), GetEnumString().ToArray(), parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); + format, invert, enableCheckOption, Tab); public int GetOptionId(T option) where T : struct, IConvertible { @@ -280,11 +281,11 @@ public int GetOptionId(T option) where T : struct, IConvertible return GetOptionId(Convert.ToInt32(option)); } - public int GetOptionId(int option) => this.IdOffset + option; + public int GetOptionId(int option) => IdOffset + option; protected string GetOptionName(T option, Color? color, bool ignorePrefix = false) where T : struct, IConvertible { - string optionName = ignorePrefix ? $"|{this.NamePrefix}|{option}" : $"{this.NamePrefix}{option}"; + string optionName = ignorePrefix ? $"|{NamePrefix}|{option}" : $"{NamePrefix}{option}"; return !color.HasValue ? optionName : Design.ColoedString(color.Value, optionName); } diff --git a/ExtremeRoles/Module/CustomOption/FloatOption.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/FloatOption.cs similarity index 79% rename from ExtremeRoles/Module/CustomOption/FloatOption.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/FloatOption.cs index 2349df15e..65b400c19 100644 --- a/ExtremeRoles/Module/CustomOption/FloatOption.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/FloatOption.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace ExtremeRoles.Module.CustomOption; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented; public sealed class FloatCustomOption : CustomOptionBase { @@ -23,7 +23,7 @@ public FloatCustomOption( enableCheckOption, tab) { } - public override float GetValue() => this.Option[CurSelection]; + public override float GetValue() => Option[CurSelection]; private static List createSelection(float min, float max, float step) { @@ -36,7 +36,7 @@ private static List createSelection(float min, float max, float step) for (decimal s = dMin; s <= dMax; s += dStep) { - selection.Add(((float)(decimal.ToDouble(s)))); + selection.Add((float)decimal.ToDouble(s)); } return selection; @@ -68,21 +68,21 @@ public FloatDynamicCustomOption( this.step = step; } - public override float GetValue() => this.Option[CurSelection]; + public override float GetValue() => Option[CurSelection]; public override void Update(float newValue) { - decimal dStep = new decimal(this.step); - decimal dMin = new decimal(this.Option[0]); + decimal dStep = new decimal(step); + decimal dMin = new decimal(Option[0]); decimal dMax = new decimal(newValue); List newSelection = new List(); for (decimal s = dMin; s <= dMax; s += dStep) { - newSelection.Add(((float)(decimal.ToDouble(s)))); + newSelection.Add((float)decimal.ToDouble(s)); } - this.Option = newSelection.ToArray(); - this.UpdateSelection(this.CurSelection); + Option = newSelection.ToArray(); + UpdateSelection(CurSelection); } private static List createSelection( @@ -97,7 +97,7 @@ private static List createSelection( decimal tempMaxValue; if (floatTempMaxValue == 0.0f) { - tempMaxValue = (min + step) < defaultValue ? new decimal(defaultValue) : dMin + dStep; + tempMaxValue = min + step < defaultValue ? new decimal(defaultValue) : dMin + dStep; } else { @@ -106,7 +106,7 @@ private static List createSelection( for (decimal s = dMin; s <= tempMaxValue; s += dStep) { - selection.Add(((float)(decimal.ToDouble(s)))); + selection.Add((float)decimal.ToDouble(s)); } return selection; diff --git a/ExtremeRoles/Module/CustomOption/IntOption.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/IntOption.cs similarity index 78% rename from ExtremeRoles/Module/CustomOption/IntOption.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/IntOption.cs index e8c433376..7ec623657 100644 --- a/ExtremeRoles/Module/CustomOption/IntOption.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/IntOption.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace ExtremeRoles.Module.CustomOption; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented; public sealed class IntCustomOption : CustomOptionBase { @@ -26,15 +26,15 @@ public IntCustomOption( format, invert, enableCheckOption, tab) { - this.minValue = this.Option[0]; - this.maxValue = this.Option[this.ValueCount - 1]; + minValue = Option[0]; + maxValue = Option[ValueCount - 1]; } public override int GetValue() => Option[CurSelection]; public override void Update(int newValue) { - int newMaxValue = this.maxValue / newValue; + int newMaxValue = maxValue / newValue; List newSelections = new List(); for (int s = minValue; s <= newMaxValue; ++s) @@ -42,8 +42,8 @@ public override void Update(int newValue) newSelections.Add(s); } - this.Option = newSelections.ToArray(); - this.UpdateSelection(this.CurSelection); + Option = newSelections.ToArray(); + UpdateSelection(CurSelection); } private static List createSelection(int min, int max, int step) @@ -85,19 +85,19 @@ public IntDynamicCustomOption( this.step = step; } - public override int GetValue() => this.Option[this.CurSelection]; + public override int GetValue() => Option[CurSelection]; public override void Update(int newValue) { - int minValue = this.Option[0]; + int minValue = Option[0]; List newSelections = new List(); - for (int s = minValue; s <= newValue; s += this.step) + for (int s = minValue; s <= newValue; s += step) { newSelections.Add(s); } - this.Option = newSelections.ToArray(); - this.UpdateSelection(this.CurSelection); + Option = newSelections.ToArray(); + UpdateSelection(CurSelection); } private static List createSelection( @@ -107,7 +107,7 @@ private static List createSelection( if (tempMaxValue == 0) { - tempMaxValue = (min + step) < defaultValue ? defaultValue : min + step; + tempMaxValue = min + step < defaultValue ? defaultValue : min + step; } for (int s = min; s <= tempMaxValue; s += step) diff --git a/ExtremeRoles/Module/CustomOption/OptionBase.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/OptionBase.cs similarity index 67% rename from ExtremeRoles/Module/CustomOption/OptionBase.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/OptionBase.cs index f3bd30fbe..b83f85602 100644 --- a/ExtremeRoles/Module/CustomOption/OptionBase.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/OptionBase.cs @@ -11,9 +11,10 @@ using ExtremeRoles.Helper; using ExtremeRoles.Performance; + #nullable enable -namespace ExtremeRoles.Module.CustomOption; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented; public enum OptionTab : byte { @@ -97,9 +98,9 @@ public abstract class CustomOptionBase public int Id { get; init; } public string Name { get; init; } - public int ValueCount => this.Option.Length; + public int ValueCount => Option.Length; public bool Enabled - => this.CurSelection != this.defaultSelection; + => CurSelection != defaultSelection; protected SelectionType[] Option = new SelectionType[1]; @@ -128,50 +129,52 @@ public CustomOptionBase( OptionTab tab = OptionTab.General) { - this.Tab = tab; - this.Parent = parent; + Tab = tab; + Parent = parent; - this.Option = selections; + Option = selections; int index = Array.IndexOf(selections, defaultValue); - this.Id = id; - this.Name = name; + Id = id; + Name = name; - this.formatStr = format == OptionUnit.None ? string.Empty : format.ToString(); - this.defaultSelection = Mathf.Clamp(index, 0, index); + formatStr = format == OptionUnit.None ? string.Empty : format.ToString(); + defaultSelection = Mathf.Clamp(index, 0, index); - this.IsHeader = isHeader; - this.IsHidden = isHidden; + IsHeader = isHeader; + IsHidden = isHidden; - this.Children = new List(); - this.withUpdateOption.Clear(); - this.forceEnableCheckOption = enableCheckOption; + Children = new List(); + withUpdateOption.Clear(); + forceEnableCheckOption = enableCheckOption; if (parent != null) { - this.enableInvert = invert; + enableInvert = invert; parent.Children.Add(this); } - this.CurSelection = 0; + CurSelection = 0; if (id > 0) { bindConfig(); - this.CurSelection = Mathf.Clamp(this.entry!.Value, 0, selections.Length - 1); + CurSelection = Mathf.Clamp(entry!.Value, 0, selections.Length - 1); } ExtremeRolesPlugin.Logger.LogInfo($"Register Options: {this}"); - OptionManager.Instance.AddOption(this.Id, this); + // OptionManager.Instance.AddOption(Id, this); } public override string ToString() - => $"ID:{this.Id} Name:{this.Name} CurValue:{this.GetValue()}"; + => $"ID:{Id} Name:{Name} CurValue:{GetValue()}"; public void AddToggleOptionCheckHook(StringNames targetOption) { + /* Patches.Option.GameOptionsMenuStartPatch.AddHook( targetOption, x => this.IsHidden = !x.GetBool()); + */ } public virtual void Update(OutType newValue) @@ -179,30 +182,30 @@ public virtual void Update(OutType newValue) return; } - public string GetTranslatedName() => Translation.GetString(this.Name); + public string GetTranslatedName() => Translation.GetString(Name); public string GetTranslatedValue() { - string? sel = this.Option[this.CurSelection].ToString(); + string? sel = Option[CurSelection].ToString(); - return string.IsNullOrEmpty(this.formatStr) ? + return string.IsNullOrEmpty(formatStr) ? Translation.GetString(sel) : - string.Format(Translation.GetString(this.formatStr), sel); + string.Format(Translation.GetString(formatStr), sel); } public bool IsActive() { - if (this.IsHidden) + if (IsHidden) { return false; } - if (this.IsHeader || this.Parent == null) + if (IsHeader || Parent == null) { return true; } - IOptionInfo parent = this.Parent; + IOptionInfo parent = Parent; bool active = true; while (parent != null && active) @@ -211,18 +214,18 @@ public bool IsActive() parent = parent.Parent; } - if (this.enableInvert) + if (enableInvert) { active = !active; } - if (this.forceEnableCheckOption is not null) + if (forceEnableCheckOption is not null) { - bool forceEnable = this.forceEnableCheckOption.Enabled; + bool forceEnable = forceEnableCheckOption.Enabled; - if (this.forceEnableCheckOption.Parent is not null) + if (forceEnableCheckOption.Parent is not null) { - forceEnable = forceEnable && this.forceEnableCheckOption.Parent.IsActive(); + forceEnable = forceEnable && forceEnableCheckOption.Parent.IsActive(); } active = active && forceEnable; @@ -232,72 +235,72 @@ public bool IsActive() public void SetUpdateOption(IValueOption option) { - this.withUpdateOption.Add(option); - option.Update(this.GetValue()); + withUpdateOption.Add(option); + option.Update(GetValue()); } public void UpdateSelection(int newSelection) { - int length = this.ValueCount; + int length = ValueCount; - this.CurSelection = Mathf.Clamp( + CurSelection = Mathf.Clamp( (newSelection + length) % length, 0, length - 1); - if (this.Body is StringOption stringOption) + if (Body is StringOption stringOption) { - stringOption.oldValue = stringOption.Value = this.CurSelection; - stringOption.ValueText.text = this.GetTranslatedValue(); + stringOption.oldValue = stringOption.Value = CurSelection; + stringOption.ValueText.text = GetTranslatedValue(); } - foreach (IValueOption option in this.withUpdateOption) + foreach (IValueOption option in withUpdateOption) { - option.Update(this.GetValue()); + option.Update(GetValue()); } if (AmongUsClient.Instance && AmongUsClient.Instance.AmHost && CachedPlayerControl.LocalPlayer && - this.entry != null) + entry != null) { - this.entry.Value = this.CurSelection; // Save selection to config + entry.Value = CurSelection; // Save selection to config } } public void SaveConfigValue() { - if (this.entry != null) + if (entry != null) { - this.entry.Value = this.CurSelection; + entry.Value = CurSelection; } } public void SwitchPreset() { bindConfig(); - this.UpdateSelection(Mathf.Clamp( - this.entry!.Value, 0, - this.ValueCount - 1)); + UpdateSelection(Mathf.Clamp( + entry!.Value, 0, + ValueCount - 1)); } public void SetOptionBehaviour(OptionBehaviour newBehaviour) { - this.Body = newBehaviour; + Body = newBehaviour; } public void SetOptionUnit(OptionUnit unit) { - this.formatStr = unit.ToString(); + formatStr = unit.ToString(); } public string ToHudString() => - this.IsActive() ? $"{this.GetTranslatedName()}: {this.GetTranslatedValue()}" : string.Empty; + IsActive() ? $"{GetTranslatedName()}: {GetTranslatedValue()}" : string.Empty; public string ToHudStringWithChildren(int indent = 0) { StringBuilder builder = new StringBuilder(); - string optStr = this.ToHudString(); - if (!this.IsHidden && optStr != string.Empty) + string optStr = ToHudString(); + if (!IsHidden && optStr != string.Empty) { builder.AppendLine(optStr); } @@ -309,14 +312,14 @@ public string ToHudStringWithChildren(int indent = 0) private void bindConfig() { - this.entry = ExtremeRolesPlugin.Instance.Config.Bind( - OptionManager.Instance.ConfigPreset, - this.cleanName(), - this.defaultSelection); + entry = ExtremeRolesPlugin.Instance.Config.Bind( + "OLD_OPTION", // OptionManager.Instance.ConfigPreset, + cleanName(), + defaultSelection); } private string cleanName() - => nameCleaner.Replace(this.Name, string.Empty).Trim(); + => nameCleaner.Replace(Name, string.Empty).Trim(); private static void addChildrenOptionHudString( ref StringBuilder builder, diff --git a/ExtremeRoles/Module/CustomOption/SelectionOption.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/SelectionOption.cs similarity index 96% rename from ExtremeRoles/Module/CustomOption/SelectionOption.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/SelectionOption.cs index 45429fb78..1c2d97027 100644 --- a/ExtremeRoles/Module/CustomOption/SelectionOption.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/SelectionOption.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace ExtremeRoles.Module.CustomOption; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented; public sealed class SelectionCustomOption : CustomOptionBase { diff --git a/ExtremeRoles/Module/CustomOption/TypeOptionHolder.cs b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/TypeOptionHolder.cs similarity index 64% rename from ExtremeRoles/Module/CustomOption/TypeOptionHolder.cs rename to ExtremeRoles/Module/CustomOption/OLDS/Implemented/TypeOptionHolder.cs index cde9d1350..308510f6f 100644 --- a/ExtremeRoles/Module/CustomOption/TypeOptionHolder.cs +++ b/ExtremeRoles/Module/CustomOption/OLDS/Implemented/TypeOptionHolder.cs @@ -4,7 +4,7 @@ #nullable enable -namespace ExtremeRoles.Module.CustomOption; +namespace ExtremeRoles.Module.CustomOption.OLDS.Implemented; public sealed class TypeOptionHolder : IEnumerable>> where T : @@ -13,24 +13,24 @@ public sealed class TypeOptionHolder : IEnumerable> option = new Dictionary>(); - public IValueOption Get(int id) => this.option[id]; + public IValueOption Get(int id) => option[id]; - public bool ContainsKey(int id) => this.option.ContainsKey(id); + public bool ContainsKey(int id) => option.ContainsKey(id); public void Add(int id, IValueOption newOption) - => this.option.Add(id, newOption); + => option.Add(id, newOption); public void Update(int id, int selectionIndex) { - lock (this.option) + lock (option) { - this.option[id].UpdateSelection(selectionIndex); + option[id].UpdateSelection(selectionIndex); } } public IEnumerator>> GetEnumerator() => - this.option.GetEnumerator(); + option.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => - this.option.GetEnumerator(); + option.GetEnumerator(); } diff --git a/ExtremeRoles/Module/CustomOption/OLDS/NamePrefix.cs b/ExtremeRoles/Module/CustomOption/OLDS/NamePrefix.cs new file mode 100644 index 000000000..c020a27aa --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/OLDS/NamePrefix.cs @@ -0,0 +1,14 @@ +using ExtremeRoles.Roles; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ExtremeRoles.Module.CustomOption.OLDS; + +public static class NamePrefix +{ + public static string SidekickOptionPrefix => ExtremeRoleId.Sidekick.ToString(); + public static string DetectiveApprenticeOptionPrefix => ExtremeRoleId.DetectiveApprentice.ToString(); +} diff --git a/ExtremeRoles/Module/CustomOption/OLDS/RoleGlobalOption.cs b/ExtremeRoles/Module/CustomOption/OLDS/RoleGlobalOption.cs new file mode 100644 index 000000000..4900afb11 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/OLDS/RoleGlobalOption.cs @@ -0,0 +1,20 @@ +namespace ExtremeRoles.Module.CustomOption.OLDS; + +public enum RoleGlobalOption : int +{ + MinCrewmateRoles = 10, + MaxCrewmateRoles, + MinNeutralRoles, + MaxNeutralRoles, + MinImpostorRoles, + MaxImpostorRoles, + + MinCrewmateGhostRoles, + MaxCrewmateGhostRoles, + MinNeutralGhostRoles, + MaxNeutralGhostRoles, + MinImpostorGhostRoles, + MaxImpostorGhostRoles, + + UseXion, +} \ No newline at end of file diff --git a/ExtremeRoles/Module/CustomOption/OptionCategory.cs b/ExtremeRoles/Module/CustomOption/OptionCategory.cs new file mode 100644 index 000000000..e315035f7 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/OptionCategory.cs @@ -0,0 +1,212 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Runtime.CompilerServices; + +using System.Text; + +using UnityEngine; + + + +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Extension; +using System.Diagnostics.CodeAnalysis; +using ExtremeRoles.Helper; + +#nullable enable + +namespace ExtremeRoles.Module.CustomOption; + +public sealed class OptionLoadWrapper(in OptionCategory category, int idOffset) : IOptionLoader +{ + private readonly OptionCategory category = category; + private readonly int idOffset = idOffset; + + public bool TryGet(int id, [NotNullWhen(true)] out IOption? option) + => this.TryGet(id + idOffset, out option); + public IOption Get(T id) where T : Enum + => this.category.Get(id.FastInt() + idOffset); + + public bool TryGetValueOption(W id, [NotNullWhen(true)] out IValueOption? option) + where W : Enum + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.category.TryGetValueOption(id.FastInt() + idOffset, out option); + public bool TryGetValueOption(int id, [NotNullWhen(true)] out IValueOption? option) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.category.TryGetValueOption(id + idOffset, out option); + + public IValueOption GetValueOption(W id) + where W : Enum + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.category.GetValueOption(id.FastInt() + idOffset); + public IValueOption GetValueOption(int id) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.category.GetValueOption(id + idOffset); + + public T GetValue(W id) where W : Enum + => this.category.GetValue(id.FastInt() + idOffset); + public T GetValue(int id) + => this.category.GetValue(id + idOffset); +} + +public sealed class OptionCategory( + OptionTab tab, + int id, + string name, + in OptionPack option, + in Color? color = null) : IOptionLoader +{ + public Color? Color { get; } = color; + + public IEnumerable Options => allOpt.Values; + public int Count => allOpt.Count; + + public OptionTab Tab { get; } = tab; + public int Id { get; } = id; + public string Name { get; } = name; + public string TransedName => Translation.GetString(Name); + + public bool IsDirty { get; set; } = false; + + private readonly IReadOnlyDictionary> intOpt = option.IntOptions; + private readonly IReadOnlyDictionary> floatOpt = option.FloatOptions; + private readonly IReadOnlyDictionary> boolOpt = option.BoolOptions; + private readonly IReadOnlyDictionary allOpt = option.AllOptions; + + public void AddHudString(in StringBuilder builder) + { + builder.Append($"・OptionCategory: {this.TransedName}"); + + foreach (var option in this.allOpt.Values) + { + if (!option.IsActiveAndEnable) + { + continue; + } + + builder.AppendLine($"{option.Title}: {option.ValueString}"); + } + } + public bool TryGet(int id, [NotNullWhen(true)] out IOption? option) + => this.allOpt.TryGetValue(id, out option) && option is not null; + public IOption Get(T id) where T : Enum + => this.Get(id.FastInt()); + + public bool TryGetValueOption(W id, [NotNullWhen(true)] out IValueOption? option) + where W : Enum + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.TryGetValueOption(id.FastInt(), out option); + + public bool TryGetValueOption(int id, [NotNullWhen(true)] out IValueOption? option) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + { + option = null; + if (!this.allOpt.ContainsKey(id)) { return false; } + + if (typeof(T) == typeof(int)) + { + var intOption = this.intOpt[id]; + option = Unsafe.As, IValueOption>(ref intOption); + return option is not null; + } + else if (typeof(T) == typeof(float)) + { + var floatOption = this.floatOpt[id]; + option = Unsafe.As, IValueOption>(ref floatOption); + return option is not null; + } + else if (typeof(T) == typeof(bool)) + { + var boolOption = this.boolOpt[id]; + option = Unsafe.As, IValueOption>(ref boolOption); + return option is not null; + } + else + { + throw new ArgumentException("Cannot Find Options"); + } + } + + public IValueOption GetValueOption(W id) + where W : Enum + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + => this.GetValueOption(id.FastInt()); + + public IValueOption GetValueOption(int id) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + { + if (typeof(T) == typeof(int)) + { + var intOption = this.intOpt[id]; + return Unsafe.As, IValueOption>(ref intOption); + } + else if (typeof(T) == typeof(float)) + { + var floatOption = this.floatOpt[id]; + return Unsafe.As, IValueOption>(ref floatOption); + } + else if (typeof(T) == typeof(bool)) + { + var boolOption = this.boolOpt[id]; + return Unsafe.As, IValueOption>(ref boolOption); + } + else + { + throw new ArgumentException($"OptionId: {id} Not Found"); + } + } + + public IOption Get(int id) + { + if (!TryGet(id, out var option)) + { + throw new ArgumentException($"OptionId: {id} Not Found"); + } + return option; + } + public T GetValue(W id) where W : Enum + => this.GetValue(id.FastInt()); + + public T GetValue(int id) + { + if (typeof(T) == typeof(int)) + { + var intOption = this.intOpt[id]; + int intValue = intOption.Value; + return Unsafe.As(ref intValue); + } + else if (typeof(T) == typeof(float)) + { + var floatOption = this.floatOpt[id]; + float floatValue = floatOption.Value; + return Unsafe.As(ref floatValue); + } + else if (typeof(T) == typeof(bool)) + { + var boolOption = this.boolOpt[id]; + bool boolValue = boolOption.Value; + return Unsafe.As(ref boolValue); + } + else + { + throw new ArgumentException($"OptionId: {typeof(T)} Not Found"); + } + } +} diff --git a/ExtremeRoles/Module/CustomOption/OptionManager.cs b/ExtremeRoles/Module/CustomOption/OptionManager.cs index 4786f9bd9..dc5240b59 100644 --- a/ExtremeRoles/Module/CustomOption/OptionManager.cs +++ b/ExtremeRoles/Module/CustomOption/OptionManager.cs @@ -1,368 +1,295 @@ -using Hazel; -using System; +using System; +using System.Collections; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Linq; +using System.Diagnostics.CodeAnalysis; using UnityEngine; +using Hazel; using ExtremeRoles.Helper; +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Module.CustomOption.Factory; using ExtremeRoles.GameMode; -using ExtremeRoles.Module.RoleAssign; +using ExtremeRoles.Extension; using ExtremeRoles.Performance; -namespace ExtremeRoles.Module.CustomOption; #nullable enable -public sealed class OptionManager + +namespace ExtremeRoles.Module.CustomOption; + +public sealed class OptionManager : IEnumerable> { - public enum ValueType : byte - { - Int, - Float, - Bool - } + public readonly static OptionManager Instance = new (); + + private readonly Dictionary options = new (); public string ConfigPreset { get => $"Preset:{selectedPreset}"; } - - public int Count => this.allOptionId.Count; - - public readonly static OptionManager Instance = new OptionManager(); - - private Dictionary allOptionId = new Dictionary(); - private TypeOptionHolder intOption = new TypeOptionHolder(); - private TypeOptionHolder floatOption = new TypeOptionHolder(); - private TypeOptionHolder boolOption = new TypeOptionHolder(); - private int selectedPreset = 0; - - private const int chunkSize = 50; - - private const int defaultStep = 1; private const int skipStep = 10; - // ジェネリック化をJIT化する時にtypeofの比較がどうやら定数比較になり必ずtrueになる部分とfalseになる部分が決定するらしい - // それによってメソッドが特殊化されfalseの部分がJITの最適化時に削除、常にtrueの部分はifが消されるので非常に簡潔なILになる(ここはまぁコンパイラの授業で習った) - // https://qiita.com/aka-nse/items/2f45f056262d2d5c6df7#comment-a8e1c1c3e9e7a0208068 - // 実際に測ったらUnsafe.Asを使わないas キャストを使ってるのに2倍近く早かった・・・・ - + private const int chunkSize = 50; - public void Add(int id, IValueOption option) - { - this.floatOption.Add(id, option); - this.allOptionId.Add(id, ValueType.Float); - } - public void Add(int id, IValueOption option) + private OptionManager() { - this.intOption.Add(id, option); - this.allOptionId.Add(id, ValueType.Int); + foreach (var tab in Enum.GetValues()) + { + options.Add(tab, new OptionTabContainer(tab)); + } } - public void Add(int id, IValueOption option) + + public static void Load() { - this.boolOption.Add(id, option); - this.allOptionId.Add(id, ValueType.Bool); + // ランダム生成機を設定を読み込んで作成 + RandomGenerator.Initialize(); + + // ゲームモードのオプションロード + ExtremeGameModeManager.Instance.Load(); + + // 各役職を設定を読み込んで初期化する + Roles.ExtremeRoleManager.Initialize(); + GhostRoles.ExtremeGhostRoleManager.Initialize(); + + // 各種マップモジュール等のオプション値を読み込む + Patches.MiniGame.VitalsMinigameUpdatePatch.LoadOptionValue(); + Patches.MiniGame.SecurityHelper.LoadOptionValue(); + Patches.MapOverlay.MapCountOverlayUpdatePatch.LoadOptionValue(); + + MeetingReporter.Reset(); } - public void AddOption(int id, IValueOption option) - where SelectionType : - struct, IComparable, IConvertible, - IComparable, IEquatable + public static void ShareOption(in MessageReader reader) { - if (typeof(SelectionType) == typeof(int)) - { - Add(id, Unsafe.As, IValueOption>(ref option)); - } - else if (typeof(SelectionType) == typeof(float)) - { - Add(id, Unsafe.As, IValueOption>(ref option)); - } - else if (typeof(SelectionType) == typeof(bool)) + try { - Add(id, Unsafe.As, IValueOption>(ref option)); + bool isShow = reader.ReadByte() == byte.MinValue; + OptionTab tab = (OptionTab)reader.ReadByte(); + int categoryId = reader.ReadPackedInt32(); + Instance.syncOption( + isShow, tab, categoryId, reader); } - else + catch (Exception e) { - throw new ArgumentException("Cannot Add Options"); + Logging.Error($"Error while deserializing options:{e.Message}"); } } - public bool Contains(int id) => this.allOptionId.ContainsKey(id); + public IEnumerator> GetEnumerator() => this.options.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() { throw new Exception(); } - public bool TryGet(int id, out IValueOption? option) - where T : - struct, IComparable, IConvertible, - IComparable, IEquatable - { - option = null; - if (!this.allOptionId.ContainsKey(id)) { return false; } + public bool TryGetTab(OptionTab tab, [NotNullWhen(true)] out OptionTabContainer? container) + => this.options.TryGetValue(tab, out container) && container is not null; - if (typeof(T) == typeof(int)) - { - var intOption = this.intOption.Get(id); - option = Unsafe.As, IValueOption>(ref intOption); - return true; - } - else if (typeof(T) == typeof(float)) - { - var floatOption = this.floatOption.Get(id); - option = Unsafe.As, IValueOption>(ref floatOption); - return true; - } - else if (typeof(T) == typeof(bool)) - { - var boolOption = this.boolOption.Get(id); - option = Unsafe.As, IValueOption>(ref boolOption); - return true; - } - else - { - throw new ArgumentException("Cannot Find Options"); - } + public bool TryGetCategory(OptionTab tab, int categoryId, [NotNullWhen(true)] out OptionCategory? category) + { + category = null; + return this.TryGetTab(tab, out var container) && container.TryGetCategory(categoryId, out category) && category is not null; } - public bool TryGetIOption(int id, out IOptionInfo? option) + public static OptionCategoryFactory CreateOptionCategory( + int id, + string name, + in OptionTab tab = OptionTab.General, + in Color? color = null) { - option = null; - if (!this.allOptionId.TryGetValue(id, out ValueType type)) { return false; } + var factory = new OptionCategoryFactory(name, id, Instance.registerOptionGroup, tab, color); - option = type switch - { - ValueType.Int => this.intOption.Get(id), - ValueType.Float => this.floatOption.Get(id), - ValueType.Bool => this.boolOption.Get(id), - _ => null - }; - return true; + return factory; } - - public IValueOption Get(int id) - where T : - struct, IComparable, IConvertible, - IComparable, IEquatable + public static OptionCategoryFactory CreateOptionCategory( + T option, + in OptionTab tab = OptionTab.General, + in Color? color = null) where T : Enum + => CreateOptionCategory( + option.FastInt(), + option.ToString(), tab, color); + + public static SequentialOptionCategoryFactory CreateSequentialOptionCategory( + int id, + string name, + in OptionTab tab = OptionTab.General, + in Color? color = null) { - if (typeof(T) == typeof(int)) - { - var intOption = this.intOption.Get(id); - return Unsafe.As, IValueOption>(ref intOption); - } - else if (typeof(T) == typeof(float)) - { - var floatOption = this.floatOption.Get(id); - return Unsafe.As, IValueOption>(ref floatOption); - } - else if (typeof(T) == typeof(bool)) - { - var boolOption = this.boolOption.Get(id); - return Unsafe.As, IValueOption>(ref boolOption); - } - else - { - throw new ArgumentException("Cannot Find Options"); - } + var factory = new SequentialOptionCategoryFactory(name, id, Instance.registerOptionGroup, tab, color); + + return factory; } - public IEnumerable> GetKeyValueAllIOptions() + public static AutoParentSetOptionCategoryFactory CreateAutoParentSetOptionCategory( + int id, + string name, + in OptionTab tab, + in Color? color = null, + in IOption? parent = null) { - foreach (var (id, key) in this.allOptionId) - { - IOptionInfo info = key switch - { - ValueType.Int => this.intOption.Get(id), - ValueType.Float => this.floatOption.Get(id), - ValueType.Bool => this.boolOption.Get(id), - _ => throw new ArgumentException("Invalided Option Id"), - }; - yield return new KeyValuePair(id, info); - } + var internalFactory = CreateOptionCategory(id, name, tab, color); + var factory = new AutoParentSetOptionCategoryFactory(internalFactory, parent); + + return factory; } - public IEnumerable GetAllIOption() + public static AutoParentSetOptionCategoryFactory CreateAutoParentSetOptionCategory( + T option, + in OptionTab tab = OptionTab.General, + in Color? color = null, + in IOption? parent = null) where T : Enum + => CreateAutoParentSetOptionCategory( + option.FastInt(), + option.ToString(), + tab, color, parent); + + public void UpdateToStep(in OptionCategory category, in int id, int step) { - foreach (var (id, key) in this.allOptionId) - { - yield return key switch - { - ValueType.Int => this.intOption.Get(id), - ValueType.Float => this.floatOption.Get(id), - ValueType.Bool => this.boolOption.Get(id), - _ => throw new ArgumentException("Invalided Option Id"), - }; - } + var option = category.Get(id); + UpdateToStep(category, option, step); } - public IOptionInfo GetIOption(int id) - => this.allOptionId[id] switch - { - ValueType.Int => this.intOption.Get(id), - ValueType.Float => this.floatOption.Get(id), - ValueType.Bool => this.boolOption.Get(id), - _ => throw new ArgumentException("Invalided Option Id"), - }; - - public T GetValue(int id) - where T : - struct, IComparable, IConvertible, - IComparable, IEquatable + public void UpdateToStep(in OptionCategory category, in IOption option, int step) { - if (typeof(T) == typeof(int)) - { - var intOption = this.intOption.Get(id); - int intValue = intOption.GetValue(); - return Unsafe.As(ref intValue); - } - else if (typeof(T) == typeof(float)) - { - var floatOption = this.floatOption.Get(id); - float floatValue = floatOption.GetValue(); - return Unsafe.As(ref floatValue); - } - else if (typeof(T) == typeof(bool)) - { - var boolOption = this.boolOption.Get(id); - bool boolValue = boolOption.GetValue(); - return Unsafe.As(ref boolValue); - } - else + int newSelection = option.Selection + (Key.IsShift() ? step * skipStep : step); + if (Key.IsControlDown()) { - return default(T); + newSelection = newSelection > 0 ? option.Range - 1 : 0; } + Update(category, option, newSelection); } - public void ChangeOptionValue(int id, bool isIncrese) + public void Update(in OptionCategory category, in int id, int newIndex) { - var option = GetIOption(id); - - int curSelection = option.CurSelection; - int step = Key.IsShift() ? skipStep : defaultStep; - int newSelection = isIncrese ? curSelection + step : curSelection - step; - if (Key.IsControlDown()) - { - newSelection = isIncrese ? option.ValueCount - 1 : 0; - } + var option = category.Get(id); + Update(category, option, newIndex); + } - option.UpdateSelection(newSelection); + public void Update(in OptionCategory category, in IOption option, int newIndex) + { + option.Selection = newIndex; - if (id == 0) + int id = option.Info.Id; + if (category.Id == 0 && id == 0) { - SwitchPreset(newSelection); + // プリセット切り替え + switchPreset(); + ShereAllOption(); } - - if (AmongUsClient.Instance && - AmongUsClient.Instance.AmHost && - CachedPlayerControl.LocalPlayer) + else { - ShareOptionSelections();// Share all selections + shareOptionCategory(category); + category.IsDirty = true; } } - public void ShareOptionSelections() + public void ShereAllOption() { - if (PlayerControl.AllPlayerControls.Count <= 1 || - !AmongUsClient.Instance || - !AmongUsClient.Instance.AmHost || - !PlayerControl.LocalPlayer) { return; } - - shareOption(this.intOption); - shareOption(this.floatOption); - shareOption(this.boolOption); + foreach (var tabContainer in this.options.Values) + { + foreach (var category in tabContainer.Category) + { + shareOptionCategory(category, false); + } + } } - public void SwitchPreset(int newPreset) + private void registerOptionGroup(OptionTab tab, OptionCategory group) { - this.selectedPreset = newPreset; - - foreach (var (_, option) in this.GetKeyValueAllIOptions()) + if (!this.options.TryGetValue(tab, out var container)) { - if (option.Id == 0) { continue; } - option.SwitchPreset(); + throw new ArgumentException($"Tab {tab} is not registered."); } - - ShareOptionSelections(); - RoleAssignFilter.Instance.SwitchPreset(); + container.AddGroup(group); } - private void rpcValueSync(int id, int selection) + private static void shareOptionCategory( + in OptionCategory category, bool isShow = true) { - if (!this.allOptionId.TryGetValue(id, out ValueType type)) { return; } + int size = category.Count; - switch (type) + if (size <= chunkSize) + { + shareOptionCategoryWithSize(category, size, isShow); + } + else { - case ValueType.Int: - this.intOption.Update(id, selection); - break; - case ValueType.Float: - this.floatOption.Update(id, selection); - break; - case ValueType.Bool: - this.boolOption.Update(id, selection); - break; - default: - break; - }; + int mod = size; + do + { + shareOptionCategoryWithSize(category, chunkSize, isShow); + mod -= chunkSize; + } while (mod > chunkSize); + shareOptionCategoryWithSize(category, mod, isShow); + } } - public static void Load() + private static void shareOptionCategoryWithSize( + in OptionCategory category, int size, bool isShow=true) { - // ランダム生成機を設定を読み込んで作成 - RandomGenerator.Initialize(); - - // ゲームモードのオプションロード - ExtremeGameModeManager.Instance.Load(); - - // 各役職を設定を読み込んで初期化する - Roles.ExtremeRoleManager.Initialize(); - GhostRoles.ExtremeGhostRoleManager.Initialize(); - - // 各種マップモジュール等のオプション値を読み込む - Patches.MiniGame.VitalsMinigameUpdatePatch.LoadOptionValue(); - Patches.MiniGame.SecurityHelper.LoadOptionValue(); - Patches.MapOverlay.MapCountOverlayUpdatePatch.LoadOptionValue(); - - MeetingReporter.Reset(); + using (var caller = RPCOperator.CreateCaller( + RPCOperator.Command.ShareOption)) + { + caller.WriteByte(isShow ? byte.MinValue : byte.MaxValue); + caller.WriteByte((byte)category.Tab); + caller.WritePackedInt(category.Id); + caller.WriteByte((byte)size); + foreach (var option in category.Options) + { + caller.WritePackedInt(option.Info.Id); + caller.WritePackedInt(option.Selection); + } + } } - public static void ShareOption(int numberOfOptions, MessageReader reader) + private void syncOption( + bool isShow, + OptionTab tab, int categoryId, + in MessageReader reader) { - try + lock(this.options) { - for (int i = 0; i < numberOfOptions; i++) + StringNames key = (StringNames)5000; + + if (!this.options.TryGetValue(tab, out var container) || + !container.TryGetCategory(categoryId, out var category)) { - int optionId = reader.ReadPackedInt32(); + return; + } + int size = reader.ReadPackedInt32(); + for (int i = 0; i < size; i++) + { + int id = reader.ReadPackedInt32(); int selection = reader.ReadPackedInt32(); - Instance.rpcValueSync(optionId, selection); + if (!category.TryGet(id, out var option)) + { + continue; + } + int curSelection = option.Selection; + option.Selection = selection; + + // 値が変更されたのでポップアップ通知 + if (isShow && curSelection != option.Selection) + { + FastDestroyableSingleton.Instance.Notifier.AddSettingsChangeMessage( + key, $"[{tab}-{category.TransedName}]の{option.Title}が{option.ValueString}に更新されました"); + key++; + } } - } - catch (Exception e) - { - Logging.Error($"Error while deserializing options:{e.Message}"); + category.IsDirty = true; } } - private static void shareOption(TypeOptionHolder holder) - where T : - struct, IComparable, IConvertible, - IComparable, IEquatable + private void switchPreset() { - var splitOption = holder.Select((x, i) => - new { data = x, indexgroup = i / chunkSize }) - .GroupBy(x => x.indexgroup, x => x.data) - .Select(y => y.Select(x => x)); - - foreach (var chunkedOption in splitOption) + foreach (var tab in this.options.Values) { - using (var caller = RPCOperator.CreateCaller( - RPCOperator.Command.ShareOption)) + foreach (var category in tab.Category) { - caller.WriteByte((byte)chunkedOption.Count()); - foreach (var (id, option) in chunkedOption) + foreach (var option in category.Options) { - caller.WritePackedInt(id); - caller.WritePackedInt(option.CurSelection); + option.SwitchPreset(); } + category.IsDirty = true; } } } diff --git a/ExtremeRoles/Module/CustomOption/OptionPack.cs b/ExtremeRoles/Module/CustomOption/OptionPack.cs new file mode 100644 index 000000000..5c059890a --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/OptionPack.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +using ExtremeRoles.Module.CustomOption.Interfaces; + +namespace ExtremeRoles.Module.CustomOption; + +public sealed class OptionPack +{ + public IReadOnlyDictionary> IntOptions => intOpt; + public IReadOnlyDictionary> FloatOptions => floatOpt; + public IReadOnlyDictionary> BoolOptions => boolOpt; + public IReadOnlyDictionary AllOptions => allOpt; + + private readonly Dictionary> intOpt = new Dictionary>(); + private readonly Dictionary> floatOpt = new Dictionary>(); + private readonly Dictionary> boolOpt = new Dictionary>(); + private readonly Dictionary allOpt = new Dictionary(); + + public IOption Get(int id) => this.allOpt[id]; + public IValueOption Get(int id) + where T : + struct, IComparable, IConvertible, + IComparable, IEquatable + { + if (typeof(T) == typeof(int)) + { + var intOption = this.intOpt[id]; + return Unsafe.As, IValueOption>(ref intOption); + } + else if (typeof(T) == typeof(float)) + { + var floatOption = this.floatOpt[id]; + return Unsafe.As, IValueOption>(ref floatOption); + } + else if (typeof(T) == typeof(bool)) + { + var boolOption = this.boolOpt[id]; + return Unsafe.As, IValueOption>(ref boolOption); + } + else + { + throw new ArgumentException("Cannot Find Options"); + } + } + + public void Add(int id, IValueOption option) + { + this.floatOpt.Add(id, option); + this.allOpt.Add(id, option); + } + public void Add(int id, IValueOption option) + { + this.intOpt.Add(id, option); + this.allOpt.Add(id, option); + } + public void Add(int id, IValueOption option) + { + this.boolOpt.Add(id, option); + this.allOpt.Add(id, option); + } + + public void AddOption(int id, IValueOption option) + where SelectionType : + struct, IComparable, IConvertible, + IComparable, IEquatable + { + if (typeof(SelectionType) == typeof(int)) + { + Add(id, Unsafe.As, IValueOption>(ref option)); + } + else if (typeof(SelectionType) == typeof(float)) + { + Add(id, Unsafe.As, IValueOption>(ref option)); + } + else if (typeof(SelectionType) == typeof(bool)) + { + Add(id, Unsafe.As, IValueOption>(ref option)); + } + else + { + throw new ArgumentException("Cannot Add Options"); + } + } +} diff --git a/ExtremeRoles/Module/CustomOption/OptionTabContainer.cs b/ExtremeRoles/Module/CustomOption/OptionTabContainer.cs new file mode 100644 index 000000000..4d70bb311 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/OptionTabContainer.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace ExtremeRoles.Module.CustomOption; + +public sealed class OptionTabContainer(OptionTab tab) +{ + public string Name { get; } = tab.ToString(); + public int Count => this.allCategory.Count; + + public IEnumerable Category => this.allCategory.Values; + private readonly Dictionary allCategory = new (); + + public bool TryGetCategory(int id, [NotNullWhen(true)] out OptionCategory category) + => this.allCategory.TryGetValue(id, out category) && category != null; + + public void AddGroup(in OptionCategory category) + => this.allCategory.Add(category.Id, category); +} diff --git a/ExtremeRoles/Module/CustomOption/View/OptionGroupViewObject.cs b/ExtremeRoles/Module/CustomOption/View/OptionGroupViewObject.cs new file mode 100644 index 000000000..6499e6523 --- /dev/null +++ b/ExtremeRoles/Module/CustomOption/View/OptionGroupViewObject.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +using UnityEngine; + +namespace ExtremeRoles.Module.CustomOption.View; + +public sealed class OptionGroupViewObject(in CategoryHeaderMasked categoryObj, int capacity) where T : MonoBehaviour +{ + public CategoryHeaderMasked Category { get; } = categoryObj; + public List Options { get; } = new(capacity); +} diff --git a/ExtremeRoles/Module/CustomOptionProcessor.cs b/ExtremeRoles/Module/CustomOptionProcessor.cs index 9841b7190..7eca7f762 100644 --- a/ExtremeRoles/Module/CustomOptionProcessor.cs +++ b/ExtremeRoles/Module/CustomOptionProcessor.cs @@ -5,11 +5,14 @@ using System.Text; using System.Text.RegularExpressions; -using ExtremeRoles.Module.CustomOption; + using AmongUs.GameOptions; using ExtremeRoles.Module.RoleAssign; using ExtremeRoles.Performance; +using ExtremeRoles.Extension.Il2Cpp; + +#nullable enable namespace ExtremeRoles.Module; @@ -21,7 +24,7 @@ public static class CustomOptionCsvProcessor private const string vanilaOptionKey = "BytedVanillaOptions"; private const string comma = ","; - private const int curVersion = 7; + private const int curVersion = 8; private sealed class StringCleaner { @@ -53,19 +56,27 @@ public static bool Export() string.Format("{1}{0}{2}{0}{3}{0}{4}", comma, "Name", "OptionValue", "CustomOptionName", "SelectedIndex")); //ヘッダー - - foreach (IOptionInfo option in OptionManager.Instance.GetAllIOption()) + foreach (var (tab, tabContainer) in OptionManager.Instance) { - - if (option.Id == 0) { continue; } - - csv.WriteLine( - string.Format("{1}{0}{2}{0}{3}{0}{4}", - comma, - cleaner.Clean(option.GetTranslatedName()), - cleaner.Clean(option.GetTranslatedValue()), - cleaner.Clean(option.Name), - option.CurSelection)); + foreach (var cate in tabContainer.Category) + { + if (cate.Id == 0 && + tab is OptionTab.General) + { + continue; + } + + foreach (var option in cate.Options) + { + csv.WriteLine( + string.Format("{1}{0}{2}{0}{3}{0}{4}", + comma, + cleaner.Clean(option.Title), + cleaner.Clean(option.ValueString), + cleaner.Clean(option.Info.Name), + option.Selection)); + } + } } csv.WriteLine( @@ -83,9 +94,9 @@ public static bool Export() "{1}{0}{1}", comma, string.Empty)); var gameOptionManager = GameOptionsManager.Instance; - foreach (GameModes gameMode in Enum.GetValues(typeof(GameModes))) + foreach (GameModes gameMode in Enum.GetValues()) { - IGameOptions option = gameMode switch + IGameOptions? option = gameMode switch { GameModes.Normal or GameModes.NormalFools => gameOptionManager.normalGameHostOptions.Cast(), @@ -117,13 +128,33 @@ public static bool Import() { using var csv = new StreamReader(csvName, new UTF8Encoding(true)); - string infoData = csv.ReadLine(); // verHeader + if (csv is null) + { + return false; + } + + string? infoData = csv.ReadLine(); // verHeader + if (infoData is null) + { + return false; + } + string[] info = infoData.Split(comma); + string exrVersion = info[2]; + exrVersion = exrVersion.Replace("ExtremeRoles ver.", ""); + if (!Version.TryParse(exrVersion, out var version) || + version is null || + version.Major <= 10) + { + ExtremeRolesPlugin.Logger.LogError( + $"Can't load v11 below options data, wait for next update."); + return false; + } ExtremeRolesPlugin.Logger.LogInfo( - $"Loading from {info[1]} with {info[2]} {info[3]} Data"); + $"Loading from {info[1]} with {exrVersion} {info[3]} Data"); - string line = csv.ReadLine(); // ヘッダー + string? line = csv.ReadLine(); // ヘッダー while ((line = csv.ReadLine()) != null) { string[] option = line.Split(comma); @@ -135,7 +166,8 @@ public static bool Import() case vanilaOptionKey: GameModes mode = (GameModes)Enum.Parse(typeof(GameModes), option[1]); if (!importedVanillaOptions.TryGetValue( - mode, out List modeOption)) + mode, out var modeOption) && + modeOption is null) { modeOption = new List(); importedVanillaOptions.Add(mode, modeOption); @@ -166,29 +198,19 @@ public static bool Import() { case GameModes.Normal: case GameModes.NormalFools: - NormalGameOptionsV07 normalOption = option.Cast(); - - if (option.Version < curVersion) + if (!option.IsTryCast(out var normalOption)) { normalOption = gameOptionManager.MigrateNormalGameOptions(option); } - - if (normalOption == null) { continue; } - gameOptionManager.normalGameHostOptions = normalOption; gameOptionManager.SaveNormalHostOptions(); break; case GameModes.HideNSeek: case GameModes.SeekFools: - HideNSeekGameOptionsV07 hideNSeekOption = option.Cast(); - - if (option.Version < curVersion) + if (!option.IsTryCast(out var hideNSeekOption)) { hideNSeekOption = gameOptionManager.MigrateHideNSeekGameOptions(option); } - - if (hideNSeekOption == null) { continue; } - gameOptionManager.hideNSeekGameHostOptions = hideNSeekOption; gameOptionManager.SaveHideNSeekHostOptions(); break; @@ -196,30 +218,37 @@ public static bool Import() break; } } - - var options = OptionManager.Instance; + var optionMng = OptionManager.Instance; var cleaner = new StringCleaner(); - foreach (IOptionInfo option in options.GetAllIOption()) + foreach (var (tab, tabContainer) in optionMng) { - if (option.Id == 0) { continue; } - - if (importedOption.TryGetValue( - cleaner.Clean(option.Name), - out int selection)) + foreach (var cate in tabContainer.Category) { - ExtremeRolesPlugin.Logger.LogInfo( - $"Update Option : {option.Name} to Selection:{selection}"); - option.UpdateSelection(selection); - option.SaveConfigValue(); + if (cate.Id == 0 && tab is OptionTab.General) { continue; } + + foreach (var option in cate.Options) + { + string name = option.Info.Name; + if (!importedOption.TryGetValue( + cleaner.Clean(name), + out int selection)) + { + continue; + } + + ExtremeRolesPlugin.Logger.LogInfo( + $"Update Option : {name} to Selection:{selection}"); + + option.Selection = selection; + } } } - - if (AmongUsClient.Instance && + if (AmongUsClient.Instance != null && AmongUsClient.Instance.AmHost && - CachedPlayerControl.LocalPlayer) + CachedPlayerControl.LocalPlayer != null) { - options.ShareOptionSelections();// Share all selections + optionMng.ShereAllOption();// Share all selections } ExtremeRolesPlugin.Logger.LogInfo("---------- Option Import Complete ----------"); diff --git a/ExtremeRoles/Module/ExtremeGameResult.cs b/ExtremeRoles/Module/ExtremeGameResult.cs index 55144dc1d..d17255d12 100644 --- a/ExtremeRoles/Module/ExtremeGameResult.cs +++ b/ExtremeRoles/Module/ExtremeGameResult.cs @@ -15,8 +15,8 @@ using ExtremeRoles.Performance.Il2Cpp; -using TempWinData = Il2CppSystem.Collections.Generic.List; -using Player = GameData.PlayerInfo; +using TempWinData = Il2CppSystem.Collections.Generic.List; +using Player = NetworkedPlayerInfo; #nullable enable @@ -25,18 +25,18 @@ namespace ExtremeRoles.Module; public sealed class ExtremeGameResult : NullableSingleton { public readonly record struct WinnerResult( - IReadOnlyList Winner, + IReadOnlyList Winner, IReadOnlyList PlusedWinner); public readonly record struct TaskInfo(int CompletedTask, int TotalTask); public class WinnerTempData { - public TempWinData DefaultWinPlayer => TempData.winners; + public TempWinData DefaultWinPlayer => EndGameResult.CachedWinners; public IReadOnlyList PlusedWinner => this.plusWinPlayr; - private readonly Dictionary allWinnerPool = new Dictionary(); - private readonly List finalWinPlayer = new List(); + private readonly Dictionary allWinnerPool = new Dictionary(); + private readonly List finalWinPlayer = new List(); private readonly List plusWinPlayr = new List(); public void SetWinner() @@ -93,7 +93,7 @@ public void RemoveAll(Player playerInfo) this.plusWinPlayr.RemoveAll(x => x.PlayerName == playerInfo.PlayerName); Remove(playerInfo); } - public void Remove(WinningPlayerData player) + public void Remove(CachedPlayerData player) { this.finalWinPlayer.RemoveAll(x => x.PlayerName == player.PlayerName); } @@ -125,7 +125,7 @@ public void AddPlusWinner(Player player) public void AddPool(Player playerInfo) { - WinningPlayerData wpd = new WinningPlayerData(playerInfo); + CachedPlayerData wpd = new CachedPlayerData(playerInfo); this.allWinnerPool.Add(playerInfo.PlayerId, wpd); } diff --git a/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Roles.cs b/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Roles.cs index 382ca7e72..5608c8d22 100644 --- a/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Roles.cs +++ b/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Roles.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using ExtremeRoles.Module.CustomMonoBehaviour; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.Solo.Crewmate; @@ -26,8 +26,6 @@ public sealed partial class ExtremeShipStatus public void AddGlobalActionRole(SingleRoleBase role) { - var allOpt = OptionManager.Instance; - switch (role.Id) { case ExtremeRoleId.Assassin: diff --git a/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Win.cs b/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Win.cs index a24e59c0e..65a20ef7f 100644 --- a/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Win.cs +++ b/ExtremeRoles/Module/ExtremeShipStatus/ExtremeShipStatus.Win.cs @@ -11,7 +11,7 @@ public sealed partial class ExtremeShipStatus private bool disableWinCheck = false; private GameOverReason reason; private int winGameControlId = int.MaxValue; - private List plusWinner = new List(); + private List plusWinner = new List(); public void RpcRoleIsWin(byte playerId) { @@ -28,7 +28,7 @@ public void AddWinner(PlayerControl player) this.plusWinner.Add(player.Data); } - public void AddWinner(GameData.PlayerInfo player) + public void AddWinner(NetworkedPlayerInfo player) { this.plusWinner.Add(player); } @@ -38,14 +38,14 @@ public void SetDisableWinCheck(bool state) this.disableWinCheck = state; } - public List GetPlusWinner() => this.plusWinner; + public List GetPlusWinner() => this.plusWinner; public void SetGameOverReason(GameOverReason endReason) { this.reason = endReason; } - public void SetPlusWinner(List newWinner) + public void SetPlusWinner(List newWinner) { this.plusWinner = newWinner; } diff --git a/ExtremeRoles/Module/InfoOverlay/Button.cs b/ExtremeRoles/Module/InfoOverlay/Button.cs index 1dd2b5fed..df3ef9720 100644 --- a/ExtremeRoles/Module/InfoOverlay/Button.cs +++ b/ExtremeRoles/Module/InfoOverlay/Button.cs @@ -23,31 +23,23 @@ public void CreateInfoButton(System.Action openAct) this.body.name = "infoRoleButton"; this.body.SetActive(true); this.body.layer = 5; - this.body.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); - - SetInfoButtonToGameStartShipPositon(); var passiveButton = this.body.GetComponent(); passiveButton.OnClick.RemoveAllPersistentAndListeners(); passiveButton.OnClick.AddListener(openAct); - var render = this.body.GetComponent(); - render.sprite = Loader.CreateSpriteFromResources( - Path.HelpImage, 230f); - } - - public void SetInfoButtonToGameStartShipPositon() - { - if (this.body == null) { return; } - this.body.transform.localPosition = new Vector3( - 0.0f, -0.825f, 0.0f); - } - - public void SetInfoButtonToInGamePositon() - { - if (this.body == null) { return; } - this.body.SetActive(true); - this.body.transform.localPosition = new Vector3( - 0.0f, -1.75f, 0.0f); + if (passiveButton.TryGetComponent(out var aspect)) + { + Object.Destroy(aspect); + } + this.body.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); + this.body.transform.localPosition = new Vector3(-1.075f, 0.0f, 0.0f); + + passiveButton.inactiveSprites.GetComponent().sprite = Loader.CreateSpriteFromResources( + Path.HelpNoneActiveImage, 175f); + passiveButton.selectedSprites.GetComponent().sprite = Loader.CreateSpriteFromResources( + Path.HelpActiveImage, 175f); + passiveButton.activeSprites.GetComponent().sprite = Loader.CreateSpriteFromResources( + Path.HelpActiveImage, 175f); } } diff --git a/ExtremeRoles/Module/InfoOverlay/Controller.cs b/ExtremeRoles/Module/InfoOverlay/Controller.cs index 0b0e63dc8..7362a8931 100644 --- a/ExtremeRoles/Module/InfoOverlay/Controller.cs +++ b/ExtremeRoles/Module/InfoOverlay/Controller.cs @@ -53,16 +53,11 @@ public void InitializeToLobby() { this.button.CreateInfoButton(toggleView); } - else - { - this.button.SetInfoButtonToGameStartShipPositon(); - } UpdateFunc.InitializeLobby(this.model); } public void InitializeToGame() { - this.button.SetInfoButtonToInGamePositon(); if (!GameSystem.IsFreePlay) { UpdateFunc.InitializeGame(this.model); diff --git a/ExtremeRoles/Module/InfoOverlay/Model/InfoOverlayModel.cs b/ExtremeRoles/Module/InfoOverlay/Model/InfoOverlayModel.cs index 5fe6a9e9b..8e2440f79 100644 --- a/ExtremeRoles/Module/InfoOverlay/Model/InfoOverlayModel.cs +++ b/ExtremeRoles/Module/InfoOverlay/Model/InfoOverlayModel.cs @@ -7,7 +7,7 @@ namespace ExtremeRoles.Module.InfoOverlay.Model; public sealed class InfoOverlayModel { - public enum Type + public enum Type : byte { YourRolePanel, YourGhostRolePanel, diff --git a/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllGhostRoleInfoModel.cs b/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllGhostRoleInfoModel.cs index d82af27cd..95c60ff7a 100644 --- a/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllGhostRoleInfoModel.cs +++ b/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllGhostRoleInfoModel.cs @@ -4,6 +4,7 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.Module.Interface; +using ExtremeRoles.Module.CustomOption.Interfaces; namespace ExtremeRoles.Module.InfoOverlay.Model.Panel; @@ -13,7 +14,7 @@ public sealed class AllGhostRoleInfoModel : PanelPageModelBase { protected override void CreateAllRoleText() { - int optionId; + IOption option; string colorRoleName; string roleFullDesc; @@ -23,28 +24,29 @@ protected override void CreateAllRoleText() if (ghostCombRole == null) { continue; } + option = combRole.Loader.Get(RoleCommonOption.SpawnRate); + foreach (var role in ghostCombRole.CombGhostRole.Values) { - optionId = ghostCombRole.GetOptionIdOffset(); colorRoleName = role.GetColoredRoleName(); roleFullDesc = Translation.GetString($"{role.Id}FullDescription"); roleFullDesc = Design.CleanPlaceHolder(roleFullDesc); - AddPage(new RoleInfo(colorRoleName, roleFullDesc, optionId)); + AddPage(new RoleInfo(colorRoleName, roleFullDesc, option)); } } foreach (var role in GhostRoles.ExtremeGhostRoleManager.AllGhostRole.Values) { - optionId = role.OptionIdOffset; + option = role.Loader.Get(RoleCommonOption.SpawnRate); colorRoleName = role.GetColoredRoleName(); roleFullDesc = Translation.GetString($"{role.Id}FullDescription"); roleFullDesc = Design.CleanPlaceHolder(roleFullDesc); - AddPage(new RoleInfo(colorRoleName, roleFullDesc, optionId)); + AddPage(new RoleInfo(colorRoleName, roleFullDesc, option)); } } } diff --git a/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllRoleInfoModel.cs b/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllRoleInfoModel.cs index c4b9510ea..e4d5a0546 100644 --- a/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllRoleInfoModel.cs +++ b/ExtremeRoles/Module/InfoOverlay/Model/Panel/AllRoleInfoModel.cs @@ -2,6 +2,7 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.Module.Interface; +using ExtremeRoles.Module.CustomOption.Interfaces; namespace ExtremeRoles.Module.InfoOverlay.Model.Panel; @@ -11,45 +12,45 @@ public sealed class AllRoleInfoModel : PanelPageModelBase { protected override void CreateAllRoleText() { - int optionId; + IOption option; string colorRoleName; string roleFullDesc; foreach (var role in Roles.ExtremeRoleManager.NormalRole.Values) { - optionId = role.GetRoleOptionOffset(); colorRoleName = role.GetColoredRoleName(true); + option = role.Loader.Get(RoleCommonOption.SpawnRate); roleFullDesc = Translation.GetString($"{role.Id}FullDescription"); roleFullDesc = Design.CleanPlaceHolder(roleFullDesc); - AddPage(new RoleInfo(colorRoleName, roleFullDesc, optionId)); + AddPage(new RoleInfo(colorRoleName, roleFullDesc, option)); } foreach (var combRole in Roles.ExtremeRoleManager.CombRole.Values) { + option = combRole.Loader.Get(RoleCommonOption.SpawnRate); + if (combRole is ConstCombinationRoleManagerBase) { foreach (var role in combRole.Roles) { - optionId = role.GetManagerOptionOffset(); colorRoleName = role.GetColoredRoleName(true); roleFullDesc = Translation.GetString($"{role.Id}FullDescription"); roleFullDesc = Design.CleanPlaceHolder(roleFullDesc); - AddPage(new RoleInfo(colorRoleName, roleFullDesc, optionId)); + AddPage(new RoleInfo(colorRoleName, roleFullDesc, option)); } } else if (combRole is FlexibleCombinationRoleManagerBase flexCombRole) { - optionId = flexCombRole.GetOptionIdOffset(); colorRoleName = flexCombRole.GetOptionName(); roleFullDesc = flexCombRole.GetBaseRoleFullDescription(); roleFullDesc = Design.CleanPlaceHolder(roleFullDesc); - AddPage(new RoleInfo(colorRoleName, roleFullDesc, optionId)); + AddPage(new RoleInfo(colorRoleName, roleFullDesc, option)); } } } diff --git a/ExtremeRoles/Module/InfoOverlay/Model/Panel/GlobalSettingInfoModel.cs b/ExtremeRoles/Module/InfoOverlay/Model/Panel/GlobalSettingInfoModel.cs index 14bd22d51..0bc156f57 100644 --- a/ExtremeRoles/Module/InfoOverlay/Model/Panel/GlobalSettingInfoModel.cs +++ b/ExtremeRoles/Module/InfoOverlay/Model/Panel/GlobalSettingInfoModel.cs @@ -1,6 +1,5 @@ using System; using System.Text; -using System.Linq; using ExtremeRoles.Helper; @@ -9,6 +8,11 @@ using ExtremeRoles.GameMode.RoleSelector; using ExtremeRoles.GameMode.Option.ShipGlobal; + +using ExtremeRoles.Roles; + + + namespace ExtremeRoles.Module.InfoOverlay.Model.Panel; #nullable enable @@ -16,25 +20,34 @@ namespace ExtremeRoles.Module.InfoOverlay.Model.Panel; public sealed class GlobalSettingInfoModel : IInfoOverlayPanelModel { private StringBuilder printOption = new StringBuilder(); + private OptionTabContainer? container; public (string, string) GetInfoText() { this.printOption.Clear(); - - foreach (OptionCreator.CommonOptionKey key in Enum.GetValues( - typeof(OptionCreator.CommonOptionKey))) + if (container is null) { - if (key == OptionCreator.CommonOptionKey.PresetSelection) { continue; } + if (!OptionManager.Instance.TryGetTab(OptionTab.General, out var tab)) + { + return ("", ""); + } + container = tab; + } - addOptionString(ref this.printOption, key); + foreach (var key in Enum.GetValues()) + { + tryAddHudString(container, (int)key, this.printOption); } - addRoleSpawnNumOptionHudString(ref this.printOption); - addOptionString(ref this.printOption, RoleGlobalOption.UseXion); + addRoleSpawnNumOptionHudString(container, this.printOption); + tryAddHudString( + container, + ExtremeRoleManager.GetRoleGroupId(ExtremeRoleId.Xion), + this.printOption); - foreach (GlobalOption key in Enum.GetValues(typeof(GlobalOption))) + foreach (var key in Enum.GetValues()) { - addOptionString(ref this.printOption, key); + tryAddHudString(container, (int)key, this.printOption); } string integrateOption = CompatModManager.Instance.GetIntegrateOptionHudString(); @@ -49,74 +62,69 @@ public sealed class GlobalSettingInfoModel : IInfoOverlayPanelModel ); } - private static void addOptionString( - ref StringBuilder builder, T optionKey) where T : struct, IConvertible + private static void tryAddHudString(OptionTabContainer tab, int categoryId, in StringBuilder builder) { - if (!OptionManager.Instance.TryGetIOption( - Convert.ToInt32(optionKey), out IOptionInfo? option) || - option is null || - option.IsHidden) + if (!tab.TryGetCategory(categoryId, out var category)) { return; } - - string optStr = option.ToHudString(); - if (optStr != string.Empty) - { - builder.AppendLine(optStr); - } + category.AddHudString(builder); } - private static void addRoleSpawnNumOptionHudString(ref StringBuilder builder) + private static void addRoleSpawnNumOptionHudString(OptionTabContainer tab, in StringBuilder builder) { // 生存役職周り - builder.AppendLine( - createRoleSpawnNumOptionHudStringLine( - "crewmateRoles", - RoleGlobalOption.MinCrewmateRoles, - RoleGlobalOption.MaxCrewmateRoles)); - builder.AppendLine( - createRoleSpawnNumOptionHudStringLine( - "neutralRoles", - RoleGlobalOption.MinNeutralRoles, - RoleGlobalOption.MaxNeutralRoles)); - builder.AppendLine( - createRoleSpawnNumOptionHudStringLine( - "impostorRoles", - RoleGlobalOption.MinImpostorRoles, - RoleGlobalOption.MaxImpostorRoles)); - + addSpawnNumOptionHudString(tab, SpawnOptionCategory.RoleSpawnCategory, builder); // 幽霊役職周り + addSpawnNumOptionHudString(tab, SpawnOptionCategory.GhostRoleSpawnCategory, builder); + } + + private static void addSpawnNumOptionHudString( + OptionTabContainer tab, + SpawnOptionCategory categoryId, + in StringBuilder builder) + { + if (!tab.TryGetCategory((int)categoryId, out var category)) + { + return; + } + builder.AppendLine( createRoleSpawnNumOptionHudStringLine( + category, "crewmateGhostRoles", - RoleGlobalOption.MinCrewmateGhostRoles, - RoleGlobalOption.MaxCrewmateGhostRoles)); + RoleSpawnOption.MinCrewmate, + RoleSpawnOption.MaxCrewmate)); builder.AppendLine( createRoleSpawnNumOptionHudStringLine( + category, "neutralGhostRoles", - RoleGlobalOption.MinNeutralGhostRoles, - RoleGlobalOption.MaxNeutralGhostRoles)); + RoleSpawnOption.MinNeutral, + RoleSpawnOption.MaxNeutral)); builder.AppendLine( createRoleSpawnNumOptionHudStringLine( + category, "impostorGhostRoles", - RoleGlobalOption.MinImpostorGhostRoles, - RoleGlobalOption.MaxImpostorGhostRoles)); + RoleSpawnOption.MinImpostor, + RoleSpawnOption.MaxImpostor)); } private static string createRoleSpawnNumOptionHudStringLine( - string transKey, RoleGlobalOption minOptKey, RoleGlobalOption maxOptKey) + OptionCategory category, + string transKey, + RoleSpawnOption minOptKey, + RoleSpawnOption maxOptKey) { string optionName = Design.ColoedString( - new UnityEngine.Color(204f / 255f, 204f / 255f, 0, 1f), - Translation.GetString(transKey)); - int min = getSpawnOptionValue(minOptKey); - int max = getSpawnOptionValue(maxOptKey); + new UnityEngine.Color(204f / 255f, 204f / 255f, 0, 1f), + Translation.GetString(transKey)); + int min = getSpawnOptionValue(category, minOptKey); + int max = getSpawnOptionValue(category, maxOptKey); string optionValueStr = (min >= max) ? $"{max}" : $"{min} - {max}"; return $"{optionName}: {optionValueStr}"; } - private static int getSpawnOptionValue(RoleGlobalOption optionKey) - => OptionManager.Instance.GetValue((int)optionKey); + private static int getSpawnOptionValue(OptionCategory category, RoleSpawnOption optionKey) + => category.GetValue((int)optionKey); } diff --git a/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalGhostRoleInfoModel.cs b/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalGhostRoleInfoModel.cs index fdbacd522..382528bcf 100644 --- a/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalGhostRoleInfoModel.cs +++ b/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalGhostRoleInfoModel.cs @@ -1,10 +1,11 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module.Interface; -using ExtremeRoles.Roles; using ExtremeRoles.Roles.API; using ExtremeRoles.GhostRoles; using ExtremeRoles.Performance; + + namespace ExtremeRoles.Module.InfoOverlay.Model.Panel; #nullable enable @@ -24,23 +25,13 @@ public sealed class LocalGhostRoleInfoModel : IInfoOverlayPanelModel return ($"{Translation.GetString("yourNoAssignGhostRole")}\n", ""); } - var allOption = OptionManager.Instance; - string roleOptionString = ""; string colorRoleName = role.GetColoredRoleName(); if (!role.IsVanillaRole()) { - int useId = role.GetRoleOptionId(RoleCommonOption.SpawnRate); - - if (!allOption.Contains(useId)) - { - var aliveRole = (MultiAssignRoleBase)ExtremeRoleManager.GetLocalPlayerRole(); - useId = aliveRole.GetManagerOptionId(RoleCommonOption.SpawnRate); - } - - var option = allOption.GetIOption(useId); - roleOptionString = option.ToHudStringWithChildren(); + var option = role.Loader.Get(RoleCommonOption.SpawnRate); + roleOptionString = IInfoOverlayPanelModel.ToHudStringWithChildren(option); } string roleFullDesc = role.GetFullDescription(); diff --git a/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalRoleInfoModel.cs b/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalRoleInfoModel.cs index c668d9802..af68654df 100644 --- a/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalRoleInfoModel.cs +++ b/ExtremeRoles/Module/InfoOverlay/Model/Panel/LocalRoleInfoModel.cs @@ -7,6 +7,8 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Roles.API; + + namespace ExtremeRoles.Module.InfoOverlay.Model.Panel; #nullable enable @@ -66,14 +68,12 @@ private static (string, string) createMultiAssignRoleInfo(MultiAssignRoleBase mu private static (string, string, string) getRoleInfoAndOption(SingleRoleBase role) { - var allOption = OptionManager.Instance; - string roleOptionString = ""; if (!role.IsVanillaRole()) { - var option = allOption.GetIOption(role.GetRoleOptionId(RoleCommonOption.SpawnRate)); - roleOptionString = option.ToHudStringWithChildren(); + var option = role.Loader.Get(RoleCommonOption.SpawnRate); + roleOptionString = IInfoOverlayPanelModel.ToHudStringWithChildren(option); } string colorRoleName = role.GetColoredRoleName(); string roleFullDesc = role.GetFullDescription(); @@ -85,14 +85,12 @@ private static (string, string, string) getRoleInfoAndOption(SingleRoleBase role private static (string, string, string) getMultiRoleInfoAndOption(MultiAssignRoleBase role) { - var allOption = OptionManager.Instance; - string roleOptionString = ""; if (!role.IsVanillaRole()) { - var option = allOption.GetIOption(role.GetManagerOptionId(RoleCommonOption.SpawnRate)); - roleOptionString = option.ToHudStringWithChildren(); + var option = role.Loader.Get(RoleCommonOption.SpawnRate); + roleOptionString = IInfoOverlayPanelModel.ToHudStringWithChildren(option); } string colorRoleName = Design.ColoedString( diff --git a/ExtremeRoles/Module/InfoOverlay/Model/Panel/PanelPageModelBase.cs b/ExtremeRoles/Module/InfoOverlay/Model/Panel/PanelPageModelBase.cs index 59f382750..3642717b1 100644 --- a/ExtremeRoles/Module/InfoOverlay/Model/Panel/PanelPageModelBase.cs +++ b/ExtremeRoles/Module/InfoOverlay/Model/Panel/PanelPageModelBase.cs @@ -1,14 +1,16 @@ using ExtremeRoles.Helper; -using ExtremeRoles.Roles.API; + using System.Collections.Generic; +using ExtremeRoles.Module.CustomOption.Interfaces; + namespace ExtremeRoles.Module.Interface; #nullable enable public abstract class PanelPageModelBase : IInfoOverlayPanelModel { - protected readonly record struct RoleInfo(string RoleName, string FullDec, int OptionId); + protected readonly record struct RoleInfo(string RoleName, string FullDec, IOption Option); public int PageNum => this.allPage.Count; @@ -39,10 +41,7 @@ public int CurPage var info = this.allPage[this.curPage]; string colorRoleName = info.RoleName; - - var option = OptionManager.Instance.GetIOption( - info.OptionId + (int)RoleCommonOption.SpawnRate); - string roleOptionStr = option.ToHudStringWithChildren(); + string roleOptionStr = IInfoOverlayPanelModel.ToHudStringWithChildren(info.Option); return ( $"・{colorRoleName}\n{info.FullDec}", diff --git a/ExtremeRoles/Module/Interface/IAmongUs.cs b/ExtremeRoles/Module/Interface/IAmongUs.cs index 755aaef52..171c47414 100644 --- a/ExtremeRoles/Module/Interface/IAmongUs.cs +++ b/ExtremeRoles/Module/Interface/IAmongUs.cs @@ -20,7 +20,7 @@ public interface IUsable public void SetOutline(bool on, bool mainTarget); - public float CanUse(GameData.PlayerInfo pc, out bool canUse, out bool couldUse); + public float CanUse(NetworkedPlayerInfo pc, out bool canUse, out bool couldUse); public void Use(); } diff --git a/ExtremeRoles/Module/Interface/IInfoOverlayPanelModel.cs b/ExtremeRoles/Module/Interface/IInfoOverlayPanelModel.cs index a14e64cdd..d12c6caed 100644 --- a/ExtremeRoles/Module/Interface/IInfoOverlayPanelModel.cs +++ b/ExtremeRoles/Module/Interface/IInfoOverlayPanelModel.cs @@ -1,6 +1,42 @@ -namespace ExtremeRoles.Module.Interface; +using System.Text; + +using ExtremeRoles.Module.CustomOption.Interfaces; + +namespace ExtremeRoles.Module.Interface; public interface IInfoOverlayPanelModel { public (string, string) GetInfoText(); + + protected static string ToHudStringWithChildren(IOption option, int indent = 0) + { + var builder = new StringBuilder(); + if (!option.Info.IsHidden && option.IsActiveAndEnable) + { + builder.AppendLine(toHudString(option)); + } + + addChildrenOptionHudString(builder, option, indent + 1); + return builder.ToString(); + } + + private static void addChildrenOptionHudString( + in StringBuilder builder, + IOption parentOption, + int prefixIndentCount) + { + foreach (var child in parentOption.Relation.Children) + { + if (!child.Info.IsHidden && child.IsActiveAndEnable) + { + builder.Append(' ', prefixIndentCount * 4); + builder.AppendLine(toHudString(child)); + } + + addChildrenOptionHudString(in builder, child, prefixIndentCount + 1); + } + } + + private static string toHudString(in IOption option) + => $"{option.Title}: {option.ValueString}"; } diff --git a/ExtremeRoles/Module/Interface/ISpawnDataManager.cs b/ExtremeRoles/Module/Interface/ISpawnDataManager.cs index 8ef97f4d6..86dd481fb 100644 --- a/ExtremeRoles/Module/Interface/ISpawnDataManager.cs +++ b/ExtremeRoles/Module/Interface/ISpawnDataManager.cs @@ -1,20 +1,21 @@ using System; using ExtremeRoles.GameMode.RoleSelector; -using ExtremeRoles.Module.CustomOption; + + +using ExtremeRoles.Module.CustomOption.Interfaces; namespace ExtremeRoles.Module.Interface; public interface ISpawnDataManager { protected static int ComputeSpawnNum( - RoleGlobalOption minSpawnKey, - RoleGlobalOption maxSpawnKey) + OptionCategory category, + RoleSpawnOption minSpawnKey, + RoleSpawnOption maxSpawnKey) { - var allOption = OptionManager.Instance; - - int minSpawnNum = allOption.GetValue((int)minSpawnKey); - int maxSpawnNum = allOption.GetValue((int)maxSpawnKey); + int minSpawnNum = category.GetValue((int)minSpawnKey); + int maxSpawnNum = category.GetValue((int)maxSpawnKey); // 最大値が最小値より小さくならないように maxSpawnNum = Math.Clamp(maxSpawnNum, minSpawnNum, int.MaxValue); @@ -23,5 +24,5 @@ protected static int ComputeSpawnNum( } protected static int ComputePercentage(IValueOption self) - => (int)decimal.Multiply(self.GetValue(), self.ValueCount); + => (int)decimal.Multiply(self.Value, self.Range); } diff --git a/ExtremeRoles/Module/PlayerStatistics.cs b/ExtremeRoles/Module/PlayerStatistics.cs index 5f3f87c3a..62abcbaec 100644 --- a/ExtremeRoles/Module/PlayerStatistics.cs +++ b/ExtremeRoles/Module/PlayerStatistics.cs @@ -74,7 +74,7 @@ public static PlayerStatistics Create() Dictionary specialWinCheckRoleAlive = new Dictionary< int, IWinChecker>(); - foreach (GameData.PlayerInfo playerInfo in + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (playerInfo == null || diff --git a/ExtremeRoles/Module/PublicBeta.cs b/ExtremeRoles/Module/PublicBeta.cs index f70f3e126..deb066695 100644 --- a/ExtremeRoles/Module/PublicBeta.cs +++ b/ExtremeRoles/Module/PublicBeta.cs @@ -4,6 +4,8 @@ using ExtremeRoles.Beta; + + #nullable enable namespace ExtremeRoles.Module; diff --git a/ExtremeRoles/Module/RoleAssign/GhostRoleSpawnDataManager.cs b/ExtremeRoles/Module/RoleAssign/GhostRoleSpawnDataManager.cs index c877c27fb..f6ffb62e8 100644 --- a/ExtremeRoles/Module/RoleAssign/GhostRoleSpawnDataManager.cs +++ b/ExtremeRoles/Module/RoleAssign/GhostRoleSpawnDataManager.cs @@ -4,10 +4,12 @@ using ExtremeRoles.GameMode.RoleSelector; using ExtremeRoles.GhostRoles; using ExtremeRoles.Module.Interface; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles; using ExtremeRoles.Roles.API; +using Unity.Jobs.LowLevel.Unsafe; + namespace ExtremeRoles.Module.RoleAssign; public sealed class GhostRoleSpawnDataManager : @@ -40,29 +42,39 @@ public void Create( } } - this.globalSpawnLimit = new Dictionary + var opt = OptionManager.Instance; + + if (opt.TryGetCategory(OptionTab.General, (int)SpawnOptionCategory.RoleSpawnCategory, out var cate)) { + this.globalSpawnLimit = new Dictionary { - ExtremeRoleType.Crewmate, - ISpawnDataManager.ComputeSpawnNum( - RoleGlobalOption.MinCrewmateGhostRoles, - RoleGlobalOption.MaxCrewmateGhostRoles) - }, - { - ExtremeRoleType.Neutral, - ISpawnDataManager.ComputeSpawnNum( - RoleGlobalOption.MinNeutralGhostRoles, - RoleGlobalOption.MaxNeutralGhostRoles) - }, - { - ExtremeRoleType.Impostor, - ISpawnDataManager.ComputeSpawnNum( - RoleGlobalOption.MinImpostorGhostRoles, - RoleGlobalOption.MaxImpostorGhostRoles) - }, - }; - - var allOption = OptionManager.Instance; + { + ExtremeRoleType.Crewmate, + ISpawnDataManager.ComputeSpawnNum( + cate, + RoleSpawnOption.MinCrewmate, + RoleSpawnOption.MaxCrewmate) + }, + { + ExtremeRoleType.Neutral, + ISpawnDataManager.ComputeSpawnNum( + cate, + RoleSpawnOption.MinNeutral, + RoleSpawnOption.MaxNeutral) + }, + { + ExtremeRoleType.Impostor, + ISpawnDataManager.ComputeSpawnNum( + cate, + RoleSpawnOption.MinImpostor, + RoleSpawnOption.MaxImpostor) + }, + }; + } + else + { + this.globalSpawnLimit = new(); + } var tmpUseData = new Dictionary>(); foreach (ExtremeGhostRoleId roleId in @@ -70,13 +82,24 @@ public void Create( { var role = ExtremeGhostRoleManager.AllGhostRole[roleId]; - int spawnRate = ISpawnDataManager.ComputePercentage( - allOption.Get( - role.GetRoleOptionId(RoleCommonOption.SpawnRate))); - int weight = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.AssignWeight)); - int roleNum = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.RoleNum)); + var tab = role.Team switch + { + ExtremeRoleType.Neutral => OptionTab.GhostNeutral, + ExtremeRoleType.Crewmate => OptionTab.GhostCrewmate, + ExtremeRoleType.Impostor => OptionTab.GhostImpostor, + _ => throw new System.ArgumentOutOfRangeException(), + }; + + if (!opt.TryGetCategory( + tab, ExtremeGhostRoleManager.GetRoleGroupId(role.Id), + out var roleCate)) + { + continue; + } + + int spawnRate = roleCate.GetValue(RoleCommonOption.SpawnRate); + int weight = roleCate.GetValue(RoleCommonOption.AssignWeight); + int roleNum = roleCate.GetValue(RoleCommonOption.RoleNum); Helper.Logging.Debug( $"GhostRole Name:{role.Name} SpawnRate:{spawnRate} RoleNum:{roleNum}"); diff --git a/ExtremeRoles/Module/RoleAssign/NotAssignPlayerData.cs b/ExtremeRoles/Module/RoleAssign/NotAssignPlayerData.cs index a8325b14d..ed4383b86 100644 --- a/ExtremeRoles/Module/RoleAssign/NotAssignPlayerData.cs +++ b/ExtremeRoles/Module/RoleAssign/NotAssignPlayerData.cs @@ -31,6 +31,8 @@ public NotAssignPlayerData() break; case RoleTypes.Scientist: case RoleTypes.Engineer: + case RoleTypes.Noisemaker: + case RoleTypes.Tracker: ++crewMultiAssignNum; break; case RoleTypes.Impostor: @@ -38,8 +40,8 @@ public NotAssignPlayerData() ++impSingleAssignNum; break; case RoleTypes.Shapeshifter: + case RoleTypes.Phantom: ++impMultiAssignNum; - ++impSingleAssignNum; break; default: break; diff --git a/ExtremeRoles/Module/RoleAssign/PlayerRoleAssignData.cs b/ExtremeRoles/Module/RoleAssign/PlayerRoleAssignData.cs index 987d7137c..b9e78415f 100644 --- a/ExtremeRoles/Module/RoleAssign/PlayerRoleAssignData.cs +++ b/ExtremeRoles/Module/RoleAssign/PlayerRoleAssignData.cs @@ -64,7 +64,9 @@ public IReadOnlyList GetCanImpostorAssignPlayer() { return x.Data.Role.Role switch { - RoleTypes.Impostor or RoleTypes.Shapeshifter => true, + RoleTypes.Impostor or + RoleTypes.Shapeshifter or + RoleTypes.Phantom => true, _ => false }; }); @@ -79,7 +81,9 @@ public IReadOnlyList GetCanCrewmateAssignPlayer() { RoleTypes.Crewmate or RoleTypes.Engineer or - RoleTypes.Scientist => true, + RoleTypes.Scientist or + RoleTypes.Noisemaker or + RoleTypes.Tracker => true, _ => false }; diff --git a/ExtremeRoles/Module/RoleAssign/RoleAssignFilter.cs b/ExtremeRoles/Module/RoleAssign/RoleAssignFilter.cs index ad5a1ee79..9cbe80643 100644 --- a/ExtremeRoles/Module/RoleAssign/RoleAssignFilter.cs +++ b/ExtremeRoles/Module/RoleAssign/RoleAssignFilter.cs @@ -9,6 +9,8 @@ using ExtremeRoles.Module.CustomMonoBehaviour.View; using ExtremeRoles.Resources; + + #nullable enable namespace ExtremeRoles.Module.RoleAssign; diff --git a/ExtremeRoles/Module/RoleAssign/RoleSpawnDataManager.cs b/ExtremeRoles/Module/RoleAssign/RoleSpawnDataManager.cs index dc54068f9..76860a32b 100644 --- a/ExtremeRoles/Module/RoleAssign/RoleSpawnDataManager.cs +++ b/ExtremeRoles/Module/RoleAssign/RoleSpawnDataManager.cs @@ -6,7 +6,9 @@ using ExtremeRoles.GameMode.RoleSelector; using ExtremeRoles.Helper; using ExtremeRoles.Module.Interface; -using ExtremeRoles.Module.CustomOption; + + +using Unity.Jobs.LowLevel.Unsafe; namespace ExtremeRoles.Module.RoleAssign; @@ -38,27 +40,34 @@ public RoleSpawnDataManager() { ExtremeRoleType.Neutral , new Dictionary() }, }; - MaxRoleNum = new Dictionary - { - { - ExtremeRoleType.Crewmate, - ISpawnDataManager.ComputeSpawnNum( - RoleGlobalOption.MinCrewmateRoles, - RoleGlobalOption.MaxCrewmateRoles) - }, - { - ExtremeRoleType.Neutral, - ISpawnDataManager.ComputeSpawnNum( - RoleGlobalOption.MinNeutralRoles, - RoleGlobalOption.MaxNeutralRoles) - }, + var opt = OptionManager.Instance; + + MaxRoleNum = opt.TryGetCategory(OptionTab.General, (int)SpawnOptionCategory.RoleSpawnCategory, out var cate) + ? new Dictionary { - ExtremeRoleType.Impostor, - ISpawnDataManager.ComputeSpawnNum( - RoleGlobalOption.MinImpostorRoles, - RoleGlobalOption.MaxImpostorRoles) - }, - }; + { + ExtremeRoleType.Crewmate, + ISpawnDataManager.ComputeSpawnNum( + cate, + RoleSpawnOption.MinCrewmate, + RoleSpawnOption.MaxCrewmate) + }, + { + ExtremeRoleType.Neutral, + ISpawnDataManager.ComputeSpawnNum( + cate, + RoleSpawnOption.MinNeutral, + RoleSpawnOption.MaxNeutral) + }, + { + ExtremeRoleType.Impostor, + ISpawnDataManager.ComputeSpawnNum( + cate, + RoleSpawnOption.MinImpostor, + RoleSpawnOption.MaxImpostor) + }, + } : new (); + CurrentSingleRoleUseNum = new Dictionary() { @@ -67,28 +76,28 @@ public RoleSpawnDataManager() { ExtremeRoleType.Neutral , 0 }, }; - var allOption = OptionManager.Instance; - foreach (var roleId in ExtremeGameModeManager.Instance.RoleSelector.UseCombRoleType) { byte combType = (byte)roleId; - var role = ExtremeRoleManager.CombRole[combType]; - int spawnRate = ISpawnDataManager.ComputePercentage(allOption.Get( - role.GetRoleOptionId(RoleCommonOption.SpawnRate))); - int roleSet = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.RoleNum)); - int weight = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.AssignWeight)); - bool isMultiAssign = allOption.GetValue( - role.GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign)); + if (!opt.TryGetCategory( + OptionTab.Combination, + ExtremeRoleManager.GetCombRoleGroupId(roleId), + out var conbCate)) + { + continue; + } + int spawnRate = conbCate.GetValue(RoleCommonOption.SpawnRate); + int roleSet = conbCate.GetValue(RoleCommonOption.RoleNum); + int weight = conbCate.GetValue(RoleCommonOption.AssignWeight); + bool isMultiAssign = conbCate.GetValue(CombinationRoleCommonOption.IsMultiAssign); + var role = ExtremeRoleManager.CombRole[combType]; Logging.Debug($"Role:{role} SpawnRate:{spawnRate} RoleSet:{roleSet}"); if (roleSet <= 0 || spawnRate <= 0.0) { continue; } - CurrentCombRoleSpawnData.Add( combType, new CombinationRoleSpawnData( @@ -100,7 +109,7 @@ public RoleSpawnDataManager() if (role is GhostAndAliveCombinationRoleManagerBase ghostComb) { - this.UseGhostCombRole.Add(((CombinationRoleType)combType, ghostComb)); + this.UseGhostCombRole.Add((roleId, ghostComb)); } } @@ -108,13 +117,17 @@ public RoleSpawnDataManager() { int intedRoleId = (int)roleId; SingleRoleBase role = ExtremeRoleManager.NormalRole[intedRoleId]; + if (!opt.TryGetCategory( + role.Tab, + ExtremeRoleManager.GetRoleGroupId(roleId), + out var roleCate)) + { + continue; + } - int spawnRate = ISpawnDataManager.ComputePercentage(allOption.Get( - role.GetRoleOptionId(RoleCommonOption.SpawnRate))); - int weight = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.AssignWeight)); - int roleNum = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.RoleNum)); + int spawnRate = roleCate.GetValue(RoleCommonOption.SpawnRate); + int weight = roleCate.GetValue(RoleCommonOption.AssignWeight); + int roleNum = roleCate.GetValue(RoleCommonOption.RoleNum); Logging.Debug( $"Role Name:{role.RoleName} SpawnRate:{spawnRate} RoleNum:{roleNum}"); diff --git a/ExtremeRoles/Module/SpecialWinChecker/LoverWinChecker.cs b/ExtremeRoles/Module/SpecialWinChecker/LoverWinChecker.cs index 73efcbc07..77c356359 100644 --- a/ExtremeRoles/Module/SpecialWinChecker/LoverWinChecker.cs +++ b/ExtremeRoles/Module/SpecialWinChecker/LoverWinChecker.cs @@ -1,13 +1,14 @@ using System.Collections.Generic; using ExtremeRoles.Module.Interface; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Extension.State; using ExtremeRoles.Roles.Combination; using ExtremeRoles.Roles.Solo.Neutral; + namespace ExtremeRoles.Module.SpecialWinChecker; internal sealed class LoverWinChecker : IWinChecker @@ -31,11 +32,13 @@ public void AddAliveRole( byte playerId, SingleRoleBase role) { - if (this.loverNum == 0) + if (this.loverNum == 0 && + OptionManager.Instance.TryGetCategory( + OptionTab.Combination, + ExtremeRoleManager.GetCombRoleGroupId(CombinationRoleType.Lover), + out var cate)) { - this.loverNum = OptionManager.Instance.GetValue( - ((MultiAssignRoleBase)role).GetManagerOptionId( - CombinationRoleCommonOption.AssignsNum)); + this.loverNum = cate.GetValue(CombinationRoleCommonOption.AssignsNum); } if (!role.HasTask()) { diff --git a/ExtremeRoles/Module/SystemType/Roles/FakerDummySystem.cs b/ExtremeRoles/Module/SystemType/Roles/FakerDummySystem.cs index 55c8d8538..10af1f8e5 100644 --- a/ExtremeRoles/Module/SystemType/Roles/FakerDummySystem.cs +++ b/ExtremeRoles/Module/SystemType/Roles/FakerDummySystem.cs @@ -75,7 +75,7 @@ public sealed class FakePlayer : IFakerObject private struct PlayerCosmicInfo { public CosmeticsLayer Cosmetics; - public GameData.PlayerOutfit OutfitInfo; + public NetworkedPlayerInfo.PlayerOutfit OutfitInfo; public bool FlipX; public int ColorInfo; } @@ -85,7 +85,7 @@ public FakePlayer( PlayerControl targetPlayer, bool canSeeFake) { - GameData.PlayerOutfit playerOutfit = targetPlayer.Data.DefaultOutfit; + NetworkedPlayerInfo.PlayerOutfit playerOutfit = targetPlayer.Data.DefaultOutfit; PlayerCosmicInfo cosmicInfo = new PlayerCosmicInfo() { Cosmetics = targetPlayer.cosmetics, diff --git a/ExtremeRoles/Module/SystemType/Roles/TeroristTeroSabotageSystem.cs b/ExtremeRoles/Module/SystemType/Roles/TeroristTeroSabotageSystem.cs index 25ac46eac..f367c037a 100644 --- a/ExtremeRoles/Module/SystemType/Roles/TeroristTeroSabotageSystem.cs +++ b/ExtremeRoles/Module/SystemType/Roles/TeroristTeroSabotageSystem.cs @@ -78,7 +78,7 @@ public BombConsoleBehavior(in MinigameOption option, byte bombId, bool isCheckWa option.DeadPlayerActivateTime); } - public bool CanUse(GameData.PlayerInfo pc) + public bool CanUse(NetworkedPlayerInfo pc) => pc.Object.CanMove && FindTeroSaboTask(pc.Object) && (!pc.IsDead || this.info.CanUseDeadPlayer); diff --git a/ExtremeRoles/Module/SystemType/Roles/WispTorchSystem.cs b/ExtremeRoles/Module/SystemType/Roles/WispTorchSystem.cs index 98d055e22..77f39ece1 100644 --- a/ExtremeRoles/Module/SystemType/Roles/WispTorchSystem.cs +++ b/ExtremeRoles/Module/SystemType/Roles/WispTorchSystem.cs @@ -227,7 +227,7 @@ public void Deteriorate(float deltaTime) // 停電処理かつ持ってない人更新 int playerNum = 0; - foreach (GameData.PlayerInfo player in GameData.Instance.AllPlayers.GetFastEnumerator()) + foreach (NetworkedPlayerInfo player in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (player.IsDead || player.Disconnected || diff --git a/ExtremeRoles/Module/SystemType/Roles/YokoYashiroSystem.cs b/ExtremeRoles/Module/SystemType/Roles/YokoYashiroSystem.cs index e1d2f2504..af251a26a 100644 --- a/ExtremeRoles/Module/SystemType/Roles/YokoYashiroSystem.cs +++ b/ExtremeRoles/Module/SystemType/Roles/YokoYashiroSystem.cs @@ -81,7 +81,7 @@ private static Minigame prefab public RolePlayerId Id { get; init; } = id; - public bool CanUse(GameData.PlayerInfo pc) + public bool CanUse(NetworkedPlayerInfo pc) => pc.Object.CanMove && !pc.IsDead; public void Use() diff --git a/ExtremeRoles/Module/VisionComputer.cs b/ExtremeRoles/Module/VisionComputer.cs index 004168b2f..13c1b2386 100644 --- a/ExtremeRoles/Module/VisionComputer.cs +++ b/ExtremeRoles/Module/VisionComputer.cs @@ -50,7 +50,7 @@ public void ResetModifier() public bool IsModifierResetted() => this.modifier == Modifier.None; public bool IsVanillaVisionAndGetVision( - ShipStatus shipStatus, GameData.PlayerInfo playerInfo, out float vision) + ShipStatus shipStatus, NetworkedPlayerInfo playerInfo, out float vision) { vision = shipStatus.MaxLightRadius; @@ -156,7 +156,7 @@ public bool IsVanillaVisionAndGetVision( private static bool checkNormalOrCustomCalculateLightRadius( IMapMod modMap, - bool isRequireCustomVision, GameData.PlayerInfo player, ref float result) + bool isRequireCustomVision, NetworkedPlayerInfo player, ref float result) { if (!isRequireCustomVision) { return true; } diff --git a/ExtremeRoles/OptionCreator.cs b/ExtremeRoles/OptionCreator.cs index ea7ebefcb..696542c58 100644 --- a/ExtremeRoles/OptionCreator.cs +++ b/ExtremeRoles/OptionCreator.cs @@ -3,36 +3,37 @@ using ExtremeRoles.Compat; using ExtremeRoles.GameMode.Option.ShipGlobal; using ExtremeRoles.GameMode.RoleSelector; -using ExtremeRoles.Module.CustomOption.Factories; +// using ExtremeRoles.Module.CustomOption.Factories; + + namespace ExtremeRoles; public static class OptionCreator { public const int IntegrateOptionStartOffset = 15000; - - private const int singleRoleOptionStartOffset = 256; - private const int combRoleOptionStartOffset = 5000; - private const int ghostRoleOptionStartOffset = 10000; private const int maxPresetNum = 20; - public static readonly string[] SpawnRate = [ - "0%", "10%", "20%", "30%", "40%", - "50%", "60%", "70%", "80%", "90%", "100%" ]; - public static readonly string[] Range = [ "short", "middle", "long" ]; private static Color defaultOptionColor => new Color(204f / 255f, 204f / 255f, 0, 1f); - public enum CommonOptionKey : int + public enum PresetOptionKey : int { - PresetSelection = 0, + Selection = 0, + } - UseRaiseHand, + public enum RandomOptionKey : int + { + UseStrong = 0, + Algorithm, + } - UseStrongRandomGen, - UsePrngAlgorithm, - } + public enum CommonOption : int + { + PresetOption, + RandomOption + } public static void Create() { @@ -42,44 +43,40 @@ public static void Create() Roles.ExtremeRoleManager.GameRole.Clear(); - var commonOptionFactory = new ColorSyncFactory(defaultOptionColor); - - commonOptionFactory.CreateIntOption( - CommonOptionKey.PresetSelection, - 1, 1, maxPresetNum, 1, - isHeader: true, - format: OptionUnit.Preset); - - commonOptionFactory.CreateBoolOption( - CommonOptionKey.UseRaiseHand, - false, isHeader: true); - - var strongGen = commonOptionFactory.CreateBoolOption( - CommonOptionKey.UseStrongRandomGen, - true, isHeader: true); - commonOptionFactory.CreateSelectionOption( - CommonOptionKey.UsePrngAlgorithm, - [ - "Pcg32XshRr", "Pcg64RxsMXs", - "Xorshift64", "Xorshift128", - "Xorshiro256StarStar", - "Xorshiro512StarStar", - "RomuMono", "RomuTrio", "RomuQuad", - "Seiran128", "Shioi128", "JFT32", - ], - strongGen, invert: true); + using (var commonOptionFactory = OptionManager.CreateOptionCategory( + CommonOption.PresetOption, + color: defaultOptionColor)) + { + commonOptionFactory.CreateIntOption( + PresetOptionKey.Selection, + 1, 1, maxPresetNum, 1, + format: OptionUnit.Preset); + } + + using (var commonOptionFactory = OptionManager.CreateOptionCategory( + CommonOption.RandomOption, color: defaultOptionColor)) + { + var strongGen = commonOptionFactory.CreateBoolOption( + RandomOptionKey.UseStrong, true); + commonOptionFactory.CreateSelectionOption( + RandomOptionKey.Algorithm, + [ + "Pcg32XshRr", "Pcg64RxsMXs", + "Xorshift64", "Xorshift128", + "Xorshiro256StarStar", + "Xorshiro512StarStar", + "RomuMono", "RomuTrio", "RomuQuad", + "Seiran128", "Shioi128", "JFT32", + ], + strongGen, invert: true); + } IRoleSelector.CreateRoleGlobalOption(); IShipGlobalOption.Create(); - Roles.ExtremeRoleManager.CreateNormalRoleOptions( - singleRoleOptionStartOffset); - - Roles.ExtremeRoleManager.CreateCombinationRoleOptions( - combRoleOptionStartOffset); - - GhostRoles.ExtremeGhostRoleManager.CreateGhostRoleOption( - ghostRoleOptionStartOffset); + Roles.ExtremeRoleManager.CreateNormalRoleOptions(); + Roles.ExtremeRoleManager.CreateCombinationRoleOptions(); + GhostRoles.ExtremeGhostRoleManager.CreateGhostRoleOption(); CompatModManager.Instance.CreateIntegrateOption(IntegrateOptionStartOffset); diff --git a/ExtremeRoles/Patches/AmongUsClientPatch.cs b/ExtremeRoles/Patches/AmongUsClientPatch.cs index 952c11010..34fe08e39 100644 --- a/ExtremeRoles/Patches/AmongUsClientPatch.cs +++ b/ExtremeRoles/Patches/AmongUsClientPatch.cs @@ -36,16 +36,6 @@ public static void Prefix( } } -[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.Awake))] -public static class AmongUsClientAwakePatch -{ - public static void Prefix(AmongUsClient __instance) - { - // MODなので待ち時間をとりあえず +10秒しておく、デフォルトは10秒 - __instance.MAX_CLIENT_WAIT_TIME = 20; - } -} - [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CoStartGame))] public static class AmongUsClientCoStartGamePatch { diff --git a/ExtremeRoles/Patches/Button/KillButtonPatch.cs b/ExtremeRoles/Patches/Button/KillButtonPatch.cs index d001bbfd8..6e7f6c6da 100644 --- a/ExtremeRoles/Patches/Button/KillButtonPatch.cs +++ b/ExtremeRoles/Patches/Button/KillButtonPatch.cs @@ -102,7 +102,7 @@ public static bool IsMissMuderKill( target.MyPhysics.Animations.IsPlayingAnyLadderAnimation() || ( target.MyPhysics.Animations.IsPlayingEnterVentAnimation() && - ExtremeGameModeManager.Instance.ShipOption.CanKillVentInPlayer + ExtremeGameModeManager.Instance.ShipOption.Vent.CanKillVentInPlayer ) || target.inMovingPlat || MeetingHud.Instance; diff --git a/ExtremeRoles/Patches/Controller/ChatControllerPatch.cs b/ExtremeRoles/Patches/Controller/ChatControllerPatch.cs index 613993bcd..c5306dd1c 100644 --- a/ExtremeRoles/Patches/Controller/ChatControllerPatch.cs +++ b/ExtremeRoles/Patches/Controller/ChatControllerPatch.cs @@ -18,7 +18,7 @@ namespace ExtremeRoles.Patches.Controller; public static class ChatControllerAddChatNotePatch { public static bool Prefix( - [HarmonyArgument(0)] GameData.PlayerInfo srcPlayer, + [HarmonyArgument(0)] NetworkedPlayerInfo srcPlayer, [HarmonyArgument(1)] ChatNoteTypes noteType) { return !ExtremeRolesPlugin.ShipState.AssassinMeetingTrigger || noteType != ChatNoteTypes.DidVote; @@ -43,8 +43,8 @@ public static bool Prefix( return false; } - GameData.PlayerInfo localPlayerData = CachedPlayerControl.LocalPlayer.Data; - GameData.PlayerInfo sourcePlayerData = sourcePlayer.Data; + NetworkedPlayerInfo localPlayerData = CachedPlayerControl.LocalPlayer.Data; + NetworkedPlayerInfo sourcePlayerData = sourcePlayer.Data; var roleDict = ExtremeRoleManager.GameRole; diff --git a/ExtremeRoles/Patches/Controller/ExileControllerPatch.cs b/ExtremeRoles/Patches/Controller/ExileControllerPatch.cs index d25f0e635..f8c4acba0 100644 --- a/ExtremeRoles/Patches/Controller/ExileControllerPatch.cs +++ b/ExtremeRoles/Patches/Controller/ExileControllerPatch.cs @@ -46,7 +46,7 @@ public static class ExileControllerBeginePatch [HarmonyPrefix, HarmonyPriority(Priority.Last)] public static bool Prefix( ExileController __instance, - [HarmonyArgument(0)] GameData.PlayerInfo exiled, + [HarmonyArgument(0)] NetworkedPlayerInfo exiled, [HarmonyArgument(1)] bool tie) { if (CompatModManager.Instance.IsModMap()) @@ -85,7 +85,7 @@ public static void Postfix(ExileController __instance) public static bool PrefixRun( ExileController __instance, - GameData.PlayerInfo exiled, + NetworkedPlayerInfo exiled, bool tie) { if (!RoleAssignState.Instance.IsRoleSetUpEnd) { return true; } @@ -110,12 +110,16 @@ private static void assassinMeetingEndBegin( ExileController instance, ExtremeShipStatus state) { setExiledTarget(instance, null); - GameData.PlayerInfo player = GameData.Instance.GetPlayerById( + NetworkedPlayerInfo? player = GameData.Instance.GetPlayerById( state.IsMarinPlayerId); + if (player == null) + { + return; + } string transKey = state.IsAssassinateMarin ? "assassinateMarinSucsess" : "assassinateMarinFail"; - string printStr = $"{player?.PlayerName}{Translation.GetString(transKey)}"; + string printStr = $"{player.PlayerName}{Translation.GetString(transKey)}"; if (instance.Player) { @@ -129,7 +133,7 @@ private static void assassinMeetingEndBegin( private static void confirmExil( ExileController instance, - GameData.PlayerInfo exiled, + NetworkedPlayerInfo exiled, ConfirmExilMode mode, bool isShowRole, bool tie) { setExiledTarget(instance, exiled); @@ -148,19 +152,19 @@ private static void confirmExil( int aliveImpNum = Enumerable.Count( alivePlayers, - (GameData.PlayerInfo p) => + (NetworkedPlayerInfo p) => { return allRoles[p.PlayerId].IsImpostor(); }); int aliveCrewNum = Enumerable.Count( alivePlayers, - (GameData.PlayerInfo p) => + (NetworkedPlayerInfo p) => { return allRoles[p.PlayerId].IsCrewmate(); }); int aliveNeutNum = Enumerable.Count( alivePlayers, - (GameData.PlayerInfo p) => + (NetworkedPlayerInfo p) => { return allRoles[p.PlayerId].IsNeutral(); }); @@ -291,7 +295,7 @@ private static string getCompleteString( { case ConfirmExilMode.Impostor: modeTeamAlive = allPlayer.Count( - (GameData.PlayerInfo p) => + (NetworkedPlayerInfo p) => p != null && ExtremeRoleManager.TryGetRole(p.PlayerId, out var role) && role!.IsImpostor()); @@ -299,7 +303,7 @@ private static string getCompleteString( break; case ConfirmExilMode.Crewmate: modeTeamAlive = allPlayer.Count( - (GameData.PlayerInfo p) => + (NetworkedPlayerInfo p) => p != null && ExtremeRoleManager.TryGetRole(p.PlayerId, out var role) && role!.IsCrewmate()); @@ -307,7 +311,7 @@ private static string getCompleteString( break; case ConfirmExilMode.Neutral: modeTeamAlive = allPlayer.Count( - (GameData.PlayerInfo p) => + (NetworkedPlayerInfo p) => p != null && ExtremeRoleManager.TryGetRole(p.PlayerId, out var role) && role!.IsNeutral()); @@ -341,7 +345,7 @@ private static string getCompleteString( } private static void setExiledTarget( - ExileController instance, GameData.PlayerInfo? player) + ExileController instance, NetworkedPlayerInfo? player) { if (instance.specialInputHandler != null) { @@ -409,7 +413,7 @@ public static void Postfix(AirshipExileController __instance) } } - public static void WrapUpPostfix(GameData.PlayerInfo? exiled) + public static void WrapUpPostfix(NetworkedPlayerInfo? exiled) { InfoOverlay.Instance.IsBlock = false; Meeting.Hud.MeetingHudSelectPatch.SetSelectBlock(false); diff --git a/ExtremeRoles/Patches/Controller/FungleExileControllerPatch.cs b/ExtremeRoles/Patches/Controller/FungleExileControllerPatch.cs index 488d4df0f..fca59e1a3 100644 --- a/ExtremeRoles/Patches/Controller/FungleExileControllerPatch.cs +++ b/ExtremeRoles/Patches/Controller/FungleExileControllerPatch.cs @@ -20,8 +20,7 @@ public static bool Prefix(FungleExileController __instance, ref Il2CppEnumerator { var spawnOpt = ExtremeGameModeManager.Instance.ShipOption.Spawn; - if (spawnOpt is not null && - spawnOpt.EnableSpecialSetting && + if (spawnOpt.EnableSpecialSetting && spawnOpt.Fungle) { __result = animateWithRandomSpawn(__instance).WrapToIl2Cpp(); diff --git a/ExtremeRoles/Patches/Controller/MiraExileControllerPatch.cs b/ExtremeRoles/Patches/Controller/MiraExileControllerPatch.cs index ae83ae18f..90044d3c0 100644 --- a/ExtremeRoles/Patches/Controller/MiraExileControllerPatch.cs +++ b/ExtremeRoles/Patches/Controller/MiraExileControllerPatch.cs @@ -20,8 +20,7 @@ public static bool Prefix(MiraExileController __instance, ref Il2CppEnumerator _ { var spawnOpt = ExtremeGameModeManager.Instance.ShipOption.Spawn; - if (spawnOpt is not null && - spawnOpt.EnableSpecialSetting && + if (spawnOpt.EnableSpecialSetting && spawnOpt.MiraHq) { __result = animateWithRandomSpawn(__instance).WrapToIl2Cpp(); diff --git a/ExtremeRoles/Patches/Controller/PbExileControllerPatch.cs b/ExtremeRoles/Patches/Controller/PbExileControllerPatch.cs index 2bfe428df..2b8788525 100644 --- a/ExtremeRoles/Patches/Controller/PbExileControllerPatch.cs +++ b/ExtremeRoles/Patches/Controller/PbExileControllerPatch.cs @@ -20,8 +20,7 @@ public static bool Prefix(PbExileController __instance, ref Il2CppEnumerator __r { var spawnOpt = ExtremeGameModeManager.Instance.ShipOption.Spawn; - if (spawnOpt is not null && - spawnOpt.EnableSpecialSetting && + if (spawnOpt.EnableSpecialSetting && spawnOpt.Polus) { __result = animateWithRandomSpawn(__instance).WrapToIl2Cpp(); diff --git a/ExtremeRoles/Patches/Controller/SkeldExileControllerPatch.cs b/ExtremeRoles/Patches/Controller/SkeldExileControllerPatch.cs index 8ba8cc16f..a63398049 100644 --- a/ExtremeRoles/Patches/Controller/SkeldExileControllerPatch.cs +++ b/ExtremeRoles/Patches/Controller/SkeldExileControllerPatch.cs @@ -20,8 +20,7 @@ public static bool Prefix(SkeldExileController __instance, ref Il2CppEnumerator { var spawnOpt = ExtremeGameModeManager.Instance.ShipOption.Spawn; - if (spawnOpt is not null && - spawnOpt.EnableSpecialSetting && + if (spawnOpt.EnableSpecialSetting && spawnOpt.Skeld) { __result = animateWithRandomSpawn(__instance).WrapToIl2Cpp(); diff --git a/ExtremeRoles/Patches/DebugPatch/DebugKeyboardJoystickPatch.cs b/ExtremeRoles/Patches/DebugPatch/DebugKeyboardJoystickPatch.cs index 1c070b7fb..5c931b82d 100644 --- a/ExtremeRoles/Patches/DebugPatch/DebugKeyboardJoystickPatch.cs +++ b/ExtremeRoles/Patches/DebugPatch/DebugKeyboardJoystickPatch.cs @@ -75,7 +75,7 @@ public static void Postfix(KeyboardJoystick __instance) if (dict.Count == 0) { return; } for (int i = 0; i < GameData.Instance.PlayerCount; i++) { - GameData.PlayerInfo playerInfo = GameData.Instance.AllPlayers[i]; + NetworkedPlayerInfo playerInfo = GameData.Instance.AllPlayers[i]; var role = dict[playerInfo.PlayerId]; if (!role.HasTask()) { @@ -93,7 +93,7 @@ public static void Postfix(KeyboardJoystick __instance) if (dict.Count == 0) { return; } for (int i = 0; i < GameData.Instance.PlayerCount; i++) { - GameData.PlayerInfo playerInfo = GameData.Instance.AllPlayers[i]; + NetworkedPlayerInfo playerInfo = GameData.Instance.AllPlayers[i]; var role = dict[playerInfo.PlayerId]; if (!role.HasTask()) { diff --git a/ExtremeRoles/Patches/GameDataPatch.cs b/ExtremeRoles/Patches/GameDataPatch.cs index af7590655..45bc5f562 100644 --- a/ExtremeRoles/Patches/GameDataPatch.cs +++ b/ExtremeRoles/Patches/GameDataPatch.cs @@ -9,6 +9,7 @@ namespace ExtremeRoles.Patches; [HarmonyPatch(typeof(GameData), nameof(GameData.AddPlayer))] +[HarmonyPatch(typeof(GameData), nameof(GameData.AddDummy))] public static class GameDataAddPlayerPatch { public static void Postfix() @@ -21,20 +22,6 @@ public static void Postfix() } } -[HarmonyPatch(typeof(GameData), nameof(GameData.Deserialize))] -public static class GameDataDeserializePatch -{ - public static void Postfix() - { - foreach (CachedPlayerControl cachedPlayer in CachedPlayerControl.AllPlayerControls) - { - cachedPlayer.Data = cachedPlayer.PlayerControl.Data; - cachedPlayer.PlayerId = cachedPlayer.PlayerControl.PlayerId; - } - } -} - - [HarmonyPatch(typeof(GameData), nameof(GameData.RecomputeTaskCounts))] public static class GameDataRecomputeTaskCountsPatch { @@ -63,7 +50,7 @@ public static bool Prefix(GameData __instance) int completedTask = 0; int doTaskCrew = 0; - foreach (GameData.PlayerInfo playerInfo in __instance.AllPlayers.GetFastEnumerator()) + foreach (NetworkedPlayerInfo playerInfo in __instance.AllPlayers.GetFastEnumerator()) { if (!playerInfo.Disconnected && playerInfo.Tasks != null && @@ -90,7 +77,7 @@ public static bool Prefix(GameData __instance) ++doTaskCrew; - foreach (GameData.TaskInfo taskInfo in playerInfo.Tasks.GetFastEnumerator()) + foreach (var taskInfo in playerInfo.Tasks.GetFastEnumerator()) { ++totalTask; if (taskInfo.Complete) diff --git a/ExtremeRoles/Patches/HashRandomPatch.cs b/ExtremeRoles/Patches/HashRandomPatch.cs index 7b56ef83b..5717a5c36 100644 --- a/ExtremeRoles/Patches/HashRandomPatch.cs +++ b/ExtremeRoles/Patches/HashRandomPatch.cs @@ -1,5 +1,7 @@ using HarmonyLib; + + namespace ExtremeRoles.Patches; [HarmonyPatch(typeof(HashRandom), nameof(HashRandom.FastNext))] @@ -9,8 +11,7 @@ public static bool Prefix( ref int __result, [HarmonyArgument(0)] int maxInt) { - if (OptionManager.Instance.GetValue( - (int)OptionCreator.CommonOptionKey.UseStrongRandomGen)) + if (RandomGenerator.IsUsingStrongGenerator) { __result = RandomGenerator.Instance.Next(maxInt); return false; @@ -29,8 +30,7 @@ public static bool Prefix( ref int __result, [HarmonyArgument(0)] int maxInt) { - if (OptionManager.Instance.GetValue( - (int)OptionCreator.CommonOptionKey.UseStrongRandomGen)) + if (RandomGenerator.IsUsingStrongGenerator) { __result = RandomGenerator.Instance.Next(maxInt); return false; diff --git a/ExtremeRoles/Patches/KeyboardJoystickPatch.cs b/ExtremeRoles/Patches/KeyboardJoystickPatch.cs index e003a51af..11a57a3b2 100644 --- a/ExtremeRoles/Patches/KeyboardJoystickPatch.cs +++ b/ExtremeRoles/Patches/KeyboardJoystickPatch.cs @@ -8,6 +8,8 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module.RoleAssign; using ExtremeRoles.Roles.API.Extension.State; + + using ExtremeRoles.Performance; namespace ExtremeRoles.Patches; @@ -21,7 +23,7 @@ public static void Postfix() { return; } if (ExtremeGameModeManager.Instance.RoleSelector.CanUseXion && - OptionManager.Instance.GetValue((int)RoleGlobalOption.UseXion) && + // OptionManager.Instance.GetValue((int)RoleGlobalOption.UseXion) && !ExtremeRolesPlugin.DebugMode.Value) { Roles.Solo.Host.Xion.SpecialKeyShortCut(); @@ -29,7 +31,7 @@ public static void Postfix() if (GameSystem.IsLobby && Input.GetKeyDown(KeyCode.Tab)) { - Option.IGameOptionsExtensionsToHudStringPatch.ChangePage(1); + // Option.IGameOptionsExtensionsToHudStringPatch.ChangePage(1); } InfoOverlay.Instance.Update(); @@ -56,7 +58,7 @@ public static void Postfix() if (role.TryGetVanillaRoleId(out RoleTypes roleId)) { if (roleId != RoleTypes.Engineer || - ExtremeGameModeManager.Instance.ShipOption.EngineerUseImpostorVent) + ExtremeGameModeManager.Instance.ShipOption.Vent.EngineerUseImpostorVent) { hudManager.ImpostorVentButton.DoClick(); } diff --git a/ExtremeRoles/Patches/LogicGame/LogicGameFlowNormalPatch.cs b/ExtremeRoles/Patches/LogicGame/LogicGameFlowNormalPatch.cs index a82e5ad08..e9efcc1b5 100644 --- a/ExtremeRoles/Patches/LogicGame/LogicGameFlowNormalPatch.cs +++ b/ExtremeRoles/Patches/LogicGame/LogicGameFlowNormalPatch.cs @@ -79,7 +79,7 @@ private static bool isImpostorWin( if (statistics.TeamImpostorAlive >= (statistics.TotalAlive - statistics.TeamImpostorAlive) && statistics.SeparatedNeutralAlive.Count == 0) { - GameOverReason endReason = TempData.LastDeathReason switch + GameOverReason endReason = GameData.LastDeathReason switch { DeathReason.Exile => GameOverReason.ImpostorByVote, DeathReason.Kill => GameOverReason.ImpostorByKill, diff --git a/ExtremeRoles/Patches/Manager/EndGameManagerPatch.cs b/ExtremeRoles/Patches/Manager/EndGameManagerPatch.cs index d5ff219ec..2ebd01ea1 100644 --- a/ExtremeRoles/Patches/Manager/EndGameManagerPatch.cs +++ b/ExtremeRoles/Patches/Manager/EndGameManagerPatch.cs @@ -18,6 +18,8 @@ using ExtremeRoles.GameMode; using ExtremeRoles.Performance; + + using Il2CppArray = Il2CppSystem.Array; using Il2CppObject = Il2CppSystem.Object; @@ -45,7 +47,7 @@ public static void Postfix(EndGameManager __instance) private static List<(SingleRoleBase, byte)> setPlayerNameAndRole( in EndGameManager manager, in IReadOnlyList summaries, - in IReadOnlyList winner) + in IReadOnlyList winner) { List<(SingleRoleBase, byte)> winNeutral = new List<(SingleRoleBase, byte)>(winner.Count); @@ -55,8 +57,8 @@ public static void Postfix(EndGameManager __instance) Object.Destroy(pb.gameObject); } int num = Mathf.CeilToInt(7.5f); - IReadOnlyList winnerList = winner.OrderBy( - delegate (WinningPlayerData b) + IReadOnlyList winnerList = winner.OrderBy( + delegate (CachedPlayerData b) { if (!b.IsYou) { @@ -80,7 +82,7 @@ public static void Postfix(EndGameManager __instance) for (int i = 0; i < winnerList.Count; i++) { - WinningPlayerData winningPlayerData = winnerList[i]; + CachedPlayerData playerData = winnerList[i]; int num2 = (i % 2 == 0) ? -1 : 1; int num3 = (i + 1) / 2; float num4 = (float)num3 / (float)num; @@ -97,7 +99,7 @@ public static void Postfix(EndGameManager __instance) float num7 = Mathf.Lerp(1f, 0.65f, num4) * 0.9f; Vector3 vector = new Vector3(num7, num7, 1f); - bool isDead = winningPlayerData.IsDead; + bool isDead = playerData.IsDead; poolablePlayer.transform.localScale = vector; if (isDead) @@ -111,7 +113,7 @@ public static void Postfix(EndGameManager __instance) } poolablePlayer.UpdateFromPlayerOutfit( - winningPlayerData, + playerData.Outfit, PlayerMaterial.MaskType.None, isDead, true, null); @@ -123,7 +125,7 @@ public static void Postfix(EndGameManager __instance) text.transform.localPosition.x, text.transform.localPosition.y - 1.0f, -15f); - string name = winningPlayerData.PlayerName; + string name = playerData.PlayerName; text.text = name; foreach (var data in summaries) @@ -165,7 +167,7 @@ private static void setRoleSummary( private static void setWinDetailText( in EndGameManager manager, in List<(SingleRoleBase, byte)> winNeutral, - in IReadOnlyList plusWinner) + in IReadOnlyList plusWinner) { var winText = manager.WinText; diff --git a/ExtremeRoles/Patches/Manager/GameStartManagerPatch.cs b/ExtremeRoles/Patches/Manager/GameStartManagerPatch.cs index c7d8db4d5..a47137935 100644 --- a/ExtremeRoles/Patches/Manager/GameStartManagerPatch.cs +++ b/ExtremeRoles/Patches/Manager/GameStartManagerPatch.cs @@ -7,7 +7,7 @@ using AmongUs.Data; using ExtremeRoles.GameMode; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Helper; using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; @@ -236,24 +236,34 @@ public static void UpdatePostfix(GameStartManager __instance) } } - if (blockStart) + if (blockStart) { - __instance.StartButton.color = - __instance.startLabelText.color = Palette.DisabledClear; - __instance.GameStartText.text = message; + if (__instance.StartButtonGlyph != null) + { + __instance.StartButtonGlyph.SetColor(Palette.DisabledClear); + } + __instance.StartButton.SetButtonEnableState(false); + + __instance.GameStartText.text = message; __instance.GameStartText.transform.localPosition = __instance.StartButton.transform.localPosition + Vector3.up * 2; } else { - __instance.StartButton.color = __instance.startLabelText.color = ( - (__instance.LastPlayerCount >= __instance.MinPlayers) ? - Palette.EnabledColor : Palette.DisabledClear); - __instance.GameStartText.transform.localPosition = + bool isPlayerOk = __instance.LastPlayerCount >= __instance.MinPlayers; + + if (__instance.StartButtonGlyph != null) + { + __instance.StartButtonGlyph.SetColor(isPlayerOk ? + Palette.EnabledColor : Palette.DisabledClear); + } + + __instance.StartButton.SetButtonEnableState(isPlayerOk); + __instance.GameStartText.transform.localPosition = __instance.StartButton.transform.localPosition; } - if (AmongUsClient.Instance.NetworkMode == NetworkModes.OnlineGame && !isCustomServer) + if (AmongUsClient.Instance.NetworkMode == NetworkModes.OnlineGame && !isCustomServer) { // プレイヤーカウントアップデート if (update) diff --git a/ExtremeRoles/Patches/Manager/HudManagerPatch.cs b/ExtremeRoles/Patches/Manager/HudManagerPatch.cs index 3564b0b3f..09ecfc9a1 100644 --- a/ExtremeRoles/Patches/Manager/HudManagerPatch.cs +++ b/ExtremeRoles/Patches/Manager/HudManagerPatch.cs @@ -19,6 +19,8 @@ using ExtremeRoles.Performance; using ExtremeRoles.Patches.MapOverlay; + + using CommomSystem = ExtremeRoles.Roles.API.Systems.Common; namespace ExtremeRoles.Patches.Manager; @@ -103,10 +105,6 @@ public static void SetBlockUpdate(bool isBlock) public static bool Prefix(HudManager __instance) { - if (__instance.GameSettings != null) - { - __instance.GameSettings.fontSize = 1.2f; - } if (ExtremeRolesPlugin.ShipState.AssassinMeetingTrigger) { __instance.UseButton.ToggleVisible(false); diff --git a/ExtremeRoles/Patches/Manager/RoleManagerPatch.cs b/ExtremeRoles/Patches/Manager/RoleManagerPatch.cs index 2cd4c6f1a..7efbcbbc1 100644 --- a/ExtremeRoles/Patches/Manager/RoleManagerPatch.cs +++ b/ExtremeRoles/Patches/Manager/RoleManagerPatch.cs @@ -63,7 +63,7 @@ public static void Prefix() int adjustedNumImpostors = currentOption.GetAdjustedNumImpostors(allPlayer.Count); - var il2CppListPlayer = new Il2CppSystem.Collections.Generic.List(); + var il2CppListPlayer = new Il2CppSystem.Collections.Generic.List(); foreach (PlayerControl player in allPlayer) { @@ -224,15 +224,15 @@ private static void addSingleExtremeRoleAssignData( $"----------------------------- SingleRoleAssign End!! -----------------------------"); } - private static void addImpostorSingleExtremeRoleAssignData( - ref RoleSpawnDataManager spawnData, - ref PlayerRoleAssignData assignData) - { - addSingleExtremeRoleAssignDataFromTeamAndPlayer( - ref spawnData, ref assignData, - ExtremeRoleType.Impostor, - assignData.GetCanImpostorAssignPlayer(), - new HashSet { RoleTypes.Shapeshifter }); + private static void addImpostorSingleExtremeRoleAssignData( + ref RoleSpawnDataManager spawnData, + ref PlayerRoleAssignData assignData) + { + addSingleExtremeRoleAssignDataFromTeamAndPlayer( + ref spawnData, ref assignData, + ExtremeRoleType.Impostor, + assignData.GetCanImpostorAssignPlayer(), + [ RoleTypes.Shapeshifter, RoleTypes.Phantom ]); } private static void addNeutralSingleExtremeRoleAssignData( @@ -273,7 +273,7 @@ private static void addNeutralSingleExtremeRoleAssignData( ref spawnData, ref assignData, ExtremeRoleType.Neutral, neutralAssignTargetPlayer, - new HashSet { RoleTypes.Engineer, RoleTypes.Scientist }); + [RoleTypes.Engineer, RoleTypes.Scientist, RoleTypes.Noisemaker, RoleTypes.Tracker]); } private static void addCrewmateSingleExtremeRoleAssignData( @@ -284,7 +284,7 @@ private static void addCrewmateSingleExtremeRoleAssignData( ref spawnData, ref assignData, ExtremeRoleType.Crewmate, assignData.GetCanCrewmateAssignPlayer(), - new HashSet { RoleTypes.Engineer, RoleTypes.Scientist }); + [RoleTypes.Engineer, RoleTypes.Scientist, RoleTypes.Noisemaker, RoleTypes.Tracker]); } private static void addSingleExtremeRoleAssignDataFromTeamAndPlayer( @@ -541,25 +541,32 @@ private static bool isCanMulitAssignRoleToPlayer( return ( - roleType == RoleTypes.Crewmate && isAssignToCrewmate + roleType is RoleTypes.Crewmate && isAssignToCrewmate ) || ( - roleType == RoleTypes.Impostor && isImpostor + roleType is RoleTypes.Impostor && isImpostor ) || ( ( - roleType == RoleTypes.Engineer || - roleType == RoleTypes.Scientist + roleType is + RoleTypes.Engineer or + RoleTypes.Scientist or + RoleTypes.Noisemaker or + RoleTypes.Tracker ) && hasAnotherRole && isAssignToCrewmate ) || ( - roleType == RoleTypes.Shapeshifter && - hasAnotherRole && isAssignToCrewmate - ); + ( + roleType is + RoleTypes.Shapeshifter or + RoleTypes.Phantom + ) && + hasAnotherRole && isImpostor + ); } } @@ -603,10 +610,10 @@ public static class RoleManagerTryAssignRoleOnDeathPatch // クルーの幽霊役職の処理(インポスターの時はここに来ない) public static bool Prefix([HarmonyArgument(0)] PlayerControl player) { - if (ExtremeRoleManager.GameRole.Count == 0) { return true; } - if (!RoleAssignState.Instance.IsRoleSetUpEnd) { return true; } // バニラ幽霊クルー役職にニュートラルがアサインされる時はTrueを返す - if (ExtremeGameModeManager.Instance.ShipOption.IsAssignNeutralToVanillaCrewGhostRole) + if (ExtremeRoleManager.GameRole.Count == 0 || + !RoleAssignState.Instance.IsRoleSetUpEnd || + ExtremeGameModeManager.Instance.ShipOption.GhostRole.IsAssignNeutralToVanillaCrewGhostRole) { return true; } diff --git a/ExtremeRoles/Patches/MapModule/ConsolePatch.cs b/ExtremeRoles/Patches/MapModule/ConsolePatch.cs index 59a9b3bd9..0c7d12d25 100644 --- a/ExtremeRoles/Patches/MapModule/ConsolePatch.cs +++ b/ExtremeRoles/Patches/MapModule/ConsolePatch.cs @@ -12,7 +12,7 @@ public static class ConsoleCanUsePatch { public static bool Prefix( ref float __result, Console __instance, - [HarmonyArgument(0)] GameData.PlayerInfo pc, + [HarmonyArgument(0)] NetworkedPlayerInfo pc, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse) { canUse = couldUse = false; diff --git a/ExtremeRoles/Patches/MapModule/VentPatch.cs b/ExtremeRoles/Patches/MapModule/VentPatch.cs index 71a5b3953..3715f22bd 100644 --- a/ExtremeRoles/Patches/MapModule/VentPatch.cs +++ b/ExtremeRoles/Patches/MapModule/VentPatch.cs @@ -8,7 +8,7 @@ using ExtremeRoles.Compat; using ExtremeRoles.GameMode; -using ExtremeRoles.GameMode.Option.ShipGlobal; +using ExtremeRoles.GameMode.Option.ShipGlobal.Sub.MapModule; using ExtremeRoles.Module.RoleAssign; using ExtremeRoles.Roles.API.Extension.State; using ExtremeRoles.Roles; @@ -121,7 +121,7 @@ private static IEnumerator noExitVentAnim(Vent vent, PlayerControl pc) private static bool isRunOriginal(Vent vent, PlayerControl pc) { - var ventAnimationMode = ExtremeGameModeManager.Instance.ShipOption.VentAnimationMode; + var ventAnimationMode = ExtremeGameModeManager.Instance.ShipOption.Vent.AnimationMode; PlayerControl? localPlayer = CachedPlayerControl.LocalPlayer; if (localPlayer == null || @@ -160,7 +160,7 @@ public static class VentCanUsePatch public static bool Prefix( Vent __instance, ref float __result, - [HarmonyArgument(0)] GameData.PlayerInfo playerInfo, + [HarmonyArgument(0)] NetworkedPlayerInfo playerInfo, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse) { @@ -169,7 +169,7 @@ public static bool Prefix( canUse = couldUse = false; - if (ExtremeGameModeManager.Instance.ShipOption.DisableVent) + if (ExtremeGameModeManager.Instance.ShipOption.Vent.Disable) { __result = num; return false; @@ -190,7 +190,7 @@ public static bool Prefix( { (__result, canUse, couldUse) = modMap!.IsCustomVentUseResult( __instance, playerInfo, - playerInfo.Role.IsImpostor || playerInfo.Role.Role == RoleTypes.Engineer); + playerInfo.Role.IsImpostor || playerInfo.Role.Role is RoleTypes.Engineer); return false; } return true; diff --git a/ExtremeRoles/Patches/MapOverlay/MapCountOverlayPatch.cs b/ExtremeRoles/Patches/MapOverlay/MapCountOverlayPatch.cs index 94d60a153..8dda98aa2 100644 --- a/ExtremeRoles/Patches/MapOverlay/MapCountOverlayPatch.cs +++ b/ExtremeRoles/Patches/MapOverlay/MapCountOverlayPatch.cs @@ -112,7 +112,7 @@ public static bool Prefix(MapCountOverlay __instance) { showNum++; - GameData.PlayerInfo playerInfo = GameData.Instance.GetPlayerById( + NetworkedPlayerInfo playerInfo = GameData.Instance.GetPlayerById( component.ParentId); if (playerInfo != null) { @@ -205,11 +205,10 @@ public static void Initialize() public static void LoadOptionValue() { var adminOpt = ExtremeGameModeManager.Instance.ShipOption.Admin; - if (adminOpt == null) { return; } - adminTimer = adminOpt.AdminLimitTime; + adminTimer = adminOpt.LimitTime; isRemoveAdmin = adminOpt.Disable; - enableAdminLimit = adminOpt.EnableAdminLimit; + enableAdminLimit = adminOpt.EnableLimit; Logging.Debug("---- AdminCondition ----"); Logging.Debug($"IsRemoveAdmin:{isRemoveAdmin}"); diff --git a/ExtremeRoles/Patches/Meeting/Hud/BloopAVoteIconPatch.cs b/ExtremeRoles/Patches/Meeting/Hud/BloopAVoteIconPatch.cs index d55e6860f..0256fcfd1 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/BloopAVoteIconPatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/BloopAVoteIconPatch.cs @@ -11,6 +11,8 @@ using CommomSystem = ExtremeRoles.Roles.API.Systems.Common; + + namespace ExtremeRoles.Patches.Meeting.Hud; #nullable enable @@ -20,7 +22,7 @@ public static class MeetingHudBloopAVoteIconPatch { public static bool Prefix( MeetingHud __instance, - [HarmonyArgument(0)] GameData.PlayerInfo voterPlayer, + [HarmonyArgument(0)] NetworkedPlayerInfo voterPlayer, [HarmonyArgument(1)] int index, [HarmonyArgument(2)] Transform parent) { diff --git a/ExtremeRoles/Patches/Meeting/Hud/CheckForEndVotingPatch.cs b/ExtremeRoles/Patches/Meeting/Hud/CheckForEndVotingPatch.cs index 1629e10ac..cf9697a31 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/CheckForEndVotingPatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/CheckForEndVotingPatch.cs @@ -45,7 +45,7 @@ private static void assassinMeetingVote(MeetingHud instance) var logger = ExtremeRolesPlugin.Logger; logger.LogInfo(" ----- AssassinMeeting Target selecting is End ----- "); - //GameData.PlayerInfo exiled = Helper.Player.GetPlayerControlById(voteFor).Data; + //NetworkedPlayerInfo exiled = Helper.Player.GetPlayerControlById(voteFor).Data; Il2CppStructArray array = new Il2CppStructArray( instance.playerStates.Length); @@ -214,8 +214,8 @@ private static void normalMeetingVote(MeetingHud instance) } } - GameData.PlayerInfo? exiled = GameData.Instance.AllPlayers.ToArray().FirstOrDefault( - (GameData.PlayerInfo v) => !isTie && v.PlayerId == result.PlayerId); + NetworkedPlayerInfo? exiled = GameData.Instance.AllPlayers.ToArray().FirstOrDefault( + (NetworkedPlayerInfo v) => !isTie && v.PlayerId == result.PlayerId); if (exiled != null) { diff --git a/ExtremeRoles/Patches/Meeting/Hud/CoIntroPatch.cs b/ExtremeRoles/Patches/Meeting/Hud/CoIntroPatch.cs index 37bb342a1..5c7b67c45 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/CoIntroPatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/CoIntroPatch.cs @@ -14,8 +14,8 @@ public static class MeetingHudCoIntroPatch { public static void Postfix( MeetingHud __instance, - [HarmonyArgument(0)] GameData.PlayerInfo reporter, - [HarmonyArgument(1)] GameData.PlayerInfo reportedBody) + [HarmonyArgument(0)] NetworkedPlayerInfo reporter, + [HarmonyArgument(1)] NetworkedPlayerInfo reportedBody) { if (ExtremeRoleManager.GameRole.Count == 0) { return; } diff --git a/ExtremeRoles/Patches/Meeting/Hud/PopulateResultsPatch.cs b/ExtremeRoles/Patches/Meeting/Hud/PopulateResultsPatch.cs index ee8556fad..b55146c23 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/PopulateResultsPatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/PopulateResultsPatch.cs @@ -31,8 +31,8 @@ public static bool Prefix( StringNames.MeetingVotingResults, Array.Empty()); Dictionary voteIndex = new Dictionary(); - SortedList voteModifier = new SortedList< - int, (IRoleVoteModifier, GameData.PlayerInfo)>(); + SortedList voteModifier = new SortedList< + int, (IRoleVoteModifier, NetworkedPlayerInfo)>(); int num = 0; // それぞれの人に対してどんな投票があったか @@ -56,7 +56,7 @@ public static bool Prefix( int num2 = 0; foreach (MeetingHud.VoterState voterState in states) { - GameData.PlayerInfo playerById = GameData.Instance.GetPlayerById(voterState.VoterId); + NetworkedPlayerInfo playerById = GameData.Instance.GetPlayerById(voterState.VoterId); if (playerById == null) { Debug.LogError( @@ -91,14 +91,14 @@ public static bool Prefix( } private static void addVoteModRole( IRoleVoteModifier? role, byte rolePlayerId, - ref SortedList voteModifier) + ref SortedList voteModifier) { if (role is null) { return; } - GameData.PlayerInfo playerById = GameData.Instance.GetPlayerById(rolePlayerId); + NetworkedPlayerInfo playerById = GameData.Instance.GetPlayerById(rolePlayerId); int order = role.Order; // 同じ役職は同じ優先度になるので次の優先度になるようにセット diff --git a/ExtremeRoles/Patches/Meeting/Hud/SelectPatch.cs b/ExtremeRoles/Patches/Meeting/Hud/SelectPatch.cs index 837580377..d8c9f35dd 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/SelectPatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/SelectPatch.cs @@ -26,7 +26,7 @@ public static bool Prefix( if (isBlock) { return false; } - var shipOpt = ExtremeGameModeManager.Instance.ShipOption; + var shipOpt = ExtremeGameModeManager.Instance.ShipOption.Meeting; if (shipOpt.DisableSelfVote && CachedPlayerControl.LocalPlayer.PlayerId == suspectStateIdx) diff --git a/ExtremeRoles/Patches/Meeting/Hud/SortButtonsPatch.cs b/ExtremeRoles/Patches/Meeting/Hud/SortButtonsPatch.cs index 97091d553..ba5fc020a 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/SortButtonsPatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/SortButtonsPatch.cs @@ -13,6 +13,7 @@ using ExtremeRoles.Module.SystemType; + using ExtremeRoles.Module.Interface; namespace ExtremeRoles.Patches.Meeting.Hud; @@ -22,7 +23,7 @@ public static class MeetingHudSortButtonsPatch { public static bool Prefix(MeetingHud __instance) { - if (!ExtremeGameModeManager.Instance.ShipOption.IsChangeVoteAreaButtonSortArg || + if (!ExtremeGameModeManager.Instance.ShipOption.Meeting.IsChangeVoteAreaButtonSortArg || ExtremeRoleManager.GameRole.Count == 0) { return true; } PlayerVoteArea[] array = __instance.playerStates.OrderBy(delegate (PlayerVoteArea p) @@ -54,8 +55,7 @@ public static void Postfix(MeetingHud __instance) bool isHudOverrideTaskActive = PlayerTask.PlayerHasTaskOfType( player); - var system = OptionManager.Instance.GetValue - ((int)OptionCreator.CommonOptionKey.UseRaiseHand) ? IRaiseHandSystem.Get() : null; + var system = ExtremeGameModeManager.Instance.ShipOption.Meeting.UseRaiseHand ? IRaiseHandSystem.Get() : null; for (int i = 0; i < __instance.playerStates.Length; i++) { diff --git a/ExtremeRoles/Patches/Meeting/Hud/UpdateButtonsPatch.cs b/ExtremeRoles/Patches/Meeting/Hud/UpdateButtonsPatch.cs index 85b14c4be..9edd5b365 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/UpdateButtonsPatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/UpdateButtonsPatch.cs @@ -22,7 +22,7 @@ public static bool Prefix(MeetingHud __instance) for (int i = 0; i < __instance.playerStates.Length; i++) { PlayerVoteArea playerVoteArea = __instance.playerStates[i]; - GameData.PlayerInfo playerById = GameData.Instance.GetPlayerById( + NetworkedPlayerInfo playerById = GameData.Instance.GetPlayerById( playerVoteArea.TargetPlayerId); if (playerById == null) { diff --git a/ExtremeRoles/Patches/Meeting/Hud/UpdatePatch.cs b/ExtremeRoles/Patches/Meeting/Hud/UpdatePatch.cs index 903928776..8b98dda7f 100644 --- a/ExtremeRoles/Patches/Meeting/Hud/UpdatePatch.cs +++ b/ExtremeRoles/Patches/Meeting/Hud/UpdatePatch.cs @@ -71,7 +71,7 @@ public static void Postfix(MeetingHud __instance) } // Deactivate skip Button if skipping on emergency meetings is disabled - if (ExtremeGameModeManager.Instance.ShipOption.IsBlockSkipInMeeting) + if (ExtremeGameModeManager.Instance.ShipOption.Meeting.IsBlockSkipInMeeting) { __instance.SkipVoteButton.gameObject.SetActive(false); } diff --git a/ExtremeRoles/Patches/Meeting/MeetingIntroAnimationPatch.cs b/ExtremeRoles/Patches/Meeting/MeetingIntroAnimationPatch.cs index 297298733..f475e1344 100644 --- a/ExtremeRoles/Patches/Meeting/MeetingIntroAnimationPatch.cs +++ b/ExtremeRoles/Patches/Meeting/MeetingIntroAnimationPatch.cs @@ -56,7 +56,7 @@ public static void Postfix( string gaProtectText = string.Empty; - if (someoneWasProtected && !ExtremeGameModeManager.Instance.ShipOption.IsBlockGAAbilityReport) + if (someoneWasProtected && !ExtremeGameModeManager.Instance.ShipOption.GhostRole.IsBlockGAAbilityReport) { gaProtectText = text.text; } diff --git a/ExtremeRoles/Patches/Meeting/PlayerVoteAreaPatch.cs b/ExtremeRoles/Patches/Meeting/PlayerVoteAreaPatch.cs index ed9a5807d..4d6566d6a 100644 --- a/ExtremeRoles/Patches/Meeting/PlayerVoteAreaPatch.cs +++ b/ExtremeRoles/Patches/Meeting/PlayerVoteAreaPatch.cs @@ -13,6 +13,8 @@ using ExtremeRoles.Roles; using ExtremeRoles.Roles.API.Interface; + + using Il2CppActionFloat = Il2CppSystem.Action; using Il2CppIEnumerator = Il2CppSystem.Collections.IEnumerator; @@ -47,7 +49,7 @@ public static void UpdateNameplate( [HarmonyPatch(typeof(PlayerVoteArea), nameof(PlayerVoteArea.SetCosmetics))] public static class PlayerVoteAreaCosmetics { - public static void Postfix(PlayerVoteArea __instance, GameData.PlayerInfo playerInfo) + public static void Postfix(PlayerVoteArea __instance, NetworkedPlayerInfo playerInfo) { NamePlateHelper.UpdateNameplate( __instance, playerInfo.PlayerId); @@ -241,7 +243,7 @@ public static class PlayerVoteAreaSetCosmeticsPatch { public static void Postfix(PlayerVoteArea __instance) { - if (ExtremeGameModeManager.Instance.ShipOption.IsFixedVoteAreaPlayerLevel) + if (ExtremeGameModeManager.Instance.ShipOption.Meeting.IsFixedVoteAreaPlayerLevel) { __instance.LevelNumberText.text = "99"; } @@ -275,7 +277,7 @@ public static void Postfix( [HarmonyArgument(1)] bool isDead, [HarmonyArgument(2)] bool isGuardian = false) { - if (ExtremeGameModeManager.Instance.ShipOption.IsRemoveAngleIcon) + if (ExtremeGameModeManager.Instance.ShipOption.GhostRole.IsRemoveAngleIcon) { __instance.GAIcon.gameObject.SetActive(false); } diff --git a/ExtremeRoles/Patches/MiniGame/EmergencyMinigamePatch.cs b/ExtremeRoles/Patches/MiniGame/EmergencyMinigamePatch.cs index a43858dec..fd3c94e30 100644 --- a/ExtremeRoles/Patches/MiniGame/EmergencyMinigamePatch.cs +++ b/ExtremeRoles/Patches/MiniGame/EmergencyMinigamePatch.cs @@ -27,10 +27,10 @@ public static void Postfix(EmergencyMinigame __instance) // Handle max number of meetings if (__instance.state == 1) { - int localRemaining = + int localRemaining = CachedPlayerControl.LocalPlayer.PlayerControl.RemainingEmergencies; int teamRemaining = Mathf.Max( - 0, ExtremeGameModeManager.Instance.ShipOption.MaxMeetingCount - + 0, ExtremeGameModeManager.Instance.ShipOption.Meeting.MaxMeetingCount - ExtremeRolesPlugin.ShipState.MeetingCount); int remaining = Mathf.Min(localRemaining, teamRemaining); diff --git a/ExtremeRoles/Patches/MiniGame/SpawnInMinigamePatch.cs b/ExtremeRoles/Patches/MiniGame/SpawnInMinigamePatch.cs index 74a9a26ff..1754171e4 100644 --- a/ExtremeRoles/Patches/MiniGame/SpawnInMinigamePatch.cs +++ b/ExtremeRoles/Patches/MiniGame/SpawnInMinigamePatch.cs @@ -14,8 +14,6 @@ public static void Postfix(SpawnInMinigame __instance) { var spawnOpt = ExtremeGameModeManager.Instance.ShipOption.Spawn; - if (spawnOpt == null) { return; } - if (!(spawnOpt.EnableSpecialSetting && spawnOpt.AirShip)) { __instance.gotButton = true; diff --git a/ExtremeRoles/Patches/MiniGame/SurveillanceMinigamePatch.cs b/ExtremeRoles/Patches/MiniGame/SurveillanceMinigamePatch.cs index 44c5144b8..da4de760e 100644 --- a/ExtremeRoles/Patches/MiniGame/SurveillanceMinigamePatch.cs +++ b/ExtremeRoles/Patches/MiniGame/SurveillanceMinigamePatch.cs @@ -34,11 +34,10 @@ public static class SecurityHelper public static void LoadOptionValue() { var securityOption = ExtremeGameModeManager.Instance.ShipOption.Security; - if (securityOption == null) { return; } - cameraTimer = securityOption.SecurityLimitTime; + cameraTimer = securityOption.LimitTime; isRemoveSecurity = securityOption.Disable; - enableCameraLimit = securityOption.EnableSecurityLimit; + enableCameraLimit = securityOption.EnableLimit; Logging.Debug("---- SecurityCondition ----"); Logging.Debug($"IsRemoveSecurity:{enableCameraLimit}"); diff --git a/ExtremeRoles/Patches/MiniGame/VitalsMinigamePatch.cs b/ExtremeRoles/Patches/MiniGame/VitalsMinigamePatch.cs index c4b78e3dc..0cab8d3b6 100644 --- a/ExtremeRoles/Patches/MiniGame/VitalsMinigamePatch.cs +++ b/ExtremeRoles/Patches/MiniGame/VitalsMinigamePatch.cs @@ -97,11 +97,10 @@ public static void Initialize() public static void LoadOptionValue() { var vitalOption = ExtremeGameModeManager.Instance.ShipOption.Vital; - if (vitalOption == null) { return; } - vitalTimer = vitalOption.VitalLimitTime; + vitalTimer = vitalOption.LimitTime; isRemoveVital = vitalOption.Disable; - enableVitalLimit = vitalOption.EnableVitalLimit; + enableVitalLimit = vitalOption.EnableLimit; Logging.Debug("---- VitalCondition ----"); Logging.Debug($"IsRemoveVital:{isRemoveVital}"); diff --git a/ExtremeRoles/Patches/NetworkedPlayerInfoPatch.cs b/ExtremeRoles/Patches/NetworkedPlayerInfoPatch.cs new file mode 100644 index 000000000..dff9df78c --- /dev/null +++ b/ExtremeRoles/Patches/NetworkedPlayerInfoPatch.cs @@ -0,0 +1,19 @@ +using HarmonyLib; + +using ExtremeRoles.Performance; + +namespace ExtremeRoles.Patches; + + +[HarmonyPatch(typeof(NetworkedPlayerInfo), nameof(NetworkedPlayerInfo.Deserialize))] +public static class NetworkedPlayerInfoDeserializePatch +{ + public static void Postfix() + { + foreach (CachedPlayerControl cachedPlayer in CachedPlayerControl.AllPlayerControls) + { + cachedPlayer.Data = cachedPlayer.PlayerControl.Data; + cachedPlayer.PlayerId = cachedPlayer.PlayerControl.PlayerId; + } + } +} diff --git a/ExtremeRoles/Patches/Option/GameOptionsManuPatch.cs b/ExtremeRoles/Patches/Option/GameOptionsManuPatch.cs deleted file mode 100644 index 46a7996d2..000000000 --- a/ExtremeRoles/Patches/Option/GameOptionsManuPatch.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -using UnityEngine; -using Il2CppInterop.Runtime.InteropTypes.Arrays; - -using HarmonyLib; - - -using ExtremeRoles.Helper; -using ExtremeRoles.Module.CustomMonoBehaviour; -using ExtremeRoles.Extension.Manager; -using ExtremeRoles.Performance; - - -namespace ExtremeRoles.Patches.Option; - -[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.Start))] -public static class GameOptionsMenuStartPatch -{ - private static List<(StringNames, Action)> hooks = - new List<(StringNames, Action)>(); - - public static void AddHook(StringNames targetOption, Action hook) - { - hooks.Add((targetOption, hook)); - } - - public static void Postfix(GameOptionsMenu __instance) - { - // SliderInnner => GameGroup => Game Settings => PlayerOptionsMenu - GameObject playerOptMenuObj = __instance.transform.parent.parent.parent.gameObject; - - if (playerOptMenuObj.GetComponent() != null) { return; } - - // Adapt task count for main options - modifiedDefaultGameOptions(__instance); - // AddHook - addHookOptionValueChange(__instance.Children); - - playerOptMenuObj.AddComponent(); - } - - private static void addHookOptionValueChange( - Il2CppReferenceArray child) - { - foreach (var (name, hook) in hooks) - { - if (!child.tryGetOption(name, out OptionBehaviour opt)) { return; } - - // まず初期化 - hook.Invoke(opt); - - //ほんでで追加 - opt.OnValueChanged += hook; - } - } - - private static void changeValueRange( - Il2CppReferenceArray child, - StringNames name, float minValue, float maxValue) - { - if (!child.tryGetOption(name, out OptionBehaviour opt)) { return; } - - NumberOption numOpt = opt.TryCast(); - if (!numOpt) { return; } - numOpt.ValidRange = new FloatRange(minValue, maxValue); - } - - private static void modifiedDefaultGameOptions(GameOptionsMenu instance) - { - Il2CppReferenceArray child = instance.Children; - - if (AmongUsClient.Instance.NetworkMode == NetworkModes.LocalGame || - FastDestroyableSingleton.Instance.IsCustomServer()) - { - changeValueRange(child, StringNames.GameNumImpostors, 0f, GameSystem.MaxImposterNum); - } - - changeValueRange(child, StringNames.GameCommonTasks, 0f, 4f ); - changeValueRange(child, StringNames.GameShortTasks , 0f, 23f); - changeValueRange(child, StringNames.GameLongTasks , 0f, 15f); - } - - private static OptionBehaviour tryGetOption( - this Il2CppReferenceArray child, - StringNames name, out OptionBehaviour optionBehaviour) - { - optionBehaviour = child.FirstOrDefault(x => x.Title == name); - - return optionBehaviour; - } -} diff --git a/ExtremeRoles/Patches/Option/GameSettingMenuPatch.cs b/ExtremeRoles/Patches/Option/GameSettingMenuPatch.cs new file mode 100644 index 000000000..7aab9babf --- /dev/null +++ b/ExtremeRoles/Patches/Option/GameSettingMenuPatch.cs @@ -0,0 +1,39 @@ +using HarmonyLib; + +using ExtremeRoles.Extension.Il2Cpp; +using ExtremeRoles.Module.CustomMonoBehaviour; + + +#nullable enable + +namespace ExtremeRoles.Patches.Option; + +[HarmonyPatch(typeof(GameSettingMenu), nameof(GameSettingMenu.Start))] +public static class GameSettingMenuStartPatch +{ + private const float yScale = 0.85f; + + public static void Postfix(GameSettingMenu __instance) + { + using (var dec = new ExtremeGameSettingMenu.Initializer(__instance)) + { + var menu = __instance.gameObject.TryAddComponent(); + menu.Initialize(dec); + } + } +} + +[HarmonyPatch(typeof(GameSettingMenu), nameof(GameSettingMenu.ChangeTab))] +public static class GameSettingMenuChangeTabPatch +{ + public static void Prefix( + GameSettingMenu __instance, + [HarmonyArgument(0)] int tabNum, + [HarmonyArgument(1)] bool previewOnly) + { + if (__instance.TryGetComponent(out var menu)) + { + menu.SwitchTabPrefix(previewOnly); + } + } +} diff --git a/ExtremeRoles/Patches/Option/IGameOptionsExtensionsPatch.cs b/ExtremeRoles/Patches/Option/IGameOptionsExtensionsPatch.cs index d3d06110e..f8907171e 100644 --- a/ExtremeRoles/Patches/Option/IGameOptionsExtensionsPatch.cs +++ b/ExtremeRoles/Patches/Option/IGameOptionsExtensionsPatch.cs @@ -14,6 +14,8 @@ using ExtremeRoles.GameMode.RoleSelector; using ExtremeRoles.GameMode.Option.ShipGlobal; + + namespace ExtremeRoles.Patches.Option; [HarmonyPatch( @@ -31,7 +33,7 @@ public static bool Prefix(ref int __result) return false; } } - +/* [HarmonyPatch( typeof(IGameOptionsExtensions), nameof(IGameOptionsExtensions.ToHudString))] @@ -58,8 +60,8 @@ public static void Postfix(ref string __result) List allOptionStr = [ - getHudString(OptionCreator.CommonOptionKey.PresetSelection), - getHudString(OptionCreator.CommonOptionKey.UseRaiseHand), + getHudString(OptionCreator.PresetOptionKey.PresetSelection), + getHudString(OptionCreator.PresetOptionKey.UseRaiseHand), createRngOptionHudString(), createRoleSpawnNumOptionHudString() ]; @@ -69,7 +71,7 @@ public static void Postfix(ref string __result) allOptionStr.Add( Design.ColoedString( ColorPalette.XionBlue, - getHudString(RoleGlobalOption.UseXion))); + getHudString(RoleSpawnOption.UseXion))); } egmm.ShipOption.AddHudString(allOptionStr); @@ -80,8 +82,8 @@ public static void Postfix(ref string __result) { int optionId = option.Id; - if (Enum.IsDefined(typeof(OptionCreator.CommonOptionKey), optionId) || - Enum.IsDefined(typeof(RoleGlobalOption), optionId) || + if (Enum.IsDefined(typeof(OptionCreator.PresetOptionKey), optionId) || + Enum.IsDefined(typeof(RoleSpawnOption), optionId) || Enum.IsDefined(typeof(GlobalOption), optionId)) { continue; @@ -147,42 +149,42 @@ private static string createRoleSpawnNumOptionHudString() .AppendLine( createRoleSpawnNumOptionHudStringLine( "crewmateRoles", - RoleGlobalOption.MinCrewmateRoles, - RoleGlobalOption.MaxCrewmateRoles)) + RoleSpawnOption.MinCrewmateRoles, + RoleSpawnOption.MaxCrewmateRoles)) .AppendLine( createRoleSpawnNumOptionHudStringLine( "neutralRoles", - RoleGlobalOption.MinNeutralRoles, - RoleGlobalOption.MaxNeutralRoles)) + RoleSpawnOption.MinNeutralRoles, + RoleSpawnOption.MaxNeutralRoles)) .AppendLine( createRoleSpawnNumOptionHudStringLine( "impostorRoles", - RoleGlobalOption.MinImpostorRoles, - RoleGlobalOption.MaxImpostorRoles)) + RoleSpawnOption.MinImpostorRoles, + RoleSpawnOption.MaxImpostorRoles)) .AppendLine() // 幽霊役職周り .AppendLine( createRoleSpawnNumOptionHudStringLine( "crewmateGhostRoles", - RoleGlobalOption.MinCrewmateGhostRoles, - RoleGlobalOption.MaxCrewmateGhostRoles)) + RoleSpawnOption.MinCrewmateGhostRoles, + RoleSpawnOption.MaxCrewmateGhostRoles)) .AppendLine( createRoleSpawnNumOptionHudStringLine( "neutralGhostRoles", - RoleGlobalOption.MinNeutralGhostRoles, - RoleGlobalOption.MaxNeutralGhostRoles)) + RoleSpawnOption.MinNeutralGhostRoles, + RoleSpawnOption.MaxNeutralGhostRoles)) .AppendLine( createRoleSpawnNumOptionHudStringLine( "impostorGhostRoles", - RoleGlobalOption.MinImpostorGhostRoles, - RoleGlobalOption.MaxImpostorGhostRoles)); + RoleSpawnOption.MinImpostorGhostRoles, + RoleSpawnOption.MaxImpostorGhostRoles)); return builder.ToString().Trim('\r', '\n'); } private static string createRoleSpawnNumOptionHudStringLine( - string transKey, RoleGlobalOption minOptKey, RoleGlobalOption maxOptKey) + string transKey, RoleSpawnOption minOptKey, RoleSpawnOption maxOptKey) { string optionName = Design.ColoedString( new Color(204f / 255f, 204f / 255f, 0, 1f), @@ -199,9 +201,9 @@ private static string createRngOptionHudString() StringBuilder rngOptBuilder = new StringBuilder(); rngOptBuilder .AppendLine( - getHudString(OptionCreator.CommonOptionKey.UseStrongRandomGen)) + getHudString(OptionCreator.PresetOptionKey.UseStrongRandomGen)) .AppendLine( - getHudString(OptionCreator.CommonOptionKey.UsePrngAlgorithm)); + getHudString(OptionCreator.PresetOptionKey.UsePrngAlgorithm)); return rngOptBuilder.ToString().Trim('\r', '\n'); } @@ -212,7 +214,7 @@ private static string getHudString(T optionKey) where T : struct, IConvertibl return option.ToHudString(); } - private static int getSpawnOptionValue(RoleGlobalOption optionKey) + private static int getSpawnOptionValue(RoleSpawnOption optionKey) => OptionManager.Instance.GetValue((int)optionKey); private static string translate(string key) @@ -220,3 +222,4 @@ private static string translate(string key) return Translation.GetString(key); } } +*/ \ No newline at end of file diff --git a/ExtremeRoles/Patches/Option/KeyValueOptionPatch.cs b/ExtremeRoles/Patches/Option/KeyValueOptionPatch.cs deleted file mode 100644 index 05a133877..000000000 --- a/ExtremeRoles/Patches/Option/KeyValueOptionPatch.cs +++ /dev/null @@ -1,25 +0,0 @@ -using UnityEngine; - -using HarmonyLib; - -namespace ExtremeRoles.Patches; - -[HarmonyPatch(typeof(KeyValueOption), nameof(KeyValueOption.OnEnable))] -public static class KeyValueOptionOnEnablePatch -{ - public static void Postfix(KeyValueOption __instance) - { - if (__instance.Title == StringNames.GameMapName) - { - __instance.Selected = Helper.Map.Id; - } - - if (__instance.Values != null) - { - __instance.ValueText.text = __instance.Values[ - Mathf.Clamp( - __instance.Selected, 0, - __instance.Values.Count - 1)].Key; - } - } -} diff --git a/ExtremeRoles/Patches/Option/LobbyViewSettingsPanePatch.cs b/ExtremeRoles/Patches/Option/LobbyViewSettingsPanePatch.cs new file mode 100644 index 000000000..530e8ac0a --- /dev/null +++ b/ExtremeRoles/Patches/Option/LobbyViewSettingsPanePatch.cs @@ -0,0 +1,26 @@ +using HarmonyLib; + +using ExtremeRoles.Module.CustomMonoBehaviour.View; + +namespace ExtremeRoles.Patches.Option; + +[HarmonyPatch(typeof(LobbyViewSettingsPane), nameof(LobbyViewSettingsPane.Awake))] +public static class LobbyViewSettingsPanePatch +{ + public static void Postfix(LobbyViewSettingsPane __instance) + { + __instance.gameObject.AddComponent(); + } +} + +[HarmonyPatch(typeof(LobbyViewSettingsPane), nameof(LobbyViewSettingsPane.ChangeTab))] +public static class LobbyViewSettingsPaneChangeTabPatch +{ + public static void Prefix(LobbyViewSettingsPane __instance) + { + if (__instance.TryGetComponent(out var view)) + { + view.ChangeTabPostfix(); + } + } +} diff --git a/ExtremeRoles/Patches/Option/OptionsMenuBehaviourStartPatch.cs b/ExtremeRoles/Patches/Option/OptionsMenuBehaviourStartPatch.cs index b110d4250..1494b3f3d 100644 --- a/ExtremeRoles/Patches/Option/OptionsMenuBehaviourStartPatch.cs +++ b/ExtremeRoles/Patches/Option/OptionsMenuBehaviourStartPatch.cs @@ -3,6 +3,7 @@ using UnityEngine; + namespace ExtremeRoles.Patches.Option; diff --git a/ExtremeRoles/Patches/Option/StringOptionPatch.cs b/ExtremeRoles/Patches/Option/StringOptionPatch.cs deleted file mode 100644 index 0aa879e4f..000000000 --- a/ExtremeRoles/Patches/Option/StringOptionPatch.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; - -using HarmonyLib; -using UnityEngine; - -using ExtremeRoles.Module.CustomOption; -using ExtremeRoles.Module.CustomMonoBehaviour; - -namespace ExtremeRoles.Patches.Option; - -[HarmonyPatch(typeof(StringOption), nameof(StringOption.Decrease))] -public static class StringOptionDecreasePatch -{ - public static bool Prefix(StringOption __instance) - { - - string idStr = __instance.gameObject.name.Replace( - OptionMenuTab.StringOptionName, string.Empty); - - if (!int.TryParse(idStr, out int id)) { return true; }; - - OptionManager.Instance.ChangeOptionValue(id, false); - - return false; - } -} - -[HarmonyPatch(typeof(StringOption), nameof(StringOption.Increase))] -public static class StringOptionIncreasePatch -{ - public static bool Prefix(StringOption __instance) - { - string idStr = __instance.gameObject.name.Replace( - OptionMenuTab.StringOptionName, string.Empty); - - if (!int.TryParse(idStr, out int id)) { return true; }; - - OptionManager.Instance.ChangeOptionValue(id, true); - - return false; - } -} -[HarmonyPatch(typeof(StringOption), nameof(StringOption.OnEnable))] -public static class StringOptionOnEnablePatch -{ - public static bool Prefix(StringOption __instance) - { - string idStr = __instance.gameObject.name.Replace( - OptionMenuTab.StringOptionName, string.Empty); - - if (!int.TryParse(idStr, out int id)) { return true; }; - - IOptionInfo option = OptionManager.Instance.GetIOption(id); - - __instance.OnValueChanged = new Action((o) => { }); - __instance.TitleText.text = option.GetTranslatedName(); - __instance.Value = __instance.oldValue = option.CurSelection; - __instance.ValueText.text = option.GetTranslatedValue(); - - return false; - } -} diff --git a/ExtremeRoles/Patches/Player/FixedUpdatePatch.cs b/ExtremeRoles/Patches/Player/FixedUpdatePatch.cs index a6c39deef..e2fe14359 100644 --- a/ExtremeRoles/Patches/Player/FixedUpdatePatch.cs +++ b/ExtremeRoles/Patches/Player/FixedUpdatePatch.cs @@ -168,7 +168,10 @@ private static void ventButtonUpdate( var ship = ExtremeGameModeManager.Instance.ShipOption; if (!role.TryGetVanillaRoleId(out RoleTypes roleId) || - roleId is RoleTypes.Shapeshifter or RoleTypes.Impostor) + roleId is + RoleTypes.Impostor or + RoleTypes.Shapeshifter or + RoleTypes.Phantom) { if (ventButtonShow && ship.IsEnableImpostorVent) { @@ -180,12 +183,12 @@ private static void ventButtonUpdate( } } else if ( - roleId == RoleTypes.Engineer && - player.Data.Role.Role == RoleTypes.Engineer) + roleId is RoleTypes.Engineer && + player.Data.Role.Role is RoleTypes.Engineer) { if (ventButtonShow) { - if (!ship.EngineerUseImpostorVent) + if (!ship.Vent.EngineerUseImpostorVent) { hudManager.AbilityButton.Show(); } @@ -214,6 +217,8 @@ private static void ghostRoleButtonUpdate(GhostRoleBase playerGhostRole) case RoleTypes.Engineer: case RoleTypes.Scientist: case RoleTypes.Shapeshifter: + case RoleTypes.Tracker: + case RoleTypes.Phantom: abilityButton.Hide(); break; case RoleTypes.CrewmateGhost: diff --git a/ExtremeRoles/Patches/Player/HandleRpcPatch.cs b/ExtremeRoles/Patches/Player/HandleRpcPatch.cs index 9063f21f5..d0a22da67 100644 --- a/ExtremeRoles/Patches/Player/HandleRpcPatch.cs +++ b/ExtremeRoles/Patches/Player/HandleRpcPatch.cs @@ -64,8 +64,7 @@ public static void Postfix( } break; case RPCOperator.Command.ShareOption: - int numOptions = reader.ReadByte(); - RPCOperator.ShareOption(numOptions, reader); + RPCOperator.ShareOption(reader); break; case RPCOperator.Command.CustomVentUse: int ventId = reader.ReadPackedInt32(); diff --git a/ExtremeRoles/Patches/Player/Meeting/StartMeetingPatch.cs b/ExtremeRoles/Patches/Player/Meeting/StartMeetingPatch.cs index 7faa42eb9..9fa061daf 100644 --- a/ExtremeRoles/Patches/Player/Meeting/StartMeetingPatch.cs +++ b/ExtremeRoles/Patches/Player/Meeting/StartMeetingPatch.cs @@ -7,7 +7,7 @@ namespace ExtremeRoles.Patches.Player.Meeting; [HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.StartMeeting))] public static class PlayerControlCoStartMeetingPatch { - public static void Prefix([HarmonyArgument(0)] GameData.PlayerInfo target) + public static void Prefix([HarmonyArgument(0)] NetworkedPlayerInfo target) { InfoOverlay.Instance.IsBlock = true; diff --git a/ExtremeRoles/Patches/Player/RpcSyncSettings.cs b/ExtremeRoles/Patches/Player/RpcSyncSettings.cs index 2ac88db04..521486280 100644 --- a/ExtremeRoles/Patches/Player/RpcSyncSettings.cs +++ b/ExtremeRoles/Patches/Player/RpcSyncSettings.cs @@ -9,6 +9,6 @@ public static class PlayerControlRpcSyncSettingsPatch { public static void Postfix() { - OptionManager.Instance.ShareOptionSelections(); + OptionManager.Instance.ShereAllOption(); } } \ No newline at end of file diff --git a/ExtremeRoles/Patches/Player/ShapeshiftPatch.cs b/ExtremeRoles/Patches/Player/ShapeshiftPatch.cs index 9e025b821..538fd9055 100644 --- a/ExtremeRoles/Patches/Player/ShapeshiftPatch.cs +++ b/ExtremeRoles/Patches/Player/ShapeshiftPatch.cs @@ -35,14 +35,14 @@ public static bool Prefix( if (__instance.CurrentOutfitType == PlayerOutfitType.MushroomMixup) { return false; } - GameData.PlayerInfo targetPlayerInfo = targetPlayer.Data; + NetworkedPlayerInfo targetPlayerInfo = targetPlayer.Data; bool isSame = targetPlayerInfo.PlayerId == __instance.Data.PlayerId; var outfits = __instance.Data.Outfits; - GameData.PlayerOutfit instancePlayerOutfit = outfits[PlayerOutfitType.Default]; - GameData.PlayerOutfit newOutfit = instancePlayerOutfit; + NetworkedPlayerInfo.PlayerOutfit instancePlayerOutfit = outfits[PlayerOutfitType.Default]; + NetworkedPlayerInfo.PlayerOutfit newOutfit = instancePlayerOutfit; if (!isSame) { diff --git a/ExtremeRoles/Patches/ProgressTrackerPatch.cs b/ExtremeRoles/Patches/ProgressTrackerPatch.cs index 1039ad644..f7e6c7cad 100644 --- a/ExtremeRoles/Patches/ProgressTrackerPatch.cs +++ b/ExtremeRoles/Patches/ProgressTrackerPatch.cs @@ -39,7 +39,7 @@ public static void Postfix(ProgressTracker __instance) 1 : (gameData.PlayerCount - GameOptionsManager.Instance.CurrentGameOptions.GetInt( Int32OptionNames.NumImpostors))); num -= gameData.AllPlayers.ToArray().ToList().Count( - (GameData.PlayerInfo p) => p.Disconnected); + (NetworkedPlayerInfo p) => p.Disconnected); float curProgress = (float)gameData.CompletedTasks / (float)gameData.TotalTasks * (float)num; diff --git a/ExtremeRoles/Patches/Region/RegionMenuPatch.cs b/ExtremeRoles/Patches/Region/RegionMenuPatch.cs index f6497c7ab..2abc3494f 100644 --- a/ExtremeRoles/Patches/Region/RegionMenuPatch.cs +++ b/ExtremeRoles/Patches/Region/RegionMenuPatch.cs @@ -33,6 +33,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using ExtremeRoles.Extension.UnityEvents; + using UnityObject = UnityEngine.Object; namespace ExtremeRoles.Patches.Region; diff --git a/ExtremeRoles/Patches/Role/EngineerRolePatch.cs b/ExtremeRoles/Patches/Role/EngineerRolePatch.cs index 8561aec2d..c08aa8ba5 100644 --- a/ExtremeRoles/Patches/Role/EngineerRolePatch.cs +++ b/ExtremeRoles/Patches/Role/EngineerRolePatch.cs @@ -1,14 +1,13 @@ using ExtremeRoles.GameMode; using HarmonyLib; -namespace ExtremeRoles.Patches.Role +namespace ExtremeRoles.Patches.Role; + +[HarmonyPatch(typeof(EngineerRole), nameof(EngineerRole.FixedUpdate))] +public static class EngineerRoleFixedUpdatePatch { - [HarmonyPatch(typeof(EngineerRole), nameof(EngineerRole.FixedUpdate))] - public static class EngineerRoleFixedUpdatePatch + public static bool Prefix() { - public static bool Prefix() - { - return !ExtremeGameModeManager.Instance.ShipOption.EngineerUseImpostorVent; - } + return !ExtremeGameModeManager.Instance.ShipOption.Vent.EngineerUseImpostorVent; } } diff --git a/ExtremeRoles/Patches/Role/RoleRoleBehaviourPatch.cs b/ExtremeRoles/Patches/Role/RoleRoleBehaviourPatch.cs index 1d8b44c83..a7b02d194 100644 --- a/ExtremeRoles/Patches/Role/RoleRoleBehaviourPatch.cs +++ b/ExtremeRoles/Patches/Role/RoleRoleBehaviourPatch.cs @@ -33,7 +33,7 @@ public static class RoleBehaviourIsValidTargetPatch public static bool Prefix( RoleBehaviour __instance, ref bool __result, - [HarmonyArgument(0)] GameData.PlayerInfo target) + [HarmonyArgument(0)] NetworkedPlayerInfo target) { if (!RoleAssignState.Instance.IsRoleSetUpEnd) { return true; } @@ -49,7 +49,7 @@ public static bool Prefix( target.PlayerId != __instance.Player.PlayerId && target.Role != null && target.Object != null && - (!target.Object.inVent || ExtremeGameModeManager.Instance.ShipOption.CanKillVentInPlayer) && + (!target.Object.inVent || ExtremeGameModeManager.Instance.ShipOption.Vent.CanKillVentInPlayer) && !target.Object.inMovingPlat && !role.IsSameTeam(gameRoles[target.PlayerId]); diff --git a/ExtremeRoles/Patches/ShipStatusPatch.cs b/ExtremeRoles/Patches/ShipStatusPatch.cs index 69217b8ec..b481782d6 100644 --- a/ExtremeRoles/Patches/ShipStatusPatch.cs +++ b/ExtremeRoles/Patches/ShipStatusPatch.cs @@ -30,7 +30,7 @@ public static class ShipStatusCalculateLightRadiusPatch public static bool Prefix( ref float __result, ShipStatus __instance, - [HarmonyArgument(0)] GameData.PlayerInfo playerInfo) + [HarmonyArgument(0)] NetworkedPlayerInfo playerInfo) { return VisionComputer.Instance.IsVanillaVisionAndGetVision( __instance, playerInfo, out __result); diff --git a/ExtremeRoles/Patches/TempDataPatch.cs b/ExtremeRoles/Patches/TempDataPatch.cs index c37cc250f..6d840beb4 100644 --- a/ExtremeRoles/Patches/TempDataPatch.cs +++ b/ExtremeRoles/Patches/TempDataPatch.cs @@ -3,10 +3,10 @@ namespace ExtremeRoles.Patches; -[HarmonyPatch(typeof(TempData), nameof(TempData.OnGameEnd))] -public static class TempDataOnGameEndPatch +[HarmonyPatch(typeof(GameData), nameof(GameData.OnGameEnd))] +public static class GameDataOnGameEndPatch { - public static void Postfix() + public static void Prefix() { ExtremeGameResult.Instance.CreateTaskInfo(); } diff --git a/ExtremeRoles/Performance/CachedPlayerControl.cs b/ExtremeRoles/Performance/CachedPlayerControl.cs index 6fdb7bc0e..6e893fc19 100644 --- a/ExtremeRoles/Performance/CachedPlayerControl.cs +++ b/ExtremeRoles/Performance/CachedPlayerControl.cs @@ -17,7 +17,7 @@ public class CachedPlayerControl public PlayerControl PlayerControl; public PlayerPhysics PlayerPhysics; public CustomNetworkTransform NetTransform; - public GameData.PlayerInfo Data; + public NetworkedPlayerInfo Data; public byte PlayerId; public CachedPlayerControl(PlayerControl pc) diff --git a/ExtremeRoles/RPCOperator.cs b/ExtremeRoles/RPCOperator.cs index 7c7cc9051..4f6cb9190 100644 --- a/ExtremeRoles/RPCOperator.cs +++ b/ExtremeRoles/RPCOperator.cs @@ -14,6 +14,8 @@ using ExtremeRoles.Compat.ModIntegrator; using ExtremeRoles.Compat; + + namespace ExtremeRoles; public static class RPCOperator @@ -284,9 +286,9 @@ public static void SetRoleToAllPlayer( } } - public static void ShareOption(int numOptions, MessageReader reader) + public static void ShareOption(in MessageReader reader) { - OptionManager.ShareOption(numOptions, reader); + OptionManager.ShareOption(reader); } public static void ReplaceDeadReason(byte playerId, byte reason) @@ -404,7 +406,7 @@ public static void SetWinPlayer(List playerId) { foreach (byte id in playerId) { - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(id); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(id); if (player == null) { continue; } ExtremeRolesPlugin.ShipState.AddWinner(player); } diff --git a/ExtremeRoles/RandomGenerator.cs b/ExtremeRoles/RandomGenerator.cs index 3221dd0b5..c7e737218 100644 --- a/ExtremeRoles/RandomGenerator.cs +++ b/ExtremeRoles/RandomGenerator.cs @@ -4,9 +4,12 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module.PRNG; + + + namespace ExtremeRoles; -public static class RandomGenerator +public class RandomGenerator { public static RNGBase Instance { @@ -14,12 +17,27 @@ public static RNGBase Instance { if (instance == null) { - createGlobalRandomGenerator(OptionManager.Instance.GetValue( - (int)OptionCreator.CommonOptionKey.UseStrongRandomGen)); + createGlobalRandomGenerator( + OptionManager.Instance.TryGetCategory( + OptionTab.General, + randCategoryKey, + out var category) && + category.GetValue(useStrongKey)); } return instance; } } + + public static bool IsUsingStrongGenerator => OptionManager.Instance.TryGetCategory( + OptionTab.General, + randCategoryKey, + out var category) && + category.GetValue(useStrongKey); + + private const int randCategoryKey = (int)OptionCreator.CommonOption.RandomOption; + private const int useStrongKey = (int)OptionCreator.RandomOptionKey.UseStrong; + private const int algorithmKey = (int)OptionCreator.RandomOptionKey.Algorithm; + private static bool prevValue = false; private static int prevSelection = 0; @@ -27,8 +45,15 @@ public static RNGBase Instance public static void Initialize() { - bool useStrongGen = OptionManager.Instance.GetValue( - (int)OptionCreator.CommonOptionKey.UseStrongRandomGen); + if (!OptionManager.Instance.TryGetCategory( + OptionTab.General, + randCategoryKey, + out var category)) + { + return; + } + + bool useStrongGen = category.GetValue(useStrongKey); if (instance != null) { if (useStrongGen != prevValue) @@ -37,8 +62,7 @@ public static void Initialize() } else { - int selection = OptionManager.Instance.GetValue( - (int)OptionCreator.CommonOptionKey.UsePrngAlgorithm); + int selection = category.GetValue(algorithmKey); if (prevSelection != selection) { instance = getAditionalPrng(selection); @@ -61,10 +85,13 @@ public static void Initialize() private static void createGlobalRandomGenerator(bool isStrong) { Logging.Debug("Initialize RNG"); - if (isStrong) - { - int selection = OptionManager.Instance.GetValue( - (int)OptionCreator.CommonOptionKey.UsePrngAlgorithm); + if (OptionManager.Instance.TryGetCategory( + OptionTab.General, + randCategoryKey, + out var category) && + isStrong) + { + int selection = category.GetValue(algorithmKey); instance = getAditionalPrng(selection); UnityEngine.Random.InitState(CreateStrongRandomSeed()); prevSelection = selection; @@ -80,10 +107,7 @@ private static void createGlobalRandomGenerator(bool isStrong) public static Random GetTempGenerator() { - bool useStrongGen = OptionManager.Instance.GetValue( - (int)OptionCreator.CommonOptionKey.UseStrongRandomGen); - - if (useStrongGen) + if (IsUsingStrongGenerator) { return new Random(CreateStrongRandomSeed()); } @@ -196,7 +220,7 @@ private static RNGBase getAditionalPrng(int selection) return new JFT32( CreateLongStrongSeed(), CreateLongStrongSeed()); - + default: return new SystemRandomWrapper(0, 0); } diff --git a/ExtremeRoles/Resources/Help.png b/ExtremeRoles/Resources/Help.png deleted file mode 100644 index f20f88105..000000000 Binary files a/ExtremeRoles/Resources/Help.png and /dev/null differ diff --git a/ExtremeRoles/Resources/HelpActive.png b/ExtremeRoles/Resources/HelpActive.png new file mode 100644 index 000000000..9985471d1 Binary files /dev/null and b/ExtremeRoles/Resources/HelpActive.png differ diff --git a/ExtremeRoles/Resources/HelpNoActive.png b/ExtremeRoles/Resources/HelpNoActive.png new file mode 100644 index 000000000..f751a7ba2 Binary files /dev/null and b/ExtremeRoles/Resources/HelpNoActive.png differ diff --git a/ExtremeRoles/Resources/Loader.cs b/ExtremeRoles/Resources/Loader.cs index b8cc45895..ec677462c 100644 --- a/ExtremeRoles/Resources/Loader.cs +++ b/ExtremeRoles/Resources/Loader.cs @@ -26,8 +26,9 @@ public static class Path public const string LangData = "ExtremeRoles.Resources.LangData.stringData.json"; - public const string HelpImage = "ExtremeRoles.Resources.Help.png"; - public const string CompatModMenuImage = "ExtremeRoles.Resources.CompatModMenu.png"; + public const string HelpActiveImage = "ExtremeRoles.Resources.HelpActive.png"; + public const string HelpNoneActiveImage = "ExtremeRoles.Resources.HelpNoActive.png"; + public const string CompatModMenuImage = "ExtremeRoles.Resources.CompatModMenu.png"; public const string TitleBurner = "ExtremeRoles.Resources.TitleBurner.png"; diff --git a/ExtremeRoles/Roles/API/CombinationRoleManagerBase.cs b/ExtremeRoles/Roles/API/CombinationRoleManagerBase.cs index 5738d03c4..5dd0856fd 100644 --- a/ExtremeRoles/Roles/API/CombinationRoleManagerBase.cs +++ b/ExtremeRoles/Roles/API/CombinationRoleManagerBase.cs @@ -1,8 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using UnityEngine; using AmongUs.GameOptions; + +using ExtremeRoles.Module.CustomOption.Factory; +using ExtremeRoles.Module.CustomOption.Interfaces; + namespace ExtremeRoles.Roles.API; @@ -16,16 +21,37 @@ public enum CombinationRoleCommonOption public abstract class CombinationRoleManagerBase : RoleOptionBase { - public List Roles = new List(); + public List Roles = new List(); + + protected readonly Color OptionColor; + protected readonly string RoleName = ""; + protected readonly CombinationRoleType RoleType; + + protected static Color DefaultColor => new Color(255f, 255f, 255f); + + public sealed override IOptionLoader Loader + { + get + { + if (!OptionManager.Instance.TryGetCategory( + OptionTab.Combination, + ExtremeRoleManager.GetCombRoleGroupId(this.RoleType), + out var cate)) + { + throw new ArgumentException("Can't find category"); + } + return cate; + } + } - protected Color OptionColor; - protected string RoleName = ""; internal CombinationRoleManagerBase( + CombinationRoleType type, string roleName, Color optionColor) { this.OptionColor = optionColor; this.RoleName = roleName; + this.RoleType = type; } public abstract string GetOptionName(); @@ -34,20 +60,22 @@ internal CombinationRoleManagerBase( public abstract MultiAssignRoleBase GetRole( int roleId, RoleTypes playerRoleType); - protected override void CreateKillerOption( - IOptionInfo parentOps) + protected sealed override void CreateKillerOption( + AutoParentSetOptionCategoryFactory factory, + IOption parent = null, + bool ignorePrefix=true) { // 複数ロールの中に殺戮者がいる可能性がため、管理ロールで殺戮者の設定はしない return; } - protected override void CreateVisionOption( - IOptionInfo parentOps) + protected sealed override void CreateVisionOption( + AutoParentSetOptionCategoryFactory factory, bool ignorePrefix) { // 複数のロールがまとまっているため、管理ロールで視界の設定はしない return; } - protected override void RoleSpecificInit() + protected sealed override void RoleSpecificInit() { // 複数のロールがまとまっているため、設定はしない return; diff --git a/ExtremeRoles/Roles/API/ConstCombinationRoleManagerBase.cs b/ExtremeRoles/Roles/API/ConstCombinationRoleManagerBase.cs index a2fd8f931..87292c089 100644 --- a/ExtremeRoles/Roles/API/ConstCombinationRoleManagerBase.cs +++ b/ExtremeRoles/Roles/API/ConstCombinationRoleManagerBase.cs @@ -7,6 +7,9 @@ using ExtremeRoles.Helper; +using ExtremeRoles.Module.CustomOption.Factory; + + namespace ExtremeRoles.Roles.API; public abstract class ConstCombinationRoleManagerBase : CombinationRoleManagerBase @@ -19,11 +22,12 @@ public abstract class ConstCombinationRoleManagerBase : CombinationRoleManagerBa this.RoleName, RoleCommonOption.SpawnRate.ToString())); - public ConstCombinationRoleManagerBase( - string roleName, + public ConstCombinationRoleManagerBase( + CombinationRoleType type, + string roleName, Color optionColor, int setPlayerNum, - int maxSetNum = int.MaxValue) : base (roleName, optionColor) + int maxSetNum = int.MaxValue) : base (type, roleName, optionColor) { this.setPlayerNum = setPlayerNum; this.maxSetNum = maxSetNum; @@ -40,16 +44,16 @@ public override void AssignSetUpInit(int curImpNum) public override MultiAssignRoleBase GetRole( int roleId, RoleTypes playerRoleType) { - - foreach(var checkRole in this.Roles) + var cate = this.Loader; + foreach (var checkRole in this.Roles) { if (checkRole.Id != (ExtremeRoleId)roleId) { continue; } - checkRole.CanHasAnotherRole = OptionManager.Instance.GetValue( - GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign)); + checkRole.CanHasAnotherRole = cate.GetValue( + CombinationRoleCommonOption.IsMultiAssign); - switch (checkRole.Team) + switch (checkRole.Team) { case ExtremeRoleType.Crewmate: case ExtremeRoleType.Neutral: @@ -74,68 +78,68 @@ public override MultiAssignRoleBase GetRole( } - protected override IOptionInfo CreateSpawnOption() + protected override AutoParentSetOptionCategoryFactory CreateSpawnOption() { - // ExtremeRolesPlugin.Instance.Log.LogInfo($"Color: {this.optionColor}"); - var roleSetOption = new SelectionCustomOption( - GetRoleOptionId(RoleCommonOption.SpawnRate), - this.optionKey, - OptionCreator.SpawnRate, null, true, - tab: OptionTab.Combination); - - int thisMaxRoleNum = + // ExtremeRolesPlugin.Instance.Log.LogInfo($"Color: {this.optionColor}"); + + var factory = OptionManager.CreateAutoParentSetOptionCategory( + ExtremeRoleManager.GetCombRoleGroupId(this.RoleType), + this.RoleName, + OptionTab.Combination, + this.OptionColor == DefaultColor ? null : this.OptionColor); + + var roleSetOption = factory.Create0To100Percentage10StepOption( + RoleCommonOption.SpawnRate, + ignorePrefix: true); + + int thisMaxRoleNum = this.maxSetNum == int.MaxValue ? (int)Math.Floor((decimal)GameSystem.VanillaMaxPlayerNum / this.setPlayerNum) : this.maxSetNum; - new IntCustomOption( - GetRoleOptionId(RoleCommonOption.RoleNum), - string.Concat( - this.RoleName, - RoleCommonOption.RoleNum.ToString()), + factory.CreateIntOption( + RoleCommonOption.RoleNum, 1, 1, thisMaxRoleNum, 1, - roleSetOption, - tab: OptionTab.Combination); - new BoolCustomOption( - GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign), - string.Concat( - this.RoleName, - CombinationRoleCommonOption.IsMultiAssign.ToString()), - false, roleSetOption, - tab: OptionTab.Combination); - - new IntCustomOption( - GetRoleOptionId(RoleCommonOption.AssignWeight), - $"|{this.RoleName}|{RoleCommonOption.AssignWeight}", - 500, 1, 1000, 1, - roleSetOption, - tab: OptionTab.Combination); - - return roleSetOption; + ignorePrefix: true); + + factory.CreateBoolOption( + CombinationRoleCommonOption.IsMultiAssign, false, + ignorePrefix: true); + + factory.CreateIntOption(RoleCommonOption.AssignWeight, + 500, 1, 1000, 1, ignorePrefix: true); + + return factory; } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { IEnumerable collection = Roles; foreach (var item in collection.Select( (Value, Index) => new { Value, Index })) { - int optionOffset = this.OptionIdOffset + ( - ExtremeRoleManager.OptionOffsetPerRole * (item.Index + 1)); - item.Value.SetManagerOptionOffset(this.OptionIdOffset); - item.Value.CreateRoleSpecificOption( - parentOps, - optionOffset); + var role = item.Value; + // 同じオプションを参照したい時があるのでオフセット値を入れておく + int offset = (item.Index + 1) * ExtremeRoleManager.OptionOffsetPerRole; + + factory.IdOffset = (item.Index + 1) * ExtremeRoleManager.OptionOffsetPerRole; + factory.OptionPrefix = role.RawRoleName; + + role.CreateRoleSpecificOption(factory, false); + role.OffsetInfo = new MultiAssignRoleBase.OptionOffsetInfo( + this.RoleType, offset); } } protected override void CommonInit() { + var cate = this.Loader; foreach (var role in this.Roles) { - role.CanHasAnotherRole = OptionManager.Instance.GetValue( - GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign)); + role.CanHasAnotherRole = + cate.GetValue( + CombinationRoleCommonOption.IsMultiAssign); role.Initialize(); } } diff --git a/ExtremeRoles/Roles/API/FlexibleCombinationRoleManagerBase.cs b/ExtremeRoles/Roles/API/FlexibleCombinationRoleManagerBase.cs index e84537039..97ac7c95f 100644 --- a/ExtremeRoles/Roles/API/FlexibleCombinationRoleManagerBase.cs +++ b/ExtremeRoles/Roles/API/FlexibleCombinationRoleManagerBase.cs @@ -1,7 +1,9 @@ using AmongUs.GameOptions; using ExtremeRoles.Helper; -using ExtremeRoles.Module.CustomOption; + + +using ExtremeRoles.Module.CustomOption.Factory; namespace ExtremeRoles.Roles.API; @@ -13,10 +15,11 @@ public abstract class FlexibleCombinationRoleManagerBase : CombinationRoleManage private bool canAssignImposter = true; public FlexibleCombinationRoleManagerBase( + CombinationRoleType roleType, MultiAssignRoleBase role, int minimumRoleNum = 2, bool canAssignImposter = true) : - base(role.Id.ToString(), role.GetNameColor(true)) + base(roleType, role.Id.ToString(), role.GetNameColor(true)) { this.BaseRole = role; this.minimumRoleNum = minimumRoleNum; @@ -28,33 +31,29 @@ public sealed override string GetOptionName() this.OptionColor, Translation.GetString(this.RoleName)); - public int GetOptionIdOffset() => this.OptionIdOffset; - public string GetBaseRoleFullDescription() => Translation.GetString($"{BaseRole.Id}FullDescription"); public override void AssignSetUpInit(int curImpNum) { + var cate = this.Loader; - var allOption = OptionManager.Instance; - - foreach (var role in this.Roles) + foreach (var role in this.Roles) { - role.CanHasAnotherRole = allOption.GetValue( - GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign)); + role.CanHasAnotherRole = cate.GetValue( + CombinationRoleCommonOption.IsMultiAssign); - if (!allOption.TryGet( - GetRoleOptionId( - CombinationRoleCommonOption.IsAssignImposter), + if (!cate.TryGetValueOption( + CombinationRoleCommonOption.IsAssignImposter, out var impOpt)) { continue; } - bool isEvil = impOpt.GetValue(); + bool isEvil = impOpt.Value; - var spawnOption = allOption.Get( - GetRoleOptionId(CombinationRoleCommonOption.ImposterSelectedRate)); + var spawnOption = cate.GetValueOption( + CombinationRoleCommonOption.ImposterSelectedRate); isEvil = isEvil && (UnityEngine.Random.RandomRange(0, 110) < (int)decimal.Multiply( - spawnOption.GetValue(), spawnOption.ValueCount)) && + spawnOption.Value, spawnOption.Range)) && curImpNum < GameOptionsManager.Instance.CurrentGameOptions.GetInt( Int32OptionNames.NumImpostors); @@ -88,15 +87,16 @@ public override MultiAssignRoleBase GetRole( if (this.BaseRole.Id != (ExtremeRoleId)roleId) { return role; } - this.BaseRole.CanHasAnotherRole = OptionManager.Instance.GetValue( - GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign)); + this.BaseRole.CanHasAnotherRole = this.Loader.GetValue( + CombinationRoleCommonOption.IsMultiAssign); - role = (MultiAssignRoleBase)this.BaseRole.Clone(); + role = (MultiAssignRoleBase)this.BaseRole.Clone(); switch (playerRoleType) { case RoleTypes.Impostor: case RoleTypes.Shapeshifter: + case RoleTypes.Phantom: role.Team = ExtremeRoleType.Impostor; role.SetNameColor(Palette.ImpostorRed); role.CanKill = true; @@ -111,112 +111,83 @@ public override MultiAssignRoleBase GetRole( } - protected override IOptionInfo CreateSpawnOption() + protected override AutoParentSetOptionCategoryFactory CreateSpawnOption() { - // ExtremeRolesPlugin.Instance.Log.LogInfo($"Color: {this.optionColor}"); - var roleSetOption = new SelectionCustomOption( - GetRoleOptionId(RoleCommonOption.SpawnRate), - Design.ColoedString( - this.OptionColor, - string.Concat( - this.RoleName, - RoleCommonOption.SpawnRate.ToString())), - OptionCreator.SpawnRate, null, true, - tab: OptionTab.Combination); - - int roleAssignNum = this.BaseRole.IsImpostor() ? - GameSystem.MaxImposterNum : - GameSystem.VanillaMaxPlayerNum - 1; - - var roleAssignNumOption = new IntCustomOption( - GetRoleOptionId(CombinationRoleCommonOption.AssignsNum), - string.Concat( - this.RoleName, - CombinationRoleCommonOption.AssignsNum.ToString()), - this.minimumRoleNum, this.minimumRoleNum, - roleAssignNum, 1, - roleSetOption, isHidden: this.minimumRoleNum <= 1, - tab: OptionTab.Combination); - - - int maxSetNum = this.BaseRole.IsImpostor() ? - GameSystem.MaxImposterNum: - (GameSystem.VanillaMaxPlayerNum - 1); - - var roleSetNumOption = new IntCustomOption( - GetRoleOptionId(RoleCommonOption.RoleNum), - string.Concat( - this.RoleName, - RoleCommonOption.RoleNum.ToString()), - 1, 1, maxSetNum, 1, - roleSetOption, - tab: OptionTab.Combination); - - roleAssignNumOption.SetUpdateOption(roleSetNumOption); - - new IntCustomOption( - GetRoleOptionId(RoleCommonOption.AssignWeight), - $"|{this.RoleName}|{RoleCommonOption.AssignWeight}", - 500, 1, 1000, 1, - roleSetOption, - tab: OptionTab.Combination); + var factory = OptionManager.CreateAutoParentSetOptionCategory( + ExtremeRoleManager.GetCombRoleGroupId(this.RoleType), + this.RoleName, + OptionTab.Combination, + this.OptionColor); + + var roleSetOption = factory.Create0To100Percentage10StepOption( + RoleCommonOption.SpawnRate, + ignorePrefix: true); + + int maxSetNum = this.BaseRole.IsImpostor() ? + GameSystem.MaxImposterNum : + (GameSystem.VanillaMaxPlayerNum - 1); + + var roleSetNumOption = factory.CreateIntOption( + RoleCommonOption.RoleNum, + 1, 1, maxSetNum, 1, + ignorePrefix: true); + + int roleAssignNum = this.BaseRole.IsImpostor() ? + GameSystem.MaxImposterNum : + GameSystem.VanillaMaxPlayerNum - 1; + var roleAssignNumOption = factory.CreateIntOption( + CombinationRoleCommonOption.AssignsNum, + this.minimumRoleNum, this.minimumRoleNum, + roleAssignNum, 1, + isHidden: this.minimumRoleNum <= 1, + ignorePrefix: true); + + factory.CreateBoolOption( + CombinationRoleCommonOption.IsMultiAssign, false, + ignorePrefix: true); + + roleAssignNumOption.AddWithUpdate(roleSetNumOption); + + factory.CreateIntOption(RoleCommonOption.AssignWeight, + 500, 1, 1000, 1, ignorePrefix: true); if (this.canAssignImposter) { - var isImposterAssignOps = new BoolCustomOption( - GetRoleOptionId(CombinationRoleCommonOption.IsAssignImposter), - string.Concat( - this.RoleName, - CombinationRoleCommonOption.IsAssignImposter.ToString()), - false, roleSetOption, - tab: OptionTab.Combination); - - new SelectionCustomOption( - GetRoleOptionId(CombinationRoleCommonOption.ImposterSelectedRate), - string.Concat( - this.RoleName, - CombinationRoleCommonOption.ImposterSelectedRate.ToString()), - OptionCreator.SpawnRate, isImposterAssignOps, - tab: OptionTab.Combination); - } + var isImposterAssignOps = factory.CreateBoolOption( + CombinationRoleCommonOption.IsAssignImposter, + false, ignorePrefix: true); - new BoolCustomOption( - GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign), - string.Concat( - this.RoleName, - CombinationRoleCommonOption.IsMultiAssign.ToString()), - false, roleSetOption, - isHidden: this.minimumRoleNum <= 1, - tab: OptionTab.Combination); - - return roleSetOption; + factory.Create0To100Percentage10StepOption( + CombinationRoleCommonOption.ImposterSelectedRate, + ignorePrefix: true); + } + return factory; } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - - int optionOffset = this.OptionIdOffset + ExtremeRoleManager.OptionOffsetPerRole; - this.BaseRole.SetManagerOptionOffset(this.OptionIdOffset); this.BaseRole.CreateRoleSpecificOption( - parentOps, - optionOffset); + factory); + this.BaseRole.OffsetInfo = new MultiAssignRoleBase.OptionOffsetInfo( + this.RoleType, 0); } protected override void CommonInit() { this.Roles.Clear(); int roleAssignNum = 1; - var allOptions = OptionManager.Instance; - this.BaseRole.CanHasAnotherRole = allOptions.GetValue( - GetRoleOptionId(CombinationRoleCommonOption.IsMultiAssign)); + var cate = this.Loader; + + this.BaseRole.CanHasAnotherRole = cate.GetValue( + CombinationRoleCommonOption.IsMultiAssign); - if (allOptions.TryGet( - GetRoleOptionId(CombinationRoleCommonOption.AssignsNum), + if (cate.TryGetValueOption( + CombinationRoleCommonOption.AssignsNum, out var opt)) { - roleAssignNum = opt.GetValue(); + roleAssignNum = opt.Value; } for (int i = 0; i < roleAssignNum; ++i) diff --git a/ExtremeRoles/Roles/API/GhostAndAliveCombinationRoleManagerBase.cs b/ExtremeRoles/Roles/API/GhostAndAliveCombinationRoleManagerBase.cs index 4c9decb11..87828dd82 100644 --- a/ExtremeRoles/Roles/API/GhostAndAliveCombinationRoleManagerBase.cs +++ b/ExtremeRoles/Roles/API/GhostAndAliveCombinationRoleManagerBase.cs @@ -3,7 +3,9 @@ using UnityEngine; using ExtremeRoles.GhostRoles.API; -using ExtremeRoles.Module.CustomOption.Factories; +using ExtremeRoles.Module.CustomOption.Factory; +using ExtremeRoles.GhostRoles; +using ExtremeRoles.GhostRoles.API.Interface; namespace ExtremeRoles.Roles.API; @@ -14,11 +16,13 @@ public abstract class GhostAndAliveCombinationRoleManagerBase : Dictionary (); public GhostAndAliveCombinationRoleManagerBase( + CombinationRoleType roleType, string roleName, Color optionColor, int setPlayerNum, int maxSetNum = int.MaxValue) : base( - roleName, + roleType, + roleName, optionColor, setPlayerNum, maxSetNum) @@ -29,29 +33,32 @@ public GhostAndAliveCombinationRoleManagerBase( public abstract void InitializeGhostRole( byte rolePlayerId, GhostRoleBase role, SingleRoleBase aliveRole); - public int GetOptionIdOffset() => this.OptionIdOffset; - public GhostRoleBase GetGhostRole(ExtremeRoleId id) => this.CombGhostRole[id]; protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - base.CreateSpecificOption(parentOps); + base.CreateSpecificOption(factory); IEnumerable collection = this.CombGhostRole.Values; - var factory = new AutoParentSetFactory(tab: OptionTab.Combination, parent: parentOps); foreach (var item in collection.Select( (Value, Index) => new { Value, Index })) { - int optionOffset = this.OptionIdOffset + ( - ExtremeRoleManager.OptionOffsetPerRole * ( - item.Index + 1 + this.Roles.Count)); - factory.IdOffset = optionOffset; - factory.NamePrefix = item.Value.Name; - item.Value.CreateRoleSpecificOption(factory, optionOffset); + var role = item.Value; ; + + int offset = (item.Index + 1) * ExtremeGhostRoleManager.IdOffset; + factory.IdOffset = offset; + factory.OptionPrefix = role.Name; + + role.CreateRoleSpecificOption(factory); + if (role is ICombination combGhost) + { + combGhost.OffsetInfo = new MultiAssignRoleBase.OptionOffsetInfo( + this.RoleType, offset); + } } } protected override void CommonInit() diff --git a/ExtremeRoles/Roles/API/Interface/IRoleAbility.cs b/ExtremeRoles/Roles/API/Interface/IRoleAbility.cs index bc19f7bfb..f7bcb9c9f 100644 --- a/ExtremeRoles/Roles/API/Interface/IRoleAbility.cs +++ b/ExtremeRoles/Roles/API/Interface/IRoleAbility.cs @@ -7,7 +7,11 @@ using ExtremeRoles.Module.AbilityFactory; using ExtremeRoles.Module.AbilityBehavior.Interface; + +using ExtremeRoles.Module.CustomOption.Factory; + using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Interfaces; namespace ExtremeRoles.Roles.API.Interface; @@ -33,23 +37,22 @@ public void RoleAbilityInit() { if (this.Button == null) { return; } - var allOpt = OptionManager.Instance; + var cate = ((SingleRoleBase)this).Loader; this.Button.Behavior.SetCoolTime( - allOpt.GetValue( - this.GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime))); + cate.GetValue(RoleAbilityCommonOption.AbilityCoolTime)); - if (allOpt.TryGet( - this.GetRoleOptionId(RoleAbilityCommonOption.AbilityActiveTime), + if (cate.TryGetValueOption( + RoleAbilityCommonOption.AbilityActiveTime, out var activeTimeOption)) { - this.Button.Behavior.SetActiveTime(activeTimeOption.GetValue()); + this.Button.Behavior.SetActiveTime(activeTimeOption.Value); } if (this.Button.Behavior is ICountBehavior countBehavior) { countBehavior.SetAbilityCount( - allOpt.GetValue(this.GetRoleOptionId( - RoleAbilityCommonOption.AbilityCount))); + cate.GetValue( + RoleAbilityCommonOption.AbilityCount)); } this.Button.OnMeetingEnd(); @@ -69,10 +72,7 @@ protected static bool IsCommonUse() ExileController.Instance == null && IntroCutscene.Instance == null; } -} -public static class IRoleAbilityMixin -{ private const float defaultCoolTime = 30.0f; private const float minCoolTime = 0.5f; private const float maxCoolTime = 120.0f; @@ -82,69 +82,49 @@ public static class IRoleAbilityMixin public static void CreateCommonAbilityOption( - this IRoleAbility self, - IOptionInfo parentOps, - float defaultActiveTime = float.MaxValue) + AutoParentSetOptionCategoryFactory factory, + float defaultActiveTime = float.MaxValue, + IOption parentOpt = null) { - - SingleRoleBase role = (SingleRoleBase)self; - - new FloatCustomOption( - self.GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime), - string.Concat( - role.RoleName, - RoleAbilityCommonOption.AbilityCoolTime.ToString()), + factory.CreateFloatOption( + RoleAbilityCommonOption.AbilityCoolTime, defaultCoolTime, minCoolTime, maxCoolTime, step, - parentOps, format: OptionUnit.Second, - tab: role.Tab); + parentOpt, + format: OptionUnit.Second); if (defaultActiveTime != float.MaxValue) { defaultActiveTime = Mathf.Clamp( defaultActiveTime, minActiveTime, maxActiveTime); - - new FloatCustomOption( - self.GetRoleOptionId(RoleAbilityCommonOption.AbilityActiveTime), - string.Concat( - role.RoleName, - RoleAbilityCommonOption.AbilityActiveTime.ToString()), + factory.CreateFloatOption( + RoleAbilityCommonOption.AbilityActiveTime, defaultActiveTime, minActiveTime, maxActiveTime, step, - parentOps, format: OptionUnit.Second, - tab: role.Tab); + parentOpt, + format: OptionUnit.Second); } } public static void CreateAbilityCountOption( - this IRoleAbility self, - IOptionInfo parentOps, + AutoParentSetOptionCategoryFactory factory, int defaultAbilityCount, int maxAbilityCount, float defaultActiveTime = float.MaxValue, - int minAbilityCount = 1) + int minAbilityCount = 1, + IOption parentOpt = null) { + CreateCommonAbilityOption( + factory, + defaultActiveTime, + parentOpt); - SingleRoleBase role = (SingleRoleBase)self; - - self.CreateCommonAbilityOption( - parentOps, - defaultActiveTime); - - new IntCustomOption( - self.GetRoleOptionId(RoleAbilityCommonOption.AbilityCount), - string.Concat( - role.RoleName, - RoleAbilityCommonOption.AbilityCount.ToString()), + factory.CreateIntOption( + RoleAbilityCommonOption.AbilityCount, defaultAbilityCount, minAbilityCount, maxAbilityCount, 1, - parentOps, format: OptionUnit.Shot, - tab: role.Tab); + format: OptionUnit.Shot); } - - public static int GetRoleOptionId( - this IRoleAbility self, - RoleAbilityCommonOption option) => ((RoleOptionBase)self).GetRoleOptionId((int)option); } diff --git a/ExtremeRoles/Roles/API/Interface/IRoleReportHook.cs b/ExtremeRoles/Roles/API/Interface/IRoleReportHook.cs index 5bb5ea38c..917f25163 100644 --- a/ExtremeRoles/Roles/API/Interface/IRoleReportHook.cs +++ b/ExtremeRoles/Roles/API/Interface/IRoleReportHook.cs @@ -4,10 +4,10 @@ public interface IRoleReportHook { public void HookReportButton( PlayerControl rolePlayer, - GameData.PlayerInfo reporter); + NetworkedPlayerInfo reporter); public void HookBodyReport( PlayerControl rolePlayer, - GameData.PlayerInfo reporter, - GameData.PlayerInfo reportBody); + NetworkedPlayerInfo reporter, + NetworkedPlayerInfo reportBody); } } diff --git a/ExtremeRoles/Roles/API/Interface/IRoleResetMeeting.cs b/ExtremeRoles/Roles/API/Interface/IRoleResetMeeting.cs index d03f9c88a..490fde766 100644 --- a/ExtremeRoles/Roles/API/Interface/IRoleResetMeeting.cs +++ b/ExtremeRoles/Roles/API/Interface/IRoleResetMeeting.cs @@ -2,7 +2,7 @@ { public interface IRoleResetMeeting { - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null); + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null); public void ResetOnMeetingStart(); } diff --git a/ExtremeRoles/Roles/API/Interface/IRoleVoteModifier.cs b/ExtremeRoles/Roles/API/Interface/IRoleVoteModifier.cs index 2fe520342..1f5438988 100644 --- a/ExtremeRoles/Roles/API/Interface/IRoleVoteModifier.cs +++ b/ExtremeRoles/Roles/API/Interface/IRoleVoteModifier.cs @@ -22,7 +22,7 @@ public void ModifiedVote( public void ModifiedVoteAnime( MeetingHud instance, - GameData.PlayerInfo rolePlayer, + NetworkedPlayerInfo rolePlayer, ref Dictionary voteIndex); public void ResetModifier(); diff --git a/ExtremeRoles/Roles/API/Interface/IRoleWinPlayerModifier.cs b/ExtremeRoles/Roles/API/Interface/IRoleWinPlayerModifier.cs index 38b816115..596aff0b1 100644 --- a/ExtremeRoles/Roles/API/Interface/IRoleWinPlayerModifier.cs +++ b/ExtremeRoles/Roles/API/Interface/IRoleWinPlayerModifier.cs @@ -5,7 +5,7 @@ namespace ExtremeRoles.Roles.API.Interface; public interface IRoleWinPlayerModifier { public void ModifiedWinPlayer( - GameData.PlayerInfo rolePlayerInfo, + NetworkedPlayerInfo rolePlayerInfo, GameOverReason reason, ref ExtremeGameResult.WinnerTempData winner); } diff --git a/ExtremeRoles/Roles/API/MultiAssignRoleBase.cs b/ExtremeRoles/Roles/API/MultiAssignRoleBase.cs index 8b420145c..2749f39c5 100644 --- a/ExtremeRoles/Roles/API/MultiAssignRoleBase.cs +++ b/ExtremeRoles/Roles/API/MultiAssignRoleBase.cs @@ -4,20 +4,41 @@ using AmongUs.GameOptions; using ExtremeRoles.Helper; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Interfaces; + +#nullable enable namespace ExtremeRoles.Roles.API; public abstract class MultiAssignRoleBase : SingleRoleBase { - - public SingleRoleBase AnotherRole = null; + public sealed record class OptionOffsetInfo(CombinationRoleType RoleId, int IdOffset); + + public SingleRoleBase? AnotherRole = null; public bool CanHasAnotherRole = false; - protected int ManagerOptionOffset = 0; - public MultiAssignRoleBase( + public OptionOffsetInfo? OffsetInfo { protected get; set; } + + public override IOptionLoader Loader + { + get + { + if (OffsetInfo is null || + !OptionManager.Instance.TryGetCategory( + this.Tab, + ExtremeRoleManager.GetCombRoleGroupId(this.OffsetInfo.RoleId), + out var cate)) + { + throw new ArgumentException("Can't find category"); + } + return new OptionLoadWrapper(cate, this.OffsetInfo.IdOffset); + } + } + + public MultiAssignRoleBase( ExtremeRoleId id, ExtremeRoleType team, string roleName, @@ -43,8 +64,19 @@ public void SetRoleType(RoleTypes roleType) { switch (roleType) { - case RoleTypes.Shapeshifter: - case RoleTypes.Impostor: + case RoleTypes.Crewmate: + case RoleTypes.Engineer: + case RoleTypes.Scientist: + case RoleTypes.Noisemaker: + case RoleTypes.Tracker: + this.CanKill = false; + this.UseVent = false; + this.UseSabotage = false; + this.HasTask = true; + break; + case RoleTypes.Impostor: + case RoleTypes.Shapeshifter: + case RoleTypes.Phantom: this.Team = ExtremeRoleType.Impostor; this.NameColor = Palette.ImpostorRed; this.CanKill = true; @@ -52,20 +84,19 @@ public void SetRoleType(RoleTypes roleType) this.UseSabotage = true; this.HasTask = false; break; - case RoleTypes.Crewmate: - case RoleTypes.Engineer: - case RoleTypes.Scientist: - this.CanKill = false; - this.UseVent = false; - this.UseSabotage = false; - this.HasTask = true; - break; default: break; }; } - public void SetAnotherRole(SingleRoleBase role) + public override SingleRoleBase Clone() + { + var newRole = (MultiAssignRoleBase)base.Clone(); + newRole.OffsetInfo = this.OffsetInfo; + return newRole; + } + + public void SetAnotherRole(SingleRoleBase role) { if (this.CanHasAnotherRole) @@ -172,25 +203,10 @@ public override Color GetTargetRoleSeeColor( return base.GetTargetRoleSeeColor(targetRole, targetPlayerId); } - public virtual void OverrideAnotherRoleSetting() - { - return; - } - public int GetManagerOptionId(T option) where T : struct, IConvertible - { - EnumCheck(option); - - return GetManagerOptionId(Convert.ToInt32(option)); - } - - public int GetManagerOptionId(int option) => this.ManagerOptionOffset + option; - - public void SetManagerOptionOffset(int offset) - { - this.ManagerOptionOffset = offset; - } - - public int GetManagerOptionOffset() => this.ManagerOptionOffset; + public virtual void OverrideAnotherRoleSetting() + { + return; + } protected string CreateImpCrewPrefix() => this.IsImpostor() ? "Evil" : "Nice"; } diff --git a/ExtremeRoles/Roles/API/RoleSetting.cs b/ExtremeRoles/Roles/API/RoleSetting.cs index 58526d09c..02abd2255 100644 --- a/ExtremeRoles/Roles/API/RoleSetting.cs +++ b/ExtremeRoles/Roles/API/RoleSetting.cs @@ -1,5 +1,8 @@ using System; -using ExtremeRoles.Module.CustomOption; + + +using ExtremeRoles.Module.CustomOption.Factory; +using ExtremeRoles.Module.CustomOption.Interfaces; using ExtremeRoles.Roles.API.Interface; namespace ExtremeRoles.Roles.API; @@ -14,8 +17,8 @@ public enum ExtremeRoleType : int } public enum RoleCommonOption { - RoleNum = 20, - SpawnRate, + SpawnRate = 20, + RoleNum, AssignWeight, HasOtherVision, Vision, @@ -31,21 +34,11 @@ public enum KillerCommonOption public abstract class RoleOptionBase { - public bool CanKill = false; - protected int OptionIdOffset = 0; - - public int GetRoleOptionId(T option) where T : struct, IConvertible - { - EnumCheck(option); - return GetRoleOptionId(Convert.ToInt32(option)); - } - public int GetRoleOptionId(int option) => this.OptionIdOffset + option; + public abstract IOptionLoader Loader { get; } - public int GetRoleOptionOffset() => this.OptionIdOffset; - - public void Initialize() + public void Initialize() { CommonInit(); RoleSpecificInit(); @@ -57,42 +50,33 @@ public void Initialize() } } - public void CreateRoleAllOption( - int optionIdOffset) + public void CreateRoleAllOption() { - this.OptionIdOffset = optionIdOffset; - var parentOps = CreateSpawnOption(); - CreateVisionOption(parentOps); - - if (this.CanKill) - { - CreateKillerOption(parentOps); - } - - CreateSpecificOption(parentOps); + using var factory = CreateSpawnOption(); + this.CreateRoleSpecificOption(factory); } public void CreateRoleSpecificOption( - IOptionInfo parentOps, - int optionIdOffset) + AutoParentSetOptionCategoryFactory factory, bool ignorePrefix = true) { - this.OptionIdOffset = optionIdOffset; - CreateVisionOption(parentOps); + CreateVisionOption(factory, ignorePrefix); if (this.CanKill) { - CreateKillerOption(parentOps); + CreateKillerOption(factory, ignorePrefix: ignorePrefix); } - CreateSpecificOption(parentOps); + CreateSpecificOption(factory); } protected abstract void CreateKillerOption( - IOptionInfo parentOps); - protected abstract IOptionInfo CreateSpawnOption(); + AutoParentSetOptionCategoryFactory factory, + IOption parent = null, + bool ignorePrefix = true); + protected abstract AutoParentSetOptionCategoryFactory CreateSpawnOption(); protected abstract void CreateSpecificOption( - IOptionInfo parentOps); + AutoParentSetOptionCategoryFactory factory); protected abstract void CreateVisionOption( - IOptionInfo parentOps); + AutoParentSetOptionCategoryFactory factory, bool ignorePrefix = true); protected abstract void CommonInit(); diff --git a/ExtremeRoles/Roles/API/SingleRoleBase.Option.cs b/ExtremeRoles/Roles/API/SingleRoleBase.Option.cs index 74622edc4..9f8221a06 100644 --- a/ExtremeRoles/Roles/API/SingleRoleBase.Option.cs +++ b/ExtremeRoles/Roles/API/SingleRoleBase.Option.cs @@ -1,229 +1,81 @@ -using System; -using System.Runtime.CompilerServices; + + +using ExtremeRoles.Module.CustomOption.Factory; using ExtremeRoles.Helper; +using ExtremeRoles.Module.CustomOption.Interfaces; + namespace ExtremeRoles.Roles.API; public abstract partial class SingleRoleBase { protected sealed override void CreateKillerOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory, + IOption parent = null, + bool ignorePrefix = true) { - var killCoolOption = CreateBoolOption( + var killCoolOption = factory.CreateBoolOption( KillerCommonOption.HasOtherKillCool, - false, parentOps); - CreateFloatOption( + false, parent, + ignorePrefix: ignorePrefix); + factory.CreateFloatOption( KillerCommonOption.KillCoolDown, 30f, 1.0f, 120f, 0.5f, - killCoolOption, format: OptionUnit.Second); + killCoolOption, format: OptionUnit.Second, + ignorePrefix: ignorePrefix); - var killRangeOption = CreateBoolOption( + var killRangeOption = factory.CreateBoolOption( KillerCommonOption.HasOtherKillRange, - false, parentOps); - CreateSelectionOption( + false, parent, + ignorePrefix: ignorePrefix); + factory.CreateSelectionOption( KillerCommonOption.KillRange, OptionCreator.Range, - killRangeOption); + killRangeOption, + ignorePrefix: ignorePrefix); } - protected sealed override IOptionInfo CreateSpawnOption() + protected sealed override AutoParentSetOptionCategoryFactory CreateSpawnOption() { - var roleSetOption = CreateSelectionOption( + var factory = OptionManager.CreateAutoParentSetOptionCategory( + ExtremeRoleManager.GetRoleGroupId(this.Id), + this.RawRoleName, this.Tab, this.NameColor); + + var roleSetOption = factory.Create0To100Percentage10StepOption( RoleCommonOption.SpawnRate, - OptionCreator.SpawnRate, null, true, - colored: true); + ignorePrefix: true); int spawnNum = this.IsImpostor() ? GameSystem.MaxImposterNum : GameSystem.VanillaMaxPlayerNum - 1; - CreateIntOption( + factory.CreateIntOption( RoleCommonOption.RoleNum, - 1, 1, spawnNum, 1, roleSetOption); + 1, 1, spawnNum, 1, + ignorePrefix: true); - new IntCustomOption( - GetRoleOptionId(RoleCommonOption.AssignWeight), - $"|{this.RawRoleName}|{RoleCommonOption.AssignWeight}", + factory.CreateIntOption( + RoleCommonOption.AssignWeight, 500, 1, 1000, 1, - roleSetOption, - tab: this.Tab); + ignorePrefix: true); - return roleSetOption; + return factory; } protected sealed override void CreateVisionOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory, bool ignorePrefix = true) { - var visionOption = CreateBoolOption( + var visionOption = factory.CreateBoolOption( RoleCommonOption.HasOtherVision, - false, parentOps); - CreateFloatOption(RoleCommonOption.Vision, + false, + ignorePrefix: ignorePrefix); + factory.CreateFloatOption(RoleCommonOption.Vision, 2f, 0.25f, 5.0f, 0.25f, - visionOption, format: OptionUnit.Multiplier); + visionOption, format: OptionUnit.Multiplier, + ignorePrefix: ignorePrefix); - CreateBoolOption( + factory.CreateBoolOption( RoleCommonOption.ApplyEnvironmentVisionEffect, - this.IsCrewmate(), visionOption); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected FloatCustomOption CreateFloatOption( - T option, - float defaultValue, - float min, float max, float step, - IOptionInfo parent = null, - bool isHeader = false, - bool isHidden = false, - OptionUnit format = OptionUnit.None, - bool invert = false, - IOptionInfo enableCheckOption = null, - bool colored = false) where T : struct, IConvertible - { - EnumCheck(option); - - return new FloatCustomOption( - GetRoleOptionId(option), - createAutoOptionString(option, colored), - defaultValue, - min, max, step, - parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected FloatDynamicCustomOption CreateFloatDynamicOption( - T option, - float defaultValue, - float min, float step, - IOptionInfo parent = null, - bool isHeader = false, - bool isHidden = false, - OptionUnit format = OptionUnit.None, - bool invert = false, - IOptionInfo enableCheckOption = null, - bool colored = false, - float tempMaxValue = 0.0f) where T : struct, IConvertible - { - EnumCheck(option); - - return new FloatDynamicCustomOption( - GetRoleOptionId(option), - createAutoOptionString(option, colored), - defaultValue, - min, step, - parent, isHeader, isHidden, - format, invert, enableCheckOption, - this.Tab, tempMaxValue); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected IntCustomOption CreateIntOption( - T option, - int defaultValue, - int min, int max, int step, - IOptionInfo parent = null, - bool isHeader = false, - bool isHidden = false, - OptionUnit format = OptionUnit.None, - bool invert = false, - IOptionInfo enableCheckOption = null, - bool colored = false) where T : struct, IConvertible - { - EnumCheck(option); - - return new IntCustomOption( - GetRoleOptionId(option), - createAutoOptionString(option, colored), - defaultValue, - min, max, step, - parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected IntDynamicCustomOption CreateIntDynamicOption( - T option, - int defaultValue, - int min, int step, - IOptionInfo parent = null, - bool isHeader = false, - bool isHidden = false, - OptionUnit format = OptionUnit.None, - bool invert = false, - IOptionInfo enableCheckOption = null, - bool colored = false, - int tempMaxValue = 0) where T : struct, IConvertible - { - EnumCheck(option); - - return new IntDynamicCustomOption( - GetRoleOptionId(option), - createAutoOptionString(option, colored), - defaultValue, - min, step, - parent, isHeader, isHidden, - format, invert, enableCheckOption, - this.Tab, tempMaxValue); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected BoolCustomOption CreateBoolOption( - T option, - bool defaultValue, - IOptionInfo parent = null, - bool isHeader = false, - bool isHidden = false, - OptionUnit format = OptionUnit.None, - bool invert = false, - IOptionInfo enableCheckOption = null, - bool colored = false) where T : struct, IConvertible - { - EnumCheck(option); - - return new BoolCustomOption( - GetRoleOptionId(option), - createAutoOptionString(option, colored), - defaultValue, - parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected SelectionCustomOption CreateSelectionOption( - T option, - string[] selections, - IOptionInfo parent = null, - bool isHeader = false, - bool isHidden = false, - OptionUnit format = OptionUnit.None, - bool invert = false, - IOptionInfo enableCheckOption = null, - bool colored = false) where T : struct, IConvertible - { - EnumCheck(option); - - return new SelectionCustomOption( - GetRoleOptionId(option), - createAutoOptionString(option, colored), - selections, - parent, isHeader, isHidden, - format, invert, enableCheckOption, this.Tab); - } - - private string createAutoOptionString( - T option, bool colored) where T : struct, IConvertible - { - if (!colored) - { - return string.Concat( - this.RawRoleName, option.ToString()); - } - else - { - return Design.ColoedString( - this.NameColor, - string.Concat( - this.RawRoleName, - RoleCommonOption.SpawnRate.ToString())); - } + this.IsCrewmate(), visionOption, + ignorePrefix: ignorePrefix); } } diff --git a/ExtremeRoles/Roles/API/SingleRoleBase.cs b/ExtremeRoles/Roles/API/SingleRoleBase.cs index 97c63597d..67417befd 100644 --- a/ExtremeRoles/Roles/API/SingleRoleBase.cs +++ b/ExtremeRoles/Roles/API/SingleRoleBase.cs @@ -1,8 +1,13 @@ -using UnityEngine; +using System; + +using UnityEngine; + -using ExtremeRoles.Module.CustomOption; using AmongUs.GameOptions; + +using ExtremeRoles.Module.CustomOption.Interfaces; + namespace ExtremeRoles.Roles.API; public abstract partial class SingleRoleBase : RoleOptionBase @@ -36,14 +41,29 @@ public abstract partial class SingleRoleBase : RoleOptionBase public float KillCoolTime = 0f; public int KillRange = 1; - public ExtremeRoleId Id; - public ExtremeRoleType Team; + public readonly ExtremeRoleId Id; + public ExtremeRoleType Team; protected Color NameColor; - protected string RawRoleName; - - public SingleRoleBase() + public readonly string RawRoleName; + + public override IOptionLoader Loader + { + get + { + if (!OptionManager.Instance.TryGetCategory( + this.Tab, + ExtremeRoleManager.GetRoleGroupId(this.Id), + out var cate)) + { + throw new ArgumentException("Can't find category"); + } + return cate; + } + } + + public SingleRoleBase() { } public SingleRoleBase( ExtremeRoleId id, @@ -120,7 +140,8 @@ public virtual SingleRoleBase Clone() protected override void CommonInit() { var baseOption = GameOptionsManager.Instance.CurrentGameOptions; - var allOption = OptionManager.Instance; + + var loader = this.Loader; this.Vision = this.IsImpostor() ? baseOption.GetFloat(FloatOptionNames.ImpostorLightMod) : @@ -132,33 +153,33 @@ protected override void CommonInit() this.IsApplyEnvironmentVision = !this.IsImpostor(); - this.HasOtherVision = allOption.GetValue( - GetRoleOptionId(RoleCommonOption.HasOtherVision)); + this.HasOtherVision = loader.GetValue( + RoleCommonOption.HasOtherVision); if (this.HasOtherVision) { - this.Vision = allOption.GetValue( - GetRoleOptionId(RoleCommonOption.Vision)); - this.IsApplyEnvironmentVision = allOption.GetValue( - GetRoleOptionId(RoleCommonOption.ApplyEnvironmentVisionEffect)); + this.Vision = loader.GetValue( + RoleCommonOption.Vision); + this.IsApplyEnvironmentVision = loader.GetValue( + RoleCommonOption.ApplyEnvironmentVisionEffect); } if (this.CanKill) { - this.HasOtherKillCool = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.HasOtherKillCool)); + this.HasOtherKillCool = loader.GetValue( + KillerCommonOption.HasOtherKillCool); if (this.HasOtherKillCool) { - this.KillCoolTime = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.KillCoolDown)); + this.KillCoolTime = loader.GetValue( + KillerCommonOption.KillCoolDown); } - this.HasOtherKillRange = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.HasOtherKillRange)); + this.HasOtherKillRange = loader.GetValue( + KillerCommonOption.HasOtherKillRange); if (this.HasOtherKillRange) { - this.KillRange = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.KillRange)); + this.KillRange = loader.GetValue( + KillerCommonOption.KillRange); } } } diff --git a/ExtremeRoles/Roles/Combination/Accelerator.cs b/ExtremeRoles/Roles/Combination/Accelerator.cs index d35d3e165..09781ab62 100644 --- a/ExtremeRoles/Roles/Combination/Accelerator.cs +++ b/ExtremeRoles/Roles/Combination/Accelerator.cs @@ -8,15 +8,21 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + using ExtremeRoles.Module.CustomMonoBehaviour; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; #nullable enable public sealed class AcceleratorManager : FlexibleCombinationRoleManagerBase { - public AcceleratorManager() : base(new Accelerator(), 1) + public AcceleratorManager() : base( + CombinationRoleType.Accelerator, + new Accelerator(), 1) { } } @@ -106,7 +112,7 @@ private static void setupPanel(Accelerator accelerator, PlayerControl player) obj.transform.position = firstPoint; var rend = obj.AddComponent(); - rend.sprite = Loader.CreateSpriteFromResources( + rend.sprite = Resources.Loader.CreateSpriteFromResources( Path.AcceleratorAcceleratePanel, 100.0f); accelerator.transformer = obj.AddComponent(); @@ -134,9 +140,9 @@ private static void endPanel(Accelerator accelerator, Vector2 endPos) public void CreateAbility() { this.CreateReclickableCountAbilityButton( - Translation.GetString("AccelerateSet"), - Loader.CreateSpriteFromResources( - Path.AcceleratorAccelerateSet), + Translation.GetString("AccelerateSet"), + Resources.Loader.CreateSpriteFromResources( + Path.AcceleratorAccelerateSet), checkAbility: IsAbilityActive, abilityOff: this.CleanUp); if (this.IsCrewmate()) @@ -150,7 +156,7 @@ public bool IsAbilityActive() => public bool IsAbilityUse() => IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -181,31 +187,30 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - var imposterSetting = OptionManager.Instance.Get( - GetManagerOptionId(CombinationRoleCommonOption.IsAssignImposter)); - - CreateKillerOption(imposterSetting); + var imposterSetting = factory.Get((int)CombinationRoleCommonOption.IsAssignImposter); + CreateKillerOption(factory, imposterSetting); - this.CreateAbilityCountOption( - parentOps, 3, 10, 30.0f); - CreateFloatOption( + IRoleAbility.CreateAbilityCountOption( + factory, 3, 10, 30.0f); + factory.CreateFloatOption( Option.Speed, 1.0f, 0.1f, - 3.0f, 0.1f, parentOps); - CreateBoolOption( + 3.0f, 0.1f); + factory.CreateBoolOption( Option.UseOtherPlayer, - true, parentOps); + true); } protected override void RoleSpecificInit() { this.roleNamePrefix = this.CreateImpCrewPrefix(); - this.canUseOtherPlayer = OptionManager.Instance.GetValue( - GetRoleOptionId(Option.UseOtherPlayer)); - this.speed = OptionManager.Instance.GetValue( - GetRoleOptionId(Option.Speed)); + var loader = this.Loader; + this.canUseOtherPlayer = loader.GetValue( + Option.UseOtherPlayer); + this.speed = loader.GetValue( + Option.Speed); this.EnableVentButton = true; this.EnableUseButton = true; diff --git a/ExtremeRoles/Roles/Combination/Avalon.cs b/ExtremeRoles/Roles/Combination/Avalon.cs index 6d47dbb62..eec31a173 100644 --- a/ExtremeRoles/Roles/Combination/Avalon.cs +++ b/ExtremeRoles/Roles/Combination/Avalon.cs @@ -4,19 +4,24 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; using ExtremeRoles.Module.SystemType.CheckPoint; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class Avalon : ConstCombinationRoleManagerBase { public const string Name = "AvalonsRoles"; public Avalon() : base( - Name, new Color(255f, 255f, 255f), 2, + CombinationRoleType.Avalon, + Name, DefaultColor, 2, GameSystem.MaxImposterNum) { this.Roles.Add(new Assassin()); @@ -76,30 +81,30 @@ public override bool TryRolePlayerKilledFrom( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( AssassinOption.HasTask, - false, parentOps); - var killedOps = CreateBoolOption( + false); + var killedOps = factory.CreateBoolOption( AssassinOption.CanKilled, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( AssassinOption.CanKilledFromCrew, false, killedOps); - CreateBoolOption( + factory.CreateBoolOption( AssassinOption.CanKilledFromNeutral, false, killedOps); - var meetingOpt = CreateBoolOption( + var meetingOpt = factory.CreateBoolOption( AssassinOption.IsDeadForceMeeting, true, killedOps); - CreateBoolOption( + factory.CreateBoolOption( AssassinOption.CanSeeRoleBeforeFirstMeeting, false, meetingOpt); - CreateBoolOption( + factory.CreateBoolOption( AssassinOption.CanSeeVote, - true, parentOps); + true); } public override void ExiledAction( @@ -164,23 +169,23 @@ public override bool IsBlockShowMeetingRoleInfo() } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; - - this.HasTask = allOption.GetValue( - GetRoleOptionId(AssassinOption.HasTask)); - this.CanKilled = allOption.GetValue( - GetRoleOptionId(AssassinOption.CanKilled)); - this.CanKilledFromCrew = allOption.GetValue( - GetRoleOptionId(AssassinOption.CanKilledFromCrew)); - this.CanKilledFromNeutral = allOption.GetValue( - GetRoleOptionId(AssassinOption.CanKilledFromNeutral)); - this.CanSeeVote = allOption.GetValue( - GetRoleOptionId(AssassinOption.CanSeeVote)); - - this.isDeadForceMeeting = allOption.GetValue( - GetRoleOptionId(AssassinOption.IsDeadForceMeeting)); - this.CanSeeRoleBeforeFirstMeeting = allOption.GetValue( - GetRoleOptionId(AssassinOption.CanSeeRoleBeforeFirstMeeting)); + var loader = this.Loader; + + this.HasTask = loader.GetValue( + AssassinOption.HasTask); + this.CanKilled = loader.GetValue( + AssassinOption.CanKilled); + this.CanKilledFromCrew = loader.GetValue( + AssassinOption.CanKilledFromCrew); + this.CanKilledFromNeutral = loader.GetValue( + AssassinOption.CanKilledFromNeutral); + this.CanSeeVote = loader.GetValue( + AssassinOption.CanSeeVote); + + this.isDeadForceMeeting = loader.GetValue( + AssassinOption.IsDeadForceMeeting); + this.CanSeeRoleBeforeFirstMeeting = loader.GetValue( + AssassinOption.CanSeeRoleBeforeFirstMeeting); this.IsFirstMeeting = true; } @@ -259,7 +264,7 @@ public void IntroEndSetUp() this.updateShowIcon(); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.updateShowIcon(); } @@ -294,43 +299,43 @@ public override Color GetTargetRoleSeeColor( protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( MarlinOption.HasTask, - false, parentOps); + false); - CreateBoolOption( + factory.CreateBoolOption( MarlinOption.CanSeeAssassin, - true, parentOps); + true); - CreateBoolOption( + factory.CreateBoolOption( MarlinOption.CanSeeVote, - true, parentOps); - CreateBoolOption( + true); + factory.CreateBoolOption( MarlinOption.CanSeeNeutral, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( MarlinOption.CanUseVent, - false, parentOps); + false); } protected override void RoleSpecificInit() { this.IsAssassinate = false; - var allOption = OptionManager.Instance; - - this.HasTask = allOption.GetValue( - GetRoleOptionId(MarlinOption.HasTask)); - this.canSeeAssassin = allOption.GetValue( - GetRoleOptionId(MarlinOption.CanSeeAssassin)); - this.CanSeeVote = allOption.GetValue( - GetRoleOptionId(MarlinOption.CanSeeVote)); - this.CanSeeNeutral = allOption.GetValue( - GetRoleOptionId(MarlinOption.CanSeeNeutral)); - this.UseVent = allOption.GetValue( - GetRoleOptionId(MarlinOption.CanUseVent)); + var loader = this.Loader; + + this.HasTask = loader.GetValue( + MarlinOption.HasTask); + this.canSeeAssassin = loader.GetValue( + MarlinOption.CanSeeAssassin); + this.CanSeeVote = loader.GetValue( + MarlinOption.CanSeeVote); + this.CanSeeNeutral = loader.GetValue( + MarlinOption.CanSeeNeutral); + this.UseVent = loader.GetValue( + MarlinOption.CanUseVent); this.PlayerIcon = new Dictionary(); } diff --git a/ExtremeRoles/Roles/Combination/Buddy.cs b/ExtremeRoles/Roles/Combination/Buddy.cs index 56eaf3b85..7ead5ab63 100644 --- a/ExtremeRoles/Roles/Combination/Buddy.cs +++ b/ExtremeRoles/Roles/Combination/Buddy.cs @@ -5,16 +5,20 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class BuddyManager : FlexibleCombinationRoleManagerBase { public BuddyManager() : base( + CombinationRoleType.Buddy, new Buddy(), canAssignImposter: false) { } @@ -34,10 +38,10 @@ public enum BuddyOption public sealed class BuddyContainer { - private HashSet buddy = new HashSet(); + private HashSet buddy = new HashSet(); private HashSet bytedBuddy = new HashSet(); - public HashSet PlayerInfo => this.buddy; + public HashSet PlayerInfo => this.buddy; public BuddyContainer() { @@ -49,7 +53,7 @@ public string GetAllPlayerName() { List playerName = new List(); - foreach (GameData.PlayerInfo player in this.PlayerInfo) + foreach (NetworkedPlayerInfo player in this.PlayerInfo) { if (player.PlayerId == CachedPlayerControl.LocalPlayer.PlayerId) { @@ -70,11 +74,11 @@ public string GetAllPlayerName() return string.Concat(playerName); } - public bool Contains(GameData.PlayerInfo player) => this.buddy.Contains(player); + public bool Contains(NetworkedPlayerInfo player) => this.buddy.Contains(player); public bool Contains(byte playerId) => this.bytedBuddy.Contains(playerId); - public void Add(GameData.PlayerInfo player) + public void Add(NetworkedPlayerInfo player) { this.buddy.Add(player); this.bytedBuddy.Add(player.PlayerId); @@ -103,8 +107,8 @@ public void IntroBeginSetUp() { this.buddy = this.getSameBuddy(); - if (IsAwake || - !this.CanHasAnotherRole || + if (IsAwake || + !this.CanHasAnotherRole || this.AnotherRole == null) { return; } this.hiddeRole = this.AnotherRole; @@ -125,7 +129,7 @@ this.buddy is not null && rolePlayer.Data != null && rolePlayer.Data.Tasks.Count != 0) { - foreach (GameData.PlayerInfo playerId in this.buddy.PlayerInfo) + foreach (NetworkedPlayerInfo playerId in this.buddy.PlayerInfo) { if (Player.GetPlayerTaskGage(playerId) < this.awakeTaskGage) { @@ -154,7 +158,7 @@ this.buddy is not null && public override Color GetTargetRoleSeeColor( SingleRoleBase targetRole, byte targetPlayerId) { - if (IsAwake && + if (IsAwake && this.buddy is not null && this.buddy.Contains(targetPlayerId)) { @@ -183,7 +187,7 @@ public override string GetFullDescription() { return string.Format( base.GetFullDescription(), - this.buddy is null ? + this.buddy is null ? string.Empty : this.buddy.GetAllPlayerName()); } else @@ -214,7 +218,7 @@ public override string GetIntroDescription() { return string.Format( base.GetIntroDescription(), - this.buddy is null ? + this.buddy is null ? string.Empty : this.buddy.GetAllPlayerName()); } else @@ -254,19 +258,18 @@ this.buddy is not null && return base.GetRolePlayerNameTag(targetRole, targetPlayerId); } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( BuddyOption.AwakeTaskGage, 50, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); } protected override void RoleSpecificInit() { - this.awakeTaskGage = OptionManager.Instance.GetValue( - GetRoleOptionId(BuddyOption.AwakeTaskGage)) / 100.0f; + this.awakeTaskGage = this.Loader.GetValue( + BuddyOption.AwakeTaskGage) / 100.0f; this.awakeHasOtherVision = this.HasOtherVision; diff --git a/ExtremeRoles/Roles/Combination/DetectiveOffice.cs b/ExtremeRoles/Roles/Combination/DetectiveOffice.cs index 662b56d7a..11b9760d2 100644 --- a/ExtremeRoles/Roles/Combination/DetectiveOffice.cs +++ b/ExtremeRoles/Roles/Combination/DetectiveOffice.cs @@ -7,13 +7,16 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Resources; using ExtremeRoles.Performance; using ExtremeRoles.Compat; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class DetectiveOffice : ConstCombinationRoleManagerBase @@ -22,7 +25,8 @@ public sealed class DetectiveOffice : ConstCombinationRoleManagerBase public const string Name = "DetectiveOffice"; public DetectiveOffice() : base( - Name, new Color(255f, 255f, 255f), 2, + CombinationRoleType.DetectiveOffice, + Name, DefaultColor, 2, (GameSystem.VanillaMaxPlayerNum - 1) / 2) { this.Roles.Add(new Detective()); @@ -30,11 +34,12 @@ public DetectiveOffice() : base( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - base.CreateSpecificOption(parentOps); - DetectiveApprentice.DetectiveApprenticeOptionHolder.CreateOption( - parentOps, this.OptionIdOffset); + base.CreateSpecificOption(factory); + factory.IdOffset = this.Roles.Count * ExtremeRoleManager.OptionOffsetPerRole; + factory.OptionPrefix = ExtremeRoleId.DetectiveApprentice.ToString(); + DetectiveApprentice.DetectiveApprenticeOptionHolder.CreateOption(factory); } } @@ -163,7 +168,7 @@ public void AllReset(PlayerControl rolePlayer) upgradeAssistant(); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.info.Clear(); } @@ -179,7 +184,7 @@ public void ResetOnMeetingStart() public void HookReportButton( PlayerControl rolePlayer, - GameData.PlayerInfo reporter) + NetworkedPlayerInfo reporter) { this.targetCrime = null; this.searchCrimeInfoTime = float.MaxValue; @@ -187,8 +192,8 @@ public void HookReportButton( public void HookBodyReport( PlayerControl rolePlayer, - GameData.PlayerInfo reporter, - GameData.PlayerInfo reportBody) + NetworkedPlayerInfo reporter, + NetworkedPlayerInfo reportBody) { this.targetCrime = this.info.GetCrimeInfo(reportBody.PlayerId); this.searchCrimeInfoTime = ExtremeRoleManager.GameRole[ @@ -276,27 +281,26 @@ public override void ExiledAction(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( DetectiveOption.SearchRange, - 1.0f, 0.5f, 2.8f, 0.1f, - parentOps); + 1.0f, 0.5f, 2.8f, 0.1f); - CreateFloatOption( + factory.CreateFloatOption( DetectiveOption.SearchTime, 6.0f, 3.0f, 10.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( DetectiveOption.SearchAssistantTime, 4.0f, 2.0f, 7.5f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( DetectiveOption.TextShowTime, 60.0f, 5.0f, 120.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); } protected override void RoleSpecificInit() @@ -305,16 +309,16 @@ protected override void RoleSpecificInit() this.info = new CrimeInfoContainer(); this.info.Clear(); - var allOption = OptionManager.Instance; - this.range = allOption.GetValue( - GetRoleOptionId(DetectiveOption.SearchRange)); - this.searchTime = allOption.GetValue( - GetRoleOptionId(DetectiveOption.SearchTime)); - this.searchAssistantTime = allOption.GetValue( - GetRoleOptionId(DetectiveOption.SearchAssistantTime)); + var loader = this.Loader; + this.range = loader.GetValue( + DetectiveOption.SearchRange); + this.searchTime = loader.GetValue( + DetectiveOption.SearchTime); + this.searchAssistantTime = loader.GetValue( + DetectiveOption.SearchAssistantTime); this.textPopUp = new TextPopUpper( - 4, allOption.GetValue(GetRoleOptionId(DetectiveOption.TextShowTime)), + 4, loader.GetValue(DetectiveOption.TextShowTime), new Vector3(-3.75f, -2.5f, -250.0f), TMPro.TextAlignmentOptions.BottomLeft); this.searchCrimeInfoTime = float.MaxValue; @@ -453,15 +457,15 @@ public void HookMuderPlayer( public void HookReportButton( PlayerControl rolePlayer, - GameData.PlayerInfo reporter) + NetworkedPlayerInfo reporter) { this.deadBodyInfo.Clear(); } public void HookBodyReport( PlayerControl rolePlayer, - GameData.PlayerInfo reporter, - GameData.PlayerInfo reportBody) + NetworkedPlayerInfo reporter, + NetworkedPlayerInfo reportBody) { if (this.IsSameControlId(ExtremeRoleManager.GameRole[rolePlayer.PlayerId])) { @@ -492,7 +496,7 @@ public override void ExiledAction(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { } protected override void RoleSpecificInit() @@ -528,120 +532,60 @@ public struct DetectiveApprenticeOptionHolder public bool HasOtherButton; public int HasOtherButtonNum; - public enum DetectiveApprenticeOption - { - HasOtherVision, - Vision, - ApplyEnvironmentVisionEffect, - HasOtherButton, - HasOtherButtonNum, - } + public enum DetectiveApprenticeOption + { + HasOtherVision, + Vision, + ApplyEnvironmentVisionEffect, + HasOtherButton, + HasOtherButtonNum, + } public static void CreateOption( - IOptionInfo parentOps, - int optionId) - { - int getRoleOptionId(T option) where T : struct, IConvertible - { - return optionId + Convert.ToInt32(option); - } + AutoParentSetOptionCategoryFactory factory) + { + var visionOpt = factory.CreateBoolOption( + DetectiveApprenticeOption.HasOtherVision, + false); - string roleName = ExtremeRoleId.DetectiveApprentice.ToString(); - - var visionOption = new BoolCustomOption( - getRoleOptionId(DetectiveApprenticeOption.HasOtherVision), - string.Concat( - roleName, - DetectiveApprenticeOption.HasOtherVision.ToString()), - false, parentOps, - tab: OptionTab.Combination); - - new FloatCustomOption( - getRoleOptionId(DetectiveApprenticeOption.Vision), - string.Concat( - roleName, - DetectiveApprenticeOption.Vision.ToString()), - 2f, 0.25f, 5f, 0.25f, - visionOption, format: OptionUnit.Multiplier, - tab: OptionTab.Combination); - new BoolCustomOption( - getRoleOptionId(DetectiveApprenticeOption.ApplyEnvironmentVisionEffect), - string.Concat( - roleName, - DetectiveApprenticeOption.ApplyEnvironmentVisionEffect.ToString()), - false, visionOption, - tab: OptionTab.Combination); - - new IntCustomOption( - getRoleOptionId(RoleAbilityCommonOption.AbilityCount), - string.Concat( - roleName, - RoleAbilityCommonOption.AbilityCount.ToString()), - 1, 1, 10, 1, - parentOps, format: OptionUnit.Shot, - tab: OptionTab.Combination); - - new FloatCustomOption( - getRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime), - string.Concat( - roleName, - RoleAbilityCommonOption.AbilityCoolTime.ToString()), - 30.0f, 0.5f, 60f, 0.5f, - parentOps, format: OptionUnit.Second, - tab: OptionTab.Combination); - - new FloatCustomOption( - getRoleOptionId(RoleAbilityCommonOption.AbilityActiveTime), - string.Concat( - roleName, - RoleAbilityCommonOption.AbilityActiveTime.ToString()), - 3.0f, 1.0f, 5.0f, 0.5f, - parentOps, format: OptionUnit.Second, - tab: OptionTab.Combination); - - var buttonOption = new BoolCustomOption( - getRoleOptionId(DetectiveApprenticeOption.HasOtherButton), - string.Concat( - roleName, - DetectiveApprenticeOption.HasOtherButton.ToString()), - false, parentOps, - tab: OptionTab.Combination); - new IntCustomOption( - getRoleOptionId(DetectiveApprenticeOption.HasOtherButtonNum), - string.Concat( - roleName, - DetectiveApprenticeOption.HasOtherButtonNum.ToString()), - 1, 1, 10, 1, buttonOption, - format: OptionUnit.Shot, - tab: OptionTab.Combination); - } - - public static DetectiveApprenticeOptionHolder LoadOptions( - int optionId) - { - int getRoleOptionId(DetectiveApprenticeOption option) - { - return optionId + (int)option; - } + factory.CreateFloatOption( + DetectiveApprenticeOption.Vision, + 2f, 0.25f, 5f, 0.25f, + visionOpt, + format: OptionUnit.Multiplier); + + factory.CreateBoolOption( + DetectiveApprenticeOption.ApplyEnvironmentVisionEffect, + false, visionOpt); - var allOption = OptionManager.Instance; + IRoleAbility.CreateAbilityCountOption( + factory, 1, 10, 3.0f); + + var buttonOpt = factory.CreateBoolOption( + DetectiveApprenticeOption.HasOtherButton, + false); + factory.CreateIntOption( + DetectiveApprenticeOption.HasOtherButtonNum, + 1, 1, 10, 1, buttonOpt, + format: OptionUnit.Shot); + } + public static DetectiveApprenticeOptionHolder LoadOptions(in OptionLoadWrapper loader) + { return new DetectiveApprenticeOptionHolder() { - OptionOffset = optionId, - HasOtherVision = allOption.GetValue( - getRoleOptionId(DetectiveApprenticeOption.HasOtherVision)), - Vision = allOption.GetValue( - getRoleOptionId(DetectiveApprenticeOption.Vision)), - ApplyEnvironmentVisionEffect = allOption.GetValue( - getRoleOptionId(DetectiveApprenticeOption.ApplyEnvironmentVisionEffect)), - HasOtherButton = allOption.GetValue( - getRoleOptionId(DetectiveApprenticeOption.HasOtherButton)), - HasOtherButtonNum = allOption.GetValue( - getRoleOptionId(DetectiveApprenticeOption.HasOtherButtonNum)), + HasOtherVision = loader.GetValue( + DetectiveApprenticeOption.HasOtherVision), + Vision = loader.GetValue( + DetectiveApprenticeOption.Vision), + ApplyEnvironmentVisionEffect = loader.GetValue( + DetectiveApprenticeOption.ApplyEnvironmentVisionEffect), + HasOtherButton = loader.GetValue( + DetectiveApprenticeOption.HasOtherButton), + HasOtherButtonNum = loader.GetValue( + DetectiveApprenticeOption.HasOtherButtonNum), }; } - } public ExtremeAbilityButton Button @@ -670,7 +614,6 @@ DetectiveApprenticeOptionHolder option ColorPalette.DetectiveApprenticeKonai, false, true, false, false) { - this.OptionIdOffset = option.OptionOffset; this.SetControlId(gameControlId); this.HasOtherVision = option.HasOtherVision; if (this.HasOtherVision) @@ -720,10 +663,18 @@ public static void ChangeToDetectiveApprentice( } } - DetectiveApprentice newRole = new DetectiveApprentice( + if (!OptionManager.Instance.TryGetCategory( + OptionTab.Combination, + ExtremeRoleManager.GetCombRoleGroupId(CombinationRoleType.DetectiveOffice), + out var cate)) + { + return; + } + + int offset = 2 * ExtremeRoleManager.OptionOffsetPerRole; + DetectiveApprentice newRole = new DetectiveApprentice( prevRole.GameControlId, - DetectiveApprenticeOptionHolder.LoadOptions( - prevRole.GetManagerOptionId(0))); + DetectiveApprenticeOptionHolder.LoadOptions(new OptionLoadWrapper(cate, offset))); if (playerId == CachedPlayerControl.LocalPlayer.PlayerId) { newRole.CreateAbility(); @@ -754,8 +705,8 @@ public void CreateAbility() this.CreateAbilityCountButton( "emergencyMeeting", - Loader.CreateSpriteFromResources( - Path.DetectiveApprenticeEmergencyMeeting), + Resources.Loader.CreateSpriteFromResources( + Path.DetectiveApprenticeEmergencyMeeting), abilityOff: CleanUp, checkAbility: IsOpen, isReduceOnActive: true); @@ -767,7 +718,7 @@ public bool IsAbilityUse() => public bool IsOpen() => Minigame.Instance != null; - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.meeting = null; this.callAnotherButton = false; @@ -826,7 +777,7 @@ public bool UseAbility() public void HookReportButton( PlayerControl rolePlayer, - GameData.PlayerInfo reporter) + NetworkedPlayerInfo reporter) { if (this.callAnotherButton && CachedPlayerControl.LocalPlayer.PlayerId == reporter.PlayerId && @@ -841,14 +792,14 @@ public void HookReportButton( public void HookBodyReport( PlayerControl rolePlayer, - GameData.PlayerInfo reporter, - GameData.PlayerInfo reportBody) + NetworkedPlayerInfo reporter, + NetworkedPlayerInfo reportBody) { return; } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { throw new Exception("Don't call this class method!!"); } diff --git a/ExtremeRoles/Roles/Combination/Guesser.cs b/ExtremeRoles/Roles/Combination/Guesser.cs index 97ce8ac64..d16dd0069 100644 --- a/ExtremeRoles/Roles/Combination/Guesser.cs +++ b/ExtremeRoles/Roles/Combination/Guesser.cs @@ -8,6 +8,7 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; + using ExtremeRoles.Module.CustomMonoBehaviour; using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; @@ -15,13 +16,18 @@ using ExtremeRoles.Roles.Solo; using ExtremeRoles.Roles.Solo.Crewmate; using ExtremeRoles.Performance; -using ExtremeRoles.Module.CustomOption; + + +using ExtremeRoles.Module.CustomOption.Factory; +using ExtremeRoles.Roles.Solo.Neutral; namespace ExtremeRoles.Roles.Combination; public sealed class GuesserManager : FlexibleCombinationRoleManagerBase { - public GuesserManager() : base(new Guesser(), 1) + public GuesserManager() : base( + CombinationRoleType.Guesser, + new Guesser(), 1) { } } @@ -122,11 +128,12 @@ private void addAmongUsRole() foreach (RoleTypes role in Enum.GetValues(typeof(RoleTypes))) { - if (role == RoleTypes.Crewmate || - role == RoleTypes.Impostor || - role == RoleTypes.GuardianAngel || - role == RoleTypes.CrewmateGhost || - role == RoleTypes.ImpostorGhost) + if (role is + RoleTypes.Crewmate or + RoleTypes.Impostor or + RoleTypes.GuardianAngel or + RoleTypes.CrewmateGhost or + RoleTypes.ImpostorGhost) { continue; } @@ -137,9 +144,12 @@ private void addAmongUsRole() { case RoleTypes.Engineer: case RoleTypes.Scientist: + case RoleTypes.Noisemaker: + case RoleTypes.Tracker: team = ExtremeRoleType.Crewmate; break; case RoleTypes.Shapeshifter: + case RoleTypes.Phantom: team = ExtremeRoleType.Impostor; break; default: @@ -155,14 +165,14 @@ private void addExRNormalRole(out NormalExRAssignState assignState) { assignState = new NormalExRAssignState(); - var allOption = OptionManager.Instance; - foreach (var (id, role) in ExtremeRoleManager.NormalRole) { - int spawnOptSel = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.SpawnRate)); - int roleNum = allOption.GetValue( - role.GetRoleOptionId(RoleCommonOption.RoleNum)); + var loader = role.Loader; + + int spawnOptSel = loader.GetValue( + RoleCommonOption.SpawnRate); + int roleNum = loader.GetValue( + RoleCommonOption.RoleNum); if (spawnOptSel < 1 || roleNum <= 0) { @@ -183,9 +193,10 @@ private void addExRNormalRole(out NormalExRAssignState assignState) { case ExtremeRoleId.Jackal: assignState.IsJackalOn = true; - assignState.IsJackalForceReplaceLover = allOption.GetValue( - role.GetRoleOptionId( - Solo.Neutral.Jackal.JackalOption.ForceReplaceLover)); + assignState.IsJackalForceReplaceLover = OptionManager.Instance.TryGetCategory( + OptionTab.Neutral, + ExtremeRoleManager.GetRoleGroupId(ExtremeRoleId.Jackal), + out var cate) && cate.GetValue(Jackal.JackalOption.ForceReplaceLover); break; case ExtremeRoleId.Queen: assignState.IsQueenOn = true; @@ -227,12 +238,14 @@ private void addExRNormalRole(out NormalExRAssignState assignState) foreach (var (id, roleMng) in ExtremeRoleManager.CombRole) { - int spawnOptSel = allOption.GetValue( - roleMng.GetRoleOptionId(RoleCommonOption.SpawnRate)); - int roleNum = allOption.GetValue( - roleMng.GetRoleOptionId(RoleCommonOption.RoleNum)); + var loader = roleMng.Loader; + + int spawnOptSel = loader.GetValue( + RoleCommonOption.SpawnRate); + int roleNum = loader.GetValue( + RoleCommonOption.RoleNum); - if (spawnOptSel < 1 || roleNum <= 0) + if (spawnOptSel < 1 || roleNum <= 0) { continue; } @@ -261,18 +274,17 @@ private void addExRNormalRole(out NormalExRAssignState assignState) private void addExRCombRole(NormalExRAssignState assignState) { - var allOption = OptionManager.Instance; - foreach (var (id, roleMng) in ExtremeRoleManager.CombRole) { - int spawnOptSel = allOption.GetValue( - roleMng.GetRoleOptionId(RoleCommonOption.SpawnRate)); - int roleNum = allOption.GetValue( - roleMng.GetRoleOptionId(RoleCommonOption.RoleNum)); + var loader = roleMng.Loader; - bool multiAssign = allOption.GetValue( - roleMng.GetRoleOptionId( - CombinationRoleCommonOption.IsMultiAssign)); + int spawnOptSel = loader.GetValue( + RoleCommonOption.SpawnRate); + int roleNum = loader.GetValue( + RoleCommonOption.RoleNum); + + bool multiAssign = loader.GetValue( + CombinationRoleCommonOption.IsMultiAssign); if (spawnOptSel < 1 || roleNum <= 0) { @@ -289,11 +301,10 @@ private void addExRCombRole(NormalExRAssignState assignState) if (multiAssign) { - if (allOption.TryGet( - flexMng.GetRoleOptionId( - CombinationRoleCommonOption.IsAssignImposter), + if (loader.TryGetValueOption( + CombinationRoleCommonOption.IsAssignImposter, out var option) && - option.GetValue()) + option.Value) { listAddTargetTeam( baseRoleId, @@ -459,13 +470,20 @@ public Action CreateAbilityAction(PlayerVoteArea instance) { void openGusserUi() { - if (this.uiPrefab == null) + byte targetPlayerId = instance.TargetPlayerId; + var info = GameData.Instance.GetPlayerById(targetPlayerId); + if (info == null) + { + return; + } + + if (this.uiPrefab == null) { this.uiPrefab = UnityEngine.Object.Instantiate( - Loader.GetUnityObjectFromResources( - Path.GusserUiResources, - Path.GusserUiPrefab), - CachedShipStatus.Instance.transform); + Resources.Loader.GetUnityObjectFromResources( + Path.GusserUiResources, + Path.GusserUiPrefab), + CachedShipStatus.Instance.transform); this.uiPrefab.SetActive(false); } @@ -496,12 +514,10 @@ void openGusserUi() ); } - byte targetPlayerId = instance.TargetPlayerId; - this.guesserUi.SetTitle( + this.guesserUi.SetTitle( string.Format( Translation.GetString("guesserUiTitle"), - GameData.Instance.GetPlayerById( - targetPlayerId)?.DefaultOutfit.PlayerName)); + info.DefaultOutfit.PlayerName)); this.guesserUi.SetInfo( string.Format( Translation.GetString("guesserUiInfo"), @@ -514,12 +530,12 @@ void openGusserUi() public void SetSprite(SpriteRenderer render) { - render.sprite = Loader.CreateSpriteFromResources( - Path.GuesserGuess); + render.sprite = Resources.Loader.CreateSpriteFromResources( + Path.GuesserGuess); render.transform.localScale *= new Vector2(0.625f, 0.625f); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.guesserUi = null; } @@ -558,51 +574,44 @@ public void Update(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - var imposterSetting = OptionManager.Instance.Get( - GetManagerOptionId(CombinationRoleCommonOption.IsAssignImposter)); - CreateKillerOption(imposterSetting); + var imposterSetting = factory.Get((int)CombinationRoleCommonOption.IsAssignImposter); + CreateKillerOption(factory, imposterSetting); - CreateBoolOption( + factory.CreateBoolOption( GuesserOption.CanCallMeeting, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( GuesserOption.GuessNum, 1, 1, GameSystem.MaxImposterNum, 1, - parentOps, format: OptionUnit.Shot); - CreateIntOption( + factory.CreateIntOption( GuesserOption.MaxGuessNumWhenMeeting, 1, 1, GameSystem.MaxImposterNum, 1, - parentOps, format: OptionUnit.Shot); - var noneGuessRoleOpt = CreateBoolOption( + var noneGuessRoleOpt = factory.CreateBoolOption( GuesserOption.CanGuessNoneRole, - false, parentOps); - CreateSelectionOption( - GuesserOption.GuessNoneRoleMode, - new string[] - { - GuessMode.BothGuesser.ToString(), - GuessMode.NiceGuesserOnly.ToString(), - GuessMode.EvilGuesserOnly.ToString(), - }, noneGuessRoleOpt); + false); + factory.CreateSelectionOption( + GuesserOption.GuessNoneRoleMode, noneGuessRoleOpt); } protected override void RoleSpecificInit() { this.uiPrefab = null; this.guesserUi = null; - var allOption = OptionManager.Instance; - this.CanCallMeeting = allOption.GetValue( - GetRoleOptionId(GuesserOption.CanCallMeeting)); - bool canGuessNoneRole = allOption.GetValue( - GetRoleOptionId(GuesserOption.CanGuessNoneRole)); - GuessMode guessMode = (GuessMode)allOption.GetValue( - GetRoleOptionId(GuesserOption.GuessNoneRoleMode)); + var loader = this.Loader; + + this.CanCallMeeting = loader.GetValue( + GuesserOption.CanCallMeeting); + + bool canGuessNoneRole = loader.GetValue( + GuesserOption.CanGuessNoneRole); + GuessMode guessMode = (GuessMode)loader.GetValue( + GuesserOption.GuessNoneRoleMode); this.canGuessNoneRole = canGuessNoneRole && (( @@ -617,10 +626,10 @@ protected override void RoleSpecificInit() guessMode == GuessMode.EvilGuesserOnly && this.IsImpostor() )); - this.bulletNum = allOption.GetValue( - GetRoleOptionId(GuesserOption.GuessNum)); - this.maxGuessNum = allOption.GetValue( - GetRoleOptionId(GuesserOption.MaxGuessNumWhenMeeting)); + this.bulletNum = loader.GetValue( + GuesserOption.GuessNum); + this.maxGuessNum = loader.GetValue( + GuesserOption.MaxGuessNumWhenMeeting); this.curGuessNum = 0; this.roleNamePrefix = this.CreateImpCrewPrefix(); diff --git a/ExtremeRoles/Roles/Combination/HeroAcademia.cs b/ExtremeRoles/Roles/Combination/HeroAcademia.cs index 38e9c7023..7d688ab2a 100644 --- a/ExtremeRoles/Roles/Combination/HeroAcademia.cs +++ b/ExtremeRoles/Roles/Combination/HeroAcademia.cs @@ -15,6 +15,11 @@ using ExtremeRoles.Module.ExtremeShipStatus; using ExtremeRoles.Extension.Player; + + + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Combination; @@ -163,7 +168,8 @@ public enum Condition : byte public const string Name = "HeroAca"; public HeroAcademia() : base( - Name, new Color(255f, 255f, 255f), 3, + CombinationRoleType.HeroAca, + Name, DefaultColor, 3, GameSystem.MaxImposterNum) { this.Roles.Add(new Hero()); @@ -276,7 +282,7 @@ public static void UpdateVigilante( int crewNum = 0; int impNum = 0; - foreach (GameData.PlayerInfo player in + foreach (NetworkedPlayerInfo player in GameData.Instance.AllPlayers.GetFastEnumerator()) { var role = ExtremeRoleManager.GameRole[player.PlayerId]; @@ -461,8 +467,8 @@ public void CreateAbility() { this.CreateNormalAbilityButton( "search", - Loader.CreateSpriteFromResources( - Path.HiroAcaSearch), + Resources.Loader.CreateSpriteFromResources( + Path.HiroAcaSearch), abilityOff: CleanUp); this.Button.SetLabelToCrewmate(); } @@ -471,7 +477,7 @@ public bool IsAbilityUse() => this.cond == OneForAllCondition.FeatButtonAbility && IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -659,26 +665,27 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 5.0f); - CreateIntOption( + IRoleAbility.CreateCommonAbilityOption( + factory, 5.0f); + factory.CreateIntOption( HeroOption.FeatKillPercentage, - 33, 20, 50, 1, parentOps, + 33, 20, 50, 1, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( HeroOption.FeatButtonAbilityPercentage, - 66, 50, 80, 1, parentOps, + 66, 50, 80, 1, format: OptionUnit.Percentage); } protected override void RoleSpecificInit() { - this.featKillPer = OptionManager.Instance.GetValue( - GetRoleOptionId(HeroOption.FeatKillPercentage)) / 100.0f; - this.featButtonAbilityPer = OptionManager.Instance.GetValue( - GetRoleOptionId(HeroOption.FeatButtonAbilityPercentage)) / 100.0f; + var loader = this.Loader; + this.featKillPer = loader.GetValue( + HeroOption.FeatKillPercentage) / 100.0f; + this.featButtonAbilityPer = loader.GetValue( + HeroOption.FeatButtonAbilityPercentage) / 100.0f; } private void setButtonActive(bool active) @@ -718,14 +725,14 @@ public void CreateAbility() { this.CreateNormalAbilityButton( "search", - Loader.CreateSpriteFromResources( - Path.HiroAcaSearch), + Resources.Loader.CreateSpriteFromResources( + Path.HiroAcaSearch), abilityOff: CleanUp); } public bool IsAbilityUse() => IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -843,20 +850,20 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 5.0f); - this.CreateFloatOption( + IRoleAbility.CreateCommonAbilityOption( + factory, 5.0f); + factory.CreateFloatOption( VillanOption.VigilanteSeeTime, - 2.5f, 1.0f, 10.0f, 0.5f, parentOps, + 2.5f, 1.0f, 10.0f, 0.5f, format: OptionUnit.Second); } protected override void RoleSpecificInit() { - this.vigilanteArrowTime = OptionManager.Instance.GetValue( - GetRoleOptionId(VillanOption.VigilanteSeeTime)); + this.vigilanteArrowTime = this.Loader.GetValue( + VillanOption.VigilanteSeeTime); this.vigilanteArrowTimer = 0.0f; } @@ -908,8 +915,8 @@ public void CreateAbility() { this.CreateNormalAbilityButton( "call", - Loader.CreateSpriteFromResources( - Path.VigilanteEmergencyCall), + Resources.Loader.CreateSpriteFromResources( + Path.VigilanteEmergencyCall), abilityOff: CleanUp); this.Button.SetLabelToCrewmate(); } @@ -933,7 +940,7 @@ public void CleanUp() } public void ModifiedWinPlayer( - GameData.PlayerInfo rolePlayerInfo, + NetworkedPlayerInfo rolePlayerInfo, GameOverReason reason, ref ExtremeGameResult.WinnerTempData winner) { @@ -969,7 +976,7 @@ GameOverReason.ImpostorDisconnect or } } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -1049,19 +1056,19 @@ public override string GetImportantText(bool isContainFakeTask = true) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 2, 10, 5.0f); - CreateFloatOption( + IRoleAbility.CreateAbilityCountOption( + factory, 2, 10, 5.0f); + factory.CreateFloatOption( VigilanteOption.Range, - 3.0f, 1.2f, 5.0f, 0.1f, parentOps); + 3.0f, 1.2f, 5.0f, 0.1f); } protected override void RoleSpecificInit() { - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(VigilanteOption.Range)); + this.range = this.Loader.GetValue( + VigilanteOption.Range); } public void Update(PlayerControl rolePlayer) diff --git a/ExtremeRoles/Roles/Combination/Kids.cs b/ExtremeRoles/Roles/Combination/Kids.cs index cb2d8b16e..db8017dab 100644 --- a/ExtremeRoles/Roles/Combination/Kids.cs +++ b/ExtremeRoles/Roles/Combination/Kids.cs @@ -23,7 +23,12 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Module.ButtonAutoActivator; -using OptionFactory = ExtremeRoles.Module.CustomOption.Factories.AutoParentSetFactory; + + + +using ExtremeRoles.Module.CustomOption.Factory; + +using OptionFactory = ExtremeRoles.Module.CustomOption.Factory.AutoParentSetOptionCategoryFactory; #nullable enable @@ -34,6 +39,7 @@ public sealed class Kids : GhostAndAliveCombinationRoleManagerBase public const string Name = "Kids"; public Kids() : base( + CombinationRoleType.Kids, Name, ColorPalette.KidsYellowGreen, 2, GameSystem.MaxImposterNum) { @@ -248,10 +254,10 @@ private static void setScibe(PlayerControl player, Delinquent delinquent) GameObject obj = new GameObject("Scribe"); obj.transform.position = player.transform.position; SpriteRenderer rend = obj.AddComponent(); - rend.sprite = Loader.CreateSpriteFromResources( + rend.sprite = Resources.Loader.CreateSpriteFromResources( string.Format( - Path.DelinquentScribe, - RandomGenerator.Instance.Next(0, maxImageNum))); + Path.DelinquentScribe, + RandomGenerator.Instance.Next(0, maxImageNum))); delinquent.abilityCount++; } private static void setBomb(Delinquent delinquent) @@ -275,7 +281,7 @@ public void CreateAbility() AbilityType.Scribe, new ButtonGraphic( Translation.GetString("scribble"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( string.Format( Path.DelinquentScribe, RandomGenerator.Instance.Next(0, maxImageNum)))) @@ -284,21 +290,21 @@ public void CreateAbility() AbilityType.SelfBomb, new ButtonGraphic( Translation.GetString("selfBomb"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.BomberSetBomb)) ), this.IsAbilityUse, this.UseAbility), new RoleButtonActivator(), - KeyCode.F); + KeyCode.F); ((IRoleAbility)(this)).RoleAbilityInit(); if (this.Button?.Behavior is DelinquentAbilityBehavior behavior) { behavior.SetAbilityCount( - OptionManager.Instance.GetValue(GetRoleOptionId( - RoleAbilityCommonOption.AbilityCount))); + this.Loader.GetValue( + RoleAbilityCommonOption.AbilityCount)); } } @@ -322,7 +328,7 @@ public bool IsAbilityUse() }; } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -354,13 +360,12 @@ public bool UseAbility() return true; } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption(parentOps, 7, 20); - CreateFloatOption( + IRoleAbility.CreateAbilityCountOption(factory, 7, 20); + factory.CreateFloatOption( DelinqentOption.Range, - 3.6f, 1.0f, 5.0f, 0.1f, - parentOps); + 3.6f, 1.0f, 5.0f, 0.1f); } protected override void RoleSpecificInit() @@ -369,14 +374,15 @@ protected override void RoleSpecificInit() this.abilityCount = 0; - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(DelinqentOption.Range)); + var loader = this.Loader; + this.range = loader.GetValue( + DelinqentOption.Range); if (this.Button?.Behavior is DelinquentAbilityBehavior behavior) { behavior.SetAbilityCount( - OptionManager.Instance.GetValue(GetRoleOptionId( - RoleAbilityCommonOption.AbilityCount))); + loader.GetValue( + RoleAbilityCommonOption.AbilityCount)); } this.canAssignWisp = true; @@ -384,10 +390,27 @@ protected override void RoleSpecificInit() } -public sealed class Wisp : GhostRoleBase, IGhostRoleWinable +public sealed class Wisp : GhostRoleBase, IGhostRoleWinable, ICombination { + public MultiAssignRoleBase.OptionOffsetInfo? OffsetInfo { get; set; } + public OptionLoadWrapper WrappedCategory + { + get + { + if (OffsetInfo is null || + !OptionManager.Instance.TryGetCategory( + this.Tab, + ExtremeRoleManager.GetCombRoleGroupId(this.OffsetInfo.RoleId), + out var cate)) + { + throw new ArgumentException("Can't find category"); + } + return new OptionLoadWrapper(cate, this.OffsetInfo.IdOffset); + } + } + - public enum WispOption + public enum WispOption { WinNum, TorchAbilityNum, @@ -425,11 +448,11 @@ public void SetAbilityNum(int abilityNum) public bool IsWin( GameOverReason reason, - GameData.PlayerInfo ghostRolePlayer) => this.system != null && this.system.IsWin(this); + NetworkedPlayerInfo ghostRolePlayer) => this.system != null && this.system.IsWin(this); public void SetWinPlayerNum(byte rolePlayerId) { - foreach (GameData.PlayerInfo player in + foreach (NetworkedPlayerInfo player in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (player == null || @@ -461,7 +484,7 @@ public override void CreateAbility() { this.Button = GhostRoleAbilityFactory.CreateCountAbility( AbilityType.WispSetTorch, - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.WispTorch), this.isReportAbility(), () => true, @@ -478,18 +501,19 @@ public override void CreateAbility() public override void Initialize() { - this.abilityNum = OptionManager.Instance.GetValue( - GetRoleOptionId(WispOption.TorchAbilityNum)); - this.winNum = OptionManager.Instance.GetValue( - GetRoleOptionId(WispOption.WinNum)); - this.torchNum = OptionManager.Instance.GetValue( - GetRoleOptionId(WispOption.TorchNum)); - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(WispOption.TorchRange)); - this.torchActiveTime = OptionManager.Instance.GetValue( - GetRoleOptionId(WispOption.TorchActiveTime)); - this.torchBlackOutTime = OptionManager.Instance.GetValue( - GetRoleOptionId(WispOption.BlackOutTime)); + var loader = this.WrappedCategory; + this.abilityNum = loader.GetValue( + WispOption.TorchAbilityNum); + this.winNum = loader.GetValue( + WispOption.WinNum); + this.torchNum = loader.GetValue( + WispOption.TorchNum); + this.range = loader.GetValue( + WispOption.TorchRange); + this.torchActiveTime = loader.GetValue( + WispOption.TorchActiveTime); + this.torchBlackOutTime = loader.GetValue( + WispOption.BlackOutTime); } protected override void OnMeetingEndHook() diff --git a/ExtremeRoles/Roles/Combination/Lover.cs b/ExtremeRoles/Roles/Combination/Lover.cs index 4c542debd..8308158a3 100644 --- a/ExtremeRoles/Roles/Combination/Lover.cs +++ b/ExtremeRoles/Roles/Combination/Lover.cs @@ -9,13 +9,21 @@ using ExtremeRoles.Performance; using ExtremeRoles.Extension.Player; + + using AmongUs.GameOptions; + +using ExtremeRoles.Module.CustomOption.Interfaces; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class LoverManager : FlexibleCombinationRoleManagerBase { - public LoverManager() : base(new Lover()) + public LoverManager() : base( + CombinationRoleType.Lover, + new Lover()) { } } @@ -222,46 +230,42 @@ public void ChangeAllLoverToNeutral() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - var neutralSetting = CreateBoolOption( + var neutralSetting = factory.CreateBoolOption( LoverOption.IsNeutral, - false, parentOps); + false); - var killerSetting = CreateBoolOption( + var killerSetting = factory.CreateBoolOption( LoverOption.BecomNeutral, false, neutralSetting); - var deathSetting = CreateIntDynamicOption( + var deathSetting = factory.CreateIntDynamicOption( LoverOption.DethWhenUnderAlive, 1, 1, 1, killerSetting, invert: true, - enableCheckOption: parentOps, tempMaxValue: GameSystem.VanillaMaxPlayerNum - 1); - CreateKillerOption(killerSetting); - killerVisionSetting(killerSetting); + CreateKillerOption(factory, killerSetting); + killerVisionSetting(factory, killerSetting); - CreateBoolOption( + factory.CreateBoolOption( LoverOption.BecomeNeutralLoverCanUseVent, false, killerSetting); - OptionManager.Instance.Get( - GetManagerOptionId( - CombinationRoleCommonOption.AssignsNum) - ).SetUpdateOption(deathSetting); - + factory.Get((int)CombinationRoleCommonOption.AssignsNum) + .AddWithUpdate(deathSetting); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; + var loader = this.Loader; - bool isNeutral = allOption.GetValue( - GetRoleOptionId(LoverOption.IsNeutral)); + bool isNeutral = loader.GetValue( + LoverOption.IsNeutral); - this.becomeKiller = allOption.GetValue( - GetRoleOptionId(LoverOption.BecomNeutral)) && isNeutral; + this.becomeKiller = isNeutral && loader.GetValue( + LoverOption.BecomNeutral); if (isNeutral && !this.becomeKiller) { @@ -271,39 +275,39 @@ protected override void RoleSpecificInit() { var baseOption = GameOptionsManager.Instance.CurrentGameOptions; - this.HasOtherKillCool = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.HasOtherKillCool)); + this.HasOtherKillCool = loader.GetValue( + KillerCommonOption.HasOtherKillCool); if (this.HasOtherKillCool) { - this.KillCoolTime = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.KillCoolDown)); + this.KillCoolTime = loader.GetValue( + KillerCommonOption.KillCoolDown); } else { this.KillCoolTime = baseOption.GetFloat(FloatOptionNames.KillCooldown); } - this.HasOtherKillRange = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.HasOtherKillRange)); + this.HasOtherKillRange = loader.GetValue( + KillerCommonOption.HasOtherKillRange); if (this.HasOtherKillRange) { - this.KillRange = allOption.GetValue( - GetRoleOptionId(KillerCommonOption.KillRange)); + this.KillRange = loader.GetValue( + KillerCommonOption.KillRange); } else { this.KillRange = baseOption.GetInt(Int32OptionNames.KillDistance); } - this.killerLoverHasOtherVision = allOption.GetValue( - GetRoleOptionId(LoverOption.BecomeNeutralLoverHasOtherVision)); + this.killerLoverHasOtherVision = loader.GetValue( + LoverOption.BecomeNeutralLoverHasOtherVision); if (this.killerLoverHasOtherVision) { - this.killerLoverVision = allOption.GetValue( - GetRoleOptionId(LoverOption.BecomeNeutralLoverVision)); - this.killerLoverIsApplyEnvironmentVisionEffect = allOption.GetValue( - GetRoleOptionId(LoverOption.BecomeNeutralLoverApplyEnvironmentVisionEffect)); + this.killerLoverVision = loader.GetValue( + LoverOption.BecomeNeutralLoverVision); + this.killerLoverIsApplyEnvironmentVisionEffect = loader.GetValue( + LoverOption.BecomeNeutralLoverApplyEnvironmentVisionEffect); } else { @@ -311,26 +315,27 @@ protected override void RoleSpecificInit() this.killerLoverIsApplyEnvironmentVisionEffect = this.IsApplyEnvironmentVision; } - this.killerLoverCanUseVent = allOption.GetValue( - GetRoleOptionId(LoverOption.BecomeNeutralLoverCanUseVent)); + this.killerLoverCanUseVent = loader.GetValue( + LoverOption.BecomeNeutralLoverCanUseVent); } - this.limit = allOption.GetValue( - GetRoleOptionId(LoverOption.DethWhenUnderAlive)); + this.limit = loader.GetValue( + LoverOption.DethWhenUnderAlive); } private void killerVisionSetting( - IOptionInfo killerOpt) + AutoParentSetOptionCategoryFactory factory, + IOption killerOpt) { - var visionOption = CreateBoolOption( + var visionOption = factory.CreateBoolOption( LoverOption.BecomeNeutralLoverHasOtherVision, false, killerOpt); - CreateFloatOption(LoverOption.BecomeNeutralLoverVision, + factory.CreateFloatOption(LoverOption.BecomeNeutralLoverVision, 2f, 0.25f, 5.0f, 0.25f, visionOption, format: OptionUnit.Multiplier); - CreateBoolOption( + factory.CreateBoolOption( LoverOption.BecomeNeutralLoverApplyEnvironmentVisionEffect, false, visionOption); } diff --git a/ExtremeRoles/Roles/Combination/Mover.cs b/ExtremeRoles/Roles/Combination/Mover.cs index 13dafd768..e80d625dc 100644 --- a/ExtremeRoles/Roles/Combination/Mover.cs +++ b/ExtremeRoles/Roles/Combination/Mover.cs @@ -11,13 +11,20 @@ using ExtremeRoles.Performance; using ExtremeRoles.Compat; + + using UnityHelper = ExtremeRoles.Helper.Unity; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class MoverManager : FlexibleCombinationRoleManagerBase { - public MoverManager() : base(new Mover(), 1) + public MoverManager() : base( + CombinationRoleType.Mover, + new Mover(), 1) { } } @@ -171,9 +178,9 @@ private static void removeConsole(Mover mover, PlayerControl player) public void CreateAbility() { this.CreateReclickableCountAbilityButton( - Translation.GetString("Moving"), - Loader.CreateSpriteFromResources( - Path.MoverMove), + Translation.GetString("Moving"), + Resources.Loader.CreateSpriteFromResources( + Path.MoverMove), checkAbility: IsAbilityActive, abilityOff: this.CleanUp); if (this.IsCrewmate()) @@ -200,7 +207,7 @@ public bool IsAbilityUse() GameSystem.IsValidConsole(localPlayer, this.targetConsole); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -256,15 +263,13 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - var imposterSetting = OptionManager.Instance.Get( - GetManagerOptionId(CombinationRoleCommonOption.IsAssignImposter)); - - CreateKillerOption(imposterSetting); + var imposterSetting = factory.Get((int)CombinationRoleCommonOption.IsAssignImposter); + CreateKillerOption(factory, imposterSetting); - this.CreateAbilityCountOption( - parentOps, 3, 10, 30.0f); + IRoleAbility.CreateAbilityCountOption( + factory, 3, 10, 30.0f); } protected override void RoleSpecificInit() diff --git a/ExtremeRoles/Roles/Combination/Sharer.cs b/ExtremeRoles/Roles/Combination/Sharer.cs index 10bbf1c2c..bdae61ae2 100644 --- a/ExtremeRoles/Roles/Combination/Sharer.cs +++ b/ExtremeRoles/Roles/Combination/Sharer.cs @@ -4,16 +4,20 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class SharerManager : FlexibleCombinationRoleManagerBase { public SharerManager() : base( + CombinationRoleType.Sharer, new Sharer(), 2, false) { } @@ -121,7 +125,7 @@ public void Update( } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { if (this.sameSharer != null) { @@ -244,18 +248,18 @@ public override bool IsSameTeam(SingleRoleBase targetRole) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( SharerOption.SharerTellKill, - true, parentOps); + true); } protected override void RoleSpecificInit() { - this.sharerTellKill = OptionManager.Instance.GetValue( - GetRoleOptionId(SharerOption.SharerTellKill)); + this.sharerTellKill = this.Loader.GetValue( + SharerOption.SharerTellKill); if (this.sharerTellKill) { diff --git a/ExtremeRoles/Roles/Combination/Skater.cs b/ExtremeRoles/Roles/Combination/Skater.cs index 2a931b535..0d1943609 100644 --- a/ExtremeRoles/Roles/Combination/Skater.cs +++ b/ExtremeRoles/Roles/Combination/Skater.cs @@ -5,11 +5,17 @@ using ExtremeRoles.Performance; using ExtremeRoles.Resources; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class SkaterManager : FlexibleCombinationRoleManagerBase { - public SkaterManager() : base(new Skater(), 1) + public SkaterManager() : base( + CombinationRoleType.Skater, new Skater(), 1) { } } @@ -61,52 +67,46 @@ public Skater( {} protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - var imposterSetting = OptionManager.Instance.Get( - GetManagerOptionId(CombinationRoleCommonOption.IsAssignImposter)); - CreateKillerOption(imposterSetting); + var imposterSetting = factory.Get((int)CombinationRoleCommonOption.IsAssignImposter); + CreateKillerOption(factory, imposterSetting); - this.CreateAbilityCountOption(parentOps, 3, 50, 5.0f); + IRoleAbility.CreateAbilityCountOption(factory, 3, 50, 5.0f); - CreateFloatOption( + factory.CreateFloatOption( Option.Acceleration, - 1.25f, 0.05f, 2.0f, 0.05f, - parentOps); - CreateIntOption( + 1.25f, 0.05f, 2.0f, 0.05f); + factory.CreateIntOption( Option.MaxSpeed, - 10, 5, 50, 1, - parentOps); - CreateFloatOption( + 10, 5, 50, 1); + factory.CreateFloatOption( Option.Friction, - 0.25f, -1.0f, 1.0f, 0.01f, - parentOps); - var eOpt = CreateBoolOption( - Option.UseE, true, parentOps); - CreateFloatOption( + 0.25f, -1.0f, 1.0f, 0.01f); + var eOpt = factory.CreateBoolOption( + Option.UseE, true); + factory.CreateFloatOption( Option.EValue, 0.9f, 0.0f, 2.0f, 0.01f, eOpt, - invert: true, - enableCheckOption: parentOps); - CreateFloatOption( + invert: true); + factory.CreateFloatOption( Option.CanUseSpeed, - 2.0f, 0.0f, 50.0f, 0.1f, - parentOps); + 2.0f, 0.0f, 50.0f, 0.1f); } protected override void RoleSpecificInit() { this.roleNamePrefix = this.CreateImpCrewPrefix(); - var opt = OptionManager.Instance; + var loader = this.Loader; this.param = new SkaterSkateBehaviour.Parameter( - opt.GetValue(this.GetRoleOptionId(Option.Friction)), - opt.GetValue(this.GetRoleOptionId(Option.Acceleration)), - opt.GetValue(this.GetRoleOptionId(Option.MaxSpeed)), - opt.GetValue(this.GetRoleOptionId(Option.UseE)) ? opt.GetValue(this.GetRoleOptionId(Option.EValue)) : null); + loader.GetValue(Option.Friction), + loader.GetValue(Option.Acceleration), + loader.GetValue(Option.MaxSpeed), + loader.GetValue(Option.UseE) ? loader.GetValue(Option.EValue) : null); this.canUseSpeed = - opt.GetValue(this.GetRoleOptionId(Option.CanUseSpeed)) * + loader.GetValue(Option.CanUseSpeed) * SkaterSkateBehaviour.SpeedOffset; } @@ -137,9 +137,9 @@ public void CreateAbility() { this.CreatePassiveAbilityButton( "SkaterSkateOn", "SkaterSkateOff", - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.SkaterSkateOn), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.SkaterSkateOff), this.CleanUp); @@ -154,7 +154,7 @@ public void CleanUp() this.setBehaviourEnable(false); } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { } public void ResetOnMeetingStart() diff --git a/ExtremeRoles/Roles/Combination/Supporter.cs b/ExtremeRoles/Roles/Combination/Supporter.cs index 4d8c8bd59..d7832da6f 100644 --- a/ExtremeRoles/Roles/Combination/Supporter.cs +++ b/ExtremeRoles/Roles/Combination/Supporter.cs @@ -7,13 +7,18 @@ using ExtremeRoles.Module; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; -using ExtremeRoles.Module.CustomOption; + + + +using ExtremeRoles.Module.CustomOption.Factory; namespace ExtremeRoles.Roles.Combination; public sealed class SupporterManager : FlexibleCombinationRoleManagerBase { - public SupporterManager() : base(new Supporter(), 1) + public SupporterManager() : base( + CombinationRoleType.Supporter, + new Supporter(), 1) { } } @@ -151,14 +156,11 @@ public override string GetIntroDescription() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - var imposterSetting = OptionManager.Instance.Get( - GetManagerOptionId(CombinationRoleCommonOption.IsAssignImposter)); - - CreateKillerOption(imposterSetting); - - } + var imposterSetting = factory.Get((int)CombinationRoleCommonOption.IsAssignImposter); + CreateKillerOption(factory, imposterSetting); + } protected override void RoleSpecificInit() { diff --git a/ExtremeRoles/Roles/Combination/Traitor.cs b/ExtremeRoles/Roles/Combination/Traitor.cs index b79b19aee..cb3ddced5 100644 --- a/ExtremeRoles/Roles/Combination/Traitor.cs +++ b/ExtremeRoles/Roles/Combination/Traitor.cs @@ -9,11 +9,19 @@ using ExtremeRoles.Roles.API.Extension.Neutral; using ExtremeRoles.Performance; + + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Combination; public sealed class TraitorManager : FlexibleCombinationRoleManagerBase { - public TraitorManager() : base(new Traitor(), 1, false) + public TraitorManager() : base( + CombinationRoleType.Traitor, + new Traitor(), 1, false) { } public override void AssignSetUpInit(int curImpNum) @@ -41,18 +49,21 @@ protected override void CommonInit() { this.Roles.Clear(); int roleAssignNum = 1; - var allOptions = OptionManager.Instance; + var loader = this.Loader; this.BaseRole.CanHasAnotherRole = true; // 0:オフ、1:オン - allOptions.Get(GetRoleOptionId( - CombinationRoleCommonOption.IsMultiAssign)).UpdateSelection(1); - - if (allOptions.Contains(GetRoleOptionId(CombinationRoleCommonOption.AssignsNum))) + if (loader.TryGetValueOption( + CombinationRoleCommonOption.IsMultiAssign, out var option)) + { + option.Selection = 1; + } + + if (loader.TryGetValueOption( + CombinationRoleCommonOption.AssignsNum, out var o)) { - roleAssignNum = allOptions.GetValue( - GetRoleOptionId(CombinationRoleCommonOption.AssignsNum)); + roleAssignNum = o.Value; } for (int i = 0; i < roleAssignNum; ++i) @@ -262,7 +273,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -364,10 +375,10 @@ public override string GetFullDescription() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 5.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 5.0f); } protected override void RoleSpecificInit() diff --git a/ExtremeRoles/Roles/ExtremeRoleManager.cs b/ExtremeRoles/Roles/ExtremeRoleManager.cs index 5a9965240..7443f7312 100644 --- a/ExtremeRoles/Roles/ExtremeRoleManager.cs +++ b/ExtremeRoles/Roles/ExtremeRoleManager.cs @@ -206,7 +206,7 @@ public enum NeutralSeparateTeam public static class ExtremeRoleManager { - public const int OptionOffsetPerRole = 75; + public const int OptionOffsetPerRole = 200; public static readonly IReadOnlySet SpecialWinCheckRole = new HashSet() { @@ -328,40 +328,29 @@ public enum ReplaceOperation : byte CreateServant, } - public static void CreateCombinationRoleOptions( - int optionIdOffsetChord) - { + private const int roleIdOffset = 200; - if (CombRole.Count == 0) { return; }; + public static int GetRoleGroupId(ExtremeRoleId roleId) + => roleIdOffset + (int)roleId; - IEnumerable roles = CombRole.Values; + private const int conbRoleIdOffset = 1000; - int roleOptionOffset = optionIdOffsetChord; + public static int GetCombRoleGroupId(CombinationRoleType roleId) + => conbRoleIdOffset + (int)roleId; - foreach (var item - in roles.Select((Value, Index) => new { Value, Index })) + public static void CreateCombinationRoleOptions() + { + foreach (var role in CombRole.Values) { - roleOptionOffset = roleOptionOffset + ( - OptionOffsetPerRole * (item.Index + item.Value.Roles.Count + 1)); - item.Value.CreateRoleAllOption(roleOptionOffset); + role.CreateRoleAllOption(); } } - public static void CreateNormalRoleOptions( - int optionIdOffsetChord) + public static void CreateNormalRoleOptions() { - - if (NormalRole.Count == 0) { return; }; - - IEnumerable roles = NormalRole.Values; - - int roleOptionOffset = 0; - - foreach (var item in roles.Select( - (Value, Index) => new { Value, Index })) + foreach (var role in NormalRole.Values) { - roleOptionOffset = optionIdOffsetChord + (OptionOffsetPerRole * item.Index); - item.Value.CreateRoleAllOption(roleOptionOffset); + role.CreateRoleAllOption(); } } @@ -402,7 +391,7 @@ public static bool IsDisableWinCheckRole(SingleRoleBase role) } } public static bool IsAliveWinNeutral( - SingleRoleBase role, GameData.PlayerInfo playerInfo) + SingleRoleBase role, NetworkedPlayerInfo playerInfo) => role.Id switch { ExtremeRoleId.Neet => !(playerInfo.IsDead || playerInfo.Disconnected), @@ -423,18 +412,16 @@ public static void SetPlayerIdToMultiRoleId( { RoleTypes roleType = (RoleTypes)bytedRoleType; - bool hasVanilaRole = false; - - switch (roleType) - { - case RoleTypes.Scientist: - case RoleTypes.Engineer: - case RoleTypes.Shapeshifter: - hasVanilaRole = true; - break; - default: - break; - } + bool hasVanilaRole = roleType switch + { + RoleTypes.Scientist or + RoleTypes.Scientist or + RoleTypes.Shapeshifter or + RoleTypes.Noisemaker or + RoleTypes.Phantom or + RoleTypes.Tracker => true, + _ => false + }; var role = CombRole[combType].GetRole(roleId, roleType); diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Agency.cs b/ExtremeRoles/Roles/Solo/Crewmate/Agency.cs index 572eef2cf..42b81935b 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Agency.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Agency.cs @@ -10,6 +10,11 @@ using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Agency : SingleRoleBase, IRoleAutoBuildAbility, IRoleUpdate @@ -79,18 +84,16 @@ public static void TakeTargetPlayerTask( Sound.PlaySound( Sound.Type.AgencyTakeTask, 1.2f); } - - GameData.Instance.SetDirtyBit( - 1U << (int)targetPlayer.PlayerId); - } + targetPlayer.Data.MarkDirty(); + } public void CreateAbility() { this.CreateAbilityCountButton( "takeTask", - Loader.CreateSpriteFromResources( - Path.AgencyTakeTask)); + Resources.Loader.CreateSpriteFromResources( + Path.AgencyTakeTask)); this.Button.SetLabelToCrewmate(); } @@ -125,7 +128,7 @@ public bool UseAbility() byte playerId = PlayerControl.LocalPlayer.PlayerId; - GameData.PlayerInfo targetPlayerInfo = GameData.Instance.GetPlayerById( + NetworkedPlayerInfo targetPlayerInfo = GameData.Instance.GetPlayerById( this.TargetPlayer); var shuffleTaskIndex = Enumerable.Range( @@ -202,7 +205,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -230,7 +233,7 @@ public void Update(PlayerControl rolePlayer) switch (taskType) { case TakeTaskType.Normal: - taskIndex = GameSystem.GetRandomNormalTaskId(); + taskIndex = GameSystem.GetRandomShortTaskId(); break; case TakeTaskType.Long: taskIndex = GameSystem.GetRandomLongTask(); @@ -250,31 +253,32 @@ public void Update(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( AgencyOption.CanSeeTaskBar, - true, parentOps); - CreateIntOption( + true); + factory.CreateIntOption( AgencyOption.MaxTaskNum, - 2, 1, 3, 1, parentOps); - CreateFloatOption( + 2, 1, 3, 1); + factory.CreateFloatOption( AgencyOption.TakeTaskRange, - 1.0f, 0.5f, 2.0f, 0.1f, - parentOps); + 1.0f, 0.5f, 2.0f, 0.1f); - this.CreateAbilityCountOption( - parentOps, 2, 5); + IRoleAbility.CreateAbilityCountOption( + factory, 2, 5); } protected override void RoleSpecificInit() { - this.CanSeeTaskBar = OptionManager.Instance.GetValue( - GetRoleOptionId(AgencyOption.CanSeeTaskBar)); - this.maxTakeTask = OptionManager.Instance.GetValue( - GetRoleOptionId(AgencyOption.MaxTaskNum)) + 1; - this.takeTaskRange = OptionManager.Instance.GetValue( - GetRoleOptionId(AgencyOption.TakeTaskRange)); + var loader = this.Loader; + + this.CanSeeTaskBar = loader.GetValue( + AgencyOption.CanSeeTaskBar); + this.maxTakeTask = loader.GetValue( + AgencyOption.MaxTaskNum) + 1; + this.takeTaskRange = loader.GetValue( + AgencyOption.TakeTaskRange); this.TakeTask = new List(); diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Bait.cs b/ExtremeRoles/Roles/Solo/Crewmate/Bait.cs index 4109dbccf..263a485ac 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Bait.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Bait.cs @@ -12,6 +12,11 @@ using ExtremeRoles.Roles.API.Extension.State; using ExtremeRoles.Extension.Il2Cpp; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Bait : SingleRoleBase, IRoleAwake @@ -176,44 +181,43 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( Option.AwakeTaskGage, 70, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( Option.DelayUntilForceReport, 5.0f, 0.0f, 30.0f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateBoolOption( + format: OptionUnit.Second); + factory.CreateBoolOption( Option.EnableBaitBenefit, - true, parentOps); - CreateFloatOption( + true); + factory.CreateFloatOption( Option.KillCoolReduceMulti, - 2.0f, 1.1f, 5.0f, 0.1f, parentOps, + 2.0f, 1.1f, 5.0f, 0.1f, format: OptionUnit.Multiplier); - CreateFloatOption( + factory.CreateFloatOption( Option.ReduceTimer, - 5.0f, 1.0f, 30.0f, 0.5f, parentOps, + 5.0f, 1.0f, 30.0f, 0.5f, format: OptionUnit.Second); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; - - this.awakeTaskGage = allOpt.GetValue( - GetRoleOptionId(Option.AwakeTaskGage)) / 100.0f; - this.delayUntilForceReport = allOpt.GetValue( - GetRoleOptionId(Option.DelayUntilForceReport)); - this.enableBaitBenefit = allOpt.GetValue( - GetRoleOptionId(Option.EnableBaitBenefit)); - this.killCoolReduceMulti = allOpt.GetValue( - GetRoleOptionId(Option.KillCoolReduceMulti)) - 1.0f; - this.timer = allOpt.GetValue( - GetRoleOptionId(Option.ReduceTimer)); + var loader = this.Loader; + + this.awakeTaskGage = loader.GetValue( + Option.AwakeTaskGage) / 100.0f; + this.delayUntilForceReport = loader.GetValue( + Option.DelayUntilForceReport); + this.enableBaitBenefit = loader.GetValue( + Option.EnableBaitBenefit); + this.killCoolReduceMulti = loader.GetValue( + Option.KillCoolReduceMulti) - 1.0f; + this.timer = loader.GetValue( + Option.ReduceTimer); this.awakeHasOtherVision = this.HasOtherVision; diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Bakary.cs b/ExtremeRoles/Roles/Solo/Crewmate/Bakary.cs index 114a30d6a..f8d044930 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Bakary.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Bakary.cs @@ -1,9 +1,12 @@ using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Module.SystemType; using ExtremeRoles.Module.SystemType.Roles; using ExtremeRoles.Roles.API; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Bakary : SingleRoleBase @@ -24,36 +27,36 @@ public Bakary() : base( { } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - var changeCooking = CreateBoolOption( + var changeCooking = factory.CreateBoolOption( BakaryOption.ChangeCooking, - true, parentOps); + true); - CreateFloatOption( + factory.CreateFloatOption( BakaryOption.GoodBakeTime, 60.0f, 45.0f, 75.0f, 0.5f, changeCooking, format: OptionUnit.Second, - invert: true, enableCheckOption: parentOps); - CreateFloatOption( + invert: true); + factory.CreateFloatOption( BakaryOption.BadBakeTime, 120.0f, 105.0f, 135.0f, 0.5f, changeCooking, format: OptionUnit.Second, - invert: true, enableCheckOption: parentOps); + invert: true); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var loader = this.Loader; ExtremeSystemTypeManager.Instance.TryAdd( ExtremeSystemType.BakeryReport, new BakerySystem( - allOpt.GetValue( - GetRoleOptionId(BakaryOption.GoodBakeTime)), - allOpt.GetValue( - GetRoleOptionId(BakaryOption.BadBakeTime)), - allOpt.GetValue( - GetRoleOptionId(BakaryOption.ChangeCooking)))); + loader.GetValue( + BakaryOption.GoodBakeTime), + loader.GetValue( + BakaryOption.BadBakeTime), + loader.GetValue( + BakaryOption.ChangeCooking))); } } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/BodyGuard.cs b/ExtremeRoles/Roles/Solo/Crewmate/BodyGuard.cs index 1cbc9aa30..a7dcc8776 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/BodyGuard.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/BodyGuard.cs @@ -17,8 +17,13 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable + + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class BodyGuard : @@ -485,9 +490,8 @@ public override void RolePlayerKilledAction( public void CreateAbility() { - - this.shildButtonImage = Loader.CreateSpriteFromResources( - Path.BodyGuardShield); + this.shildButtonImage = Resources.Loader.CreateSpriteFromResources( + Path.BodyGuardShield); this.Button = new ExtremeAbilityButton( new BodyGuardAbilityBehavior( @@ -500,21 +504,21 @@ public void CreateAbility() BodyGuardAbilityMode.Reset, new ButtonGraphic( Translation.GetString("resetShield"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.BodyGuardResetShield))), featShield: UseAbility, resetShield: Reset, canUse: IsAbilityUse, resetModeCheck: IsResetMode), new RoleButtonActivator(), - KeyCode.F); + KeyCode.F); ((IRoleAbility)(this)).RoleAbilityInit(); if (this.Button.Behavior is BodyGuardAbilityBehavior behavior) { - int abilityNum = OptionManager.Instance.GetValue(GetRoleOptionId( - RoleAbilityCommonOption.AbilityCount)); + int abilityNum = this.Loader.GetValue( + RoleAbilityCommonOption.AbilityCount); this.shildNum = abilityNum; behavior.SetAbilityCount(abilityNum); @@ -597,7 +601,7 @@ public bool IsAbilityUse() public void ResetOnMeetingStart() { } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { } public bool IsBlockMeetingButtonAbility(PlayerVoteArea instance) @@ -724,62 +728,54 @@ public void Update(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( BodyGuardOption.ShieldRange, - 1.0f, 0.0f, 2.0f, 0.1f, - parentOps); + 1.0f, 0.0f, 2.0f, 0.1f); - this.CreateAbilityCountOption( - parentOps, 2, 5); + IRoleAbility.CreateAbilityCountOption( + factory, 2, 5); - CreateIntOption( + factory.CreateIntOption( BodyGuardOption.FeatMeetingAbilityTaskGage, 30, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( BodyGuardOption.FeatMeetingReportTaskGage, 60, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - var reportPlayerNameOpt = CreateBoolOption( + var reportPlayerNameOpt = factory.CreateBoolOption( BodyGuardOption.IsReportPlayerName, - false, parentOps); - CreateSelectionOption( + false); + factory.CreateSelectionOption( BodyGuardOption.ReportPlayerMode, - new string[] - { - BodyGuardReportPlayerNameMode.GuardedPlayerNameOnly.ToString(), - BodyGuardReportPlayerNameMode.BodyGuardPlayerNameOnly.ToString(), - BodyGuardReportPlayerNameMode.BothPlayerName.ToString(), - }, reportPlayerNameOpt); - CreateBoolOption( + reportPlayerNameOpt); + factory.CreateBoolOption( BodyGuardOption.IsBlockMeetingKill, - true, parentOps); + true); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var loader = this.Loader; - IsBlockMeetingKill = allOpt.GetValue( - GetRoleOptionId(BodyGuardOption.IsBlockMeetingKill)); + IsBlockMeetingKill = loader.GetValue( + BodyGuardOption.IsBlockMeetingKill); - this.shieldRange = allOpt.GetValue( - GetRoleOptionId(BodyGuardOption.ShieldRange)); + this.shieldRange = loader.GetValue( + BodyGuardOption.ShieldRange); - this.meetingAbilityTaskGage = allOpt.GetValue( - GetRoleOptionId(BodyGuardOption.FeatMeetingAbilityTaskGage)) / 100.0f; - this.meetingReportTaskGage = allOpt.GetValue( - GetRoleOptionId(BodyGuardOption.FeatMeetingReportTaskGage)) / 100.0f; + this.meetingAbilityTaskGage = loader.GetValue( + BodyGuardOption.FeatMeetingAbilityTaskGage) / 100.0f; + this.meetingReportTaskGage = loader.GetValue( + BodyGuardOption.FeatMeetingReportTaskGage) / 100.0f; - this.isReportWithPlayerName = allOpt.GetValue( - GetRoleOptionId(BodyGuardOption.IsReportPlayerName)); - this.reportMode = (BodyGuardReportPlayerNameMode)allOpt.GetValue( - GetRoleOptionId(BodyGuardOption.ReportPlayerMode)); + this.isReportWithPlayerName = loader.GetValue( + BodyGuardOption.IsReportPlayerName); + this.reportMode = (BodyGuardReportPlayerNameMode)loader.GetValue( + BodyGuardOption.ReportPlayerMode); this.awakeMeetingAbility = this.meetingAbilityTaskGage <= 0.0f; this.awakeMeetingReport = this.meetingReportTaskGage <= 0.0f; diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Captain.cs b/ExtremeRoles/Roles/Solo/Crewmate/Captain.cs index d4c0b900b..c4311a7b5 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Captain.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Captain.cs @@ -11,12 +11,17 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; -public sealed class Captain : - SingleRoleBase, - IRoleAwake, - IRoleMeetingButtonAbility, +public sealed class Captain : + SingleRoleBase, + IRoleAwake, + IRoleMeetingButtonAbility, IRoleVoteModifier { public enum CaptainOption @@ -111,7 +116,7 @@ public void ModifiedVote( // スキップ => チャージ if (voteFor == 252 || voteFor == 253 || - voteFor == 254 || + voteFor == 254 || voteFor == byte.MaxValue) { using (var caller = RPCOperator.CreateCaller( @@ -140,12 +145,12 @@ public void ModifiedVote( } public void ModifiedVoteAnime( MeetingHud instance, - GameData.PlayerInfo rolePlayer, + NetworkedPlayerInfo rolePlayer, ref Dictionary voteIndex) { PlayerVoteArea pva = instance.playerStates.FirstOrDefault( x => x.TargetPlayerId == this.voteTarget); - + if (pva == null) { return; } if (!voteIndex.TryGetValue(pva.TargetPlayerId, out int startIndex)) @@ -227,7 +232,7 @@ void setTarget() public string GetFakeOptionString() => ""; - public bool IsBlockMeetingButtonAbility(PlayerVoteArea instance) => + public bool IsBlockMeetingButtonAbility(PlayerVoteArea instance) => instance.TargetPlayerId == 253 || isNotUseSpecialVote(); public void SetSprite(SpriteRenderer render) @@ -338,36 +343,33 @@ public override Color GetNameColor(bool isTruthColor = false) } } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( CaptainOption.AwakeTaskGage, 70, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( CaptainOption.ChargeVoteWhenSkip, 0.7f, 0.1f, 100.0f, 0.1f, - parentOps, format: OptionUnit.VoteNum); - CreateFloatOption( + factory.CreateFloatOption( CaptainOption.AwakedDefaultVoteNum, 0.0f, 0.0f, 100.0f, 0.1f, - parentOps, format: OptionUnit.VoteNum); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var loader = this.Loader; - this.chargeVoteNum = allOpt.GetValue( - GetRoleOptionId(CaptainOption.ChargeVoteWhenSkip)); - this.defaultVote = allOpt.GetValue( - GetRoleOptionId(CaptainOption.AwakedDefaultVoteNum)); - this.awakeTaskGage = allOpt.GetValue( - GetRoleOptionId(CaptainOption.AwakeTaskGage)) / 100.0f; + this.chargeVoteNum = loader.GetValue( + CaptainOption.ChargeVoteWhenSkip); + this.defaultVote = loader.GetValue( + CaptainOption.AwakedDefaultVoteNum); + this.awakeTaskGage = loader.GetValue( + CaptainOption.AwakeTaskGage) / 100.0f; this.awakeHasOtherVision = this.HasOtherVision; this.curChargedVote = this.defaultVote; diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Carpenter.cs b/ExtremeRoles/Roles/Solo/Crewmate/Carpenter.cs index e2ba861de..8fcf614d2 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Carpenter.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Carpenter.cs @@ -18,6 +18,10 @@ using ExtremeRoles.Compat; using ExtremeRoles.Extension.VentModule; + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Carpenter : SingleRoleBase, IRoleAbility, IRoleAwake @@ -498,7 +502,7 @@ public void Update(PlayerControl rolePlayer) public void CreateAbility() { - var allOpt = OptionManager.Instance; + var loader = this.Loader; this.Button = new ExtremeAbilityButton( new CarpenterAbilityBehavior( @@ -506,31 +510,31 @@ public void CreateAbility() mode: CarpenterAbilityMode.RemoveVent, graphic: new ( Translation.GetString("ventSeal"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.CarpenterVentSeal)), - time: allOpt.GetValue( - GetRoleOptionId(CarpenterOption.RemoveVentStopTime)) + time: loader.GetValue( + CarpenterOption.RemoveVentStopTime) ), cameraMode: new( mode: CarpenterAbilityMode.SetCamera, graphic: new( Translation.GetString("cameraSet"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.CarpenterSetCamera)), - time: allOpt.GetValue( - GetRoleOptionId(CarpenterOption.SetCameraStopTime)) + time: loader.GetValue( + CarpenterOption.SetCameraStopTime) ), - ventRemoveScrewNum: allOpt.GetValue( - GetRoleOptionId(CarpenterOption.RemoveVentScrew)), - cameraSetScrewNum: allOpt.GetValue( - GetRoleOptionId(CarpenterOption.SetCameraScrew)), + ventRemoveScrewNum: loader.GetValue( + CarpenterOption.RemoveVentScrew), + cameraSetScrewNum: loader.GetValue( + CarpenterOption.SetCameraScrew), setCountStart: UseAbility, canUse: IsAbilityUse, abilityCheck: IsAbilityCheck, updateMapObj: CleanUp, ventRemoveModeCheck: IsVentMode), new RoleButtonActivator(), - KeyCode.F); + KeyCode.F); this.RoleAbilityInit(); this.Button.SetLabelToCrewmate(); @@ -647,7 +651,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.targetVent = null; } @@ -720,21 +724,20 @@ public override Color GetNameColor(bool isTruthColor = false) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( CarpenterOption.AwakeTaskGage, 70, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - createAbilityOption(parentOps); + createAbilityOption(factory); } protected override void RoleSpecificInit() { this.targetVent = null; - this.awakeTaskGage = OptionManager.Instance.GetValue( - GetRoleOptionId(CarpenterOption.AwakeTaskGage)) / 100.0f; + this.awakeTaskGage = this.Loader.GetValue( + CarpenterOption.AwakeTaskGage) / 100.0f; this.awakeHasOtherVision = this.HasOtherVision; @@ -750,50 +753,46 @@ protected override void RoleSpecificInit() } } - private void createAbilityOption(IOptionInfo parentOps) + private void createAbilityOption(AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( RoleAbilityCommonOption.AbilityCoolTime, 15.0f, 2.0f, 60.0f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateIntOption( + format: OptionUnit.Second); + factory.CreateIntOption( RoleAbilityCommonOption.AbilityCount, 15, 5, 100, 1, - parentOps, format: OptionUnit.Shot); - CreateIntOption( + format: OptionUnit.ScrewNum); + factory.CreateIntOption( CarpenterOption.RemoveVentScrew, 10, 1, 20, 1, - parentOps, format: OptionUnit.ScrewNum); - CreateFloatOption( + format: OptionUnit.ScrewNum); + factory.CreateFloatOption( CarpenterOption.RemoveVentStopTime, 5.0f, 2.0f, 15.0f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateIntOption( + format: OptionUnit.Second); + factory.CreateIntOption( CarpenterOption.SetCameraScrew, 5, 1, 10, 1, - parentOps, format: OptionUnit.ScrewNum); - CreateFloatOption( + format: OptionUnit.ScrewNum); + factory.CreateFloatOption( CarpenterOption.SetCameraStopTime, 2.5f, 1.0f, 5.0f, 0.5f, - parentOps, format: OptionUnit.Second); - ((IntCustomOption)OptionManager.Instance.Get( - GetRoleOptionId( - RoleAbilityCommonOption.AbilityCount)) - ).SetOptionUnit(OptionUnit.ScrewNum); + format: OptionUnit.Second); } public void RoleAbilityInit() { if (this.Button == null) { return; } - var allOps = OptionManager.Instance; + var loader = this.Loader; this.Button.Behavior.SetCoolTime( - allOps.GetValue(GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime))); + loader.GetValue(RoleAbilityCommonOption.AbilityCoolTime)); if (this.Button.Behavior is CarpenterAbilityBehavior behavior) { behavior.SetAbilityCount( - allOps.GetValue(GetRoleOptionId(RoleAbilityCommonOption.AbilityCount))); + loader.GetValue(RoleAbilityCommonOption.AbilityCount)); } this.Button.OnMeetingEnd(); } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/CurseMaker.cs b/ExtremeRoles/Roles/Solo/Crewmate/CurseMaker.cs index 0d5fdd836..8004e232d 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/CurseMaker.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/CurseMaker.cs @@ -6,13 +6,16 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Roles.API.Extension.State; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class CurseMaker : @@ -101,7 +104,7 @@ private DeadBody[] getAllDeadBody() => UnityEngine.Object.FindObjectsOfType< private Dictionary deadBodyArrow; private Dictionary deadBodyData; - private GameData.PlayerInfo targetBody; + private NetworkedPlayerInfo targetBody; private byte deadBodyId; private bool isDeadBodySearch = false; @@ -195,8 +198,8 @@ public void CreateAbility() this.CreateAbilityCountButton( "curse", - Loader.CreateSpriteFromResources( - Path.CurseMakerCurse), + Resources.Loader.CreateSpriteFromResources( + Path.CurseMakerCurse), checkAbility: CheckAbility, abilityOff: CleanUp, forceAbilityOff: () => { }); @@ -277,105 +280,99 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( CurseMakerOption.CursingRange, - 2.5f, 0.5f, 5.0f, 0.5f, - parentOps); + 2.5f, 0.5f, 5.0f, 0.5f); - CreateFloatOption( + factory.CreateFloatOption( CurseMakerOption.AdditionalKillCool, 5.0f, 1.0f, 30.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - this.CreateAbilityCountOption( - parentOps, 1, 3, 5.0f); + IRoleAbility.CreateAbilityCountOption( + factory, 1, 3, 5.0f); - CreateIntOption( + factory.CreateIntOption( CurseMakerOption.TaskCurseTimeReduceRate, - 0, 0, 10, 1, parentOps, + 0, 0, 10, 1, format: OptionUnit.Percentage); - var removeDeadBodyOpt = CreateBoolOption( + var removeDeadBodyOpt = factory.CreateBoolOption( CurseMakerOption.IsNotRemoveDeadBodyByTask, - false, parentOps); + false); - CreateIntOption( + factory.CreateIntOption( CurseMakerOption.NotRemoveDeadBodyTaskGage, 100, 0, 100, 5, removeDeadBodyOpt, format: OptionUnit.Percentage); - var searchDeadBodyOption = CreateBoolOption( + var searchDeadBodyOption = factory.CreateBoolOption( CurseMakerOption.IsDeadBodySearch, - true, parentOps); + true); - CreateBoolOption( + factory.CreateBoolOption( CurseMakerOption.IsMultiDeadBodySearch, false, searchDeadBodyOption, - invert: true, - enableCheckOption: parentOps); + invert: true); - var searchTimeOpt = CreateFloatOption( + var searchTimeOpt = factory.CreateFloatOption( CurseMakerOption.SearchDeadBodyTime, 60.0f, 0.5f, 120.0f, 0.5f, searchDeadBodyOption, format: OptionUnit.Second, - invert: true, - enableCheckOption: parentOps); + invert: true); - var taskBoostOpt = CreateBoolOption( + var taskBoostOpt = factory.CreateBoolOption( CurseMakerOption.IsReduceSearchForTask, false, searchDeadBodyOption, - invert: true, - enableCheckOption: parentOps); + invert: true); - CreateIntOption( + factory.CreateIntOption( CurseMakerOption.ReduceSearchTaskGage, 100, 25, 100, 5, taskBoostOpt, format: OptionUnit.Percentage, - invert: true, - enableCheckOption: taskBoostOpt); + invert: true); - var reduceTimeOpt = CreateFloatDynamicOption( + var reduceTimeOpt = factory.CreateFloatDynamicOption( CurseMakerOption.ReduceSearchDeadBodyTime, 30f, 0.5f, 0.5f, taskBoostOpt, format: OptionUnit.Second, invert: true, - enableCheckOption: taskBoostOpt, tempMaxValue: 120.0f); - searchTimeOpt.SetUpdateOption(reduceTimeOpt); + searchTimeOpt.AddWithUpdate(reduceTimeOpt); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; - - this.additionalKillCool = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.AdditionalKillCool)); - this.deadBodyCheckRange = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.CursingRange)); - this.curseTimeReduceRate = 1.0f - (allOption.GetValue( - GetRoleOptionId(CurseMakerOption.TaskCurseTimeReduceRate)) / 100.0f); - this.isNotRemoveDeadBodyByTask = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.IsNotRemoveDeadBodyByTask)); - this.notRemoveDeadBodyTaskGage = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.NotRemoveDeadBodyTaskGage)) / 100.0f; - this.isDeadBodySearch = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.IsDeadBodySearch)); - this.isMultiDeadBodySearch = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.IsMultiDeadBodySearch)); - this.searchDeadBodyTime = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.SearchDeadBodyTime)); + var loader = this.Loader; + + this.additionalKillCool = loader.GetValue( + CurseMakerOption.AdditionalKillCool); + this.deadBodyCheckRange = loader.GetValue( + CurseMakerOption.CursingRange); + this.curseTimeReduceRate = 1.0f - (loader.GetValue( + CurseMakerOption.TaskCurseTimeReduceRate) / 100.0f); + this.isNotRemoveDeadBodyByTask = loader.GetValue( + CurseMakerOption.IsNotRemoveDeadBodyByTask); + this.notRemoveDeadBodyTaskGage = loader.GetValue( + CurseMakerOption.NotRemoveDeadBodyTaskGage) / 100.0f; + this.isDeadBodySearch = loader.GetValue( + CurseMakerOption.IsDeadBodySearch); + this.isMultiDeadBodySearch = loader.GetValue( + CurseMakerOption.IsMultiDeadBodySearch); + this.searchDeadBodyTime = loader.GetValue( + CurseMakerOption.SearchDeadBodyTime); this.isDeadBodySearchUsed = false; - this.isReduceSearchByTask = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.IsReduceSearchForTask)); - this.reduceSearchtaskGage = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.ReduceSearchTaskGage)) / 100.0f; - this.reduceTime = allOption.GetValue( - GetRoleOptionId(CurseMakerOption.ReduceSearchDeadBodyTime)); + this.isReduceSearchByTask = loader.GetValue( + CurseMakerOption.IsReduceSearchForTask); + this.reduceSearchtaskGage = loader.GetValue( + CurseMakerOption.ReduceSearchTaskGage) / 100.0f; + this.reduceTime = loader.GetValue( + CurseMakerOption.ReduceSearchDeadBodyTime); this.cursingText = Translation.GetString("cursing"); this.deadBodyData = new Dictionary(); @@ -384,8 +381,8 @@ protected override void RoleSpecificInit() this.isRemoveDeadBody = this.isNotRemoveDeadBodyByTask && this.notRemoveDeadBodyTaskGage == 0.0f ? false : true; - this.curCurseTime = allOption.GetValue( - GetRoleOptionId(RoleAbilityCommonOption.AbilityActiveTime)); + this.curCurseTime = loader.GetValue( + RoleAbilityCommonOption.AbilityActiveTime); } public void ResetOnMeetingStart() @@ -399,7 +396,7 @@ public void ResetOnMeetingStart() deadBodyData.Clear(); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Delusioner.cs b/ExtremeRoles/Roles/Solo/Crewmate/Delusioner.cs index 8f8a8d276..b00229825 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Delusioner.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Delusioner.cs @@ -12,6 +12,11 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Module.CustomMonoBehaviour.Minigames; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Delusioner : @@ -85,8 +90,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "deflectDamage", - Loader.CreateSpriteFromResources( - Path.DelusionerDeflectDamage)); + Resources.Loader.CreateSpriteFromResources( + Path.DelusionerDeflectDamage)); this.Button.SetLabelToCrewmate(); } @@ -118,7 +123,7 @@ public void ModifiedVote( public void ModifiedVoteAnime( MeetingHud instance, - GameData.PlayerInfo rolePlayer, + NetworkedPlayerInfo rolePlayer, ref Dictionary voteIndex) { if (voteIndex.TryGetValue( @@ -150,7 +155,7 @@ public void ResetModifier() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -186,7 +191,7 @@ public bool UseAbility() Map.AddSpawnPoint(randomPos, teloportTarget); } - foreach (GameData.PlayerInfo player in allPlayer.GetFastEnumerator()) + foreach (NetworkedPlayerInfo player in allPlayer.GetFastEnumerator()) { if (player == null) { continue; } if (!player.Disconnected && @@ -295,64 +300,63 @@ public override Color GetNameColor(bool isTruthColor = false) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( DelusionerOption.AwakeVoteNum, - 3, 0, 8, 1, parentOps, + 3, 0, 8, 1, format: OptionUnit.VoteNum); - CreateBoolOption( + factory.CreateBoolOption( DelusionerOption.IsOnetimeAwake, - false, parentOps); + false); - CreateFloatOption( + factory.CreateFloatOption( DelusionerOption.Range, - 2.5f, 0.0f, 7.5f, 0.1f, - parentOps); + 2.5f, 0.0f, 7.5f, 0.1f); - this.CreateAbilityCountOption( - parentOps, 3, 25); + IRoleAbility.CreateAbilityCountOption( + factory, 3, 25); - CreateIntOption( + factory.CreateIntOption( DelusionerOption.VoteCoolTimeReduceRate, - 5, 0, 100, 5, parentOps, + 5, 0, 100, 5, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( DelusionerOption.DeflectDamagePenaltyRate, - 10, 0, 100, 5, parentOps, + 10, 0, 100, 5, format: OptionUnit.Percentage); - CreateBoolOption( + factory.CreateBoolOption( DelusionerOption.IsIncludeLocalPlayer, - true, parentOps); - CreateBoolOption( + true); + factory.CreateBoolOption( DelusionerOption.IsIncludeSpawnPoint, - false, parentOps); + false); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; - this.awakeVoteCount = allOpt.GetValue( - GetRoleOptionId(DelusionerOption.AwakeVoteNum)); - this.isOneTimeAwake = allOpt.GetValue( - GetRoleOptionId(DelusionerOption.IsOnetimeAwake)); - this.voteCoolTimeReduceRate = allOpt.GetValue( - GetRoleOptionId(DelusionerOption.VoteCoolTimeReduceRate)); - this.deflectDamagePenaltyMod = 100f - (allOpt.GetValue( - GetRoleOptionId(DelusionerOption.DeflectDamagePenaltyRate)) / 100f); - this.range = allOpt.GetValue( - GetRoleOptionId(DelusionerOption.Range)); - - this.includeLocalPlayer = allOpt.GetValue( - GetRoleOptionId(DelusionerOption.IsIncludeLocalPlayer)); - this.includeSpawnPoint = allOpt.GetValue( - GetRoleOptionId(DelusionerOption.IsIncludeSpawnPoint)); + var loader = this.Loader; + this.awakeVoteCount = loader.GetValue( + DelusionerOption.AwakeVoteNum); + this.isOneTimeAwake = loader.GetValue( + DelusionerOption.IsOnetimeAwake); + this.voteCoolTimeReduceRate = loader.GetValue( + DelusionerOption.VoteCoolTimeReduceRate); + this.deflectDamagePenaltyMod = 100f - (loader.GetValue( + DelusionerOption.DeflectDamagePenaltyRate) / 100f); + this.range = loader.GetValue( + DelusionerOption.Range); + + this.includeLocalPlayer = loader.GetValue( + DelusionerOption.IsIncludeLocalPlayer); + this.includeSpawnPoint = loader.GetValue( + DelusionerOption.IsIncludeSpawnPoint); this.isOneTimeAwake = this.isOneTimeAwake && this.awakeVoteCount > 0; - this.defaultCoolTime = allOpt.GetValue( - GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime)); + this.defaultCoolTime = loader.GetValue( + RoleAbilityCommonOption.AbilityCoolTime); this.curCoolTime = this.defaultCoolTime; this.isAwakeRole = this.awakeVoteCount == 0; diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Fencer.cs b/ExtremeRoles/Roles/Solo/Crewmate/Fencer.cs index 7439a76b4..116993897 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Fencer.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Fencer.cs @@ -3,12 +3,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Fencer : SingleRoleBase, IRoleAutoBuildAbility, IRoleUpdate @@ -109,8 +112,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "counter", - Loader.CreateSpriteFromResources( - Path.FencerCounter), + Resources.Loader.CreateSpriteFromResources( + Path.FencerCounter), abilityOff: this.CleanUp, isReduceOnActive: true); this.Button.SetLabelToCrewmate(); @@ -151,7 +154,7 @@ public void ResetOnMeetingStart() this.CanKill = false; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -190,20 +193,20 @@ public override bool TryRolePlayerKilledFrom( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 2, 7, 3.0f); - CreateFloatOption( + IRoleAbility.CreateAbilityCountOption( + factory, 2, 7, 3.0f); + factory.CreateFloatOption( FencerOption.ResetTime, 5.0f, 2.5f, 30.0f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); } protected override void RoleSpecificInit() { this.Timer = 0.0f; - this.MaxTime = OptionManager.Instance.GetValue( - GetRoleOptionId(FencerOption.ResetTime)); + this.MaxTime = this.Loader.GetValue( + FencerOption.ResetTime); } } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Gambler.cs b/ExtremeRoles/Roles/Solo/Crewmate/Gambler.cs index c33875e4a..9b8ddd4d0 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Gambler.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Gambler.cs @@ -2,14 +2,17 @@ using System.Collections.Generic; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; -public sealed class Gambler : - SingleRoleBase, +public sealed class Gambler : + SingleRoleBase, IRoleVoteModifier { public enum GamblerOption @@ -45,33 +48,33 @@ public void ModifiedVote( Array.Fill(voteArray, 2, this.normalVoteRate + zeroVoteRate, dualVoteRate); int playerVoteNum = voteArray[RandomGenerator.Instance.Next(100)]; - + if (playerVoteNum == 1) { return; } - + int newVotedNum = playerVoteNum == 0 ? curVoteNum - 1 : curVoteNum + 1; voteResult[voteTo] = newVotedNum; } public void ModifiedVoteAnime( MeetingHud instance, - GameData.PlayerInfo rolePlayer, + NetworkedPlayerInfo rolePlayer, ref Dictionary voteIndex) { } public void ResetModifier() { } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( GamblerOption.NormalVoteRate, - 50, 0, 90, 5, parentOps, + 50, 0, 90, 5, format: OptionUnit.Percentage); } protected override void RoleSpecificInit() { - this.normalVoteRate = OptionManager.Instance.GetValue( - GetRoleOptionId(GamblerOption.NormalVoteRate)); + this.normalVoteRate = this.Loader.GetValue( + GamblerOption.NormalVoteRate); } } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Maintainer.cs b/ExtremeRoles/Roles/Solo/Crewmate/Maintainer.cs index 010031600..2b3c56dca 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Maintainer.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Maintainer.cs @@ -8,6 +8,10 @@ using ExtremeRoles.Performance.Il2Cpp; + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Maintainer : SingleRoleBase, IRoleAutoBuildAbility @@ -35,8 +39,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "maintenance", - Loader.CreateSpriteFromResources( - Path.MaintainerRepair)); + Resources.Loader.CreateSpriteFromResources( + Path.MaintainerRepair)); this.Button.SetLabelToCrewmate(); } @@ -92,16 +96,16 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 2, 10); + IRoleAbility.CreateAbilityCountOption( + factory, 2, 10); } protected override void RoleSpecificInit() diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Moderator.cs b/ExtremeRoles/Roles/Solo/Crewmate/Moderator.cs index cdac7d95c..f53c9a0fe 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Moderator.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Moderator.cs @@ -11,6 +11,11 @@ using ExtremeRoles.Helper; using ExtremeRoles.Performance; + + + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Solo.Crewmate; @@ -145,7 +150,7 @@ public void CreateAbility() { this.CreateAbilityCountButton( "moderate", - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.ModeratorModerate)); this.Button?.SetLabelToCrewmate(); } @@ -181,22 +186,23 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( ModeratorOption.AwakeTaskGage, 60, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - this.CreateAbilityCountOption( - parentOps, 2, 10); - CreateIntOption(ModeratorOption.MeetingTimerOffset, 30, 5, 360, 5, parentOps, format: OptionUnit.Second); + IRoleAbility.CreateAbilityCountOption( + factory, 2, 10); + factory.CreateIntOption( + ModeratorOption.MeetingTimerOffset, + 30, 5, 360, 5, format: OptionUnit.Second); } protected override void RoleSpecificInit() @@ -206,8 +212,10 @@ protected override void RoleSpecificInit() new Vector3(-3.75f, -2.5f, -250.0f), TMPro.TextAlignmentOptions.BottomLeft); - this.awakeTaskGage = OptionManager.Instance.GetValue( - GetRoleOptionId(ModeratorOption.AwakeTaskGage)) / 100.0f; + var cate = this.Loader; + + this.awakeTaskGage = cate.GetValue( + ModeratorOption.AwakeTaskGage) / 100.0f; this.awakeHasOtherVision = this.HasOtherVision; @@ -222,8 +230,8 @@ protected override void RoleSpecificInit() this.HasOtherVision = false; } - this.offset = OptionManager.Instance.GetValue( - this.GetRoleOptionId(ModeratorOption.MeetingTimerOffset)); + this.offset = cate.GetValue( + ModeratorOption.MeetingTimerOffset); ExtremeSystemTypeManager.Instance.TryAdd(ExtremeSystemType.ModdedMeetingTimeSystem, new ModdedMeetingTimeSystem()); } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Neet.cs b/ExtremeRoles/Roles/Solo/Crewmate/Neet.cs index 950345c5d..7cffe8dc8 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Neet.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Neet.cs @@ -1,8 +1,11 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Neet : SingleRoleBase @@ -36,38 +39,36 @@ public override string GetFullDescription() return base.GetFullDescription(); } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( NeetOption.CanCallMeeting, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( NeetOption.CanRepairSabotage, - false, parentOps); - - var neutralOps = CreateBoolOption( + false); + + var neutralOps = factory.CreateBoolOption( NeetOption.IsNeutral, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( NeetOption.HasTask, false, neutralOps, - invert: true, - enableCheckOption: parentOps); + invert: true); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; + var loader = this.Loader; - this.CanCallMeeting = allOption.GetValue( - GetRoleOptionId(NeetOption.CanCallMeeting)); - this.CanRepairSabotage = allOption.GetValue( - GetRoleOptionId(NeetOption.CanRepairSabotage)); - this.HasTask = allOption.GetValue( - GetRoleOptionId(NeetOption.HasTask)); + this.CanCallMeeting = loader.GetValue( + NeetOption.CanCallMeeting); + this.CanRepairSabotage = loader.GetValue( + NeetOption.CanRepairSabotage); + this.HasTask = loader.GetValue( + NeetOption.HasTask); - if (allOption.GetValue( - GetRoleOptionId(NeetOption.IsNeutral))) + if (loader.GetValue(NeetOption.IsNeutral)) { this.Team = ExtremeRoleType.Neutral; } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Opener.cs b/ExtremeRoles/Roles/Solo/Crewmate/Opener.cs index 4e247b877..5bdd32ba6 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Opener.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Opener.cs @@ -2,12 +2,15 @@ using ExtremeRoles.Module; using ExtremeRoles.Module.AbilityBehavior; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Opener : SingleRoleBase, IRoleAutoBuildAbility, IRoleUpdate @@ -34,6 +37,7 @@ public ExtremeAbilityButton Button private float range; private float reduceRate; private int plusAbilityNum; + private float abilityCoolTime; public Opener() : base( ExtremeRoleId.Opener, @@ -47,8 +51,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "openDoor", - Loader.CreateSpriteFromResources( - Path.OpenerOpenDoor)); + Resources.Loader.CreateSpriteFromResources( + Path.OpenerOpenDoor)); this.Button.SetLabelToCrewmate(); } public bool UseAbility() @@ -96,7 +100,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.targetDoor = null; return; @@ -120,9 +124,7 @@ public void Update( float rate = 1.0f - ((float)this.reduceRate / 100f); - this.Button.Behavior.SetCoolTime( - OptionManager.Instance.GetValue( - GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime)) * rate); + this.Button.Behavior.SetCoolTime(this.abilityCoolTime * rate); if (this.Button.Behavior is AbilityCountBehavior countBehavior) { @@ -132,34 +134,35 @@ public void Update( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 2, 5); - CreateFloatOption( + IRoleAbility.CreateAbilityCountOption( + factory, 2, 5); + factory.CreateFloatOption( OpenerOption.Range, - 2.0f, 0.5f, 5.0f, 0.1f, - parentOps); - CreateIntOption( + 2.0f, 0.5f, 5.0f, 0.1f); + factory.CreateIntOption( OpenerOption.ReduceRate, 45, 5, 95, 1, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( OpenerOption.PlusAbility, 5, 1, 10, 1, - parentOps, format: OptionUnit.Shot); } protected override void RoleSpecificInit() { this.isUpgraded = false; - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(OpenerOption.Range)); - this.reduceRate = OptionManager.Instance.GetValue( - GetRoleOptionId(OpenerOption.ReduceRate)); - this.plusAbilityNum = OptionManager.Instance.GetValue( - GetRoleOptionId(OpenerOption.PlusAbility)); + + var loader = this.Loader; + this.range = loader.GetValue( + OpenerOption.Range); + this.reduceRate = loader.GetValue( + OpenerOption.ReduceRate); + this.plusAbilityNum = loader.GetValue( + OpenerOption.PlusAbility); + this.abilityCoolTime = loader.GetValue( + RoleAbilityCommonOption.AbilityCoolTime); } } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Photographer.cs b/ExtremeRoles/Roles/Solo/Crewmate/Photographer.cs index 339a820d5..97e36aad5 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Photographer.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Photographer.cs @@ -9,7 +9,7 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; @@ -17,6 +17,9 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Module.Interface; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; #nullable enable @@ -34,14 +37,14 @@ public readonly struct PlayerPosInfo private readonly byte playerId; public PlayerPosInfo( - GameData.PlayerInfo player) + NetworkedPlayerInfo player) { this.playerId = player.PlayerId; this.PlayerName = player.PlayerName; Player.TryGetPlayerRoom(player.Object, out var room); this.Room = room; } - public PlayerPosInfo(GameData.PlayerInfo player, SystemTypes? room) + public PlayerPosInfo(NetworkedPlayerInfo player, SystemTypes? room) { this.playerId = player.PlayerId; this.PlayerName = player.PlayerName; @@ -328,8 +331,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "takePhoto", - Loader.CreateSpriteFromResources( - Path.PhotographerPhotoCamera)); + Resources.Loader.CreateSpriteFromResources( + Path.PhotographerPhotoCamera)); this.Button.SetLabelToCrewmate(); } @@ -380,15 +383,15 @@ public bool IsAbilityUse() public string GetFakeOptionString() => ""; public void HookReportButton( - PlayerControl rolePlayer, GameData.PlayerInfo reporter) + PlayerControl rolePlayer, NetworkedPlayerInfo reporter) { sendPhotoInfo(); } public void HookBodyReport( PlayerControl rolePlayer, - GameData.PlayerInfo reporter, - GameData.PlayerInfo reportBody) + NetworkedPlayerInfo reporter, + NetworkedPlayerInfo reportBody) { sendPhotoInfo(); } @@ -401,7 +404,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { this.photoCreater.Reset(); } @@ -505,53 +508,49 @@ public override Color GetNameColor(bool isTruthColor = false) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( PhotographerOption.AwakeTaskGage, 30, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( PhotographerOption.UpgradePhotoTaskGage, 60, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - var chatUpgradeOpt = CreateBoolOption( + var chatUpgradeOpt = factory.CreateBoolOption( PhotographerOption.EnableAllSendChat, - false, parentOps, isHidden: true); + false); - CreateIntOption( + factory.CreateIntOption( PhotographerOption.UpgradeAllSendChatTaskGage, 80, 0, 100, 10, chatUpgradeOpt, - format: OptionUnit.Percentage, - isHidden: true); + format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( PhotographerOption.PhotoRange, - 10.0f, 2.5f, 50f, 0.5f, - parentOps); + 10.0f, 2.5f, 50f, 0.5f); - this.CreateAbilityCountOption( - parentOps, 5, 10); + IRoleAbility.CreateAbilityCountOption( + factory, 5, 10); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var loader = this.Loader; - this.awakeTaskGage = allOpt.GetValue( - GetRoleOptionId(PhotographerOption.AwakeTaskGage)) / 100.0f; - this.upgradePhotoTaskGage = allOpt.GetValue( - GetRoleOptionId(PhotographerOption.UpgradePhotoTaskGage)) / 100.0f; + this.awakeTaskGage = loader.GetValue( + PhotographerOption.AwakeTaskGage) / 100.0f; + this.upgradePhotoTaskGage = loader.GetValue( + PhotographerOption.UpgradePhotoTaskGage) / 100.0f; this.enableAllSend = - allOpt.GetValue( - GetRoleOptionId(PhotographerOption.EnableAllSendChat)); - this.upgradeAllSendChatTaskGage = allOpt.GetValue( - GetRoleOptionId(PhotographerOption.UpgradeAllSendChatTaskGage)) / 100.0f; + loader.GetValue( + PhotographerOption.EnableAllSendChat); + this.upgradeAllSendChatTaskGage = loader.GetValue( + PhotographerOption.UpgradeAllSendChatTaskGage) / 100.0f; this.awakeHasOtherVision = this.HasOtherVision; @@ -570,8 +569,8 @@ protected override void RoleSpecificInit() this.upgradeAllSendChatTaskGage <= 0.0f; this.photoCreater = new PhotoCamera( - allOpt.GetValue( - GetRoleOptionId(PhotographerOption.PhotoRange))); + loader.GetValue( + PhotographerOption.PhotoRange)); this.photoCreater.IsUpgraded = this.upgradePhotoTaskGage <= 0.0f; } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Psychic.cs b/ExtremeRoles/Roles/Solo/Crewmate/Psychic.cs index 6193aabb7..090b490b8 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Psychic.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Psychic.cs @@ -16,6 +16,11 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Module.AbilityBehavior.Interface; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; #nullable enable @@ -228,8 +233,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( Translation.GetString("PsychicPsychic"), - Loader.CreateSpriteFromResources( - Path.PsychicPsychic), + Resources.Loader.CreateSpriteFromResources( + Path.PsychicPsychic), CheckAbility, CleanUp, ForceAbilityOff); @@ -272,15 +277,15 @@ public bool IsAbilityUse() public string GetFakeOptionString() => ""; public void HookReportButton( - PlayerControl rolePlayer, GameData.PlayerInfo reporter) + PlayerControl rolePlayer, NetworkedPlayerInfo reporter) { sendPhotoInfo(); } public void HookBodyReport( PlayerControl rolePlayer, - GameData.PlayerInfo reporter, - GameData.PlayerInfo reportBody) + NetworkedPlayerInfo reporter, + NetworkedPlayerInfo reportBody) { sendPhotoInfo(); } @@ -290,7 +295,7 @@ public void ResetOnMeetingStart() this.popUpper?.Clear(); } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { this.counters?.Clear(); } @@ -397,48 +402,47 @@ public override Color GetNameColor(bool isTruthColor = false) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( PsychicOption.AwakeTaskGage, 30, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( PsychicOption.AwakeDeadPlayerNum, - 2, 0, 7, 1, parentOps); + 2, 0, 7, 1); - this.CreateAbilityCountOption( - parentOps, 1, 5, 3.0f); + IRoleAbility.CreateAbilityCountOption( + factory, 1, 5, 3.0f); - var isUpgradeOpt = CreateBoolOption( + var isUpgradeOpt = factory.CreateBoolOption( PsychicOption.IsUpgradeAbility, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( PsychicOption.UpgradeTaskGage, 70, 0, 100, 10, isUpgradeOpt, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( PsychicOption.UpgradeDeadPlayerNum, 5, 0, 15, 1, isUpgradeOpt); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; - - this.awakeTaskGage = allOpt.GetValue( - GetRoleOptionId(PsychicOption.AwakeTaskGage)) / 100.0f; - this.awakeDeadPlayerNum = allOpt.GetValue( - GetRoleOptionId(PsychicOption.AwakeDeadPlayerNum)); - - this.upgradeTaskGage = allOpt.GetValue( - GetRoleOptionId(PsychicOption.UpgradeTaskGage)) / 100.0f; - this.upgradeDeadPlayerNum = allOpt.GetValue( - GetRoleOptionId(PsychicOption.UpgradeDeadPlayerNum)); - this.enableUpgrade = allOpt.GetValue( - GetRoleOptionId(PsychicOption.IsUpgradeAbility)); + var loader = this.Loader; + + this.awakeTaskGage = loader.GetValue( + PsychicOption.AwakeTaskGage) / 100.0f; + this.awakeDeadPlayerNum = loader.GetValue( + PsychicOption.AwakeDeadPlayerNum); + + this.upgradeTaskGage = loader.GetValue( + PsychicOption.UpgradeTaskGage) / 100.0f; + this.upgradeDeadPlayerNum = loader.GetValue( + PsychicOption.UpgradeDeadPlayerNum); + this.enableUpgrade = loader.GetValue( + PsychicOption.IsUpgradeAbility); int maxPlayerNum = CachedPlayerControl.AllPlayerControls.Count - 1; diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Resurrecter.cs b/ExtremeRoles/Roles/Solo/Crewmate/Resurrecter.cs index 9a5489ac6..6fd416da6 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Resurrecter.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Resurrecter.cs @@ -13,6 +13,11 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Roles.API.Extension.State; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Resurrecter : @@ -145,7 +150,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { if (this.isActiveMeetingCount && this.meetingCounter >= this.maxMeetingCount) @@ -387,77 +392,72 @@ public override void RolePlayerKilledAction( protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( ResurrecterOption.AwakeTaskGage, 100, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( ResurrecterOption.ResurrectTaskGage, 100, 50, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( ResurrecterOption.ResurrectDelayTime, 5.0f, 4.0f, 60.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - var meetingResetOpt = CreateBoolOption( + var meetingResetOpt = factory.CreateBoolOption( ResurrecterOption.IsMeetingCoolResetOnResurrect, - true, parentOps); + true); - CreateFloatOption( + factory.CreateFloatOption( ResurrecterOption.ResurrectMeetingCooltime, 20.0f, 5.0f, 60.0f, 0.25f, meetingResetOpt, format: OptionUnit.Second, - invert: true, - enableCheckOption: parentOps); + invert: true); - CreateIntOption( + factory.CreateIntOption( ResurrecterOption.ResurrectTaskResetMeetingNum, - 1, 1, 5, 1, - parentOps); + 1, 1, 5, 1); - CreateIntOption( + factory.CreateIntOption( ResurrecterOption.ResurrectTaskResetGage, 20, 10, 50, 5, - parentOps, format: OptionUnit.Percentage); - CreateBoolOption( + factory.CreateBoolOption( ResurrecterOption.CanResurrectAfterDeath, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( ResurrecterOption.CanResurrectOnExil, - false, parentOps); + false); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; - - this.awakeTaskGage = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.AwakeTaskGage)) / 100.0f; - this.resurrectTaskGage = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.ResurrectTaskGage)) / 100.0f; - this.resetTaskGage = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.ResurrectTaskResetGage)) / 100.0f; - - this.resurrectTimer = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.ResurrectDelayTime)); - this.canResurrectAfterDeath = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.CanResurrectAfterDeath)); - this.canResurrectOnExil = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.CanResurrectOnExil)); - this.maxMeetingCount = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.ResurrectTaskResetMeetingNum)); - this.isMeetingCoolResetOnResurrect = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.IsMeetingCoolResetOnResurrect)); - this.meetingCoolDown = allOpt.GetValue( - GetRoleOptionId(ResurrecterOption.ResurrectMeetingCooltime)); + var loader = this.Loader; + + this.awakeTaskGage = loader.GetValue( + ResurrecterOption.AwakeTaskGage) / 100.0f; + this.resurrectTaskGage = loader.GetValue( + ResurrecterOption.ResurrectTaskGage) / 100.0f; + this.resetTaskGage = loader.GetValue( + ResurrecterOption.ResurrectTaskResetGage) / 100.0f; + + this.resurrectTimer = loader.GetValue( + ResurrecterOption.ResurrectDelayTime); + this.canResurrectAfterDeath = loader.GetValue( + ResurrecterOption.CanResurrectAfterDeath); + this.canResurrectOnExil = loader.GetValue( + ResurrecterOption.CanResurrectOnExil); + this.maxMeetingCount = loader.GetValue( + ResurrecterOption.ResurrectTaskResetMeetingNum); + this.isMeetingCoolResetOnResurrect = loader.GetValue( + ResurrecterOption.IsMeetingCoolResetOnResurrect); + this.meetingCoolDown = loader.GetValue( + ResurrecterOption.ResurrectMeetingCooltime); this.awakeHasOtherVision = this.HasOtherVision; this.canResurrect = false; @@ -535,7 +535,7 @@ private void revive(PlayerControl rolePlayer) private void replaceTask(PlayerControl rolePlayer) { - GameData.PlayerInfo playerInfo = rolePlayer.Data; + NetworkedPlayerInfo playerInfo = rolePlayer.Data; var shuffleTaskIndex = Enumerable.Range( 0, playerInfo.Tasks.Count).ToList().OrderBy( @@ -567,7 +567,7 @@ private void replaceTask(PlayerControl rolePlayer) else if (CachedShipStatus.Instance.ShortTasks.FirstOrDefault( (NormalPlayerTask t) => t.Index == replaceTaskId) != null) { - taskIndex = GameSystem.GetRandomNormalTaskId(); + taskIndex = GameSystem.GetRandomShortTaskId(); } else { diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Sheriff.cs b/ExtremeRoles/Roles/Solo/Crewmate/Sheriff.cs index 57b3c8576..d496d50c6 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Sheriff.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Sheriff.cs @@ -4,12 +4,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; using ExtremeRoles.Module.AbilityBehavior.Interface; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Module.ExtremeShipStatus; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Sheriff : SingleRoleBase, IRoleUpdate, IRoleResetMeeting @@ -55,9 +58,9 @@ public override bool TryRolePlayerKillTo( { var targetPlayerRole = ExtremeRoleManager.GameRole[ targetPlayer.PlayerId]; - - if ((targetPlayerRole.IsImpostor()) || + + if ((targetPlayerRole.IsImpostor()) || (targetPlayerRole.IsNeutral() && this.canShootNeutral)) { if ((!this.canShootAssassin && targetPlayerRole.Id == ExtremeRoleId.Assassin) || @@ -179,40 +182,39 @@ private void createText() protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - - CreateBoolOption( + factory.CreateBoolOption( SheriffOption.CanShootAssassin, - false, parentOps); + false); - CreateBoolOption( + factory.CreateBoolOption( SheriffOption.CanShootNeutral, - true, parentOps); + true); - CreateIntOption( + factory.CreateIntOption( SheriffOption.ShootNum, 1, 1, GameSystem.VanillaMaxPlayerNum - 1, 1, - parentOps, format: OptionUnit.Shot); + format: OptionUnit.Shot); - var enableTaskRelatedOps = CreateBoolOption( + var enableTaskRelatedOps = factory.CreateBoolOption( SheriffOption.EnableTaskRelated, - false, parentOps); + false); - CreateFloatOption( + factory.CreateFloatOption( SheriffOption.ReduceCurKillCool, 2.0f, 1.0f, 5.0f, 0.1f, enableTaskRelatedOps, format:OptionUnit.Second); - CreateBoolOption( + factory.CreateBoolOption( SheriffOption.IsPerm, false, enableTaskRelatedOps); - var syncOpt = CreateBoolOption( + var syncOpt = factory.CreateBoolOption( SheriffOption.IsSyncTaskAndShootNum, false, enableTaskRelatedOps);; - CreateIntOption( + factory.CreateIntOption( SheriffOption.SyncShootTaskGage, 5, 5, 100, 1, syncOpt, format: OptionUnit.Percentage); @@ -221,29 +223,29 @@ protected override void CreateSpecificOption( protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var loader = this.Loader; - this.shootNum = allOpt.GetValue( - GetRoleOptionId(SheriffOption.ShootNum)); - this.canShootNeutral = allOpt.GetValue( - GetRoleOptionId(SheriffOption.CanShootNeutral)); - this.canShootAssassin = allOpt.GetValue( - GetRoleOptionId(SheriffOption.CanShootAssassin)); + this.shootNum = loader.GetValue( + SheriffOption.ShootNum); + this.canShootNeutral = loader.GetValue( + SheriffOption.CanShootNeutral); + this.canShootAssassin = loader.GetValue( + SheriffOption.CanShootAssassin); this.killCountText = null; - this.enableTaskRelatedSetting = allOpt.GetValue( - GetRoleOptionId(SheriffOption.EnableTaskRelated)); - this.reduceKillCool = allOpt.GetValue( - GetRoleOptionId(SheriffOption.ReduceCurKillCool)); - this.isPerm = allOpt.GetValue( - GetRoleOptionId(SheriffOption.IsPerm)); - this.isSyncTaskShootNum = allOpt.GetValue( - GetRoleOptionId(SheriffOption.IsSyncTaskAndShootNum)); - this.syncShootTaskGage = allOpt.GetValue( - GetRoleOptionId(SheriffOption.SyncShootTaskGage)) / 100.0f; + this.enableTaskRelatedSetting = loader.GetValue( + SheriffOption.EnableTaskRelated); + this.reduceKillCool = loader.GetValue( + SheriffOption.ReduceCurKillCool); + this.isPerm = loader.GetValue( + SheriffOption.IsPerm); + this.isSyncTaskShootNum = loader.GetValue( + SheriffOption.IsSyncTaskAndShootNum); + this.syncShootTaskGage = loader.GetValue( + SheriffOption.SyncShootTaskGage) / 100.0f; this.prevGage = 0.0f; - + this.maxShootNum = this.shootNum; if (this.enableTaskRelatedSetting && this.isSyncTaskShootNum) @@ -290,7 +292,7 @@ private void updateKillCountText() ICountBehavior.DefaultButtonCountText), this.shootNum); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { if (this.killCountText != null) { diff --git a/ExtremeRoles/Roles/Solo/Crewmate/SpecialCrew.cs b/ExtremeRoles/Roles/Solo/Crewmate/SpecialCrew.cs index e453b282a..c30c57ec0 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/SpecialCrew.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/SpecialCrew.cs @@ -1,6 +1,9 @@ -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class SpecialCrew : SingleRoleBase @@ -13,11 +16,11 @@ public SpecialCrew(): base( false, true, false, false) {} - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { return; } - + protected override void RoleSpecificInit() { return; diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Supervisor.cs b/ExtremeRoles/Roles/Solo/Crewmate/Supervisor.cs index 6f373fab0..96dbc2316 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Supervisor.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Supervisor.cs @@ -2,11 +2,14 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Performance; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Supervisor : SingleRoleBase, IRoleAutoBuildAbility, IRoleUpdate @@ -78,7 +81,7 @@ public bool IsAbilityUse() public bool IsOpen() => MapBehaviour.Instance.isActiveAndEnabled; - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -134,15 +137,15 @@ public void Update(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 3.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 3.0f); - var boostOption = this.CreateBoolOption( + var boostOption = factory.CreateBoolOption( SuperviosrOption.IsBoostTask, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( SuperviosrOption.TaskGage, 100, 50, 100, 5, boostOption, @@ -151,9 +154,10 @@ protected override void CreateSpecificOption( protected override void RoleSpecificInit() { - this.isBoostTask = OptionManager.Instance.GetValue( - GetRoleOptionId(SuperviosrOption.IsBoostTask)); - this.taskGage = OptionManager.Instance.GetValue( - GetRoleOptionId(SuperviosrOption.TaskGage)) / 100.0f; + var loader = this.Loader; + this.isBoostTask = loader.GetValue( + SuperviosrOption.IsBoostTask); + this.taskGage = loader.GetValue( + SuperviosrOption.TaskGage) / 100.0f; } } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Survivor.cs b/ExtremeRoles/Roles/Solo/Crewmate/Survivor.cs index a939df82f..d8241ef83 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Survivor.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Survivor.cs @@ -5,11 +5,14 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Performance; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Survivor : SingleRoleBase, IRoleAwake, IRoleWinPlayerModifier @@ -65,7 +68,7 @@ public static void DeadWin(byte rolePlayerId) public string GetFakeOptionString() => ""; public void ModifiedWinPlayer( - GameData.PlayerInfo rolePlayerInfo, + NetworkedPlayerInfo rolePlayerInfo, GameOverReason reason, ref ExtremeGameResult.WinnerTempData winner) { @@ -194,31 +197,30 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( SurvivorOption.AwakeTaskGage, 70, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( SurvivorOption.DeadWinTaskGage, 100, 50, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateBoolOption( + factory.CreateBoolOption( SurvivorOption.NoWinSurvivorAssignGhostRole, - true, parentOps); + true); } protected override void RoleSpecificInit() { - this.awakeTaskGage = OptionManager.Instance.GetValue( - GetRoleOptionId(SurvivorOption.AwakeTaskGage)) / 100.0f; - this.deadWinTaskGage = OptionManager.Instance.GetValue( - GetRoleOptionId(SurvivorOption.DeadWinTaskGage)) / 100.0f; - this.isNoWinSurvivorAssignGhostRole = OptionManager.Instance.GetValue( - GetRoleOptionId(SurvivorOption.NoWinSurvivorAssignGhostRole)); + var loader = this.Loader; + this.awakeTaskGage = loader.GetValue( + SurvivorOption.AwakeTaskGage) / 100.0f; + this.deadWinTaskGage = loader.GetValue( + SurvivorOption.DeadWinTaskGage) / 100.0f; + this.isNoWinSurvivorAssignGhostRole = loader.GetValue( + SurvivorOption.NoWinSurvivorAssignGhostRole); this.awakeHasOtherVision = this.HasOtherVision; this.isDeadWin = false; diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Teleporter.cs b/ExtremeRoles/Roles/Solo/Crewmate/Teleporter.cs index bc44da4b2..aeb4defb1 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Teleporter.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Teleporter.cs @@ -20,6 +20,11 @@ using ExtremeRoles.Performance; using ExtremeRoles.Compat; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Teleporter : @@ -206,10 +211,9 @@ public void RoleAbilityInit() { if (this.Button == null) { return; } - var allOpt = OptionManager.Instance; this.Button.Behavior.SetCoolTime( - allOpt.GetValue(this.GetRoleOptionId( - RoleAbilityCommonOption.AbilityCoolTime))); + this.Loader.GetValue( + RoleAbilityCommonOption.AbilityCoolTime)); this.behavior.SetAbilityCount(0); @@ -237,10 +241,10 @@ public void IntroEndSetUp() public void CreateAbility() { - this.firstPortalImg = Loader.CreateSpriteFromResources( - Path.TeleporterFirstPortal); - this.secondPortalImg = Loader.CreateSpriteFromResources( - Path.TeleporterSecondPortal); + this.firstPortalImg = Resources.Loader.CreateSpriteFromResources( + Path.TeleporterFirstPortal); + this.secondPortalImg = Resources.Loader.CreateSpriteFromResources( + Path.TeleporterSecondPortal); this.behavior = new TeleporterAbilityBehavior( Translation.GetString("SetPortal"), @@ -289,27 +293,28 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( TeleporterOption.CanUseOtherPlayer, - false, parentOps); - this.CreateAbilityCountOption( - parentOps, 1, 3); + false); + IRoleAbility.CreateAbilityCountOption( + factory, 1, 3); } protected override void RoleSpecificInit() { - this.isSharePortal = OptionManager.Instance.GetValue( - GetRoleOptionId(TeleporterOption.CanUseOtherPlayer)); - this.partNum = OptionManager.Instance.GetValue( - GetRoleOptionId(RoleAbilityCommonOption.AbilityCount)); + var loader = this.Loader; + this.isSharePortal = loader.GetValue( + TeleporterOption.CanUseOtherPlayer); + this.partNum = loader.GetValue( + RoleAbilityCommonOption.AbilityCount); } private static void setPartFromMapJsonInfo(JArray json, int num) diff --git a/ExtremeRoles/Roles/Solo/Crewmate/TimeMaster.cs b/ExtremeRoles/Roles/Solo/Crewmate/TimeMaster.cs index b753b59e5..cf01ec52a 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/TimeMaster.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/TimeMaster.cs @@ -11,8 +11,13 @@ using ExtremeRoles.Module.CustomMonoBehaviour; using ExtremeRoles.Performance; + + using BepInEx.Unity.IL2CPP.Utils; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class TimeMaster : SingleRoleBase, IRoleAutoBuildAbility @@ -307,8 +312,8 @@ public void CreateAbility() { this.CreateNormalAbilityButton( "timeShield", - Loader.CreateSpriteFromResources( - Path.TimeMasterTimeShield), + Resources.Loader.CreateSpriteFromResources( + Path.TimeMasterTimeShield), abilityOff: this.CleanUp); this.Button.SetLabelToCrewmate(); } @@ -343,7 +348,7 @@ public void ResetOnMeetingStart() resetMeeting(localPlayer.PlayerId); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -370,15 +375,15 @@ public override bool TryRolePlayerKilledFrom( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 3.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 3.0f); - CreateFloatOption( + factory.CreateFloatOption( TimeMasterOption.RewindTime, 5.0f, 1.0f, 60.0f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); } protected override void RoleSpecificInit() @@ -388,7 +393,7 @@ protected override void RoleSpecificInit() history = CachedPlayerControl.LocalPlayer.PlayerControl.gameObject.AddComponent< TimeMasterHistory>(); history.Initialize( - OptionManager.Instance.GetValue(GetRoleOptionId( - TimeMasterOption.RewindTime))); + this.Loader.GetValue( + TimeMasterOption.RewindTime)); } } diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Watchdog.cs b/ExtremeRoles/Roles/Solo/Crewmate/Watchdog.cs index c6b4aafb1..fca3ce6fc 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Watchdog.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Watchdog.cs @@ -3,12 +3,14 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Crewmate; public sealed class Watchdog : SingleRoleBase, IRoleAutoBuildAbility, IRoleUpdate @@ -76,7 +78,7 @@ public bool IsAbilityUse() public bool IsOpen() => Minigame.Instance != null; - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -136,10 +138,10 @@ public void Update(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 3.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 3.0f); } protected override void RoleSpecificInit() diff --git a/ExtremeRoles/Roles/Solo/Crewmate/Whisper.cs b/ExtremeRoles/Roles/Solo/Crewmate/Whisper.cs index 760a12941..5fb585d1c 100644 --- a/ExtremeRoles/Roles/Solo/Crewmate/Whisper.cs +++ b/ExtremeRoles/Roles/Solo/Crewmate/Whisper.cs @@ -6,6 +6,11 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + + + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Solo.Crewmate; @@ -52,7 +57,7 @@ public Whisper() : base( { } #pragma warning restore CS8618 - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -197,32 +202,31 @@ public void Update(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( WhisperOption.AbilityOffTime, 2.0f, 1.0f, 5.0f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( WhisperOption.AbilityOnTime, 4.0f, 1.0f, 10.0f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( WhisperOption.TellTextTime, 3.0f, 1.0f, 25.0f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateIntOption( + factory.CreateIntOption( WhisperOption.MaxTellText, - 3, 1, 10, 1, - parentOps); - var awakeOpt = CreateBoolOption( + 3, 1, 10, 1); + var awakeOpt = factory.CreateBoolOption( WhisperOption.EnableAwakeAbility, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( WhisperOption.AbilityTaskGage, 70, 0, 100, 10, awakeOpt, @@ -231,22 +235,22 @@ protected override void CreateSpecificOption( protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; + var loader = this.Loader; this.textPopUp = new TextPopUpper( - allOption.GetValue(GetRoleOptionId(WhisperOption.MaxTellText)), - allOption.GetValue(GetRoleOptionId(WhisperOption.TellTextTime)), + loader.GetValue(WhisperOption.MaxTellText), + loader.GetValue(WhisperOption.TellTextTime), new Vector3(-3.75f, -2.5f, -250.0f), TMPro.TextAlignmentOptions.BottomLeft); - this.abilityOffTime = allOption.GetValue( - GetRoleOptionId(WhisperOption.AbilityOffTime)); - this.abilityOnTime = allOption.GetValue(GetRoleOptionId(WhisperOption.AbilityOnTime)); + this.abilityOffTime = loader.GetValue( + WhisperOption.AbilityOffTime); + this.abilityOnTime = loader.GetValue(WhisperOption.AbilityOnTime); - this.isEnableAwakeAbility = allOption.GetValue( - GetRoleOptionId(WhisperOption.EnableAwakeAbility)); - this.awakeTaskGage = allOption.GetValue( - GetRoleOptionId(WhisperOption.AbilityTaskGage)) / 100.0f; + this.isEnableAwakeAbility = loader.GetValue( + WhisperOption.EnableAwakeAbility); + this.awakeTaskGage = loader.GetValue( + WhisperOption.AbilityTaskGage) / 100.0f; this.isAwake = this.isEnableAwakeAbility && this.awakeTaskGage <= 0.0f; this.prevPlayerPos = defaultPos; diff --git a/ExtremeRoles/Roles/Solo/Host/Button/XionActionToPlayerButton.cs b/ExtremeRoles/Roles/Solo/Host/Button/XionActionToPlayerButton.cs index e66c891a8..03faec349 100644 --- a/ExtremeRoles/Roles/Solo/Host/Button/XionActionToPlayerButton.cs +++ b/ExtremeRoles/Roles/Solo/Host/Button/XionActionToPlayerButton.cs @@ -65,7 +65,7 @@ public XionActionToPlayerButton(byte xionPlayerId) { if (playerId == xionPlayerId) { continue; } - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(playerId); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(playerId); if (player == null || player.Disconnected) { continue; @@ -125,7 +125,7 @@ private void updateButtonIcons(bool isHideGui) bool updated = false; foreach (var (playerId, pool) in this.buttonIcons) { - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(playerId); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(playerId); if (player == null || player.Disconnected) { SetActive(playerId, false); diff --git a/ExtremeRoles/Roles/Solo/Host/Xion.Button.cs b/ExtremeRoles/Roles/Solo/Host/Xion.Button.cs index 5186fe5bd..0998cf2a8 100644 --- a/ExtremeRoles/Roles/Solo/Host/Xion.Button.cs +++ b/ExtremeRoles/Roles/Solo/Host/Xion.Button.cs @@ -37,15 +37,15 @@ public void CreateButton() this.funcButton = new List(6) { new XionActionButton( - Loader.CreateSpriteFromResources( - Path.XionMapZoomIn), + Resources.Loader.CreateSpriteFromResources( + Path.XionMapZoomIn), this.cameraZoomIn, - Translation.GetString("zoomIn")), + Translation.GetString("zoomIn")), new XionActionButton( - Loader.CreateSpriteFromResources( - Path.XionSpeedDown), + Resources.Loader.CreateSpriteFromResources( + Path.XionSpeedDown), this.RpcSpeedDown, - Translation.GetString("speedDown")), + Translation.GetString("speedDown")), }; bool enableMeeting = !ExtremeGameModeManager.Instance.ShipOption.IsBreakEmergencyButton; @@ -53,7 +53,7 @@ public void CreateButton() { this.funcButton.Add( new XionActionButton( - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.DetectiveApprenticeEmergencyMeeting), this.RpcCallMeeting, Translation.GetString("emergencyMeeting"))); @@ -62,19 +62,19 @@ public void CreateButton() // 残りのボタン this.funcButton.Add( new XionActionButton( - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.MaintainerRepair), this.RpcRepairSabotage, Translation.GetString("maintenance"))); this.funcButton.Add( new XionActionButton( - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.XionMapZoomOut), this.cameraZoomOut, Translation.GetString("zoomOut"))); this.funcButton.Add( new XionActionButton( - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.XionSpeedUp), this.RpcSpeedUp, Translation.GetString("speedUp"))); @@ -183,7 +183,7 @@ public static Action GetPlayerButtonAction(byte playerId) { return () => { - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(playerId); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(playerId); if (player == null || player.Disconnected) { return; } if (Key.IsAltDown()) diff --git a/ExtremeRoles/Roles/Solo/Host/Xion.Command.cs b/ExtremeRoles/Roles/Solo/Host/Xion.Command.cs index 738729f5b..b1c8c68d9 100644 --- a/ExtremeRoles/Roles/Solo/Host/Xion.Command.cs +++ b/ExtremeRoles/Roles/Solo/Host/Xion.Command.cs @@ -130,7 +130,7 @@ private static void specificPlayerIdToSpecificRole(string[] args) byte targetPlayerId = byte.MaxValue; - foreach (GameData.PlayerInfo player in GameData.Instance.AllPlayers) + foreach (NetworkedPlayerInfo player in GameData.Instance.AllPlayers) { if (player.DefaultOutfit.PlayerName == playerName) { @@ -237,7 +237,7 @@ private static void specialResetRoleReset( private static void xionPlayerToDead(byte xionPlayerId) { - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(xionPlayerId); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(xionPlayerId); if (player.IsDead) { return; } diff --git a/ExtremeRoles/Roles/Solo/Host/Xion.Interface.cs b/ExtremeRoles/Roles/Solo/Host/Xion.Interface.cs index 73d6b3614..b520d022e 100644 --- a/ExtremeRoles/Roles/Solo/Host/Xion.Interface.cs +++ b/ExtremeRoles/Roles/Solo/Host/Xion.Interface.cs @@ -15,7 +15,7 @@ public void IntroEndSetUp() CreateButton(); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.resetCoolTime(); } diff --git a/ExtremeRoles/Roles/Solo/Host/Xion.RpcOps.cs b/ExtremeRoles/Roles/Solo/Host/Xion.RpcOps.cs index e3178f4e9..7880edfe7 100644 --- a/ExtremeRoles/Roles/Solo/Host/Xion.RpcOps.cs +++ b/ExtremeRoles/Roles/Solo/Host/Xion.RpcOps.cs @@ -48,7 +48,7 @@ public static void UseAbility(ref MessageReader reader) byte playerId = reader.ReadByte(); XionRpcOpsCode ops = (XionRpcOpsCode)reader.ReadByte(); Xion xion = ExtremeRoleManager.GetSafeCastedRole(playerId); - GameData.PlayerInfo xionPlayer = GameData.Instance.GetPlayerById(playerId); + NetworkedPlayerInfo xionPlayer = GameData.Instance.GetPlayerById(playerId); switch (ops) { @@ -60,7 +60,8 @@ public static void UseAbility(ref MessageReader reader) case XionRpcOpsCode.Teleport: float x = reader.ReadSingle(); float y = reader.ReadSingle(); - if (xionPlayer?.Object == null) { return; } + if (xionPlayer == null || + xionPlayer.Object == null) { return; } teleport(xionPlayer.Object, new Vector2(x, y)); break; case XionRpcOpsCode.NoXionVote: diff --git a/ExtremeRoles/Roles/Solo/Host/Xion.cs b/ExtremeRoles/Roles/Solo/Host/Xion.cs index 0efaac19d..c9c95c65e 100644 --- a/ExtremeRoles/Roles/Solo/Host/Xion.cs +++ b/ExtremeRoles/Roles/Solo/Host/Xion.cs @@ -1,10 +1,12 @@ using UnityEngine; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Host; public sealed partial class Xion : SingleRoleBase @@ -28,7 +30,7 @@ public Xion(byte xionPlayerId) : base( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { } public static void XionPlayerToGhostLayer() @@ -39,7 +41,7 @@ public static void XionPlayerToGhostLayer() player.gameObject.layer = LayerMask.NameToLayer("Ghost"); } } - + public static void RemoveXionPlayerToAllPlayerControl() { bool isXion(PlayerControl x) => x.PlayerId == PlayerId; diff --git a/ExtremeRoles/Roles/Solo/Impostor/AssaultMaster.cs b/ExtremeRoles/Roles/Solo/Impostor/AssaultMaster.cs index ce32fdae4..d15bd6813 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/AssaultMaster.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/AssaultMaster.cs @@ -4,12 +4,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class AssaultMaster : SingleRoleBase, IRoleAutoBuildAbility, IRoleReportHook, IRoleUpdate @@ -65,20 +68,20 @@ public void CreateAbility() { this.CreateNormalAbilityButton( "reload", - Loader.CreateSpriteFromResources( - Path.AssaultMasterReload)); + Resources.Loader.CreateSpriteFromResources( + Path.AssaultMasterReload)); } public void HookBodyReport( PlayerControl rolePlayer, - GameData.PlayerInfo reporter, - GameData.PlayerInfo reportBody) + NetworkedPlayerInfo reporter, + NetworkedPlayerInfo reportBody) { addStock(this.addStockWhenReport); } public void HookReportButton( - PlayerControl rolePlayer, GameData.PlayerInfo reporter) + PlayerControl rolePlayer, NetworkedPlayerInfo reporter) { addStock(this.addStockWhenMeetingButton); } @@ -88,7 +91,7 @@ public bool IsAbilityUse() => this.stock > 0 && PlayerControl.LocalPlayer.killTimer > 0; - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { if (this.reloadButton != null && this.timerStock > 0) { @@ -205,63 +208,63 @@ public override string GetFullDescription() => string.Format( base.GetFullDescription(), this.stock, this.stockMax, this.curReloadCoolTime); - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption(parentOps); + IRoleAbility.CreateCommonAbilityOption(factory); - CreateIntOption( + factory.CreateIntOption( AssaultMasterOption.StockLimit, - 2, 1, 10, 1, parentOps, + 2, 1, 10, 1, format: OptionUnit.ScrewNum); - CreateIntOption( + factory.CreateIntOption( AssaultMasterOption.StockNumWhenReport, - 1, 1, 5, 1, parentOps, + 1, 1, 5, 1, format: OptionUnit.ScrewNum); - CreateIntOption( + factory.CreateIntOption( AssaultMasterOption.StockNumWhenMeetingButton, - 3, 1, 10, 1, parentOps, + 3, 1, 10, 1, format: OptionUnit.ScrewNum); - CreateFloatOption( + factory.CreateFloatOption( AssaultMasterOption.CockingKillCoolReduceTime, - 2.0f, 1.0f, 5.0f, 0.1f, parentOps, + 2.0f, 1.0f, 5.0f, 0.1f, format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( AssaultMasterOption.ReloadReduceKillCoolTimePerStock, - 5.0f, 2.0f, 10.0f, 0.1f, parentOps, + 5.0f, 2.0f, 10.0f, 0.1f, format: OptionUnit.Second); - CreateBoolOption( + factory.CreateBoolOption( AssaultMasterOption.IsResetReloadCoolTimeWhenKill, - true, parentOps); - CreateIntOption( + true); + factory.CreateIntOption( AssaultMasterOption.ReloadCoolTimeReduceRatePerHideStock, - 75, 30, 90, 1, parentOps, + 75, 30, 90, 1, format: OptionUnit.Percentage); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; - - this.stockMax = allOpt.GetValue( - GetRoleOptionId(AssaultMasterOption.StockLimit)); - this.addStockWhenReport = allOpt.GetValue( - GetRoleOptionId(AssaultMasterOption.StockNumWhenReport)); - this.addStockWhenMeetingButton = allOpt.GetValue( - GetRoleOptionId(AssaultMasterOption.StockNumWhenMeetingButton)); - this.cockingReduceTime = allOpt.GetValue( - GetRoleOptionId(AssaultMasterOption.CockingKillCoolReduceTime)); - this.reloadReduceTimePerStock = allOpt.GetValue( - GetRoleOptionId(AssaultMasterOption.ReloadReduceKillCoolTimePerStock)); - this.isResetCoolTimeWhenKill = allOpt.GetValue( - GetRoleOptionId(AssaultMasterOption.IsResetReloadCoolTimeWhenKill)); - this.timerReduceRate = 1.0f - allOpt.GetValue( - GetRoleOptionId(AssaultMasterOption.ReloadCoolTimeReduceRatePerHideStock)) / 100.0f; + var cate = this.Loader; + + this.stockMax = cate.GetValue( + AssaultMasterOption.StockLimit); + this.addStockWhenReport = cate.GetValue( + AssaultMasterOption.StockNumWhenReport); + this.addStockWhenMeetingButton = cate.GetValue( + AssaultMasterOption.StockNumWhenMeetingButton); + this.cockingReduceTime = cate.GetValue( + AssaultMasterOption.CockingKillCoolReduceTime); + this.reloadReduceTimePerStock = cate.GetValue( + AssaultMasterOption.ReloadReduceKillCoolTimePerStock); + this.isResetCoolTimeWhenKill = cate.GetValue( + AssaultMasterOption.IsResetReloadCoolTimeWhenKill); + this.timerReduceRate = 1.0f - cate.GetValue( + AssaultMasterOption.ReloadCoolTimeReduceRatePerHideStock) / 100.0f; this.stock = 0; this.timerStock = 0; - this.defaultReloadCoolTime = allOpt.GetValue( - GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime)); + this.defaultReloadCoolTime = cate.GetValue( + RoleAbilityCommonOption.AbilityCoolTime); this.curReloadCoolTime = this.defaultReloadCoolTime; diff --git a/ExtremeRoles/Roles/Solo/Impostor/Bomber.cs b/ExtremeRoles/Roles/Solo/Impostor/Bomber.cs index 9e6a94134..bceef0a9c 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Bomber.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Bomber.cs @@ -14,8 +14,14 @@ using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; + + using BepInEx.Unity.IL2CPP.Utils; + +using ExtremeRoles.Module.CustomOption.Factory; +using static UnityEngine.GridBrushBase; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Bomber : SingleRoleBase, IRoleAutoBuildAbility, IRoleUpdate @@ -65,9 +71,9 @@ public void CreateAbility() this.CreateAbilityCountButton( "setBomb", - Loader.CreateSpriteFromResources( - Path.BomberSetBomb), - CheckAbility, CleanUp, ForceCleanUp); + Resources.Loader.CreateSpriteFromResources( + Path.BomberSetBomb), + CheckAbility, CleanUp, ForceCleanUp); } public bool IsAbilityUse() @@ -103,45 +109,44 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 2, 5, 2.5f); - CreateIntOption( + IRoleAbility.CreateAbilityCountOption( + factory, 2, 5, 2.5f); + factory.CreateIntOption( BomberOption.ExplosionRange, - 2, 1, 5, 1, - parentOps); - CreateIntOption( + 2, 1, 5, 1); + factory.CreateIntOption( BomberOption.ExplosionKillChance, 50, 25, 75, 1, - parentOps, format: OptionUnit.Percentage); - CreateFloatOption( + format: OptionUnit.Percentage); + factory.CreateFloatOption( BomberOption.TimerMinTime, 15f, 5.0f, 30f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateFloatOption( + format: OptionUnit.Second); + factory.CreateFloatOption( BomberOption.TimerMaxTime, 60f, 45f, 75f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateBoolOption( + format: OptionUnit.Second); + factory.CreateBoolOption( BomberOption.TellExplosion, - true, parentOps); + true); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; - - this.timerMinTime = allOption.GetValue( - GetRoleOptionId(BomberOption.TimerMinTime)); - this.timerMaxTime = allOption.GetValue( - GetRoleOptionId(BomberOption.TimerMaxTime)); - this.explosionKillChance = allOption.GetValue( - GetRoleOptionId(BomberOption.ExplosionKillChance)); - this.explosionRange = allOption.GetValue( - GetRoleOptionId(BomberOption.ExplosionRange)); - this.tellExplosion = allOption.GetValue( - GetRoleOptionId(BomberOption.TellExplosion)); + var cate = this.Loader; + + this.timerMinTime = cate.GetValue( + BomberOption.TimerMinTime); + this.timerMaxTime = cate.GetValue( + BomberOption.TimerMaxTime); + this.explosionKillChance = cate.GetValue( + BomberOption.ExplosionKillChance); + this.explosionRange = cate.GetValue( + BomberOption.ExplosionRange); + this.tellExplosion = cate.GetValue( + BomberOption.TellExplosion); this.bombPlayerId = new Queue(); resetTimer(); @@ -155,7 +160,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -212,14 +217,14 @@ private HashSet getAllPlayerInExplosion( Vector2 truePosition = sourcePlayer.GetTruePosition(); - foreach (GameData.PlayerInfo playerInfo in + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (!playerInfo.Disconnected && !playerInfo.IsDead && (playerInfo.PlayerId != sourcePlayer.PlayerId) && - (!playerInfo.Object.inVent || ExtremeGameModeManager.Instance.ShipOption.CanKillVentInPlayer) && + (!playerInfo.Object.inVent || ExtremeGameModeManager.Instance.ShipOption.Vent.CanKillVentInPlayer) && (!ExtremeRoleManager.GameRole[playerInfo.PlayerId].IsImpostor() || playerInfo.PlayerId == rolePlayer.PlayerId)) { diff --git a/ExtremeRoles/Roles/Solo/Impostor/BountyHunter.cs b/ExtremeRoles/Roles/Solo/Impostor/BountyHunter.cs index a487c749a..07c285bcd 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/BountyHunter.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/BountyHunter.cs @@ -6,12 +6,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; using AmongUs.GameOptions; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class BountyHunter : SingleRoleBase, IRoleUpdate, IRoleSpecialSetUp, IRoleResetMeeting @@ -52,7 +55,7 @@ public BountyHunter() : base( true, false, true, true) { } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { this.setNewTarget(); @@ -104,29 +107,29 @@ public override bool TryRolePlayerKillTo( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( BountyHunterOption.TargetUpdateTime, 60f, 30.0f, 120f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( BountyHunterOption.TargetKillCoolTime, 5f, 1.0f, 60f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( BountyHunterOption.NoneTargetKillCoolTime, 45f, 1.0f, 120f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - var arrowOption = CreateBoolOption( + var arrowOption = factory.CreateBoolOption( BountyHunterOption.IsShowArrow, - false, parentOps); + false); - CreateFloatOption( + factory.CreateFloatOption( BountyHunterOption.ArrowUpdateCycle, 10f, 1.0f, 120f, 0.5f, arrowOption, format: OptionUnit.Second); @@ -145,20 +148,20 @@ protected override void RoleSpecificInit() this.defaultKillCool = this.KillCoolTime; - var allOption = OptionManager.Instance; + var cate = this.Loader; - this.changeTargetTime = allOption.GetValue( - GetRoleOptionId(BountyHunterOption.TargetUpdateTime)); - this.targetKillCool = allOption.GetValue( - GetRoleOptionId(BountyHunterOption.TargetKillCoolTime)); - this.noneTargetKillCool = allOption.GetValue( - GetRoleOptionId(BountyHunterOption.NoneTargetKillCoolTime)); - this.isShowArrow = allOption.GetValue( - GetRoleOptionId(BountyHunterOption.IsShowArrow)); + this.changeTargetTime = cate.GetValue( + BountyHunterOption.TargetUpdateTime); + this.targetKillCool = cate.GetValue( + BountyHunterOption.TargetKillCoolTime); + this.noneTargetKillCool = cate.GetValue( + BountyHunterOption.NoneTargetKillCoolTime); + this.isShowArrow = cate.GetValue( + BountyHunterOption.IsShowArrow); if (this.isShowArrow) { - this.targetArrowUpdateTime = allOption.GetValue( - GetRoleOptionId(BountyHunterOption.ArrowUpdateCycle)); + this.targetArrowUpdateTime = cate.GetValue( + BountyHunterOption.ArrowUpdateCycle); } this.targetArrowUpdateTimer = 0; this.targetTimer = 0; diff --git a/ExtremeRoles/Roles/Solo/Impostor/Carrier.cs b/ExtremeRoles/Roles/Solo/Impostor/Carrier.cs index 433047e4d..d2ac707c5 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Carrier.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Carrier.cs @@ -5,7 +5,7 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; @@ -13,6 +13,9 @@ using BepInEx.Unity.IL2CPP.Utils; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Carrier : SingleRoleBase, IRoleAutoBuildAbility, IRoleSpecialReset @@ -20,7 +23,7 @@ public sealed class Carrier : SingleRoleBase, IRoleAutoBuildAbility, IRoleSpecia private DeadBody carringBody; private float[] alphaValue; private bool canReportOnCarry; - private GameData.PlayerInfo targetBody; + private NetworkedPlayerInfo targetBody; public enum CarrierOption { @@ -141,8 +144,8 @@ public void CreateAbility() { this.CreateReclickableAbilityButton( "carry", - Loader.CreateSpriteFromResources( - Path.CarrierCarry), + Resources.Loader.CreateSpriteFromResources( + Path.CarrierCarry), abilityOff: this.CleanUp); } @@ -152,7 +155,7 @@ public bool IsAbilityUse() return IRoleAbility.IsCommonUse() && this.targetBody != null; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -203,27 +206,27 @@ public void CleanUp() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 5.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 5.0f); - CreateFloatOption( + factory.CreateFloatOption( CarrierOption.CarryDistance, - 1.0f, 1.0f, 5.0f, 0.5f, - parentOps); + 1.0f, 1.0f, 5.0f, 0.5f); - CreateBoolOption( + factory.CreateBoolOption( CarrierOption.CanReportOnCarry, - true, parentOps); + true); } protected override void RoleSpecificInit() { - this.carryDistance = OptionManager.Instance.GetValue( - GetRoleOptionId(CarrierOption.CarryDistance)); - this.canReportOnCarry = OptionManager.Instance.GetValue( - GetRoleOptionId(CarrierOption.CanReportOnCarry)); + var cate = this.Loader; + this.carryDistance = cate.GetValue( + CarrierOption.CarryDistance); + this.canReportOnCarry = cate.GetValue( + CarrierOption.CanReportOnCarry); } public void AllReset(PlayerControl rolePlayer) diff --git a/ExtremeRoles/Roles/Solo/Impostor/Commander.cs b/ExtremeRoles/Roles/Solo/Impostor/Commander.cs index e7b1af850..8e403c1d7 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Commander.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Commander.cs @@ -4,12 +4,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; using ExtremeRoles.Module.AbilityBehavior; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Commander : SingleRoleBase, IRoleAutoBuildAbility @@ -84,13 +87,13 @@ public void CreateAbility() { this.CreateAbilityCountButton( "attackCommand", - Loader.CreateSpriteFromResources( - Path.CommanderAttackCommand)); + Resources.Loader.CreateSpriteFromResources( + Path.CommanderAttackCommand)); } public bool IsAbilityUse() => IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -128,32 +131,32 @@ public override bool TryRolePlayerKillTo( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( CommanderOption.KillCoolReduceTime, - 2.0f, 0.5f, 5.0f, 0.1f, parentOps, + 2.0f, 0.5f, 5.0f, 0.1f, format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( CommanderOption.KillCoolReduceImpBonus, - 1.5f, 0.1f, 3.0f, 0.1f, parentOps, + 1.5f, 0.1f, 3.0f, 0.1f, format: OptionUnit.Second); - CreateIntOption( + factory.CreateIntOption( CommanderOption.IncreaseKillNum, - 2, 1, 3, 1, parentOps, + 2, 1, 3, 1, format: OptionUnit.Shot); - this.CreateAbilityCountOption(parentOps, 1, 3); + IRoleAbility.CreateAbilityCountOption(factory, 1, 3); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; - this.killCoolReduceTime = allOpt.GetValue( - GetRoleOptionId(CommanderOption.KillCoolReduceTime)); - this.killCoolImpNumBonus = allOpt.GetValue( - GetRoleOptionId(CommanderOption.KillCoolReduceImpBonus)); - this.increaseKillNum = allOpt.GetValue( - GetRoleOptionId(CommanderOption.IncreaseKillNum)); + var cate = this.Loader; + this.killCoolReduceTime = cate.GetValue( + CommanderOption.KillCoolReduceTime); + this.killCoolImpNumBonus = cate.GetValue( + CommanderOption.KillCoolReduceImpBonus); + this.increaseKillNum = cate.GetValue( + CommanderOption.IncreaseKillNum); this.killCount = 0; } diff --git a/ExtremeRoles/Roles/Solo/Impostor/Cracker.cs b/ExtremeRoles/Roles/Solo/Impostor/Cracker.cs index fa1d82f23..104baffe4 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Cracker.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Cracker.cs @@ -4,13 +4,16 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; using ExtremeRoles.Module.Interface; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; using ExtremeRoles.Compat; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Cracker : SingleRoleBase, IRoleAutoBuildAbility @@ -24,8 +27,8 @@ public CrackTrace(Vector3 pos) { this.body = new GameObject("CrackTrace"); this.image = this.body.AddComponent(); - this.image.sprite = Loader.CreateSpriteFromResources( - Path.CrackerCrackTrace, 300f); + this.image.sprite = Resources.Loader.CreateSpriteFromResources( + Path.CrackerCrackTrace, 300f); this.body.transform.position = pos; @@ -102,14 +105,14 @@ public void CreateAbility() { this.CreateAbilityCountButton( "crack", - Loader.CreateSpriteFromResources( - Path.CrackerCrack)); + Resources.Loader.CreateSpriteFromResources( + Path.CrackerCrack)); } public bool IsAbilityUse() { this.targetDeadBodyId = byte.MaxValue; - GameData.PlayerInfo info = Player.GetDeadBodyInfo( + NetworkedPlayerInfo info = Player.GetDeadBodyInfo( this.crackDistance); if (info != null) @@ -120,7 +123,7 @@ public bool IsAbilityUse() return IRoleAbility.IsCommonUse() && this.targetDeadBodyId != byte.MaxValue; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -145,26 +148,26 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 2, 5); + IRoleAbility.CreateAbilityCountOption( + factory, 2, 5); - CreateFloatOption( + factory.CreateFloatOption( CrackerOption.CanCrackDistance, - 1.0f, 1.0f, 5.0f, 0.5f, - parentOps); + 1.0f, 1.0f, 5.0f, 0.5f); - CreateBoolOption( + factory.CreateBoolOption( CrackerOption.RemoveDeadBody, - false, parentOps); + false); } protected override void RoleSpecificInit() { - this.crackDistance = OptionManager.Instance.GetValue( - GetRoleOptionId(CrackerOption.CanCrackDistance)); - this.IsRemoveDeadBody = OptionManager.Instance.GetValue( - GetRoleOptionId(CrackerOption.RemoveDeadBody)); + var cate = this.Loader; + this.crackDistance = cate.GetValue( + CrackerOption.CanCrackDistance); + this.IsRemoveDeadBody = cate.GetValue( + CrackerOption.RemoveDeadBody); } } diff --git a/ExtremeRoles/Roles/Solo/Impostor/Crewshroom.cs b/ExtremeRoles/Roles/Solo/Impostor/Crewshroom.cs index e3fb66077..efa8b1984 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Crewshroom.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Crewshroom.cs @@ -10,6 +10,11 @@ using UnityEngine; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; #nullable enable @@ -37,7 +42,7 @@ public void CreateAbility() { this.CreateAbilityCountButton( Translation.GetString("CrewshroomSet"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.CrewshroomSet)); } @@ -50,7 +55,7 @@ public override string GetIntroDescription() public bool IsAbilityUse() => IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -70,10 +75,11 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption(parentOps, 3, 50); - CreateFloatOption(Option.DelaySecond, 5.0f, 0.5f, 30.0f, 0.5f, parentOps, format:OptionUnit.Second); + IRoleAbility.CreateAbilityCountOption(factory, 3, 50); + factory.CreateFloatOption( + Option.DelaySecond, 5.0f, 0.5f, 30.0f, 0.5f, format:OptionUnit.Second); } protected override void RoleSpecificInit() @@ -81,7 +87,7 @@ protected override void RoleSpecificInit() ExtremeSystemTypeManager.Instance.TryAdd( ModedMushroomSystem.Type, new ModedMushroomSystem( - OptionManager.Instance.GetValue( - GetRoleOptionId(Option.DelaySecond)))); + this.Loader.GetValue( + Option.DelaySecond))); } } diff --git a/ExtremeRoles/Roles/Solo/Impostor/Evolver.cs b/ExtremeRoles/Roles/Solo/Impostor/Evolver.cs index 87d0cc14b..614e3463a 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Evolver.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Evolver.cs @@ -3,12 +3,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Evolver : SingleRoleBase, IRoleAutoBuildAbility @@ -23,7 +26,7 @@ public enum EvolverOption } - public GameData.PlayerInfo targetBody; + public NetworkedPlayerInfo targetBody; public byte eatingBodyId; private float eatingRange = 1.0f; @@ -63,8 +66,8 @@ public void CreateAbility() this.CreateAbilityCountButton( "evolve", - Loader.CreateSpriteFromResources( - Path.EvolverEvolved), + Resources.Loader.CreateSpriteFromResources( + Path.EvolverEvolved), checkAbility: CheckAbility, abilityOff: CleanUp, forceAbilityOff: ForceCleanUp); @@ -145,33 +148,32 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( EvolverOption.IsEvolvedAnimation, - true, parentOps); + true); - CreateBoolOption( + factory.CreateBoolOption( EvolverOption.IsEatingEndCleanBody, - true, parentOps); + true); - CreateFloatOption( + factory.CreateFloatOption( EvolverOption.EatingRange, - 2.5f, 0.5f, 5.0f, 0.5f, - parentOps); + 2.5f, 0.5f, 5.0f, 0.5f); - CreateIntOption( + factory.CreateIntOption( EvolverOption.KillCoolReduceRate, - 10, 1, 50, 1, parentOps, + 10, 1, 50, 1, format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( EvolverOption.KillCoolResuceRateMulti, 1.0f, 1.0f, 5.0f, 0.1f, - parentOps, format: OptionUnit.Multiplier); + format: OptionUnit.Multiplier); - this.CreateAbilityCountOption( - parentOps, 5, 10, 5.0f); + IRoleAbility.CreateAbilityCountOption( + factory, 5, 10, 5.0f); } protected override void RoleSpecificInit() @@ -185,18 +187,18 @@ protected override void RoleSpecificInit() this.defaultKillCoolTime = this.KillCoolTime; - var allOption = OptionManager.Instance; + var cate = this.Loader; - this.isEvolvdAnimation = allOption.GetValue( - GetRoleOptionId(EvolverOption.IsEvolvedAnimation)); - this.isEatingEndCleanBody = allOption.GetValue ( - GetRoleOptionId(EvolverOption.IsEatingEndCleanBody)); - this.eatingRange = allOption.GetValue( - GetRoleOptionId(EvolverOption.EatingRange)); - this.reduceRate = allOption.GetValue( - GetRoleOptionId(EvolverOption.KillCoolReduceRate)); - this.reruceMulti = allOption.GetValue( - GetRoleOptionId(EvolverOption.KillCoolResuceRateMulti)); + this.isEvolvdAnimation = cate.GetValue( + EvolverOption.IsEvolvedAnimation); + this.isEatingEndCleanBody = cate.GetValue( + EvolverOption.IsEatingEndCleanBody); + this.eatingRange = cate.GetValue( + EvolverOption.EatingRange); + this.reduceRate = cate.GetValue( + EvolverOption.KillCoolReduceRate); + this.reruceMulti = cate.GetValue( + EvolverOption.KillCoolResuceRateMulti); this.eatingText = Translation.GetString("eating"); @@ -207,7 +209,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Impostor/Faker.cs b/ExtremeRoles/Roles/Solo/Impostor/Faker.cs index 9e3f6eacc..5d4163008 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Faker.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Faker.cs @@ -9,6 +9,11 @@ using ExtremeRoles.Module.SystemType; using ExtremeRoles.Module.SystemType.Roles; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Faker : SingleRoleBase, IRoleAutoBuildAbility @@ -46,9 +51,9 @@ public Faker() : base( public void CreateAbility() { - this.deadBodyDummy = Loader.CreateSpriteFromResources( + this.deadBodyDummy = Resources.Loader.CreateSpriteFromResources( Path.FakerDummyDeadBody, 115f); - this.playerDummy = Loader.CreateSpriteFromResources( + this.playerDummy = Resources.Loader.CreateSpriteFromResources( Path.FakerDummyPlayer, 115f); this.deadBodyDummyStr = Translation.GetString("dummyDeadBody"); @@ -70,7 +75,7 @@ public bool IsAbilityUse() return IRoleAbility.IsCommonUse(); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -126,10 +131,10 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps); + IRoleAbility.CreateCommonAbilityOption( + factory); } protected override void RoleSpecificInit() diff --git a/ExtremeRoles/Roles/Solo/Impostor/Hypnotist.cs b/ExtremeRoles/Roles/Solo/Impostor/Hypnotist.cs index 4f9ae51b8..edda8f06a 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Hypnotist.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Hypnotist.cs @@ -27,6 +27,11 @@ using ExtremeRoles.Patches; using ExtremeRoles.Compat; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; #nullable enable @@ -337,7 +342,7 @@ public void ResetOnMeetingStart() this.isActiveTimer = false; } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { updateAwakeCheck(exiledPlayer); @@ -569,60 +574,51 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( HypnotistOption.AwakeCheckImpostorNum, - 1, 1, GameSystem.MaxImposterNum, 1, - parentOps); - CreateIntOption( + 1, 1, GameSystem.MaxImposterNum, 1); + factory.CreateIntOption( HypnotistOption.AwakeCheckTaskGage, 60, 0, 100, 10, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( HypnotistOption.AwakeKillCount, - 2, 0, 5, 1, parentOps, + 2, 0, 5, 1, format: OptionUnit.Shot); - CreateFloatOption( + factory.CreateFloatOption( HypnotistOption.Range, - 1.6f, 0.5f, 5.0f, 0.1f, - parentOps); + 1.6f, 0.5f, 5.0f, 0.1f); - this.CreateAbilityCountOption(parentOps, 1, 5); + IRoleAbility.CreateAbilityCountOption(factory, 1, 5); - CreateFloatOption( + factory.CreateFloatOption( HypnotistOption.HideArrowRange, - 10.0f, 5.0f, 25.0f, 0.5f, - parentOps); - CreateIntOption( + 10.0f, 5.0f, 25.0f, 0.5f); + factory.CreateIntOption( HypnotistOption.DefaultRedAbilityPart, - 0, 0, 10, 1, - parentOps); - CreateFloatOption( + 0, 0, 10, 1); + factory.CreateFloatOption( HypnotistOption.HideKillButtonTime, 15.0f, 2.5f, 60.0f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateIntOption( + factory.CreateIntOption( HypnotistOption.DollKillCoolReduceRate, 10, 0, 75, 1, - parentOps, format: OptionUnit.Percentage); - CreateBoolOption( + factory.CreateBoolOption( HypnotistOption.IsResetKillCoolWhenDollKill, - true, parentOps); - CreateFloatOption( + true); + factory.CreateFloatOption( HypnotistOption.DollCrakingCoolTime, 30.0f, 0.5f, 120.0f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( HypnotistOption.DollCrakingActiveTime, 3.0f, 0.5f, 60.0f, 0.5f, - parentOps, format: OptionUnit.Second); } @@ -638,33 +634,33 @@ protected override void RoleSpecificInit() this.defaultKillCool = this.KillCoolTime; } - var allOpt = OptionManager.Instance; - this.awakeCheckImpNum = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.AwakeCheckImpostorNum)); - this.awakeCheckTaskGage = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.AwakeCheckTaskGage)) / 100.0f; - this.awakeKillCount = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.AwakeKillCount)); + var cate = this.Loader; + this.awakeCheckImpNum = cate.GetValue( + HypnotistOption.AwakeCheckImpostorNum); + this.awakeCheckTaskGage = cate.GetValue( + HypnotistOption.AwakeCheckTaskGage) / 100.0f; + this.awakeKillCount = cate.GetValue( + HypnotistOption.AwakeKillCount); - this.range = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.Range)); + this.range = cate.GetValue( + HypnotistOption.Range); - this.hideDistance = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.HideArrowRange)); - this.isResetKillCoolWhenDollKill = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.IsResetKillCoolWhenDollKill)); - this.dollKillCoolReduceRate = (1.0f - (allOpt.GetValue( - GetRoleOptionId(HypnotistOption.DollKillCoolReduceRate)) / 100.0f)); - this.defaultRedAbilityPartNum = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.DefaultRedAbilityPart)); + this.hideDistance = cate.GetValue( + HypnotistOption.HideArrowRange); + this.isResetKillCoolWhenDollKill = cate.GetValue( + HypnotistOption.IsResetKillCoolWhenDollKill); + this.dollKillCoolReduceRate = (1.0f - (cate.GetValue( + HypnotistOption.DollKillCoolReduceRate) / 100.0f)); + this.defaultRedAbilityPartNum = cate.GetValue( + HypnotistOption.DefaultRedAbilityPart); - this.DollCrakingActiveTime = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.DollCrakingActiveTime)); - this.DollCrakingCoolTime = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.DollCrakingCoolTime)); + this.DollCrakingActiveTime = cate.GetValue( + HypnotistOption.DollCrakingActiveTime); + this.DollCrakingCoolTime = cate.GetValue( + HypnotistOption.DollCrakingCoolTime); - this.defaultTimer = allOpt.GetValue( - GetRoleOptionId(HypnotistOption.HideKillButtonTime)); + this.defaultTimer = cate.GetValue( + HypnotistOption.HideKillButtonTime); this.canAwakeNow = this.awakeCheckImpNum >= curOption.GetInt(Int32OptionNames.NumImpostors) && @@ -810,7 +806,7 @@ private T setParts(in Vector3 pos) where T : AbilityPartBase return abilityPart; } - private void updateAwakeCheck(GameData.PlayerInfo? ignorePlayer) + private void updateAwakeCheck(NetworkedPlayerInfo? ignorePlayer) { int impNum = 0; @@ -1047,7 +1043,7 @@ public void RemoveParent(byte rolePlayerId) } public void ModifiedWinPlayer( - GameData.PlayerInfo rolePlayerInfo, + NetworkedPlayerInfo rolePlayerInfo, GameOverReason reason, ref ExtremeGameResult.WinnerTempData winner) { @@ -1209,7 +1205,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -1278,10 +1274,14 @@ public override string GetFullDescription() var hypno = Player.GetPlayerControlById(this.hypnotistPlayerId); string fullDesc = base.GetFullDescription(); - if (!hypno) { return fullDesc; } + if (hypno == null || + hypno.Data == null) + { + return fullDesc; + } return string.Format( - fullDesc, hypno.Data?.PlayerName); + fullDesc, hypno.Data.PlayerName); } public override bool IsSameTeam(SingleRoleBase targetRole) @@ -1304,7 +1304,7 @@ public override bool IsSameTeam(SingleRoleBase targetRole) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { throw new Exception("Don't call this class method!!"); } diff --git a/ExtremeRoles/Roles/Solo/Impostor/LastWolf.cs b/ExtremeRoles/Roles/Solo/Impostor/LastWolf.cs index f9e72dbad..ad79764d5 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/LastWolf.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/LastWolf.cs @@ -5,12 +5,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class LastWolf : SingleRoleBase, IRoleAutoBuildAbility, IRoleAwake @@ -111,7 +114,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -260,48 +263,44 @@ public override bool TryRolePlayerKillTo( protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( LastWolfOption.AwakeImpostorNum, - 1, 1, GameSystem.MaxImposterNum, 1, - parentOps); + 1, 1, GameSystem.MaxImposterNum, 1); - CreateFloatOption( + factory.CreateFloatOption( LastWolfOption.DeadPlayerNumBonus, 1.0f, 2.0f, 6.5f, 0.1f, - parentOps, format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( LastWolfOption.KillPlayerNumBonus, 2.5f, 4.0f, 10.0f, 0.1f, - parentOps, format: OptionUnit.Percentage); - this.CreateCommonAbilityOption( - parentOps, 10.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 10.0f); - CreateFloatOption( + factory.CreateFloatOption( LastWolfOption.LightOffVision, - 0.1f, 0.0f, 1.0f, 0.1f, - parentOps); + 0.1f, 0.0f, 1.0f, 0.1f); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var cate = this.Loader; - this.awakeImpNum = allOpt.GetValue( - GetRoleOptionId(LastWolfOption.AwakeImpostorNum)); + this.awakeImpNum = cate.GetValue( + LastWolfOption.AwakeImpostorNum); - this.noneAwakeKillBonus = allOpt.GetValue( - GetRoleOptionId(LastWolfOption.KillPlayerNumBonus)); - this.deadPlayerKillBonus = allOpt.GetValue( - GetRoleOptionId(LastWolfOption.DeadPlayerNumBonus)); + this.noneAwakeKillBonus = cate.GetValue( + LastWolfOption.KillPlayerNumBonus); + this.deadPlayerKillBonus = cate.GetValue( + LastWolfOption.DeadPlayerNumBonus); - LightOffVision = allOpt.GetValue( - GetRoleOptionId(LastWolfOption.LightOffVision)); + LightOffVision = cate.GetValue( + LastWolfOption.LightOffVision); this.noneAwakeKillCount = 0; diff --git a/ExtremeRoles/Roles/Solo/Impostor/Magician.cs b/ExtremeRoles/Roles/Solo/Impostor/Magician.cs index 362c11a1b..32bcf0bcb 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Magician.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Magician.cs @@ -14,6 +14,11 @@ using ExtremeRoles.Performance; using ExtremeRoles.Module.CustomMonoBehaviour.Minigames; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Magician : SingleRoleBase, IRoleAutoBuildAbility @@ -55,13 +60,13 @@ public void CreateAbility() { this.CreateAbilityCountButton( "juggling", - Loader.CreateSpriteFromResources( - Path.MagicianJuggling)); + Resources.Loader.CreateSpriteFromResources( + Path.MagicianJuggling)); } public bool IsAbilityUse() => IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -131,35 +136,35 @@ public bool UseAbility() return true; } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption(parentOps, 1, 10); + IRoleAbility.CreateAbilityCountOption(factory, 1, 10); - CreateIntOption( + factory.CreateIntOption( MagicianOption.TeleportTargetRate, - 100, 10, 100, 10, parentOps, + 100, 10, 100, 10, format: OptionUnit.Percentage); - CreateBoolOption( + factory.CreateBoolOption( MagicianOption.DupeTeleportTargetTo, - true, parentOps); - CreateBoolOption( + true); + factory.CreateBoolOption( MagicianOption.IncludeSpawnPoint, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( MagicianOption.IncludeRolePlayer, - false, parentOps); + false); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; - this.teleportRate = (float)allOption.GetValue( - GetRoleOptionId(MagicianOption.TeleportTargetRate)) / 100.0f; - this.dupeTeleportTarget = allOption.GetValue( - GetRoleOptionId(MagicianOption.DupeTeleportTargetTo)); - this.includeRolePlayer = allOption.GetValue( - GetRoleOptionId(MagicianOption.IncludeSpawnPoint)); - this.includeSpawnPoint = allOption.GetValue( - GetRoleOptionId(MagicianOption.IncludeRolePlayer)); + var cate = this.Loader; + this.teleportRate = (float)cate.GetValue( + MagicianOption.TeleportTargetRate) / 100.0f; + this.dupeTeleportTarget = cate.GetValue( + MagicianOption.DupeTeleportTargetTo); + this.includeRolePlayer = cate.GetValue( + MagicianOption.IncludeSpawnPoint); + this.includeSpawnPoint = cate.GetValue( + MagicianOption.IncludeRolePlayer); } } diff --git a/ExtremeRoles/Roles/Solo/Impostor/Mery.cs b/ExtremeRoles/Roles/Solo/Impostor/Mery.cs index 198feefa7..eae6ef276 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Mery.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Mery.cs @@ -13,11 +13,14 @@ using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Extension.Ship; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Compat; using AmongUs.GameOptions; using ExtremeRoles.Helper; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Mery : SingleRoleBase, IRoleAutoBuildAbility @@ -41,8 +44,8 @@ public Camp( { this.body = new GameObject("MaryCamp"); this.img = this.body.AddComponent(); - this.img.sprite = Loader.CreateSpriteFromResources( - Path.MeryNoneActiveVent, 125f); + this.img.sprite = Resources.Loader.CreateSpriteFromResources( + Path.MeryNoneActiveVent, 125f); this.body.SetActive(canSee); this.body.transform.position = new Vector3( @@ -68,7 +71,7 @@ public void Update(int index) this.body.transform.position.x, this.body.transform.position.y); - foreach (GameData.PlayerInfo playerInfo in + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (playerInfo == null) { continue; } @@ -137,7 +140,7 @@ public Vent GetConvertedVent() vent.myAnim.enabled = false; } - ventRenderer.sprite = Loader.CreateSpriteFromResources( + ventRenderer.sprite = Resources.Loader.CreateSpriteFromResources( string.Format(Path.MeryCustomVentAnime, "0"), 125f); vent.myRend = ventRenderer; @@ -288,7 +291,7 @@ public void CreateAbility() this.CreateAbilityCountButton( "setCamp", - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( string.Format(Path.MeryCustomVentAnime, "0"))); } @@ -316,27 +319,27 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 3, 5); + IRoleAbility.CreateAbilityCountOption( + factory, 3, 5); - CreateIntOption( + factory.CreateIntOption( MeryOption.ActiveNum, - 3, 1, 5, 1, parentOps); - CreateFloatOption( + 3, 1, 5, 1); + factory.CreateFloatOption( MeryOption.ActiveRange, - 2.0f, 0.1f, 3.0f, 0.1f, parentOps); + 2.0f, 0.1f, 3.0f, 0.1f); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; + var cate = this.Loader; - this.ActiveNum = allOption.GetValue( - GetRoleOptionId(MeryOption.ActiveNum)); - this.ActiveRange = allOption.GetValue( - GetRoleOptionId(MeryOption.ActiveRange)); + this.ActiveNum = cate.GetValue( + MeryOption.ActiveNum); + this.ActiveRange = cate.GetValue( + MeryOption.ActiveRange); } @@ -345,7 +348,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Impostor/OverLoader.cs b/ExtremeRoles/Roles/Solo/Impostor/OverLoader.cs index db4a47c26..5b144123f 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/OverLoader.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/OverLoader.cs @@ -5,7 +5,7 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; @@ -13,6 +13,9 @@ using ExtremeRoles.Performance.Il2Cpp; +using ExtremeRoles.Module.CustomOption.Factory; + + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class OverLoader : SingleRoleBase, IRoleAutoBuildAbility, IRoleAwake @@ -88,17 +91,17 @@ public void CreateAbility() { this.CreatePassiveAbilityButton( "overLoad", "downLoad", - Loader.CreateSpriteFromResources( - Path.OverLoaderOverLoad), - Loader.CreateSpriteFromResources( - Path.OverLoaderDownLoad), + Resources.Loader.CreateSpriteFromResources( + Path.OverLoaderOverLoad), + Resources.Loader.CreateSpriteFromResources( + Path.OverLoaderDownLoad), this.CleanUp); } public bool IsAbilityUse() => this.IsAwake && IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -243,29 +246,27 @@ public override Color GetNameColor(bool isTruthColor = false) protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( OverLoaderOption.AwakeImpostorNum, GameSystem.MaxImposterNum, 1, - GameSystem.MaxImposterNum, 1, - parentOps); + GameSystem.MaxImposterNum, 1); - CreateIntOption( + factory.CreateIntOption( OverLoaderOption.AwakeKillCount, - 0, 0, 3, 1, - parentOps); + 0, 0, 3, 1); - this.CreateCommonAbilityOption( - parentOps, 7.5f); + IRoleAbility.CreateCommonAbilityOption( + factory, 7.5f); - CreateFloatOption( + factory.CreateFloatOption( OverLoaderOption.KillCoolReduceRate, - 75.0f, 50.0f, 90.0f, 1.0f, parentOps, + 75.0f, 50.0f, 90.0f, 1.0f, format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( OverLoaderOption.MoveSpeed, - 1.5f, 1.0f, 3.0f, 0.1f, parentOps, + 1.5f, 1.0f, 3.0f, 0.1f, format: OptionUnit.Multiplier); } @@ -288,17 +289,17 @@ protected override void RoleSpecificInit() this.defaultKillRange = this.KillRange; this.IsOverLoad = false; - var allOption = OptionManager.Instance; + var cate = this.Loader; - this.awakeImpNum = allOption.GetValue( - GetRoleOptionId(OverLoaderOption.AwakeImpostorNum)); - this.awakeKillCount = allOption.GetValue( - GetRoleOptionId(OverLoaderOption.AwakeKillCount)); + this.awakeImpNum = cate.GetValue( + OverLoaderOption.AwakeImpostorNum); + this.awakeKillCount = cate.GetValue( + OverLoaderOption.AwakeKillCount); - this.MoveSpeed = allOption.GetValue( - GetRoleOptionId(OverLoaderOption.MoveSpeed)); - this.reduceRate = allOption.GetValue( - GetRoleOptionId(OverLoaderOption.KillCoolReduceRate)); + this.MoveSpeed = cate.GetValue( + OverLoaderOption.MoveSpeed); + this.reduceRate = cate.GetValue( + OverLoaderOption.KillCoolReduceRate); this.killCount = 0; diff --git a/ExtremeRoles/Roles/Solo/Impostor/Painter.cs b/ExtremeRoles/Roles/Solo/Impostor/Painter.cs index 9b9822085..7cccd0e8e 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Painter.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Painter.cs @@ -6,6 +6,11 @@ using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Painter : SingleRoleBase, IRoleAutoBuildAbility @@ -81,10 +86,10 @@ public static void PaintDeadBody( public void CreateAbility() { - this.randomColorPaintImage = Loader.CreateSpriteFromResources( - Path.PainterPaintRandom); - this.transColorPaintImage = Loader.CreateSpriteFromResources( - Path.PainterPaintTrans); + this.randomColorPaintImage = Resources.Loader.CreateSpriteFromResources( + Path.PainterPaintRandom); + this.transColorPaintImage = Resources.Loader.CreateSpriteFromResources( + Path.PainterPaintTrans); this.CreateNormalAbilityButton( "paint", this.randomColorPaintImage); @@ -93,7 +98,7 @@ public void CreateAbility() public bool IsAbilityUse() { this.targetDeadBodyId = byte.MaxValue; - GameData.PlayerInfo info = Player.GetDeadBodyInfo( + NetworkedPlayerInfo info = Player.GetDeadBodyInfo( this.paintDistance); this.Button.Behavior.SetButtonImage( @@ -108,7 +113,7 @@ public bool IsAbilityUse() return IRoleAbility.IsCommonUse() && this.targetDeadBodyId != byte.MaxValue; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -135,20 +140,19 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps); + IRoleAbility.CreateCommonAbilityOption( + factory); - CreateFloatOption( + factory.CreateFloatOption( PainterOption.CanPaintDistance, - 1.0f, 1.0f, 5.0f, 0.5f, - parentOps); + 1.0f, 1.0f, 5.0f, 0.5f); } protected override void RoleSpecificInit() { - this.paintDistance = OptionManager.Instance.GetValue( - GetRoleOptionId(PainterOption.CanPaintDistance)); + this.paintDistance = this.Loader.GetValue( + PainterOption.CanPaintDistance); } } diff --git a/ExtremeRoles/Roles/Solo/Impostor/PsychoKiller.cs b/ExtremeRoles/Roles/Solo/Impostor/PsychoKiller.cs index da02246f4..3eb85f65e 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/PsychoKiller.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/PsychoKiller.cs @@ -9,6 +9,11 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class PsychoKiller : @@ -101,7 +106,7 @@ public void Update(PlayerControl rolePlayer) byte.MaxValue); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { if (this.hasSelfTimer) { @@ -164,39 +169,37 @@ public override bool TryRolePlayerKillTo( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( PsychoKillerOption.KillCoolReduceRate, - 5, 1, 15, 1, parentOps, + 5, 1, 15, 1, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( PsychoKillerOption.CombMax, - 2, 1, 5, 1, - parentOps); + 2, 1, 5, 1); - CreateBoolOption( + factory.CreateBoolOption( PsychoKillerOption.CombResetWhenMeeting, - true, parentOps); + true); - var hasSelfKillTimer = CreateBoolOption( + var hasSelfKillTimer = factory.CreateBoolOption( PsychoKillerOption.HasSelfKillTimer, - false, parentOps); - CreateFloatOption( + false); + factory.CreateFloatOption( PsychoKillerOption.SelfKillTimerTime, 30.0f, 5.0f, 120.0f, 0.5f, hasSelfKillTimer, format: OptionUnit.Second); - var timerOpt = CreateBoolOption( + var timerOpt = factory.CreateBoolOption( PsychoKillerOption.IsForceRestartWhenMeetingEnd, false, hasSelfKillTimer); - CreateBoolOption( + factory.CreateBoolOption( PsychoKillerOption.IsDiactiveUntilKillWhenMeetingEnd, false, timerOpt, - invert: true, - enableCheckOption: parentOps); - CreateIntOption( + invert: true); + factory.CreateIntOption( PsychoKillerOption.SelfKillTimerModRate, 0, -50, 50, 1, hasSelfKillTimer, format: OptionUnit.Percentage); @@ -212,26 +215,26 @@ protected override void RoleSpecificInit() FloatOptionNames.KillCooldown); } - var allOption = OptionManager.Instance; - - this.reduceRate = allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.KillCoolReduceRate)); - this.isResetMeeting = allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.CombResetWhenMeeting)); - this.combMax= allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.CombMax)); - - this.hasSelfTimer = allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.HasSelfKillTimer)); - this.defaultTimer = allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.SelfKillTimerTime)); - this.isForceRestartWhenMeetingEnd = allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.IsForceRestartWhenMeetingEnd)); - this.isDiactiveUntilKillWhenMeetingEnd = allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.IsDiactiveUntilKillWhenMeetingEnd)); - - this.timerModRate = (100.0f - (float)allOption.GetValue( - GetRoleOptionId(PsychoKillerOption.SelfKillTimerModRate))) / 100.0f; + var cate = this.Loader; + + this.reduceRate = cate.GetValue( + PsychoKillerOption.KillCoolReduceRate); + this.isResetMeeting = cate.GetValue( + PsychoKillerOption.CombResetWhenMeeting); + this.combMax= cate.GetValue( + PsychoKillerOption.CombMax); + + this.hasSelfTimer = cate.GetValue( + PsychoKillerOption.HasSelfKillTimer); + this.defaultTimer = cate.GetValue( + PsychoKillerOption.SelfKillTimerTime); + this.isForceRestartWhenMeetingEnd = cate.GetValue( + PsychoKillerOption.IsForceRestartWhenMeetingEnd); + this.isDiactiveUntilKillWhenMeetingEnd = cate.GetValue( + PsychoKillerOption.IsDiactiveUntilKillWhenMeetingEnd); + + this.timerModRate = (100.0f - (float)cate.GetValue( + PsychoKillerOption.SelfKillTimerModRate)) / 100.0f; if (this.hasSelfTimer) { this.timer = this.defaultTimer; diff --git a/ExtremeRoles/Roles/Solo/Impostor/SandWorm.cs b/ExtremeRoles/Roles/Solo/Impostor/SandWorm.cs index db3dd757a..f494a26c4 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/SandWorm.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/SandWorm.cs @@ -13,6 +13,11 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Extension.VentModule; + +using ExtremeRoles.Module.CustomOption.Factory; + + + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class SandWorm : SingleRoleBase, IRoleAbility @@ -175,7 +180,7 @@ public bool IsAbilityUse() return isVentIn() && this.targetPlayer != null; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -219,39 +224,39 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( SandWormOption.KillCoolPenalty, 5.0f, 1.0f, 10.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( SandWormOption.AssaultKillCoolReduce, 3.0f, 1.0f, 5.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( SandWormOption.AssaultRange, - 2.0f, 0.1f, 3.0f, 0.1f, - parentOps); + 2.0f, 0.1f, 3.0f, 0.1f); - CreateFloatOption( + factory.CreateFloatOption( RoleAbilityCommonOption.AbilityCoolTime, 15.0f, 0.5f, 45.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); } protected override void RoleSpecificInit() { - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(SandWormOption.AssaultRange)); - - this.killPenalty = OptionManager.Instance.GetValue( - GetRoleOptionId(SandWormOption.KillCoolPenalty)); - this.killBonus = OptionManager.Instance.GetValue( - GetRoleOptionId(SandWormOption.AssaultKillCoolReduce)); + var cate = this.Loader; + this.range = cate.GetValue( + SandWormOption.AssaultRange); + + this.killPenalty = cate.GetValue( + SandWormOption.KillCoolPenalty); + this.killBonus = cate.GetValue( + SandWormOption.AssaultKillCoolReduce); if (!this.HasOtherKillCool) { diff --git a/ExtremeRoles/Roles/Solo/Impostor/Shooter.cs b/ExtremeRoles/Roles/Solo/Impostor/Shooter.cs index 0f58a7115..1a5e9755a 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Shooter.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Shooter.cs @@ -4,7 +4,7 @@ using AmongUs.GameOptions; using ExtremeRoles.Helper; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Roles.Solo.Crewmate; @@ -13,6 +13,9 @@ using TMPro; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Shooter : @@ -149,7 +152,7 @@ public void SetSprite(SpriteRenderer render) } public void HookReportButton( - PlayerControl rolePlayer, GameData.PlayerInfo reporter) + PlayerControl rolePlayer, NetworkedPlayerInfo reporter) { this.canShootThisMeeting = true; if (rolePlayer.PlayerId == reporter.PlayerId) @@ -159,7 +162,7 @@ public void HookReportButton( } public void HookBodyReport( - PlayerControl rolePlayer, GameData.PlayerInfo reporter, GameData.PlayerInfo reportBody) + PlayerControl rolePlayer, NetworkedPlayerInfo reporter, NetworkedPlayerInfo reportBody) { this.canShootThisMeeting = true; } @@ -180,7 +183,7 @@ public void Shoot() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { chargeInfoSetActive(true); this.canShootThisMeeting = true; @@ -372,103 +375,99 @@ public override bool TryRolePlayerKillTo( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( ShooterOption.IsInitAwake, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( ShooterOption.AwakeKillNum, 1, 0, 5, 1, - parentOps, format: OptionUnit.Shot); - CreateIntOption( + factory.CreateIntOption( ShooterOption.AwakeImpNum, - 1, 1, GameSystem.MaxImposterNum, 1, - parentOps); + 1, 1, GameSystem.MaxImposterNum, 1); - CreateBoolOption( + factory.CreateBoolOption( ShooterOption.NoneAwakeWhenShoot, - true, parentOps); - CreateFloatOption( + true); + factory.CreateFloatOption( ShooterOption.ShootKillCoolPenalty, 5.0f, 0.0f, 30.0f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - var meetingOps = CreateBoolOption( + var meetingOps = factory.CreateBoolOption( ShooterOption.CanCallMeeting, - true, parentOps); + true); - CreateBoolOption( + factory.CreateBoolOption( ShooterOption.CanShootSelfCallMeeting, true, meetingOps, - invert: true, - enableCheckOption: parentOps); + invert: true); - var maxShootOps = CreateIntOption( + var maxShootOps = factory.CreateIntOption( ShooterOption.MaxShootNum, - 1, 1, 14, 1, parentOps, + 1, 1, 14, 1, format: OptionUnit.Shot); - var initShootOps = CreateIntDynamicOption( + var initShootOps = factory.CreateIntDynamicOption( ShooterOption.InitShootNum, - 0, 0, 1, parentOps, + 0, 0, 1, format: OptionUnit.Shot, tempMaxValue: 14); - var maxMeetingShootOps = CreateIntDynamicOption( + var maxMeetingShootOps = factory.CreateIntDynamicOption( ShooterOption.MaxMeetingShootNum, - 1, 1, 1, parentOps, + 1, 1, 1, format: OptionUnit.Shot, tempMaxValue: 14); - CreateFloatOption( + factory.CreateFloatOption( ShooterOption.ShootChargeTime, 90.0f, 30.0f, 120.0f, 5.0f, - parentOps, format: OptionUnit.Second); - CreateIntOption( + format: OptionUnit.Second); + factory.CreateIntOption( ShooterOption.ShootKillNum, 1, 0, 5, 1, - parentOps, format: OptionUnit.Shot); - maxShootOps.SetUpdateOption(initShootOps); - maxShootOps.SetUpdateOption(maxMeetingShootOps); + maxShootOps.AddWithUpdate(initShootOps); + maxShootOps.AddWithUpdate(maxMeetingShootOps); } protected override void RoleSpecificInit() { - var allOps = OptionManager.Instance; - - this.isAwake = allOps.GetValue( - GetRoleOptionId(ShooterOption.IsInitAwake)); - - this.awakeKillCount = allOps.GetValue( - GetRoleOptionId(ShooterOption.AwakeKillNum)); - this.awakeImpNum = allOps.GetValue( - GetRoleOptionId(ShooterOption.AwakeImpNum)); - - this.isNoneAwakeWhenShoot = allOps.GetValue( - GetRoleOptionId(ShooterOption.NoneAwakeWhenShoot)); - - this.awakedCallMeeting = allOps.GetValue( - GetRoleOptionId(ShooterOption.CanCallMeeting)); - this.canShootSelfCallMeeting = allOps.GetValue( - GetRoleOptionId(ShooterOption.CanShootSelfCallMeeting)); - - this.maxShootNum = allOps.GetValue( - GetRoleOptionId(ShooterOption.MaxShootNum)); - this.curShootNum = allOps.GetValue( - GetRoleOptionId(ShooterOption.InitShootNum)); - this.maxMeetingShootNum = allOps.GetValue( - GetRoleOptionId(ShooterOption.MaxMeetingShootNum)); - this.chargeTime = allOps.GetValue( - GetRoleOptionId(ShooterOption.ShootChargeTime)); - this.chargeKillNum = allOps.GetValue( - GetRoleOptionId(ShooterOption.ShootKillNum)); - this.killCoolPenalty = allOps.GetValue( - GetRoleOptionId(ShooterOption.ShootKillCoolPenalty)); + var cate = this.Loader; + + this.isAwake = cate.GetValue( + ShooterOption.IsInitAwake); + + this.awakeKillCount = cate.GetValue( + ShooterOption.AwakeKillNum); + this.awakeImpNum = cate.GetValue( + ShooterOption.AwakeImpNum); + + this.isNoneAwakeWhenShoot = cate.GetValue( + ShooterOption.NoneAwakeWhenShoot); + + this.awakedCallMeeting = cate.GetValue( + ShooterOption.CanCallMeeting); + this.canShootSelfCallMeeting = cate.GetValue( + ShooterOption.CanShootSelfCallMeeting); + + this.maxShootNum = cate.GetValue( + ShooterOption.MaxShootNum); + this.curShootNum = cate.GetValue( + ShooterOption.InitShootNum); + this.maxMeetingShootNum = cate.GetValue( + ShooterOption.MaxMeetingShootNum); + this.chargeTime = cate.GetValue( + ShooterOption.ShootChargeTime); + this.chargeKillNum = cate.GetValue( + ShooterOption.ShootKillNum); + this.killCoolPenalty = cate.GetValue( + ShooterOption.ShootKillCoolPenalty); this.isNoneAwakeWhenShoot = diff --git a/ExtremeRoles/Roles/Solo/Impostor/SlaveDriver.cs b/ExtremeRoles/Roles/Solo/Impostor/SlaveDriver.cs index 8dc784995..7b3a9482a 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/SlaveDriver.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/SlaveDriver.cs @@ -11,6 +11,11 @@ using ExtremeRoles.Module.Interface; using Hazel; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class SlaveDriver : @@ -66,31 +71,32 @@ public override string GetRolePlayerNameTag(SingleRoleBase targetRole, byte targ } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( SlaveDriverOption.CanSeeTaskBar, - true, parentOps); - this.CreateAbilityCountOption(parentOps, 2, 10); - CreateIntOption( + true); + IRoleAbility.CreateAbilityCountOption(factory, 2, 10); + factory.CreateIntOption( SlaveDriverOption.RevartTaskNum, - 2, 1, 5, 1, parentOps); - CreateFloatOption( + 2, 1, 5, 1); + factory.CreateFloatOption( SlaveDriverOption.Range, - 0.75f, 0.25f, 3.5f, 0.25f, parentOps); + 0.75f, 0.25f, 3.5f, 0.25f); } protected override void RoleSpecificInit() { - this.CanSeeTaskBar = OptionManager.Instance.GetValue( - GetRoleOptionId(SlaveDriverOption.CanSeeTaskBar)); - this.revartTaskNum= OptionManager.Instance.GetValue( - GetRoleOptionId(SlaveDriverOption.RevartTaskNum)); - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(SlaveDriverOption.Range)); + var cate = this.Loader; + this.CanSeeTaskBar = cate.GetValue( + SlaveDriverOption.CanSeeTaskBar); + this.revartTaskNum= cate.GetValue( + SlaveDriverOption.RevartTaskNum); + this.range = cate.GetValue( + SlaveDriverOption.Range); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -100,7 +106,7 @@ public void ResetOnMeetingStart() this.target = byte.MaxValue; foreach (byte playerId in this.effectPlayer) { - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(playerId); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(playerId); if (player == null || !ExtremeRoleManager.GameRole[player.PlayerId].HasTask()) { continue; } @@ -129,7 +135,7 @@ public void ResetOnMeetingStart() else if (CachedShipStatus.Instance.ShortTasks.FirstOrDefault( (NormalPlayerTask t) => t.Index == taskId) != null) { - newTaskId = GameSystem.GetRandomNormalTaskId(); + newTaskId = GameSystem.GetRandomShortTaskId(); } else { diff --git a/ExtremeRoles/Roles/Solo/Impostor/Slime.cs b/ExtremeRoles/Roles/Solo/Impostor/Slime.cs index 661e7ae5a..d773cdec1 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Slime.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Slime.cs @@ -3,12 +3,15 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Slime : @@ -105,9 +108,9 @@ public void OnEndKill() public void CreateAbility() { this.CreateReclickableAbilityButton( - Translation.GetString("SlimeMorph"), - Loader.CreateSpriteFromResources( - Path.SlimeMorph), + Translation.GetString("SlimeMorph"), + Resources.Loader.CreateSpriteFromResources( + Path.SlimeMorph), checkAbility: IsAbilityActive, abilityOff: this.CleanUp); } @@ -130,7 +133,7 @@ public bool IsAbilityUse() GameSystem.IsValidConsole(localPlayer, this.targetConsole); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -183,10 +186,10 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateCommonAbilityOption( - parentOps, 30.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 30.0f); } protected override void RoleSpecificInit() diff --git a/ExtremeRoles/Roles/Solo/Impostor/Smasher.cs b/ExtremeRoles/Roles/Solo/Impostor/Smasher.cs index 59af098fb..1092191fa 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Smasher.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Smasher.cs @@ -1,11 +1,13 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Smasher : SingleRoleBase, IRoleAutoBuildAbility @@ -132,22 +134,22 @@ private void featKillPenalty(PlayerControl killer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 1, 14); + IRoleAbility.CreateAbilityCountOption( + factory, 1, 14); - CreateFloatOption( + factory.CreateFloatOption( SmasherOption.SmashPenaltyKillCool, - 4.0f, 0.0f, 30f, 0.5f, parentOps, + 4.0f, 0.0f, 30f, 0.5f, format: OptionUnit.Second); } protected override void RoleSpecificInit() { - this.penaltyKillCool = OptionManager.Instance.GetValue( - GetRoleOptionId(SmasherOption.SmashPenaltyKillCool)); + this.penaltyKillCool = this.Loader.GetValue( + SmasherOption.SmashPenaltyKillCool); } public void ResetOnMeetingStart() @@ -155,7 +157,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Impostor/SpecialImpostor.cs b/ExtremeRoles/Roles/Solo/Impostor/SpecialImpostor.cs index fbd068fe8..f66c405ff 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/SpecialImpostor.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/SpecialImpostor.cs @@ -1,6 +1,9 @@ -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class SpecialImpostor : SingleRoleBase @@ -13,11 +16,11 @@ public SpecialImpostor(): base( true, false, true, true) {} - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { return; } - + protected override void RoleSpecificInit() { return; diff --git a/ExtremeRoles/Roles/Solo/Impostor/Terorist.cs b/ExtremeRoles/Roles/Solo/Impostor/Terorist.cs index e8e7117bf..67e6f56a7 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Terorist.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Terorist.cs @@ -8,6 +8,11 @@ using ExtremeRoles.Extension.Il2Cpp; using ExtremeRoles.Resources; + +using ExtremeRoles.Module.CustomOption.Factory; + + + #nullable enable namespace ExtremeRoles.Roles.Solo.Impostor; @@ -42,7 +47,7 @@ public void CreateAbility() { this.CreateAbilityCountButton( Translation.GetString("TeroristBombSet"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.TeroristTeroSabotageButton)); } @@ -66,28 +71,28 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 5, 100); - CreateBoolOption( + IRoleAbility.CreateAbilityCountOption( + factory, 5, 100); + factory.CreateBoolOption( TeroristOption.CanActiveOtherSabotage, - false, parentOps); - CreateFloatOption( + false); + factory.CreateFloatOption( TeroristOption.ExplosionTime, 45.0f, 10.0f, 240.0f, 1.0f, - parentOps, format: OptionUnit.Second); - CreateIntOption( + format: OptionUnit.Second); + factory.CreateIntOption( TeroristOption.BombNum, - 3, 1, 6, 1, parentOps); - CreateFloatOption( + 3, 1, 6, 1); + factory.CreateFloatOption( TeroristOption.PlayerActivateTime, 3.0f, 0.25f, 10.0f, 0.25f, - parentOps, format: OptionUnit.Second); - var deadPlayerOpt = CreateBoolOption( + format: OptionUnit.Second); + var deadPlayerOpt = factory.CreateBoolOption( TeroristOption.CanUseDeadPlayer, - false, parentOps); - CreateFloatOption( + false); + factory.CreateFloatOption( TeroristOption.DeadPlayerActivateTime, 10.0f, 3.0f, 45.0f, 1.0f, deadPlayerOpt, format: OptionUnit.Second); @@ -101,24 +106,24 @@ protected override void RoleSpecificInit() this.saboSystem = saboSystem; } - var optionMng = OptionManager.Instance; - this.canActiveOtherSabotage = optionMng.GetValue( - GetRoleOptionId(TeroristOption.CanActiveOtherSabotage)); + var cate = this.Loader; + this.canActiveOtherSabotage = cate.GetValue( + TeroristOption.CanActiveOtherSabotage); var miniGameOption = new TeroristTeroSabotageSystem.MinigameOption( - optionMng.GetValue( - GetRoleOptionId(TeroristOption.PlayerActivateTime)), - optionMng.GetValue( - GetRoleOptionId(TeroristOption.CanUseDeadPlayer)), - optionMng.GetValue( - GetRoleOptionId(TeroristOption.DeadPlayerActivateTime))); + cate.GetValue( + TeroristOption.PlayerActivateTime), + cate.GetValue( + TeroristOption.CanUseDeadPlayer), + cate.GetValue( + TeroristOption.DeadPlayerActivateTime)); var sabotageOption = new TeroristTeroSabotageSystem.Option( - optionMng.GetValue( - GetRoleOptionId(TeroristOption.ExplosionTime)), - optionMng.GetValue( - GetRoleOptionId(TeroristOption.BombNum)), + cate.GetValue( + TeroristOption.ExplosionTime), + cate.GetValue( + TeroristOption.BombNum), miniGameOption); this.teroSabo = ExtremeSystemTypeManager.Instance.CreateOrGet( @@ -131,7 +136,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Impostor/Thief.cs b/ExtremeRoles/Roles/Solo/Impostor/Thief.cs index 79395e202..d55dc9ead 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Thief.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Thief.cs @@ -10,6 +10,10 @@ using UnityEngine.Video; + + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Solo.Impostor; @@ -26,7 +30,7 @@ public enum ThiefOption } - private GameData.PlayerInfo? targetBody; + private NetworkedPlayerInfo? targetBody; private byte targetPlayerId = byte.MaxValue; private float activeRange; private bool isAddEffect; @@ -52,9 +56,9 @@ public static void AddEffect(byte deadBody) effect.transform.localPosition = new Vector2(-0.25f, -0.15f); var player = effect.AddComponent(); - player.SetThum(Loader.CreateSpriteFromResources( + player.SetThum(Resources.Loader.CreateSpriteFromResources( Path.TheifMagicCircle)); - player.SetVideo(Loader.GetUnityObjectFromResources( + player.SetVideo(Resources.Loader.GetUnityObjectFromResources( Path.VideoAsset, string.Format( Path.VideoAssetPlaceHolder, Path.TheifMagicCircleVideo))); } @@ -63,8 +67,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "steal", - Loader.CreateSpriteFromResources( - Path.TheifMagicCircle), + Resources.Loader.CreateSpriteFromResources( + Path.TheifMagicCircle), checkAbility: CheckAbility, abilityOff: CleanUp, forceAbilityOff: ForceCleanUp); @@ -129,30 +133,30 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 2, 5, 2.0f); - CreateFloatOption(ThiefOption.Range, 0.1f, 1.8f, 3.6f, 0.1f, parentOps); - CreateIntOption(ThiefOption.SetTimeOffset, 30, 10, 360, 5, parentOps, format: OptionUnit.Second); - CreateIntOption(ThiefOption.SetNum, 5, 1, 10, 1, parentOps); - CreateIntOption(ThiefOption.PickUpTimeOffset, 6, 1, 60, 1, parentOps, format: OptionUnit.Second); - CreateBoolOption(ThiefOption.IsAddEffect, true, parentOps); + IRoleAbility.CreateAbilityCountOption( + factory, 2, 5, 2.0f); + factory.CreateFloatOption(ThiefOption.Range, 0.1f, 1.8f, 3.6f, 0.1f); + factory.CreateIntOption(ThiefOption.SetTimeOffset, 30, 10, 360, 5, format: OptionUnit.Second); + factory.CreateIntOption(ThiefOption.SetNum, 5, 1, 10, 1); + factory.CreateIntOption(ThiefOption.PickUpTimeOffset, 6, 1, 60, 1, format: OptionUnit.Second); + factory.CreateBoolOption(ThiefOption.IsAddEffect, true); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; + var cate = this.Loader; - this.activeRange = allOption.GetValue(GetRoleOptionId(ThiefOption.Range)); - this.isAddEffect = allOption.GetValue(GetRoleOptionId(ThiefOption.IsAddEffect)); + this.activeRange = cate.GetValue(ThiefOption.Range); + this.isAddEffect = cate.GetValue(ThiefOption.IsAddEffect); ExtremeSystemTypeManager.Instance.TryAdd( ExtremeSystemType.ThiefMeetingTimeChange, new ThiefMeetingTimeStealSystem( - allOption.GetValue(GetRoleOptionId(ThiefOption.SetNum)), - -allOption.GetValue(GetRoleOptionId(ThiefOption.SetTimeOffset)), - allOption.GetValue(GetRoleOptionId(ThiefOption.PickUpTimeOffset)))); + cate.GetValue(ThiefOption.SetNum), + -cate.GetValue(ThiefOption.SetTimeOffset), + cate.GetValue(ThiefOption.PickUpTimeOffset))); } public void ResetOnMeetingStart() @@ -160,7 +164,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Impostor/UnderWarper.cs b/ExtremeRoles/Roles/Solo/Impostor/UnderWarper.cs index 145f33f93..b0d68f0b4 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/UnderWarper.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/UnderWarper.cs @@ -13,6 +13,11 @@ using RoleEffectAction = Il2CppSystem.Action; + + + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Solo.Impostor; @@ -217,7 +222,7 @@ public void IntroEndSetUp() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { if (!this.isAwake && this.killCount >= this.awakeKillCount) @@ -332,45 +337,45 @@ public override bool TryRolePlayerKillTo( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( UnderWarperOption.AwakeKillCount, - 1, 0, 5, 1, parentOps, + 1, 0, 5, 1, format: OptionUnit.Shot); - CreateIntOption( + factory.CreateIntOption( UnderWarperOption.VentLinkKillCout, - 2, 0, 5, 1, parentOps, + 2, 0, 5, 1, format: OptionUnit.Shot); - CreateIntOption( + factory.CreateIntOption( UnderWarperOption.NoVentAnimeKillCout, - 2, 0, 5, 1, parentOps, + 2, 0, 5, 1, format: OptionUnit.Shot); - CreateBoolOption( + factory.CreateBoolOption( UnderWarperOption.WallHackVent, - false, parentOps); - CreateFloatOption( + false); + factory.CreateFloatOption( UnderWarperOption.Range, - 2.75f, 0.75f, 10.0f, 0.25f, parentOps); + 2.75f, 0.75f, 10.0f, 0.25f); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var cate = this.Loader; - this.awakeKillCount = allOpt.GetValue( - GetRoleOptionId(UnderWarperOption.AwakeKillCount)); - this.ventLinkKillCout = allOpt.GetValue( - GetRoleOptionId(UnderWarperOption.VentLinkKillCout)); - this.noVentAnimeKillCout = allOpt.GetValue( - GetRoleOptionId(UnderWarperOption.NoVentAnimeKillCout)); + this.awakeKillCount = cate.GetValue( + UnderWarperOption.AwakeKillCount); + this.ventLinkKillCout = cate.GetValue( + UnderWarperOption.VentLinkKillCout); + this.noVentAnimeKillCout = cate.GetValue( + UnderWarperOption.NoVentAnimeKillCout); - this.isWallHackVent = allOpt.GetValue( - GetRoleOptionId(UnderWarperOption.WallHackVent)); + this.isWallHackVent = cate.GetValue( + UnderWarperOption.WallHackVent); - this.VentUseRange = allOpt.GetValue( - GetRoleOptionId(UnderWarperOption.Range)); + this.VentUseRange = cate.GetValue( + UnderWarperOption.Range); this.isAwakedHasOtherVision = false; this.isAwakedHasOtherKillCool = true; diff --git a/ExtremeRoles/Roles/Solo/Impostor/Zombie.cs b/ExtremeRoles/Roles/Solo/Impostor/Zombie.cs index dee75f697..6f36a839e 100644 --- a/ExtremeRoles/Roles/Solo/Impostor/Zombie.cs +++ b/ExtremeRoles/Roles/Solo/Impostor/Zombie.cs @@ -21,6 +21,11 @@ using Il2CppObject = Il2CppSystem.Object; using SystemArray = System.Array; + + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Impostor; public sealed class Zombie : @@ -129,22 +134,22 @@ private static void setMagicCircle(Vector2 pos, float activeTime) var player = circle.AddComponent(); - player.SetThum(Loader.CreateSpriteFromResources( - Path.ZombieMagicCircle)); - player.SetVideo(Loader.GetUnityObjectFromResources( - Path.VideoAsset, string.Format( - Path.VideoAssetPlaceHolder, Path.ZombieMagicCircleVideo))); + player.SetThum(Resources.Loader.CreateSpriteFromResources( + Path.ZombieMagicCircle)); + player.SetVideo(Resources.Loader.GetUnityObjectFromResources( + Path.VideoAsset, string.Format( + Path.VideoAssetPlaceHolder, Path.ZombieMagicCircleVideo))); player.SetTimer(activeTime); } public void CreateAbility() { this.CreateAbilityCountButton( - Translation.GetString("featMagicCircle"), - Loader.CreateSpriteFromResources( - Path.ZombieMagicCircleButton), - IsActivate, - SetMagicCircle, + Translation.GetString("featMagicCircle"), + Resources.Loader.CreateSpriteFromResources( + Path.ZombieMagicCircleButton), + IsActivate, + SetMagicCircle, () => { }); if (this.Button?.Behavior is not AbilityCountBehavior countBehavior) @@ -221,7 +226,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -425,54 +430,51 @@ public override void RolePlayerKilledAction( protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( ZombieOption.AwakeKillCount, 1, 0, 3, 1, - parentOps, format: OptionUnit.Shot); - this.CreateAbilityCountOption(parentOps, 1, 3, 3f); + IRoleAbility.CreateAbilityCountOption(factory, 1, 3, 3f); - CreateIntOption( + factory.CreateIntOption( ZombieOption.ResurrectKillCount, 2, 0, 3, 1, - parentOps, format: OptionUnit.Shot); - CreateFloatOption( + factory.CreateFloatOption( ZombieOption.ShowMagicCircleTime, 10.0f, 0.0f, 30.0f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( ZombieOption.ResurrectDelayTime, 5.0f, 4.0f, 60.0f, 0.1f, - parentOps, format: OptionUnit.Second); - CreateBoolOption( + format: OptionUnit.Second); + factory.CreateBoolOption( ZombieOption.CanResurrectOnExil, - false, parentOps); + false); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var cate = this.Loader; this.killCount = 0; - this.awakeKillCount = allOpt.GetValue( - GetRoleOptionId(ZombieOption.AwakeKillCount)); - this.resurrectKillCount = allOpt.GetValue( - GetRoleOptionId(ZombieOption.ResurrectKillCount)); - - this.showMagicCircleTime = allOpt.GetValue( - GetRoleOptionId(ZombieOption.ShowMagicCircleTime)); - this.resurrectTimer = allOpt.GetValue( - GetRoleOptionId(ZombieOption.ResurrectDelayTime)); - this.canResurrectOnExil = allOpt.GetValue( - GetRoleOptionId(ZombieOption.CanResurrectOnExil)); + this.awakeKillCount = cate.GetValue( + ZombieOption.AwakeKillCount); + this.resurrectKillCount = cate.GetValue( + ZombieOption.ResurrectKillCount); + + this.showMagicCircleTime = cate.GetValue( + ZombieOption.ShowMagicCircleTime); + this.resurrectTimer = cate.GetValue( + ZombieOption.ResurrectDelayTime); + this.canResurrectOnExil = cate.GetValue( + ZombieOption.CanResurrectOnExil); this.awakeHasOtherVision = this.HasOtherVision; this.canResurrect = false; diff --git a/ExtremeRoles/Roles/Solo/Neutral/Alice.cs b/ExtremeRoles/Roles/Solo/Neutral/Alice.cs index a7070390c..34adbe796 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Alice.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Alice.cs @@ -2,7 +2,7 @@ using System.Linq; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Extension.State; @@ -10,6 +10,8 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class Alice : SingleRoleBase, IRoleAutoBuildAbility @@ -48,8 +50,8 @@ public Alice(): base( public void CreateAbility() { this.CreateAbilityCountButton( - "shipBroken", Loader.CreateSpriteFromResources( - Path.AliceShipBroken)); + "shipBroken", Resources.Loader.CreateSpriteFromResources( + Path.AliceShipBroken)); } public override bool IsSameTeam(SingleRoleBase targetRole) => @@ -94,7 +96,7 @@ public bool UseAbility() } for (int i = 0; i < this.RevartNormalTask; ++i) { - addTaskId.Add(Helper.GameSystem.GetRandomNormalTaskId()); + addTaskId.Add(Helper.GameSystem.GetRandomShortTaskId()); } var shuffled = addTaskId.OrderBy( @@ -130,57 +132,56 @@ public static void ShipBroken( { if (addTaskId.Count == 0) { break; } - if (player.Data.Tasks[i].Complete) + var task = player.Data.Tasks[i]; + if (task.Complete) { byte taskId = (byte)addTaskId[0]; addTaskId.RemoveAt(0); - - if (Helper.GameSystem.SetPlayerNewTask( - ref player, taskId, player.Data.Tasks[i].Id)) + uint id = task.Id; + if (Helper.GameSystem.SetPlayerNewTask( + ref player, taskId, id)) { - player.Data.Tasks[i] = new GameData.TaskInfo( - taskId, player.Data.Tasks[i].Id); + player.Data.Tasks[i] = new (taskId, id); } } } - GameData.Instance.SetDirtyBit( - 1U << (int)player.PlayerId); + player.Data.MarkDirty(); } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( AliceOption.CanUseSabotage, - true, parentOps); + true); - this.CreateAbilityCountOption( - parentOps, 2, 100); - CreateIntOption( + IRoleAbility.CreateAbilityCountOption( + factory, 2, 100); + factory.CreateIntOption( AliceOption.RevartLongTaskNum, - 1, 0, 15, 1, parentOps); - CreateIntOption( + 1, 0, 15, 1); + factory.CreateIntOption( AliceOption.RevartCommonTaskNum, - 1, 0, 15, 1, parentOps); - CreateIntOption( + 1, 0, 15, 1); + factory.CreateIntOption( AliceOption.RevartNormalTaskNum, - 1, 0, 15, 1, parentOps); + 1, 0, 15, 1); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; - - this.UseSabotage = allOption.GetValue( - GetRoleOptionId(AliceOption.CanUseSabotage)); - this.RevartNormalTask = allOption.GetValue( - GetRoleOptionId(AliceOption.RevartNormalTaskNum)); - this.RevartLongTask = allOption.GetValue( - GetRoleOptionId(AliceOption.RevartLongTaskNum)); - this.RevartCommonTask = allOption.GetValue( - GetRoleOptionId(AliceOption.RevartCommonTaskNum)); + var loader = this.Loader; + + this.UseSabotage = loader.GetValue( + AliceOption.CanUseSabotage); + this.RevartNormalTask = loader.GetValue( + AliceOption.RevartNormalTaskNum); + this.RevartLongTask = loader.GetValue( + AliceOption.RevartLongTaskNum); + this.RevartCommonTask = loader.GetValue( + AliceOption.RevartCommonTaskNum); } public void ResetOnMeetingStart() @@ -188,7 +189,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Neutral/Artist.cs b/ExtremeRoles/Roles/Solo/Neutral/Artist.cs index c8b7287d7..10c35f37f 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Artist.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Artist.cs @@ -10,6 +10,10 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; + + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Solo.Neutral; @@ -69,9 +73,9 @@ public void CreateAbility() { this.CreatePassiveAbilityButton( "ArtistArtOn", "ArtistArtOff", - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.ArtistArtOn), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.ArtistArtOff), this.CleanUp, () => @@ -143,28 +147,28 @@ public static void DrawOps(in MessageReader reader) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( ArtistOption.CanUseVent, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( ArtistOption.WinAreaSize, - 15, 1, 100, 1, parentOps); - this.CreateCommonAbilityOption( - parentOps, 3.0f); + 15, 1, 100, 1); + IRoleAbility.CreateCommonAbilityOption( + factory, 3.0f); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; + var cate = this.Loader; this.area = 0.0f; - this.UseVent = allOption.GetValue( - GetRoleOptionId(ArtistOption.CanUseVent)); - this.winArea = allOption.GetValue( - GetRoleOptionId(ArtistOption.WinAreaSize)); + this.UseVent = cate.GetValue( + ArtistOption.CanUseVent); + this.winArea = cate.GetValue( + ArtistOption.WinAreaSize); } public void ResetOnMeetingStart() @@ -173,7 +177,7 @@ public void ResetOnMeetingStart() drawOps(CachedPlayerControl.LocalPlayer); } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Neutral/Eater.cs b/ExtremeRoles/Roles/Solo/Neutral/Eater.cs index 8d1c13459..be70d5007 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Eater.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Eater.cs @@ -12,8 +12,12 @@ using ExtremeRoles.Performance; using ExtremeRoles.Resources; + + using BepInEx.Unity.IL2CPP.Utils; +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Solo.Neutral; @@ -40,7 +44,7 @@ public enum EaterAbilityMode : byte public ExtremeAbilityButton? Button { get; set; } private PlayerControl? tmpTarget; private PlayerControl? targetPlayer; - private GameData.PlayerInfo? targetDeadBody; + private NetworkedPlayerInfo? targetDeadBody; private float range; private float deadBodyEatActiveCoolTimePenalty; @@ -68,13 +72,11 @@ public Eater() : base( public void CreateAbility() { - var allOpt = OptionManager.Instance; - var deadBodyMode = new GraphicAndActiveTimeMode( EaterAbilityMode.DeadBody, new ButtonGraphic( Translation.GetString("deadBodyEat"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.EaterDeadBodyEat)), 1.0f); @@ -91,7 +93,7 @@ public void CreateAbility() EaterAbilityMode.Kill, new ButtonGraphic( Translation.GetString("eatKill"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.EaterEatKill)), this.Button.Behavior.ActiveTime)); } @@ -139,7 +141,7 @@ public bool IsAbilityUse() (hasPlayerTarget || hasDedBodyTarget); } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { if (this.Button != null) { @@ -174,7 +176,7 @@ public bool UseAbility() { byte playerId = this.tmpTarget.PlayerId; - if (ExtremeRoleManager.GameRole[playerId] is Combination.Assassin assassin && + if (ExtremeRoleManager.GameRole[playerId] is Combination.Assassin assassin && (!assassin.CanKilled || !assassin.CanKilledFromNeutral)) { return false; @@ -287,36 +289,37 @@ public override bool IsSameTeam(SingleRoleBase targetRole) => this.IsNeutralSameTeam(targetRole); protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( EaterOption.CanUseVent, - true, parentOps); - this.CreateAbilityCountOption( - parentOps, 5, 7, 7.5f); - CreateFloatOption( + true); + + IRoleAbility.CreateAbilityCountOption( + factory, 5, 7, 7.5f); + + factory.CreateFloatOption( EaterOption.EatRange, - 1.0f, 0.0f, 2.0f, 0.1f, - parentOps); - CreateIntOption( + 1.0f, 0.0f, 2.0f, 0.1f); + factory.CreateIntOption( EaterOption.DeadBodyEatActiveCoolTimePenalty, - 10, 0, 25, 1, parentOps, + 10, 0, 25, 1, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( EaterOption.KillEatCoolTimePenalty, - 10, 0, 25, 1, parentOps, + 10, 0, 25, 1, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( EaterOption.KillEatActiveCoolTimeReduceRate, - 10, 0, 50, 1, parentOps, + 10, 0, 50, 1, format: OptionUnit.Percentage); - CreateBoolOption( + factory.CreateBoolOption( EaterOption.IsResetCoolTimeWhenMeeting, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( EaterOption.IsShowArrowForDeadBody, - true, parentOps); + true); } protected override void RoleSpecificInit() @@ -324,33 +327,33 @@ protected override void RoleSpecificInit() this.targetDeadBody = null; this.targetPlayer = null; - var allOpt = OptionManager.Instance; - - this.UseVent = allOpt.GetValue( - GetRoleOptionId(EaterOption.CanUseVent)); - this.range = allOpt.GetValue( - GetRoleOptionId(EaterOption.EatRange)); - this.deadBodyEatActiveCoolTimePenalty = (allOpt.GetValue( - GetRoleOptionId(EaterOption.DeadBodyEatActiveCoolTimePenalty)) / 100.0f) + 1.0f; - this.killEatCoolTimePenalty = (allOpt.GetValue( - GetRoleOptionId(EaterOption.KillEatCoolTimePenalty)) / 100.0f) + 1.0f; - this.killEatActiveCoolTimeReduceRate = 1.0f - allOpt.GetValue( - GetRoleOptionId(EaterOption.KillEatCoolTimePenalty)) / 100.0f; - this.isResetCoolTimeWhenMeeting = allOpt.GetValue( - GetRoleOptionId(EaterOption.IsResetCoolTimeWhenMeeting)); - this.isShowArrow = allOpt.GetValue( - GetRoleOptionId(EaterOption.IsShowArrowForDeadBody)); - - this.defaultCoolTime = allOpt.GetValue(GetRoleOptionId( - RoleAbilityCommonOption.AbilityCoolTime)); + var cate = this.Loader; + + this.UseVent = cate.GetValue( + EaterOption.CanUseVent); + this.range = cate.GetValue( + EaterOption.EatRange); + this.deadBodyEatActiveCoolTimePenalty = (cate.GetValue( + EaterOption.DeadBodyEatActiveCoolTimePenalty) / 100.0f) + 1.0f; + this.killEatCoolTimePenalty = (cate.GetValue( + EaterOption.KillEatCoolTimePenalty) / 100.0f) + 1.0f; + this.killEatActiveCoolTimeReduceRate = 1.0f - cate.GetValue( + EaterOption.KillEatCoolTimePenalty) / 100.0f; + this.isResetCoolTimeWhenMeeting = cate.GetValue( + EaterOption.IsResetCoolTimeWhenMeeting); + this.isShowArrow = cate.GetValue( + EaterOption.IsShowArrowForDeadBody); + + this.defaultCoolTime = cate.GetValue( + RoleAbilityCommonOption.AbilityCoolTime); this.deadBodyArrow = new Dictionary(); this.isActivated = false; if (this.Button?.Behavior is AbilityCountBehavior behaviour) { - int abilityNum = allOpt.GetValue(GetRoleOptionId( - RoleAbilityCommonOption.AbilityCount)); + int abilityNum = cate.GetValue( + RoleAbilityCommonOption.AbilityCount); int halfPlayerNum = GameData.Instance.PlayerCount / 2; behaviour.SetCountText("eaterWinNum"); diff --git a/ExtremeRoles/Roles/Solo/Neutral/Hatter.cs b/ExtremeRoles/Roles/Solo/Neutral/Hatter.cs index 11ec46034..e6f7254a3 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Hatter.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Hatter.cs @@ -12,6 +12,9 @@ using ExtremeRoles.Performance; + +using ExtremeRoles.Module.CustomOption.Factory; + #nullable enable namespace ExtremeRoles.Roles.Solo.Neutral; @@ -75,8 +78,8 @@ this.Button is not null && public void CreateAbility() { this.CreateAbilityCountButton( - "timeKill", Loader.CreateSpriteFromResources( - Path.HatterTimeKill)); + "timeKill", Resources.Loader.CreateSpriteFromResources( + Path.HatterTimeKill)); } public override bool IsSameTeam(SingleRoleBase targetRole) => @@ -126,65 +129,64 @@ public bool UseAbility() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( HatterOption.CanRepairSabotage, - false, parentOps); + false); - CreateIntOption( + factory.CreateIntOption( HatterOption.WinCount, - 3, 1, 10, 1, parentOps); + 3, 1, 10, 1); - this.CreateAbilityCountOption( - parentOps, 3, 10, minAbilityCount: 0); + IRoleAbility.CreateAbilityCountOption( + factory, 3, 10, minAbilityCount: 0); - CreateBoolOption( - HatterOption.HideMeetingTimer, true, - parentOps); + factory.CreateBoolOption( + HatterOption.HideMeetingTimer, true); - var lowerOpt = CreateIntDynamicOption( + var lowerOpt = factory.CreateIntDynamicOption( HatterOption.MeetingTimerDecreaseLower, - 0, 0, 5, parentOps, + 0, 0, 5, format: OptionUnit.Percentage); - var upperOpt = CreateIntOption( + var upperOpt = factory.CreateIntOption( HatterOption.MeetingTimerDecreaseUpper, - 20, 0, 50, 5, parentOps, + 20, 0, 50, 5, format: OptionUnit.Percentage); - upperOpt.SetUpdateOption(lowerOpt); + upperOpt.AddWithUpdate(lowerOpt); - CreateIntOption( + factory.CreateIntOption( HatterOption.IncreaseTaskGage, - 50, 0, 100, 10, parentOps, + 50, 0, 100, 10, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( HatterOption.IncreseNum, - 3, 1, 10, 1, parentOps); + 3, 1, 10, 1); } protected override void RoleSpecificInit() { - var optMng = OptionManager.Instance; - this.CanRepairSabotage = optMng.GetValue( - GetRoleOptionId(HatterOption.CanRepairSabotage)); - this.winSkipCount = optMng.GetValue( - GetRoleOptionId(HatterOption.WinCount)); + var cate = this.Loader; + this.CanRepairSabotage = cate.GetValue( + HatterOption.CanRepairSabotage); + this.winSkipCount = cate.GetValue( + HatterOption.WinCount); - this.isHideMeetingTimer = optMng.GetValue( - GetRoleOptionId(HatterOption.HideMeetingTimer)); + this.isHideMeetingTimer = cate.GetValue( + HatterOption.HideMeetingTimer); - this.meetingTimerDecreaseLower = optMng.GetValue( - GetRoleOptionId(HatterOption.MeetingTimerDecreaseLower)); - this.meetingTimerDecreaseUpper = optMng.GetValue( - GetRoleOptionId(HatterOption.MeetingTimerDecreaseUpper)); + this.meetingTimerDecreaseLower = cate.GetValue( + HatterOption.MeetingTimerDecreaseLower); + this.meetingTimerDecreaseUpper = cate.GetValue( + HatterOption.MeetingTimerDecreaseUpper); this.isUpgrated = false; - this.abilityIncreaseTaskGage = (float)optMng.GetValue( - GetRoleOptionId(HatterOption.IncreaseTaskGage)) / 100.0f; - this.abilityIncreaseNum = optMng.GetValue( - GetRoleOptionId(HatterOption.IncreseNum)); + this.abilityIncreaseTaskGage = (float)cate.GetValue( + HatterOption.IncreaseTaskGage) / 100.0f; + this.abilityIncreaseNum = cate.GetValue( + HatterOption.IncreseNum); ExtremeSystemTypeManager.Instance.TryAdd( ExtremeSystemType.ModdedMeetingTimeSystem, new ModdedMeetingTimeSystem()); @@ -199,7 +201,7 @@ public void ResetOnMeetingStart() this.isAssassinMeeting = ExtremeRolesPlugin.ShipState.AssassinMeetingTrigger; } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { PlayerControl localPlayer = CachedPlayerControl.LocalPlayer; diff --git a/ExtremeRoles/Roles/Solo/Neutral/Jackal.cs b/ExtremeRoles/Roles/Solo/Neutral/Jackal.cs index fbe27abb4..bb41c9518 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Jackal.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Jackal.cs @@ -7,13 +7,17 @@ using ExtremeRoles.GameMode; using ExtremeRoles.Module; using ExtremeRoles.Module.AbilityBehavior; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Helper; using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + +using ExtremeRoles.Module.CustomOption.Interfaces; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class Jackal : SingleRoleBase, IRoleAutoBuildAbility, IRoleSpecialReset @@ -30,7 +34,20 @@ public enum JackalOption CanSetImpostorToSidekick, CanSeeImpostorToSidekickImpostor, SidekickJackalCanMakeSidekick, - } + + SidekickUseSabotage = 10, + SidekickUseVent, + SidekickCanKill, + + SidekickHasOtherKillCool, + SidekickKillCoolDown, + SidekickHasOtherKillRange, + SidekickKillRange, + + SidekickHasOtherVision, + SidekickVision, + SidekickApplyEnvironmentVisionEffect, + } public List SidekickPlayerId; @@ -78,156 +95,88 @@ public struct SidekickOptionHolder public bool HasOtherKillRange = false; public int KillRange = 0; - public int OptionIdOffset = 0; - - private enum SidekickOption - { - UseSabotage = 10, - UseVent, - CanKill, - - HasOtherKillCool, - KillCoolDown, - HasOtherKillRange, - KillRange, - - HasOtherVision, - Vision, - ApplyEnvironmentVisionEffect, - } - public SidekickOptionHolder( - IOptionInfo parentOps, - int optionOffset, - OptionTab tab) + in AutoParentSetOptionCategoryFactory factory) { - this.OptionIdOffset = optionOffset; string roleName = ExtremeRoleId.Sidekick.ToString(); - new BoolCustomOption( - GetRoleOptionId(SidekickOption.UseSabotage), - string.Concat( - roleName, - SidekickOption.UseSabotage.ToString()), - true, parentOps, - tab: tab); - new BoolCustomOption( - GetRoleOptionId(SidekickOption.UseVent), - string.Concat( - roleName, - SidekickOption.UseVent.ToString()), - true, parentOps, - tab: tab); - - var sidekickKillerOps = new BoolCustomOption( - GetRoleOptionId(SidekickOption.CanKill), - string.Concat( - roleName, - SidekickOption.CanKill.ToString()), - false, parentOps, - tab: tab); - - var killCoolOption = new BoolCustomOption( - GetRoleOptionId(SidekickOption.HasOtherKillCool), - string.Concat( - roleName, - SidekickOption.HasOtherKillCool.ToString()), - false, sidekickKillerOps, - tab: tab); - new FloatCustomOption( - GetRoleOptionId(SidekickOption.KillCoolDown), - string.Concat( - roleName, - SidekickOption.KillCoolDown.ToString()), - 30f, 1.0f, 120f, 0.5f, - killCoolOption, format: OptionUnit.Second, - tab: tab); - - var killRangeOption = new BoolCustomOption( - GetRoleOptionId(SidekickOption.HasOtherKillRange), - string.Concat( - roleName, - SidekickOption.HasOtherKillRange.ToString()), - false, sidekickKillerOps, - tab: tab); - new SelectionCustomOption( - GetRoleOptionId(SidekickOption.KillRange), - string.Concat( - roleName, - SidekickOption.KillRange.ToString()), - OptionCreator.Range, - killRangeOption, - tab: tab); - - var visionOption = new BoolCustomOption( - GetRoleOptionId(SidekickOption.HasOtherVision), - string.Concat( - roleName, - SidekickOption.HasOtherVision.ToString()), - false, parentOps, - tab: tab); - - new FloatCustomOption( - GetRoleOptionId(SidekickOption.Vision), - string.Concat( - roleName, - SidekickOption.Vision.ToString()), - 2f, 0.25f, 5f, 0.25f, - visionOption, format: OptionUnit.Multiplier, - tab: tab); - new BoolCustomOption( - GetRoleOptionId(SidekickOption.ApplyEnvironmentVisionEffect), - string.Concat( - roleName, - SidekickOption.ApplyEnvironmentVisionEffect.ToString()), - false, visionOption, - tab: tab); + factory.CreateBoolOption(JackalOption.SidekickUseSabotage, true); + factory.CreateBoolOption(JackalOption.SidekickUseVent, true); + + + var sidekickKillerOps = factory.CreateBoolOption(JackalOption.SidekickCanKill, false); + + var killCoolOption = factory.CreateBoolOption( + JackalOption.SidekickHasOtherKillCool, + false, sidekickKillerOps); + factory.CreateFloatOption( + JackalOption.SidekickKillCoolDown, + 30f, 1.0f, 120f, 0.5f, + killCoolOption, format: OptionUnit.Second); + + var killRangeOption = factory.CreateBoolOption( + JackalOption.SidekickHasOtherKillRange, + false, sidekickKillerOps); + factory.CreateSelectionOption( + JackalOption.SidekickKillRange, + OptionCreator.Range, + killRangeOption); + + var visionOption = factory.CreateBoolOption( + JackalOption.SidekickHasOtherVision, false); + + factory.CreateFloatOption( + JackalOption.SidekickVision, + 2f, 0.25f, 5f, 0.25f, + visionOption, format: OptionUnit.Multiplier); + + factory.CreateBoolOption( + JackalOption.SidekickApplyEnvironmentVisionEffect, + false, visionOption); } - public void ApplyOption() + public void ApplyOption(in IOptionLoader loader) { var curOption = GameOptionsManager.Instance.CurrentGameOptions; - var allOption = OptionManager.Instance; - this.UseSabotage = allOption.GetValue( - GetRoleOptionId(SidekickOption.UseSabotage)); - this.UseVent = allOption.GetValue( - GetRoleOptionId(SidekickOption.UseVent)); + this.UseSabotage = loader.GetValue( + JackalOption.SidekickUseSabotage); + this.UseVent = loader.GetValue( + JackalOption.SidekickUseVent); - this.CanKill = allOption.GetValue( - GetRoleOptionId(SidekickOption.CanKill)); + this.CanKill = loader.GetValue( + JackalOption.SidekickCanKill); - this.HasOtherKillCool = allOption.GetValue( - GetRoleOptionId(SidekickOption.HasOtherKillCool)); + this.HasOtherKillCool = loader.GetValue( + JackalOption.SidekickHasOtherKillCool); this.KillCool = curOption.GetFloat(FloatOptionNames.KillCooldown); if (this.HasOtherKillCool) { - this.KillCool = allOption.GetValue( - GetRoleOptionId(SidekickOption.KillCoolDown)); + this.KillCool = loader.GetValue( + JackalOption.SidekickKillCoolDown); } - this.HasOtherKillRange = allOption.GetValue( - GetRoleOptionId(SidekickOption.HasOtherKillRange)); + this.HasOtherKillRange = loader.GetValue( + JackalOption.SidekickHasOtherKillRange); this.KillRange = curOption.GetInt(Int32OptionNames.KillDistance); if (this.HasOtherKillRange) { - this.KillRange = allOption.GetValue( - GetRoleOptionId(SidekickOption.KillRange)); + this.KillRange = loader.GetValue( + JackalOption.SidekickKillRange); } - this.HasOtherVision = allOption.GetValue( - GetRoleOptionId(SidekickOption.HasOtherVision)); + this.HasOtherVision = loader.GetValue( + JackalOption.SidekickHasOtherVision); this.Vision = curOption.GetFloat(FloatOptionNames.CrewLightMod); this.ApplyEnvironmentVisionEffect = false; if (this.HasOtherVision) { - this.Vision = allOption.GetValue( - GetRoleOptionId(SidekickOption.Vision)); - this.ApplyEnvironmentVisionEffect = allOption.GetValue( - GetRoleOptionId(SidekickOption.ApplyEnvironmentVisionEffect)); + this.Vision = loader.GetValue( + JackalOption.SidekickVision); + this.ApplyEnvironmentVisionEffect = loader.GetValue( + JackalOption.SidekickApplyEnvironmentVisionEffect); } } - private int GetRoleOptionId(SidekickOption ops) => (int)ops + this.OptionIdOffset; public SidekickOptionHolder Clone() { @@ -264,7 +213,7 @@ public static void TargetToSideKick(byte callerId, byte targetId) sourceJackal, callerId, targetRole.IsImpostor(), - ref sourceJackal.SidekickOption); + sourceJackal.SidekickOption); sourceJackal.SidekickPlayerId.Add(targetId); @@ -303,8 +252,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "Sidekick", - Loader.CreateSpriteFromResources( - Path.JackalSidekick)); + Resources.Loader.CreateSpriteFromResources( + Path.JackalSidekick)); } public override Color GetTargetRoleSeeColor( @@ -410,7 +359,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -446,14 +395,14 @@ public void AllReset(PlayerControl rolePlayer) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { // JackalOption - this.createJackalOption(parentOps); + this.createJackalOption(factory); - // SideKickOption - this.SidekickOption = new SidekickOptionHolder( - parentOps, this.OptionIdOffset, this.Tab); + // SideKickOption + factory.OptionPrefix = string.Empty; + this.SidekickOption = new SidekickOptionHolder(factory); } protected override void RoleSpecificInit() @@ -461,75 +410,71 @@ protected override void RoleSpecificInit() this.CurRecursion = 0; this.SidekickPlayerId = new List(); - var allOption = OptionManager.Instance; + var cate = this.Loader; - this.SidekickRecursionLimit = allOption.GetValue( - GetRoleOptionId(JackalOption.SidekickLimitNum)); + this.SidekickRecursionLimit = cate.GetValue( + JackalOption.SidekickLimitNum); - this.canLoverSidekick = allOption.GetValue( - GetRoleOptionId(JackalOption.CanLoverSidekick)); + this.canLoverSidekick = cate.GetValue( + JackalOption.CanLoverSidekick); - this.ForceReplaceLover = allOption.GetValue( - GetRoleOptionId(JackalOption.ForceReplaceLover)); + this.ForceReplaceLover = cate.GetValue( + JackalOption.ForceReplaceLover); - this.CanSetImpostorToSidekick = allOption.GetValue( - GetRoleOptionId(JackalOption.CanSetImpostorToSidekick)); - this.CanSeeImpostorToSidekickImpostor = allOption.GetValue( - GetRoleOptionId(JackalOption.CanSeeImpostorToSidekickImpostor)); + this.CanSetImpostorToSidekick = cate.GetValue( + JackalOption.CanSetImpostorToSidekick); + this.CanSeeImpostorToSidekickImpostor = cate.GetValue( + JackalOption.CanSeeImpostorToSidekickImpostor); - this.SidekickJackalCanMakeSidekick = allOption.GetValue( - GetRoleOptionId(JackalOption.SidekickJackalCanMakeSidekick)); + this.SidekickJackalCanMakeSidekick = cate.GetValue( + JackalOption.SidekickJackalCanMakeSidekick); - this.createSidekickRange = allOption.GetValue( - GetRoleOptionId(JackalOption.RangeSidekickTarget)); + this.createSidekickRange = cate.GetValue( + JackalOption.RangeSidekickTarget); - this.numUpgradeSidekick = allOption.GetValue( - GetRoleOptionId(JackalOption.UpgradeSidekickNum)); + this.numUpgradeSidekick = cate.GetValue( + JackalOption.UpgradeSidekickNum); - this.SidekickOption.ApplyOption(); + this.SidekickOption.ApplyOption(cate); } - private void createJackalOption(IOptionInfo parentOps) + private void createJackalOption(AutoParentSetOptionCategoryFactory factory) { - this.CreateAbilityCountOption( - parentOps, 1, GameSystem.VanillaMaxPlayerNum - 1); + IRoleAbility.CreateAbilityCountOption( + factory, 1, GameSystem.VanillaMaxPlayerNum - 1); - CreateSelectionOption( + factory.CreateSelectionOption( JackalOption.RangeSidekickTarget, - OptionCreator.Range, - parentOps); + OptionCreator.Range); - var loverSkOpt = CreateBoolOption( + var loverSkOpt = factory.CreateBoolOption( JackalOption.CanLoverSidekick, - true, parentOps); + true); - CreateBoolOption( + factory.CreateBoolOption( JackalOption.ForceReplaceLover, true, loverSkOpt, - invert: true, enableCheckOption: parentOps); + invert: true); - CreateIntOption( + factory.CreateIntOption( JackalOption.UpgradeSidekickNum, - 1, 1, GameSystem.VanillaMaxPlayerNum - 1, 1, - parentOps); + 1, 1, GameSystem.VanillaMaxPlayerNum - 1, 1); - var sidekickMakeSidekickOps = CreateBoolOption( + var sidekickMakeSidekickOps = factory.CreateBoolOption( JackalOption.SidekickJackalCanMakeSidekick, - false, parentOps); + false); - CreateIntOption( + factory.CreateIntOption( JackalOption.SidekickLimitNum, 1, 1, GameSystem.VanillaMaxPlayerNum / 2, 1, sidekickMakeSidekickOps); - CreateBoolOption( - JackalOption.CanSetImpostorToSidekick, - false, parentOps); + factory.CreateBoolOption( + JackalOption.CanSetImpostorToSidekick, false); - CreateBoolOption( - JackalOption.CanSeeImpostorToSidekickImpostor, - false, parentOps); + factory.CreateBoolOption( + JackalOption.CanSeeImpostorToSidekickImpostor, false); } @@ -571,7 +516,7 @@ public Sidekick( Jackal jackal, byte jackalPlayerId, bool isImpostor, - ref Jackal.SidekickOptionHolder option) : base( + in Jackal.SidekickOptionHolder option) : base( ExtremeRoleId.Sidekick, ExtremeRoleType.Neutral, ExtremeRoleId.Sidekick.ToString(), @@ -580,7 +525,6 @@ public Sidekick( option.UseVent, option.UseSabotage) { this.jackal = jackal; - this.OptionIdOffset = option.OptionIdOffset; this.jackalPlayerId = jackalPlayerId; this.SetControlId(jackal.GameControlId); @@ -640,10 +584,14 @@ public override string GetFullDescription() var jackal = Player.GetPlayerControlById(this.jackalPlayerId); string fullDesc = base.GetFullDescription(); - if (!jackal) { return fullDesc; } + if (jackal == null || + jackal.Data == null) + { + return fullDesc; + } return string.Format( - fullDesc, jackal.Data?.PlayerName); + fullDesc, jackal.Data.PlayerName); } public static void BecomeToJackal(byte callerId, byte targetId) @@ -706,7 +654,7 @@ public static void BecomeToJackal(byte callerId, byte targetId) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { throw new Exception("Don't call this class method!!"); } diff --git a/ExtremeRoles/Roles/Solo/Neutral/Jester.cs b/ExtremeRoles/Roles/Solo/Neutral/Jester.cs index aff76ac6a..a97bf349f 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Jester.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Jester.cs @@ -1,5 +1,5 @@ using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Extension.State; @@ -7,6 +7,8 @@ using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class Jester : SingleRoleBase, IRoleAutoBuildAbility @@ -104,8 +106,8 @@ public void CreateAbility() { this.CreateAbilityCountButton( "outburst", - Loader.CreateSpriteFromResources( - Path.JesterOutburst), + Resources.Loader.CreateSpriteFromResources( + Path.JesterOutburst), abilityOff: CleanUp, forceAbilityOff: () => { }); } @@ -157,27 +159,27 @@ public void CleanUp() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( JesterOption.OutburstDistance, - 1.0f, 0.0f, 2.0f, 0.1f, - parentOps); + 1.0f, 0.0f, 2.0f, 0.1f); - CreateBoolOption( + factory.CreateBoolOption( JesterOption.UseSabotage, - true, parentOps); + true); - this.CreateAbilityCountOption( - parentOps, 5, 100, 2.0f); + IRoleAbility.CreateAbilityCountOption( + factory, 5, 100, 2.0f); } protected override void RoleSpecificInit() { - this.UseSabotage = OptionManager.Instance.GetValue( - GetRoleOptionId(JesterOption.UseSabotage)); - this.outburstDistance = OptionManager.Instance.GetValue( - GetRoleOptionId(JesterOption.OutburstDistance)); + var cat = this.Loader; + this.UseSabotage = cat.GetValue( + (int)JesterOption.UseSabotage); + this.outburstDistance = cat.GetValue( + (int)JesterOption.OutburstDistance); } public void ResetOnMeetingStart() @@ -185,7 +187,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } diff --git a/ExtremeRoles/Roles/Solo/Neutral/Madmate.cs b/ExtremeRoles/Roles/Solo/Neutral/Madmate.cs index 0acdc0fbe..11b085cef 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Madmate.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Madmate.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; - -using UnityEngine; +using UnityEngine; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class Madmate : @@ -72,8 +72,8 @@ public static void ToFakeImpostor(byte playerId) public void CreateAbility() { this.CreateNormalAbilityButton( - "selfKill", Loader.CreateSpriteFromResources( - Path.SucideSprite)); + "selfKill", Resources.Loader.CreateSpriteFromResources( + Path.SucideSprite)); } public bool UseAbility() @@ -93,7 +93,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -117,7 +117,7 @@ public void IntroEndSetUp() } public void ModifiedWinPlayer( - GameData.PlayerInfo rolePlayerInfo, + NetworkedPlayerInfo rolePlayerInfo, GameOverReason reason, ref ExtremeGameResult.WinnerTempData winner) { @@ -174,64 +174,64 @@ public override Color GetTargetRoleSeeColor( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( MadmateOption.IsDontCountAliveCrew, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( MadmateOption.CanFixSabotage, - false, parentOps); - var ventUseOpt = CreateBoolOption( + false); + var ventUseOpt = factory.CreateBoolOption( MadmateOption.CanUseVent, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( MadmateOption.CanMoveVentToVent, false, ventUseOpt); - var taskOpt = CreateBoolOption( + var taskOpt = factory.CreateBoolOption( MadmateOption.HasTask, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( MadmateOption.SeeImpostorTaskGage, 70, 0, 100, 10, taskOpt, format: OptionUnit.Percentage); - var impFromSeeOpt = CreateBoolOption( + var impFromSeeOpt = factory.CreateBoolOption( MadmateOption.CanSeeFromImpostor, false, taskOpt); - CreateIntOption( + factory.CreateIntOption( MadmateOption.CanSeeFromImpostorTaskGage, 70, 0, 100, 10, impFromSeeOpt, format: OptionUnit.Percentage); - this.CreateCommonAbilityOption(parentOps); + IRoleAbility.CreateCommonAbilityOption(factory); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var cate = this.Loader; this.isSeeImpostorNow = false; this.isUpdateMadmate = false; this.FakeImposter = false; - this.isDontCountAliveCrew = allOpt.GetValue( - GetRoleOptionId(MadmateOption.IsDontCountAliveCrew)); - - this.CanRepairSabotage = allOpt.GetValue( - GetRoleOptionId(MadmateOption.CanFixSabotage)); - this.UseVent = allOpt.GetValue( - GetRoleOptionId(MadmateOption.CanUseVent)); - this.canMoveVentToVent = allOpt.GetValue( - GetRoleOptionId(MadmateOption.CanMoveVentToVent)); - this.HasTask = allOpt.GetValue( - GetRoleOptionId(MadmateOption.HasTask)); - this.seeImpostorTaskGage = allOpt.GetValue( - GetRoleOptionId(MadmateOption.SeeImpostorTaskGage)) / 100.0f; - this.canSeeFromImpostor = allOpt.GetValue( - GetRoleOptionId(MadmateOption.CanSeeFromImpostor)); - this.seeFromImpostorTaskGage = allOpt.GetValue( - GetRoleOptionId(MadmateOption.CanSeeFromImpostorTaskGage)) / 100.0f; + this.isDontCountAliveCrew = cate.GetValue( + MadmateOption.IsDontCountAliveCrew); + + this.CanRepairSabotage = cate.GetValue( + MadmateOption.CanFixSabotage); + this.UseVent = cate.GetValue( + MadmateOption.CanUseVent); + this.canMoveVentToVent = cate.GetValue( + MadmateOption.CanMoveVentToVent); + this.HasTask = cate.GetValue( + MadmateOption.HasTask); + this.seeImpostorTaskGage = cate.GetValue( + MadmateOption.SeeImpostorTaskGage) / 100.0f; + this.canSeeFromImpostor = cate.GetValue( + MadmateOption.CanSeeFromImpostor); + this.seeFromImpostorTaskGage = cate.GetValue( + MadmateOption.CanSeeFromImpostorTaskGage) / 100.0f; this.isSeeImpostorNow = this.HasTask && diff --git a/ExtremeRoles/Roles/Solo/Neutral/Miner.cs b/ExtremeRoles/Roles/Solo/Neutral/Miner.cs index 39d61b1a3..cde2962f6 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Miner.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Miner.cs @@ -15,6 +15,10 @@ using ExtremeRoles.Module.CustomMonoBehaviour; using ExtremeRoles.Compat; +using ExtremeRoles.Module.CustomOption.Factory; + + + #nullable enable namespace ExtremeRoles.Roles.Solo.Neutral; @@ -156,8 +160,8 @@ public void CreateAbility() { this.CreateNormalAbilityButton( "setMine", - Loader.CreateSpriteFromResources( - Path.MinerSetMine), + Resources.Loader.CreateSpriteFromResources( + Path.MinerSetMine), abilityOff: CleanUp, forceAbilityOff: () => { }); } @@ -212,7 +216,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -252,7 +256,7 @@ public void Update(PlayerControl rolePlayer) } Vector2 pos = mine.transform.position; - foreach (GameData.PlayerInfo playerInfo in + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (playerInfo == null || @@ -311,7 +315,7 @@ public void Update(PlayerControl rolePlayer) if (this.isShowKillLog) { - GameData.PlayerInfo killPlayer = GameData.Instance.GetPlayerById(player); + NetworkedPlayerInfo killPlayer = GameData.Instance.GetPlayerById(player); if (killPlayer != null) { @@ -340,80 +344,72 @@ public override bool IsSameTeam(SingleRoleBase targetRole) => this.IsNeutralSameTeam(targetRole); protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( MinerOption.LinkingAllVent, - false, parentOps); - this.CreateCommonAbilityOption( - parentOps, 2.0f); - CreateFloatOption( + false); + IRoleAbility.CreateCommonAbilityOption( + factory, 2.0f); + factory.CreateFloatOption( MinerOption.MineKillRange, - 1.8f, 0.5f, 5f, 0.1f, parentOps); - var showOpt = CreateBoolOption( + 1.8f, 0.5f, 5f, 0.1f); + var showOpt = factory.CreateBoolOption( MinerOption.CanShowMine, - false, parentOps); - CreateSelectionOption( + false); + factory.CreateSelectionOption( MinerOption.RolePlayerShowMode, - new string[] - { - ShowMode.MineSeeOnlySe.ToString(), - ShowMode.MineSeeOnlyImg.ToString(), - ShowMode.MineSeeBoth.ToString(), - }, showOpt); - var anotherPlayerShowMode = CreateSelectionOption( - MinerOption.AnotherPlayerShowMode, - new string[] - { - ShowMode.MineSeeNone.ToString(), + [ ShowMode.MineSeeOnlySe.ToString(), ShowMode.MineSeeOnlyImg.ToString(), ShowMode.MineSeeBoth.ToString(), - }, showOpt); - CreateBoolOption( + ], showOpt); + var anotherPlayerShowMode = factory.CreateSelectionOption( + MinerOption.AnotherPlayerShowMode, showOpt); + factory.CreateBoolOption( MinerOption.CanShowNoneActiveAnotherPlayer, false, anotherPlayerShowMode); - CreateFloatOption( + factory.CreateFloatOption( MinerOption.NoneActiveTime, 20.0f, 1.0f, 45f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateBoolOption( + format: OptionUnit.Second); + factory.CreateBoolOption( MinerOption.ShowKillLog, - true, parentOps); + true); } protected override void RoleSpecificInit() { - var allOpt = OptionManager.Instance; + var cate = this.Loader; - this.isLinkingVent = allOpt.GetValue( - GetRoleOptionId(MinerOption.LinkingAllVent)); + this.isLinkingVent = cate.GetValue( + MinerOption.LinkingAllVent); - this.killRange = allOpt.GetValue( - GetRoleOptionId(MinerOption.MineKillRange)); - this.nonActiveTime = allOpt.GetValue( - GetRoleOptionId(MinerOption.NoneActiveTime)); - this.isShowKillLog = allOpt.GetValue( - GetRoleOptionId(MinerOption.ShowKillLog)); + this.killRange = cate.GetValue( + MinerOption.MineKillRange); + this.nonActiveTime = cate.GetValue( + MinerOption.NoneActiveTime); + this.isShowKillLog = cate.GetValue( + MinerOption.ShowKillLog); this.mines = new Dictionary(); this.timer = this.nonActiveTime; this.mineId = 0; - bool isShowMine = allOpt.GetValue( - GetRoleOptionId(MinerOption.CanShowMine)); + bool isShowMine = cate.GetValue( + MinerOption.CanShowMine); - var rolePlayerShowMode = (ShowMode)(allOpt.GetValue( - GetRoleOptionId(MinerOption.RolePlayerShowMode)) + 1); - var anotherPlayerShowMode = (ShowMode)allOpt.GetValue( - GetRoleOptionId(MinerOption.AnotherPlayerShowMode)); + var rolePlayerShowMode = (ShowMode)(cate.GetValue( + MinerOption.RolePlayerShowMode) + 1); + var anotherPlayerShowMode = (ShowMode)cate.GetValue( + MinerOption.AnotherPlayerShowMode); this.isShowAnotherPlayer = anotherPlayerShowMode != ShowMode.MineSeeNone && isShowMine; this.parameter = new MineEffectParameter( RolePlayerShowMode: isShowMine ? rolePlayerShowMode : ShowMode.MineSeeNone, AnotherPlayerShowMode: anotherPlayerShowMode, CanShowNoneActiveAtherPlayer: - allOpt.GetValue( - GetRoleOptionId(MinerOption.CanShowNoneActiveAnotherPlayer)) && + cate.GetValue( + MinerOption.CanShowNoneActiveAnotherPlayer) && this.isShowAnotherPlayer); this.killLogger = new TextPopUpper( diff --git a/ExtremeRoles/Roles/Solo/Neutral/Missionary.cs b/ExtremeRoles/Roles/Solo/Neutral/Missionary.cs index 82525ca02..fc91120c1 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Missionary.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Missionary.cs @@ -16,6 +16,10 @@ using BepInEx.Unity.IL2CPP.Utils; using System.Linq; +using ExtremeRoles.Module.CustomOption.Factory; + + + #nullable enable namespace ExtremeRoles.Roles.Solo.Neutral; @@ -82,30 +86,29 @@ public override bool IsSameTeam(SingleRoleBase targetRole) => this.IsNeutralSameTeam(targetRole); protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( MissionaryOption.TellDeparture, - true, parentOps); - CreateFloatOption( + true); + factory.CreateFloatOption( MissionaryOption.DepartureMinTime, 10f, 1.0f, 15f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateFloatOption( + format: OptionUnit.Second); + factory.CreateFloatOption( MissionaryOption.DepartureMaxTime, - 30f, 15f, 120f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateFloatOption( + 30f, 15f, 120f, 0.5f + , format: OptionUnit.Second); + factory.CreateFloatOption( MissionaryOption.PropagateRange, - 1.2f, 0.0f, 2.0f, 0.1f, - parentOps); + 1.2f, 0.0f, 2.0f, 0.1f); - this.CreateCommonAbilityOption(parentOps); + IRoleAbility.CreateCommonAbilityOption(factory); - var useOpt = CreateBoolOption( + var useOpt = factory.CreateBoolOption( MissionaryOption.IsUseSolemnJudgment, - false, parentOps); - CreateIntOption( + false); + factory.CreateIntOption( MissionaryOption.MaxJudgementNum, 3, 1, GameSystem.VanillaMaxPlayerNum, 1, useOpt); @@ -116,18 +119,20 @@ protected override void RoleSpecificInit() this.lamb = new List(CachedPlayerControl.AllPlayerControls.Count); this.timer = 0; - this.tellDeparture = OptionManager.Instance.GetValue( - GetRoleOptionId(MissionaryOption.TellDeparture)); - this.maxTimerTime = OptionManager.Instance.GetValue( - GetRoleOptionId(MissionaryOption.DepartureMaxTime)); - this.minTimerTime = OptionManager.Instance.GetValue( - GetRoleOptionId(MissionaryOption.DepartureMinTime)); - this.propagateRange = OptionManager.Instance.GetValue( - GetRoleOptionId(MissionaryOption.PropagateRange)); - this.isUseSolemnJudgment = OptionManager.Instance.GetValue( - GetRoleOptionId(MissionaryOption.IsUseSolemnJudgment)); - this.maxJudgementTarget = OptionManager.Instance.GetValue( - GetRoleOptionId(MissionaryOption.MaxJudgementNum)); + var cate = this.Loader; + + this.tellDeparture = cate.GetValue( + MissionaryOption.TellDeparture); + this.maxTimerTime = cate.GetValue( + MissionaryOption.DepartureMaxTime); + this.minTimerTime = cate.GetValue( + MissionaryOption.DepartureMinTime); + this.propagateRange = cate.GetValue( + MissionaryOption.PropagateRange); + this.isUseSolemnJudgment = cate.GetValue( + MissionaryOption.IsUseSolemnJudgment); + this.maxJudgementTarget = cate.GetValue( + MissionaryOption.MaxJudgementNum); this.judgementTarget = new HashSet(); @@ -137,8 +142,8 @@ protected override void RoleSpecificInit() public void CreateAbility() { this.CreateNormalAbilityButton( - "propagate", Loader.CreateSpriteFromResources( - Path.MissionaryPropagate)); + "propagate", Resources.Loader.CreateSpriteFromResources( + Path.MissionaryPropagate)); } public bool IsAbilityUse() @@ -166,7 +171,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { if (exiledPlayer != null) { diff --git a/ExtremeRoles/Roles/Solo/Neutral/Queen.cs b/ExtremeRoles/Roles/Solo/Neutral/Queen.cs index 3144c762a..57bd884cf 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Queen.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Queen.cs @@ -17,6 +17,10 @@ using ExtremeRoles.Roles.Solo.Crewmate; using ExtremeRoles.Performance; + + +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class Queen : @@ -173,26 +177,21 @@ private static void replaceVanilaRole( SingleRoleBase targetRole, PlayerControl targetPlayer) { - var multiAssignRole = targetRole as MultiAssignRoleBase; - if (multiAssignRole != null) + if (targetRole is MultiAssignRoleBase multiAssignRole && + multiAssignRole.AnotherRole is VanillaRoleWrapper) { - if (multiAssignRole.AnotherRole is VanillaRoleWrapper) - { - FastDestroyableSingleton.Instance.SetRole( - targetPlayer, RoleTypes.Crewmate); - return; - } - } + FastDestroyableSingleton.Instance.SetRole( + targetPlayer, RoleTypes.Crewmate); + return; + } switch (targetPlayer.Data.Role.Role) { case RoleTypes.Crewmate: case RoleTypes.Impostor: - FastDestroyableSingleton.Instance.SetRole( - targetPlayer, RoleTypes.Crewmate); - break; - default: - break; + FastDestroyableSingleton.Instance.SetRole( + targetPlayer, RoleTypes.Crewmate); + break; } } private static void resetRole( @@ -324,8 +323,8 @@ public void AllReset(PlayerControl rolePlayer) public void CreateAbility() { this.CreateAbilityCountButton( - "queenCharm", Loader.CreateSpriteFromResources( - Path.QueenCharm)); + "queenCharm", Resources.Loader.CreateSpriteFromResources( + Path.QueenCharm)); } public bool UseAbility() @@ -358,7 +357,7 @@ public void ResetOnMeetingStart() return; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -445,61 +444,56 @@ public override bool IsSameTeam(SingleRoleBase targetRole) } } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( QueenOption.CanUseVent, - false, parentOps); + false); - this.CreateAbilityCountOption( - parentOps, 1, 3); + IRoleAbility.CreateAbilityCountOption( + factory, 1, 3); - CreateFloatOption( + factory.CreateFloatOption( QueenOption.Range, - 1.0f, 0.5f, 2.6f, 0.1f, - parentOps); - CreateIntOption( + 1.0f, 0.5f, 2.6f, 0.1f); + factory.CreateIntOption( QueenOption.ServantKillKillCoolReduceRate, 40, 0, 85, 1, - parentOps, format:OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( QueenOption.ServantTaskKillCoolReduceRate, 75, 0, 99, 1, - parentOps, format: OptionUnit.Percentage); - CreateIntOption( + factory.CreateIntOption( QueenOption.ServantTaskCompKillCoolReduceRate, 30, 0, 75, 1, - parentOps, format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( QueenOption.ServantSelfKillCool, 30.0f, 0.5f, 60.0f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateBoolOption( + factory.CreateBoolOption( QueenOption.ServantSucideWithQueenWhenHasKill, - true, parentOps); + true); } protected override void RoleSpecificInit() { - var optMng = OptionManager.Instance; - - this.range = optMng.GetValue(GetRoleOptionId(QueenOption.Range)); - this.UseVent = optMng.GetValue( - GetRoleOptionId(QueenOption.CanUseVent)); - this.ServantSelfKillCool = optMng.GetValue( - GetRoleOptionId(QueenOption.ServantSelfKillCool)); - this.killKillCoolReduceRate = 1.0f - (optMng.GetValue( - GetRoleOptionId(QueenOption.ServantKillKillCoolReduceRate)) / 100.0f); - this.taskKillCoolReduceRate = 1.0f - (optMng.GetValue( - GetRoleOptionId(QueenOption.ServantTaskKillCoolReduceRate)) / 100.0f); - this.taskCompKillCoolReduceRate = 1.0f - (optMng.GetValue( - GetRoleOptionId(QueenOption.ServantTaskCompKillCoolReduceRate)) / 100.0f); - this.servantSucideWithQueenWhenHasKill = optMng.GetValue( - GetRoleOptionId(QueenOption.ServantSucideWithQueenWhenHasKill)); + var cate = this.Loader; + + this.range = cate.GetValue(QueenOption.Range); + this.UseVent = cate.GetValue( + QueenOption.CanUseVent); + this.ServantSelfKillCool = cate.GetValue( + QueenOption.ServantSelfKillCool); + this.killKillCoolReduceRate = 1.0f - (cate.GetValue( + QueenOption.ServantKillKillCoolReduceRate) / 100.0f); + this.taskKillCoolReduceRate = 1.0f - (cate.GetValue( + QueenOption.ServantTaskKillCoolReduceRate) / 100.0f); + this.taskCompKillCoolReduceRate = 1.0f - (cate.GetValue( + QueenOption.ServantTaskCompKillCoolReduceRate) / 100.0f); + this.servantSucideWithQueenWhenHasKill = cate.GetValue( + QueenOption.ServantSucideWithQueenWhenHasKill); this.servantTaskGage = new Dictionary(); this.servantPlayerId = new HashSet(); @@ -580,8 +574,8 @@ public void SelfKillAbility(float coolTime) { this.Button = RoleAbilityFactory.CreateReusableAbility( "selfKill", - Loader.CreateSpriteFromResources( - Path.SucideSprite), + Resources.Loader.CreateSpriteFromResources( + Path.SucideSprite), this.IsAbilityUse, this.UseAbility); this.Button.Behavior.SetCoolTime(coolTime); @@ -644,7 +638,7 @@ public void CreateAbility() public bool IsAbilityUse() => IRoleAbility.IsCommonUse(); - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -709,10 +703,14 @@ public override string GetFullDescription() var queen = Player.GetPlayerControlById(this.queenPlayerId); string fullDesc = base.GetFullDescription(); - if (!queen) { return fullDesc; } + if (queen == null || + queen.Data == null) + { + return fullDesc; + } return string.Format( - fullDesc, queen.Data?.PlayerName); + fullDesc, queen.Data.PlayerName); } public override Color GetTargetRoleSeeColor( @@ -744,7 +742,7 @@ public override string GetRolePlayerNameTag( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { throw new Exception("Don't call this class method!!"); } diff --git a/ExtremeRoles/Roles/Solo/Neutral/TaskMaster.cs b/ExtremeRoles/Roles/Solo/Neutral/TaskMaster.cs index 3b86d8991..6dcc70449 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/TaskMaster.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/TaskMaster.cs @@ -2,13 +2,15 @@ using System.Linq; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Helper; using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Roles.API.Extension.Neutral; using ExtremeRoles.Performance; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class TaskMaster : SingleRoleBase, IRoleSpecialSetUp, IRoleUpdate @@ -44,8 +46,8 @@ public void Update(PlayerControl rolePlayer) var playerInfo = GameData.Instance.GetPlayerById( rolePlayer.PlayerId); - if (playerInfo.IsDead || - playerInfo.Disconnected || + if (playerInfo.IsDead || + playerInfo.Disconnected || playerInfo.Tasks.Count == 0) { return; } int compCount = 0; @@ -96,7 +98,7 @@ public void IntroEndSetUp() } for (int i = 0; i < this.addNormalTask; ++i) { - this.addTask.Add(GameSystem.GetRandomNormalTaskId()); + this.addTask.Add(GameSystem.GetRandomShortTaskId()); } } @@ -115,33 +117,33 @@ public override void RolePlayerKilledAction( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( TaskMasterOption.CanUseSabotage, - true, parentOps); - CreateIntOption( + true); + factory.CreateIntOption( TaskMasterOption.AddCommonTaskNum, - 1, 0, 15, 1, parentOps); - CreateIntOption( + 1, 0, 15, 1); + factory.CreateIntOption( TaskMasterOption.AddLongTaskNum, - 1, 0, 15, 1, parentOps); - CreateIntOption( + 1, 0, 15, 1); + factory.CreateIntOption( TaskMasterOption.AddNormalTaskNum, - 1, 0, 15, 1, parentOps); + 1, 0, 15, 1); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; - this.UseSabotage = allOption.GetValue( - GetRoleOptionId(TaskMasterOption.CanUseSabotage)); - this.addLongTask = allOption.GetValue( - GetRoleOptionId(TaskMasterOption.AddLongTaskNum)); - this.addNormalTask = allOption.GetValue( - GetRoleOptionId(TaskMasterOption.AddNormalTaskNum)); - this.addCommonTask = allOption.GetValue( - GetRoleOptionId(TaskMasterOption.AddCommonTaskNum)); + var cate = this.Loader; + this.UseSabotage = cate.GetValue( + TaskMasterOption.CanUseSabotage); + this.addLongTask = cate.GetValue( + TaskMasterOption.AddLongTaskNum); + this.addNormalTask = cate.GetValue( + TaskMasterOption.AddNormalTaskNum); + this.addCommonTask = cate.GetValue( + TaskMasterOption.AddCommonTaskNum); this.addTask = new List(); } private void resetTask(byte playerId) diff --git a/ExtremeRoles/Roles/Solo/Neutral/TotoCalcio.cs b/ExtremeRoles/Roles/Solo/Neutral/TotoCalcio.cs index 6d31da8bd..5b65e535a 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/TotoCalcio.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/TotoCalcio.cs @@ -1,13 +1,15 @@ using System.Collections.Generic; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Resources; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class Totocalcio : SingleRoleBase, IRoleAutoBuildAbility, IRoleWinPlayerModifier @@ -37,7 +39,7 @@ public ExtremeAbilityButton Button private ExtremeAbilityButton betButton; private float range; - private GameData.PlayerInfo betPlayer; + private NetworkedPlayerInfo betPlayer; private PlayerControl tmpTarget; private float defaultCoolTime; @@ -66,8 +68,8 @@ public static void SetBetTarget( public void CreateAbility() { this.CreateAbilityCountButton( - "betPlayer",Loader.CreateSpriteFromResources( - Path.TotocalcioBetPlayer)); + "betPlayer", Resources.Loader.CreateSpriteFromResources( + Path.TotocalcioBetPlayer)); this.Button.SetLabelToCrewmate(); } @@ -94,7 +96,7 @@ public bool IsAbilityUse() } public void ModifiedWinPlayer( - GameData.PlayerInfo rolePlayerInfo, + NetworkedPlayerInfo rolePlayerInfo, GameOverReason reason, ref ExtremeGameResult.WinnerTempData winner) { @@ -107,7 +109,7 @@ public void ModifiedWinPlayer( winner.AddWithPlus(rolePlayerInfo); } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -174,30 +176,30 @@ public override string GetRolePlayerNameTag( } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( TotocalcioOption.Range, - 1.0f, 0.0f, 2.0f, 0.1f, - parentOps); + 1.0f, 0.0f, 2.0f, 0.1f); - this.CreateAbilityCountOption(parentOps, 3, 5); + IRoleAbility.CreateAbilityCountOption(factory, 3, 5); - CreateFloatOption( + factory.CreateFloatOption( TotocalcioOption.FinalCoolTime, 80.0f, 45.0f, 180.0f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); } protected override void RoleSpecificInit() { this.betPlayer = null; - this.range = OptionManager.Instance.GetValue( - GetRoleOptionId(TotocalcioOption.Range)); - this.defaultCoolTime = OptionManager.Instance.GetValue( - GetRoleOptionId(RoleAbilityCommonOption.AbilityCoolTime)); - this.finalCoolTime = OptionManager.Instance.GetValue( - GetRoleOptionId(TotocalcioOption.FinalCoolTime)); + var cate = this.Loader; + this.range = cate.GetValue( + TotocalcioOption.Range); + this.defaultCoolTime = cate.GetValue( + RoleAbilityCommonOption.AbilityCoolTime); + this.finalCoolTime = cate.GetValue( + TotocalcioOption.FinalCoolTime); } } diff --git a/ExtremeRoles/Roles/Solo/Neutral/Umbrer.cs b/ExtremeRoles/Roles/Solo/Neutral/Umbrer.cs index cdf52859e..bc61a144b 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Umbrer.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Umbrer.cs @@ -5,7 +5,7 @@ using ExtremeRoles.GameMode; using ExtremeRoles.Module; using ExtremeRoles.Module.AbilityModeSwitcher; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Module.RoleAssign; using ExtremeRoles.Resources; using ExtremeRoles.Roles.API; @@ -14,6 +14,8 @@ using ExtremeRoles.Performance.Il2Cpp; using ExtremeRoles.Helper; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo.Neutral; public sealed class Umbrer : SingleRoleBase, IRoleAutoBuildAbility, IRoleSpecialSetUp, IRoleUpdate @@ -47,11 +49,11 @@ public bool IsAllPlayerInfected() { if (this.firstStage.Count <= 0) { return false; } - foreach (GameData.PlayerInfo player in + foreach (NetworkedPlayerInfo player in GameData.Instance.AllPlayers.GetFastEnumerator()) { - if (player == null || player?.Object == null) { continue; } - if (player.IsDead || player.Disconnected) { continue; } + if (player == null || player.Object == null || + player.IsDead || player.Disconnected) { continue; } if (!this.firstStage.Contains(player.PlayerId)) { @@ -65,7 +67,7 @@ public bool IsAllPlayerInfected() public bool IsContain(byte playerId) => this.firstStage.Contains(playerId) || this.finalStage.Contains(playerId); - public bool IsFirstStage(byte playerId) => + public bool IsFirstStage(byte playerId) => this.firstStage.Contains(playerId); public bool IsFinalStage(byte playerId) => @@ -84,7 +86,7 @@ private void removeToHashSet(ref HashSet cont) foreach (byte playerId in this.firstStage) { - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(playerId); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(playerId); if (player == null || player.IsDead || @@ -149,15 +151,15 @@ public Umbrer() : base( public void CreateAbility() { - var allOpt = OptionManager.Instance; + var cate = this.Loader; var featVirusMode = new GraphicAndActiveTimeMode( UmbrerMode.Feat, new Module.AbilityBehavior.ButtonGraphic( Translation.GetString("featVirus"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.UmbrerFeatVirus)), - allOpt.GetValue(GetRoleOptionId( - RoleAbilityCommonOption.AbilityActiveTime)) + cate.GetValue( + RoleAbilityCommonOption.AbilityActiveTime) ); this.CreateNormalAbilityButton( @@ -171,11 +173,11 @@ public void CreateAbility() UmbrerMode.Upgrage, new Module.AbilityBehavior.ButtonGraphic( Translation.GetString("upgradeVirus"), - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.UmbrerUpgradeVirus)), - allOpt.GetValue(GetRoleOptionId( + cate.GetValue( UmbrerOption.UpgradeVirusTime)) - )); + ); } public bool UseAbility() @@ -260,7 +262,7 @@ public void ResetOnMeetingStart() } } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { return; } @@ -330,31 +332,27 @@ public override bool IsSameTeam(SingleRoleBase targetRole) } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateFloatOption( + factory.CreateFloatOption( UmbrerOption.Range, - 1.0f, 0.1f, 4.0f, 0.1f, - parentOps); + 1.0f, 0.1f, 4.0f, 0.1f); - this.CreateCommonAbilityOption( - parentOps, 3.0f); + IRoleAbility.CreateCommonAbilityOption( + factory, 3.0f); - CreateFloatOption( + factory.CreateFloatOption( UmbrerOption.UpgradeVirusTime, 3.5f, 0.5f, 10.0f, 0.1f, - parentOps, format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( UmbrerOption.InfectRange, - 1.4f, 0.1f, 3.6f, 0.1f, - parentOps); + 1.4f, 0.1f, 3.6f, 0.1f); - CreateFloatOption( + factory.CreateFloatOption( UmbrerOption.KeepUpgradedVirus, 10.0f, 2.5f, 360.0f, 0.5f, - parentOps, format: OptionUnit.Second); } @@ -365,11 +363,11 @@ protected override void RoleSpecificInit() this.timer = new Dictionary(); this.playerIcon = new Dictionary(); - var allOpt = OptionManager.Instance; + var cate = this.Loader; - this.range = allOpt.GetValue(GetRoleOptionId(UmbrerOption.Range)); - this.infectRange = allOpt.GetValue(GetRoleOptionId(UmbrerOption.InfectRange)); - this.maxTimer = allOpt.GetValue(GetRoleOptionId(UmbrerOption.KeepUpgradedVirus)); + this.range = cate.GetValue(UmbrerOption.Range); + this.infectRange = cate.GetValue(UmbrerOption.InfectRange); + this.maxTimer = cate.GetValue(UmbrerOption.KeepUpgradedVirus); this.isFetch = false; } @@ -380,7 +378,7 @@ private bool isInfectOtherPlayer(PlayerControl sourcePlayer) byte sourcePlayerId = sourcePlayer.PlayerId; byte rolePlayerId = CachedPlayerControl.LocalPlayer.PlayerId; - foreach (GameData.PlayerInfo playerInfo in + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (playerInfo == null) { continue; } @@ -414,7 +412,7 @@ private void updateShowIcon(bool update = false) { foreach (var (playerId, poolPlayer) in this.playerIcon) { - GameData.PlayerInfo player = GameData.Instance.GetPlayerById(playerId); + NetworkedPlayerInfo player = GameData.Instance.GetPlayerById(playerId); if (this.container.IsContain(playerId) || player == null || diff --git a/ExtremeRoles/Roles/Solo/Neutral/Yandere.cs b/ExtremeRoles/Roles/Solo/Neutral/Yandere.cs index 1b262fcb9..e12c54cee 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Yandere.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Yandere.cs @@ -6,13 +6,16 @@ using ExtremeRoles.Helper; using ExtremeRoles.Module; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Roles.API.Interface; using ExtremeRoles.Roles.API.Extension.Neutral; using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; +using ExtremeRoles.Module.CustomOption.Factory; +using static ExtremeRoles.Roles.Solo.Neutral.Yoko; + namespace ExtremeRoles.Roles.Solo.Neutral; // TODO: 復活しても問題ないようにする #281 @@ -365,7 +368,7 @@ public void IntroEndSetUp() this.CanKill = false; } - public void ResetOnMeetingEnd(GameData.PlayerInfo exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo exiledPlayer = null) { if (this.isRunawayNextMeetingEnd) { @@ -398,81 +401,79 @@ public void ResetOnMeetingStart() } protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateIntOption( + factory.CreateIntOption( YandereOption.TargetKilledKillCoolReduceRate, 85, 25, 99, 1, - parentOps, format: OptionUnit.Percentage); + format: OptionUnit.Percentage); - CreateFloatOption( + factory.CreateFloatOption( YandereOption.NoneTargetKilledKillCoolMultiplier, 1.2f, 1.0f, 2.0f, 0.1f, - parentOps, format: OptionUnit.Multiplier); + format: OptionUnit.Multiplier); - CreateFloatOption( + factory.CreateFloatOption( YandereOption.BlockTargetTime, 5.0f, 0.5f, 30.0f, 0.5f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( YandereOption.SetTargetRange, - 1.8f, 0.5f, 5.0f, 0.1f, - parentOps); + 1.8f, 0.5f, 5.0f, 0.1f); - CreateFloatOption( + factory.CreateFloatOption( YandereOption.SetTargetTime, 2.0f, 0.1f, 7.5f, 0.1f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateIntOption( + factory.CreateIntOption( YandereOption.MaxTargetNum, - 5, 1, GameSystem.VanillaMaxPlayerNum, 1, parentOps); + 5, 1, GameSystem.VanillaMaxPlayerNum, 1); - CreateFloatOption( + factory.CreateFloatOption( YandereOption.RunawayTime, 60.0f, 25.0f, 120.0f, 0.25f, - parentOps, format: OptionUnit.Second); + format: OptionUnit.Second); - CreateBoolOption( + factory.CreateBoolOption( YandereOption.HasOneSidedArrow, - true, parentOps); + true); - CreateBoolOption( + factory.CreateBoolOption( YandereOption.HasTargetArrow, - true, parentOps); + true); } protected override void RoleSpecificInit() { - var allOption = OptionManager.Instance; - + var cate = this.Loader; - this.setTargetRange = allOption.GetValue( - GetRoleOptionId(YandereOption.SetTargetRange)); - this.setTargetTime = allOption.GetValue( - GetRoleOptionId(YandereOption.SetTargetTime)); + this.setTargetRange = cate.GetValue( + YandereOption.SetTargetRange); + this.setTargetTime = cate.GetValue( + YandereOption.SetTargetTime); - this.targetKillReduceRate = allOption.GetValue( - GetRoleOptionId(YandereOption.TargetKilledKillCoolReduceRate)); - this.noneTargetKillMultiplier = allOption.GetValue( - GetRoleOptionId(YandereOption.NoneTargetKilledKillCoolMultiplier)); + this.targetKillReduceRate = cate.GetValue( + YandereOption.TargetKilledKillCoolReduceRate); + this.noneTargetKillMultiplier = cate.GetValue( + YandereOption.NoneTargetKilledKillCoolMultiplier); - this.maxTargetNum = allOption.GetValue( - GetRoleOptionId(YandereOption.MaxTargetNum)); + this.maxTargetNum = cate.GetValue( + YandereOption.MaxTargetNum); this.timer = 0.0f; - this.timeLimit = allOption.GetValue( - GetRoleOptionId(YandereOption.RunawayTime)); + this.timeLimit = cate.GetValue( + YandereOption.RunawayTime); this.blockTimer = 0.0f; - this.blockTargetTime = allOption.GetValue( - GetRoleOptionId(YandereOption.BlockTargetTime)); + this.blockTargetTime = cate.GetValue( + YandereOption.BlockTargetTime); - this.hasOneSidedArrow = allOption.GetValue( - GetRoleOptionId(YandereOption.HasOneSidedArrow)); + this.hasOneSidedArrow = cate.GetValue( + YandereOption.HasOneSidedArrow); this.target = new KillTarget( - allOption.GetValue(GetRoleOptionId(YandereOption.HasTargetArrow))); + cate.GetValue(YandereOption.HasTargetArrow)); this.progress = new Dictionary(); @@ -514,7 +515,7 @@ private void searchTarget( PlayerControl rolePlayer, Vector2 pos) { - foreach (GameData.PlayerInfo playerInfo in + foreach (NetworkedPlayerInfo playerInfo in GameData.Instance.AllPlayers.GetFastEnumerator()) { diff --git a/ExtremeRoles/Roles/Solo/Neutral/Yoko.cs b/ExtremeRoles/Roles/Solo/Neutral/Yoko.cs index 26cab1dc5..625e0e1f9 100644 --- a/ExtremeRoles/Roles/Solo/Neutral/Yoko.cs +++ b/ExtremeRoles/Roles/Solo/Neutral/Yoko.cs @@ -14,6 +14,9 @@ using ExtremeRoles.Performance; using ExtremeRoles.Performance.Il2Cpp; + +using ExtremeRoles.Module.CustomOption.Factory; + using BepInEx.Unity.IL2CPP.Utils; #nullable enable @@ -70,7 +73,7 @@ public Yoko() : base( { } public void ModifiedWinPlayer( - GameData.PlayerInfo rolePlayerInfo, + NetworkedPlayerInfo rolePlayerInfo, GameOverReason reason, ref ExtremeGameResult.WinnerTempData winner) { @@ -104,77 +107,69 @@ public override bool IsSameTeam(SingleRoleBase targetRole) => this.IsNeutralSameTeam(targetRole); protected override void CreateSpecificOption( - IOptionInfo parentOps) + AutoParentSetOptionCategoryFactory factory) { - CreateBoolOption( + factory.CreateBoolOption( YokoOption.CanRepairSabo, - false, parentOps); - CreateBoolOption( + false); + factory.CreateBoolOption( YokoOption.CanUseVent, - false, parentOps); - CreateFloatOption( + false); + factory.CreateFloatOption( YokoOption.SearchRange, - 7.5f, 5.0f, 15.0f, 0.5f, - parentOps); - CreateFloatOption( + 7.5f, 5.0f, 15.0f, 0.5f); + factory.CreateFloatOption( YokoOption.SearchTime, 10f, 3.0f, 30f, 0.5f, - parentOps, format: OptionUnit.Second); - CreateIntOption( + factory.CreateIntOption( YokoOption.TrueInfoRate, - 50, 25, 80, 5, parentOps, + 50, 25, 80, 5, format: OptionUnit.Percentage); - var yashiroOpt = CreateBoolOption( + var yashiroOpt = factory.CreateBoolOption( YokoOption.UseYashiro, - false, parentOps); - this.CreateAbilityCountOption(yashiroOpt, 3, 10, 5f); + false); + IRoleAbility.CreateAbilityCountOption(factory, 3, 10, 5f, parentOpt: yashiroOpt); - CreateIntOption( + factory.CreateIntOption( YokoOption.YashiroActiveTime, 30, 1, 360, 1, yashiroOpt, format: OptionUnit.Second); - CreateIntOption( + factory.CreateIntOption( YokoOption.YashiroSeelTime, 10, 1, 360, 1, yashiroOpt, format: OptionUnit.Second); - CreateFloatOption( + factory.CreateFloatOption( YokoOption.YashiroProtectRange, 5.0f, 1.0f, 10.0f, 0.1f, yashiroOpt); - CreateBoolOption( + factory.CreateBoolOption( YokoOption.YashiroUpdateWithMeeting, true, yashiroOpt); } protected override void RoleSpecificInit() { - var opt = OptionManager.Instance; - this.CanRepairSabotage = opt.GetValue( - GetRoleOptionId(YokoOption.CanRepairSabo)); - this.UseVent = opt.GetValue( - GetRoleOptionId(YokoOption.CanUseVent)); - this.searchRange = opt.GetValue( - GetRoleOptionId(YokoOption.SearchRange)); - this.searchTime = opt.GetValue( - GetRoleOptionId(YokoOption.SearchTime)); - this.trueInfoGage = opt.GetValue( - GetRoleOptionId(YokoOption.TrueInfoRate)); + var cate = this.Loader; + this.CanRepairSabotage = cate.GetValue(YokoOption.CanRepairSabo); + this.UseVent = cate.GetValue(YokoOption.CanUseVent); + this.searchRange = cate.GetValue(YokoOption.SearchRange); + this.searchTime = cate.GetValue(YokoOption.SearchTime); + this.trueInfoGage = cate.GetValue(YokoOption.TrueInfoRate); this.yashiro = null; - if (opt.GetValue(GetRoleOptionId(YokoOption.UseYashiro))) + if (cate.GetValue(YokoOption.UseYashiro)) { - float activeTime = opt.GetValue(GetRoleOptionId(YokoOption.YashiroActiveTime)); - float sealTime = opt.GetValue(GetRoleOptionId(YokoOption.YashiroSeelTime)); - float protectRange = opt.GetValue(GetRoleOptionId(YokoOption.YashiroProtectRange)); - bool isUpdateMeeting = opt.GetValue( - GetRoleOptionId(YokoOption.YashiroUpdateWithMeeting)); + float activeTime = cate.GetValue(YokoOption.YashiroActiveTime); + float sealTime = cate.GetValue(YokoOption.YashiroSeelTime); + float protectRange = cate.GetValue(YokoOption.YashiroProtectRange); + bool isUpdateMeeting = cate.GetValue(YokoOption.YashiroUpdateWithMeeting); this.yashiro = ExtremeSystemTypeManager.Instance.CreateOrGet( YokoYashiroSystem.Type, @@ -183,7 +178,7 @@ protected override void RoleSpecificInit() this.timer = this.searchTime; } - public void ResetOnMeetingEnd(GameData.PlayerInfo? exiledPlayer = null) + public void ResetOnMeetingEnd(NetworkedPlayerInfo? exiledPlayer = null) { return; } @@ -223,7 +218,7 @@ public void Update(PlayerControl rolePlayer) this.timer = this.searchTime; bool isEnemy = false; - foreach (GameData.PlayerInfo player in GameData.Instance.AllPlayers.GetFastEnumerator()) + foreach (NetworkedPlayerInfo player in GameData.Instance.AllPlayers.GetFastEnumerator()) { if (player == null || @@ -359,7 +354,7 @@ public void CreateAbility() { this.CreateAbilityCountButton( "yokoYashiro", - Loader.CreateSpriteFromResources( + Resources.Loader.CreateSpriteFromResources( Path.YokoYashiro), this.IsAbilityActive, this.CleanUp, diff --git a/ExtremeRoles/Roles/Solo/VanillaRoleWrapper.cs b/ExtremeRoles/Roles/Solo/VanillaRoleWrapper.cs index a1d20fbb8..5e183d96c 100644 --- a/ExtremeRoles/Roles/Solo/VanillaRoleWrapper.cs +++ b/ExtremeRoles/Roles/Solo/VanillaRoleWrapper.cs @@ -2,12 +2,14 @@ using AmongUs.GameOptions; using ExtremeRoles.GameMode; -using ExtremeRoles.Module.CustomOption; + using ExtremeRoles.Roles.API; using ExtremeRoles.Performance; using ExtremeRoles.Helper; using ExtremeRoles.Roles.API.Interface; +using ExtremeRoles.Module.CustomOption.Factory; + namespace ExtremeRoles.Roles.Solo; public sealed class VanillaRoleWrapper : MultiAssignRoleBase @@ -44,8 +46,8 @@ private VanillaRoleWrapper(RoleTypes id, bool isImpostor) : base( } public VanillaRoleWrapper( - RoleTypes id) : - this(id, id == RoleTypes.Impostor || id == RoleTypes.Shapeshifter) + RoleTypes id) : + this(id, id is RoleTypes.Impostor or RoleTypes.Shapeshifter or RoleTypes.Phantom) { } public override void OverrideAnotherRoleSetting() @@ -73,7 +75,7 @@ public override string GetFullDescription() public override string GetColoredRoleName(bool isTruthColor = false) { - if (!isTruthColor && + if (!isTruthColor && (this.AnotherRole is IRoleAwake awakeRole && !awakeRole.IsAwake)) { return Design.ColoedString( @@ -143,7 +145,7 @@ protected override void RoleSpecificInit() return; } - protected override void CreateSpecificOption(IOptionInfo parentOps) + protected override void CreateSpecificOption(AutoParentSetOptionCategoryFactory factory) { throw new System.Exception("Don't call this class method!!"); } @@ -154,16 +156,16 @@ private string getVanilaImportantText(bool isContainFakeTask = true) { var trans = FastDestroyableSingleton.Instance; - return string.Concat(new string[] - { + return string.Concat( + [ trans.GetString(StringNames.ImpostorTask, Array.Empty()), "\r\n", Palette.ImpostorRed.ToTextColor(), - isContainFakeTask ? - trans.GetString(StringNames.FakeTasks, Array.Empty()) : + isContainFakeTask ? + trans.GetString(StringNames.FakeTasks, Array.Empty()) : string.Empty, "" - }); + ]); } return Design.ColoedString( diff --git a/ExtremeRolesTransData.xlsx b/ExtremeRolesTransData.xlsx index 2bc06bbde..3103d4fa3 100644 Binary files a/ExtremeRolesTransData.xlsx and b/ExtremeRolesTransData.xlsx differ diff --git a/ExtremeSkins/ExtremeSkins.csproj b/ExtremeSkins/ExtremeSkins.csproj index 2c76d82ee..853e4ae2f 100644 --- a/ExtremeSkins/ExtremeSkins.csproj +++ b/ExtremeSkins/ExtremeSkins.csproj @@ -3,9 +3,9 @@ net6.0 latest 7 - 9.0.0.10 - - AmongUsV2024305 + + 10.0.0 + AmongUsv20240618 Extreme Skins for Extreme Roles yukieiji Debug;Release @@ -27,7 +27,7 @@ - + diff --git a/ExtremeSkins/Helper/CustomCosmicTab.cs b/ExtremeSkins/Helper/CustomCosmicTab.cs index f2cbf679b..9437061b1 100644 --- a/ExtremeSkins/Helper/CustomCosmicTab.cs +++ b/ExtremeSkins/Helper/CustomCosmicTab.cs @@ -5,6 +5,7 @@ using UnityEngine; using ExtremeSkins.Patches.AmongUs.Tab; +using Innersloth.Assets; namespace ExtremeSkins.Helper; @@ -60,7 +61,18 @@ public static void AddTmpTextPackageName( } } - public static void RemoveAllTabs() + public static void SetPreviewToRawSprite(ColorChip colorChip, Sprite? sprite, int color) + { + var renderer = colorChip.Inner.FrontLayer; + renderer.sprite = sprite; + AddressableAssetHandler.AddToGameObject(renderer.gameObject); + if (Application.isPlaying) + { + PlayerMaterial.SetColors(color, renderer); + } + } + + public static void RemoveAllTabs() { #if WITHHAT if (HatsTabPatch.Tab != null) diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeHat/GetHatHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeHat/GetHatHandler.cs index ebcc3d8a7..fddee7dc1 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeHat/GetHatHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeHat/GetHatHandler.cs @@ -10,6 +10,7 @@ namespace ExtremeSkins.Module.ApiHandler.ExtremeHat; +#if WITHHAT public sealed class GetHatHandler : IRequestHandler { public Action Request => this.requestAction; @@ -25,4 +26,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.Write(response, curData); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeHat/PostNewHatHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeHat/PostNewHatHandler.cs index 01f5b1a81..2acf1e26d 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeHat/PostNewHatHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeHat/PostNewHatHandler.cs @@ -15,6 +15,8 @@ namespace ExtremeSkins.Module.ApiHandler.ExtremeHat; +#if WITHHAT + public sealed class PostNewHatHandler : IRequestHandler { public Action Request => this.requestAction; @@ -63,4 +65,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.SetStatusOK(response); response.Close(); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeHat/PutHatHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeHat/PutHatHandler.cs index 12c730831..ef50a10d6 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeHat/PutHatHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeHat/PutHatHandler.cs @@ -15,6 +15,8 @@ namespace ExtremeSkins.Module.ApiHandler.ExtremeHat; +#if WITHHAT + public sealed class PutHatHandler : IRequestHandler { public Action Request => this.requestAction; @@ -81,4 +83,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.SetStatusOK(response); response.Close(); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/GetNamePlateHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/GetNamePlateHandler.cs index a8a483f4c..246f5b887 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/GetNamePlateHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/GetNamePlateHandler.cs @@ -7,7 +7,7 @@ using ExtremeSkins.SkinManager; namespace ExtremeSkins.Module.ApiHandler.ExtremeNamePlate; - +#if WITHNAMEPLATE public sealed class GetNamePlateHandler : IRequestHandler { @@ -24,4 +24,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.Write(response, curData); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PostNewNamePlateHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PostNewNamePlateHandler.cs index 7b2c94302..c3aec1422 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PostNewNamePlateHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PostNewNamePlateHandler.cs @@ -12,6 +12,7 @@ namespace ExtremeSkins.Module.ApiHandler.ExtremeNamePlate; +#if WITHNAMEPLATE public sealed class PostNewNamePlateHandler : IRequestHandler { public Action Request => this.requestAction; @@ -54,4 +55,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.SetStatusOK(response); response.Close(); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PutNamePlateHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PutNamePlateHandler.cs index 06623f0ea..6dc3ca821 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PutNamePlateHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeNamePlate/PutNamePlateHandler.cs @@ -12,6 +12,7 @@ namespace ExtremeSkins.Module.ApiHandler.ExtremeNamePlate; +#if WITHNAMEPLATE public sealed class PutNamePlateHandler : IRequestHandler { public Action Request => this.requestAction; @@ -71,4 +72,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.SetStatusOK(response); response.Close(); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeVisor/GetVisorHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeVisor/GetVisorHandler.cs index c708d35e3..ada3803a2 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeVisor/GetVisorHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeVisor/GetVisorHandler.cs @@ -7,6 +7,7 @@ using ExtremeSkins.SkinManager; namespace ExtremeSkins.Module.ApiHandler.ExtremeVisor; +#if WITHVISOR public sealed class GetVisorHandler : IRequestHandler { @@ -24,4 +25,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.Write(response, curData); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PostNewVisorHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PostNewVisorHandler.cs index 846906fab..208f0789f 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PostNewVisorHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PostNewVisorHandler.cs @@ -14,7 +14,7 @@ using ExtremeSkins.Helper; namespace ExtremeSkins.Module.ApiHandler.ExtremeVisor; - +#if WITHVISOR public sealed class PostNewVisorHandler : IRequestHandler { public Action Request => this.requestAction; @@ -62,4 +62,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.SetStatusOK(response); response.Close(); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PutVisorHandler.cs b/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PutVisorHandler.cs index df819854f..6c7c9922d 100644 --- a/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PutVisorHandler.cs +++ b/ExtremeSkins/Module/ApiHandler/ExtremeVisor/PutVisorHandler.cs @@ -14,6 +14,7 @@ using ExtremeSkins.Helper; namespace ExtremeSkins.Module.ApiHandler.ExtremeVisor; +#if WITHVISOR public sealed class PutVisorHandler : IRequestHandler { @@ -81,4 +82,5 @@ private void requestAction(HttpListenerContext context) IRequestHandler.SetStatusOK(response); response.Close(); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/AssetWrapper.cs b/ExtremeSkins/Module/AssetWrapper.cs index a6c70596b..1e2c9a7a6 100644 --- a/ExtremeSkins/Module/AssetWrapper.cs +++ b/ExtremeSkins/Module/AssetWrapper.cs @@ -7,7 +7,7 @@ using ExtremeRoles.Module; namespace ExtremeSkins.Module; - +#if WITHHAT [Il2CppRegister] public sealed class HatAddressableAsset : AddressableAsset { @@ -124,7 +124,9 @@ public override void Destroy() public override AssetLoadState GetState() => AssetLoadState.Success; } +#endif +#if WITHVISOR [Il2CppRegister] public sealed class VisorAddressableAsset : AddressableAsset { @@ -183,3 +185,4 @@ public override void Destroy() public override AssetLoadState GetState() => AssetLoadState.Success; } +#endif \ No newline at end of file diff --git a/ExtremeSkins/Module/CustomHat.cs b/ExtremeSkins/Module/CustomHat.cs index 323016fb7..135b851ca 100644 --- a/ExtremeSkins/Module/CustomHat.cs +++ b/ExtremeSkins/Module/CustomHat.cs @@ -43,6 +43,7 @@ public string Id { get => $"hat_{new DirectoryInfo(this.FolderPath).Name}_{this.Author}_{this.Name}"; } + public Sprite? Preview { get; private set; } protected readonly string FolderPath; protected readonly HatInfo Info; @@ -85,7 +86,7 @@ public virtual HatViewData GetViewData() private HatViewData createView() { var view = ScriptableObject.CreateInstance(); - view.MainImage = GetSprite(Path.Combine(this.FolderPath, DataStructure.FrontImageName)); + view.MainImage = this.Preview; if (this.Info.FrontFlip) { @@ -127,7 +128,7 @@ private HatData crateData() data.NotInStore = true; data.PreviewCrewmateColor = this.Info.Shader; - data.SpritePreview = GetSprite(Path.Combine(this.FolderPath, DataStructure.FrontImageName)); + this.Preview = GetSprite(Path.Combine(this.FolderPath, DataStructure.FrontImageName)); this.HatView = ScriptableObject.CreateInstance(); data.ViewDataRef = new AssetReference(this.HatView.Pointer); @@ -258,7 +259,7 @@ animation.BackFlip is not null && sprite = GetSprite(Path.Combine(this.FolderPath, path)); if (sprite == null) { - sprite = this.Data.SpritePreview; + sprite = this.Preview; } this.cacheSprite.Add(path, sprite); } diff --git a/ExtremeSkins/Module/CustomNamePlate.cs b/ExtremeSkins/Module/CustomNamePlate.cs index ae9513c82..ac25a5632 100644 --- a/ExtremeSkins/Module/CustomNamePlate.cs +++ b/ExtremeSkins/Module/CustomNamePlate.cs @@ -32,6 +32,7 @@ public string Id private string name; private string author; private string imgPath; + public Sprite? Preview { get; private set; } private NamePlateViewData? viewData; public CustomNamePlate( @@ -65,7 +66,7 @@ public NamePlateViewData GetViewData() if (this.viewData == null) { this.viewData = ScriptableObject.CreateInstance(); - this.viewData.Image = getSprite(this.imgPath); + this.viewData.Image = this.Preview; } return this.viewData; } @@ -84,9 +85,8 @@ public NamePlateData GetData() this.Data.PreviewCrewmateColor = false; this.viewData = ScriptableObject.CreateInstance(); - var img = getSprite(this.imgPath); - this.viewData.Image = img; - this.Data.SpritePreview = img; + this.Preview = getSprite(this.imgPath); + this.viewData.Image = this.Preview; this.Data.ViewDataRef = new AssetReference(this.viewData.Pointer); return this.Data; diff --git a/ExtremeSkins/Module/CustomVisor.cs b/ExtremeSkins/Module/CustomVisor.cs index 26f36138a..848dbedd8 100644 --- a/ExtremeSkins/Module/CustomVisor.cs +++ b/ExtremeSkins/Module/CustomVisor.cs @@ -43,6 +43,8 @@ public string Id get => $"visor_{new DirectoryInfo(this.FolderPath).Name}_{this.Author}_{this.Name}"; } + public Sprite? Preview { get; private set; } + protected readonly string FolderPath; protected readonly VisorInfo Info; protected VisorViewData? View; @@ -94,7 +96,7 @@ private VisorData createData() data.Free = true; data.NotInStore = true; - data.SpritePreview = GetSprite(Path.Combine(this.FolderPath, DataStructure.IdleImageName)); + this.Preview = GetSprite(Path.Combine(this.FolderPath, DataStructure.IdleImageName)); data.behindHats = this.Info.BehindHat; data.PreviewCrewmateColor = this.Info.Shader; @@ -109,8 +111,7 @@ private VisorViewData loadViewData() { var view = ScriptableObject.CreateInstance(); - view.IdleFrame = GetSprite( - Path.Combine(this.FolderPath, DataStructure.IdleImageName)); + view.IdleFrame = this.Preview; if (this.Info.LeftIdle) { @@ -212,7 +213,7 @@ animation.LeftIdle is not null && sprite = GetSprite(Path.Combine(this.FolderPath, path)); if (sprite == null) { - sprite = this.Data.SpritePreview; + sprite = this.Preview; } this.cacheSprite.Add(path, sprite); } diff --git a/ExtremeSkins/Module/Interface/ICustomCosmicData.cs b/ExtremeSkins/Module/Interface/ICustomCosmicData.cs index 57be9271a..00c15b378 100644 --- a/ExtremeSkins/Module/Interface/ICustomCosmicData.cs +++ b/ExtremeSkins/Module/Interface/ICustomCosmicData.cs @@ -12,6 +12,7 @@ public interface ICustomCosmicData public string Name { get; } public string Id { get; } + public Sprite? Preview { get; } public C GetViewData(); } diff --git a/ExtremeSkins/Patches/AmongUs/Manager/GameStartManagerPatchPatch.cs b/ExtremeSkins/Patches/AmongUs/Manager/GameStartManagerPatchPatch.cs index 8b6840446..56c6727f7 100644 --- a/ExtremeSkins/Patches/AmongUs/Manager/GameStartManagerPatchPatch.cs +++ b/ExtremeSkins/Patches/AmongUs/Manager/GameStartManagerPatchPatch.cs @@ -150,7 +150,7 @@ public static void UpdatePostfix(GameStartManager __instance) } } } - + /* if (blockStart) { __instance.StartButton.color = __instance.startLabelText.color = Palette.DisabledClear; @@ -163,6 +163,7 @@ public static void UpdatePostfix(GameStartManager __instance) (__instance.LastPlayerCount >= __instance.MinPlayers) ? Palette.EnabledColor : Palette.DisabledClear); __instance.GameStartText.transform.localPosition = __instance.StartButton.transform.localPosition; } + */ } diff --git a/ExtremeSkins/Patches/AmongUs/PlayerControlPatch.cs b/ExtremeSkins/Patches/AmongUs/PlayerControlPatch.cs index 62f334979..21db53834 100644 --- a/ExtremeSkins/Patches/AmongUs/PlayerControlPatch.cs +++ b/ExtremeSkins/Patches/AmongUs/PlayerControlPatch.cs @@ -27,7 +27,7 @@ public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] byte bo private static bool isTaken(PlayerControl player, uint color) { - foreach (GameData.PlayerInfo info in GameData.Instance.AllPlayers) + foreach (NetworkedPlayerInfo info in GameData.Instance.AllPlayers) { if (!info.Disconnected && info.PlayerId != player.PlayerId && diff --git a/ExtremeSkins/Patches/AmongUs/Tab/HatsTabPatch.cs b/ExtremeSkins/Patches/AmongUs/Tab/HatsTabPatch.cs index 44af01b27..7532e3598 100644 --- a/ExtremeSkins/Patches/AmongUs/Tab/HatsTabPatch.cs +++ b/ExtremeSkins/Patches/AmongUs/Tab/HatsTabPatch.cs @@ -174,7 +174,16 @@ private static void createHatTab( CachedPlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color; __instance.UpdateMaterials(colorChip.Inner.FrontLayer, hat); - hat.SetPreview(colorChip.Inner.FrontLayer,color); + if (ExtremeHatManager.HatData.TryGetValue( + hat.ProductId, out var customHat) && + customHat != null) + { + CustomCosmicTab.SetPreviewToRawSprite(colorChip, customHat.Preview, color); + } + else + { + hat.SetPreview(colorChip.Inner.FrontLayer, color); + } colorChip.SelectionHighlight.gameObject.SetActive(false); __instance.ColorChips.Add(colorChip); diff --git a/ExtremeSkins/Patches/AmongUs/Tab/VisorsTabPatch.cs b/ExtremeSkins/Patches/AmongUs/Tab/VisorsTabPatch.cs index 7fff06d33..6c75c033c 100644 --- a/ExtremeSkins/Patches/AmongUs/Tab/VisorsTabPatch.cs +++ b/ExtremeSkins/Patches/AmongUs/Tab/VisorsTabPatch.cs @@ -170,7 +170,16 @@ private static void createVisorTab( DataManager.Player.Customization.Color; __instance.UpdateMaterials(colorChip.Inner.FrontLayer, vi); - vi.SetPreview(colorChip.Inner.FrontLayer, color); + if (ExtremeVisorManager.VisorData.TryGetValue( + vi.ProductId, out var customVi) && + customVi != null) + { + CustomCosmicTab.SetPreviewToRawSprite(colorChip, customVi.Preview, color); + } + else + { + vi.SetPreview(colorChip.Inner.FrontLayer, color); + } __instance.ColorChips.Add(colorChip); diff --git a/ExtremeVoiceEngine/ExtremeVoiceEngine.csproj b/ExtremeVoiceEngine/ExtremeVoiceEngine.csproj index 210ffa915..b49353492 100644 --- a/ExtremeVoiceEngine/ExtremeVoiceEngine.csproj +++ b/ExtremeVoiceEngine/ExtremeVoiceEngine.csproj @@ -6,7 +6,7 @@ 7 2.0.0.61 - AmongUsV20230711 + Extreme Voice Engine for bridging Extreme Roles and Voice Engine yukieiji Debug;Release @@ -28,7 +28,7 @@ - + diff --git a/ExtremeVoiceEngine/Patches/ChatControllerPatch.cs b/ExtremeVoiceEngine/Patches/ChatControllerPatch.cs index 14cf144c0..f2286c514 100644 --- a/ExtremeVoiceEngine/Patches/ChatControllerPatch.cs +++ b/ExtremeVoiceEngine/Patches/ChatControllerPatch.cs @@ -12,8 +12,8 @@ public static void Postfix( [HarmonyArgument(0)] PlayerControl sourcePlayer, [HarmonyArgument(1)] string chatText) { - GameData.PlayerInfo localPlayerData = CachedPlayerControl.LocalPlayer.Data; - GameData.PlayerInfo sourcePlayerData = sourcePlayer.Data; + NetworkedPlayerInfo localPlayerData = CachedPlayerControl.LocalPlayer.Data; + NetworkedPlayerInfo sourcePlayerData = sourcePlayer.Data; if (VoiceEngine.Instance == null || chatText.StartsWith(Command.CommandManager.CmdChar) ||