Skip to content

Commit

Permalink
还原GameHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyx0412 committed Nov 23, 2024
1 parent c4abf35 commit a5aa627
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 69 deletions.
Binary file modified Strings.xlsx
Binary file not shown.
35 changes: 16 additions & 19 deletions TheOtherRoles/Buttons/Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,42 +576,41 @@ public static void createButtonsPostfix(HudManager __instance)
{
byte targetId = 0;

if (Sheriff.sheriffCanKillNeutral(target))
targetId = target.PlayerId;
if (Sheriff.sheriffCanKillNeutral(target)) targetId = target.PlayerId;
else
{
switch (Sheriff.misfireKills)
{
case 0:
targetId = CachedPlayer.LocalPlayer.PlayerId;
GameHistory.RpcOverrideDeathReasonAndKiller(target, CustomDeathReason.SheriffMisfire, Sheriff.sheriff);
break;
case 1:
targetId = target.PlayerId;
GameHistory.RpcOverrideDeathReasonAndKiller(target, CustomDeathReason.SheriffMisfire, Sheriff.sheriff);
break;
case 2:
targetId = target.PlayerId;
var killWriter2 = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
(byte)CustomRPC.UncheckedMurderPlayer, SendOption.Reliable);
var killWriter2 = StartRPC(CachedPlayer.LocalPlayer.PlayerControl.NetId, CustomRPC.UncheckedMurderPlayer);
killWriter2.Write(Sheriff.sheriff.Data.PlayerId);
killWriter2.Write(CachedPlayer.LocalPlayer.PlayerId);
killWriter2.Write(byte.MaxValue);
AmongUsClient.Instance.FinishRpcImmediately(killWriter2);
killWriter2.EndRPC();
RPCProcedure.uncheckedMurderPlayer(Sheriff.sheriff.Data.PlayerId, CachedPlayer.LocalPlayer.PlayerId, byte.MaxValue);
GameHistory.RpcOverrideDeathReasonAndKiller(target, CustomDeathReason.SheriffMisadventure, Sheriff.sheriff);
GameHistory.RpcOverrideDeathReasonAndKiller(Sheriff.sheriff, CustomDeathReason.SheriffMisfire, Sheriff.sheriff);
break;
}
}

var killWriter = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId,
(byte)CustomRPC.UncheckedMurderPlayer, SendOption.Reliable
);
var killWriter = StartRPC(CachedPlayer.LocalPlayer.PlayerControl.NetId, CustomRPC.UncheckedMurderPlayer);
killWriter.Write(Sheriff.sheriff.Data.PlayerId);
killWriter.Write(targetId);
killWriter.Write(byte.MaxValue);
AmongUsClient.Instance.FinishRpcImmediately(killWriter);
killWriter.EndRPC();
RPCProcedure.uncheckedMurderPlayer(Sheriff.sheriff.Data.PlayerId, targetId, byte.MaxValue);
}


if (murderAttemptResult == MurderAttemptResult.BodyGuardKill) checkMurderAttemptAndKill(Sheriff.sheriff, target);

sheriffKillButton.Timer = sheriffKillButton.MaxTimer;
Expand Down Expand Up @@ -3015,7 +3014,7 @@ public static void createButtonsPostfix(HudManager __instance)
securityGuardChargesText.transform.localScale = Vector3.one * 0.5f;
securityGuardChargesText.transform.localPosition += new Vector3(-0.05f, 0.7f, 0);

// Arsonist button
// Arsonist button (涂油)
arsonistButton = new CustomButton(
() =>
{
Expand Down Expand Up @@ -3078,16 +3077,15 @@ public static void createButtonsPostfix(HudManager __instance)
}
);

