mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
Summary Text
This commit is contained in:
1 parent
62de1325b3
commit
4c581c7abb
4 files changed
+134
-12
No files matched your search
@@ -18,32 +18,46 @@ public class ExtendedPlayerInfo
|
||||
public uint LastTaskId { get; set; } = 0;
|
||||
public int TimesCalledMeeting { get; set; } = 0;
|
||||
public RoleTypes DeadDisplayRole { get; set; }
|
||||
public ExtendedRoleInfo? RoleInfo { get; set; }
|
||||
}
|
||||
|
||||
public class ExtendedRoleInfo
|
||||
{
|
||||
public int Kills { get; set; } = 0;
|
||||
}
|
||||
|
||||
public static class PlayerControlExtensions
|
||||
{
|
||||
private static readonly Dictionary<NetworkedPlayerInfo, ExtendedPlayerInfo> playerInfo = [];
|
||||
private static readonly Dictionary<string, ExtendedPlayerInfo> playerInfo = [];
|
||||
|
||||
// Get BetterData from PlayerControl
|
||||
public static ExtendedPlayerInfo BetterData(this PlayerControl player)
|
||||
public static ExtendedPlayerInfo? BetterData(this PlayerControl player)
|
||||
{
|
||||
if (!playerInfo.ContainsKey(player.Data))
|
||||
if (player == null) return null;
|
||||
|
||||
if (!playerInfo.ContainsKey(player.Data.Puid))
|
||||
{
|
||||
playerInfo[player.Data] = new ExtendedPlayerInfo();
|
||||
playerInfo[player.Data.Puid] = new ExtendedPlayerInfo
|
||||
{
|
||||
RoleInfo = new ExtendedRoleInfo()
|
||||
};
|
||||
}
|
||||
|
||||
return playerInfo[player.Data];
|
||||
return playerInfo[player.Data.Puid];
|
||||
}
|
||||
|
||||
// Get BetterData from NetworkedPlayerInfo
|
||||
public static ExtendedPlayerInfo BetterData(this NetworkedPlayerInfo info)
|
||||
public static ExtendedPlayerInfo? BetterData(this NetworkedPlayerInfo info)
|
||||
{
|
||||
if (!playerInfo.ContainsKey(info))
|
||||
if (!playerInfo.ContainsKey(info.Puid))
|
||||
{
|
||||
playerInfo[info] = new ExtendedPlayerInfo();
|
||||
playerInfo[info.Puid] = new ExtendedPlayerInfo
|
||||
{
|
||||
RoleInfo = new ExtendedRoleInfo()
|
||||
};
|
||||
}
|
||||
|
||||
return playerInfo[info];
|
||||
return playerInfo[info.Puid];
|
||||
}
|
||||
|
||||
// Get BetterData from ClientData
|
||||
@@ -53,12 +67,15 @@ public static class PlayerControlExtensions
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
if (!playerInfo.ContainsKey(player.Data))
|
||||
if (!playerInfo.ContainsKey(player.Data.Puid))
|
||||
{
|
||||
playerInfo[player.Data] = new ExtendedPlayerInfo();
|
||||
playerInfo[player.Data.Puid] = new ExtendedPlayerInfo
|
||||
{
|
||||
RoleInfo = new ExtendedRoleInfo()
|
||||
};
|
||||
}
|
||||
|
||||
return playerInfo[player.Data];
|
||||
return playerInfo[player.Data.Puid];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -106,6 +106,18 @@ public static class Utils
|
||||
}
|
||||
// Get name for role
|
||||
public static string GetRoleName(RoleTypes role) => Main.GetRoleName[(int)role];
|
||||
// Get hex color for team
|
||||
public static string GetTeamHexColor(RoleTeamTypes team)
|
||||
{
|
||||
if (team == RoleTeamTypes.Impostor)
|
||||
{
|
||||
return "#f00202";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "#8cffff";
|
||||
}
|
||||
}
|
||||
public static string Color32ToHex(Color32 color) => $"#{color.r:X2}{color.g:X2}{color.b:X2}{255:X2}";
|
||||
// Disconnect client
|
||||
public static void DisconnectSelf(string reason, bool showReason = true)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using HarmonyLib;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BetterAmongUs.Patches;
|
||||
|
||||
@@ -94,4 +98,90 @@ class GamePlayManager
|
||||
return true;
|
||||
}
|
||||
}
|
||||
[HarmonyPatch(typeof(EndGameManager))]
|
||||
public class EndGameManagerPatch
|
||||
{
|
||||
[HarmonyPatch(nameof(EndGameManager.SetEverythingUp))]
|
||||
[HarmonyPostfix]
|
||||
private static void SetEverythingUp_Postfix(EndGameManager __instance)
|
||||
{
|
||||
GameObject SummaryObj = UnityEngine.Object.Instantiate(__instance.WinText.gameObject, __instance.WinText.transform.parent.transform);
|
||||
SummaryObj.name = "SummaryObj (TMP)";
|
||||
SummaryObj.transform.SetSiblingIndex(0);
|
||||
Camera localCamera;
|
||||
if (DestroyableSingleton<HudManager>.InstanceExists)
|
||||
{
|
||||
localCamera = DestroyableSingleton<HudManager>.Instance.GetComponentInChildren<Camera>();
|
||||
}
|
||||
else
|
||||
{
|
||||
localCamera = Camera.main;
|
||||
}
|
||||
|
||||
SummaryObj.transform.position = AspectPosition.ComputeWorldPosition(localCamera, AspectPosition.EdgeAlignments.LeftTop, new Vector3(1f, 0.2f, -5f));
|
||||
SummaryObj.transform.localScale = new Vector3(0.22f, 0.22f, 0.22f);
|
||||
TextMeshPro SummaryText = SummaryObj.GetComponent<TextMeshPro>();
|
||||
if (SummaryText != null)
|
||||
{
|
||||
SummaryText.autoSizeTextContainer = false;
|
||||
SummaryText.enableAutoSizing = false;
|
||||
SummaryText.lineSpacing = -25f;
|
||||
SummaryText.alignment = TextAlignmentOptions.TopLeft;
|
||||
SummaryText.color = Color.white;
|
||||
|
||||
NetworkedPlayerInfo[] playersData = GameData.Instance.AllPlayers.ToArray();
|
||||
|
||||
string SummaryHeader = "<align=\"center\">Game Summary</align>";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (var data in playersData)
|
||||
{
|
||||
var name = $"<color={Utils.Color32ToHex(Palette.PlayerColors[data.DefaultOutfit.ColorId])}>{data.PlayerName}</color>";
|
||||
string playerTheme(string text) => $"<color={Utils.GetTeamHexColor(data.Role.TeamType)}>{text}</color>";
|
||||
|
||||
string roleInfo;
|
||||
if (data.Role.IsImpostor)
|
||||
{
|
||||
roleInfo = $"({playerTheme(Utils.GetRoleName(data.RoleType))}) → {playerTheme($"Kills: {data.BetterData().RoleInfo.Kills}")}";
|
||||
}
|
||||
else
|
||||
{
|
||||
roleInfo = $"({playerTheme(Utils.GetRoleName(data.RoleType))}) → {playerTheme($"Tasks: {data.Tasks.ToArray().Where(task => task.Complete).Count()}/{data.Tasks.Count}")}";
|
||||
}
|
||||
|
||||
string deathReason;
|
||||
if (data.Disconnected)
|
||||
{
|
||||
deathReason = "『<color=#838383><b>D/C</b></color>』";
|
||||
}
|
||||
else if (!data.IsDead)
|
||||
{
|
||||
deathReason = "『<color=#80ff00><b>Alive</b></color>』";
|
||||
;
|
||||
}
|
||||
else if (data.IsDead)
|
||||
{
|
||||
deathReason = "『<color=#ff0600><b>Dead</b></color>』";
|
||||
}
|
||||
else
|
||||
{
|
||||
deathReason = "『<color=#838383<b>Unknown</b></color>』";
|
||||
}
|
||||
|
||||
sb.AppendLine($"- {deathReason} {name} {roleInfo}\n");
|
||||
}
|
||||
|
||||
SummaryText.text = $"{SummaryHeader}\n\n<size=58%>{sb}</size>";
|
||||
}
|
||||
}
|
||||
[HarmonyPatch(nameof(EndGameManager.ShowButtons))]
|
||||
[HarmonyPrefix]
|
||||
private static bool ShowButtons_Prefix(EndGameManager __instance)
|
||||
{
|
||||
__instance.FrontMost.gameObject.SetActive(false);
|
||||
__instance.Navigation.ShowDefaultNavigation();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ class PlayerControlPatch
|
||||
__instance.BetterData().HasNoisemakerNotify = false;
|
||||
__instance.BetterData().TimeSinceLastTask = 5f;
|
||||
__instance.BetterData().LastTaskId = 999;
|
||||
__instance.BetterData().RoleInfo.Kills = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -253,6 +254,8 @@ class PlayerControlPatch
|
||||
HudManager.Instance?.NotifyOfDeath();
|
||||
|
||||
Logger.LogPrivate($"{__instance.Data.PlayerName} Has killed {target.Data.PlayerName} as {Utils.GetRoleName(__instance.Data.RoleType)}", "EventLog");
|
||||
|
||||
__instance.BetterData().RoleInfo.Kills += 1;
|
||||
}
|
||||
[HarmonyPatch(nameof(PlayerControl.Shapeshift))]
|
||||
[HarmonyPostfix]
|
||||
|
||||
Reference in new issue
Block a user