namespace Holo.Virtual.Rooms.Bots { using Holo; using Holo.Virtual.Rooms; using Holo.Virtual.Rooms.Pathfinding; using Holo.Virtual.Users; using System; using System.Collections; using System.Runtime.CompilerServices; using System.Threading; internal class virtualBot { private ᙄ 00AAA; private Hashtable 10AA1; private Thread 6AAAA; private string[] 7AAA1; private string[] 8AAAA; private Coord[] 9AAA1; private ᙄ[] BAAAA; private virtualRoomUser CAAA1; internal string Figure; internal bool freeRoam; internal int goalX; internal int goalY; internal double H; internal string Mission; internal string Name; internal string noShoutingMessage; internal virtualRoom Room; internal int roomUID; internal int X; internal int Y; internal byte Z1; internal byte Z2; internal virtualBot(int botID, int roomUID, virtualRoom Room) { this.roomUID = roomUID; this.Room = Room; string[] strArray = DB.runReadRow("SELECT name,mission,figure,x,y,z,freeroam,message_noshouting FROM roombots WHERE id = '" + botID + "'"); this.Name = strArray[0]; this.Mission = strArray[1]; this.Figure = strArray[2]; this.X = int.Parse(strArray[3]); this.Y = int.Parse(strArray[4]); this.Z1 = byte.Parse(strArray[5]); this.Z2 = this.Z1; this.goalX = -1; this.freeRoam = strArray[6] == "1"; this.noShoutingMessage = strArray[7]; this.7AAA1 = DB.runReadColumn("SELECT text FROM roombots_texts WHERE id = '" + botID + "' AND type = 'say'", 0); this.8AAAA = DB.runReadColumn("SELECT text FROM roombots_texts WHERE id = '" + botID + "' AND type = 'shout'", 0); string[] strArray2 = DB.runReadColumn("SELECT words FROM roombots_texts_triggers WHERE id = '" + botID + "' ORDER BY id ASC", 0); if (strArray2.Length > 0) { string[] strArray3 = DB.runReadColumn("SELECT replies FROM roombots_texts_triggers WHERE id = '" + botID + "' ORDER BY id ASC", 0); string[] strArray4 = DB.runReadColumn("SELECT serve_replies FROM roombots_texts_triggers WHERE id = '" + botID + "' ORDER BY id ASC", 0); string[] strArray5 = DB.runReadColumn("SELECT serve_item FROM roombots_texts_triggers WHERE id = '" + botID + "' ORDER BY id ASC", 0); this.BAAAA = new ᙄ[strArray2.Length]; for (int i = 0; i < strArray2.Length; i++) { this.BAAAA[i] = new ᙄ(strArray2[i].Split(new char[] { '}' }), strArray3[i].Split(new char[] { '}' }), strArray4[i].Split(new char[] { '}' }), strArray5[i]); } } int[] numArray = DB.runReadColumn("SELECT x FROM roombots_coords WHERE id = '" + botID + "' ORDER BY id ASC", 0, null); this.9AAA1 = new Coord[numArray.Length + 1]; this.9AAA1[numArray.Length] = new Coord(this.X, this.Y); if (numArray.Length > 1) { int[] numArray2 = DB.runReadColumn("SELECT y FROM roombots_coords WHERE id = '" + botID + "' ORDER BY id ASC", 0, null); for (int j = 0; j < numArray.Length; j++) { this.9AAA1[j] = new Coord(numArray[j], numArray2[j]); } } this.10AA1 = new Hashtable(); this.6AAAA = new Thread(new ThreadStart(this.AI)); this.6AAAA.Priority = ThreadPriority.BelowNormal; this.6AAAA.Start(); } internal void addStatus(string Key, string Value) { if (this.10AA1.ContainsKey(Key)) { this.10AA1.Remove(Key); } this.10AA1.Add(Key, Value); } private void AI() { Coord coord; int num = -1; Random random = new Random(this.roomUID * DateTime.Now.Millisecond); Label_001D: while (this.CAAA1 != null) { } switch (random.Next(0, 15)) { case 1: { coord = new Coord(); if (!this.freeRoam) { coord = this.9AAA1[random.Next(0, this.9AAA1.Length)]; break; } int[] numArray = this.Room.getMapBorders(); coord = new Coord(random.Next(0, numArray[0]), random.Next(0, numArray[1])); break; } case 2: { byte r = (byte) random.Next(0, 10); while (r == this.Z2) { r = (byte) random.Next(0, 10); } this.Rotate(r); goto Label_024B; } case 3: if (this.8AAAA.Length > 0) { int index = random.Next(0, this.8AAAA.Length); if (this.8AAAA.Length > 1) { while (index == num) { index = random.Next(0, this.8AAAA.Length); } num = index; } this.Room.sendShout(this, this.8AAAA[index]); } goto Label_024B; case 4: if (this.7AAA1.Length > 0) { int num5 = random.Next(0, this.7AAA1.Length); if (this.7AAA1.Length > 1) { while (num5 == num) { num5 = random.Next(0, this.7AAA1.Length); } num = num5; } this.Room.sendSaying(this, this.7AAA1[num5]); } goto Label_024B; case 5: if (random.Next(0, 2) != 0) { this.addStatus("dance", "3"); this.Refresh(); } else { this.10AA1.Remove("dance"); this.handleStatus("wave", "", Config.Statuses_Wave_waveDuration); } goto Label_024B; default: goto Label_024B; } if ((coord.X == this.X) && (coord.Y == this.Y)) { this.Z1 = (byte) random.Next(0, 10); this.Z2 = this.Z1; this.Refresh(); } else { this.goalX = coord.X; this.goalY = coord.Y; } Label_024B: Thread.Sleep(0xbb8); Out.WriteTrace("Bot AI loop"); goto Label_001D; } internal void checkOrders() { if (this.CAAA1 != null) { this.goalX = -1; this.Rotate(this.CAAA1.X, this.CAAA1.Y); this.removeStatus("carryd"); this.Room.sendSaying(this, this.00AAA.serveReply); if (!this.CAAA1.statusManager.containsStatus("sit")) { this.CAAA1.Z1 = Rotation.Calculate(this.CAAA1.X, this.CAAA1.Y, this.X, this.Y); this.CAAA1.Z2 = this.CAAA1.Z1; } this.CAAA1.statusManager.carryItem(this.00AAA.serveItem); this.CAAA1 = null; this.00AAA = null; } } internal bool containsStatus(string Key) { return this.10AA1.ContainsKey(Key); } internal Coord getClosestWalkCoordTo(int X, int Y) { int num = 6; Coord coord = new Coord(-1, 0); foreach (Coord coord2 in this.9AAA1) { int num2 = Math.Abs((int) (X - coord2.X)) + Math.Abs((int) (Y - coord2.Y)); if (num2 < num) { num = num2; coord = coord2; } } return coord; } internal void handleStatus(string Key, string Value, int Length) { if (this.10AA1.ContainsKey(Key)) { this.10AA1.Remove(Key); } new ᙃ(this.HANDLESTATUS).BeginInvoke(Key, Value, Length, null, null); } private void HANDLESTATUS(string Key, string Value, int Length) { try { this.10AA1.Add(Key, Value); this.Refresh(); Thread.Sleep(Length); this.10AA1.Remove(Key); this.Refresh(); } catch { } } internal void Interact(virtualRoomUser roomUser, string Message) { Message = Message.ToLower(); string[] strArray = Message.Split(new char[] { ' ' }); if (this.BAAAA != null) { foreach (virtualBot.ᙄ ᙄ in this.BAAAA) { for (int i = 0; i < strArray.Length; i++) { if (ᙄ.containsWord(strArray[i])) { if (ᙄ.serveItem != "") { if (this.CAAA1 == null) { Coord coord = this.getClosestWalkCoordTo(roomUser.X, roomUser.Y); if (coord.X != -1) { this.Room.sendSaying(this, ᙄ.Reply); this.removeStatus("dance"); this.addStatus("carryd", ᙄ.serveItem); this.goalX = coord.X; this.goalY = coord.Y; this.CAAA1 = roomUser; this.00AAA = ᙄ; } } } else { this.Z1 = Rotation.Calculate(this.X, this.Y, roomUser.X, roomUser.Y); this.Z2 = this.Z1; this.Room.sendSaying(this, ᙄ.Reply); } return; } } } } } internal void Kill() { try { this.6AAAA.Abort(); } catch { } this.6AAAA = null; this.Room = null; this.10AA1 = null; this.9AAA1 = null; this.7AAA1 = null; this.8AAAA = null; this.BAAAA = null; this.CAAA1 = null; this.00AAA = null; } internal void Refresh() { this.Room.Refresh(this); } internal void removeStatus(string Key) { try { if (this.10AA1.ContainsKey(Key)) { this.10AA1.Remove(Key); } } catch { } } internal void Rotate(byte R) { if ((R != this.Z1) && !this.10AA1.ContainsKey("sit")) { this.Z1 = R; this.Z2 = R; this.Refresh(); } } internal void Rotate(int toX, int toY) { this.Rotate(Rotation.Calculate(this.X, this.Y, toX, toY)); } internal string detailsString { get { string str = string.Concat(new object[] { "i:", this.roomUID, Convert.ToChar(13), "a:-1", Convert.ToChar(13), "n:", this.Name, Convert.ToChar(13), "f:", this.Figure, Convert.ToChar(13), "l:", this.X, " ", this.Y, " ", this.H, Convert.ToChar(13) }); if (this.Mission != "") { object obj2 = str; str = string.Concat(new object[] { obj2, "c:", this.Mission, Convert.ToChar(13) }); } return (str + "[bot]" + Convert.ToChar(13)); } } internal string statusString { get { string str = string.Concat(new object[] { this.roomUID, " ", this.X, ",", this.Y, ",", this.H.ToString().Replace(",", "."), ",", this.Z1, ",", this.Z2, "/" }); foreach (string str2 in this.10AA1.Keys) { str = str + str2; string str3 = (string) this.10AA1[str2]; if (str3 != "") { str = str + " " + str3; } str = str + "/"; } return str; } } private class ᙄ { private string[] ᙅ; private string[] 4AAAA; private string[] 5AAA1; internal string serveItem; internal ᙄ(string[] Words, string[] Replies, string[] serveReplies, string serveItem) { this.ᙅ = Words; this.4AAAA = Replies; this.5AAA1 = serveReplies; this.serveItem = serveItem; } internal bool containsWord(string Word) { if (Word.Substring(Word.Length - 1, 1) == "?") { Word = Word.Substring(0, Word.Length - 1); } for (int i = 0; i < this.ᙅ.Length; i++) { if (this.ᙅ[i] == Word) { return true; } } return false; } internal string Reply { get { return this.4AAAA[new Random(DateTime.Now.Millisecond).Next(0, this.4AAAA.Length)]; } } internal string serveReply { get { return this.5AAA1[new Random(DateTime.Now.Millisecond).Next(0, this.5AAA1.Length)]; } } } private delegate void ᙃ(string Key, string Value, int Length); } }