// Arsonist button
// Arsonist button (点火)
arsonistKillButton = new CustomButton(
() =>
{
foreach (PlayerControl p in Arsonist.dousedPlayers.Where(p => p.IsAlive()))
{
checkMurderAttemptAndKill(Arsonist.arsonist, p, false, false, false);
GameHistory.OverrideDeathReasonAndKiller(p, CustomDeathReason.Arson, Arsonist.arsonist);
MurderPlayer(Arsonist.arsonist, p, false);
GameHistory.RpcOverrideDeathReasonAndKiller(p, CustomDeathReason.Arson, Arsonist.arsonist);
}
Message("点火");
arsonistKillButton.Timer = arsonistKillButton.MaxTimer;
arsonistButton.Timer = arsonistButton.MaxTimer;
},
Expand All @@ -3103,12 +3101,11 @@ public static void createButtonsPostfix(HudManager __instance)
},
() =>
{
/*var alivePlayersList = PlayerControl.AllPlayerControls.ToArray().Where(pc => !pc.Data.IsDead);
var alivePlayersList = PlayerControl.AllPlayerControls.ToArray().Where(pc => !pc.Data.IsDead);
var count = alivePlayersList.Count(pc => isNeutral(pc) && pc.isKiller());

if (count < 1) arsonistKillButton.Timer = arsonistKillButton.MaxTimer = 0f;
else */
arsonistKillButton.Timer = arsonistKillButton.MaxTimer;
if (count < 1 && Arsonist.igniteCooldownRemoved) arsonistKillButton.Timer = arsonistKillButton.MaxTimer = 0f;
else arsonistKillButton.Timer = arsonistKillButton.MaxTimer;
},
Arsonist.igniteSprite,
ButtonPositions.upperRowCenter,
Expand Down
57 changes: 32 additions & 25 deletions TheOtherRoles/GameHistory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Hazel;
using TheOtherRoles.Utilities;
using UnityEngine;

namespace TheOtherRoles;
Expand Down Expand Up @@ -35,56 +37,61 @@ public class DeadPlayer
public DateTime TimeOfDeath { get; }
public bool wasCleaned { get; set; }

public DeadPlayer(PlayerControl player, DateTime timeOfDeath, CustomDeathReason deathReason, PlayerControl killerIfExisting)
public DeadPlayer(PlayerControl Player, DateTime TimeOfDeath, CustomDeathReason DeathReason, PlayerControl KillerIfExisting)
{
this.Player = player;
this.TimeOfDeath = timeOfDeath;
DeathReason = deathReason;
KillerIfExisting = killerIfExisting;
this.Player = Player;
this.TimeOfDeath = TimeOfDeath;
this.DeathReason = DeathReason;
this.KillerIfExisting = KillerIfExisting;
wasCleaned = false;
}
}

public static class GameHistory
internal static class GameHistory
{
private static readonly Dictionary<byte, DeadPlayer> allDeadPlayers = new();

public static List<Tuple<Vector3, bool>> localPlayerPositions = new();
public static List<DeadPlayer> DeadPlayers = new();

public static void Clear()
{
localPlayerPositions.Clear();
allDeadPlayers.Clear();
}

public static IReadOnlyDictionary<byte, DeadPlayer> AllDeadPlayers => allDeadPlayers;

public static DeadPlayer GetByPlayerId(byte playerId)
{
return allDeadPlayers.TryGetValue(playerId, out var deadPlayer) ? deadPlayer : null;
DeadPlayers.Clear();
}

public static void OverrideDeathReasonAndKiller(PlayerControl player, CustomDeathReason deathReason, PlayerControl killer = null)
{
if (player == null) return;

var target = DeadPlayers.FirstOrDefault(x => x.Player.PlayerId == player.PlayerId);
byte playerId = player.PlayerId;
if (allDeadPlayers.TryGetValue(playerId, out var existingDeadPlayer))
if (target != null)
{
existingDeadPlayer.DeathReason = deathReason;
if (killer != null) existingDeadPlayer.KillerIfExisting = killer;
target.DeathReason = deathReason;
if (killer != null) target.KillerIfExisting = killer;
}
else
else if (player != null)
{
var newDeadPlayer = new DeadPlayer(player, DateTime.UtcNow, deathReason, killer);
allDeadPlayers[playerId] = newDeadPlayer;
// Create dead player if needed:
var dp = new DeadPlayer(player, DateTime.UtcNow, deathReason, killer);
DeadPlayers.Add(dp);
}
}

public static void RpcOverrideDeathReasonAndKiller(PlayerControl player, CustomDeathReason deathReason, PlayerControl killer = null)
{
if (player == null) return;
var writer = StartRPC(player.NetId, CustomRPC.ShareGhostInfo);
writer.Write(player.PlayerId);
writer.Write((byte)RPCProcedure.GhostInfoTypes.DeathReasonAndKiller);
writer.Write(player.PlayerId);
writer.Write((byte)deathReason);
writer.Write(killer.PlayerId);
writer.EndRPC();
OverrideDeathReasonAndKiller(player, deathReason, killer);
}

public static int GetKillCount(PlayerControl killer)
{
if (killer == null) return 0;

return allDeadPlayers.Values.Count(info => info.KillerIfExisting != null && info.KillerIfExisting.PlayerId == killer.PlayerId);
return DeadPlayers.Count(dp => dp.KillerIfExisting == killer && dp.Player != killer);
}
}
2 changes: 2 additions & 0 deletions TheOtherRoles/Options/CustomOptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class CustomOptionHolder
public static CustomOption arsonistSpawnRate;
public static CustomOption arsonistCooldown;
public static CustomOption arsonistDuration;
public static CustomOption arsonistIgniteCdRemoved;

