Skip to content

Commit d1268c7

Browse files
committed
Finish
1 parent b7f541c commit d1268c7

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

PatateChaude/Button.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using HarmonyLib;
44
using Hazel;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using UnityEngine;
78

89
namespace PatateChaud {
@@ -17,15 +18,14 @@ public static void Postfix(HudManager __instance) {
1718
button = new CooldownButton
1819
(() => OnClick(),
1920
HotPatatoes.HotPatatoesCooldwon.GetValue(),
20-
Plugin.LoadSpriteFromEmbeddedResources("RolesMods.Resources.potato.png", 16f),
21+
Plugin.LoadSpriteFromEmbeddedResources("PatateChaude.Resources.potato.png", 16f),
2122
250,
2223
new Vector2(0f, 0f),
2324
__instance,
2425
() => OnUpdate(button)
2526
);
2627
}
2728

28-
2929
private static void OnClick() {
3030
if (allPlayersTargetable == null)
3131
return;
@@ -42,7 +42,7 @@ private static void OnUpdate(CooldownButton button) {
4242
button.SetCanUse(!MeetingHud.Instance);
4343

4444
if (allPlayersTargetable != null) {
45-
PlayerControl target = PlayerControlUtils.GetClosestPlayer(PlayerControl.LocalPlayer, allPlayersTargetable);
45+
PlayerControl target = PlayerControlUtils.GetClosestPlayer(PlayerControl.LocalPlayer, allPlayersTargetable, 1f);
4646
if (closestPlayer != null) {
4747
button.isDisable = false;
4848
closestPlayer.myRend.material.SetFloat("_Outline", 0f);
@@ -58,14 +58,34 @@ private static void OnUpdate(CooldownButton button) {
5858
closestPlayer = null;
5959
}
6060
}
61+
} else {
62+
button.SetCanUse(false);
63+
}
64+
65+
if (closestPlayer != null && !HotPatatoes.Instance.HasRole(PlayerControl.LocalPlayer)) {
66+
closestPlayer.myRend.material.SetFloat("_Outline", 0f);
67+
closestPlayer = null;
6168
}
69+
} else {
70+
button.SetCanUse(false);
6271
}
6372
}
6473

6574
private static void RpcSendPatatoes() {
66-
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.SendPatato, SendOption.Reliable, -1);
67-
messageWriter.Write(closestPlayer.PlayerId);
68-
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
75+
if (closestPlayer != null) {
76+
Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();
77+
if (HotPatatoes.DontParent.GetValue())
78+
Button.allPlayersTargetable.RemovePlayer(closestPlayer);
79+
80+
HotPatatoes.Instance.AllPlayers = new List<PlayerControl>() { closestPlayer };
81+
HotPatatoes.Instance.DefineVisibleByWhitelist();
82+
83+
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.SendPatato, SendOption.Reliable, -1);
84+
messageWriter.Write(closestPlayer.PlayerId);
85+
messageWriter.Write(PlayerControl.LocalPlayer.PlayerId);
86+
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
87+
}
88+
6989
}
7090
}
7191
}

PatateChaude/HandleRpcPatch.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ class HandleRpcPatch {
1111
public static bool Prefix([HarmonyArgument(0)] byte callId, [HarmonyArgument(1)] MessageReader reader) {
1212
if (callId == (byte) CustomRPC.SendPatato) {
1313
PlayerControl player = PlayerControlUtils.FromPlayerId(reader.ReadByte());
14+
PlayerControl parent = PlayerControlUtils.FromPlayerId(reader.ReadByte());
1415

1516
if (player != null) {
1617
Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();
17-
Button.allPlayersTargetable.RemovePlayer(player);
18-
HotPatatoes.Instance.AllPlayers = new System.Collections.Generic.List<PlayerControl>();
19-
HotPatatoes.Instance.AllPlayers.Add(PlayerControlUtils.FromPlayerId(reader.ReadByte()));
18+
if (HotPatatoes.DontParent.GetValue())
19+
Button.allPlayersTargetable.RemovePlayer(parent);
20+
21+
HotPatatoes.Instance.AllPlayers = new System.Collections.Generic.List<PlayerControl>() { player };
22+
HotPatatoes.Instance.DefineVisibleByWhitelist();
2023
}
21-
2224
return false;
2325
}
2426

PatateChaude/HotPatatoes.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Essentials.Options;
22
using HardelAPI.CustomRoles;
33
using HardelAPI.Enumerations;
4+
using System.Collections.Generic;
45
using System.Linq;
56
using UnityEngine;
67

@@ -12,12 +13,12 @@ public class HotPatatoes : CustomRole<HotPatatoes> {
1213
public static CustomOptionHeader HotPatatoesHeader = CustomOptionHeader.AddHeader("<color=#f5d142ff>Hot Patatoes Options :</color>");
1314
public static CustomNumberOption HotPatatoesPercent = CustomOption.AddNumber("Hot Patatoes Apparition", 0f, 0f, 100f, 5f);
1415
public static CustomNumberOption HotPatatoesCooldwon = CustomOption.AddNumber("Hot Patatoes Apparition", 30f, 10f, 120f, 5f);
15-
public static CustomNumberOption TimeBeforeApparition = CustomOption.AddNumber("Time Before First Apparition", 30f, 10f, 120f, 5f);
16-
public static CustomToggleOption DontParent = CustomOption.AddToggle("Don't give the patato to parent", true);
16+
public static CustomToggleOption DontParent = CustomOption.AddToggle("Dont give the patato to parent", true);
1717

1818
public HotPatatoes() : base() {
1919
GameOptionFormat();
2020
Side = PlayerSide.Everyone;
21+
LooseRole = true;
2122
RoleActive = true;
2223
ForceExiledReveal = true;
2324
GiveTasksAt = Moment.Never;
@@ -31,16 +32,36 @@ public override void OnInfectedStart() {
3132
PercentApparition = (int) HotPatatoesPercent.GetValue();
3233
}
3334

35+
public override void OnUpdate(PlayerControl Player) {
36+
if (Player.PlayerId == PlayerControl.LocalPlayer.PlayerId) {
37+
if (Player.Data.IsImpostor)
38+
Color = Palette.ImpostorRed;
39+
else
40+
Color = Palette.White;
41+
}
42+
}
43+
3444
public override void OnGameStarted() {
45+
PatateChaud.Button.button.MaxTimer = (int) HotPatatoesCooldwon.GetValue();
3546
PatateChaud.Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();
3647
}
3748

49+
public override void OnPlayerDisconnect(PlayerControl Player) {
50+
if (HasRole(Player)) {
51+
List<PlayerControl> users = PlayerControl.AllPlayerControls.ToArray().ToList().Where(p => !p.Data.IsDead && !p.Data.Disconnected).ToList();
52+
PlayerControl newUsers = users[new System.Random().Next(users.Count)];
53+
PatateChaud.Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();
54+
55+
Instance.AllPlayers = new List<PlayerControl>() { newUsers };
56+
Instance.DefineVisibleByWhitelist();
57+
}
58+
}
59+
3860
private void GameOptionFormat() {
3961
HotPatatoesHeader.HudStringFormat = (option, name, value) => $"\n{name}";
4062

4163
HotPatatoesPercent.ValueStringFormat = (option, value) => $"{value}%";
4264
HotPatatoesCooldwon.ValueStringFormat = (option, value) => $"{value}s";
43-
TimeBeforeApparition.ValueStringFormat = (option, value) => $"{value}s";
4465
}
4566
}
4667
}

0 commit comments

Comments
 (0)