Notice
Member
- Nov 27, 2010
- 99
- 0
UberEmu - Pets
Right, I can't be fucked working with Uber anymore so err...
I shall release my half decent pets coding...
Credits to shorty/Habchop
Pets -> Pet.cs
Replace with:
Then RoomBots --> Petbot.cs
Replace With:
If you don't know how to add, then don't do it. I'm not answering anymore questions on UberEmu.
Right, I can't be fucked working with Uber anymore so err...
I shall release my half decent pets coding...
Credits to shorty/Habchop
Pets -> Pet.cs
Replace with:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Uber.HabboHotel.Rooms;
using Uber.Messages;
using Uber.Storage;
namespace Uber.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 UberEnvironment.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((UberEnvironment.GetUnixTimestamp() - CreationStamp) / 86400);
}
}
public string Look
{
get
{
return Type + " " + Race + " " + Color;
}
}
public string OwnerName
{
get
{
return UberEnvironment.GetGame().GetClientManager().GetNameById(OwnerId);
}
}
/*
public int BasketX
{
get
{
try
{
using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
{
dbClient.AddParamWithValue("rID", RoomId);
int ItemX = dbClient.ReadInt32("SELECT x FROM room_items WHERE room_id = @rID AND base_item = 317");
// 317- nest
return ItemX;
}
}
catch { return 0; } // Doesn't Exist
}
}
public int BasketY
{
get
{
try
{
using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
{
dbClient.AddParamWithValue("rID", RoomId);
int ItemY = dbClient.ReadInt32("SELECT y FROM room_items WHERE room_id = @rID AND base_item = 317");
// 317- nest
return ItemY;
}
}
catch { return 0; } // Doesn't Exist
}
}
*/
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 dbClient = UberEnvironment.GetDatabase().GetClient())
{
dbClient.AddParamWithValue("petid", PetId);
dbClient.ExecuteQuery("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 dbClient = UberEnvironment.GetDatabase().GetClient())
{
dbClient.AddParamWithValue("petid", PetId);
dbClient.AddParamWithValue("expirience", Expirience);
dbClient.ExecuteQuery("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 = UberEnvironment.GetRandomNumber(4, MaxE);
using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
{
if (!Add)
{
this.Energy = this.Energy - r;
if (this.Energy < 0)
{
dbClient.AddParamWithValue("pid", PetId);
dbClient.ExecuteQuery("UPDATE user_pets SET energy = 1 WHERE id = @pid LIMIT 1");
this.Energy = 1;
r = 1;
}
dbClient.AddParamWithValue("r", r);
dbClient.AddParamWithValue("petid", PetId);
dbClient.ExecuteQuery("UPDATE user_pets SET energy = energy - @r WHERE id = @petid LIMIT 1");
} else {
dbClient.AddParamWithValue("r", r);
dbClient.AddParamWithValue("petid", PetId);
dbClient.ExecuteQuery("UPDATE user_pets SET energy = energy + @r WHERE id = @petid LIMIT 1");
this.Energy = this.Energy + r;
}
}
}
public void SerializeInventory(ServerMessage Message)
{
Message.AppendUInt(PetId);
Message.AppendStringWithBreak(Name);
Message.AppendStringWithBreak(Look);
Message.AppendBoolean(false);
}
public ServerMessage SerializeInfo()
{
// IYbtmFZoefKPEY]AXdAPhPhHPh0 008 D98961SBhRPZA[lFmybad
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(Look);
Nfo.AppendInt32(Respect);
Nfo.AppendUInt(OwnerId);
Nfo.AppendInt32(Age);
Nfo.AppendStringWithBreak(OwnerName);
return Nfo;
}
}
}
Then RoomBots --> Petbot.cs
Replace With:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Uber.Messages;
using Uber.HabboHotel.Rooms;
using Uber.HabboHotel.Pathfinding;
namespace Uber.HabboHotel.RoomBots
{
class PetBot : BotAI
{
private int SpeechTimer;
private int ActionTimer;
private int EnergyTimer;
// TO-DO: This needs cleaning up BADLY, If anyone wants to attempt cleaning up my mess, go for it (Y) (Half done - Shorty)
public PetBot(int VirtualId)
{
this.SpeechTimer = new Random((VirtualId ^ 2) + DateTime.Now.Millisecond).Next(10, 60);
this.ActionTimer = new Random((VirtualId ^ 2) + DateTime.Now.Millisecond).Next(10, 30 + VirtualId);
this.EnergyTimer = new Random((VirtualId ^ 2) + DateTime.Now.Millisecond).Next(10, 60);
}
private void RemovePetStatus()
{
RoomUser Pet = GetRoomUser();
// Remove Status
Pet.Statusses.Remove("sit");
Pet.Statusses.Remove("lay");
Pet.Statusses.Remove("snf");
Pet.Statusses.Remove("eat");
Pet.Statusses.Remove("ded");
Pet.Statusses.Remove("jmp");
}
public override void OnSelfEnterRoom()
{
int randomX = UberEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeX);
int randomY = UberEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeY);
GetRoomUser().MoveTo(randomX, randomY);
}
public override void OnSelfLeaveRoom(bool Kicked) { }
public override void OnUserEnterRoom(Rooms.RoomUser User)
{
if (User.GetClient().GetHabbo().Username.ToLower() == GetRoomUser().PetData.OwnerName.ToLower())
{
GetRoomUser().Chat(null, "*drools over master*", false);
}
}
public override void OnUserLeaveRoom(GameClients.GameClient Client) { }
#region Commands
public override void OnUserSay(Rooms.RoomUser User, string Message)
{
RoomUser Pet = GetRoomUser();
if (Message.ToLower().Equals(Pet.PetData.Name.ToLower()))
{
Pet.SetRot(Rotation.Calculate(Pet.X, Pet.Y, User.X, User.Y));
return;
}
if (Message.ToLower().StartsWith(Pet.PetData.Name.ToLower() + " ") && User.GetClient().GetHabbo().Username.ToLower() == GetRoomUser().PetData.OwnerName.ToLower())
{
string Command = Message.Substring(Pet.PetData.Name.ToLower().Length + 1);
int r = UberEnvironment.GetRandomNumber(1, 8); // Made Random
if (Pet.PetData.Energy > 10 && r < 6 || Pet.PetData.Level > 15)
{
RemovePetStatus(); // Remove Status
switch (Command)
{
// TODO - Level you can use the commands at...
#region free
case "free":
RemovePetStatus();
int randomX = UberEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeX);
int randomY = UberEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeY);
Pet.MoveTo(randomX, randomY);
Pet.PetData.AddExpirience(10); // Give XP
break;
#endregion
#region here
case "come":
case "here":
RemovePetStatus();
int NewX = User.X;
int NewY = User.Y;
ActionTimer = 30; // Reset ActionTimer
#region Rotation
if (User.RotBody == 4)
{
NewY = User.Y + 1;
}
else if (User.RotBody == 0)
{
NewY = User.Y - 1;
}
else if (User.RotBody == 6)
{
NewX = User.X - 1;
}
else if (User.RotBody == 2)
{
NewX = User.X + 1;
}
else if (User.RotBody == 3)
{
NewX = User.X + 1;
NewY = User.Y + 1;
}
else if (User.RotBody == 1)
{
NewX = User.X + 1;
NewY = User.Y - 1;
}
else if (User.RotBody == 7)
{
NewX = User.X - 1;
NewY = User.Y - 1;
}
else if (User.RotBody == 5)
{
NewX = User.X - 1;
NewY = User.Y + 1;
}
#endregion
Pet.PetData.AddExpirience(10); // Give XP
Pet.MoveTo(NewX, NewY);
break;
#endregion
#region sit
case "sit":
// Remove Status
RemovePetStatus();
Pet.PetData.AddExpirience(10); // Give XP
// Add Status
Pet.Statusses.Add("sit", Pet.Z.ToString());
ActionTimer = 25;
EnergyTimer = 10;
break;
#endregion
#region lay
case "lay":
case "down":
// Remove Status
RemovePetStatus();
// Add Status
Pet.Statusses.Add("lay", Pet.Z.ToString());
Pet.PetData.AddExpirience(10); // Give XP
ActionTimer = 30;
EnergyTimer = 5;
break;
#endregion
#region dead
case "play dead":
case "dead":
// Remove Status
RemovePetStatus();
// Add Status
Pet.Statusses.Add("ded", Pet.Z.ToString());
Pet.PetData.AddExpirience(10); // Give XP
// Don't move to speak for a set amount of time.
SpeechTimer = 45;
ActionTimer = 30;
break;
#endregion
#region sleep
case "sleep":
// Remove Status
RemovePetStatus();
Pet.Chat(null, "ZzzZZZzzzzZzz", false);
Pet.Statusses.Add("lay", Pet.Z.ToString());
Pet.PetData.AddExpirience(10); // Give XP
// Don't move to speak for a set amount of time.
EnergyTimer = 5;
SpeechTimer = 30;
ActionTimer = 45;
break;
#endregion
#region jump
case "jump":
// Remove Status
RemovePetStatus();
// Add Status
Pet.Statusses.Add("jmp", Pet.Z.ToString());
Pet.PetData.AddExpirience(10); // Give XP
// Don't move to speak for a set amount of time.
EnergyTimer = 5;
SpeechTimer = 10;
ActionTimer = 5;
break;
#endregion
default:
string[] Speech = { "*confused*", "What?", "Huh?", "What is that?", "hmm..?" };
Random RandomSpeech = new Random();
Pet.Chat(null, Speech[RandomSpeech.Next(0, Speech.Length - 1)], false);
break;
}
Pet.PetData.PetEnergy(false); // Remove Energy
Pet.PetData.PetEnergy(false); // Remove Energy
} else {
RemovePetStatus(); // Remove Status
if (Pet.PetData.Energy < 10)
{
string[] Speech = { "ZzZzzzzz", "*sleeps*", "Tired... *sleeps*", "ZzZzZZzzzZZz", "zzZzzZzzz", "... Yawnn ..", "ZzZzzZ" };
Random RandomSpeech = new Random();
Pet.Chat(null, Speech[RandomSpeech.Next(0, Speech.Length - 1)], false);
Pet.Statusses.Add("lay", Pet.Z.ToString());
SpeechTimer = 50;
ActionTimer = 45;
EnergyTimer = 5;
} else {
string[] Speech = { "*sigh*", "*refuses*", " ... ", "Who do you think you are?", "you do it", "Grr!", "*laughs*", "Why?" };
Random RandomSpeech = new Random();
Pet.Chat(null, Speech[RandomSpeech.Next(0, Speech.Length - 1)], false);
Pet.PetData.PetEnergy(false); // Remove Energy
}
}
}
Pet = null;
}
#endregion
public override void OnUserShout(Rooms.RoomUser User, string Message) { }
public override void OnTimerTick()
{
#region Speech
if (SpeechTimer <= 0)
{
RoomUser Pet = GetRoomUser();
if (Pet != null)
{
Random RandomSpeech = new Random();
RemovePetStatus();
if (Pet.PetData.Type == 0 || Pet.PetData.Type == 3) // Dog & Terrier
{
string[] Speech = { "woof woof woof!!!", "hooooowl", "wooooof!", "Woof Woof!", "sit", "lay", "snf", "Woof" };
string rSpeech = Speech[RandomSpeech.Next(0, Speech.Length - 1)];
if (rSpeech.Length != 3)
{
Pet.Chat(null, rSpeech, false);
} else {
Pet.Statusses.Add(rSpeech, Pet.Z.ToString());
}
} else if (Pet.PetData.Type == 1) { // Cat
string[] Speech = { "meow", "meow...meOW", "muew..muew", "lay", "sit", "lay" };
string rSpeech = Speech[RandomSpeech.Next(0, Speech.Length - 1)];
if (rSpeech.Length != 3)
{
Pet.Chat(null, rSpeech, false);
} else {
Pet.Statusses.Add(rSpeech, Pet.Z.ToString());
}
} else if (Pet.PetData.Type == 2) { // Crocodile
string[] Speech = { "Rrrr....Grrrrrg....", "*Mellow*", "Tick tock tick....", "*feels like eating my owner*", "Nom Nom Nom", ".. Yawwnn!", "snf" };
string rSpeech = Speech[RandomSpeech.Next(0, Speech.Length - 1)];
if (rSpeech.Length != 3)
{
Pet.Chat(null, rSpeech, false);
} else {
Pet.Statusses.Add(rSpeech, Pet.Z.ToString());
}
} else if (Pet.PetData.Type == 4) { // Bear
string[] Speech = { "*pack of fresh salmon please*", "Rawrrr!", "*sniff sniff*", "Yawnnnn..", "Rawr! ... Rawrrrrr?", "snf" };
string rSpeech = Speech[RandomSpeech.Next(0, Speech.Length - 1)];
if (rSpeech.Length != 3)
{
Pet.Chat(null, rSpeech, false);
} else {
Pet.Statusses.Add(rSpeech, Pet.Z.ToString());
}
} else if (Pet.PetData.Type == 5) { // Pig
string[] Speech = { "Oink Oink..", "*Mellow*", "Sniff... Sniff..", "snf", "Oink!", "snf", "lay", "oink" };
string rSpeech = Speech[RandomSpeech.Next(0, Speech.Length - 1)];
if (rSpeech.Length != 3)
{
Pet.Chat(null, rSpeech, false);
} else {
Pet.Statusses.Add(rSpeech, Pet.Z.ToString());
}
}
Pet = null;
}
SpeechTimer = UberEnvironment.GetRandomNumber(20, 120);
} else {
SpeechTimer--;
}
#endregion
if (ActionTimer <= 0)
{
// Remove Status
RemovePetStatus();
int randomX = UberEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeX);
int randomY = UberEnvironment.GetRandomNumber(0, GetRoom().Model.MapSizeY);
GetRoomUser().MoveTo(randomX, randomY);
ActionTimer = UberEnvironment.GetRandomNumber(15, 40 + GetRoomUser().PetData.VirtualId);
} else {
ActionTimer--;
}
if (EnergyTimer <= 0)
{
RemovePetStatus(); // Remove Status
RoomUser Pet = GetRoomUser();
Pet.PetData.PetEnergy(true); // Add Energy
EnergyTimer = UberEnvironment.GetRandomNumber(30, 120); // 2 Min Max
} else {
EnergyTimer--;
}
}
}
}
If you don't know how to add, then don't do it. I'm not answering anymore questions on UberEmu.