コード例 #1
0
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            CSPlayer csPlayer = CSPlayer.Get(player);

            if (args.Length == 0)
            {
                Main.NewTextMultiline(Usage, c: Color.Red);
                return;
            }

            args[0] = args[0].ToLower();

            if (args[0].Equals("-a"))
            {
                List <string> ammo = new List <string>();

                foreach (GunDefinition gun in csPlayer.OwnedAmmo())
                {
                    ammo.Add($"{gun.UnlocalizedName}:{csPlayer.GetAmmo(gun)}");
                }
            }
            else
            {
                GunDefinition definition = GunDefinitions.Instance.FindGeneric(g => g.UnlocalizedName.Equals(args[0], StringComparison.CurrentCultureIgnoreCase));

                if (definition == default)
                {
                    Main.NewText($"Specified gun `{args[0]}` doesn't exist.", Color.Red);
                    return;
                }

                Main.NewText($"{definition.UnlocalizedName}:{csPlayer.GetAmmo(definition)}");
            }
        }
コード例 #2
0
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            if (args.Length == 0)
            {
                Main.NewText(Usage, Color.Red);
                return;
            }


            GunDefinition definition = GunDefinitions.Instance.FindGeneric(g => g.UnlocalizedName.Equals(args[0], StringComparison.CurrentCultureIgnoreCase));

            if (definition == default)
            {
                Main.NewText($"Gun name '{args[0]} is invalid. Use /cs_guns for a list of guns.");
                return;
            }


            CSPlayer csPlayer = CSPlayer.Get(player);

            if (csPlayer.Money < definition.Price)
            {
                Main.NewText($"Specified gun '{args[0]}' is too costly. Use /cs_guns -a for a list of guns you can buy.");
                return;
            }


            csPlayer.TryBuyGun(definition);
        }
コード例 #3
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            var display = OptionName;

            if (Gun != default)
            {
                var csPlayer    = CSPlayer.Get();
                var playerMoney = csPlayer.Money;

                if (playerMoney < Gun.Price)
                {
                    display += $" ({playerMoney} / {Gun.Price} $)";
                }

                csPlayer.GetAmmoCost(Gun, out var buyable, out var cost);

                if (cost > 0)
                {
                    display += $" (r: {(int)Math.Ceiling(cost)} for {buyable})";
                }
            }


            DrawBorderedRectangle(this.GetDimensions().Position(), (int)this.Width.Pixels, (int)this.Height.Pixels, IsMouseHovering ? Color.Red * 0.5f : Color.Black * 0.5f, Color.Orange, spriteBatch);
            spriteBatch.DrawString(Main.fontMouseText, display, this.GetDimensions().Position() + new Vector2(6, this.Height.Pixels - 28), Color.Orange);

            var mousePosition = new Vector2((float)Main.mouseX, (float)Main.mouseY);

            if (this.ContainsPoint(mousePosition))
            {
                Main.LocalPlayer.mouseInterface = true;
            }
        }
コード例 #4
0
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            CSPlayer csPlayer = CSPlayer.Get(player);

            Color textColor = csPlayer.Money > 0 ? Color.Green : csPlayer.Money == 0 ? Color.White : Color.Red;

            Main.NewText("Current money: " + csPlayer.Money, textColor);
        }
コード例 #5
0
        public override void NPCLoot(NPC npc)
        {
            if (npc.lastInteraction == 255)
            {
                return;
            }

            CSPlayer.Get(npc.lastInteraction).OnKillNPC(npc);
        }
コード例 #6
0
        public override void HoldItem(Player player)
        {
            CSPlayer csPlayer = CSPlayer.Get(player);

            if (Definition.CanBeMounted && csPlayer.GunMounted)
            {
                player.maxRunSpeed = 0;
                player.velocity    = Vector2.Zero;
            }
        }
コード例 #7
0
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            CSPlayer csPlayer = CSPlayer.Get(player);

            Vector2 unaccurateSpeed = new Vector2(speedX, speedY).RotatedByRandom(
                (1 - csPlayer.AccuracyFactor) * MathHelper.ToRadians((1 - Definition.GetAccuracy(csPlayer)) * Constants.MAX_SPREAD));

            speedX = unaccurateSpeed.X;
            speedY = unaccurateSpeed.Y;

            csPlayer.AccuracyFactor += Definition.GetAccuracyChangePerShot(csPlayer);

            csPlayer.ConsumeAmmo(Definition, 1);

            return(true);
        }
コード例 #8
0
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            CSPlayer csPlayer = CSPlayer.Get(player);

            if (args.Length == 0)
            {
                return;
            }

            if (!int.TryParse(args[0], out int money))
            {
                return;
            }

            csPlayer.ModifyMoney(money);
        }
コード例 #9
0
        public override bool CanUseItem(Player player)
        {
            CSPlayer csPlayer = CSPlayer.Get(player);

            if (player.altFunctionUse == ItemAlternativeFunctionID.ActivatedAndUsed)
            {
                if (Main.mouseRightRelease)
                {
                    csPlayer.ToggleMount();
                    CombatText.NewText(new Rectangle((int)player.Center.X, (int)player.Center.Y, 0, 0), Color.Red, csPlayer.GunMounted ? "Mounted" : "Dismounted");
                }

                return(false);
            }

            return(csPlayer.HasAmmo(Definition) && !csPlayer.Reloading);
        }
コード例 #10
0
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            if (!(player.HeldItem?.modItem is GunItem gun))
            {
                Main.NewText("You must be holding a gun to refill ammo!", Color.Yellow);
                return;
            }

            var csPlayer = CSPlayer.Get(player);

            if (!csPlayer.TryFillAmmo(gun.Definition))
            {
                Main.NewText($"Couldn't buy ammo for this {gun.Definition.UnlocalizedName}.", Color.DarkRed);
            }
            else
            {
                Main.NewText("Ammo refilled!", Color.DarkGreen);
            }
        }
コード例 #11
0
        protected override void ActionLocal(CommandCaller caller, Player player, string input, string[] args)
        {
            List <string> guns = new List <string>();

            CSPlayer csPlayer = CSPlayer.Get(player);

            if (args.Length == 0)
            {
                GunDefinitions.Instance.ForAllGeneric(g => guns.Add(g.UnlocalizedName));
            }

            else if (args[0].Equals("-a", StringComparison.CurrentCultureIgnoreCase))
            {
                GunDefinitions.Instance.ForAllGeneric(g =>
                {
                    if (g.Price <= csPlayer.Money)
                    {
                        guns.Add(g.UnlocalizedName);
                    }
                });
            }

            Main.NewText(string.Join(", ", guns));
        }
コード例 #12
0
 public override void Click(UIMouseEvent evt)
 {
     CSPlayer.Get().UIBuyGun(Gun);
 }
コード例 #13
0
        public override void ModifyTooltips(List <TooltipLine> tooltips)
        {
            var player = CSPlayer.Get();

            tooltips.Add(new TooltipLine(mod, "cs_ammo_avail", $"{player.GetAmmo(Definition)} / {Definition.MagazineSize}, max of {player.GetMaxClips(Definition)} clips"));
        }