Exemplo n.º 1
0
        //TODO there is some null ref exception thrown in this Postfix everytime the game starts (only after the first game)
        static void Postfix(HudManager __instance)
        {
            if (IsCultistUsed && __instance != null)
            {
                if (AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started &&
                    __instance.KillButton != null)
                {
                    if (!PlayerControl.LocalPlayer.Data.IsImpostor && Input.GetKeyDown(KeyCode.Q) && !lastQ)
                    {
                        KillButtonPatch.Prefix();
                    }

                    lastQ      = Input.GetKeyUp(KeyCode.Q);
                    KillButton = __instance.KillButton;
                    PlayerTools.closestPlayer = PlayerTools.getClosestPlayer(PlayerControl.LocalPlayer);
                    DistLocalClosest          =
                        PlayerTools.getDistBetweenPlayers(PlayerControl.LocalPlayer, PlayerTools.closestPlayer);

                    if (InitialCultist.PlayerId == PlayerControl.LocalPlayer.PlayerId && ConversionsLeft <= 0)
                    {
                        KillButton.gameObject.SetActive(false);
                        KillButton.isActive = false;
                    }

                    else if (InitialCultist.PlayerId == PlayerControl.LocalPlayer.PlayerId &&
                             __instance.UseButton.isActiveAndEnabled)
                    {
                        KillButton.gameObject.SetActive(true);
                        KillButton.isActive = true;
                        KillButton.SetCoolDown(PlayerTools.GetConversionCooldown(),
                                               PlayerControl.GameOptions.KillCooldown + 15.0f);
                        KillButton.renderer.sprite = convertIcon;
                        KillButton.renderer.color  = Palette.EnabledColor;
                        KillButton.renderer.material.SetFloat("_Desat", 0f);

                        if (DistLocalClosest < GameOptionsData.KillDistances[PlayerControl.GameOptions.KillDistance])
                        {
                            KillButton.SetTarget(PlayerTools.closestPlayer);
                            CurrentTarget = PlayerTools.closestPlayer;
                        }
                        else
                        {
                            KillButton.SetTarget(null);
                            CurrentTarget = null;
                        }
                    }


                    // adds purple color during the game and meetings depending on settings
                    if (IsCultist(PlayerControl.LocalPlayer.PlayerId))
                    {
                        PlayerControl.LocalPlayer.nameText.Color = CultistColor;
                        var isLocalCultLeader = PlayerControl.LocalPlayer.PlayerId == InitialCultist.PlayerId;

                        foreach (var player in PlayerControl.AllPlayerControls)
                        {
                            if (((CultistsKnowEachOther || isLocalCultLeader) && IsCultist(player.PlayerId)) ||
                                player.PlayerId == InitialCultist.PlayerId)
                            {
                                player.nameText.Color = CultistColor;
                            }
                        }

                        if (MeetingHud.Instance != null)
                        {
                            foreach (PlayerVoteArea player in MeetingHud.Instance.playerStates)
                            {
                                if ((player.TargetPlayerId == PlayerControl.LocalPlayer.PlayerId) ||
                                    (player.NameText != null && InitialCultist.PlayerId == player.TargetPlayerId) ||
                                    ((CultistsKnowEachOther || isLocalCultLeader) &&
                                     IsCultist((byte)player.TargetPlayerId)))
                                {
                                    player.NameText.Color = CultistColor;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static bool Prefix()
        {
            if (PlayerControl.LocalPlayer.Data.IsDead)
            {
                return(false);
            }

            if (PlayerControl.LocalPlayer.Data.IsImpostor)
            {
                return(true);
            }

            if (IsCultistUsed && CurrentTarget != null && !PlayerControl.LocalPlayer.Data.IsImpostor)
            {
                PlayerControl target = CurrentTarget;

                if (PlayerControl.LocalPlayer == InitialCultist && PlayerTools.GetConversionCooldown() == 0)
                {
                    bool createNewTask = false;
                    var  player        = PlayerControl.LocalPlayer;
                    CLog.Info("CULTIST TRYING TO CONVERT!");
                    CLog.Info("Target is Impostor:" + target.Data.IsImpostor);
                    CLog.Info("Target is Cultist:" + IsCultist(target.PlayerId));

                    if (!target.Data.IsImpostor && !IsCultist(target.PlayerId))
                    {
                        if (ConversionsLeft > 0)
                        {
                            MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(
                                PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ConvertAction, Hazel.SendOption.None,
                                -1);
                            writer.Write(PlayerControl.LocalPlayer.PlayerId);
                            writer.Write(target.PlayerId);
                            AmongUsClient.Instance.FinishRpcImmediately(writer);
                            AddCultistToLists(target);
                            ConversionsLeft--;
                            LastConversion = DateTime.UtcNow;

                            if (CheckCultistWin())
                            {
                                ExecuteCultistWin();
                            }

                            var tasksToRemove = new List <PlayerTask>();
                            foreach (var task in target.myTasks)
                            {
                                if (task.TaskType != TaskTypes.FixComms && task.TaskType != TaskTypes.FixLights &&
                                    task.TaskType != TaskTypes.ResetReactor &&
                                    task.TaskType != TaskTypes.ResetSeismic && task.TaskType != TaskTypes.RestoreOxy)
                                {
                                    tasksToRemove.Add(task);
                                }
                            }

                            foreach (var taskToRemove in tasksToRemove)
                            {
                                player.RemoveTask(taskToRemove);
                            }

                            target.myTasks.Clear();
                            CLog.Info("Done with removing tasks for target!");

                            createNewTask = true;
                        }
                    }

                    if (target.Data.IsImpostor)
                    {
                        LastConversion = DateTime.UtcNow;
                        if (ImpostorConversionAttemptUsesConversion)
                        {
                            if (ConversionsLeft > 0)
                            {
                                ConversionsLeft--;
                                createNewTask = true;
                            }
                        }
                    }

                    if (createNewTask)
                    {
                        MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(
                            PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ConversionsLeft, Hazel.SendOption.None,
                            -1);
                        writer.Write(ConversionsLeft);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);


                        ImportantTextTask cultLeaderTask =
                            new GameObject("CultistLeaderTask").AddComponent <ImportantTextTask>();
                        cultLeaderTask.transform.SetParent(player.transform, false);

                        cultLeaderTask.Text =
                            "You are the cult leader.\nConvert crewmates to your cult.\nConversions left: " +
                            ConversionsLeft + "/" + MaxCultistConversions;
                        player.myTasks.Clear();
                        player.myTasks.Insert(0, cultLeaderTask);
                    }

                    return(false);
                }
            }

            return(true);
        }