|
| 1 | +using System; |
| 2 | +using UnityEngine; |
| 3 | +using Object = UnityEngine.Object; |
| 4 | +using UnityEngine.Events; |
1 | 5 | using System.Collections.Generic; |
2 | 6 | using HarmonyLib; |
3 | 7 | using NewMod.Utilities; |
| 8 | +using MiraAPI.Roles; |
| 9 | +using MiraAPI.Hud; |
| 10 | +using Reactor.Utilities; |
4 | 11 | using System.Linq; |
5 | 12 | using Il2CppInterop.Runtime.InteropTypes.Arrays; |
6 | 13 | using AmongUs.GameOptions; |
| 14 | +using NewMod.Roles.NeutralRoles; |
7 | 15 |
|
8 | 16 | namespace NewMod.Patches.Roles |
9 | 17 | { |
@@ -58,10 +66,76 @@ public static bool Prefix(MeetingHud __instance, byte reporter) |
58 | 66 | __instance.playerStates[i] = voteArea; |
59 | 67 | } |
60 | 68 | __instance.SortButtons(); |
61 | | - |
| 69 | + |
62 | 70 | return false; |
63 | 71 | } |
64 | 72 | } |
| 73 | + [HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.VotingComplete))] |
| 74 | + public static class MeetingHud_VotingComplete_Patch |
| 75 | + { |
| 76 | + public static void Postfix(MeetingHud __instance, MeetingHud.VoterState[] states, NetworkedPlayerInfo exiled, bool tie) |
| 77 | + { |
| 78 | + if (tie || exiled == null) return; |
| 79 | + |
| 80 | + var exiledPlayer = Utils.PlayerById(exiled.PlayerId); |
| 81 | + foreach (var overload in PlayerControl.AllPlayerControls.ToArray().Where(p => p.AmOwner && p.Data.Role is OverloadRole)) |
| 82 | + { |
| 83 | + if (!(exiledPlayer.Data.Role is ICustomRole)) |
| 84 | + { |
| 85 | + if (exiledPlayer.Data.Role.Ability == null) |
| 86 | + { |
| 87 | + Coroutines.Start(CoroutinesHelper.CoNotify("<color=orange>No ability to absorb from this player.</color>")); |
| 88 | + continue; |
| 89 | + } |
| 90 | + if (OverloadRole.AbsorbedAbilityCount >= 3) |
| 91 | + { |
| 92 | + Coroutines.Start(CoroutinesHelper.CoNotify("<color=red>Maximum abilities absorbed.</color>")); |
| 93 | + continue; |
| 94 | + } |
| 95 | + OverloadRole.AbsorbedAbilityCount++; |
| 96 | + var role = exiledPlayer.Data.Role; |
| 97 | + |
| 98 | + var absorbedButton = Object.Instantiate(HudManager.Instance.AbilityButton, HudManager.Instance.AbilityButton.transform.parent); |
| 99 | + absorbedButton.SetFromSettings(role.Ability); |
| 100 | + |
| 101 | + var pb = absorbedButton.GetComponent<PassiveButton>(); |
| 102 | + pb.OnClick.RemoveAllListeners(); |
| 103 | + pb.OnClick.AddListener((UnityAction)role.UseAbility); |
| 104 | + |
| 105 | + Coroutines.Start(CoroutinesHelper.CoNotify( |
| 106 | + $"<color=green>Ability absorbed from {exiledPlayer.Data.PlayerName}. Total absorbed: {OverloadRole.AbsorbedAbilityCount}</color>")); |
| 107 | + } |
| 108 | + else |
| 109 | + { |
| 110 | + if (OverloadRole.AbsorbedAbilityCount >= 3) |
| 111 | + { |
| 112 | + Coroutines.Start(CoroutinesHelper.CoNotify("<color=red>Maximum abilities absorbed.</color>")); |
| 113 | + continue; |
| 114 | + } |
| 115 | + OverloadRole.AbsorbedAbilityCount++; |
| 116 | + var customRole = (ICustomRole)exiledPlayer.Data.Role; |
| 117 | + var parentMod = customRole.ParentMod; |
| 118 | + Debug.Log(parentMod == null); |
| 119 | + |
| 120 | + var buttons = parentMod.GetButtons(); |
| 121 | + Debug.Log(buttons.Count); |
| 122 | + |
| 123 | + var exiledButton = buttons.First(); |
| 124 | + var newButton = Activator.CreateInstance(exiledButton.GetType()) as CustomActionButton; |
| 125 | + newButton.CreateButton(HudManager.Instance.AbilityButton.transform.parent); |
| 126 | + newButton.OverrideName(exiledButton.Name); |
| 127 | + newButton.OverrideSprite(exiledButton.Sprite.LoadAsset()); |
| 128 | + |
| 129 | + var passive = newButton.Button.GetComponent<PassiveButton>(); |
| 130 | + passive.OnClick.RemoveAllListeners(); |
| 131 | + passive.OnClick.AddListener((UnityAction)newButton.ClickHandler); |
| 132 | + |
| 133 | + Coroutines.Start(CoroutinesHelper.CoNotify( |
| 134 | + $"<color=green>Custom ability absorbed from {exiledPlayer.Data.PlayerName}. Total absorbed: {OverloadRole.AbsorbedAbilityCount}</color>")); |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + } |
65 | 139 | } |
66 | 140 | } |
67 | 141 | } |
0 commit comments