Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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>();
}
}
}
21 changes: 21 additions & 0 deletions source/Patches/AmongUsClient_OnGameEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,29 @@ 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>();
}

_sessionRoleHistory[playerId].Add(roleType);
}
}

public static void Prefix()
{
if (CustomGameOptions.WeightedRoleSelection)
{
RecordSessionRoles(); // Record roles at the end of each game
}
Comment on lines +13 to +37

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably happen at the start of the game and not the end as the final roles people end up with are not the same as those they initially were assigned and we only care about those original roles.

Additionally, I'm not sure how PlayerIds are handled in Among Us so doing it at game start may handle situations like disconnects better?

@AmongUsafk AmongUsafk May 17, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, no this affect end game because you can see there is a harmony patch to patch the end game
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.Start))]

and about player id is a bit complicated

i don't think so that will make disconnects better

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that currently it's targeting the end of the game, I'm suggesting that instead targeting the start of the game would make more sense due to the switching of roles and potentially disconnects (though the latter point you're saying doesn't matter). Conceptually it still makes more sense to me to save this stuff pretty much the moments it is generated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by "genereted" ?there

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the original roles are randomly rolled and assigned.

List<int> losers = new List<int>();
foreach (var role in Role.GetRoles(RoleEnum.Amnesiac))
{
Expand Down
5 changes: 4 additions & 1 deletion source/Patches/CustomGameOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ 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();

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 +386,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);
}
}
}