Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/Extensions/AmongUsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,11 @@ public static Texture2D CreateEmptyTexture(int width = 0, int height = 0)
public static TMPro.TextMeshPro NameText(this PoolablePlayer p) => p.cosmetics.nameText;

public static UnityEngine.SpriteRenderer myRend(this PlayerControl p) => p.cosmetics.currentBodySprite.BodySprite;

// Add a method to calculate weighted role probabilities based on the session's role history.
public static Dictionary<RoleEnum, float> CalculateWeightedRoleProbabilities(PlayerControl player) {
// Placeholder for actual implementation
return new Dictionary<RoleEnum, float>();
}
}
}
23 changes: 23 additions & 0 deletions source/Patches/AmongUsClient_OnGameEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,31 @@ namespace TownOfUs
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.Start))]
public class EndGameManager_SetEverythingUp
{
// Implement a method to record the roles assigned to each player at the end of a game.
// Store the role history in a session-based collection.
private static Dictionary<byte, List<RoleEnum>> _sessionRoleHistory = new Dictionary<byte, List<RoleEnum>>();

public static void RecordSessionRoles() {
foreach (var player in PlayerControl.AllPlayerControls) {
var playerId = player.PlayerId;
var roleType = Role.GetRole(player)?.RoleType ?? RoleEnum.None;

if (!_sessionRoleHistory.ContainsKey(playerId)) {
_sessionRoleHistory[playerId] = new List<RoleEnum>();
}
if (_sessionRoleHistory[playerId].Count > CustomGameOptions.MaxRoleHistoryListSize) {
_sessionRoleHistory[playerId].RemoveRange(0, _sessionRoleHistory[playerId].Count - CustomGameOptions.MaxRoleHistoryListSize);
}
_sessionRoleHistory[playerId].Add(roleType);
}
}

public static void Prefix()
{
if (CustomGameOptions.WeightedRoleSelection)
{
RecordSessionRoles(); // Record roles at the end of each game
}
List<int> losers = new List<int>();
foreach (var role in Role.GetRoles(RoleEnum.Amnesiac))
{
Expand Down
7 changes: 6 additions & 1 deletion source/Patches/CustomGameOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public enum AdminDeadPlayers
}
public static class CustomGameOptions
{
// Define a new game option to enable or disable the weighted role selection system.
public static bool WeightedRoleSelection = Generate.WeightedRoleSelection.Get();
// Define a new game option to set the maximum size of the role history list.
public static int MaxRoleHistoryListSize = 100; // always value at 100 for better performance and user cannot modify it in the game

public static int MayorOn => (int)Generate.MayorOn.Get();
public static int JesterOn => (int)Generate.JesterOn.Get();
public static int SheriffOn => (int)Generate.SheriffOn.Get();
Expand Down Expand Up @@ -383,4 +388,4 @@ public static class CustomGameOptions
public static bool HunterBodyReport => Generate.HunterBodyReport.Get();
public static bool DoomsayerCantObserve => Generate.DoomsayerCantObserve.Get();
}
}
}
5 changes: 4 additions & 1 deletion source/Patches/CustomOption/Generate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ public class Generate
public static CustomNumberOption ChillDuration;
public static CustomNumberOption ChillStartSpeed;

public static CustomToggleOption WeightedRoleSelection;

public static Func<object, string> PercentFormat { get; } = value => $"{value:0}%";
private static Func<object, string> CooldownFormat { get; } = value => $"{value:0.0#}s";
private static Func<object, string> MultiplierFormat { get; } = value => $"{value:0.0#}x";
Expand Down Expand Up @@ -1297,7 +1299,6 @@ public static void GenerateAll()
Frosty = new CustomHeaderOption(num++, MultiMenu.modifiers, "<color=#99FFFFFF>Frosty</color>");
ChillDuration = new CustomNumberOption(num++, MultiMenu.modifiers, "Chill Duration", 10f, 1f, 15f, 1f, CooldownFormat);
ChillStartSpeed = new CustomNumberOption(num++, MultiMenu.modifiers, "Chill Start Speed", 0.75f, 0.25f, 0.95f, 0.05f, MultiplierFormat);

Flash = new CustomHeaderOption(num++, MultiMenu.modifiers, "<color=#FF8080FF>Flash</color>");
FlashSpeed = new CustomNumberOption(num++, MultiMenu.modifiers, "Flash Speed", 1.25f, 1.05f, 2.5f, 0.05f, MultiplierFormat);

Expand All @@ -1314,6 +1315,8 @@ public static void GenerateAll()
Underdog = new CustomHeaderOption(num++, MultiMenu.modifiers, "<color=#FF0000FF>Underdog</color>");
UnderdogKillBonus = new CustomNumberOption(num++, MultiMenu.modifiers, "Kill Cooldown Bonus", 5f, 2.5f, 10f, 2.5f, CooldownFormat);
UnderdogIncreasedKC = new CustomToggleOption(num++, MultiMenu.modifiers, "Increased Kill Cooldown When 2+ Imps", true);

WeightedRoleSelection = new CustomToggleOption(num++, MultiMenu.main, "Record Roles On each game ends (weighted role selection)", true);
}
}
}