using System; using System.Collections.Generic; using Butterfly.HabboHotel.GameClients; using Butterfly.HabboHotel.Misc; using Butterfly.HabboHotel.Pathfinding; using Butterfly.HabboHotel.Pets; using Butterfly.HabboHotel.RoomBots; using Butterfly.Messages; namespace Butterfly.HabboHotel.Rooms { class RoomUser { internal UInt32 HabboId; internal Int32 VirtualId; internal UInt32 RoomId; internal int IdleTime; //internal int Steps; internal int X; internal int Y; internal double Z; internal byte SqState; internal int AchievementPoints; internal int CarryItemID; internal int CarryTimer; internal int RotHead; internal int RotBody; internal bool CanWalk; internal bool AllowOverride; internal int GoalX; internal int GoalY; internal Boolean SetStep; internal int SetX; internal int SetY; internal double SetZ; internal RoomBot BotData; internal BotAI BotAI; internal SwimType CurrentSwimType; internal bool Freezed; internal Coord Coordinate { get { return new Coord(X, Y); } } internal bool IsPet { get { return (IsBot && BotData.IsPet); } } internal Pet PetData; internal Boolean IsWalking; internal Boolean UpdateNeeded; internal Boolean IsAsleep; internal Dictionary Statusses; internal int DanceId; //internal List Path; //internal int PathStep; //internal bool PathRecalcNeeded; //internal int PathRecalcX; //internal int PathRecalcY; internal int TeleDelay; internal Boolean IsDancing { get { if (DanceId >= 1) { return true; } return false; } } internal Boolean NeedsAutokick { get { if (IsBot) { return false; } if (IdleTime >= 1800) { return true; } return false; } } internal bool IsTrading { get { if (IsBot) { return false; } if (Statusses.ContainsKey("trd")) { return true; } return false; } } internal bool IsBot { get { if (this.BotData != null) { return true; } return false; } } internal bool IsSpectator; internal int InternalRoomID; internal RoomUser(uint HabboId, uint RoomId, int VirtualId) { this.Freezed = false; this.HabboId = HabboId; this.RoomId = RoomId; this.VirtualId = VirtualId; this.IdleTime = 0; this.X = 0; this.Y = 0; this.Z = 0; this.RotHead = 0; this.RotBody = 0; this.UpdateNeeded = true; this.Statusses = new Dictionary(); //this.Path = new List(); //this.PathStep = 0; this.TeleDelay = -1; this.AllowOverride = false; this.CanWalk = true; this.IsSpectator = false; this.SqState = 3; //this.Steps = 0; this.InternalRoomID = 0; this.CurrentSwimType = SwimType.Walk; } internal RoomUser(uint HabboId, uint RoomId, int VirtualId, GameClient pClient) { this.mClient = pClient; this.Freezed = false; this.HabboId = HabboId; this.RoomId = RoomId; this.VirtualId = VirtualId; this.IdleTime = 0; this.X = 0; this.Y = 0; this.Z = 0; this.RotHead = 0; this.RotBody = 0; this.UpdateNeeded = true; this.Statusses = new Dictionary(); //this.Path = new List(); //this.PathStep = 0; this.TeleDelay = -1; this.AllowOverride = false; this.CanWalk = true; this.IsSpectator = false; this.SqState = 3; //this.Steps = 0; this.InternalRoomID = 0; this.CurrentSwimType = SwimType.Walk; } internal void Unidle() { this.IdleTime = 0; if (this.IsAsleep) { this.IsAsleep = false; ServerMessage Message = new ServerMessage(486); Message.AppendInt32(VirtualId); Message.AppendBoolean(false); GetRoom().SendMessage(Message); } } internal void Chat(GameClient Session, string Message, bool Shout) { if (Session != null) { if (Session.GetHabbo().Rank < 5) { if (GetRoom().RoomMuted) return; } } Unidle(); if (!IsBot && GetClient().GetHabbo().Muted) { GetClient().SendNotif("You are muted."); return; } if (Message.StartsWith(":") && Session != null && ChatCommandHandler.Parse(Session, Message.Substring(1))) { return; } uint ChatHeader = 24; if (Shout) { ChatHeader = 26; } ServerMessage ChatMessage = new ServerMessage(ChatHeader); ChatMessage.AppendInt32(VirtualId); ChatMessage.AppendStringWithBreak(Message); ChatMessage.AppendInt32(GetSpeechEmotion(Message)); GetRoom().TurnHeads(X, Y, HabboId); GetRoom().SendMessage(ChatMessage); if (!IsBot) { GetRoom().OnUserSay(this, Message, Shout); } //if (!IsBot) //{ // //using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient()) // //{ // // dbClient.AddParamWithValue("message", Message); // // dbClient.AddParamWithValue("username", Session.GetHabbo().Username); // // dbClient.ExecuteQuery("INSERT INTO chatlogs (user_id,room_id,hour,minute,timestamp,message,user_name,full_date) VALUES ('" + Session.GetHabbo().Id + "','" + GetRoom().RoomId + "','" + DateTime.Now.Hour + "','" + DateTime.Now.Minute + "','" + UberEnvironment.GetUnixTimestamp() + "',@message,@username,'" + DateTime.Now.ToLongDateString() + "')"); // //} ^^ // //UberEnvironment.GetGame().GetRoomManager().AddChatmessage(Session.GetHabbo().Username, Session.GetHabbo().Id, RoomId, Message); //} } internal static int GetSpeechEmotion(string Message) { Message = Message.ToLower(); if (Message.Contains(":)") || Message.Contains(":d") || Message.Contains("=]") || Message.Contains("=d") || Message.Contains(":>")) { return 1; } if (Message.Contains(">:(") || Message.Contains(":@")) { return 2; } if (Message.Contains(":o")) { return 3; } if (Message.Contains(":(") || Message.Contains("=[") || Message.Contains(":'(") || Message.Contains("='[")) { return 4; } return 0; } internal void ClearMovement(bool Update) { IsWalking = false; //PathRecalcNeeded = false; //Path = new List(); Statusses.Remove("mv"); GoalX = 0; GoalY = 0; SetStep = false; SetX = 0; SetY = 0; SetZ = 0; if (Update) { UpdateNeeded = true; } } internal void MoveTo(Coord c) { MoveTo(c.X, c.Y); } internal void MoveTo(int pX, int pY) { if (GetRoom().SquareHasUsers(pX, pY)) return; Unidle(); IsWalking = true; //PathRecalcNeeded = true; //PathRecalcX = pX; //PathRecalcY = pY; GoalX = pX; GoalY = pY; } internal void UnlockWalking() { this.AllowOverride = false; this.CanWalk = true; } internal void SetPos(int pX, int pY, double pZ) { this.X = pX; this.Y = pY; this.Z = pZ; } internal void CarryItem(int Item) { this.CarryItemID = Item; if (Item > 0) { this.CarryTimer = 240; } else { this.CarryTimer = 0; } ServerMessage Message = new ServerMessage(482); Message.AppendInt32(VirtualId); Message.AppendInt32(Item); GetRoom().SendMessage(Message); } internal void SetRot(int Rotation) { SetRot(Rotation, false); } internal void SetRot(int Rotation, bool HeadOnly) { if (Statusses.ContainsKey("lay") || IsWalking) { return; } int diff = this.RotBody - Rotation; this.RotHead = this.RotBody; if (Statusses.ContainsKey("sit") || HeadOnly) { if (RotBody == 2 || RotBody == 4) { if (diff > 0) { RotHead = RotBody - 1; } else if (diff < 0) { RotHead = RotBody + 1; } } else if (RotBody == 0 || RotBody == 6) { if (diff > 0) { RotHead = RotBody - 1; } else if (diff < 0) { RotHead = RotBody + 1; } } } else if (diff <= -2 || diff >= 2) { this.RotHead = Rotation; this.RotBody = Rotation; } else { this.RotHead = Rotation; } this.UpdateNeeded = true; } internal void AddStatus(string Key, string Value) { Statusses[Key] = Value; } internal void RemoveStatus(string Key) { if (Statusses.ContainsKey(Key)) { Statusses.Remove(Key); } } //internal void ResetStatus() //{ // Statusses = new Dictionary(); //} internal void Serialize(ServerMessage Message) { // @\Ihqu@UMeth0d13haiihr-893-45.hd-180-8.ch-875-62.lg-280-62.sh-290-62.ca-1813-.he-1601-[IMRAPD4.0JImMcIrDK // MSadiePull up a pew and have a brew!hr-500-45.hd-600-1.ch-823-75.lg-716-76.sh-730-62.he-1602-75IRBPA2.0PAK if (Message == null) return; if (IsSpectator) return; //if (GetClient() == null) Could be a bot // return; //if (GetClient().GetHabbo() == null) // return; if (!IsBot) { Users.Habbo User = GetClient().GetHabbo(); Message.AppendUInt(User.Id); Message.AppendStringWithBreak(User.Username); Message.AppendStringWithBreak(User.Motto); Message.AppendStringWithBreak(User.Look); Message.AppendInt32(VirtualId); Message.AppendInt32(X); Message.AppendInt32(Y); Message.AppendStringWithBreak(Z.ToString().Replace(',', '.')); Message.AppendInt32(2); Message.AppendInt32(1); Message.AppendStringWithBreak(User.Gender.ToLower()); Message.AppendInt32(-1); Message.AppendInt32(-1); Message.AppendInt32(-1); Message.AppendStringWithBreak(""); Message.AppendInt32(0); // Achiv. points } else { Message.AppendInt32(BotAI.BaseId); Message.AppendStringWithBreak(BotData.Name); Message.AppendStringWithBreak(BotData.Motto); Message.AppendStringWithBreak(BotData.Look); Message.AppendInt32(VirtualId); Message.AppendInt32(X); Message.AppendInt32(Y); Message.AppendStringWithBreak(Z.ToString().Replace(',', '.')); Message.AppendInt32(4); Message.AppendInt32((BotData.AiType == AIType.Pet) ? 2 : 3); if (BotData.AiType == AIType.Pet) { Message.AppendInt32(0); } } } internal void SerializeStatus(ServerMessage Message) { if (IsSpectator) { return; } Message.AppendInt32(VirtualId); Message.AppendInt32(X); Message.AppendInt32(Y); Message.AppendStringWithBreak(Z.ToString().Replace(',','.')); Message.AppendInt32(RotHead); Message.AppendInt32(RotBody); Message.AppendString("/"); foreach (KeyValuePair Status in Statusses) { Message.AppendString(Status.Key); Message.AppendString(" "); Message.AppendString(Status.Value); Message.AppendString("/"); } Message.AppendStringWithBreak("/"); } private GameClient mClient; internal GameClient GetClient() { if (IsBot) { return null; } if (mClient == null) mClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByHabbo(HabboId); return mClient; } private Room mRoom; private Room GetRoom() { if (mRoom == null) mRoom = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(RoomId); return mRoom; } } internal enum SwimType { Deep, Normal, Walk } }