Skip to content

Commit

Permalink
Add StickyBomber first cooldown option, fix trigger both cooldown, fi…
Browse files Browse the repository at this point in the history
…x unwanted comportment when stuck player is killed before explosion
  • Loading branch information
EnoPM committed Oct 7, 2023
1 parent ba53261 commit 32e74e6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 26 deletions.
52 changes: 48 additions & 4 deletions BetterOtherRoles/BetterOtherRoles.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using HarmonyLib;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BetterOtherRoles.Objects;
Expand Down Expand Up @@ -1895,22 +1896,65 @@ public static void GiveBomb(byte playerId)
{
StuckPlayer = null;
if (Player != PlayerControl.LocalPlayer) return;
HudManagerStartPatch.stickyBomberButton.isEffectActive = false;
HudManagerStartPatch.stickyBomberButton.HasEffect = false;
HudManagerStartPatch.stickyBomberButton.Timer = HudManagerStartPatch.stickyBomberButton.MaxTimer;
if (!TriggerBothCooldown) return;
var killCooldown = GameOptionsManager.Instance.currentNormalGameOptions.KillCooldown;
HudManager.Instance.KillButton.SetCoolDown(killCooldown, killCooldown);
return;
}

var player = Helpers.playerById(playerId);
if (player == null) return;
RemainingDelay = StuckPlayer == null ? FirstDelay : OtherDelay;
if (StuckPlayer == null)
{
RemainingTime = Duration;
if (TriggerBothCooldown && Player == CachedPlayer.LocalPlayer.PlayerControl)
{
Player.killTimer = Duration + 1f;
}
}
StuckPlayer = player;
}

public static IEnumerator CoCreateBomb()
{
var timer = 0f;
while (timer <= Duration)
{
timer += Time.deltaTime;
if (StuckPlayer && StuckPlayer.Data.IsDead)
{
System.Console.WriteLine($"Stuck player is dead");
RpcGiveBomb(byte.MaxValue);
if (HudManagerStartPatch.stickyBomberButton != null)
{
HudManagerStartPatch.stickyBomberButton.HasEffect = false;
HudManagerStartPatch.stickyBomberButton.Timer = 0.5f;
}

if (TriggerBothCooldown)
{
Player.killTimer = 0.5f;
}
break;
}
yield return new WaitForEndOfFrame();
}
if (!Player || !StuckPlayer) yield break;
var killAttempt = Helpers.checkMurderAttemptAndKill(Player, StuckPlayer, showAnimation: false);
if (killAttempt == MurderAttemptResult.PerformKill)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId, (byte)CustomRPC.ShareGhostInfo, Hazel.SendOption.Reliable, -1);
writer.Write(CachedPlayer.LocalPlayer.PlayerId);
writer.Write((byte)RPCProcedure.GhostInfoTypes.DeathReasonAndKiller);
writer.Write(StuckPlayer.PlayerId);
writer.Write((byte)DeadPlayer.CustomDeathReason.StickyBomb);
writer.Write(Player.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
GameHistory.overrideDeathReasonAndKiller(StuckPlayer, DeadPlayer.CustomDeathReason.StickyBomb, killer: StickyBomber.Player);

}
RpcGiveBomb(byte.MaxValue);
}
}

// Modifier
Expand Down
25 changes: 3 additions & 22 deletions BetterOtherRoles/Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using BetterOtherRoles.Objects;
using System.Linq;
using System.Collections.Generic;
using BepInEx.Unity.IL2CPP.Utils;
using BetterOtherRoles.Players;
using BetterOtherRoles.Utilities;
using BetterOtherRoles.CustomGameModes;
Expand Down Expand Up @@ -93,6 +94,7 @@ private static void SetFirstCooldowns()
witchSpellButton.Timer = CustomOptionHolder.witchFirstCooldown.getFloat();
arsonistButton.Timer = CustomOptionHolder.arsonistFirstCooldown.getFloat();
warlockCurseButton.Timer = CustomOptionHolder.warlockFirstCooldown.getFloat();
stickyBomberButton.Timer = CustomOptionHolder.StickyBomberFirstCooldown.getFloat();
}

