using System;
using System.Windows.Forms;
using GTA;

namespace handgun
{

    public class handgun : Script
    {

        bool onoff = true,animated = false;
        AnimationSet armsup = new AnimationSet("cover_l_high_corner");
        AnimationFlags animflags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09 | AnimationFlags.Unknown06;

        public handgun()
        {
            this.Tick += new EventHandler(this.ArmsOnUp);
            BindKey(Settings.GetValueKey("TURNOFF-ON", "SETTINGS", Keys.I), new KeyPressDelegate(TurnONOFF));
            Interval = Settings.GetValueInteger("INTERVAL", "SETTINGS", 20);
            
        }
        private void ArmsOnUp(object sender, EventArgs e)
        {
            if
                ((onoff == true) &&
                Player.Character.isAlive &&
                Player.Character.isIdle &&
                !Player.Character.isInVehicle() &&
                !Player.Character.isGettingUp &&
                !Player.Character.isShooting &&
                !Player.Character.isRagdoll &&
                !Player.Character.isInMeleeCombat &&
                !Player.Character.isGettingIntoAVehicle &&
                !Player.Character.isInCombat &&
                !Player.Character.isOnFire &&
                !Player.Character.isInWater &&
                !(GTA.Game.isGameKeyPressed(GameKey.Aim)) &&
                !(GTA.Native.Function.Call<bool>("IS_CHAR_SHOOTING",Player.Character)))
            {
                    if ((Player.Character.Weapons.CurrentType == Weapon.Handgun_Glock) ||
                     (Player.Character.Weapons.CurrentType == Weapon.Handgun_DesertEagle) ||
                     (Player.Character.Weapons.CurrentType == Weapon.TBOGT_Pistol44) ||
                     (Player.Character.Weapons.CurrentType == Weapon.TLAD_Automatic9mm))
                        {
                        GTA.Native.Function.Call("REQUEST_ANIMS", "cover_l_high_corner");
                        Player.Character.Task.PlayAnimation(armsup, "lowerhalf_fire", 2.00F, animflags);
                        Player.Character.Task.AlwaysKeepTask = false;
                        
                        }
                        else
                        {
                            Player.Character.Task.ClearSecondary();
                            animated = true;
                        }
            }
            else if ((animated==true) || ((GTA.Game.isGameKeyPressed(GameKey.Aim))) || (GTA.Game.isGameKeyPressed(GameKey.Jump)) || (GTA.Game.isGameKeyPressed(GameKey.Attack)))
                    {
                        Player.Character.Task.ClearSecondary();
                        GTA.Native.Function.Call("REMOVE_ANIMS", "cover_l_high_corner");
                            animated = false;
                            Player.CanControlCharacter = true;
                    }
        }
        private void TurnONOFF()
        {
            if (onoff)
            {
                onoff = false;
                Game.DisplayText("handgun Mod OFF");
            }
            else
            {
                onoff = true;
                Game.DisplayText("handgun Mod ON");
            }
        }
}
}
