mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
fix sns draft & improve id to pc lookup
This commit is contained in:
1 parent
128c3e0c83
commit
7c5e793c07
9 files changed
+34
-41
No files matched your search
@@ -78,13 +78,14 @@ internal static class CustomHnS
|
||||
LastUpdate = Utils.TimeStamp;
|
||||
|
||||
Type[] types = GetAllHnsRoleTypes();
|
||||
|
||||
AllHnSRoles = GetAllHnsRoles(types);
|
||||
bool sns = ShiftAndSeek.GetBool();
|
||||
|
||||
HideAndSeekRoles = types
|
||||
.Select(x => (IHideAndSeekRole)Activator.CreateInstance(x))
|
||||
.Where(x => x != null)
|
||||
.Join(AllHnSRoles.FindAll(role => !ShiftAndSeek.GetBool() ? (role is CustomRoles.Seeker or CustomRoles.Hider || role.GetMode() != 0) : (role == CustomRoles.Disguiser || (role is not (CustomRoles.Seeker or CustomRoles.Locator or CustomRoles.Dasher or CustomRoles.Venter or CustomRoles.Agent) && role.GetMode() != 0))), x => x.GetType().Name.ToLower(), x => x.ToString().ToLower(), (Interface, Enum) => (Enum, Interface))
|
||||
.Join(AllHnSRoles, x => x.GetType().Name.ToLower(), x => x.ToString().ToLower(), (Interface, Enum) => (Enum, Interface))
|
||||
.Where(x => !sns ? (x.Enum is CustomRoles.Seeker or CustomRoles.Hider || x.Enum.GetMode() != 0) : (x.Enum == CustomRoles.Disguiser || (x.Interface.Team != Team.Impostor && x.Enum.GetMode() != 0)))
|
||||
.Where(x => (!x.Enum.OnlySpawnsWithPets() || Options.UsePets.GetBool()) && (x.Enum != CustomRoles.Agent || SeekerNum >= 2) && x.Interface.Count > 0 && (x.Interface.Team == Team.Neutral || x.Interface.Chance > IRandom.Instance.Next(100)))
|
||||
.OrderBy(x => x.Enum is CustomRoles.Seeker or CustomRoles.Hider ? 100 : IRandom.Instance.Next(100))
|
||||
.GroupBy(x => x.Interface.Team)
|
||||
|
||||
@@ -92,7 +92,7 @@ public class PlayerState(byte playerId)
|
||||
etc = -1
|
||||
}
|
||||
|
||||
public readonly PlayerControl Player = Utils.GetPlayerById(playerId, false);
|
||||
public readonly PlayerControl Player = Utils.GetPlayerById(playerId);
|
||||
|
||||
private readonly byte PlayerId = playerId;
|
||||
public readonly List<CustomRoles> SubRoles = [];
|
||||
|
||||
+11
-24
@@ -1825,7 +1825,7 @@ public static class Utils
|
||||
{
|
||||
Logger.Info($"SendMessage called from {callerFilePath.Split('\\')[^1].Split('/')[^1]} at line {callerLineNumber}", "SendMessage");
|
||||
|
||||
PlayerControl receiver = GetPlayerById(sendTo, GameStates.InGame);
|
||||
PlayerControl receiver = GetPlayerById(sendTo);
|
||||
if (sendTo != byte.MaxValue && !receiver || !force && title.RemoveHtmlTags().Trim().Length == 0 && text.RemoveHtmlTags().Trim().Length == 0) return writer;
|
||||
|
||||
if (!AmongUsClient.Instance.AmHost)
|
||||
@@ -2680,31 +2680,18 @@ public static class Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerControl GetPlayerById(int playerId, bool fast = true)
|
||||
private static readonly PlayerControl[] IdToPC = new PlayerControl[256];
|
||||
|
||||
public static PlayerControl GetPlayerById(byte playerId) => IdToPC[playerId];
|
||||
|
||||
public static void UpdatePlayerIdCache()
|
||||
{
|
||||
try
|
||||
Array.Clear(IdToPC);
|
||||
|
||||
foreach (var pc in PlayerControl.AllPlayerControls)
|
||||
{
|
||||
if (playerId == PlayerControl.LocalPlayer.PlayerId)
|
||||
return PlayerControl.LocalPlayer;
|
||||
|
||||
byte id = (byte)playerId;
|
||||
|
||||
if (fast && GameStates.InGame &&
|
||||
Main.PlayerStates.TryGetValue(id, out PlayerState state) &&
|
||||
state.Player) { return state.Player; }
|
||||
|
||||
foreach (var pc in PlayerControl.AllPlayerControls)
|
||||
{
|
||||
if (pc.PlayerId == id)
|
||||
return pc;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ThrowException(e);
|
||||
return null;
|
||||
if (pc)
|
||||
IdToPC[pc.PlayerId] = pc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1547,7 +1547,8 @@ internal static class ChatCommands
|
||||
|
||||
if (gameMode == CustomGameMode.HideAndSeek)
|
||||
{
|
||||
List<(CustomRoles Role, IHideAndSeekRole Interface)> hnsRoles = CustomHnS.GetAllHnsRoleTypes().Select(x => (Role: Enum.Parse<CustomRoles>(ignoreCase: true, value: x.Name), Interface: (IHideAndSeekRole)Activator.CreateInstance(x))).Where(x => x.Role is CustomRoles.Seeker or CustomRoles.Hider || x.Role.GetMode() != 0).ToList();
|
||||
bool sns = CustomHnS.SNS;
|
||||
List<(CustomRoles Role, IHideAndSeekRole Interface)> hnsRoles = CustomHnS.GetAllHnsRoleTypes().Select(x => (Role: Enum.Parse<CustomRoles>(ignoreCase: true, value: x.Name), Interface: (IHideAndSeekRole)Activator.CreateInstance(x))).Where(x => !sns ? (x.Role is CustomRoles.Seeker or CustomRoles.Hider || x.Role.GetMode() != 0) : (x.Role == CustomRoles.Disguiser || (x.Interface.Team != Team.Impostor && x.Role.GetMode() != 0))).ToList();
|
||||
Dictionary<Team, int> memberNum = new()
|
||||
{
|
||||
[Team.Impostor] = Main.NormalOptions.NumImpostors,
|
||||
@@ -2184,11 +2185,11 @@ internal static class ChatCommands
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length < 2 || !int.TryParse(args[1], out int id2)) return;
|
||||
if (args.Length < 2 || !byte.TryParse(args[1], out byte id2)) return;
|
||||
|
||||
PlayerControl target = Utils.GetPlayerById(id2);
|
||||
|
||||
if (target != null)
|
||||
if (target)
|
||||
{
|
||||
target.Kill(target);
|
||||
|
||||
@@ -2207,11 +2208,11 @@ internal static class ChatCommands
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length < 2 || !int.TryParse(args[1], out int id)) return;
|
||||
if (args.Length < 2 || !byte.TryParse(args[1], out byte id)) return;
|
||||
|
||||
PlayerControl pc = Utils.GetPlayerById(id);
|
||||
|
||||
if (pc != null)
|
||||
if (pc)
|
||||
{
|
||||
Main.PlayerStates[pc.PlayerId].deathReason = PlayerState.DeathReason.etc;
|
||||
pc.RpcExileV2();
|
||||
|
||||
@@ -168,7 +168,7 @@ internal static class ChangeRoleSettings
|
||||
ChatCommands.LastSpectators.UnionWith(ChatCommands.Spectators);
|
||||
|
||||
RPCHandlerPatch.RemoveExpiredWhiteList();
|
||||
|
||||
Utils.UpdatePlayerIdCache();
|
||||
LobbyViewSettingsPanePatch.ClearReferences();
|
||||
|
||||
try
|
||||
@@ -565,6 +565,7 @@ internal static class StartGameHostPatch
|
||||
if (AmongUsClient.Instance.IsGameOver || GameStates.IsLobby || GameEndChecker.Ended) yield break;
|
||||
|
||||
Main.ForceRebuildCachesPlayerControls();
|
||||
Utils.UpdatePlayerIdCache();
|
||||
|
||||
Options.AutoSetFactionMinMaxSettings();
|
||||
|
||||
|
||||
@@ -691,6 +691,7 @@ internal static class InnerNetClientSpawnPatch
|
||||
|
||||
Logger.Msg($"Spawn player data: ID {client?.Character?.PlayerId}: {client?.PlayerName}", "CreatePlayer");
|
||||
Main.ForceRebuildCachesPlayerControls();
|
||||
Utils.UpdatePlayerIdCache();
|
||||
|
||||
if (client == null || !client.Character // client is null
|
||||
|| client.ColorId < 0 || Palette.PlayerColors.Length <= client.ColorId) // invalid client color
|
||||
|
||||
@@ -165,8 +165,8 @@ internal class Sentry : RoleBase
|
||||
|
||||
PlayerControl realTarget = null;
|
||||
|
||||
if (target.shapeshiftTargetPlayerId != byte.MaxValue)
|
||||
realTarget = Utils.GetPlayerById(target.shapeshiftTargetPlayerId);
|
||||
if (target.shapeshiftTargetPlayerId is <= byte.MaxValue and >= byte.MinValue)
|
||||
realTarget = Utils.GetPlayerById((byte)target.shapeshiftTargetPlayerId);
|
||||
|
||||
if (!realTarget) realTarget = target;
|
||||
|
||||
@@ -211,7 +211,7 @@ internal class Sentry : RoleBase
|
||||
|
||||
bool shapeshifting = shapeshifter.PlayerId != target.PlayerId;
|
||||
PlayerControl ssTarget = shapeshifting ? target : shapeshifter;
|
||||
PlayerControl ss = shapeshifting ? shapeshifter : Utils.GetPlayerById(shapeshifter.shapeshiftTargetPlayerId);
|
||||
PlayerControl ss = shapeshifting ? shapeshifter : Utils.GetPlayerById((byte)shapeshifter.shapeshiftTargetPlayerId);
|
||||
|
||||
string text = "\n" + string.Format(
|
||||
Translator.GetString("Sentry.Notify.Shapeshifted"),
|
||||
|
||||
@@ -99,8 +99,9 @@ public class Echo : RoleBase
|
||||
}
|
||||
else
|
||||
{
|
||||
target = Utils.GetPlayerById(shapeshifter.shapeshiftTargetPlayerId);
|
||||
if (target == null) return true;
|
||||
if (shapeshifter.shapeshiftTargetPlayerId is > byte.MaxValue or < byte.MinValue) return true;
|
||||
target = Utils.GetPlayerById((byte)shapeshifter.shapeshiftTargetPlayerId);
|
||||
if (!target) return true;
|
||||
|
||||
RevertSwap(shapeshifter, target);
|
||||
LateTask.New(() => target.Suicide(PlayerState.DeathReason.Echoed, shapeshifter), 0.2f, "Echo Unshift Kill");
|
||||
@@ -123,8 +124,9 @@ public class Echo : RoleBase
|
||||
SkipCheck = true;
|
||||
LateTask.New(() => SkipCheck = false, 3f, log: false);
|
||||
|
||||
PlayerControl ssTarget = Utils.GetPlayerById(target.shapeshiftTargetPlayerId);
|
||||
if (ssTarget == null || !killer.RpcCheckAndMurder(ssTarget, true)) return true;
|
||||
if (target.shapeshiftTargetPlayerId is > byte.MaxValue or < byte.MinValue) return true;
|
||||
PlayerControl ssTarget = Utils.GetPlayerById((byte)target.shapeshiftTargetPlayerId);
|
||||
if (!ssTarget || !killer.RpcCheckAndMurder(ssTarget, true)) return true;
|
||||
|
||||
RevertSwap(target, ssTarget);
|
||||
LateTask.New(() => killer.Kill(ssTarget), 0.2f, log: false);
|
||||
|
||||
@@ -111,7 +111,7 @@ internal class Nemesis : RoleBase
|
||||
|
||||
try
|
||||
{
|
||||
int targetId = int.Parse(msg.Replace("/rv", string.Empty));
|
||||
byte targetId = byte.Parse(msg.Replace("/rv", string.Empty));
|
||||
target = Utils.GetPlayerById(targetId);
|
||||
}
|
||||
catch
|
||||
|
||||
Reference in new issue
Block a user