Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions NewMod/Buttons/Overload/FinalButton.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using MiraAPI.GameEnd;
using MiraAPI.GameOptions;
using MiraAPI.Hud;
using MiraAPI.Keybinds;
Expand Down Expand Up @@ -66,10 +67,7 @@ public override bool Enabled(RoleBehaviour role)
/// </summary>
protected override void OnClick()
{
GameManager.Instance.RpcEndGame(
(GameOverReason)NewModEndReasons.OverloadWin,
false
);
CustomGameOver.Trigger<OverloadGameOver>([PlayerControl.LocalPlayer.Data]);
}
}
}
}
6 changes: 5 additions & 1 deletion NewMod/Components/WraithCallerNpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public IEnumerator CoMove()

UpdateWalkAnimation(velocity);

if (AmongUsClient.Instance.AmHost && delta.magnitude <= 0.15f)
if (AmongUsClient.Instance.AmHost && delta.magnitude <= 0.01f)
{
body.velocity = Vector2.zero;
UpdateWalkAnimation(Vector2.zero);
Expand All @@ -126,6 +126,7 @@ public IEnumerator CoMove()
UpdateWalkAnimation(Vector2.zero);
Dispose();
}

[HideFromIl2Cpp]
public void UpdateWalkAnimation(Vector2 velocity)
{
Expand All @@ -142,6 +143,7 @@ public void UpdateWalkAnimation(Vector2 velocity)
{
animations.PlayRunAnimation();
}

if (Visual.cosmetics.HasSkinLoaded() && !Visual.cosmetics.IsSkinPlayingRunAnim())
{
Visual.cosmetics.AnimateSkinRun();
Expand All @@ -159,10 +161,12 @@ public void UpdateWalkAnimation(Vector2 velocity)
}
}
}

var pos = Visual.transform.position;
pos.z = pos.y / 1000f;
Visual.transform.position = pos;
}

