Skip to content

Commit

Permalink
Finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardel-DW committed May 6, 2021
1 parent b7f541c commit d1268c7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
32 changes: 26 additions & 6 deletions PatateChaude/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HarmonyLib;
using Hazel;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace PatateChaud {
Expand All @@ -17,15 +18,14 @@ public static void Postfix(HudManager __instance) {
button = new CooldownButton
(() => OnClick(),
HotPatatoes.HotPatatoesCooldwon.GetValue(),
Plugin.LoadSpriteFromEmbeddedResources("RolesMods.Resources.potato.png", 16f),
Plugin.LoadSpriteFromEmbeddedResources("PatateChaude.Resources.potato.png", 16f),
250,
new Vector2(0f, 0f),
__instance,
() => OnUpdate(button)
);
}


private static void OnClick() {
if (allPlayersTargetable == null)
return;
Expand All @@ -42,7 +42,7 @@ private static void OnUpdate(CooldownButton button) {
button.SetCanUse(!MeetingHud.Instance);

if (allPlayersTargetable != null) {
PlayerControl target = PlayerControlUtils.GetClosestPlayer(PlayerControl.LocalPlayer, allPlayersTargetable);
PlayerControl target = PlayerControlUtils.GetClosestPlayer(PlayerControl.LocalPlayer, allPlayersTargetable, 1f);
if (closestPlayer != null) {
button.isDisable = false;
closestPlayer.myRend.material.SetFloat("_Outline", 0f);
Expand All @@ -58,14 +58,34 @@ private static void OnUpdate(CooldownButton button) {
closestPlayer = null;
}
}
} else {
button.SetCanUse(false);
}

if (closestPlayer != null && !HotPatatoes.Instance.HasRole(PlayerControl.LocalPlayer)) {
closestPlayer.myRend.material.SetFloat("_Outline", 0f);
closestPlayer = null;
}
} else {
button.SetCanUse(false);
}
}

private static void RpcSendPatatoes() {
MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.SendPatato, SendOption.Reliable, -1);
messageWriter.Write(closestPlayer.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
if (closestPlayer != null) {
Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();
if (HotPatatoes.DontParent.GetValue())
Button.allPlayersTargetable.RemovePlayer(closestPlayer);

HotPatatoes.Instance.AllPlayers = new List<PlayerControl>() { closestPlayer };
HotPatatoes.Instance.DefineVisibleByWhitelist();

MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.SendPatato, SendOption.Reliable, -1);
messageWriter.Write(closestPlayer.PlayerId);
messageWriter.Write(PlayerControl.LocalPlayer.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(messageWriter);
}

}
}
}
10 changes: 6 additions & 4 deletions PatateChaude/HandleRpcPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ class HandleRpcPatch {
public static bool Prefix([HarmonyArgument(0)] byte callId, [HarmonyArgument(1)] MessageReader reader) {
if (callId == (byte) CustomRPC.SendPatato) {
PlayerControl player = PlayerControlUtils.FromPlayerId(reader.ReadByte());
PlayerControl parent = PlayerControlUtils.FromPlayerId(reader.ReadByte());

if (player != null) {
Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();
Button.allPlayersTargetable.RemovePlayer(player);
HotPatatoes.Instance.AllPlayers = new System.Collections.Generic.List<PlayerControl>();
HotPatatoes.Instance.AllPlayers.Add(PlayerControlUtils.FromPlayerId(reader.ReadByte()));
if (HotPatatoes.DontParent.GetValue())
Button.allPlayersTargetable.RemovePlayer(parent);

HotPatatoes.Instance.AllPlayers = new System.Collections.Generic.List<PlayerControl>() { player };
HotPatatoes.Instance.DefineVisibleByWhitelist();
}

return false;
}

Expand Down
27 changes: 24 additions & 3 deletions PatateChaude/HotPatatoes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Essentials.Options;
using HardelAPI.CustomRoles;
using HardelAPI.Enumerations;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

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

public HotPatatoes() : base() {
GameOptionFormat();
Side = PlayerSide.Everyone;
LooseRole = true;
RoleActive = true;
ForceExiledReveal = true;
GiveTasksAt = Moment.Never;
Expand All @@ -31,16 +32,36 @@ public override void OnInfectedStart() {
PercentApparition = (int) HotPatatoesPercent.GetValue();
}

public override void OnUpdate(PlayerControl Player) {
if (Player.PlayerId == PlayerControl.LocalPlayer.PlayerId) {
if (Player.Data.IsImpostor)
Color = Palette.ImpostorRed;
else
Color = Palette.White;
}
}

public override void OnGameStarted() {
PatateChaud.Button.button.MaxTimer = (int) HotPatatoesCooldwon.GetValue();
PatateChaud.Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();
}

public override void OnPlayerDisconnect(PlayerControl Player) {
if (HasRole(Player)) {
List<PlayerControl> users = PlayerControl.AllPlayerControls.ToArray().ToList().Where(p => !p.Data.IsDead && !p.Data.Disconnected).ToList();
PlayerControl newUsers = users[new System.Random().Next(users.Count)];
PatateChaud.Button.allPlayersTargetable = PlayerControl.AllPlayerControls.ToArray().ToList();

Instance.AllPlayers = new List<PlayerControl>() { newUsers };
Instance.DefineVisibleByWhitelist();
}
}

private void GameOptionFormat() {
HotPatatoesHeader.HudStringFormat = (option, name, value) => $"\n{name}";

HotPatatoesPercent.ValueStringFormat = (option, value) => $"{value}%";
HotPatatoesCooldwon.ValueStringFormat = (option, value) => $"{value}s";
TimeBeforeApparition.ValueStringFormat = (option, value) => $"{value}s";
}
}
}

0 comments on commit d1268c7

Please sign in to comment.