Skip to content

Commit a4f9df9

Browse files
Merge pull request #25 from CallOfCreator/dev
v1.2.9 Hotfix 2
2 parents 164058b + 68e4e44 commit a4f9df9

26 files changed

Lines changed: 536 additions & 333 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ obj/
33
References/
44
NewMod/Components/Minigames
55
NewMod/Components/Hidden.cs
6+
NewMod/Private
67
/packages/
78
riderModule.iml
89
.idea

NewMod/Buttons/Necromancer/ReviveButton.cs

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
using UnityEngine;
77
using NewMod.Utilities;
88
using MiraAPI.Keybinds;
9+
using AmongUs.GameOptions;
10+
using Reactor.Utilities;
11+
using MiraAPI.Utilities;
12+
using System.Linq;
913

1014
namespace NewMod.Buttons.Necromancer
1115
{
@@ -54,15 +58,29 @@ public class ReviveButton : CustomActionButton
5458
/// </summary>
5559
protected override void OnClick()
5660
{
61+
var local = PlayerControl.LocalPlayer;
62+
63+
var body = Helpers.GetNearestDeadBodies(
64+
local.GetTruePosition(),
65+
ShipStatus.Instance.MaxLightRadius,
66+
Helpers.CreateFilter(Constants.NotShipMask))
67+
.Where(b => b != null && !PranksterUtilities.IsPranksterBody(b))
68+
.OrderBy(b => Vector2.Distance(local.GetTruePosition(), b.TruePosition))
69+
.FirstOrDefault();
70+
71+
if (body == null) return;
72+
5773
SoundManager.Instance.PlaySound(NewModAsset.ReviveSound?.LoadAsset(), false, 2f);
5874

59-
var closestBody = Utils.GetClosestBody();
60-
if (closestBody != null)
61-
{
62-
Utils.RpcRevive(closestBody);
63-
}
75+
Utils.HandleRevive(
76+
local,
77+
body.ParentId,
78+
RoleTypes.Crewmate,
79+
body.transform.position.x,
80+
body.transform.position.y
81+
);
82+
NecromancerRole.RevivedPlayers[body.ParentId] = local.PlayerId;
6483
}
65-
6684
/// <summary>
6785
/// Determines whether this button is enabled for the role, returning true if the role is <see cref="NecromancerRole"/>.
6886
/// </summary>
@@ -79,32 +97,26 @@ public override bool Enabled(RoleBehaviour role)
7997
/// <returns>True if all requirements to use this button are met; otherwise false.</returns>
8098
public override bool CanUse()
8199
{
82-
bool isTimerDone = Timer <= 0;
83-
bool hasUsesLeft = UsesLeft > 0;
84-
var closestBody = Utils.GetClosestBody();
85-
bool isNearDeadBody = closestBody != null;
86-
bool isFakeBody = isNearDeadBody && PranksterUtilities.IsPranksterBody(closestBody);
100+
var bodiesInRange = Helpers.GetNearestDeadBodies(
101+
PlayerControl.LocalPlayer.transform.position,
102+
ShipStatus.Instance.MaxLightRadius,
103+
Helpers.CreateFilter(Constants.NotShipMask));
87104

88-
if (closestBody == null)
105+
bool canUse = bodiesInRange.Any(body =>
89106
{
90-
return false;
91-
}
107+
if (PranksterUtilities.IsPranksterBody(body)) return false;
92108

93-
bool wasNotKilledByNecromancer = true;
94-
var deadBody = closestBody.GetComponent<DeadBody>();
95-
if (deadBody != null)
96-
{
97-
var killedPlayer = GameData.Instance.GetPlayerById(deadBody.ParentId)?.Object;
98-
if (killedPlayer != null)
99-
{
100-
var killer = Utils.GetKiller(killedPlayer);
101-
if (killer != null && killer.Data.Role is NecromancerRole)
102-
{
103-
wasNotKilledByNecromancer = false;
104-
}
105-
}
106-
}
107-
return isTimerDone && hasUsesLeft && isNearDeadBody && wasNotKilledByNecromancer && !isFakeBody;
109+
var killedPlayer = GameData.Instance.GetPlayerById(body.ParentId)?.Object;
110+
if (killedPlayer == null) return false;
111+
112+
var killer = Utils.GetKiller(killedPlayer);
113+
if (killer.PlayerId == PlayerControl.LocalPlayer.PlayerId)
114+
return false;
115+
116+
return true;
117+
});
118+
119+
return canUse;
108120
}
109121
}
110122
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using MiraAPI.Hud;
2+
using MiraAPI.Keybinds;
3+
using MiraAPI.Utilities.Assets;
4+
using NewMod.Roles.ImpostorRoles;
5+
using Reactor.Utilities;
6+
using AmongUs.GameOptions;
7+
using System.Linq;
8+
using UnityEngine;
9+
using MiraAPI.Networking;
10+
using MiraAPI.Utilities;
11+
12+
namespace NewMod.Buttons
13+
{
14+
public class RevivedKillButton : CustomActionButton<PlayerControl>
15+
{
16+
public override string Name => "KILL";
17+
public override float Cooldown => GameOptionsManager.Instance.CurrentGameOptions.GetFloat(FloatOptionNames.KillCooldown);
18+
public override int MaxUses => 0;
19+
public override float EffectDuration => 0f;
20+
public override MiraKeybind Keybind => MiraGlobalKeybinds.PrimaryAbility;
21+
public override ButtonLocation Location => ButtonLocation.BottomRight;
22+
public override LoadableAsset<Sprite> Sprite => NewModAsset.VanillaKillButton;
23+
public override bool Enabled(RoleBehaviour role)
24+
{
25+
return NecromancerRole.RevivedPlayers.ContainsKey(PlayerControl.LocalPlayer.PlayerId);
26+
}
27+
public override PlayerControl GetTarget()
28+
{
29+
return PlayerControl.LocalPlayer.GetClosestPlayer(true, Distance);
30+
}
31+
public override bool IsTargetValid(PlayerControl target)
32+
{
33+
return target.PlayerId != PlayerControl.LocalPlayer.PlayerId;
34+
}
35+
public override void SetOutline(bool active)
36+
{
37+
Target.cosmetics.SetOutline(active, new Il2CppSystem.Nullable<Color>(Palette.ImpostorRed));
38+
}
39+
40+
public override bool CanUse()
41+
{
42+
if (!NecromancerRole.RevivedPlayers.ContainsKey(PlayerControl.LocalPlayer.PlayerId)) return false;
43+
return true;
44+
}
45+
46+
protected override void OnClick()
47+
{
48+
var local = PlayerControl.LocalPlayer;
49+
50+
local.RpcCustomMurder(
51+
Target,
52+
didSucceed: true,
53+
resetKillTimer: true,
54+
createDeadBody: true,
55+
teleportMurderer: true,
56+
showKillAnim: true,
57+
playKillSound: true
58+
);
59+
60+
NecromancerRole.RevivedPlayers.Remove(local.PlayerId);
61+
}
62+
}
63+
}