[HideFromIl2Cpp]
public void Dispose()
{
Expand Down
209 changes: 209 additions & 0 deletions NewMod/CustomGameOvers/CustomGameEnd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Gameplay;
using MiraAPI.GameEnd;
using MiraAPI.GameOptions;
using NewMod.Options.Roles.EnergyThiefOptions;
using NewMod.Options.Roles.InjectorOptions;
using NewMod.Options.Roles.PulseBladeOptions;
using NewMod.Options.Roles.ShadeOptions;
using NewMod.Options.Roles.SpecialAgentOptions;
using NewMod.Options.Roles.WraithCallerOptions;
using NewMod.Roles.CrewmateRoles;
using NewMod.Roles.ImpostorRoles;
using NewMod.Roles.NeutralRoles;
using NewMod.Utilities;

namespace NewMod.CustomGameOvers;

public static class CustomEndGame
{
internal static bool IsMatchReady { get; set; }

[RegisterEvent]
public static void OnRoundStart(RoundStartEvent evt)
{
if (evt.TriggeredByIntro)
{
IsMatchReady = true;
}
}

[RegisterEvent]
public static void OnGameEnd(GameEndEvent evt)
{
IsMatchReady = false;
}

public static bool TryEndGame()
{
if (!IsMatchReady || !AmongUsClient.Instance.AmHost || !GameManager.Instance.ShouldCheckForGameEnd)
{
return false;
}

var alivePlayers = PlayerControl.AllPlayerControls.ToArray()
.Where(player => !player.Data.IsDead && !player.Data.Disconnected)
.ToArray();

var wraithRequired = (int)OptionGroupSingleton<WraithCallerOptions>.Instance.RequiredNPCsToSend;
var wraithCaller = alivePlayers.FirstOrDefault(player =>
player.Data.Role is WraithCaller &&
WraithCallerUtilities.GetKillsNPC(player.PlayerId) >= wraithRequired);

if (wraithCaller)
{
CustomGameOver.Trigger<WraithCallerGameOver>([wraithCaller.Data]);
return true;
}

var shadeRequired = (int)OptionGroupSingleton<ShadeOptions>.Instance.RequiredKills;
var shade = alivePlayers.FirstOrDefault(player =>
{
if (player.Data.Role is not Shade)
{
return false;
}

Shade.ShadeKills.TryGetValue(player.PlayerId, out var kills);
return kills >= shadeRequired;
});

if (shade)
{
CustomGameOver.Trigger<ShadeGameOver>([shade.Data]);
return true;
}

var pulseBladeOptions = OptionGroupSingleton<PulseBladeOptions>.Instance;

if (alivePlayers.Length <= pulseBladeOptions.PlayersThreshold)
{
var pulseBlade = alivePlayers.FirstOrDefault(player =>
player.Data.Role is PulseBlade &&
Utils.GetStrikes(player.PlayerId) >= pulseBladeOptions.RequiredStrikes);

if (pulseBlade)
{
CustomGameOver.Trigger<PulseBladeGameOver>([pulseBlade.Data]);
return true;
}
}

if (Tyrant.ApexThroneReady && Tyrant.ApexThroneOutcomeSet)
{
var tyrant = alivePlayers.FirstOrDefault(player => player.Data.Role is Tyrant);

if (tyrant)
{
var winners = new List<NetworkedPlayerInfo> { tyrant.Data };

if (Tyrant.Outcome == Tyrant.ThroneOutcome.ChampionSideWin)
{
var champion = Utils.PlayerById(Tyrant.ChampionId);

if (champion && !champion.Data.Disconnected)
{
winners.Add(champion.Data);
}
}

CustomGameOver.Trigger<TyrantGameOver>(winners);
return true;
}
}

var doubleAgent = alivePlayers.FirstOrDefault(player =>
player.Data.Role is DoubleAgent &&
player.AllTasksCompleted() &&
Utils.IsSabotage());

if (doubleAgent)
{
CustomGameOver.Trigger<DoubleAgentGameOver>([doubleAgent.Data]);
return true;
}

var specialAgentRequired =
OptionGroupSingleton<SpecialAgentOptions>.Instance.RequiredMissionsToWin;

var specialAgent = alivePlayers.FirstOrDefault(player =>
player.Data.Role is SpecialAgent &&
Utils.GetMissionSuccessCount(player.PlayerId) -
Utils.GetMissionFailureCount(player.PlayerId) >= specialAgentRequired);

if (specialAgent)
{
CustomGameOver.Trigger<SpecialAgentGameOver>([specialAgent.Data]);
return true;
}

var prankster = alivePlayers.FirstOrDefault(player =>
player.Data.Role is Prankster &&
PranksterUtilities.GetReportCount(player.PlayerId) >= 2);

if (prankster)
{
CustomGameOver.Trigger<PranksterGameOver>([prankster.Data]);
return true;
}

var energyThiefRequired =
(int)OptionGroupSingleton<EnergyThiefOptions>.Instance.RequiredDrainCount;

var energyThief = alivePlayers.FirstOrDefault(player =>
player.Data.Role is EnergyThief &&
Utils.GetDrainCount(player.PlayerId) >= energyThiefRequired);

if (energyThief)
{
CustomGameOver.Trigger<EnergyThiefGameOver>([energyThief.Data]);
return true;
}

var injectorRequired =
(int)OptionGroupSingleton<InjectorOptions>.Instance.RequiredInjectCount;

var injector = alivePlayers.FirstOrDefault(player =>
player.Data.Role is InjectorRole &&
Utils.GetInjectedCount() >= injectorRequired);

if (injector)
{
CustomGameOver.Trigger<InjectorGameOver>([injector.Data]);
return true;
}

return false;
}
}

[HarmonyPatch(typeof(GameManager), nameof(GameManager.StartGame))]
public static class GameStartPatch
{
[HarmonyPrefix]
public static void Prefix()
{
CustomEndGame.IsMatchReady = false;
NewModEventHandler.ResetMatchState();
}
}

[HarmonyPatch(typeof(LogicGameFlowNormal), nameof(LogicGameFlowNormal.CheckEndCriteria))]
public static class CustomEndGameCheckPatch
{
[HarmonyPostfix]
public static void Postfix()
{
if (!CustomEndGame.IsMatchReady || !AmongUsClient.Instance.AmHost ||
DestroyableSingleton<TutorialManager>.InstanceExists || MeetingHud.Instance || ExileController.Instance ||
!GameManager.Instance.ShouldCheckForGameEnd)
{
return;
}

CustomEndGame.TryEndGame();
}
}
37 changes: 4 additions & 33 deletions NewMod/DiscordStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Inspired by: https://github.com/All-Of-Us-Mods/LaunchpadReloaded/blob/master/LaunchpadReloaded/Patches/Generic/DiscordManagerPatch.cs#L12

using System;
using Discord;
using HarmonyLib;
Expand All @@ -11,37 +12,6 @@ namespace NewMod
[HarmonyPatch]
public static class NewModDiscordPatch
{
private static Discord.Discord discord;
public static ActivityManager activityManager;

[HarmonyPrefix]
[HarmonyPatch(typeof(DiscordManager), nameof(DiscordManager.Start))]
public static bool StartPrefix(DiscordManager __instance)
{
if (Application.platform == RuntimePlatform.Android) return true;

InitializeDiscord(__instance);
return false;
}

private static void InitializeDiscord(DiscordManager __instance)
{
const long clientId = 1405946628115791933;

discord = new Discord.Discord(clientId, (ulong)CreateFlags.Default);
activityManager = discord.GetActivityManager();

activityManager.RegisterSteam(945360U);
activityManager.add_OnActivityJoin((Action<string>)__instance.HandleJoinRequest);

SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>)((scene, _) =>
{
__instance.OnSceneChange(scene.name);
}));
__instance.presence = discord;
__instance.SetInMenus();
}

[HarmonyPrefix]
[HarmonyPatch(typeof(ActivityManager), nameof(ActivityManager.UpdateActivity))]
public static void UpdateActivityPrefix([HarmonyArgument(0)] ref Activity activity)
Expand Down Expand Up @@ -69,7 +39,8 @@ public static void UpdateActivityPrefix([HarmonyArgument(0)] ref Activity activi
var miraVersion = MiraApiPlugin.Version;
var platform = Application.platform;

activity.Details += $" | Lobby: {lobbyCode} | Max: {maxPlayers} | MiraAPI: {miraVersion} | {platform}";
activity.Details +=
$" | Lobby: {lobbyCode} | Max: {maxPlayers} | MiraAPI: {miraVersion} | {platform}";
}

if (MeetingHud.Instance)
Expand All @@ -83,4 +54,4 @@ public static void UpdateActivityPrefix([HarmonyArgument(0)] ref Activity activi
}
}
}
}
}
Loading
Loading