using System; using Hang.HabboHotel.Rooms; using Hang.Messages; using Hang.Storage; namespace Hang.HabboHotel.Pets { class Pet { public uint PetId; public uint OwnerId; public int VirtualId; public uint Type; public string Name; public string Race; public string Color; public int Expirience; public int Energy; public int Nutrition; public uint RoomId; public int X; public int Y; public double Z; public int Respect; public double CreationStamp; public bool PlacedInRoom; public int[] experienceLevels = new int[] { 100, 200, 400, 600, 1000, 1300, 1800, 2400, 3200, 4300, 7200, 8500, 10100, 13300, 17500, 23000, 51900 }; // ty scott public Room Room { get { if (!IsInRoom) { return null; } return HangEnvironment.GetGame().GetRoomManager().GetRoom(RoomId); } } public bool IsInRoom { get { return (RoomId > 0); } } public int Level { get { for (int level = 0; level < experienceLevels.Length; ++level) { if (Expirience < experienceLevels[level]) return level + 1; } return experienceLevels.Length + 1; } } public int MaxLevel { get { return 20; } } public int ExpirienceGoal { get { return experienceLevels[Level - 1]; } } public int MaxEnergy { get { return 100; } } public int MaxNutrition { get { return 150; } } public int Age { get { return (int)Math.Floor((HangEnvironment.GetUnixTimestamp() - CreationStamp) / 86400); } } public string Look { get { return Type + " " + Race + " " + Color; } } public string OwnerName { get { return HangEnvironment.GetGame().GetClientManager().GetNameById(OwnerId); } } public Pet(uint PetId, uint OwnerId, uint RoomId, string Name, uint Type, string Race, string Color, int Expirience, int Energy, int Nutrition, int Respect, double CreationStamp, int X, int Y, double Z) { this.PetId = PetId; this.OwnerId = OwnerId; this.RoomId = RoomId; this.Name = Name; this.Type = Type; this.Race = Race; this.Color = Color; this.Expirience = Expirience; this.Energy = Energy; this.Nutrition = Nutrition; this.Respect = Respect; this.CreationStamp = CreationStamp; this.X = X; this.Y = Y; this.Z = Z; this.PlacedInRoom = false; } public void OnRespect() { Respect++; ServerMessage Message = new ServerMessage(440); Message.AppendUInt(PetId); Message.AppendInt32(Expirience + 10); Room.SendMessage(Message); using (DatabaseClient MySQL = HangEnvironment.GetDatabase().GetClient()) { MySQL.AddParamWithValue("petid", PetId); MySQL.query("UPDATE user_pets SET respect = respect + 1 WHERE id = @petid LIMIT 1"); } if (Expirience <= 51900) { AddExpirience(10); } } public void AddExpirience(int Amount) { Expirience = Expirience + Amount; if (Expirience >= 51900) { return; } using (DatabaseClient MySQL = HangEnvironment.GetDatabase().GetClient()) { MySQL.AddParamWithValue("petid", PetId); MySQL.AddParamWithValue("expirience", Expirience); MySQL.query("UPDATE user_pets SET expirience = @expirience WHERE id = @petid LIMIT 1"); } if (Room != null) { ServerMessage Message = new ServerMessage(609); Message.AppendUInt(PetId); Message.AppendInt32(VirtualId); Message.AppendInt32(Amount); Room.SendMessage(Message); if (Expirience > ExpirienceGoal) { // Level the pet ServerMessage ChatMessage = new ServerMessage(24); ChatMessage.AppendInt32(VirtualId); ChatMessage.AppendStringWithBreak("*leveled up to level " + Level + " *"); ChatMessage.AppendInt32(0); Room.SendMessage(ChatMessage); } } } public void PetEnergy(bool Add) { int MaxE; if (Add) { if (this.Energy == 100) // If Energy is 100, no point. return; if (this.Energy > 85) { MaxE = this.MaxEnergy - this.Energy; } else { MaxE = 10; } } else { MaxE = 15; } // Remove Max Energy as 15 int r = HangEnvironment.GetRandomNumber(4, MaxE); using (DatabaseClient MySQL = HangEnvironment.GetDatabase().GetClient()) { if (!Add) { this.Energy = this.Energy - r; if (this.Energy < 0) { MySQL.AddParamWithValue("pid", PetId); MySQL.query("UPDATE user_pets SET energy = 1 WHERE id = @pid LIMIT 1"); this.Energy = 1; r = 1; } MySQL.AddParamWithValue("r", r); MySQL.AddParamWithValue("petid", PetId); MySQL.query("UPDATE user_pets SET energy = energy - @r WHERE id = @petid LIMIT 1"); } else { MySQL.AddParamWithValue("r", r); MySQL.AddParamWithValue("petid", PetId); MySQL.query("UPDATE user_pets SET energy = energy + @r WHERE id = @petid LIMIT 1"); this.Energy = this.Energy + r; } } } public void PetNutrition(bool Add) { int MaxN; if (Add) { if (this.Nutrition == 150) // If Nutrition is 150, no point. return; if (this.Nutrition > 125) { MaxN = this.MaxNutrition - this.Nutrition; } else { MaxN = 10; } } else { MaxN = 15; } // Remove Max Nutrition as 15 int r = HangEnvironment.GetRandomNumber(5, 50); using (DatabaseClient MySQL = HangEnvironment.GetDatabase().GetClient()) { if (!Add) { this.Nutrition = this.Nutrition - r; if (this.Nutrition < 0) { MySQL.AddParamWithValue("pid", PetId); MySQL.query("UPDATE user_pets SET nutrition = 1 WHERE id = @pid LIMIT 1"); this.Nutrition = 1; r = 1; } MySQL.AddParamWithValue("r", r); MySQL.AddParamWithValue("petid", PetId); MySQL.query("UPDATE user_pets SET nutrition = nutrition - @r WHERE id = @petid LIMIT 1"); } else { MySQL.AddParamWithValue("r", r); MySQL.AddParamWithValue("petid", PetId); MySQL.query("UPDATE user_pets SET nutrition = nutrition + @r WHERE id = @petid LIMIT 1"); this.Nutrition = this.Nutrition + r; } } } public void SerializeInventory(ServerMessage Message) { Message.AppendUInt(PetId); Message.AppendStringWithBreak(Name); Message.AppendUInt(Type); Message.AppendInt32(int.Parse(Race)); Message.AppendString(Color.ToLower()); } public ServerMessage SerializeInfo() { ServerMessage Nfo = new ServerMessage(601); Nfo.AppendUInt(PetId); Nfo.AppendStringWithBreak(Name); Nfo.AppendInt32(Level); Nfo.AppendInt32(MaxLevel); Nfo.AppendInt32(Expirience); Nfo.AppendInt32(ExpirienceGoal); Nfo.AppendInt32(Energy); Nfo.AppendInt32(MaxEnergy); Nfo.AppendInt32(Nutrition); Nfo.AppendInt32(MaxNutrition); Nfo.AppendStringWithBreak(Color.ToLower()); Nfo.AppendInt32(Respect); Nfo.AppendUInt(OwnerId); Nfo.AppendInt32(Age); Nfo.AppendStringWithBreak(OwnerName); return Nfo; } } }