namespace Holo.Virtual.Rooms.Pets { using Holo; using Holo.Virtual.Rooms; using Holo.Virtual.Rooms.Pathfinding; using Holo.Virtual.Users; using Ion.Storage; using System; using System.Collections; using System.Data; using System.Runtime.CompilerServices; using System.Threading; internal class virtualPet { private Hashtable _Items; private virtualRoom _Room; private Thread aiHandler; private chatTrigger[] chatTriggers; internal string Colour; private Coord[] Coords; internal int goalX; internal int goalY; internal double H; internal int ID; internal string Name; internal string Race; internal virtualRoom Room; internal int roomUID; private string[] Sayings; private string[] Shouts; private Hashtable Statuses; internal int Type; internal int X; internal int Y; internal byte Z1; internal byte Z2; internal virtualPet(int petID, int roomUID, virtualRoom Room, int mX, int mY) { DataRow row; DataColumn column; DataTable table; this._Items = new Hashtable(); this.roomUID = roomUID; this.Room = Room; this.ID = petID; using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { row = client.getRow("SELECT * FROM pets WHERE id = '" + petID + "'"); client.runQuery(string.Concat(new object[] { "UPDATE pets SET roomid = '", Room.roomID, "' WHERE id = '", this.ID, "'" })); } this.Name = row["name"].ToString(); this.Type = int.Parse(row["type"].ToString()); this.Race = row["race"].ToString(); this.Colour = row["colour"].ToString(); if ((mX == 0) && (mY == 0)) { Coord coord = new Coord(); int[] numArray = Room.getMapBorders(); Random random = new Random(roomUID * DateTime.Now.Millisecond); coord = new Coord(random.Next(0, numArray[0]), random.Next(0, numArray[1])); this.X = coord.X; this.Y = coord.Y; this.Z1 = Room.sqFLOORHEIGHT[this.X, this.Y]; } else { this.X = mX; this.Y = mY; this.Z1 = 1; } this.Z2 = this.Z1; this.goalX = -1; using (DatabaseClient client2 = Eucalypt.dbManager.GetClient()) { column = client2.getColumn("SELECT text FROM pets_texts WHERE animal = '" + this.Type + "' AND type = 'say'"); } this.Sayings = dataHandling.dColToArray(column); using (DatabaseClient client3 = Eucalypt.dbManager.GetClient()) { column = client3.getColumn("SELECT text FROM pets_texts WHERE animal = '" + this.Type + "' AND type = 'shout'"); } this.Shouts = dataHandling.dColToArray(column); using (DatabaseClient client4 = Eucalypt.dbManager.GetClient()) { table = client4.getTable("SELECT words, replies, serve_replies, serve_item FROM pets_texts_triggers"); } this.chatTriggers = new chatTrigger[table.Rows.Count]; int index = 0; foreach (DataRow row2 in table.Rows) { this.chatTriggers[index] = new chatTrigger(Convert.ToString(row2["words"]).ToLower().Split(new char[] { '}' }), Convert.ToString(row2["replies"]).Split(new char[] { '}' }), Convert.ToString(row2["serve_replies"]).Split(new char[] { '}' }), Convert.ToString(row2["serve_item"])); index++; } this.Statuses = new Hashtable(); this.aiHandler = new Thread(new ThreadStart(this.AI)); this.aiHandler.Priority = ThreadPriority.BelowNormal; this.aiHandler.Start(); } internal void addStatus(string Key, string Value) { if (this.Statuses.ContainsKey(Key)) { this.Statuses.Remove(Key); } this.Statuses.Add(Key, Value); } private void AI() { int num4; int num = -1; Random random = new Random(this.roomUID * DateTime.Now.Millisecond); Label_001D: switch (random.Next(0, 6)) { case 1: { this.Statuses.Remove("jmp"); this.Statuses.Remove("sit"); this.Statuses.Remove("ded"); Coord coord = new Coord(); int[] numArray = this.Room.getMapBorders(); coord = new Coord(random.Next(0, numArray[0]), random.Next(0, numArray[1])); if ((coord.X != this.X) || (coord.Y != this.Y)) { this.goalX = coord.X; this.goalY = coord.Y; } else { this.Z1 = (byte) random.Next(0, 10); this.Z2 = this.Z1; this.Refresh(); } goto Label_01F5; } case 2: { byte r = (byte) random.Next(0, 10); while (r == this.Z2) { r = (byte) random.Next(0, 10); } this.Rotate(r); goto Label_01F5; } case 3: if (this.Shouts.Length <= 0) { goto Label_01F5; } num4 = random.Next(0, this.Shouts.Length); if (this.Shouts.Length > 1) { while (num4 == num) { num4 = random.Next(0, this.Shouts.Length); } num = num4; } break; case 4: if (this.Sayings.Length > 0) { int index = random.Next(0, this.Sayings.Length); if (this.Sayings.Length > 1) { while (index == num) { index = random.Next(0, this.Sayings.Length); } num = index; } this.Room.sendSaying(this, this.Sayings[index]); } goto Label_01F5; default: goto Label_01F5; } this.Room.sendShout(this, this.Shouts[num4]); Label_01F5: Thread.Sleep(0xbb8); Out.WriteTrace("Bot AI loop"); goto Label_001D; } internal bool containsStatus(string Key) { return this.Statuses.ContainsKey(Key); } internal Coord getClosestWalkCoordTo(int X, int Y) { int num = 6; Coord coord = new Coord(-1, 0); foreach (Coord coord2 in this.Coords) { 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.Statuses.ContainsKey(Key)) { this.Statuses.Remove(Key); } new statusVoid(this.HANDLESTATUS).BeginInvoke(Key, Value, Length, null, null); } private void HANDLESTATUS(string Key, string Value, int Length) { try { this.Statuses.Add(Key, Value); this.Refresh(); Thread.Sleep(Length); this.Statuses.Remove(Key); this.Refresh(); } catch { } } internal void Interact(virtualRoomUser roomUser, string Message) { Message = Message.ToLower(); string[] strArray = Message.Split(new char[] { ' ' }); if ((this.chatTriggers != null) && (strArray[0] == this.Name)) { foreach (chatTrigger trigger in this.chatTriggers) { for (int i = 0; i < strArray.Length; i++) { if (trigger.containsWord(strArray[i])) { this.Z1 = Rotation.Calculate(this.X, this.Y, roomUser.X, roomUser.Y); this.Z2 = this.Z1; this.Room.sendSaying(this, trigger.Reply); return; } } } switch (strArray[1]) { case "spill d\x00f8d": case "d\x00f8d": case "play dead": case "d\x00e3\x00b8d": this.Statuses.Remove("sit"); this.Statuses.Remove("jmp"); this.addStatus("ded", ""); return; case "jump": case "hopp": this.Statuses.Remove("sit"); this.Statuses.Remove("ded"); this.addStatus("jmp", ""); return; case "kom": { Coord coord = new Coord(); this.Room.getMapBorders(); coord = new Coord(roomUser.X - 1, roomUser.Y); this.goalX = coord.X; this.goalY = coord.Y; return; } default: return; } } } internal void Kill() { try { this.aiHandler.Abort(); } catch { } this.aiHandler = null; this.Room = null; this.Statuses = null; this.Coords = null; this.Sayings = null; this.Shouts = null; this.chatTriggers = null; } internal void Refresh() { this.Room.Refresh(this); } internal void removeItem(int itemID, int ownerID) { if (this._Items.ContainsKey(itemID)) { this._Room.sendData("AT" + itemID + Convert.ToChar(2)); this._Items.Remove(itemID); using (DatabaseClient client = Eucalypt.dbManager.GetClient()) { if (ownerID > 0) { client.runQuery(string.Concat(new object[] { "UPDATE furniture SET ownerid = '", ownerID, "',roomid = '0',pickedup = '", Convert.ToString(DateTime.Now), "' WHERE id = '", itemID, "' LIMIT 1" })); } else { client.runQuery("DELETE FROM furniture WHERE id = '" + itemID + "' LIMIT 1"); } } } } internal void removeStatus(string Key) { try { if (this.Statuses.ContainsKey(Key)) { this.Statuses.Remove(Key); } } catch { } } internal void Rotate(byte R) { if ((R != this.Z1) && !this.Statuses.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 { return string.Concat(new object[] { Encoding.encodeVL64(this.ID), this.Name, Convert.ToChar(2), Convert.ToChar(2), this.Type, Convert.ToChar(0x20), this.Race, Convert.ToChar(0x20), this.Colour, Convert.ToChar(2), Encoding.encodeVL64(this.roomUID), Encoding.encodeVL64(this.X), Encoding.encodeVL64(this.Y), "0.0", Convert.ToChar(2), Encoding.encodeVL64(0), Encoding.encodeVL64(2), Encoding.encodeVL64(this.Type) }); } } internal string statusString { get { string str = string.Concat(new object[] { Encoding.encodeVL64(this.roomUID), Encoding.encodeVL64(this.X), Encoding.encodeVL64(this.Y), this.H.ToString().Replace(",", "."), Convert.ToChar(2), Encoding.encodeVL64(this.Z1), Encoding.encodeVL64(this.Z2) }); foreach (string str2 in this.Statuses.Keys) { str = str + str2; string str3 = (string) this.Statuses[str2]; if (str3 != "") { str = str + " " + str3; } str = str + "/"; } return str; } } private class chatTrigger { private string[] Replies; private string[] serve_item; private string[] serve_replies; private string[] Words; internal chatTrigger(string[] Words, string[] Replies, string[] serve_replies, string serve_item) { this.Words = Words; this.Replies = Replies; this.serve_replies = serve_replies; } 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.Words.Length; i++) { if (this.Words[i] == Word) { return true; } } return false; } internal string Reply { get { return this.Replies[new Random(DateTime.Now.Millisecond).Next(0, this.Replies.Length)]; } } } private delegate void statusVoid(string Key, string Value, int Length); } }