-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAbilityPatches.cs
128 lines (111 loc) · 5.02 KB
/
AbilityPatches.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using AmongUs.GameOptions;
using HarmonyLib;
using UnityEngine;
namespace DillyzRoleApi_Rewritten
{
class AbilityPatches
{
[HarmonyPatch(typeof(Vent), nameof(Vent.CanUse))]
public class VentPatch {
public static bool Prefix(Vent __instance, GameData.PlayerInfo pc, ref bool canUse, ref bool couldUse, ref float __result) {
float dist = float.MaxValue;
var obj = pc.Object;
canUse = couldUse = (obj.CanMove || obj.inVent) && roleCanVent(obj);
if (canUse)
{
Vector3 truepos = obj.GetTruePosition();
Vector3 pos = __instance.transform.position;
dist = Vector2.Distance(truepos, pos);
canUse &= (dist <= __instance.UsableDistance);
}
__result = dist;
return false;
}
public static bool roleCanVent(PlayerControl player)
{
string rolename = DillyzUtil.getRoleName(player);
if (player.Data.IsDead)
return false;
if (rolename == "Impostor" || rolename == "ShapeShifter" || rolename == "Engineer")
return true;
CustomRole role = CustomRole.getByName(rolename);
if (role == null)
return false;
return role.ventPrivilege != VentPrivilege.None;
}
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.MurderPlayer))]
public class MurderPatch {
public static bool Prefix(PlayerControl __instance, PlayerControl target)
{
string rolename = DillyzUtil.getRoleName(__instance);
CustomRole role = CustomRole.getByName(rolename);
if (rolename == "Impostor" || rolename == "ShapeShifter" || (role != null && role.switchToImpostor && role.canKill))
return true;
// don't kill em
return false;
}
}
[HarmonyPatch(typeof(ActionButton), nameof(ActionButton.CanInteract))]
public static class ActionButtonInteractionPatch
{
public static bool Prefix(ActionButton __instance, ref bool __result)
{
CustomRole role = CustomRole.getByName(DillyzUtil.getRoleName(PlayerControl.LocalPlayer));
if (role == null)
return true;
switch (__instance.name) {
case "KillButton":
if (role.canKill)
__result = true;
else
__result = false;
return false;
case "VentButton":
if (role.ventPrivilege != VentPrivilege.None)
__result = true;
else
__result = false;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(KillButton), nameof(KillButton.DoClick))]
[HarmonyPriority(Priority.Last)]
public static class KillButtonClickPatch
{
public static bool Prefix(KillButton __instance)
{
if (__instance.gameObject.GetComponent<KillButtonCustomData>() != null)
return false;
string rolename = DillyzUtil.getRoleName(PlayerControl.LocalPlayer);
CustomRole role = CustomRole.getByName(rolename);
if (PlayerControl.LocalPlayer.Data.IsDead || !PlayerControl.LocalPlayer.CanMove || __instance.currentTarget == null || __instance.isCoolingDown)
return false;
if (rolename == "GuardianAngel")
return true;
if (role != null && !role.canKill)
return false;
HudManagerPatch.lastKillThingForCustoms = DateTime.UtcNow;
DillyzUtil.RpcCommitAssassination(PlayerControl.LocalPlayer, __instance.currentTarget);
__instance.SetTarget(null);
if (rolename == "Impostor" || rolename == "ShapeShifter")
PlayerControl.LocalPlayer.SetKillTimer(GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown));
return false;
}
}
// not really an ability, however, i don't care.
[HarmonyPatch(typeof(Vent), nameof(Vent.SetOutline))]
public class VentPatch_SetOutline
{
public static void Postfix(Vent __instance, bool on, bool mainTarget)
{
Color color = DillyzUtil.color32ToColor(DillyzUtil.roleColor(PlayerControl.LocalPlayer, true));
__instance.myRend.material.SetColor("_OutlineColor", color);
__instance.myRend.material.SetColor("_AddColor", mainTarget ? color : Color.clear);
}
}
}
}