public static void JoinGame(CommandArgs args) { TSPlayer tSPlayer = args.Player; if (HubEvent.GetEventPlayerIn(tSPlayer.Name) != null) { tSPlayer.SendErrorMessage("You're already in an event! Please use /leave first!"); return; } if (args.Parameters.Count < 1) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /join <Event Name>"); return; } string eventName = string.Join("", args.Parameters).ToLower(); HubEvent hubEvent = HubEvent.GetEvent(eventName); if (hubEvent == null) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /forcejoinall <Event Name>"); return; } HubEvent.AddPlayerToEvent(tSPlayer, hubEvent); hubEvent.TeleportPlayerToSpawn(tSPlayer); tSPlayer.SendSuccessMessage(string.Format("You successfully joined {0}!", hubEvent.eventName)); }
public static void ResetMap(CommandArgs args) { TSPlayer tSPlayer = args.Player; if (args.Parameters.Count < 1) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /resetmap <Event Name>"); return; } string eventName = string.Join("", args.Parameters).ToLower(); HubEvent hubEvent = HubEvent.GetEvent(eventName); if (hubEvent == null) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /forcejoinall <Event Name>"); return; } if (hubEvent.ResetMap()) { tSPlayer.SendSuccessMessage("The map was successfully reset."); return; } TShock.Log.ConsoleError("The ResetMap method was used but the WorldEdit plugin was not found!"); tSPlayer.SendErrorMessage("The WorldEdit plugin is required to use this command!"); }
public VotingSystem(string question, double voteLengthMS, HubEvent linkedEvent, params OptionInfo[] options) { this.question = question; this.linkedEvent = linkedEvent; this.voteLengthMS = voteLengthMS; voteTimer.Interval = voteLengthMS; voteTimer.Elapsed += (sender, elapsedArgs) => Stop(); this.options = options; }
public static void ForceJoin(CommandArgs args) { TSPlayer tSPlayer = args.Player; if (args.Parameters.Count < 2) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /forcejoin <Player Name> <Event Name>"); return; } List <TSPlayer> tSPlayerTargets = TSPlayer.FindByNameOrID(args.Parameters[0]); if (tSPlayerTargets.Count == 0) { tSPlayer.SendErrorMessage("The player specified was not found!"); return; } if (tSPlayerTargets.Count > 1) { tSPlayer.SendErrorMessage("Multiple players with that name were found!"); return; } TSPlayer tSPlayerTarget = tSPlayerTargets.First(); string eventName = string.Join("", args.Parameters.Skip(1)).ToLower(); HubEvent hubEvent = HubEvent.GetEvent(eventName); if (hubEvent == null) { tSPlayer.SendErrorMessage("The event specified was not found!"); return; } // Check if player has already joined an event, and if so, remove them from it HubEvent playerHubEvent = HubEvent.GetEventPlayerIn(tSPlayerTarget.Name); if (playerHubEvent != null) { HubEvent.RemovePlayerFromEvent(tSPlayerTarget, playerHubEvent); } HubEvent.AddPlayerToEvent(tSPlayerTarget, hubEvent); tSPlayer.SendSuccessMessage(string.Format("{0} was successfully added to {1}!", tSPlayerTarget.Name, hubEvent.eventName)); }
public static void LeaveGame(CommandArgs args) { TSPlayer tSPlayer = args.Player; HubEvent hubEvent = HubEvent.GetEventPlayerIn(tSPlayer.Name); if (hubEvent == null) { tSPlayer.SendErrorMessage("You are not in an event!"); return; } HubEvent.RemovePlayerFromEvent(tSPlayer, hubEvent); tSPlayer.SendSuccessMessage("You were successfully removed from " + hubEvent.eventName + "!"); return; }
public static void OnServerLeave(LeaveEventArgs args) { // Kick players out of events if they leave the game. TSPlayer tSPlayer = TShock.Players[args.Who]; HubEvent hubEvent = HubEvent.GetEventPlayerIn(tSPlayer.Name); if (hubEvent == null) { return; } HubEvent.RemovePlayerFromEvent(tSPlayer, hubEvent); Util.spectatingPlayersToTargets.Remove(tSPlayer); }
public static void ForceJoinAll(CommandArgs args) { TSPlayer tSPlayer = args.Player; if (args.Parameters.Count < 1) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /forcejoinall <Event Name>"); return; } string eventName = string.Join("", args.Parameters).ToLower(); HubEvent hubEvent = HubEvent.GetEvent(eventName); if (hubEvent == null) { tSPlayer.SendErrorMessage("The event specified was not found!"); return; } string players = ""; foreach (TSPlayer tSP in TShock.Players) { if (tSP == null) { continue; } // Check if player has already joined an event, and if so, remove them from it HubEvent playerHubEvent = HubEvent.GetEventPlayerIn(tSP.Name); if (playerHubEvent != null) { HubEvent.RemovePlayerFromEvent(tSP, playerHubEvent); } HubEvent.AddPlayerToEvent(tSP, hubEvent); players += tSP.Name + ", "; } players = players.Trim(' ', ','); tSPlayer.SendSuccessMessage(string.Format("{0} was successfully added to {1}!", players, hubEvent.eventName)); }
public static void ForceStartGame(CommandArgs args) { TSPlayer tSPlayer = args.Player; HubEvent hubEvent = HubEvent.GetEventPlayerIn(tSPlayer.Name); if (hubEvent == null) { tSPlayer.SendErrorMessage("You are not in an event!"); return; } tSPlayer.SendSuccessMessage("You successfully started the event!"); TShock.Utils.Broadcast("An admin has forcibly started the event!", Color.Aquamarine); hubEvent.StartEventCountdown(); }
public static void StartGame(CommandArgs args) { TSPlayer tSPlayer = args.Player; HubEvent hubEvent = HubEvent.GetEventPlayerIn(tSPlayer.Name); if (hubEvent == null) { tSPlayer.SendErrorMessage("You are not in an event!"); return; } tSPlayer.SendSuccessMessage("You successfully started a vote to start the event!"); VotingSystem votingSystem = new VotingSystem("Should the game start?", 60000, hubEvent, new OptionInfo("Yes", hubEvent.StartEventCountdown), new OptionInfo("No")); votingSystem.Start(); }
public static void OnGameUpdate(EventArgs _) { // Teleport spectating players to their targets. foreach (TSPlayer tSPlayer in Util.spectatingPlayersToTargets.Keys) { TSPlayer target = Util.spectatingPlayersToTargets[tSPlayer]; Vector2 position = target.TPlayer.position; tSPlayer.TeleportNoDust(position); } // Check if an event has already started. HubEvent startedEvent = HubEvent.GetOngoingEvent(); if (startedEvent != null) { startedEvent.GameUpdate(); return; } // Check if there is already an ongoing vote. if (VotingSystem.ongoingVotes.Count > 0) { return; } // Start the event countdown vote if there are enough players. foreach (HubEvent hubEvent in HubConfig.config.HubEvents) { if (hubEvent.tSPlayers.Count >= hubEvent.minPlayersForStart) { VotingSystem votingSystem = new VotingSystem("Should the game start?", 60000, hubEvent, new OptionInfo("Yes", hubEvent.StartEventCountdown), new OptionInfo("No", hubEvent.DeclineStart)); votingSystem.Start(); } } }
public static void ChooseClass(CommandArgs args) { TSPlayer tSPlayer = args.Player; Player player = tSPlayer.TPlayer; if (!TShock.ServerSideCharacterConfig.Enabled) { tSPlayer.SendErrorMessage("SSC is not enabled so choosing classes has been disabled."); return; } HubEvent hubEvent = HubEvent.GetEventPlayerIn(tSPlayer.Name); if (hubEvent == null) { tSPlayer.SendErrorMessage("You are not in an event!"); return; } IEnumerable <EventClass> eventClasses = ClassConfig.config.eventClasses.Where(c => c.eventName == hubEvent.eventName); if (eventClasses.Count() < 1) { tSPlayer.SendErrorMessage("This event has no classes."); return; } if (args.Parameters.Count < 1) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /chooseclass <Class Name>"); string classesFormatted = ""; foreach (EventClass eventClass in eventClasses) { classesFormatted += eventClass.className + ", "; } classesFormatted = classesFormatted.TrimEnd(',', ' '); tSPlayer.SendInfoMessage(string.Format("The available classes for {0} are: {1}.", hubEvent.eventName, classesFormatted)); return; } string className = args.Parameters[0].ToLower(); IEnumerable <EventClass> classes = eventClasses.Where(c => c.className.ToLower() == className); if (classes.Count() < 1) { tSPlayer.SendErrorMessage("No classes with that name were found!"); string classesFormatted = ""; foreach (EventClass eventClass in eventClasses) { classesFormatted += eventClass.className + ", "; } classesFormatted = classesFormatted.TrimEnd(',', ' '); tSPlayer.SendInfoMessage(string.Format("Try \"/chooseclass [c/FFFF00: {0}] instead.\"", classesFormatted)); return; } if (classes.Count() > 1) { tSPlayer.SendErrorMessage("Multiple classes with that name were found!"); return; } EventClass chosenClass = classes.First(); tSPlayer.ResetPlayer(chosenClass.maxHealth, chosenClass.maxMana); // Main items for (int i = 0; i < (int)InventoryLengths.Main; i++) { if (!chosenClass.items.TryGetValue(i, out ClassItem classItem)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(classItem.name).First(); item.stack = classItem.stack; item.prefix = (byte)TShock.Utils.GetPrefixByIdOrName(classItem.prefix).First(); player.inventory[i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, i); } // Coins for (int i = 0; i < (int)InventoryLengths.Coins; i++) { if (!chosenClass.coins.TryGetValue(i, out ClassItem classItem)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(classItem.name).First(); item.stack = classItem.stack; item.prefix = (byte)TShock.Utils.GetPrefixByIdOrName(classItem.prefix).First(); player.inventory[(int)ItemSlot.CoinSlot1 + i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.CoinSlot1 + i); } // Ammo for (int i = 0; i < (int)InventoryLengths.Ammo; i++) { if (!chosenClass.ammo.TryGetValue(i, out ClassItem classItem)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(classItem.name).First(); item.stack = classItem.stack; item.prefix = (byte)TShock.Utils.GetPrefixByIdOrName(classItem.prefix).First(); player.inventory[(int)ItemSlot.AmmoSlot1 + i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.AmmoSlot1 + i); } // Armor for (int i = 0; i < (int)InventoryLengths.Armor; i++) { if (!chosenClass.armor.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.armor[i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.ArmorHeadSlot + i); } // Accessories for (int i = 0; i < (int)InventoryLengths.Accessories; i++) { if (!chosenClass.accessories.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.armor[(int)InventoryLengths.Armor + i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.AccessorySlot1 + i); } // Armor Vanity for (int i = 0; i < (int)InventoryLengths.Armor; i++) { if (!chosenClass.armorVanity.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.armor[(int)InventoryLengths.Armor + (int)InventoryLengths.AllAccessories + i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.VanityHeadSlot + i); } // Accessory Vanity for (int i = 0; i < (int)InventoryLengths.Accessories; i++) { if (!chosenClass.accessoryVanity.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.armor[(int)InventoryLengths.Armor + (int)InventoryLengths.AllAccessories + (int)InventoryLengths.Armor + i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.SocialAccessorySlot1 + i); } // Armor Dyes for (int i = 0; i < (int)InventoryLengths.Armor; i++) { if (!chosenClass.armorDyes.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.dye[i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.DyeHeadSlot + i); } // Accessory Dyes for (int i = 0; i < (int)InventoryLengths.Accessories; i++) { if (!chosenClass.accessoryDyes.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.dye[(int)InventoryLengths.Armor + i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.DyeAccessorySlot1 + i); } // Misc Equips for (int i = 0; i < (int)InventoryLengths.MiscEquips; i++) { if (!chosenClass.miscEquips.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.miscEquips[i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.EquipmentSlot1 + i); } // Misc Equip Dyes for (int i = 0; i < (int)InventoryLengths.MiscEquips; i++) { if (!chosenClass.miscEquipDyes.TryGetValue(i, out string itemName)) { continue; } Item item = TShock.Utils.GetItemByIdOrName(itemName).First(); player.miscDyes[i] = item; NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, (int)ItemSlot.DyeEquipmentSlot1 + i); } tSPlayer.SendSuccessMessage(string.Format("{0} class chosen!", chosenClass.className)); }
public static void AddClass(CommandArgs args) { TSPlayer tSPlayer = args.Player; Player player = tSPlayer.TPlayer; if (args.Parameters.Count < 2) { tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /addclass <Class Name> <Event Name>"); return; } string eventName = string.Join("", args.Parameters.Skip(1)).ToLower(); HubEvent hubEvent = HubEvent.GetEvent(eventName); if (hubEvent == null) { tSPlayer.SendErrorMessage("That is not a valid event!"); return; } string className = args.Parameters[0]; EventClass eventClass = new EventClass { className = className, eventName = hubEvent.eventName, maxHealth = player.statLifeMax2, maxMana = player.statManaMax2, }; // Main items, coins, and ammo for (int i = 0; i < NetItem.InventorySlots; i++) { Item item = player.inventory[i]; if (item.netID == 0) { continue; } ClassItem classItem = new ClassItem() { name = item.Name, stack = item.stack, prefix = TShock.Utils.GetPrefixById(item.prefix) }; if (i <= (int)ItemSlot.InvRow5Slot10) { eventClass.items[i] = classItem; } else if (i <= (int)ItemSlot.CoinSlot4) { int index = i - (int)ItemSlot.CoinSlot1; eventClass.coins[index] = classItem; } else { int index = i - (int)ItemSlot.AmmoSlot1; eventClass.ammo[index] = classItem; } } // Armor, accessories, and their vanity for (int i = 0; i < NetItem.ArmorSlots; i++) { Item item = player.armor[i]; if (item.netID == 0) { continue; } if (i < (int)InventoryLengths.Armor) { eventClass.armor[i] = item.Name; } else if (i < (int)InventoryLengths.Armor + (int)InventoryLengths.Accessories) { int index = i - (int)InventoryLengths.Armor; eventClass.accessories[index] = item.Name; } else if (i < (int)InventoryLengths.Armor + (int)InventoryLengths.AllAccessories + (int)InventoryLengths.Armor) { int index = i - ((int)InventoryLengths.Armor + (int)InventoryLengths.AllAccessories); eventClass.armorVanity[index] = item.Name; } else { int index = i - ((int)InventoryLengths.Armor + (int)InventoryLengths.AllAccessories + (int)InventoryLengths.Armor); eventClass.accessoryVanity[index] = item.Name; } } // Armor and accessory dyes for (int i = 0; i < NetItem.DyeSlots; i++) { Item item = player.dye[i]; if (item.netID == 0) { continue; } if (i < (int)InventoryLengths.Armor) { eventClass.armorDyes[i] = item.Name; } else { int index = i - (int)InventoryLengths.Armor; eventClass.accessoryDyes[index] = item.Name; } } // MiscEquips for (int i = 0; i < NetItem.MiscEquipSlots; i++) { Item item = player.miscEquips[i]; if (item.netID == 0) { continue; } eventClass.miscEquips[i] = item.Name; } // MiscEquip Dyes for (int i = 0; i < NetItem.MiscEquipSlots; i++) { Item item = player.miscDyes[i]; if (item.netID == 0) { continue; } eventClass.miscEquipDyes[i] = item.Name; } ClassConfig.config.eventClasses.Add(eventClass); tSPlayer.SendSuccessMessage("The " + className + " class was successfully added!"); }
public static void RemovePlayerFromEvent(TSPlayer tSPlayer, HubEvent hubEvent) { hubEvent.tSPlayers.Remove(tSPlayer); }
public static void AddPlayerToEvent(TSPlayer tSPlayer, HubEvent hubEvent) { hubEvent.tSPlayers.Add(tSPlayer); }