Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
yukieiji committed Jun 26, 2024
2 parents 6c1c12b + c39493e commit 9fc3de4
Show file tree
Hide file tree
Showing 329 changed files with 8,004 additions and 5,441 deletions.
2 changes: 1 addition & 1 deletion ExtremeRoles.Test/ExtremeRoles.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="BepInEx.Unity.Common" Version="6.0.0-be.671" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.671" />
<PackageReference Include="HarmonyX" Version="2.10.1" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.6.4" PrivateAssets="all" />
<PackageReference Include="AmongUs.GameLibs.Steam" Version="2024.6.18" PrivateAssets="all" />
<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.Unity.Analyzers" Version="1.18.0">
Expand Down
24 changes: 18 additions & 6 deletions ExtremeRoles.Test/GameTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using ExtremeRoles.GameMode.Option.ShipGlobal;

using UnityResource = UnityEngine.Resources;
using ExtremeRoles.Module.CustomOption;

namespace ExtremeRoles.Test;

Expand All @@ -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,
Expand Down Expand Up @@ -62,7 +63,9 @@ public override void Run()
() =>
{
GameUtility.UpdateExROption(
new((int)GlobalOption.IsSameNeutralSameWin, 1));
OptionTab.General,
(int)ShipGlobalOptionCategory.NeutralWinOption,
new RequireOption<int, int>((int)NeutralWinOption.IsSame, 1));
}),
new("NeutralWin", 100,
[
Expand All @@ -73,7 +76,9 @@ public override void Run()
() =>
{
GameUtility.UpdateExROption(
new((int)GlobalOption.IsSameNeutralSameWin, 1));
OptionTab.General,
(int)ShipGlobalOptionCategory.NeutralWinOption,
new RequireOption<int, int>((int)NeutralWinOption.IsSame, 1));
GameUtility.UpdateAmongUsOption(
new RequireOption<Int32OptionNames, int>(
Int32OptionNames.NumImpostors, 0));
Expand All @@ -82,7 +87,9 @@ public override void Run()
() =>
{
GameUtility.UpdateExROption(
new((int)GlobalOption.IsSameNeutralSameWin, 0));
OptionTab.General,
(int)ShipGlobalOptionCategory.NeutralWinOption,
new RequireOption<int, int>((int)NeutralWinOption.IsSame, 1));
GameUtility.UpdateAmongUsOption(
new RequireOption<Int32OptionNames, int>(
Int32OptionNames.NumImpostors, 3));
Expand Down Expand Up @@ -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();
Expand Down
155 changes: 100 additions & 55 deletions ExtremeRoles.Test/Helper/GameUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, W>(T OptionId, W Velue)
Expand All @@ -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)
Expand Down Expand Up @@ -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<OptionTab>())
{
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();
Expand All @@ -103,38 +119,51 @@ public static void PrepereGameWithRole(ManualLogSource logger, HashSet<ExtremeRo
{
logger.LogInfo("Update Option....");
// オプションを適当にアプデ
foreach (var opt in OptionManager.Instance.GetAllIOption())

var mng = OptionManager.Instance;
foreach (var tab in Enum.GetValues<OptionTab>())
{
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();
Expand All @@ -149,11 +178,12 @@ public static void PrepereGameWithRole(ManualLogSource logger, HashSet<ExtremeRo
}
}

public static void UpdateExROption(in RequireOption<int, int> option)
public static void UpdateExROption(OptionTab tab, int categoryId, in RequireOption<int, int> 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<BoolOptionNames, bool> option)
Expand All @@ -180,23 +210,38 @@ public static void UpdateAmongUsOption(in RequireOption<FloatOptionNames, float>

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}");
}
}
4 changes: 2 additions & 2 deletions ExtremeRoles.Test/Helper/RandomRoleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
53 changes: 23 additions & 30 deletions ExtremeRoles.Test/OptionRunner.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<OptionTab>())
{
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}");
}
}
}
}
}
Expand Down Expand Up @@ -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}");
}
}
}
}
Loading

0 comments on commit 9fc3de4

Please sign in to comment.