Skip to content

Commit

Permalink
Update v1.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dabao40 committed Oct 5, 2024
1 parent e8e5383 commit e681a4f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
9 changes: 5 additions & 4 deletions TheOtherRoles/CustomGameModes/FreePlayGM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ void SetWidget(int tab)

if (tab == 0)
{
inner = gui.Arrange(GUIAlignment.Center, RoleInfo.allRoleInfos.Where(x => x != RoleInfo.bomberB && x != RoleInfo.bomberA && x != RoleInfo.jackal
&& x != RoleInfo.sidekick && x != RoleInfo.mimicA && x != RoleInfo.mimicK && x != RoleInfo.arsonist && x != RoleInfo.bountyHunter && !x.isModifier).Select(r => gui.RawButton(GUIAlignment.Center, roleMaskedTittleAttr, Helpers.cs(r.color, r.name), () =>
inner = gui.Arrange(GUIAlignment.Center, RoleInfo.allRoleInfos.Where(x => x != RoleInfo.bomberB && x != RoleInfo.bomberA && x != RoleInfo.mimicA && x != RoleInfo.mimicK && x != RoleInfo.arsonist && x != RoleInfo.bountyHunter && !x.isModifier).Select(r => gui.RawButton(GUIAlignment.Center, roleMaskedTittleAttr, Helpers.cs(r.color, r.name), () =>
{
bool isImpostorFormer = PlayerControl.LocalPlayer.Data.Role.IsImpostor;
var formerRole = RoleInfo.getRoleInfoForPlayer(PlayerControl.LocalPlayer, false).FirstOrDefault();
if (formerRole == r) return; // Do nothing if the same role was given
if (formerRole.roleId == RoleId.Jackal) Jackal.clearAndReload();
else if (formerRole.roleId == RoleId.Sidekick) Sidekick.clearAndReload();
RPCProcedure.erasePlayerRoles(PlayerControl.LocalPlayer.PlayerId);
if (r.isImpostor() && !isImpostorFormer) PlayerControl.LocalPlayer.FastSetRole(RoleTypes.Impostor);
else if (!r.isImpostor() && isImpostorFormer) PlayerControl.LocalPlayer.FastSetRole(RoleTypes.Crewmate);
Expand All @@ -81,7 +82,7 @@ void SetWidget(int tab)
cpt.addTaskToPlayer(CachedPlayer.LocalPlayer.PlayerId);
} else if (r.roleId == RoleId.JekyllAndHyde) {
CachedPlayer.LocalPlayer.PlayerControl.generateAndAssignTasks(JekyllAndHyde.numCommonTasks, JekyllAndHyde.numShortTasks, JekyllAndHyde.numLongTasks);
} else if (formerRole.roleId == RoleId.Fox || formerRole.roleId == RoleId.JekyllAndHyde || formerRole.roleId == RoleId.TaskMaster) {
} else if (formerRole.roleId is RoleId.Fox or RoleId.JekyllAndHyde or RoleId.TaskMaster) {
var options = GameOptionsManager.Instance.currentNormalGameOptions;
PlayerControl.LocalPlayer.generateAndAssignTasks(options.NumCommonTasks, options.NumShortTasks, options.NumLongTasks);
}
Expand Down Expand Up @@ -119,7 +120,7 @@ private static void FastSetRole(this PlayerControl targetPlayer, RoleTypes roleT
roleBehaviour.Initialize(targetPlayer);
targetPlayer.Data.Role = roleBehaviour;
targetPlayer.Data.RoleType = roleType;
if (roleType != RoleTypes.ImpostorGhost && roleType != RoleTypes.CrewmateGhost)
if (roleType is not RoleTypes.ImpostorGhost and not RoleTypes.CrewmateGhost)
targetPlayer.Data.RoleWhenAlive = new Il2CppSystem.Nullable<RoleTypes>(roleType);
roleBehaviour.AdjustTasks(targetPlayer);
}
Expand Down
2 changes: 1 addition & 1 deletion TheOtherRoles/Modules/CustomOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static void showInfoOverlay()
}

var rows = rolesText.Count(c => c == '\n');
var maxY = Mathf.Max(1.15f, (2 * rows - 33) * 0.06f);
var maxY = Mathf.Max(1.15f, (2 * rows - 24) * 0.04f + 1.16f);
scroller.enabled = true;
scroller.ContentYBounds = new FloatRange(1.15f, maxY);
scroller.ScrollToTop();
Expand Down
4 changes: 3 additions & 1 deletion TheOtherRoles/Patches/MeetingPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,16 @@ static void guesserOnClick(int buttonTarget, MeetingHud __instance) {
else
__instance.playerStates.ToList().ForEach(x => { if (x.transform.FindChild("ShootButton") != null) UnityEngine.Object.Destroy(x.transform.FindChild("ShootButton").gameObject); });

bool isSpecialRole = roleInfo == RoleInfo.niceshifter || roleInfo == RoleInfo.niceSwapper;
// Shoot player and send chat info if activated
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId, (byte)CustomRPC.GuesserShoot, Hazel.SendOption.Reliable, -1);
writer.Write(CachedPlayer.LocalPlayer.PlayerId);
writer.Write(dyingTarget.PlayerId);
writer.Write(focusedTarget.PlayerId);
writer.Write((byte)roleInfo.roleId);
writer.Write(isSpecialRole);
AmongUsClient.Instance.FinishRpcImmediately(writer);
RPCProcedure.guesserShoot(CachedPlayer.LocalPlayer.PlayerId, dyingTarget.PlayerId, focusedTarget.PlayerId, (byte)roleInfo.roleId);
RPCProcedure.guesserShoot(CachedPlayer.LocalPlayer.PlayerId, dyingTarget.PlayerId, focusedTarget.PlayerId, (byte)roleInfo.roleId, isSpecialRole);
}
}));

Expand Down
20 changes: 17 additions & 3 deletions TheOtherRoles/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ public static void jackalCreatesSidekick(byte targetId) {
}

public static void sidekickPromotes() {
if (FreePlayGM.isFreePlayGM) return;
Jackal.removeCurrentJackal();
Jackal.jackal = Sidekick.sidekick;
Jackal.canCreateSidekick = Jackal.jackalPromotedFromSidekickCanCreateSidekick;
Expand Down Expand Up @@ -2467,7 +2468,15 @@ public static void lawyerWin()
Lawyer.triggerLawyerWin = true;
}

public static void guesserShoot(byte killerId, byte dyingTargetId, byte guessedTargetId, byte guessedRoleId) {
/// <summary>
/// Shoots the dying target during the meeting
/// </summary>
/// <param name="killerId">PlayerId of the Guesser</param>
/// <param name="dyingTargetId">PlayerId of the dying target (i.e. wrong guess = Guesser, right guess = target)</param>
/// <param name="guessedTargetId">The PlayerId the dying target has guessed</param>
/// <param name="guessedRoleId">The RoleId the Guesser has guessed (2 same RoleIds for Swapper and Shifter)</param>
/// <param name="isSpecialRole">Whether or not this is a Nice Shifter or a Nice Swapper etc.</param>
public static void guesserShoot(byte killerId, byte dyingTargetId, byte guessedTargetId, byte guessedRoleId, bool isSpecialRole) {
GameStatistics.Event.GameStatistics.RecordEvent(new(GameStatistics.EventVariation.Kill, killerId, 1 << dyingTargetId) { RelatedTag = killerId == dyingTargetId ? EventDetail.MisGuess : EventDetail.Guessed});

PlayerControl killer = Helpers.playerById(killerId);
Expand Down Expand Up @@ -2644,7 +2653,11 @@ public static void guesserShoot(byte killerId, byte dyingTargetId, byte guessedT
{
PlayerControl guessedTarget = Helpers.playerById(guessedTargetId);
PlayerControl sender = CachedPlayer.LocalPlayer.PlayerControl;
RoleInfo guessedRoleInfo = RoleInfo.allRoleInfos.FirstOrDefault(x => (byte)x.roleId == guessedRoleId);
RoleInfo guessedRoleInfo = RoleInfo.allRoleInfos.FirstOrDefault(x => (byte)x.roleId == guessedRoleId);
if (isSpecialRole) {
if ((RoleId)guessedRoleId == RoleId.Swapper) guessedRoleInfo = RoleInfo.niceSwapper;
else if ((RoleId)guessedRoleId == RoleId.Shifter) guessedRoleInfo = RoleInfo.niceshifter;
}
string msg = "";
if (CachedPlayer.LocalPlayer.Data.IsDead && guessedTarget != null && guesser != null)
{
Expand Down Expand Up @@ -3385,7 +3398,8 @@ static void Postfix([HarmonyArgument(0)]byte callId, [HarmonyArgument(1)]Message
byte dyingTarget = reader.ReadByte();
byte guessedTarget = reader.ReadByte();
byte guessedRoleId = reader.ReadByte();
RPCProcedure.guesserShoot(killerId, dyingTarget, guessedTarget, guessedRoleId);
bool isSpecialRole = reader.ReadBoolean();
RPCProcedure.guesserShoot(killerId, dyingTarget, guessedTarget, guessedRoleId, isSpecialRole);
break;
case (byte)CustomRPC.LawyerSetTarget:
RPCProcedure.lawyerSetTarget(reader.ReadByte());
Expand Down

0 comments on commit e681a4f

Please sign in to comment.