Exemple #1
0
        public static MurderAttemptResult checkMuderAttemptAndKill(PlayerControl killer, PlayerControl target, bool isMeetingStart = false, bool showAnimation = true)
        {
            // The local player checks for the validity of the kill and performs it afterwards (different to vanilla, where the host performs all the checks)
            // The kill attempt will be shared using a custom RPC, hence combining modded and unmodded versions is impossible

            MurderAttemptResult murder = checkMuderAttempt(killer, target, isMeetingStart);

            if (murder == MurderAttemptResult.PerformKill)
            {
                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.UncheckedMurderPlayer, Hazel.SendOption.Reliable, -1);
                writer.Write(killer.PlayerId);
                writer.Write(target.PlayerId);
                writer.Write(showAnimation ? Byte.MaxValue : 0);
                AmongUsClient.Instance.FinishRpcImmediately(writer);
                RPCProcedure.uncheckedMurderPlayer(killer.PlayerId, target.PlayerId, showAnimation ? Byte.MaxValue : (byte)0);
            }
            return(murder);
        }
            public static bool Prefix(KillButton __instance)
            {
                if (__instance.isActiveAndEnabled && __instance.currentTarget && !__instance.isCoolingDown && PlayerControl.LocalPlayer.isAlive() && PlayerControl.LocalPlayer.CanMove)
                {
                    bool showAnimation = true;
                    if (PlayerControl.LocalPlayer.isRole(RoleType.Ninja) && Ninja.isStealthed(PlayerControl.LocalPlayer))
                    {
                        showAnimation = false;
                    }

                    // Use an unchecked kill command, to allow shorter kill cooldowns etc. without getting kicked
                    MurderAttemptResult res = Helpers.checkMuderAttemptAndKill(PlayerControl.LocalPlayer, __instance.currentTarget, showAnimation: showAnimation);
                    // Handle blank kill
                    if (res == MurderAttemptResult.BlankKill)
                    {
                        PlayerControl.LocalPlayer.killTimer = PlayerControl.GameOptions.KillCooldown;
                        if (PlayerControl.LocalPlayer == Cleaner.cleaner)
                        {
                            Cleaner.cleaner.killTimer = HudManagerStartPatch.cleanerCleanButton.Timer = HudManagerStartPatch.cleanerCleanButton.MaxTimer;
                        }
                        else if (PlayerControl.LocalPlayer == Warlock.warlock)
                        {
                            Warlock.warlock.killTimer = HudManagerStartPatch.warlockCurseButton.Timer = HudManagerStartPatch.warlockCurseButton.MaxTimer;
                        }
                        else if (PlayerControl.LocalPlayer.hasModifier(ModifierType.Mini) && PlayerControl.LocalPlayer.Data.Role.IsImpostor)
                        {
                            PlayerControl.LocalPlayer.SetKillTimer(PlayerControl.GameOptions.KillCooldown * (Mini.isGrownUp(PlayerControl.LocalPlayer) ? 0.66f : 2f));
                        }
                        else if (PlayerControl.LocalPlayer == Witch.witch)
                        {
                            Witch.witch.killTimer = HudManagerStartPatch.witchSpellButton.Timer = HudManagerStartPatch.witchSpellButton.MaxTimer;
                        }
                        else if (PlayerControl.LocalPlayer == Assassin.assassin)
                        {
                            Assassin.assassin.killTimer = HudManagerStartPatch.assassinButton.Timer = HudManagerStartPatch.assassinButton.MaxTimer;
                        }
                    }

                    __instance.SetTarget(null);
                }
                return(false);
            }
Exemple #3
0
        public static void MakeButtons(HudManager hm)
        {
            // Sheriff Kill
            sheriffKillButton = new CustomButton(
                () =>
            {
                if (local.numShots <= 0)
                {
                    return;
                }

                MurderAttemptResult murderAttemptResult = Helpers.checkMuderAttempt(PlayerControl.LocalPlayer, local.currentTarget);
                if (murderAttemptResult == MurderAttemptResult.SuppressKill)
                {
                    return;
                }

                if (murderAttemptResult == MurderAttemptResult.PerformKill)
                {
                    bool misfire  = false;
                    byte targetId = local.currentTarget.PlayerId;;
                    if ((local.currentTarget.Data.Role.IsImpostor && (!local.currentTarget.hasModifier(ModifierType.Mini) || Mini.isGrownUp(local.currentTarget))) ||
                        (Sheriff.spyCanDieToSheriff && Spy.spy == local.currentTarget) ||
                        (Sheriff.madmateCanDieToSheriff && local.currentTarget.hasModifier(ModifierType.Madmate)) ||
                        (Sheriff.createdMadmateCanDieToSheriff && local.currentTarget.hasModifier(ModifierType.CreatedMadmate)) ||
                        (Sheriff.canKillNeutrals && local.currentTarget.isNeutral()) ||
                        (Jackal.jackal == local.currentTarget || Sidekick.sidekick == local.currentTarget))
                    {
                        //targetId = Sheriff.currentTarget.PlayerId;
                        misfire = false;
                    }
                    else
                    {
                        //targetId = PlayerControl.LocalPlayer.PlayerId;
                        misfire = true;
                    }

                    // Mad sheriff always misfires.
                    if (local.player.hasModifier(ModifierType.Madmate))
                    {
                        misfire = true;
                    }
                    MessageWriter killWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SheriffKill, Hazel.SendOption.Reliable, -1);
                    killWriter.Write(PlayerControl.LocalPlayer.Data.PlayerId);
                    killWriter.Write(targetId);
                    killWriter.Write(misfire);
                    AmongUsClient.Instance.FinishRpcImmediately(killWriter);
                    RPCProcedure.sheriffKill(PlayerControl.LocalPlayer.Data.PlayerId, targetId, misfire);
                }

                sheriffKillButton.Timer = sheriffKillButton.MaxTimer;
                local.currentTarget     = null;
            },
                () => { return(PlayerControl.LocalPlayer.isRole(RoleType.Sheriff) && local.numShots > 0 && !PlayerControl.LocalPlayer.Data.IsDead && local.canKill); },
                () =>
            {
                if (sheriffNumShotsText != null)
                {
                    if (local.numShots > 0)
                    {
                        sheriffNumShotsText.text = String.Format(ModTranslation.getString("sheriffShots"), local.numShots);
                    }
                    else
                    {
                        sheriffNumShotsText.text = "";
                    }
                }
                return(local.currentTarget && PlayerControl.LocalPlayer.CanMove);
            },
                () => { sheriffKillButton.Timer = sheriffKillButton.MaxTimer; },
                hm.KillButton.graphic.sprite,
                new Vector3(0f, 1f, 0),
                hm,
                hm.KillButton,
                KeyCode.Q
                );

            sheriffNumShotsText      = GameObject.Instantiate(sheriffKillButton.actionButton.cooldownTimerText, sheriffKillButton.actionButton.cooldownTimerText.transform.parent);
            sheriffNumShotsText.text = "";
            sheriffNumShotsText.enableWordWrapping       = false;
            sheriffNumShotsText.transform.localScale     = Vector3.one * 0.5f;
            sheriffNumShotsText.transform.localPosition += new Vector3(-0.05f, 0.7f, 0);
        }