using System; using System.Collections.Generic; using UnityEngine; namespace EHR; internal static class DoubleTrigger { public static Dictionary FirstTriggerTimer = []; public static Dictionary FirstTriggerTarget = []; public static Dictionary FirstTriggerAction = []; public static void Init() { FirstTriggerTimer = []; FirstTriggerAction = []; } /// /// Checks for whether the killer pressed their kill button twice on the same player /// /// Who the killer is /// Who the killer is targeting with the kill button /// The action that should be done if the killer only presses their kill button once /// Whether the Action should be done or not /// /// Returns true if the kill button is clicked twice within 1 second. Otherwise, does the Action specified in the /// parameter firstAction and returns false /// public static bool CheckDoubleTrigger(this PlayerControl killer, PlayerControl target, Action firstAction, bool doAction = true) { if (FirstTriggerTimer.ContainsKey(killer.PlayerId)) { if (FirstTriggerTarget[killer.PlayerId] != target.PlayerId) { // If the second target is off target, single action on the first opponent. return false; } Logger.Info($"{killer.name} - Do Double Action", "DoubleTrigger"); FirstTriggerTimer.Remove(killer.PlayerId); FirstTriggerTarget.Remove(killer.PlayerId); if (doAction) FirstTriggerAction.Remove(killer.PlayerId); return true; } // Ignore the kill interval during single action CheckMurderPatch.TimeSinceLastKill.Remove(killer.PlayerId); FirstTriggerTimer.Add(killer.PlayerId, 1f); FirstTriggerTarget.Add(killer.PlayerId, target.PlayerId); if (doAction) FirstTriggerAction.Add(killer.PlayerId, firstAction); return false; } public static void OnFixedUpdate(PlayerControl player) { if (!GameStates.IsInTask) { FirstTriggerTimer.Clear(); FirstTriggerTarget.Clear(); FirstTriggerAction.Clear(); return; } byte playerId = player.PlayerId; if (!FirstTriggerTimer.ContainsKey(playerId)) return; FirstTriggerTimer[playerId] -= Time.fixedDeltaTime; if (FirstTriggerTimer[playerId] <= 0) { Logger.Info($"{player.name} - Do Single Action", "DoubleTrigger"); if (FirstTriggerAction.ContainsKey(playerId)) FirstTriggerAction[playerId](); FirstTriggerTimer.Remove(playerId); FirstTriggerTarget.Remove(playerId); FirstTriggerAction.Remove(playerId); } } }