using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace tMx.Mechanics.CleanResearched { public class CleanResearchedCommand : ModCommand { public override CommandType Type => CommandType.Chat; public override string Command => "tmx"; public override string Description => "Clean all researched objects from inventory and your hotbar."; public override void Action(CommandCaller caller, string input, string[] args) { tMxConfigs config = ModContent.GetInstance(); Player p = caller.Player; int pic = 0; if (args.Length == 0) { Main.NewText($"[tMx] You must specify an argument.", Color.Red); Main.NewText($"[tMx] /tmx clean - Clean your inventory and your hotbar of any fully searched item(s).", Color.Red); } if (args.Contains("clean")) { List piggy = new List(); foreach (Item i in p.bank.item) { if (i.type != ItemID.None) { piggy.Add(i.type); } } // Clean the inventory of any fully researched item(s) int ic = 0; for (int index = 10; index < 50; index++) { Item i = p.inventory[index]; if (Main.LocalPlayerCreativeTracker.ItemSacrifices.TryGetSacrificeNumbers(i.type, out var amountWeHave, out var amountNeededTotal) && amountWeHave >= amountNeededTotal && !i.potion && !piggy.Contains(i.type)) { ic++; p.inventory[index].TurnToAir(); } else if (piggy.Contains(i.type) && config.CleanResearchedPiggyProtect) { pic++; } } Main.NewText($"[tMx] Cleaned {ic} item(s) from your inventory.", Color.Brown); // Clean the hotbar of any fully researched item(s) int ichot = 0; for (int indexhot = 0; indexhot < 10; indexhot++) { Item i = p.inventory[indexhot]; if (Main.LocalPlayerCreativeTracker.ItemSacrifices.TryGetSacrificeNumbers(i.type, out var amountWeHave, out var amountNeededTotal) && amountWeHave >= amountNeededTotal && !i.potion && !i.GetPrefixCategories().Contains(PrefixCategory.Accessory) && !i.GetPrefixCategories().Contains(PrefixCategory.AnyWeapon) && i.type != ItemID.Torch && i.type != ItemID.FallenStar && !piggy.Contains(i.type)) { ichot++; p.inventory[indexhot].TurnToAir(); } else if (piggy.Contains(i.type) && config.CleanResearchedPiggyProtect) { pic++; } } Main.NewText($"[tMx] Cleaned {ichot} item(s) from your hotbar.", Color.Brown); if (pic == 1) { Main.NewText($"[tMx] {pic} item was protected for being in your piggy bank.", Color.Brown); } else if (pic > 1) { Main.NewText($"[tMx] {pic} items were protected for being in your piggy bank.", Color.Brown); } ic = 0; ichot = 0; } } } }