public static bool Prefix()
        {
            if (PlayerControl.LocalPlayer.isPlayerRole("Engineer"))
            {
                DestroyableSingleton <HudManager> .Instance.ShowMap((Action <MapBehaviour>) delegate(MapBehaviour m)
                {
                    m.ShowInfectedMap();
                    m.ColorControl.baseColor = Main.Logic.sabotageActive ? Color.gray : Main.Palette.engineerColor;
                });

                return(false);
            }

            if (PlayerControl.LocalPlayer.Data.IsDead)
            {
                return(false);
            }

            MessageWriter writer;

            if (CurrentTarget != null)
            {
                var target = CurrentTarget;
                //code that handles the ability button presses
                if (PlayerControl.LocalPlayer.isPlayerRole("Officer"))
                {
                    if (PlayerTools.getOfficerCD() != 0)
                    {
                        return(false);
                    }

                    var isPlayerJokerAndCanDieToOfficer =
                        Main.Config.jokerCanDieToOfficer && target.isPlayerRole("Joker");

                    writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                        (byte)CustomRPC.OfficerKill, Hazel.SendOption.None, -1);
                    writer.Write(PlayerControl.LocalPlayer.PlayerId);
                    writer.Write(!target.isPlayerImmortal() &&
                                 (isPlayerJokerAndCanDieToOfficer || target.Data.IsImpostor) ?
                                 target.PlayerId : PlayerControl.LocalPlayer.PlayerId); // kill target or suicide
                    AmongUsClient.Instance.FinishRpcImmediately(writer);
                    PlayerControl.LocalPlayer.MurderPlayer(target);
                    PlayerControl.LocalPlayer.getModdedControl().LastAbilityTime = DateTime.UtcNow;

                    // attempted to kill shielded player
                    if (target.isPlayerImmortal())
                    {
                        writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                            (byte)CustomRPC.AttemptSound, Hazel.SendOption.None, -1);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);
                        BreakShield(false);
                    }

                    return(false);
                }

                if (PlayerControl.LocalPlayer.isPlayerRole("Medic"))
                {
                    writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                        (byte)CustomRPC.SetProtected, Hazel.SendOption.None, -1);
                    target.getModdedControl().Immortal = true;
                    PlayerControl.LocalPlayer.getModdedControl().UsedAbility = true;
                    writer.Write(target.PlayerId);
                    AmongUsClient.Instance.FinishRpcImmediately(writer);
                    return(false);
                }
            }

            // continue the murder as normal
            if (!KillButton.CurrentTarget.isPlayerImmortal())
            {
                return(true);
            }

            // play shield break sound
            var shouldPlayShieldBreakSound = KillButton.CurrentTarget.isPlayerImmortal() &&
                                             KillButton.isActiveAndEnabled &&
                                             !KillButton.isCoolingDown && Main.Config.shieldKillAttemptIndicator;

            if (!shouldPlayShieldBreakSound)
            {
                return(false);
            }

            writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                (byte)CustomRPC.AttemptSound, Hazel.SendOption.None, -1);
            AmongUsClient.Instance.FinishRpcImmediately(writer);
            BreakShield(false);

            return(false);
        }
        public static bool Prefix()
        {
            if (PlayerControl.LocalPlayer.isPlayerRole(Role.Engineer))
            {
                DestroyableSingleton <HudManager> .Instance.ShowMap((Action <MapBehaviour>) delegate(MapBehaviour m)
                {
                    m.ShowInfectedMap();
                    m.ColorControl.baseColor = Main.Logic.sabotageActive ? Color.gray : Main.Palette.engineerColor;
                });

                return(false);
            }

            if (PlayerControl.LocalPlayer.Data.IsDead)
            {
                return(false);
            }

            if (CurrentTarget != null)
            {
                var target = CurrentTarget;
                //code that handles the ability button presses
                if (PlayerControl.LocalPlayer.isPlayerRole(Role.Officer))
                {
                    if (PlayerTools.getOfficerCD() > 0)
                    {
                        return(false);
                    }

                    var isTargetJoker      = target.isPlayerRole(Role.Joker);
                    var isTargetImpostor   = target.Data.IsImpostor;
                    var officerKillSetting = Main.Config.officerKillBehaviour;
                    if (target.isPlayerImmortal())
                    {
                        if (Main.Config.officerShouldDieToShieldedPlayers)
                        {
                            // suicide packet
                            SendOfficerKillRpc(PlayerControl.LocalPlayer);
                        }
                        BreakShield(false);
                    }
                    else if (officerKillSetting == OfficerKillBehaviour.OfficerSurvives || // don't care who it is, kill them
                             isTargetImpostor || // impostors always die
                             (officerKillSetting != OfficerKillBehaviour.Impostor && isTargetJoker)) // joker can die and target is joker
                    {
                        // kill target
                        SendOfficerKillRpc(target);
                    }
                    else // officer dies
                    {
                        if (officerKillSetting == OfficerKillBehaviour.CrewDie)
                        {
                            // kill target too
                            SendOfficerKillRpc(target);
                        }
                        // kill officer
                        SendOfficerKillRpc(PlayerControl.LocalPlayer);
                    }

                    return(false);
                }

                if (PlayerControl.LocalPlayer.isPlayerRole(Role.Medic))
                {
                    WriteGiveShieldRpc(target);
                    return(false);
                }
            }

            // continue the murder as normal
            if (!KillButton.CurrentTarget.isPlayerImmortal())
            {
                return(true);
            }

            // play shield break sound
            var shouldPlayShieldBreakSound = KillButton.CurrentTarget.isPlayerImmortal() &&
                                             KillButton.isActiveAndEnabled &&
                                             !KillButton.isCoolingDown && Main.Config.shieldKillAttemptIndicator;

            if (!shouldPlayShieldBreakSound)
            {
                return(false);
            }

            // Send Play Shield Break RPC
            Rpc <AttemptKillShieldedPlayerRpc> .Instance.Send(data : PlayerControl.LocalPlayer.PlayerId, immediately : true);

            return(false);
        }
        static void Postfix(HudManager __instance)
        {
            if (AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started)
            {
                return;
            }

            foreach (var player in PlayerControl.AllPlayerControls)
            {
                if (player.Data.PlayerName != "Hunter")
                {
                    continue;
                }

                if (!defaultSet)
                {
                    System.Console.Write(currentColor);
                    defaultSet = true;
                    player.myRend.material.SetColor("_BackColor", colors[currentColor]);
                    player.myRend.material.SetColor("_BodyColor", colors[currentColor]);
                    newColor = colors[currentColor];
                    if (currentColor + 1 >= colors.Length)
                    {
                        currentColor = -1;
                    }
                    nextColor = colors[currentColor + 1];
                }

                newColor = VecToColor(Vector3.MoveTowards(ColorToVec(newColor), ColorToVec(nextColor), 0.02f));
                player.myRend.material.SetColor("_BackColor", newColor);
                player.myRend.material.SetColor("_BodyColor", newColor);

                if (newColor != nextColor)
                {
                    continue;
                }

                currentColor++;
                defaultSet = false;
            }

            lastQ      = Input.GetKeyUp(KeyCode.Q);
            KillButton = __instance.KillButton;
            var target = PlayerControl.LocalPlayer.FindClosestPlayer();

            if (!PlayerControl.LocalPlayer.Data.IsImpostor && Input.GetKeyDown(KeyCode.Q) && !lastQ && __instance.UseButton.isActiveAndEnabled)
            {
                PerformKillPatch.Prefix(KillButton);
            }

            if (PlayerControl.LocalPlayer.isPlayerRole(Role.Engineer) && __instance.UseButton.isActiveAndEnabled)
            {
                KillButton.gameObject.SetActive(true);
                KillButton.isActive = true;
                KillButton.SetCoolDown(0f, 1f);
                KillButton.renderer.sprite = Main.Assets.repairIco;
                KillButton.renderer.color  = Palette.EnabledColor;
                KillButton.renderer.material.SetFloat("_Desat", 0f);
            }

            Main.Logic.clearJokerTasks();
            if (rend != null)
            {
                rend.SetActive(false);
            }

            var sabotageActive = false;

            foreach (var task in PlayerControl.LocalPlayer.myTasks)
            {
                if (PlayerTools.sabotageTasks.Contains(task.TaskType))
                {
                    sabotageActive = true;
                }
            }
            Main.Logic.sabotageActive = sabotageActive;

            if (Main.Logic.getImmortalPlayer() != null && Main.Logic.getImmortalPlayer().PlayerControl.Data.IsDead)
            {
                BreakShield(true);
            }
            if (Main.Logic.getImmortalPlayer() != null && Main.Logic.getRolePlayer(Role.Medic) != null &&
                Main.Logic.getRolePlayer(Role.Medic).PlayerControl.Data.IsDead)
            {
                BreakShield(true);
            }
            if (Main.Logic.getRolePlayer(Role.Medic) == null && Main.Logic.getImmortalPlayer() != null)
            {
                BreakShield(true);
            }

            // TODO: this list could maybe find a better place?
            //       It is only meant for looping through role "name", "color" and "show" simultaneously
            var roles = new List <(Role roleName, Color roleColor, bool showRole)>()
            {
                (Role.Medic, Main.Palette.medicColor, Main.Config.showMedic),
                (Role.Officer, Main.Palette.officerColor, Main.Config.showOfficer),
                (Role.Engineer, Main.Palette.engineerColor, Main.Config.showEngineer),
                (Role.Joker, Main.Palette.jokerColor, Main.Config.showJoker),
            };

            // Color of imposters and crewmates
            foreach (var player in PlayerControl.AllPlayerControls)
            {
                player.nameText.Color = player.Data.IsImpostor && (PlayerControl.LocalPlayer.Data.IsImpostor || PlayerControl.LocalPlayer.Data.IsDead)
                    ? Color.red
                    : Color.white;
            }

            // Color of roles (always see yourself, and depending on setting, others may see the role too)
            foreach (var(roleName, roleColor, showRole) in roles)
            {
                var role = Main.Logic.getRolePlayer(roleName);
                if (role == null)
                {
                    continue;
                }
                if (PlayerControl.LocalPlayer.isPlayerRole(roleName) || showRole || PlayerControl.LocalPlayer.Data.IsDead)
                {
                    role.PlayerControl.nameText.Color = roleColor;
                }
            }

            //Color of name plates in the voting hub should be the same as in-game
            if (MeetingHud.Instance != null)
            {
                foreach (var playerVoteArea in MeetingHud.Instance.playerStates)
                {
                    if (playerVoteArea.NameText == null)
                    {
                        continue;
                    }

                    var player = PlayerTools.getPlayerById((byte)playerVoteArea.TargetPlayerId);
                    playerVoteArea.NameText.Color = player.nameText.Color;
                }
            }

            if (Main.Logic.anyPlayerImmortal())
            {
                var showShielded   = Main.Config.showProtected;
                var shieldedPlayer = Main.Logic.getImmortalPlayer().PlayerControl;
                if (showShielded == (int)ShieldOptions.Everyone)
                {
                    GiveShieldedPlayerShield(shieldedPlayer);
                }
                else if (PlayerControl.LocalPlayer.isPlayerImmortal() && (showShielded == (int)ShieldOptions.Self || showShielded == (int)ShieldOptions.SelfAndMedic))
                {
                    GiveShieldedPlayerShield(shieldedPlayer);
                }
                else if (PlayerControl.LocalPlayer.isPlayerRole(Role.Medic) &&
                         (showShielded == (int)ShieldOptions.Medic || showShielded == (int)ShieldOptions.SelfAndMedic))
                {
                    GiveShieldedPlayerShield(shieldedPlayer);
                }
            }

            if (PlayerControl.LocalPlayer.Data.IsDead)
            {
                if (!PlayerControl.LocalPlayer.isPlayerRole(Role.Engineer))
                {
                    KillButton.gameObject.SetActive(false);
                    KillButton.renderer.enabled = false;
                    KillButton.isActive         = false;
                    KillButton.SetTarget(null);
                    KillButton.enabled = false;
                    return;
                }
            }

            if (__instance.UseButton != null && PlayerControl.LocalPlayer.isPlayerRole(Role.Medic) &&
                __instance.UseButton.isActiveAndEnabled)
            {
                KillButton.renderer.sprite = Main.Assets.shieldIco;
                KillButton.gameObject.SetActive(true);
                KillButton.isActive = true;
                KillButton.SetCoolDown(0f, 1f);
                KillButton.SetTarget(target);
            }

            if (__instance.UseButton != null && PlayerControl.LocalPlayer.isPlayerRole(Role.Officer) &&
                __instance.UseButton.isActiveAndEnabled)
            {
                KillButton.gameObject.SetActive(true);
                KillButton.isActive = true;
                KillButton.SetCoolDown(PlayerTools.getOfficerCD(), PlayerControl.GameOptions.KillCooldown + 15.0f);
                KillButton.SetTarget(target);
            }
        }
