コード例 #1
0
        ////////////////

        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);
        }
コード例 #2
0
        public override bool PreDrawInInventory(
            SpriteBatch spriteBatch,
            Vector2 position,
            Rectangle frame,
            Color drawColor,
            Color itemColor,
            Vector2 origin,
            float scale)
        {
            Texture2D tex = Main.itemTexture[this.item.type];

            if (this.LoadedRounds > 0)
            {
                tex = ModContent.GetTexture(this.Texture);
            }

            spriteBatch.Draw(tex, position, frame, drawColor, 0f, origin, scale, SpriteEffects.None, 0f);
            if (this.item.color != Color.Transparent)
            {
                spriteBatch.Draw(tex, position, frame, itemColor, 0f, origin, scale, SpriteEffects.None, 0f);
            }

            if (SpeedloaderItem.IsReloading(Main.myPlayer))
            {
                Vector2 overlayPos = position;
                overlayPos.X += tex.Width / 2;
                overlayPos.Y += tex.Height / 2;
                overlayPos.Y += 6;
                Vector2 overlayDim = Main.fontMouseText.MeasureString("X");

                spriteBatch.DrawString(
                    spriteFont: Main.fontMouseText,
                    text: "X",
                    position: overlayPos,
                    color: AnimatedColors.Alert.CurrentColor,
                    rotation: 0f,
                    origin: overlayDim * 0.5f,
                    scale: 2f,
                    effects: SpriteEffects.None,
                    layerDepth: 0f
                    );
            }

            return(false);
        }
コード例 #3
0
        ////

        public static bool IsReloading(int plrWho)
        {
            string timerName = SpeedloaderItem.GetReloadingTimerName(plrWho);

            return(Timers.GetTimerTickDuration(timerName) > 0);
        }