From 7f52cde68be4f6f81419d5bc3f6932f34e534356 Mon Sep 17 00:00:00 2001 From: Jbro129 Date: Wed, 7 Apr 2021 12:57:43 -0400 Subject: [PATCH 1/2] Update CustomItems.cs Added option for random values and for defined colors. --- CustomItems.cs | 460 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 430 insertions(+), 30 deletions(-) diff --git a/CustomItems.cs b/CustomItems.cs index 3defec7..e660660 100644 --- a/CustomItems.cs +++ b/CustomItems.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; @@ -32,12 +32,16 @@ protected override void Dispose(bool disposing) { private void OnInitialize(EventArgs args) { Commands.ChatCommands.Add(new Command("customitem", CustomItem, "customitem", "citem") { HelpText = "/customitem <#> ... \nParameters: hexcolor, damage, knockback, useanimation, " + - "usetime, shoot, shootspeed, width, height, scale, ammo, useammo, notammo." + "usetime, shoot, shootspeed, width, height, scale, ammo, useammo, notammo. \n" + + "Random value identifiers: random, rand, and r. \n" + + "Colors: red, blue, green, yellow, orange, black, white, pink, purple, teal, navy, turquoise, indigo, gray, cyan, brown, and beige" }); Commands.ChatCommands.Add(new Command("customitem.give", GiveCustomItem, "givecustomitem", "gcitem") { HelpText = "/givecustomitem <#> ... \nParameters: hexcolor, damage, knockback, useanimation, " + - "usetime, shoot, shootspeed, width, height, scale, ammo, useammo, notammo." + "usetime, shoot, shootspeed, width, height, scale, ammo, useammo, notammo. \n" + + "Random value identifiers: random, rand, and r. \n" + + "Colors: red, blue, green, yellow, orange, black, white, pink, purple, teal, navy, turquoise, indigo, gray, cyan, brown, and beige" }); } @@ -72,56 +76,218 @@ private void CustomItem(CommandArgs args) { switch (param) { case "hexcolor": case "hc": - targetItem.color = new Color(int.Parse(arg.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), + case "color": + + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.color = getRandomColor(); + } + else if (arg.Equals("red")) + { + targetItem.color = Color.Red; + } + else if (arg.Equals("blue")) + { + targetItem.color = Color.Blue; + } + else if (arg.Equals("green")) + { + targetItem.color = Color.Green; + } + else if (arg.Equals("yellow")) + { + targetItem.color = Color.Yellow; + } + else if (arg.Equals("orange")) + { + targetItem.color = Color.Orange; + } + else if (arg.Equals("black")) + { + targetItem.color = Color.Black; + } + else if (arg.Equals("white")) + { + targetItem.color = Color.White; + } + else if (arg.Equals("pink")) + { + targetItem.color = Color.Pink; + } + else if (arg.Equals("purple")) + { + targetItem.color = Color.Purple; + } + else if (arg.Equals("teal")) + { + targetItem.color = Color.Teal; + } + else if (arg.Equals("navy")) + { + targetItem.color = Color.Navy; + } + else if (arg.Equals("turquoise")) + { + targetItem.color = Color.Turquoise; + } + else if (arg.Equals("indigo")) + { + targetItem.color = Color.Indigo; + } + else if (arg.Equals("gray")) + { + targetItem.color = Color.Gray; + } + else if (arg.Equals("cyan")) + { + targetItem.color = Color.Cyan; + } + else if (arg.Equals("brown")) + { + targetItem.color = Color.Brown; + } + else if (arg.Equals("beige")) + { + targetItem.color = Color.Beige; + } + else + { + targetItem.color = new Color(int.Parse(arg.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), int.Parse(arg.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), int.Parse(arg.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)); + } + break; case "damage": case "d": - targetItem.damage = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.damage = genRandom(1, 1000); // damage can range from 1 to 1000 + } + else + { + targetItem.damage = int.Parse(arg); + } break; case "knockback": case "kb": - targetItem.knockBack = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.knockBack = genRandom(1, 100); // knockback can range from 1 to 10 + } + else + { + targetItem.knockBack = int.Parse(arg); + } break; case "useanimation": case "ua": - targetItem.useAnimation = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.useAnimation = genRandom(2, 10); // useanimation can range from 2 to 10 + } + else + { + targetItem.useAnimation = int.Parse(arg); + } break; case "usetime": case "ut": - targetItem.useTime = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.useTime = genRandom(1, 40); // usetime can range from 1 to 40 + } + else + { + targetItem.useTime = int.Parse(arg); + } break; case "shoot": case "s": - targetItem.shoot = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.shoot = genRandom(1, 955); // 650 for 1.3 | 955 for 1.4 + } + else + { + targetItem.shoot = int.Parse(arg); + } break; case "shootspeed": case "ss": - targetItem.shootSpeed = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.shootSpeed = genRandom(1, 50); // shootspeed can range from 1 to 50 + } + else + { + targetItem.shootSpeed = int.Parse(arg); + } break; case "width": case "w": - targetItem.width = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.width = genRandom(1, 255); // width can range from 1 to 255 + } + else + { + targetItem.width = int.Parse(arg); + } break; case "height": case "h": - targetItem.height = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.height = genRandom(1, 255); // height can range from 1 to 255 + } + else + { + targetItem.height = int.Parse(arg); + } break; case "scale": case "sc": - targetItem.scale = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.scale = genRandom(1, 10); // scale can range from 1 to 10 + } + else + { + targetItem.scale = int.Parse(arg); + } break; case "ammo": case "a": - targetItem.ammo = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.ammo = genRandom(0, 10); // ammo can range from 0 to 10 + } + else + { + targetItem.ammo = int.Parse(arg); + } break; case "useammo": - targetItem.useAmmo = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.useAmmo = genRandom(0, 10); + } + else + { + targetItem.useAmmo = int.Parse(arg); + } break; case "notammo": case "na": - targetItem.notAmmo = Boolean.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.notAmmo = Convert.ToBoolean(genRandom(0, 1)); + } + else + { + targetItem.notAmmo = Boolean.Parse(arg); + } break; } } @@ -133,7 +299,7 @@ private void CustomItem(CommandArgs args) { private void GiveCustomItem(CommandArgs args) { List parameters = args.Parameters; - int num = parameters.Count(); + int num = parameters.Counta(); if (num == 0) { args.Player.SendErrorMessage("Invalid Syntax. /givecustomitem <#> ... \nParameters: hexcolor, damage, knockback, useanimation, " + @@ -172,56 +338,218 @@ private void GiveCustomItem(CommandArgs args) { switch (param) { case "hexcolor": case "hc": - targetItem.color = new Color(int.Parse(arg.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), + case "color": + + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.color = getRandomColor(); + } + else if (arg.Equals("red")) + { + targetItem.color = Color.Red; + } + else if (arg.Equals("blue")) + { + targetItem.color = Color.Blue; + } + else if (arg.Equals("green")) + { + targetItem.color = Color.Green; + } + else if (arg.Equals("yellow")) + { + targetItem.color = Color.Yellow; + } + else if (arg.Equals("orange")) + { + targetItem.color = Color.Orange; + } + else if (arg.Equals("black")) + { + targetItem.color = Color.Black; + } + else if (arg.Equals("white")) + { + targetItem.color = Color.White; + } + else if (arg.Equals("pink")) + { + targetItem.color = Color.Pink; + } + else if (arg.Equals("purple")) + { + targetItem.color = Color.Purple; + } + else if (arg.Equals("teal")) + { + targetItem.color = Color.Teal; + } + else if (arg.Equals("navy")) + { + targetItem.color = Color.Navy; + } + else if (arg.Equals("turquoise")) + { + targetItem.color = Color.Turquoise; + } + else if (arg.Equals("indigo")) + { + targetItem.color = Color.Indigo; + } + else if (arg.Equals("gray")) + { + targetItem.color = Color.Gray; + } + else if (arg.Equals("cyan")) + { + targetItem.color = Color.Cyan; + } + else if (arg.Equals("brown")) + { + targetItem.color = Color.Brown; + } + else if (arg.Equals("beige")) + { + targetItem.color = Color.Beige; + } + else + { + targetItem.color = new Color(int.Parse(arg.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), int.Parse(arg.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), int.Parse(arg.Substring(4, 2), System.Globalization.NumberStyles.HexNumber)); + } + break; case "damage": case "d": - targetItem.damage = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.damage = genRandom(1, 1000); // damage can range from 1 to 1000 + } + else + { + targetItem.damage = int.Parse(arg); + } break; case "knockback": case "kb": - targetItem.knockBack = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.knockBack = genRandom(1, 100); // knockback can range from 1 to 10 + } + else + { + targetItem.knockBack = int.Parse(arg); + } break; case "useanimation": case "ua": - targetItem.useAnimation = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.useAnimation = genRandom(2, 10); // useanimation can range from 2 to 10 + } + else + { + targetItem.useAnimation = int.Parse(arg); + } break; case "usetime": case "ut": - targetItem.useTime = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.useTime = genRandom(1, 40); // usetime can range from 1 to 40 + } + else + { + targetItem.useTime = int.Parse(arg); + } break; case "shoot": case "s": - targetItem.shoot = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.shoot = genRandom(1, 955); // 650 for 1.3 | 955 for 1.4 + } + else + { + targetItem.shoot = int.Parse(arg); + } break; case "shootspeed": case "ss": - targetItem.shootSpeed = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.shootSpeed = genRandom(1, 50); // shootspeed can range from 1 to 50 + } + else + { + targetItem.shootSpeed = int.Parse(arg); + } break; case "width": case "w": - targetItem.width = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.width = genRandom(1, 255); // width can range from 1 to 255 + } + else + { + targetItem.width = int.Parse(arg); + } break; case "height": case "h": - targetItem.height = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.height = genRandom(1, 255); // height can range from 1 to 255 + } + else + { + targetItem.height = int.Parse(arg); + } break; case "scale": case "sc": - targetItem.scale = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.scale = genRandom(1, 10); // scale can range from 1 to 10 + } + else + { + targetItem.scale = int.Parse(arg); + } break; case "ammo": case "a": - targetItem.ammo = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.ammo = genRandom(0, 10); // ammo can range from 0 to 10 + } + else + { + targetItem.ammo = int.Parse(arg); + } break; case "useammo": - targetItem.useAmmo = int.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.useAmmo = genRandom(0, 10); + } + else + { + targetItem.useAmmo = int.Parse(arg); + } break; case "notammo": case "na": - targetItem.notAmmo = Boolean.Parse(arg); + if (arg.Equals("random") || arg.Equals("rand") || arg.Equals("r")) + { + targetItem.notAmmo = Convert.ToBoolean(genRandom(0, 1)); + } + else + { + targetItem.notAmmo = Boolean.Parse(arg); + } break; } } @@ -240,5 +568,77 @@ public static T[][] SplitIntoPairs(T[] input) { return split; } + public Color getRandomColor() + { + Color color = Color.Transparent; + + Random rnd = new Random(); + int num = rnd.Next(1, 17); + + switch (num) + { + default: + break; + case 1: + color = Color.Red; + break; + case 2: + color = Color.Blue; + break; + case 3: + color = Color.Green; + break; + case 4: + color = Color.Yellow; + break; + case 5: + color = Color.Orange; + break; + case 6: + color = Color.Black; + break; + case 7: + color = Color.White; + break; + case 8: + color = Color.Pink; + break; + case 9: + color = Color.Purple; + break; + case 10: + color = Color.Teal; + break; + case 11: + color = Color.Navy; + break; + case 12: + color = Color.Turquoise; + break; + case 13: + color = Color.Indigo; + break; + case 14: + color = Color.Gray; + break; + case 15: + color = Color.Cyan; + break; + case 16: + color = Color.Brown; + break; + case 17: + color = Color.Beige; + break; + } + + return color; + } + + public int genRandom(int min, int max) + { + Random rnd = new Random(); + return rnd.Next(min, max); + } } } From e4ab8269ee82d40e6a64ae9c2d1a5e72abda5bf7 Mon Sep 17 00:00:00 2001 From: Jbro129 Date: Wed, 7 Apr 2021 13:01:44 -0400 Subject: [PATCH 2/2] Update CustomItems.cs Fixed typo --- CustomItems.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CustomItems.cs b/CustomItems.cs index e660660..f705559 100644 --- a/CustomItems.cs +++ b/CustomItems.cs @@ -299,7 +299,7 @@ private void CustomItem(CommandArgs args) { private void GiveCustomItem(CommandArgs args) { List parameters = args.Parameters; - int num = parameters.Counta(); + int num = parameters.Count(); if (num == 0) { args.Player.SendErrorMessage("Invalid Syntax. /givecustomitem <#> ... \nParameters: hexcolor, damage, knockback, useanimation, " +