using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using Uber.Collections; using Uber.HabboHotel.Rooms; using Uber.Storage; namespace Uber.HabboHotel.RoomBots { class BotManager { private SafeList Bots; private SafeList RandomPetSpeech; public BotManager() { this.Bots = new SafeList(); this.RandomPetSpeech = new SafeList(); } public void LoadBots() { this.Bots = null; this.Bots = new SafeList(); DataTable Data = null; using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient()) { Data = dbClient.ReadDataTable("SELECT * FROM bots"); } if (Data == null) { return; } foreach (DataRow Row in Data.Rows) { Bots.Add(new RoomBot((uint)Row["id"], (uint)Row["room_id"], (string)Row["ai_type"], (string)Row["walk_mode"], (String)Row["name"], (string)Row["motto"], (String)Row["look"], (int)Row["x"], (int)Row["y"], (int)Row["z"], (int)Row["rotation"], (int)Row["min_x"], (int)Row["min_y"], (int)Row["max_x"], (int)Row["max_y"])); } } public void LoadPetMessages() { this.RandomPetSpeech = null; this.RandomPetSpeech = new SafeList(); DataTable Messages = null; using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient()) { Messages = dbClient.ReadDataTable("SELECT pet_type,speech FROM bots_pet_speech ORDER BY id DESC"); } if (Messages == null) { return; } foreach (DataRow Row in Messages.Rows) { this.RandomPetSpeech.Add(new PetSpeech((int)Row["pet_type"], (string)Row["speech"])); } } public List GetRandomForPetType(uint Type) { var List = new List(); foreach (PetSpeech Speech in RandomPetSpeech) { if (Speech.PetType == Type) { List.Add(Speech.Speech); } } return List.ToList(); } public bool RoomHasBots(uint RoomId) { return (GetBotsForRoom(RoomId).Count >= 1); } public List GetBotsForRoom(uint RoomId) { var List = new List(); foreach (RoomBot Bot in Bots) { if (Bot.RoomId == RoomId) { List.Add(Bot); } } return List.ToList(); } public RoomBot GetBot(uint BotId) { foreach (RoomBot Bot in Bots) { if (Bot.BotId == BotId) { return Bot; } } return null; } public RoomBot GetRandomGuide { get { foreach (RoomBot Bot in this.Bots) { if (Bot == null) { continue; } if (Bot.AiType == "guide") { return Bot; } } return null; } } } }