private void onInitialize(EventArgs e) { Config = Config.Read(); //This is the main command, which branches to everything the plugin can do, by checking the first parameter a player inputs Commands.ChatCommands.Add(new Command(new List <string>() { "botin.abrir", "botin.reload", "botin.modo" }, KeyChange, "botin") { HelpDesc = new[] { $"{Commands.Specifier}botin - Muestra informacion del plugin.", $"{Commands.Specifier}botin abrir <tipo> - Utiliza la llave correspondiente para abrir el botin especificado en <tipo>.", $"{Commands.Specifier}botin lista <pagina> - Muestra el listado de botines disponibles que puedes conseguir por pagina.", $"{Commands.Specifier}botin modo <modo> - Cambia el modo de intercambio.", $"{Commands.Specifier}botin recargar - Vuelve a cargar la configuracion.", "Si no logras realizar el intercambio, asegurate de tener suficiente espacio en tu inventario." } }); Exchanging = new KeyTypes?[Main.maxNetPlayers]; }
private void onInitialize(EventArgs e) { Config = Config.Read(); //This is the main command, which branches to everything the plugin can do, by checking the first parameter a player inputs Commands.ChatCommands.Add(new Command(new List <string>() { "key.change", "key.reload", "key.mode" }, KeyChange, "key") { HelpDesc = new[] { $"{Commands.Specifier}key - Shows plugin info.", $"{Commands.Specifier}key change <type> - Exchanges a key of the input type.", $"{Commands.Specifier}key list - Shows a list of available keys and items.", $"{Commands.Specifier}key mode <mode> - Changes exchange mode.", $"{Commands.Specifier}key reload - Reloads the config file.", "If an exchange fails, make sure your inventory has free slots." } }); Exchanging = new KeyTypes?[Main.maxNetPlayers]; }
private void KeyChange(CommandArgs args) { TSPlayer ply = args.Player; // SSC check to alert users if (!Main.ServerSideCharacter) { ply.SendWarningMessage("[Advertencia] Este complemento puede no funcionar en servidores que no tengan SSC activado."); } if (args.Parameters.Count < 1) { // Plugin Info var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; ply.SendMessage($"KeyChanger (v{version}) por Enerdy - Actualizado y traducido por Tsviets", Color.SkyBlue); ply.SendMessage("Descripcion: Abre cajas de botin con llaves para obtener objetos.", Color.SkyBlue); ply.SendMessage($"Modo de uso: {Commands.Specifier}botin <lista/modo/abrir> [tipo]", Color.SkyBlue); ply.SendMessage($"Escribe {Commands.Specifier}help botin para más informacion.", Color.SkyBlue); } else if (args.Parameters[0].ToLower() == "abrir" && args.Parameters.Count == 1) { ply.SendErrorMessage("Error de uso. Uso correcto: {0}botin abrir <tipo>", Commands.Specifier); } else if (args.Parameters.Count > 0) { string cmd = args.Parameters[0].ToLower(); switch (cmd) { case "abrir": // Prevents cast from the server console if (!ply.RealPlayer) { ply.SendErrorMessage("Debes usar este comando dentro del juego."); return; } if (!ply.HasPermission("botin.abrir")) { ply.SendErrorMessage("No tienes acceso a este comando."); break; } KeyTypes type; if (!Enum.TryParse(args.Parameters[1].ToLowerInvariant(), true, out type)) { ply.SendErrorMessage("El botin seleccionado es invalido. Tipos de botines disponibles: " + String.Join(", ", Config.EnableTempleKey ? "templo" : null, Config.EnableJungleKey ? "jungla" : null, Config.EnableCorruptionKey ? "corrupto" : null, Config.EnableCrimsonKey ? "carmesi" : null, Config.EnableHallowedKey ? "sagrado" : null, Config.EnableFrozenKey ? "helado" : null, Config.EnableGoldenKey ? "dorado" : null, Config.EnableShadowKey ? "sombrio" : null, Config.EnableLightKey ? "radiante" : null, Config.EnableNightKey ? "nocturno" : null, Config.EnableDesertKey ? "desierto" : null)); return; } Key key = Utils.LoadKey(type); // Verifies whether the key has been enabled if (!key.Enabled) { ply.SendInfoMessage("El botin seleccionado se encuentra deshabilitado."); return; } if (!Config.UseSSC) { // Begin the exchange, expect the player to drop the key Exchanging[args.Player.Index] = type; ply.SendInfoMessage($"Drop (hold & right-click) any number of {key.Name} keys to proceed."); return; } // Checks if the player carries the necessary key var lookup = ply.TPlayer.inventory.FirstOrDefault(i => i.netID == (int)key.Type); if (lookup == null) { ply.SendErrorMessage("Asegurate de tener en tu inventario la llave del botin que quieres abrir."); return; } if (Config.EnableRegionExchanges) { Region region; if (Config.MarketMode) { region = TShock.Regions.GetRegionByName(Config.MarketRegion); } else { region = key.Region; } // Checks if the required region is set to null if (region == null) { ply.SendInfoMessage("No se ha especificado una region de intercambio para este botin."); return; } // Checks if the player is inside the region if (!region.InArea(args.Player.TileX, args.Player.TileY)) { ply.SendErrorMessage("Debes ir a la region indicada para abrir tu botin -> " + region.Name); return; } } Item item; for (int i = 0; i < 50; i++) { item = ply.TPlayer.inventory[i]; // Loops through the player's inventory if (item.netID == (int)key.Type) { // Found the item, checking for available slots. This will increase invManage for each empty slot until ic = 50, as any further slot have other purposes (coins, ammo, etc.) var invManage = 0; for (int ic = 0; ic < 50; ic++) { if (ply.TPlayer.inventory[ic].Name == "") { invManage++; } } var cfgCount = Config.ItemCountGiven; var LBenabler = Config.EnableLootboxMode; if ((item.stack == 1 & (item.stack + invManage) >= cfgCount & LBenabler == true) || ((invManage >= cfgCount) & LBenabler == true)) // If your key stack is 1, this will consider it as an empty slot as well. { ply.TPlayer.inventory[i].stack--; ply.SendSuccessMessage("Has usado una llave de botin => [i:{0}]", key.Items); // This here will show the opened lootbox, rename args as you see fit. Random rand = new Random(); for (int icount = 0; icount < cfgCount; icount++) { NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, ply.Index, i); Item give = key.Items[rand.Next(0, key.Items.Count)]; ply.GiveItem(give.netID, 1); Item take = TShock.Utils.GetItemById((int)key.Type); ply.SendSuccessMessage("Has recibido [i:{0}]!", give.netID); } } else if ((item.stack == 1 & (item.stack + invManage) > key.Items.Count & LBenabler == false) || ((invManage > key.Items.Count) & LBenabler == false)) { ply.TPlayer.inventory[i].stack--; ply.SendSuccessMessage("Has abierto usado una llave de botin => [i:{0}]", key.Type); for (int norand = 0; norand < key.Items.Count; norand++) { NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, ply.Index, i); Item give = key.Items[norand]; ply.GiveItem(give.netID, 1); Item take = TShock.Utils.GetItemById((int)key.Type); ply.SendSuccessMessage("Has recibido [i:{0}]!", give.netID); } } else { // Sent if neither of the above conditions were fulfilled. ply.SendErrorMessage("Asegurate de tener espacio en tu inventario."); return; } } } break; case "reload": { if (!ply.HasPermission("botin.reload")) { ply.SendErrorMessage("No tienes permiso para usar este comando."); break; } Config = Config.Read(); ply.SendSuccessMessage("Se han actualizado los cambios en la configuracion."); break; } case "lista": { ply.SendMessage("Botin del Templo - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Templo).Items.Select(i => i.netID)) + "]", Color.Chocolate); ply.SendMessage("Botin de la Jungla - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Jungla).Items.Select(i => i.netID)) + "]", Color.DarkGreen); ply.SendMessage("Botin Corrupto - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Corrupto).Items.Select(i => i.netID)) + "]", Color.Purple); ply.SendMessage("Botin Carmesi - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Carmesi).Items.Select(i => i.netID)) + "]", Color.OrangeRed); ply.SendMessage("Botin Sagrado - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Sagrado).Items.Select(i => i.netID)) + "]", Color.LightPink); ply.SendMessage("Botin Helado - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Helado).Items.Select(i => i.netID)) + "]", Color.SkyBlue); break; } case "lista 1": { ply.SendMessage("Botin del Templo [i:1141] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Templo).Items.Select(i => i.netID)) + "]", Color.Chocolate); ply.SendMessage("Botin de la Jungla [i:1533] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Jungla).Items.Select(i => i.netID)) + "]", Color.DarkGreen); ply.SendMessage("Botin Corrupto [i:1534] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Corrupto).Items.Select(i => i.netID)) + "]", Color.Purple); ply.SendMessage("Botin Carmesi [i:1535] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Carmesi).Items.Select(i => i.netID)) + "]", Color.OrangeRed); ply.SendMessage("Botin Sagrado [i:1536] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Sagrado).Items.Select(i => i.netID)) + "]", Color.LightPink); ply.SendMessage("Escribe /botin lista 2 para ver más resultados", Color.Yellow); break; } case "lista 2": { ply.SendMessage("Botin Helado [i:1537] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Helado).Items.Select(i => i.netID)) + "]", Color.SkyBlue); ply.SendMessage("Botin Dorado [i:327] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Dorado).Items.Select(i => i.netID)) + "]", Color.Goldenrod); ply.SendMessage("Botin Sombrio [i:329] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Sombrio).Items.Select(i => i.netID)) + "]", Color.DarkViolet); ply.SendMessage("Botin Radiante [i:3092] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Radiante).Items.Select(i => i.netID)) + "]", Color.LightYellow); ply.SendMessage("Botin Nocturno [i:3091] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Nocturno).Items.Select(i => i.netID)) + "]", Color.DarkBlue); ply.SendMessage("Botin del Desierto [i:4714] - [i:" + String.Join("] [i:", Utils.LoadKey(KeyTypes.Desierto).Items.Select(i => i.netID)) + "]", Color.LightGoldenrodYellow); break; } case "modo": { if (!ply.HasPermission("botin.modo")) { ply.SendErrorMessage("No tienes acceso a este comando."); break; } if (args.Parameters.Count < 2) { ply.SendErrorMessage("Error de uso. Modo de uso: {0}botin modo <normal/region/mercado>", Commands.Specifier); break; } string query = args.Parameters[1].ToLower(); if (query == "normal") { Config.EnableRegionExchanges = false; ply.SendSuccessMessage("Modo de intercambio asignado: normal (cualquier lugar)."); } else if (query == "region") { Config.EnableRegionExchanges = true; Config.MarketMode = false; ply.SendSuccessMessage("Modo de intercambio asignado: region (una region por cada llave)."); } else if (query == "mercado") { Config.EnableRegionExchanges = true; Config.MarketMode = true; ply.SendSuccessMessage("Modo de intercambio asignado: mercado (una region para todas las llaves)."); } else { ply.SendErrorMessage("Sintaxis invalida. Modo de uso: {0}llaves modo <normal/region/mercado>", Commands.Specifier); return; } Config.Write(); break; } default: { ply.SendErrorMessage(Utils.ErrorMessage(ply)); break; } } } else { ply.SendErrorMessage(Utils.ErrorMessage(ply)); } }
private void KeyChange(CommandArgs args) { TSPlayer ply = args.Player; // SSC check to alert users if (!Main.ServerSideCharacter) { ply.SendWarningMessage("[Warning] This plugin will not work properly with ServerSideCharacters disabled."); } if (args.Parameters.Count < 1) { // Plugin Info var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; ply.SendMessage($"KeyChanger (v{version}) by Enerdy", Color.SkyBlue); ply.SendMessage("Description: Changes special chest keys into their specific items", Color.SkyBlue); ply.SendMessage($"Syntax: {Commands.Specifier}key <list/mode/change/reload> [type]", Color.SkyBlue); ply.SendMessage($"Type {Commands.Specifier}help key for more info", Color.SkyBlue); } else if (args.Parameters[0].ToLower() == "change" && args.Parameters.Count == 1) { ply.SendErrorMessage("Invalid syntax! Proper syntax: {0}key change <type>", Commands.Specifier); } else if (args.Parameters.Count > 0) { string cmd = args.Parameters[0].ToLower(); switch (cmd) { case "change": // Prevents cast from the server console if (!ply.RealPlayer) { ply.SendErrorMessage("You must use this command in-game."); return; } if (!ply.HasPermission("key.change")) { ply.SendErrorMessage("You do not have access to this command."); break; } KeyTypes type; if (!Enum.TryParse(args.Parameters[1].ToLowerInvariant(), true, out type)) { ply.SendErrorMessage("Invalid key type! Available types: " + String.Join(", ", Config.EnableTempleKey ? "temple" : null, Config.EnableJungleKey ? "jungle" : null, Config.EnableCorruptionKey ? "corruption" : null, Config.EnableCrimsonKey ? "crimson" : null, Config.EnableHallowedKey ? "hallowed" : null, Config.EnableFrozenKey ? "frozen" : null)); return; } Key key = Utils.LoadKey(type); // Verifies whether the key has been enabled if (!key.Enabled) { ply.SendInfoMessage("The selected key is disabled."); return; } if (!Config.UseSSC) { // Begin the exchange, expect the player to drop the key Exchanging[args.Player.Index] = type; ply.SendInfoMessage($"Drop (hold & right-click) any number of {key.Name} keys to proceed."); return; } // Checks if the player carries the necessary key var lookup = ply.TPlayer.inventory.FirstOrDefault(i => i.netID == (int)key.Type); if (lookup == null) { ply.SendErrorMessage("Make sure you carry the selected key in your inventory."); return; } if (Config.EnableRegionExchanges) { Region region; if (Config.MarketMode) { region = TShock.Regions.GetRegionByName(Config.MarketRegion); } else { region = key.Region; } // Checks if the required region is set to null if (region == null) { ply.SendInfoMessage("No valid region was set for this key."); return; } // Checks if the player is inside the region if (!region.InArea(args.Player.TileX, args.Player.TileY)) { ply.SendErrorMessage("You are not in a valid region to make this exchange."); return; } } Item item; for (int i = 0; i < 50; i++) { item = ply.TPlayer.inventory[i]; // Loops through the player's inventory if (item.netID == (int)key.Type) { // Found the item, checking for available slots if (item.stack == 1 || ply.InventorySlotAvailable) { ply.TPlayer.inventory[i].stack--; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, ply.Index, i); Random rand = new Random(); Item give = key.Items[rand.Next(0, key.Items.Count)]; ply.GiveItem(give.netID, give.Name, give.width, give.height, 1); Item take = TShock.Utils.GetItemById((int)key.Type); ply.SendSuccessMessage("Exchanged a {0} for 1 {1}!", take.Name, give.Name); return; } // Sent if neither of the above conditions were fulfilled. ply.SendErrorMessage("Make sure you have at least one available inventory slot."); return; } } break; case "reload": { if (!ply.HasPermission("key.reload")) { ply.SendErrorMessage("You do not have access to this command."); break; } Config = Config.Read(); ply.SendSuccessMessage("KeyChangerConfig.json reloaded successfully."); break; } case "list": { ply.SendMessage("Temple Key - " + String.Join(", ", Utils.LoadKey(KeyTypes.Temple).Items.Select(i => i.Name)), Color.Goldenrod); ply.SendMessage("Jungle Key - " + String.Join(", ", Utils.LoadKey(KeyTypes.Jungle).Items.Select(i => i.Name)), Color.Goldenrod); ply.SendMessage("Corruption Key - " + String.Join(", ", Utils.LoadKey(KeyTypes.Corruption).Items.Select(i => i.Name)), Color.Goldenrod); ply.SendMessage("Crimson Key - " + String.Join(", ", Utils.LoadKey(KeyTypes.Crimson).Items.Select(i => i.Name)), Color.Goldenrod); ply.SendMessage("Hallowed Key - " + String.Join(", ", Utils.LoadKey(KeyTypes.Hallowed).Items.Select(i => i.Name)), Color.Goldenrod); ply.SendMessage("Frozen Key - " + String.Join(", ", Utils.LoadKey(KeyTypes.Frozen).Items.Select(i => i.Name)), Color.Goldenrod); break; } case "mode": { if (!ply.HasPermission("key.mode")) { ply.SendErrorMessage("You do not have access to this command."); break; } if (args.Parameters.Count < 2) { ply.SendErrorMessage("Invalid syntax! Proper syntax: {0}key mode <normal/region/market>", Commands.Specifier); break; } string query = args.Parameters[1].ToLower(); if (query == "normal") { Config.EnableRegionExchanges = false; ply.SendSuccessMessage("Exchange mode set to normal (exchange everywhere)."); } else if (query == "region") { Config.EnableRegionExchanges = true; Config.MarketMode = false; ply.SendSuccessMessage("Exchange mode set to region (a region for each type)."); } else if (query == "market") { Config.EnableRegionExchanges = true; Config.MarketMode = true; ply.SendSuccessMessage("Exchange mode set to market (one region for every type)."); } else { ply.SendErrorMessage("Invalid syntax! Proper syntax: {0}key mode <normal/region/market>", Commands.Specifier); return; } Config.Write(); break; } default: { ply.SendErrorMessage(Utils.ErrorMessage(ply)); break; } } } else { ply.SendErrorMessage(Utils.ErrorMessage(ply)); } }