Exemple #4
0
        public static bool Prefix()
        {
            if (PlayerControl.LocalPlayer.isPlayerRole("Engineer"))
            {
                DestroyableSingleton <HudManager> .Instance.ShowMap((Action <MapBehaviour>) delegate(MapBehaviour m)
                {
                    m.ShowInfectedMap();
                    m.ColorControl.baseColor = Main.Logic.sabotageActive ? Color.gray : Main.Palette.engineerColor;
                });

                return(false);
            }

            if (PlayerControl.LocalPlayer.Data.IsDead)
            {
                return(false);
            }

            if (CurrentTarget != null)
            {
                var target = CurrentTarget;
                //code that handles the ability button presses
                if (PlayerControl.LocalPlayer.isPlayerRole("Officer"))
                {
                    if (PlayerTools.getOfficerCD() > 0)
                    {
                        return(false);
                    }

                    var isTargetJoker      = target.isPlayerRole("Joker");
                    var isTargetImpostor   = target.Data.IsImpostor;
                    var officerKillSetting = Main.Config.officerKillBehaviour;
                    if (target.isPlayerImmortal())
                    {
                        // suicide packet
                        WriteKillRpc(PlayerControl.LocalPlayer, PlayerControl.LocalPlayer);
                        BreakShield(false);
                    }
                    else if (officerKillSetting == OfficerKillBehaviour.OfficerSurvives || // don't care who it is, kill them
                             isTargetImpostor || // impostors always die
                             officerKillSetting == OfficerKillBehaviour.Joker && isTargetJoker) // joker can die and target is joker
                    {
                        // kill target
                        WriteKillRpc(PlayerControl.LocalPlayer, target);
                    }
                    else // officer dies
                    {
                        if (officerKillSetting == OfficerKillBehaviour.CrewDie)
                        {
                            // kill target too
                            WriteKillRpc(PlayerControl.LocalPlayer, target);
                        }
                        // kill officer
                        WriteKillRpc(PlayerControl.LocalPlayer, PlayerControl.LocalPlayer);
                    }

                    return(false);
                }

                if (PlayerControl.LocalPlayer.isPlayerRole("Medic"))
                {
                    WriteGiveShieldRpc(PlayerControl.LocalPlayer, target);
                    return(false);
                }
            }

            // continue the murder as normal
            if (!KillButton.CurrentTarget.isPlayerImmortal())
            {
                return(true);
            }

            // play shield break sound
            var shouldPlayShieldBreakSound = KillButton.CurrentTarget.isPlayerImmortal() &&
                                             KillButton.isActiveAndEnabled &&
                                             !KillButton.isCoolingDown && Main.Config.shieldKillAttemptIndicator;

            if (!shouldPlayShieldBreakSound)
            {
                return(false);
            }

            // Send Play Shield Break RPC
            MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                              (byte)CustomRPC.AttemptSound, Hazel.SendOption.None, -1);

            AmongUsClient.Instance.FinishRpcImmediately(writer);
            BreakShield(false);

            return(false);
        }