////

        /// <summary>
        /// Interrupts any reloading of a player's currently-held gun.
        /// </summary>
        /// <param name="plr"></param>
        public void StopReloading(Player plr, TheMadRangerItem mygun)
        {
            mygun.CloseCylinder(plr);

            this.ReloadDuration  = 0;
            this.ReloadingRounds = false;
        }
 public TheMadRangerRecipe(TheMadRangerItem myitem) : base(TMRMod.Instance)
 {
     this.AddIngredient(ItemID.IllegalGunParts, 1);
     this.AddIngredient(ItemID.SilverBar, 15);
     this.AddIngredient(ItemID.SuspiciousLookingEye, 1);
     this.AddTile(TileID.WorkBenches);
     this.SetResult(myitem);
 }
        ////////////////

        private void UpdateReloadingSequence(Player plr)
        {
            // Not reloading
            if (this.ReloadDuration == 0)
            {
                return;
            }

            // Reloading timer
            if (this.ReloadDuration > 1)
            {
                this.ReloadDuration--;
                return;
            }

            // No item to reload
            var mygun = plr.HeldItem?.modItem as TheMadRangerItem;

            if (mygun == null)
            {
                return;
            }

            var config = TMRConfig.Instance;

            // Not yet loading rounds
            if (!this.ReloadingRounds)
            {
                // Start loading rounds, if cylinder empty
                if (!mygun.IsCylinderEmpty())
                {
                    (int Shells, int Rounds)unloadings = mygun.UnloadCylinder(plr);
                    this.ProcessUnloadedGunRounds(plr, unloadings.Shells, unloadings.Rounds);
                }
                this.ReloadDuration  = config.Get <int>(nameof(TMRConfig.ReloadRoundTickDuration));
                this.ReloadingRounds = true;
                return;
            }

            // No ammo source; stop reloading
            if (!TheMadRangerItem.IsAmmoSourceAvailable(plr, false, out string result))
            {
                Main.NewText(result, Color.Yellow);
                this.StopReloading(plr, mygun);
                return;
            }

            // Reload rounds until not possible
            if (mygun.InsertSpeedloader(plr) || mygun.InsertRound(plr))
            {
                this.ReloadDuration = config.Get <int>(nameof(TMRConfig.ReloadRoundTickDuration));
                return;
            }

            this.StopReloading(plr, mygun);
            return;
        }
        ////////////////

        public bool AttemptReload(Player player)
        {
            int    plrWho = player.whoAmI;
            string result;

            bool Reload()
            {
                Player plr = Main.player[plrWho];

                if (!TheMadRangerItem.IsAmmoSourceAvailable(plr, true, out result))
                {
                    Main.NewText(result, Color.Yellow);
                    return(false);
                }

                this.LoadedRounds = TheMadRangerItem.CylinderCapacity;
                return(true);
            }

            //

            if (!TheMadRangerItem.IsAmmoSourceAvailable(player, true, out result))
            {
                Main.NewText(result, Color.Yellow);
                return(false);
            }

            var myplayer = player.GetModPlayer <TMRPlayer>();

            if (myplayer.GunHandling.IsAnimating)
            {
                return(false);
            }

            string timerName = SpeedloaderItem.GetReloadingTimerName(plrWho);

            if (Timers.GetTimerTickDuration(timerName) > 0)
            {
                return(false);
            }

            SoundLibraries.PlaySound(TMRMod.Instance, "RevolverReloadBegin", player.Center, 0.5f);

            int duration = TMRConfig.Instance.Get <int>(nameof(TMRConfig.SpeedloaderLoadTickDuration));

            Timers.SetTimer(timerName, duration, false, () => {
                Reload();
                return(false);
            });

            return(true);
        }
        /// <summary>
        /// Begins a gun holstering sequence. Currently ignores all other sequences (needs testing).
        /// </summary>
        /// <param name="plr"></param>
        /// <param name="mygun"></param>
        public void BeginHolster(Player plr, TheMadRangerItem mygun)
        {
            this.HolsterDuration = TMRConfig.Instance.Get <int>(nameof(TMRConfig.HolsterTwirlTickDuration));

            this.IsQuickDrawReady = true;

            if (this.HolsterDuration == 0)
            {
                return;
            }

            SoundLibraries.PlaySound(TMRMod.Instance, "RevolverTwirl", plr.Center, 0.65f);
        }
        /// <summary>
        /// Begins a gun reload sequence, if the gun or player allows. Not synced.
        /// </summary>
        /// <param name="plr"></param>
        /// <param name="mygun"></param>
        /// <returns></returns>
        public bool BeginReload(Player plr, TheMadRangerItem mygun)
        {
            if (this.IsReloading)
            {
                return(false);
            }

            if (SpeedloaderItem.IsReloading(plr.whoAmI))
            {
                return(false);
            }

            if (mygun.IsCylinderFull())
            {
                return(false);
            }

            mygun.OpenCylinder(plr);
            this.ReloadDuration = TMRConfig.Instance.Get <int>(nameof(TMRConfig.ReloadInitTickDuration));

            this.IsQuickDrawReady = true;

            return(true);
        }