NewMod/Buttons/WraithCaller/CallWraith.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected override void OnClick()
8585
player =>
8686
{
8787
menu.Close();
88-
WraithCallerUtilities.RpcSummonNPC(PlayerControl.LocalPlayer, player);
88+
WraithCallerUtilities.RpcRequestSummonNPC(PlayerControl.LocalPlayer, player);
8989
SetTimerPaused(false);
9090
});
9191

NewMod/Components/FearPulseArea.cs

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@ namespace NewMod.Components
1313
public class FearPulseArea(IntPtr ptr) : MonoBehaviour(ptr)
1414
{
1515
public byte ownerId;
16-
float _radius, _duration, _speedMul, _t;
16+
17+
float _radius;
18+
float _duration;
19+
float _speedMul;
20+
float _t;
21+
1722
readonly Dictionary<byte, float> _origSpeed = new();
1823
readonly HashSet<byte> _insideNow = new();
24+
1925
public static readonly HashSet<byte> AffectedPlayers = new();
2026
public static readonly HashSet<byte> _speedNotifShown = new();
2127
public static readonly HashSet<byte> _visionNotifShown = new();
28+
2229
public AudioClip _enterClip;
2330
public AudioClip _heartbeatClip;
2431
public bool _pulsingHb;
2532

33+
bool _restored;
34+
2635
public void Init(byte ownerId, float radius, float duration, float speedMul)
2736
{
2837
this.ownerId = ownerId;
@@ -35,6 +44,8 @@ public void Init(byte ownerId, float radius, float duration, float speedMul)
3544

3645
public void Update()
3746
{
47+
if (_restored) return;
48+
3849
_t += Time.deltaTime;
3950
if (_t > _duration)
4051
{
@@ -89,12 +100,13 @@ public void Update()
89100
{
90101
_visionNotifShown.Add(p.PlayerId);
91102
var notif = Helpers.CreateAndShowNotification(
92-
"You have entered the Fear Pulse Area. Your vision is reduced!",
93-
new Color(1f, 0.8f, 0.2f),
94-
spr: NewModAsset.VisionDebuff.LoadAsset()
95-
);
103+
"You have entered the Fear Pulse Area. Your vision is reduced!",
104+
new Color(1f, 0.8f, 0.2f),
105+
spr: NewModAsset.VisionDebuff.LoadAsset()
106+
);
96107
notif.Text.SetOutlineThickness(0.36f);
97108
}
109+
98110
Coroutines.Start(Utils.CoShakeCamera(Camera.main.GetComponent<FollowerCamera>(), 0.5f));
99111
}
100112

@@ -112,40 +124,57 @@ public void Update()
112124
var toRestore = _origSpeed.Keys.Where(id => !_insideNow.Contains(id)).ToList();
113125
foreach (var id in toRestore)
114126
{
115-
var p = Utils.PlayerById(id);
116-
if (p) p.MyPhysics.Speed = _origSpeed[id];
117-
_origSpeed.Remove(id);
127+
RestorePlayer(id);
128+
}
129+
}
130+
}
131+
132+
public void RestorePlayer(byte playerId)
133+
{
134+
if (_origSpeed.TryGetValue(playerId, out var originalSpeed))
135+
{
136+
var p = Utils.PlayerById(playerId);
137+
138+
if (!p.Data.IsDead || !p.Data.Disconnected)
139+
{
140+
p.MyPhysics.Speed = originalSpeed;
118141

119142
if (p.AmOwner)
120143
{
121-
AffectedPlayers.Remove(p.PlayerId);
122144
p.lightSource.lightChild.SetActive(true);
123-
_speedNotifShown.Remove(p.PlayerId);
124-
_visionNotifShown.Remove(p.PlayerId);
125-
Helpers.CreateAndShowNotification("Your vision is restored.", new Color(0.8f, 1f, 0.8f));
145+
146+
Helpers.CreateAndShowNotification(
147+
"Your speed and vision are restored.",
148+
new Color(0.8f, 1f, 0.8f)
149+
);
126150
}
127151
}
152+
153+
_origSpeed.Remove(playerId);
128154
}
155+
156+
AffectedPlayers.Remove(playerId);
157+
_speedNotifShown.Remove(playerId);
158+
_visionNotifShown.Remove(playerId);
129159
}
160+
130161
public void RestoreAll()
131162
{
132-
foreach (var kv in _origSpeed)
163+
if (_restored) return;
164+
_restored = true;
165+
166+
var ids = _origSpeed.Keys.ToList();
167+
foreach (var id in ids)
133168
{
134-
var p = Utils.PlayerById(kv.Key);
135-
if (p) p.MyPhysics.Speed = kv.Value;
169+
RestorePlayer(id);
136170
}
137-
_origSpeed.Clear();
138-
AffectedPlayers.Clear();
139-
140-
var lp = PlayerControl.LocalPlayer;
141-
142-
if (AffectedPlayers.Contains(lp.PlayerId))
143-
AffectedPlayers.Remove(lp.PlayerId);
144171

145-
lp.lightSource.lightChild.SetActive(true);
172+
_insideNow.Clear();
173+
}
146174

147-
_speedNotifShown.Remove(lp.PlayerId);
148-
_visionNotifShown.Remove(lp.PlayerId);
175+
public void OnDestroy()
176+
{
177+
RestoreAll();
149178
}
150179
}
151-
}
180+
}

0 commit comments

Comments
 (0)