/// <summary> /// Handle a bot kill command to kill the bots /// </summary> /// <param name="sender">Sending object</param> /// <param name="listEvent"></param> internal void HandleBotKillEvent(object sender, BotKillEvent listEvent) { // Send the response message to the bot BotInstance sourceBot = (sender as BotInstance); // Make sure the bot is not a public arena bot if ((sourceBot.Settings.SessionSettings.InitialArena.Length > 0) || (listEvent.Message.Equals("!forcekill"))) { // close the bot sourceBot.Close(); // Create a fresh new bot instance BotInstance newBot = new BotInstance(sourceBot.Settings); newBot.CoreEventManager += (new BotEvent(HandleCoreEvents)); // Add the bot to the available list m_availableBots.Add(newBot.Settings.SessionSettings.UserName.ToUpper(), newBot); // Remove the bot from the active list m_activeBots.Remove(sourceBot.Settings.SessionSettings.UserName.ToUpper()); } else { // Create the chat response packet ChatEvent response = new ChatEvent(); // Set the player Identifier to reply to response.PlayerId = listEvent.PlayerId; response.ChatType = ChatTypes.Private; response.Message = "ERROR: unable to !kill bots in public arena!"; sourceBot.SendGameEvent(response); } }
/// <summary> /// Handle a bot list command to list all bots /// </summary> /// <param name="sender">Sending object</param> /// <param name="listEvent"></param> internal void HandleBotListEvent(object sender, BotListEvent listEvent) { // Send the response message to the bot BotInstance sourceBot = (sender as BotInstance); // Create the chat response packet ChatEvent response = new ChatEvent(); // Set the player Identifier to reply to response.PlayerId = listEvent.PlayerId; response.ChatType = ChatTypes.Private; response.Message = "< ================================================= >"; sourceBot.SendGameEvent(response); response.Message = "< BattleCore Configured Bots >"; sourceBot.SendGameEvent(response); response.Message = "< >"; sourceBot.SendGameEvent(response); response.Message = "< Name Arena Status >"; sourceBot.SendGameEvent(response); response.Message = "< ================================================= >"; sourceBot.SendGameEvent(response); foreach (BotInstance bot in m_activeBots.Values) { // Only list the bots configured for the same server if (bot.Settings.SessionSettings.ServerAddress == sourceBot.Settings.SessionSettings.ServerAddress) { // List the bot status as active response.Message = "< " + bot.Settings.SessionSettings.UserName.PadRight(24) + bot.Settings.SessionSettings.InitialArena.PadRight(16) + "ACTIVE >"; sourceBot.SendGameEvent(response); } } foreach (BotInstance bot in m_availableBots.Values) { // Only list the bots configured for the same server if (bot.Settings.SessionSettings.ServerAddress == sourceBot.Settings.SessionSettings.ServerAddress) { // List the bot as inactive response.Message = "< " + bot.Settings.SessionSettings.UserName.PadRight(24) + bot.Settings.SessionSettings.InitialArena.PadRight(16) + " >"; sourceBot.SendGameEvent(response); } } // Send the response message to the bot response.Message = "< ================================================= >"; sourceBot.SendGameEvent(response); }
/// <summary> /// Handle BotGetInfoEvents and sends back info to user - used for modules /// Going to try and keep this internal only. /// </summary> /// <param name="sender">Sending object</param> /// <param name="infoEvent"></param> internal void HandleGetBotInfoEvent(object sender, BotGetInfoEvent infoEvent) { // Send the response message to the bot BotInstance sourceBot = (sender as BotInstance); // Create the chat response packet ChatEvent response = new ChatEvent(); // Get the settings for the source bot BotSettings sourceSettings = sourceBot.Settings; // Set the player Identifier to reply to response.PlayerName = sourceSettings.SessionSettings.UserName; response.ChatType = ChatTypes.Private; response.Message = "@BotInfo@:" + sourceSettings.SessionSettings.UserName + ":" + sourceSettings.SessionSettings.InitialArena; // Send the response message to the bot sourceBot.SendGameEvent(response); }
/// <summary> /// Handle a bot spawn command to create a new bot instance /// </summary> /// <param name="sender">Sending object</param> /// <param name="spawnEvent"></param> internal void HandleBotSpawnEvent(object sender, BotSpawnEvent spawnEvent) { // Send the response message to the bot BotInstance sourceBot = (sender as BotInstance); // Create the chat response packet ChatEvent response = new ChatEvent(); // Set the player Identifier to reply to response.PlayerId = spawnEvent.PlayerId; response.ChatType = ChatTypes.Private; // Check if the spawn bot name is valid if (spawnEvent.BotName.Length > 0) { // Find the bot in the available bot list int nIndex = m_availableBots.IndexOfKey(spawnEvent.BotName.ToUpper()); if (nIndex >= 0) { // Get the bot instance from the available bots BotInstance bot = m_availableBots[spawnEvent.BotName.ToUpper()]; if (spawnEvent.Arena.Length > 0) { // Set the new arena to enter bot.Settings.SessionSettings.InitialArena = spawnEvent.Arena; } // Remove the bot from the available list m_availableBots.Remove(spawnEvent.BotName.ToUpper()); // Add the bot to the active bot list m_activeBots.Add(spawnEvent.BotName.ToUpper(), bot); // Create the response message response.Message = "Spawning bot: " + spawnEvent.BotName; // Start the bot bot.Start(); } else if (m_activeBots.IndexOfKey(spawnEvent.BotName.ToUpper()) != -1) { response.Message = "Error: " + spawnEvent.BotName + "is already active!"; } else { response.Message = "Error: " + spawnEvent.BotName + "is not a valid bot name!"; } /* * else if (spawnEvent.ModLevel == ModLevels.Sysop) * { * * // Create the core settings object * CoreSettings coreSettings = new CoreSettings (); * * // Create the bot settings object * BotSettings spawnSettings = new BotSettings (); * * // Get the settings for the source bot * BotSettings sourceSettings = sourceBot.Settings; * * // Set the bot settings * spawnSettings.BotDirectory = spawnEvent.BotName; * spawnSettings.AutoLoad = false; * * // Set the session connection settings * spawnSettings.SessionSettings.UserName = spawnEvent.BotName; * spawnSettings.SessionSettings.Password = sourceSettings.SessionSettings.Password; * spawnSettings.SessionSettings.StaffPassword = sourceSettings.SessionSettings.StaffPassword; * spawnSettings.SessionSettings.InitialArena = spawnEvent.Arena; * * // Set the server address and port of the sending bot * spawnSettings.SessionSettings.ServerAddress = sourceSettings.SessionSettings.ServerAddress; * spawnSettings.SessionSettings.ServerPort = sourceSettings.SessionSettings.ServerPort; * * // Add the new bot to the core settings * coreSettings.ConfiguredBots.Add (spawnSettings); * coreSettings.WriteSettings (); * * // Create the new bot instance * BotInstance bot = new BotInstance (spawnSettings); * * // Add the core event manager * bot.CoreEventManager += (new BotEvent (HandleCoreEvents)); * * // Start the bot * bot.Start (); * * // Add a bot to the bot list * m_activeBots.Add (spawnEvent.BotName.ToUpper(), bot); * * // Create the response message * response.Message = "Bot does not exist. Creating a new bot: " + spawnEvent.BotName; * } */ } else { response.Message = "!spawn usage: !spawn bot !spawn bot:arena"; } // Send the response message to the bot sourceBot.SendGameEvent(response); }