using System; using System.Data; using System.Text; using System.Threading; using System.Collections; using System.Collections.Generic; using Holo.Virtual.Users; using Holo.Virtual.Rooms.Pathfinding; using Ion.Storage; namespace Holo.Virtual.Rooms.FantasyBots { internal class virtualFantasyBot { #region Declares internal int roomUID; internal virtualRoom Room; internal string Name; internal string Mission; internal string Figure; internal int X; internal int Y; internal double H; internal byte Z1; internal byte Z2; internal int goalX; internal int goalY; internal bool Guide; internal int Mvn = 0; private delegate void statusVoid(string Key, string Value, int Length); private Thread aiHandler; private string Sayings; private Coord[] Coords; #endregion #region Constructors/destructors private Hashtable Statuses; internal virtualFantasyBot(int roomUID, virtualRoom Room, string Name, string Mission, string Figure, int X, int Y, int Z1, bool Guide) { this.roomUID = roomUID; this.Room = Room; this.Name = Name; this.Mission = Mission; this.Figure = Figure; this.X = X; this.Y = Y; this.Z1 = Convert.ToByte(Z1); this.Z2 = Convert.ToByte(Z1); this.goalX = -1; this.Sayings = ""; this.Guide = Guide; Statuses = new Hashtable(); aiHandler = new Thread(new ThreadStart(AI)); aiHandler.Priority = ThreadPriority.BelowNormal; aiHandler.Start(); } internal void Kill() { try { aiHandler.Abort(); } catch { } aiHandler = null; Room = null; Statuses = null; Coords = null; Sayings = null; } internal void Move() { Mvn++; Random RND = new Random(); Coord Next = new Coord(); int[] Borders = Room.getMapBorders(); Next = new Coord(RND.Next(0, Borders[0]), RND.Next(0, Borders[1])); if (Next.X == X && Next.Y == Y) // Coord didn't changed { Z1 = (byte)RND.Next(0, 10); Z2 = Convert.ToByte(Z1); Refresh(); this.Move(); } else { goalX = Next.X; goalY = Next.Y; } if (Mvn == 3) Mvn = 0; else this.Move(); } #endregion #region Bot properties internal bool containsWord(string[] Words, string theWord) { for (int i = 0; i < Words.Length; i++) if (Words[i] == theWord) return true; return false; } internal string detailsString { get { return Encoding.encodeVL64(roomUID) + Name + Convert.ToChar(2) + Mission + " " + Convert.ToChar(2) + Figure + Convert.ToChar(2) + Encoding.encodeVL64(roomUID) + Encoding.encodeVL64(X) + Encoding.encodeVL64(Y) + H + Convert.ToChar(2) + "IK" + Convert.ToChar(2); } } internal string statusString { get { string s = Encoding.encodeVL64(roomUID) + Encoding.encodeVL64(X) + Encoding.encodeVL64(Y) + H.ToString().Replace(",", ".") + Convert.ToChar(2) + Encoding.encodeVL64(Z1) + Encoding.encodeVL64(Z2) + "/"; foreach (string Key in Statuses.Keys) { s += Key; string Value = (string)Statuses[Key]; if (Value != "") s += " " + Value; s += "/"; } return s; } } #endregion #region Actions internal void Interact(virtualRoomUser roomUser, string Message) { Message = Message.ToLower(); string[] messageWords = Message.Split(' '); if (containsWord(messageWords, "creditos") || containsWord(messageWords, "créditos")) Sayings = "Habbo es gratis, pero para decorar tus Salas necesitarás Habbo Créditos. Puedes informarte sobre ellos en la página de Créditos de la web."; if (containsWord(messageWords, "furni") || containsWord(messageWords, "furniture")) Sayings = "Para ver qué Furni o Muebles tienes en tu Inventario, haz clic en la caja correspondiente de la barra de herramientas."; if (containsWord(messageWords, "salas")) Sayings = "¿Buscas gente con la que pasar el rato? Abre el Navegador y mira a ver dónde están todos."; if(Sayings.Length > 0) Room.sendShout(this, Sayings.ToString()); Sayings = ""; } internal void Rotate(int toX, int toY) { Rotate(Rotation.Calculate(X, Y, toX, toY)); } internal void Rotate(byte R) { if (R != Z1 && Statuses.ContainsKey("sit") == false) { Z1 = R; Z2 = R; Refresh(); } } internal Coord getClosestWalkCoordTo(int X, int Y) { int minDistance = 6; Coord Closest = new Coord(-1, 0); foreach (Coord Coord in Coords) { int curDistance = Math.Abs(X - Coord.X) + Math.Abs(Y - Coord.Y); if (curDistance < minDistance) { minDistance = curDistance; Closest = Coord; } } return Closest; } #endregion #region Status management internal void addStatus(string Key, string Value) { if (Statuses.ContainsKey(Key)) Statuses.Remove(Key); Statuses.Add(Key, Value); } internal void removeStatus(string Key) { try { if (Statuses.ContainsKey(Key)) Statuses.Remove(Key); } catch { } } internal bool containsStatus(string Key) { return Statuses.ContainsKey(Key); } internal void Refresh() { Room.Refresh(this); } internal void handleStatus(string Key, string Value, int Length) { if (Statuses.ContainsKey(Key)) Statuses.Remove(Key); new statusVoid(HANDLESTATUS).BeginInvoke(Key, Value, Length, null, null); } private void HANDLESTATUS(string Key, string Value, int Length) { try { Statuses.Add(Key, Value); Refresh(); Thread.Sleep(Length); Statuses.Remove(Key); Refresh(); } catch { } } #endregion #region Misc private void AI() { //Random RND = new Random(roomUID * DateTime.Now.Millisecond); Random RND = new Random(); { while (true) { int ACTION = RND.Next(0, 5); switch (ACTION) { case 1: // Move { Coord Next = new Coord(); int[] Borders = Room.getMapBorders(); Next = new Coord(RND.Next(0, Borders[0]), RND.Next(0, Borders[1])); if (Next.X == X && Next.Y == Y) // Coord didn't changed { Z1 = (byte)RND.Next(0, 10); Z2 = Z1; Refresh(); } else { goalX = Next.X; goalY = Next.Y; } break; } case 2: // Rotate { byte R = (byte)RND.Next(0, 10); while (R == Z2) R = (byte)RND.Next(0, 10); Rotate(R); break; } case 3: // Say { if (Sayings.Length > 0) { Room.sendShout(this, Sayings.ToString()); Sayings = ""; } break; } case 4: // Generate Say { if (this.Guide) { int Text = RND.Next(0, 8); if (Text == 1) Room.sendShout(this, "Echa un vistazo a tus regalos haciendo clic en el icono de la caja. Arrástralos a tu Sala para abrirlos"); if (Text == 2) Room.sendShout(this, "Soy tu Bot Guía, a tu servicio. ¿Qué quieres saber?"); if (Text == 3) Room.sendShout(this, "¿Quieres oír unos cuantos consejos sobre lo que puedes hacer aquí?"); if (Text == 4) Room.sendShout(this, "¡Lo estás haciendo genial!"); } break; } } Thread.Sleep(3000); } } } #endregion } }