using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using Blizzard.HabboHotel.Rooms; using Blizzard.HabboHotel.Users; namespace Blizzard { class RoomsData { internal int Id; internal string Name; internal string Description; internal int OwnerId; internal string OwnerName; internal int State; internal int MaxUsers; internal int Score; internal int Category; internal string Tags; internal string Model; internal bool IsPublicRoom; internal int IconBackground; internal int IconForeground; internal Dictionary Icons; internal string WallPaper; internal string FloorPaper; internal string LandScape; internal bool WalkOnOtherUsers; internal bool HideWalls; internal bool Pets; internal bool PetsEat; internal int CurrentUsersInRoom; internal List UserList; internal List TagList; internal List FloorItems; internal List WallItems; internal bool BattleOnGame; internal bool BattlePause; internal bool FreezeOnGame; internal bool FreezePause; internal double[,] HeightMap; internal TileState[,] Matrix; internal RoomModel GetRoomModel() { return RoomModel.RoomModelByName[Model]; } public void GenerateMatrix() { Room R = StaticGame.VirtualRooms[this.Id]; this.Matrix = new TileState[this.GetRoomModel().MapSizeX, this.GetRoomModel().MapSizeY]; this.HeightMap = new double[this.GetRoomModel().MapSizeX, this.GetRoomModel().MapSizeY]; for (short y = 0; y < this.GetRoomModel().MapSizeY; y++) { for (short x = 0; x < this.GetRoomModel().MapSizeX; x++) { HeightMap[x, y] = this.GetRoomModel().DefaultHeightMap[x, y]; iPoint Point = new iPoint(x, y); if (R.GetItemsForXY(x, y).Count > 0) { foreach (RoomItem Item in R.GetItemsForXY(x, y)) { if (Item.GetBaseItem().CanSit) { Matrix[x, y] = TileState.Walkable_laststep; } else if (!R.IsItemOnXY(Point.X, Point.Y)) { Matrix[x, y] = TileState.Walkable; } else { Matrix[x, y] = TileState.Blocked; } } } else { Matrix[x, y] = this.GetRoomModel().DefaultTiles[x, y]; } } } } public static List AllRoom; public static Dictionary Rooms; public static int GetLastId() { int i = 0; foreach (RoomsData U in AllRoom) { if (U.Id > i) i = U.Id; else continue; } return i; } public static void InitRooms() { AllRoom = new List(); Rooms = new Dictionary(); DataRow AllRooms = BlizzardSystem.MySQL.ReadDataRow("SELECT * FROM rooms"); foreach (DataRow Row in AllRooms.Table.Rows) { RoomsData R = new RoomsData(); R.Id = (int)Row["id"]; R.OwnerId = (int)Row["ownerid"]; if (UsersData.UsersRegister.ContainsKey(R.OwnerId)) { R.OwnerName = (UsersData.UsersRegister[R.OwnerId]).UserName; } R.Name = (string)Row["name"]; R.Description = (string)Row["description"]; R.State = int.Parse(Row["state"].ToString()); R.MaxUsers = int.Parse(Row["maxusers"].ToString()); R.Score = (int)Row["score"]; R.Category = int.Parse(Row["category"].ToString()); R.Tags = (string)Row["tags"]; R.TagList = new List(); if (R.Tags.Contains(";")) { string[] Separe = R.Tags.Split(';'); foreach (string s in Separe) { R.TagList.Add(s); } } R.Model = (string)Row["model"]; R.IsPublicRoom = BlizzardSystem.ConvertEnumToBool(Row["public_room"].ToString()); R.IconBackground = int.Parse(Row["icon_bg"].ToString()); R.IconForeground = int.Parse(Row["icon_fg"].ToString()); R.Icons = new Dictionary(); foreach(RoomIcon Icon in RoomIcon.Icons) { if (Icon.RoomId == R.Id) R.Icons.Add(Icon.Pos, Icon.Item); } R.WallPaper = Row["wall"].ToString(); R.FloorPaper = Row["floor"].ToString(); R.LandScape = Row["landscape"].ToString(); R.HideWalls = BlizzardSystem.ConvertEnumToBool(Row["hidewalls"].ToString()); R.Pets = BlizzardSystem.ConvertEnumToBool(Row["pets"].ToString()); R.PetsEat = BlizzardSystem.ConvertEnumToBool(Row["petseat"].ToString()); R.WalkOnOtherUsers = BlizzardSystem.ConvertEnumToBool(Row["walkonusers"].ToString()); R.CurrentUsersInRoom = 0; R.UserList = new List(); R.WallItems = new List(); R.FloorItems = new List(); R.BattleOnGame = false; R.BattlePause = false; R.FreezeOnGame = false; R.FreezePause = false; AllRoom.Add(R); Rooms.Add(R.Id, R); } BlizzardSystem.WriteLine("@Server >> Added " + Rooms.Count + " rooms to static system"); } public static List GetRoomsForCategory(int Id) { List R = new List(); foreach (RoomsData Ro in AllRoom) { if (Ro.Category == Id) R.Add(Ro); } return R; } public static void AddNewRoom(int RoomId, int UserId, string RoomName, string RoomModel) { RoomsData R = new RoomsData(); R.Id = RoomId; R.OwnerId = UserId; if (UsersData.UsersRegister.ContainsKey(R.OwnerId)) { R.OwnerName = (UsersData.UsersRegister[R.OwnerId]).UserName; } R.Name = RoomName; R.Description = ""; R.State = 0; R.MaxUsers = 10; R.Score = 0; R.Category = 0; R.Tags = ""; R.Model = RoomModel; R.IsPublicRoom = false; R.IconBackground = 0; R.IconForeground = 0; R.WallPaper = "0.0"; R.FloorPaper = "0.0"; R.LandScape = "0.0"; R.HideWalls = false; R.Pets = false; R.PetsEat = false; R.WalkOnOtherUsers = true; R.CurrentUsersInRoom = 0; R.UserList = new List(); R.FloorItems = new List(); R.WallItems = new List(); R.Icons = new Dictionary(); R.TagList = new List(); R.BattleOnGame = false; R.BattlePause = false; R.FreezeOnGame = false; R.FreezePause = false; AllRoom.Add(R); Rooms.Add(R.Id, R); } } class RoomIcon { internal int RoomId; internal int Pos; internal int Item; public static List Icons; public static Dictionary RegisteredIcons; public static void InitIcons() { DataRow Data = BlizzardSystem.MySQL.ReadDataRow("SELECT * FROM rooms_icons"); Icons = new List(); RegisteredIcons = new Dictionary(); foreach (DataRow Row in Data.Table.Rows) { RoomIcon I = new RoomIcon(); I.RoomId = (int)Row["roomid"]; I.Pos = (int)Row["itempos"]; I.Item = (int)Row["itemid"]; Icons.Add(I); } } } class RoomCategory { internal int Id; internal int MinRank; internal string Caption; public static List Categorys; public static void InitCategorys() { Categorys = new List(); DataRow Data = BlizzardSystem.MySQL.ReadDataRow("SELECT * FROM navigator_categories ORDER BY id DESC"); foreach (DataRow Row in Data.Table.Rows) { RoomCategory C = new RoomCategory(); C.Id = (int)Row["id"]; C.MinRank = (int)Row["min_rank"]; C.Caption = (string)Row["caption"]; Categorys.Add(C); } } public static int CountCategorysForMyRank(int Rank) { int i = 0; foreach(RoomCategory Cat in Categorys) { if (Cat.MinRank > Rank) continue; else i++; } return i; } } public enum SquareState { OPEN = 0, BLOCKED = 1, SEAT = 2 } class RoomModel { internal string Model; internal int DoorX; internal int DoorY; internal int DoorZ; internal int DoorDir; internal string HeightMap; internal int MapSizeX { get { return Lines[0].Length; } } internal int MapSizeY { get { return Lines.Count; } } internal int Area; internal string Items; internal bool ClubOnly; internal string Map; internal TileState[,] DefaultTiles; internal double[,] DefaultHeightMap; internal List Lines = new List(); public static List RoomModels; public static Dictionary RoomModelByName; public static void InitModels() { try { RoomModels = new List(); RoomModelByName = new Dictionary(); DataRow Data = BlizzardSystem.MySQL.ReadDataRow("SELECT * FROM rooms_models"); foreach (DataRow Row in Data.Table.Rows) { RoomModel M = new RoomModel(); M.Model = (string)Row["model_name"]; M.DoorX = (int)Row["door_x"] - 1; M.DoorY = (int)Row["door_y"]; M.DoorZ = (int)Row["door_z"]; M.DoorDir = (int)Row["door_dir"]; M.HeightMap = (string)Row["heightmap"]; M.Map = M.HeightMap; M.Items = (string)Row["items"]; M.ClubOnly = BlizzardSystem.ConvertEnumToBool(Row["club_only"].ToString()); M.GenerateLines(); RoomModels.Add(M); RoomModelByName.Add(M.Model, M); } BlizzardSystem.WriteLine("@Server >> Added " + RoomModels.Count + " models to the static system"); } catch (Exception e) { BlizzardSystem.WriteLine(e.ToString()); } } private void GenerateLines() { // Add Lines to List Map.Replace(Convert.ToChar(10).ToString(), "").Split('\r').ToList().ForEach(Lines.Add); try { GetPremairParams(); GetSecondairParams(); } catch (Exception e) { BlizzardSystem.WriteLine(e.ToString()); // error } } public string GetPremairParams() { StringBuilder Builder = new StringBuilder(); for (short y = 0; y < MapSizeY; y++) { string Line = Lines[y]; Builder.AppendLine(Line); } return Builder.ToString().Replace(Convert.ToChar(10).ToString(), ""); } public string GetSecondairParams() { DefaultTiles = new TileState[MapSizeX, MapSizeY]; DefaultHeightMap = new double[MapSizeX, MapSizeY]; StringBuilder Builder = new StringBuilder(); for (short y = 0; y < MapSizeY; y++) { string FixedLine = string.Empty; for (short x = 0; x < MapSizeX; x++) { string Character = Lines[y][x].ToString().Trim().ToLower(); double HeightMapChar = 0.0; double.TryParse(Character, out HeightMapChar); DefaultHeightMap[x, y] = HeightMapChar; if (x == DoorX && y == DoorY) { DefaultTiles[x, y] = TileState.Walkable_laststep; DefaultHeightMap[x, y] = DoorZ; FixedLine += DoorZ; } else { if (Character == "x") { DefaultTiles[x, y] = TileState.Blocked; } else { DefaultTiles[x, y] = TileState.Walkable; } FixedLine += Character; } } Builder.AppendLine(FixedLine); } return Builder.ToString().Replace(Convert.ToChar(10).ToString(), ""); } private static bool isNumeric(string cadena) { try { int.Parse(cadena); return true; } catch (Exception e) { return false; } } } class RoomItem { internal int Id; internal int RoomId; internal int FurniId; internal string ExtraData; internal int X; internal int Y; internal string W; internal int Rot; internal string Mood; internal bool IsWall; internal bool IsModify = false; internal bool IsWiredModify = false; internal List WiredItems; internal string WiredString; internal ItemsData GetBaseItem() { return ItemsData.RegisteredFurnis[FurniId]; } internal Coord SquareInFront { get { Coord Sq = new Coord(X, Y); if (Rot == 0) { Sq.Y--; } else if (Rot == 2) { Sq.X++; } else if (Rot == 4) { Sq.Y++; } else if (Rot == 6) { Sq.X--; } return Sq; } } internal Coord SquareInFront2 { get { Coord Sq = new Coord(X, Y); Sq.X--; return Sq; } } internal Coord SquareDer2 { get { Coord Sq = new Coord(X, Y); Sq.Y--; return Sq; } } internal Coord SquareIzq2 { get { Coord Sq = new Coord(X, Y); Sq.Y++; return Sq; } } internal Coord SquareDer { get { Coord Sq = new Coord(X, Y); Sq.X++; return Sq; } } internal Coord SquareIzq { get { Coord Sq = new Coord(X, Y); Sq.X--; return Sq; } } internal Coord SquareBehind2 { get { Coord Sq = new Coord(X, Y); Sq.X++; return Sq; } } internal Coord SquareBehind { get { Coord Sq = new Coord(X, Y); if (Rot == 0) { Sq.Y++; } else if (Rot == 2) { Sq.X--; } else if (Rot == 4) { Sq.Y--; } else if (Rot == 6) { Sq.X++; } return Sq; } } internal List GetSquareBehind(int count) { List Squ = new List(); int i = 0; while(i != count) { Squ.Add(new Coord(X, (Y -= 1 + i))); i++; } return Squ; } internal List GetSquareInFront(int count) { List Squ = new List(); for (int i = 0; i < count; ) { Squ.Add(new Coord(X, (Y += 1 + i))); i++; } return Squ; } internal List GetSquareDer(int count) { List Squ = new List(); for (int i = 0; i < count; ) { Squ.Add(new Coord((X += 1 + i), Y)); i++; } return Squ; } internal List GetSquareIzq(int count) { List Squ = new List(); for (int i = 0; i < count; ) { Squ.Add(new Coord((X -= 1 + i), Y)); i++; } return Squ; } internal void UpdateState(Habbo User) { if (!IsWall) { ServerMessage Message = new ServerMessage("AX"); Message.AddStringWithBreak(Id.ToString()); Message.AddStringWithBreak(ExtraData); StaticGame.SSendPacketToAllRoom(User.CurrentRoomId, Message); } } public static List Items; public static Dictionary RegisteredItems; public static int GetLastId() { int i = 0; foreach (RoomItem U in Items) { if (U.Id > i) i = U.Id; else continue; } return i; } public static void InitItems() { Items = new List(); RegisteredItems = new Dictionary(); DataRow Data = BlizzardSystem.MySQL.ReadDataRow("SELECT * FROM rooms_items"); foreach (DataRow Row in Data.Table.Rows) { RoomItem I = new RoomItem(); I.Id = (int)Row["id"]; I.RoomId = (int)Row["room_id"]; I.FurniId = (int)Row["furni_id"]; I.ExtraData = (string)Row["extradata"]; I.X = (int)Row["x"]; I.Y = (int)Row["y"]; I.W = (string)Row["w"]; I.Rot = (int)Row["rot"]; I.Mood = (string)Row["moodlight"]; if (I.W == "") I.IsWall = false; else I.IsWall = true; I.WiredString = (string)Row["wired_string"]; I.WiredItems = new List(); string sWiredItems = (string)Row["wired_items"]; if (sWiredItems != "") { if (sWiredItems.Contains(";")) { foreach(string s in sWiredItems.Split(';')) { I.WiredItems.Add(int.Parse(s)); } } else I.WiredItems.Add(int.Parse(sWiredItems)); } Items.Add(I); RegisteredItems.Add(I.Id, I); } BlizzardSystem.WriteLine("@Server >> Added " + Items.Count + " room items"); } } class RoomRights { internal int UserId; internal int RoomId; public static List Rights; public static List GetRightsForRoom(int RoomId) { List r = new List(); foreach (RoomRights R in Rights) { if (R.RoomId == RoomId) r.Add(R); } return r; } public static void InitRights() { Rights = new List(); DataRow Data = BlizzardSystem.MySQL.ReadDataRow("SELECT * FROM rooms_rights"); foreach (DataRow Row in Data.Table.Rows) { RoomRights R = new RoomRights(); R.UserId = (int)Row["userid"]; R.RoomId = (int)Row["roomid"]; Rights.Add(R); } } } class RoomEvent { internal int RoomId; internal int CategoryId; internal string Title; internal string Description; internal List Tags; internal string StartTime; public static List Events; public static void InitEvents() { Events = new List(); BlizzardSystem.WriteLine("@Server >> RoomEvent static system initialized"); } public static List GetEventForCategorys(int CategoryId) { if (CategoryId == 0 || CategoryId == -1) return Events; else { List E = new List(); foreach (RoomEvent e in Events) { if (e.CategoryId == CategoryId) E.Add(e); else continue; } return E; } } public static RoomEvent GetEventForRoom(int RoomId) { foreach (RoomEvent E in Events) { if (E.RoomId == RoomId) return E; else continue; } return null; } public static bool HasEvent(int RoomId) { if (GetEventForRoom(RoomId) == null) return false; else return true; } } }