Ejemplo n.º 1
0
        public static void MakeButtons(HudManager hm)
        {
            // Bomber button
            bomberButton = new CustomButton(
                // OnClick
                () =>
            {
                if (currentTarget != null)
                {
                    tmpTarget = currentTarget;
                    bomberButton.HasEffect = true;
                }
            },
                // HasButton
                () => { return(PlayerControl.LocalPlayer.isRole(RoleType.BomberB) && PlayerControl.LocalPlayer.isAlive() && BomberA.isAlive()); },
                // CouldUse
                () =>
            {
                if (bomberButton.isEffectActive && tmpTarget != currentTarget)
                {
                    tmpTarget                   = null;
                    bomberButton.Timer          = 0f;
                    bomberButton.isEffectActive = false;
                }

                return(PlayerControl.LocalPlayer.CanMove && currentTarget != null);
            },
                // OnMeetingEnds
                () =>
            {
                bomberButton.Timer          = bomberButton.MaxTimer;
                bomberButton.isEffectActive = false;
                tmpTarget = null;
            },
                getBomberButtonSprite(),
                new Vector3(-1.8f, -0.06f, 0),
                hm,
                hm.KillButton,
                KeyCode.F,
                true,
                duration,
                // OnEffectsEnd
                () =>
            {
                if (tmpTarget != null)
                {
                    MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlantBomb, Hazel.SendOption.Reliable, -1);
                    writer.Write(tmpTarget.PlayerId);
                    AmongUsClient.Instance.FinishRpcImmediately(writer);
                    BomberB.bombTarget = tmpTarget;
                }

                tmpTarget          = null;
                bomberButton.Timer = bomberButton.MaxTimer;
            }
                );
            bomberButton.buttonText = ModTranslation.getString("bomberPlantBomb");
            // Bomber button
            releaseButton = new CustomButton(
                // OnClick
                () =>
            {
                var bomberA    = BomberA.allPlayers.FirstOrDefault();
                float distance = Vector2.Distance(PlayerControl.LocalPlayer.transform.localPosition, bomberA.transform.localPosition);

                if (PlayerControl.LocalPlayer.CanMove && BomberA.bombTarget != null && BomberB.bombTarget != null && bomberA.isAlive() && distance < 1)
                {
                    var target           = BomberB.bombTarget;
                    MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ReleaseBomb, Hazel.SendOption.Reliable, -1);
                    writer.Write(PlayerControl.LocalPlayer.PlayerId);
                    writer.Write(target.PlayerId);
                    AmongUsClient.Instance.FinishRpcImmediately(writer);
                    RPCProcedure.releaseBomb(PlayerControl.LocalPlayer.PlayerId, target.PlayerId);
                }
            },
                // HasButton
                () => { return(PlayerControl.LocalPlayer.isRole(RoleType.BomberB) && PlayerControl.LocalPlayer.isAlive() && BomberA.isAlive()); },
                // CouldUse
                () =>
            {
                var bomberA    = BomberA.allPlayers.FirstOrDefault();
                float distance = Vector2.Distance(PlayerControl.LocalPlayer.transform.localPosition, bomberA.transform.localPosition);

                return(PlayerControl.LocalPlayer.CanMove && BomberA.bombTarget != null && BomberB.bombTarget != null && bomberA.isAlive() && distance < 1);
            },
                // OnMeetingEnds
                () =>
            {
                releaseButton.Timer = releaseButton.MaxTimer;
            },
                getReleaseButtonSprite(),
                new Vector3(-2.7f, -0.06f, 0),
                hm,
                hm.KillButton,
                KeyCode.F,
                false
                );
            releaseButton.buttonText = ModTranslation.getString("bomberDetonate");
        }