mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
fix modifier errors in end game win patch
This commit is contained in:
1 parent
54d85a6996
commit
e242975d75
2 files changed
+29
-16
No files matched your search
@@ -34,7 +34,7 @@ public abstract class GameModifier : BaseModifier
|
|||||||
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
|
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether the player won the game with this modifier.
|
/// Determines whether the player won the game with this modifier. The modifier with the highest priority will override other modifiers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="reason">The reason why the game ended.</param>
|
/// <param name="reason">The reason why the game ended.</param>
|
||||||
/// <returns>True if the player won, false if they lost. Return null to use the player's default win condition.</returns>
|
/// <returns>True if the player won, false if they lost. Return null to use the player's default win condition.</returns>
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Modifiers.Types;
|
using MiraAPI.Modifiers.Types;
|
||||||
using MiraAPI.Utilities;
|
|
||||||
using Reactor.Utilities;
|
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Modifiers;
|
namespace MiraAPI.Patches.Modifiers;
|
||||||
|
|
||||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameEnd))]
|
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameEnd))]
|
||||||
public static class EndGameDidWinPatch
|
internal static class EndGameDidWinPatch
|
||||||
{
|
{
|
||||||
public static void Postfix()
|
private static List<CachedPlayerData> CachedWinners { get; set; } = [];
|
||||||
|
|
||||||
|
public static void Prefix(EndGameResult endGameResult)
|
||||||
{
|
{
|
||||||
var gameOverReason = EndGameResult.CachedGameOverReason;
|
CachedWinners.Clear();
|
||||||
EndGameResult.CachedWinners.Clear();
|
var gameOverReason = endGameResult.GameOverReason;
|
||||||
|
|
||||||
var players = GameData.Instance.AllPlayers.ToArray();
|
var players = GameData.Instance.AllPlayers.ToArray();
|
||||||
for (var i = 0; i < GameData.Instance.PlayerCount; i++)
|
for (var i = 0; i < GameData.Instance.PlayerCount; i++)
|
||||||
@@ -26,25 +27,37 @@ public static class EndGameDidWinPatch
|
|||||||
|
|
||||||
var didWin = networkedPlayerInfo.Role.DidWin(gameOverReason);
|
var didWin = networkedPlayerInfo.Role.DidWin(gameOverReason);
|
||||||
|
|
||||||
bool? modifierDidWin = null;
|
if (!networkedPlayerInfo.Object)
|
||||||
|
{
|
||||||
|
if (didWin)
|
||||||
|
{
|
||||||
|
CachedWinners.Add(new CachedPlayerData(networkedPlayerInfo));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var modifier in networkedPlayerInfo.Object.GetModifiers<GameModifier>().OrderByDescending(x => x.Priority()))
|
foreach (var modifier in networkedPlayerInfo.Object.GetModifiers<GameModifier>().OrderByDescending(x => x.Priority()))
|
||||||
{
|
{
|
||||||
var result = modifier.DidWin(gameOverReason);
|
var result = modifier.DidWin(gameOverReason);
|
||||||
if (!result.HasValue) continue;
|
if (!result.HasValue) continue;
|
||||||
|
|
||||||
modifierDidWin = result.Value;
|
didWin = result.Value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modifierDidWin.HasValue)
|
|
||||||
{
|
|
||||||
didWin = modifierDidWin.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (didWin)
|
if (didWin)
|
||||||
{
|
{
|
||||||
EndGameResult.CachedWinners.Add(new CachedPlayerData(networkedPlayerInfo));
|
CachedWinners.Add(new CachedPlayerData(networkedPlayerInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Postfix(EndGameResult endGameResult)
|
||||||
|
{
|
||||||
|
EndGameResult.CachedWinners.Clear();
|
||||||
|
foreach (var winner in CachedWinners)
|
||||||
|
{
|
||||||
|
EndGameResult.CachedWinners.Add(winner);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user