public static CustomOption jackalSpawnRate;
public static CustomOption jackalKillCooldown;
Expand Down Expand Up @@ -1026,6 +1027,7 @@ public static void Load()
arsonistSpawnRate = Create(20120, Types.Neutral, cs(Arsonist.color, "Arsonist"), rates, null, true);
arsonistCooldown = Create(20121, Types.Neutral, "arsonistCooldown", 12.5f, 5f, 60f, 2.5f, arsonistSpawnRate);
arsonistDuration = Create(20122, Types.Neutral, "arsonistDuration", 0.25f, 0f, 10f, 0.125f, arsonistSpawnRate);
arsonistIgniteCdRemoved = Create(20123, Types.Neutral, "arsonistIgniteCdRemoved", false, arsonistSpawnRate);

swooperSpawnRate = Create(20150, Types.Neutral, cs(Swooper.color, "Swooper"), rates, null, true);
swooperKillCooldown = Create(20151, Types.Neutral, "swooperKillCooldown", 25f, 10f, 60f, 2.5f, swooperSpawnRate);
Expand Down
1 change: 1 addition & 0 deletions TheOtherRoles/Patches/IntroPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal class IntroCutsceneOnDestroyPatch

public static void Prefix(IntroCutscene __instance)
{
Message("游戏开始");
// Generate and initialize player icons
var playerCounter = 0;
var hideNSeekCounter = 0;
Expand Down
12 changes: 7 additions & 5 deletions TheOtherRoles/Patches/PlayerControlPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ private static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] GameD
__instance.PlayerId == Slueth.slueth.PlayerId;
if (isMedicReport || isDetectiveReport)
{
AllDeadPlayers.TryGetValue(target.PlayerId, out var deadPlayer);
var deadPlayer = DeadPlayers?.Where(x => x.Player?.PlayerId == target?.PlayerId)?.FirstOrDefault();
if (deadPlayer != null && deadPlayer.KillerIfExisting != null)
{
var timeSinceDeath = (float)(DateTime.UtcNow - deadPlayer.TimeOfDeath).TotalMilliseconds;
Expand Down Expand Up @@ -2096,7 +2096,7 @@ private static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] GameD
CachedPlayer.LocalPlayer.PlayerControl.NetId, (byte)CustomRPC.ShareGhostInfo,
SendOption.Reliable);
writer.Write(CachedPlayer.LocalPlayer.PlayerId);
writer.Write((byte)RPCProcedure.GhostInfoTypes.DetectiveOrMedicInfo);
writer.Write((byte)RPCProcedure.GhostInfoTypes.MediumInfo);
writer.Write(msg);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
Expand Down Expand Up @@ -2133,9 +2133,10 @@ public static void Prefix(PlayerControl __instance, [HarmonyArgument(0)] PlayerC
public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] PlayerControl target)
{
// Collect dead player info
OverrideDeathReasonAndKiller(__instance, CustomDeathReason.Kill, __instance);

AllDeadPlayers.TryGetValue(__instance.PlayerId, out var deadPlayer);
var deadPlayer = new DeadPlayer(target, DateTime.UtcNow, CustomDeathReason.Kill, __instance);
if (__instance == target) deadPlayer = new DeadPlayer(target, DateTime.UtcNow, CustomDeathReason.Suicide, __instance);
DeadPlayers.Add(deadPlayer);

// Reset killer to crewmate if resetToCrewmate
if (resetToCrewmate) __instance.Data.Role.TeamType = RoleTeamTypes.Crewmate;
Expand Down Expand Up @@ -2457,7 +2458,8 @@ public static class ExilePlayerPatch
public static void Postfix(PlayerControl __instance)
{
// Collect dead player info
OverrideDeathReasonAndKiller(__instance, CustomDeathReason.Exile, null);
var deadPlayer = new DeadPlayer(__instance, DateTime.UtcNow, CustomDeathReason.Exile, null);
DeadPlayers.Add(deadPlayer);

// Remove fake tasks when player dies
if (__instance.hasFakeTasks() || __instance == Lawyer.lawyer || __instance == Pursuer.pursuer.Contains(__instance) ||
Expand Down
2 changes: 1 addition & 1 deletion TheOtherRoles/Patches/UsablesPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ private static void Postfix(VitalsMinigame __instance)
// Hacker update
if (vitalsPanel.IsDead)
{
AllDeadPlayers.TryGetValue(player.PlayerId, out var deadPlayer);
var deadPlayer = DeadPlayers?.Where(x => x.Player?.PlayerId == player?.PlayerId)?.FirstOrDefault();
if (deadPlayer != null && k < hackerTexts.Count && hackerTexts[k] != null)
{
var timeSinceDeath = (float)(DateTime.UtcNow - deadPlayer.TimeOfDeath).TotalMilliseconds;
Expand Down
2 changes: 1 addition & 1 deletion TheOtherRoles/Patches/VitalsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private static void Postfix(VitalsMinigame __instance)

// Hacker update
if (!vitalsPanel.IsDead) continue;
AllDeadPlayers.TryGetValue(player.PlayerId, out var deadPlayer);
var deadPlayer = DeadPlayers?.Where(x => x.Player?.PlayerId == player?.PlayerId)?.FirstOrDefault();
if (deadPlayer == null || k >= hackerTexts.Count || hackerTexts[k] == null) continue;
var timeSinceDeath = (float)(DateTime.UtcNow - deadPlayer.TimeOfDeath).TotalMilliseconds;
hackerTexts[k].gameObject.SetActive(true);
Expand Down
9 changes: 1 addition & 8 deletions TheOtherRoles/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ public enum GhostInfoTypes
WarlockTarget,
MediumInfo,
BlankUsed,
DetectiveOrMedicInfo,
VampireTimer,
DeathReasonAndKiller
}
Expand Down Expand Up @@ -3159,20 +3158,14 @@ public static void receiveGhostInfo(byte senderId, MessageReader reader)
if (shouldShowGhostInfo())
FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(sender, mediumInfo);
break;
case GhostInfoTypes.DetectiveOrMedicInfo:
var detectiveInfo = reader.ReadString();
if (shouldShowGhostInfo())
FastDestroyableSingleton<HudManager>.Instance.Chat.AddChat(sender, detectiveInfo);
break;
case GhostInfoTypes.BlankUsed:
Pursuer.blankedList.Remove(sender);
break;
case GhostInfoTypes.VampireTimer:
vampireKillButton.Timer = reader.ReadByte();
break;
case GhostInfoTypes.DeathReasonAndKiller:
OverrideDeathReasonAndKiller(playerById(reader.ReadByte()),
(CustomDeathReason)reader.ReadByte(), playerById(reader.ReadByte()));
OverrideDeathReasonAndKiller(playerById(reader.ReadByte()), (CustomDeathReason)reader.ReadByte(), playerById(reader.ReadByte()));
break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions TheOtherRoles/Resources/stringData.json
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,9 @@
"0": "Arsonist Douse Duration",
"13": "涂油所需时间"
},
"arsonistIgniteCdRemoved": {
"13": "仅剩最后一名杀手时移除点火冷却"
},
"jackalKillCooldown": {
"0": "Jackal/Sidekick Kill Cooldown",
"13": "豺狼/跟班击杀冷却"
Expand Down
6 changes: 4 additions & 2 deletions TheOtherRoles/Roles/Neutral/Arsonist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Arsonist

public static float cooldown = 30f;
public static float duration = 3f;
public static bool triggerArsonistWin;
public static bool igniteCooldownRemoved;

public static PlayerControl currentTarget;
public static PlayerControl currentTarget2;
Expand All @@ -36,13 +36,15 @@ public static void clearAndReload()
{
arsonist = null;
currentTarget = null;
currentTarget2 = null;
douseTarget = null;
triggerArsonistWin = false;
dousedPlayers = new List<PlayerControl>();
foreach (var p in ModOption.playerIcons.Values)
if (p != null && p.gameObject != null)
p.gameObject.SetActive(false);

cooldown = CustomOptionHolder.arsonistCooldown.getFloat();
duration = CustomOptionHolder.arsonistDuration.getFloat();
igniteCooldownRemoved = CustomOptionHolder.arsonistIgniteCdRemoved.getBool();
}
}
2 changes: 1 addition & 1 deletion TheOtherRoles/Roles/Neutral/Doomsayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace TheOtherRoles.Roles.Neutral;
public static class Doomsayer
{
public static PlayerControl doomsayer;

public static Color color = new Color32(0, 255, 128, byte.MaxValue);

public static PlayerControl currentTarget;
public static List<PlayerControl> playerTargetinformation = new();
public static float cooldown = 30f;
Expand Down
Loading

0 comments on commit a5aa627

Please sign in to comment.