some fixes

This commit is contained in:
Gurge44 committed 2026-03-21 11:28:21 +01:00
1 parent 8147d3c172
commit 63a15b4663
8 files changed
+50 -32

No files matched your search

+6 -6
View File
@@ -173,7 +173,7 @@ public class PlayerState(byte playerId)
if (role is CustomRoles.Sidekick or CustomRoles.Necromancer or CustomRoles.Deathknight or CustomRoles.Renegade)
SubRoles.ToArray().DoIf(StartGameHostPatch.BasisChangingAddons.ContainsKey, RemoveSubRole);
if (role == CustomRoles.Sidekick && Jackal.Instances.FindFirst(x => x.SidekickId == byte.MaxValue || x.SidekickId.GetPlayer() == null, out Jackal jackal))
if (role == CustomRoles.Sidekick && Jackal.Instances.FindFirst(x => x.SidekickId == byte.MaxValue || !x.SidekickId.GetPlayer(), out Jackal jackal))
jackal.SidekickId = PlayerId;
if (Options.CurrentGameMode == CustomGameMode.Standard && GameStates.IsInTask && !AntiBlackout.SkipTasks)
@@ -389,7 +389,7 @@ public class TaskState
public void Init(PlayerControl player)
{
Logger.Info($"{player.GetNameWithRole().RemoveHtmlTags()}: InitTask", "TaskState.Init");
if (player == null || player.Data?.Tasks == null) return;
if (!player || player.Data?.Tasks == null) return;
if (!Utils.HasTasks(player.Data, false))
{
@@ -563,9 +563,9 @@ public static class GameStates
}
/**********TOP ZOOM.cs***********/
public static bool IsShip => ShipStatus.Instance != null;
public static bool IsCanMove => PlayerControl.LocalPlayer != null && PlayerControl.LocalPlayer.CanMove;
public static bool IsDead => PlayerControl.LocalPlayer != null && !PlayerControl.LocalPlayer.IsAlive();
public static bool IsShip => ShipStatus.Instance;
public static bool IsCanMove => PlayerControl.LocalPlayer && PlayerControl.LocalPlayer.CanMove;
public static bool IsDead => PlayerControl.LocalPlayer && !PlayerControl.LocalPlayer.IsAlive();
}
public static class MeetingStates
@@ -575,7 +575,7 @@ public static class MeetingStates
public static int MeetingNum;
public static bool MeetingCalled;
public static bool FirstMeeting = true;
public static bool IsEmergencyMeeting => ReportTarget == null;
public static bool IsEmergencyMeeting => !ReportTarget;
public static bool IsExistDeadBody => DeadBodies.Length > 0;
public static NetworkedPlayerInfo ReportTarget { get; set; }
+2 -2
View File
@@ -1563,13 +1563,13 @@ internal static class ChatCommands
if (!meeting) yield return new WaitForSecondsRealtime(7f);
PlayerControl killer = player.GetRealKiller();
if (killer == null && id != 3) yield break;
if (!killer && id != 3) yield break;
Team team = player.GetTeam();
string message = id switch
{
1 => string.Format(GetString("MessengerMessage.1"), GetString(Main.PlayerStates[killer.PlayerId].LastRoom.RoomId.ToString())),
1 => string.Format(GetString("MessengerMessage.1"), GetString((Main.PlayerStates[killer.PlayerId].LastRoom?.RoomId ?? SystemTypes.Outside).ToString())),
2 => string.Format(GetString("MessengerMessage.2"), killer.GetCustomRole().ToColoredString()),
_ => string.Format(GetString("MessengerMessage.3"), Utils.ColorString(team.GetColor(), GetString($"{team}")))
};
+24
View File
@@ -691,6 +691,30 @@ internal static class SetHudActivePatch
}
}
[HarmonyPatch(typeof(AbilityButton), nameof(AbilityButton.SetFromSettings))]
static class AbilityButtonSetFromSettingsPatch
{
public static Exception Finalizer(Exception __exception)
{
if (__exception != null)
Utils.ThrowException(__exception);
return null;
}
}
[HarmonyPatch(typeof(ActionButton), nameof(ActionButton.SetEnabled))]
static class ActionButtonSetEnabledPatch
{
public static Exception Finalizer(Exception __exception)
{
if (__exception != null)
Utils.ThrowException(__exception);
return null;
}
}
// From https://github.com/AU-Avengers/TOU-Mira/blob/main/TownOfUs/Patches/HudManagerPatches.cs
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Start))]
[HarmonyPriority(Priority.Last)]
+2 -7
View File
@@ -283,13 +283,8 @@ internal static class CheckTaskCompletionPatch
{
public static bool Prefix(ref bool __result)
{
if (Options.DisableTaskWin.GetBool() || Options.NoGameEnd.GetBool() || TaskState.InitialTotalTasks == 0 || (Options.DisableTaskWinIfAllCrewsAreDead.GetBool() && !Main.EnumerateAlivePlayerControls().Any(x => x.Is(CustomRoleTypes.Crewmate))) || (Options.DisableTaskWinIfAllCrewsAreConverted.GetBool() && Main.EnumerateAlivePlayerControls().Where(x => x.Is(Team.Crewmate) && x.GetRoleTypes() is RoleTypes.Crewmate or RoleTypes.Engineer or RoleTypes.Scientist or RoleTypes.CrewmateGhost or RoleTypes.GuardianAngel).All(x => x.IsConverted())) || Options.CurrentGameMode != CustomGameMode.Standard)
{
__result = false;
return false;
}
return true;
__result = false;
return false;
}
}
+1 -1
View File
@@ -140,7 +140,7 @@ public class Witch : RoleBase
{
if (NowSwitchTrigger == SwitchTrigger.Vanish)
{
var killRange = GameManager.Instance.LogicOptions.GetKillDistance();
var killRange = GameManager.Instance.LogicOptions.GetKillDistance() + 1f;
if (!FastVector2.TryGetClosestPlayerInRangeTo(pc, killRange, out PlayerControl target, x => !x.IsImpostor())) return false;
SetSpelled(pc, target);
}
+1 -1
View File
@@ -125,7 +125,7 @@ public class Silencer : RoleBase
{
if (SilenceMode.GetValue() == 2)
{
var killRange = GameManager.Instance.LogicOptions.GetKillDistance();
var killRange = GameManager.Instance.LogicOptions.GetKillDistance() + 1f;
if (!FastVector2.TryGetClosestPlayerInRangeTo(pc, killRange, out PlayerControl target)) return false;
ForSilencer = [target.PlayerId];
+10 -12
View File
@@ -135,10 +135,9 @@ public class Agitator : RoleBase
{
PlayerControl pc = Utils.GetPlayerById(CurrentBombedPlayer);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (pc != null && pc.IsAlive() && killer != null) // Can be null since it's a late task
if (pc && pc.IsAlive() && killer)
{
pc.Suicide(PlayerState.DeathReason.Bombed, Utils.GetPlayerById(PlayerIdList[0]));
pc.Suicide(PlayerState.DeathReason.Bombed, killer);
Logger.Info($"{killer.GetNameWithRole().RemoveHtmlTags()} bombed {pc.GetNameWithRole().RemoveHtmlTags()}, bomb cd complete", "Agitator");
ResetBomb();
@@ -159,12 +158,13 @@ public class Agitator : RoleBase
PlayerControl target = Utils.GetPlayerById(CurrentBombedPlayer);
PlayerControl killer = Utils.GetPlayerById(PlayerIdList[0]);
if (target == null || killer == null || target.Is(CustomRoles.Pestilence)) return;
if (!target || !killer || target.Is(CustomRoles.Pestilence)) return;
target.RpcExileV2();
target.SetRealKiller(killer);
Main.PlayerStates[CurrentBombedPlayer].deathReason = PlayerState.DeathReason.Bombed;
Main.PlayerStates[CurrentBombedPlayer].SetDead();
PlayerState state = Main.PlayerStates[CurrentBombedPlayer];
state.deathReason = PlayerState.DeathReason.Bombed;
state.SetDead();
Utils.AfterPlayerDeathTasks(target, true);
ResetBomb();
Logger.Info($"{killer.GetRealName()} bombed {target.GetRealName()} on report", "Agitator");
@@ -183,11 +183,9 @@ public class Agitator : RoleBase
Vector2 agitatorPos = player.Pos();
Dictionary<byte, float> targetDistance = [];
foreach (PlayerControl target in PlayerControl.AllPlayerControls)
foreach (PlayerControl target in Main.EnumerateAlivePlayerControls())
{
if (!target.IsAlive()) continue;
if (target.PlayerId != playerId && target.PlayerId != LastBombedPlayer && target.IsAlive())
if (target.PlayerId != playerId && target.PlayerId != LastBombedPlayer)
{
float dis = Vector2.Distance(agitatorPos, player.Pos());
targetDistance[target.PlayerId] = dis;
@@ -198,8 +196,8 @@ public class Agitator : RoleBase
{
KeyValuePair<byte, float> min = targetDistance.OrderBy(c => c.Value).FirstOrDefault();
PlayerControl target = Utils.GetPlayerById(min.Key);
float KillRange = GameManager.Instance.LogicOptions.GetKillDistance();
if (min.Value <= KillRange && player.CanMove && target.CanMove) PassBomb(player, target);
float killRange = GameManager.Instance.LogicOptions.GetKillDistance();
if (min.Value <= killRange && player.CanMove && target.CanMove) PassBomb(player, target);
}
}
}
+4 -3
View File
@@ -23,7 +23,7 @@ internal class Bubble : RoleBase
private byte BubbleId = byte.MaxValue;
private static int Id => 643220;
private PlayerControl BubblePC => GetPlayerById(BubbleId);
private PlayerControl BubblePC;
public override bool IsEnable => BubbleId != byte.MaxValue;
@@ -67,6 +67,7 @@ internal class Bubble : RoleBase
public override void Add(byte playerId)
{
BubbleId = playerId;
BubblePC = GetPlayerById(BubbleId);
}
public override void SetKillCooldown(byte id)
@@ -182,7 +183,8 @@ internal class Bubble : RoleBase
{
if (!IsEnable) return;
foreach (PlayerControl pc in EncasedPlayers.Keys.Select(x => GetPlayerById(x)).Where(x => x != null && x.IsAlive())) pc.Suicide(PlayerState.DeathReason.Bombed, BubblePC);
foreach (PlayerControl pc in EncasedPlayers.Keys.ToValidPlayers().Where(x => x.IsAlive()))
pc.Suicide(PlayerState.DeathReason.Bombed, BubblePC);
EncasedPlayers.Clear();
SendRPC(clear: true);
@@ -191,7 +193,6 @@ internal class Bubble : RoleBase
public override string GetSuffix(PlayerControl seer, PlayerControl target, bool hud = false, bool meeting = false)
{
if (target == null || !EncasedPlayers.TryGetValue(target.PlayerId, out long ts) || (ts + NotifyDelay.GetInt() >= TimeStamp && !seer.Is(CustomRoles.Bubble))) return string.Empty;
return ColorString(GetRoleColor(CustomRoles.Bubble), $"⚠ {ExplodeDelay.GetInt() - (TimeStamp - ts) + 1}");
}
}