public static void setCustomButtonCooldowns() {
Expand Down Expand Up @@ -2085,28 +2087,7 @@ public static void createButtonsPostfix(HudManager __instance) {
StickyBomber.RpcGiveBomb(StickyBomber.CurrentTarget.PlayerId);
SoundEffectsManager.play("trapperTrap");
stickyBomberButton.HasEffect = true;
__instance.StartCoroutine(Effects.Lerp(StickyBomber.Duration,
new Action<float>(
p =>
{
if (p != 1f) return;
if (StickyBomber.Player == null || StickyBomber.Player.Data.IsDead || StickyBomber.StuckPlayer == null || StickyBomber.StuckPlayer.Data.IsDead) return;
var killAttempt = Helpers.checkMurderAttemptAndKill(StickyBomber.Player, StickyBomber.StuckPlayer, showAnimation: false);
if (killAttempt == MurderAttemptResult.PerformKill)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(CachedPlayer.LocalPlayer.PlayerControl.NetId, (byte)CustomRPC.ShareGhostInfo, Hazel.SendOption.Reliable, -1);
writer.Write(CachedPlayer.LocalPlayer.PlayerId);
writer.Write((byte)RPCProcedure.GhostInfoTypes.DeathReasonAndKiller);
writer.Write(StickyBomber.StuckPlayer.PlayerId);
writer.Write((byte)DeadPlayer.CustomDeathReason.StickyBomb);
writer.Write(StickyBomber.Player.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
GameHistory.overrideDeathReasonAndKiller(StickyBomber.StuckPlayer, DeadPlayer.CustomDeathReason.StickyBomb, killer: StickyBomber.Player);

}
StickyBomber.RpcGiveBomb(byte.MaxValue);

})));
__instance.StartCoroutine(StickyBomber.CoCreateBomb());
} else if (murder == MurderAttemptResult.BlankKill)
{
stickyBomberButton.HasEffect = false;
Expand Down
2 changes: 2 additions & 0 deletions BetterOtherRoles/CustomOptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public class CustomOptionHolder {

public static CustomOption StickyBomberSpawnRate;
public static CustomOption StickyBomberCooldown;
public static CustomOption StickyBomberFirstCooldown;
public static CustomOption StickyBomberFirstDelay;
public static CustomOption StickyBomberOtherDelay;
public static CustomOption StickyBomberDuration;
Expand Down Expand Up @@ -512,6 +513,7 @@ public static void Load() {

StickyBomberSpawnRate = CustomOption.Create(5021, Types.Impostor, cs(StickyBomber.Color, "Sticky Bomber"), rates, null, true);
StickyBomberCooldown = CustomOption.Create(5022, Types.Impostor, "Sticky Bomb Cooldown", 15f, 2.5f, 30f, 2.5f, StickyBomberSpawnRate, suffix: "s");
StickyBomberFirstCooldown = CustomOption.Create(5031, Types.Impostor, "Sticky Bomb First Cooldown", 15f, 2.5f, 30f, 2.5f, StickyBomberSpawnRate, suffix: "s");
StickyBomberFirstDelay = CustomOption.Create(5023, Types.Impostor, "Sticky Bomb First Delay", 5f, 0f, 20f, 1f, StickyBomberSpawnRate, suffix: "s");
StickyBomberOtherDelay = CustomOption.Create(5024, Types.Impostor, "Sticky Bomb Other Delay", 5f, 0f, 20f, 1f, StickyBomberSpawnRate, suffix: "s");
StickyBomberDuration = CustomOption.Create(5025, Types.Impostor, "Sticky Bomb Timer", 30f, 5f, 60f, 2.5f, StickyBomberSpawnRate, suffix: "s");
Expand Down
8 changes: 8 additions & 0 deletions BetterOtherRoles/Patches/PlayerControlPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,14 @@ public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)]PlayerC
// Witch Button Sync
if (Witch.triggerBothCooldowns && Witch.witch != null && CachedPlayer.LocalPlayer.PlayerControl == Witch.witch && __instance == Witch.witch && HudManagerStartPatch.witchSpellButton != null)
HudManagerStartPatch.witchSpellButton.Timer = HudManagerStartPatch.witchSpellButton.MaxTimer;

// Sticky Bomber Button Sync
if (StickyBomber.TriggerBothCooldown && StickyBomber.Player != null &&
CachedPlayer.LocalPlayer.PlayerControl == StickyBomber.Player && __instance == StickyBomber.Player &&
HudManagerStartPatch.stickyBomberButton != null)
{
HudManagerStartPatch.stickyBomberButton.Timer = HudManagerStartPatch.stickyBomberButton.MaxTimer;
}

// Warlock Button Sync
if (Warlock.warlock != null && CachedPlayer.LocalPlayer.PlayerControl == Warlock.warlock && __instance == Warlock.warlock && HudManagerStartPatch.warlockCurseButton != null) {
Expand Down

0 comments on commit 32e74e6

Please sign in to comment.