public void AddAIUser(RoomBotData data, int type, int x, int y, double z, int rot) { int virtualId = this.GetNextVirtualID(); RoomBot roomUser = null; if (type == 0) { roomUser = new RoomBot(data, this.Room, virtualId); } else if (type == 1) { roomUser = new RoomBotGuide(data, this.Room, virtualId); } else if (type == 2) { roomUser = new RoomBotNewbieGuide(data, this.Room, virtualId); } if (roomUser != null) { roomUser.SetLocation(x, y, z); roomUser.SetRotation(rot, true); this.Room.SendToAll(new MultiRevisionServerMessage(OutgoingPacketsEnum.SetRoomUser, new ValueHolder().AddValue("RoomUser", new List <RoomUnit>() { roomUser }))); this.RoomUsers.Add(roomUser.VirtualID, roomUser.GetType(), roomUser); roomUser.OnSelfEnterRoom(); } }
public void removeBot(int botID) { if (!containsBot(botID)) { return; } RoomBot botToRemove = (RoomBot)_Bots[botID]; _Bots.Remove(botID); int avatarID = botID - botID * 2; foreach (ConnectedUser usr in _Users.Values) { RemoveAvatarPacket toremove = new RemoveAvatarPacket(); toremove.I = botToRemove._MyAvatarID; string stringtoremove = JsonConvert.SerializeObject(toremove); usr.sendData("058" + stringtoremove + "#"); } if (((botToRemove._MyX + 1).ToString()) + "_" + ((botToRemove._MyY + 1).ToString()) != door) { _sqUnit[botToRemove._MyX, botToRemove._MyY] = false; } if ((countUsers()) == 0) { _Users.Clear(); _Bots.Clear(); RoomManager.removeRoom(RoomID); } }
/// <summary> /// Initializes a new instance of the <see cref="GenericBot" /> class. /// </summary> /// <param name="roomBot">The room bot.</param> /// <param name="virtualId">The virtual identifier.</param> /// <param name="speechInterval">The speech interval.</param> internal GenericBot(RoomBot roomBot, int virtualId, uint speechInterval) { _virtualId = virtualId; _speechInterval = speechInterval < 2 ? 2000 : speechInterval*1000; if ((roomBot?.AutomaticChat ?? false) && roomBot.RandomSpeech != null && roomBot.RandomSpeech.Any()) _chatTimer = new Timer(ChatTimerTick, null, _speechInterval, _speechInterval); _actionCount = Random.Next(10, 30 + virtualId); }
/// <summary> /// Adds the bot. /// </summary> /// <param name="bot">The bot.</param> internal void AddBot(RoomBot bot) { _isUpdated = false; if (bot == null || _inventoryBots.Contains(bot.BotId)) { return; } bot.RoomId = 0u; _inventoryBots.Add(bot.BotId, bot); }
/// <summary> /// Initializes a new instance of the <see cref="GenericBot" /> class. /// </summary> /// <param name="roomBot">The room bot.</param> /// <param name="virtualId">The virtual identifier.</param> /// <param name="speechInterval">The speech interval.</param> internal GenericBot(RoomBot roomBot, int virtualId, uint speechInterval) { _virtualId = virtualId; _speechInterval = speechInterval < 2 ? 2000 : speechInterval * 1000; if ((roomBot?.AutomaticChat ?? false) && roomBot.RandomSpeech != null && roomBot.RandomSpeech.Any()) { _chatTimer = new Timer(ChatTimerTick, null, _speechInterval, _speechInterval); } _actionCount = Random.Next(10, 30 + virtualId); }
//no test, you can test the "concurrent random" public async Task BotPlay(RoomBot roomBot) { //can happen with logic var randomCardIndex = StaticRandom.GetRandom(roomBot.Hand.Count); var throwResult = PlayBase(roomBot, randomCardIndex); await SendCurrentOppoThrow(roomBot, throwResult); await NextTurn(roomBot.Room); _logger.LogInformation($"bot {roomBot.Id} has played card {randomCardIndex}"); } //no test, you can test the "concurrent random"
internal void AddBot(RoomBot Bot) { this.isUpdated = false; if (Bot == null) { Logging.WriteLine("Bot was null", ConsoleColor.Gray); return; } if (this.InventoryBots.ContainsKey(Bot.BotId)) { Logging.WriteLine("Contains Bot", ConsoleColor.Gray); } Bot.RoomId = 0u; this.InventoryBots.Add(Bot.BotId, Bot); }
/// <summary> /// Loads the mafia war bots /// </summary> /// <returns></returns> public bool LoadBots() { DataTable CurrentBots; DataTable MafiaBots; using (var QueryAdapter = Plus.GetDatabaseManager().GetQueryReactor()) { QueryAdapter.SetQuery("SELECT * FROM bots"); CurrentBots = QueryAdapter.GetTable(); QueryAdapter.SetQuery("SELECT * FROM rp_mafiawars_bots"); MafiaBots = QueryAdapter.GetTable(); } if (CurrentBots == null || MafiaBots == null) { return(false); } uint CurrentID = Convert.ToUInt32(CurrentBots.Rows.Count + 1); foreach (DataRow Row in MafiaBots.Rows) { RoomBot MafiaBot = new RoomBot(CurrentID, 1, 478, AIType.MafiaWarBot, "stand", Row["name"].ToString(), Row["motto"].ToString(), Row["look"].ToString(), Convert.ToInt32(Row["x"]), Convert.ToInt32(Row["y"]), 0, 1, 4, 4, 4, 4, null, null, "M", 0, false); Room BotRoomBase = Plus.GetGame().GetRoomManager().LoadRoom(Convert.ToUInt32(Row["rid"])); if (MafiaBot == null || BotRoomBase == null) { continue; } BotRoomBase.GetRoomUserManager().DeployBot(MafiaBot, null); MafiaBot.RoomUser.BotData._Team = MWTeams[Row["team"].ToString()]; MafiaBot.RoomUser.BotData._Boss = Convert.ToBoolean(Row["boss"]); MafiaBot.RoomUser.BotData.cur_Health = Convert.ToInt32(Row["health"]); MafiaBot.RoomUser.BotData.max_Health = Convert.ToInt32(Row["maxhealth"]); MafiaBot.RoomUser.BotData.strength = Convert.ToInt32(Row["strength"]); MWBots.Add(MafiaBot, MafiaBot.RoomUser.BotData._Team); CurrentID++; } return(true); }
internal void AddBot(RoomBot Bot) { isUpdated = false; if (!inventoryHaveBots.ContainsKey(Bot.BotId)) { inventoryHaveBots.Add(Bot.BotId, Bot.AiType); } if (Bot == null) { return; } Bot.RoomId = 0; if (!InventoryBots.ContainsKey(Bot.BotId)) { InventoryBots.Add(Bot.BotId, Bot); } }
internal void loadBots(int amount) { string sendText = ""; int users = countUsers(); for (int i = 0; i < amount; i++) { if (users++ < max_users) { int botID = ++botAmount; RoomBot roomBot = new RoomBot(this, botID, 0); this._Bots.Add(botID, roomBot); if (!roomBot.startDoor) { _sqUnit[roomBot._MyX, roomBot._MyY] = true; } AddAvatarPacket avatars = new AddAvatarPacket(); avatars.I = roomBot._MyAvatarID; avatars.U = roomBot._MyName; avatars.M = roomBot._MyMission; avatars.C = roomBot._MyFigure; avatars.B = "7"; avatars.D = ""; avatars.Brb = 0; avatars.S = roomBot._Sit; avatars.X = roomBot._MyX; avatars.Y = roomBot._MyY; avatars.H = roomBot._MyZ; avatars.F = false; avatars.R = false; string stringavatars = JsonConvert.SerializeObject(avatars); sendText += "056" + stringavatars + "#"; } } foreach (ConnectedUser usr in _Users.Values) { usr.sendData(sendText); } }
private void LoadBots() { DataTable table; using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) { queryreactor.SetQuery("SELECT * FROM bots WHERE room_id = " + this.Id); table = queryreactor.GetTable(); if (table == null) { return; } foreach (DataRow Row in table.Rows) { RoomBot roomBot = new RoomBot(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["room_id"]), (this.RpRoom) ? AIType.RolePlayBot : AIType.Generic, (string)Row["walk_enabled"] == "1", (string)Row["name"], (string)Row["motto"], (string)Row["gender"], (string)Row["look"], (int)Row["x"], (int)Row["y"], (int)Row["z"], (int)Row["rotation"], (string)Row["chat_enabled"] == "1", (string)Row["chat_text"], (int)Row["chat_seconds"], (string)Row["is_dancing"] == "1", (int)Row["enable"], (int)Row["handitem"], Convert.ToInt32((string)Row["status"])); RoomUser roomUser = this.GetRoomUserManager().DeployBot(roomBot, (Pet)null); if (roomBot.IsDancing) { roomUser.DanceId = 3; } } } }
internal void InitUserBots() { using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor.setQuery("SELECT * FROM bots WHERE room_id = " + this.RoomId + " AND ai_type = 'generic'"); DataTable table = queryreactor.getTable(); if (table != null) { foreach (DataRow dataRow in table.Rows) { queryreactor.setQuery("SELECT text, shout FROM bots_speech WHERE bots_speech.bot_id = '" + dataRow["id"] + "';"); DataTable table2 = queryreactor.getTable(); RoomBot roomBot = BotManager.GenerateBotFromRow(dataRow); List <RandomSpeech> list = new List <RandomSpeech>(); foreach (DataRow dataRow2 in table2.Rows) { list.Add(new RandomSpeech((string)dataRow2["text"], CyberEnvironment.EnumToBool(dataRow2["shout"].ToString()))); } List <BotResponse> list2 = new List <BotResponse>(); this.roomUserManager.DeployBot(new RoomBot(roomBot.BotId, roomBot.OwnerId, this.RoomId, AIType.Generic, "freeroam", roomBot.Name, roomBot.Motto, roomBot.Look, roomBot.X, roomBot.Y, (double)checked ((int)roomBot.Z), 4, 0, 0, 0, 0, ref list, ref list2, roomBot.Gender, roomBot.DanceId, roomBot.IsBartender), null); } } } }
public void Parse(HabboHotel.GameClients.GameClient session, ClientPacket packet) { if (!session.GetHabbo().InRoom) { return; } Room room = session.GetHabbo().CurrentRoom; if (room == null) { return; } int botId = packet.PopInt(); int actionId = packet.PopInt(); string dataString = packet.PopString(); if (actionId < 1 || actionId > 5) { return; } if (!room.GetRoomUserManager().TryGetBot(botId, out RoomUser bot)) { return; } if (bot.BotData.OwnerId != session.GetHabbo().Id&& !session.GetHabbo().GetPermissions().HasRight("bot_edit_any_override")) { return; } RoomBot roomBot = bot.BotData; if (roomBot == null) { return; } /* 1 = Copy looks * 2 = Setup Speech * 3 = Relax * 4 = Dance * 5 = Change Name */ switch (actionId) { #region Copy Looks (1) case 1: { //Change the defaults bot.BotData.Look = session.GetHabbo().Look; bot.BotData.Gender = session.GetHabbo().Gender; UserChangeComposer userChangeComposer = new UserChangeComposer(bot.VirtualId, bot.BotData); room.SendPacket(userChangeComposer); using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `bots` SET `look` = @look, `gender` = '" + session.GetHabbo().Gender + "' WHERE `id` = '" + bot.BotData.Id + "' LIMIT 1"); dbClient.AddParameter("look", session.GetHabbo().Look); dbClient.RunQuery(); } //Room.SendMessage(new UserChangeComposer(BotUser.GetClient(), true)); break; } #endregion #region Setup Speech (2) case 2: { string[] configData = dataString.Split(new[] { ";#;" }, StringSplitOptions.None); string[] speechData = configData[0].Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); string automaticChat = Convert.ToString(configData[1]); string speakingInterval = Convert.ToString(configData[2]); string mixChat = Convert.ToString(configData[3]); if (String.IsNullOrEmpty(speakingInterval) || Convert.ToInt32(speakingInterval) <= 0 || Convert.ToInt32(speakingInterval) < 7) { speakingInterval = "7"; } roomBot.AutomaticChat = Convert.ToBoolean(automaticChat); roomBot.SpeakingInterval = Convert.ToInt32(speakingInterval); roomBot.MixSentences = Convert.ToBoolean(mixChat); using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("DELETE FROM `bots_speech` WHERE `bot_id` = '" + bot.BotData.Id + "'"); #region Save Data - TODO: MAKE METHODS FOR THIS. for (int i = 0; i <= speechData.Length - 1; i++) { dbClient.SetQuery("INSERT INTO `bots_speech` (`bot_id`, `text`) VALUES (@id, @data)"); dbClient.AddParameter("id", botId); dbClient.AddParameter("data", speechData[i]); dbClient.RunQuery(); dbClient.SetQuery("UPDATE `bots` SET `automatic_chat` = @AutomaticChat, `speaking_interval` = @SpeakingInterval, `mix_sentences` = @MixChat WHERE `id` = @id LIMIT 1"); dbClient.AddParameter("id", botId); dbClient.AddParameter("AutomaticChat", automaticChat.ToLower()); dbClient.AddParameter("SpeakingInterval", Convert.ToInt32(speakingInterval)); dbClient.AddParameter("MixChat", PlusEnvironment.BoolToEnum(Convert.ToBoolean(mixChat))); dbClient.RunQuery(); } #endregion #region Handle Speech roomBot.RandomSpeech.Clear(); dbClient.SetQuery("SELECT `text` FROM `bots_speech` WHERE `bot_id` = @id"); dbClient.AddParameter("id", botId); DataTable botSpeech = dbClient.GetTable(); foreach (DataRow speech in botSpeech.Rows) { roomBot.RandomSpeech.Add(new RandomSpeech(Convert.ToString(speech["text"]), botId)); } #endregion } break; } #endregion #region Relax (3) case 3: { if (bot.BotData.WalkingMode == "stand") { bot.BotData.WalkingMode = "freeroam"; } else { bot.BotData.WalkingMode = "stand"; } using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("UPDATE `bots` SET `walk_mode` = '" + bot.BotData.WalkingMode + "' WHERE `id` = '" + bot.BotData.Id + "' LIMIT 1"); } break; } #endregion #region Dance (4) case 4: { if (bot.BotData.DanceId > 0) { bot.BotData.DanceId = 0; } else { Random randomDance = new Random(); bot.BotData.DanceId = randomDance.Next(1, 4); } room.SendPacket(new DanceComposer(bot.VirtualId, bot.BotData.DanceId)); break; } #endregion #region Change Name (5) case 5: { if (dataString.Length == 0) { session.SendWhisper("Come on, atleast give the bot a name!"); return; } else if (dataString.Length >= 16) { session.SendWhisper("Come on, the bot doesn't need a name that long!"); return; } if (dataString.Contains("<img src") || dataString.Contains("<font ") || dataString.Contains("</font>") || dataString.Contains("</a>") || dataString.Contains("<i>")) { session.SendWhisper("No HTML, please :<"); return; } bot.BotData.Name = dataString; using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `bots` SET `name` = @name WHERE `id` = '" + bot.BotData.Id + "' LIMIT 1"); dbClient.AddParameter("name", dataString); dbClient.RunQuery(); } room.SendPacket(new UsersComposer(bot)); break; } #endregion } }
internal RoomUser DeployBot(RoomBot Bot, Pet PetData) { RoomUser BotUser = new RoomUser(0, room.RoomId, primaryPrivateUserID++, room, false); int PersonalID = secondaryPrivateUserID++; BotUser.InternalRoomID = PersonalID; //this.UserList[PersonalID] = BotUser; userlist.Add(PersonalID, BotUser); DynamicRoomModel Model = room.GetGameMap().Model; if ((Bot.X > 0 && Bot.Y > 0) && Bot.X < Model.MapSizeX && Bot.Y < Model.MapSizeY) { BotUser.SetPos(Bot.X, Bot.Y, Bot.Z); BotUser.SetRot(Bot.Rot, false); } else { Bot.X = Model.DoorX; Bot.Y = Model.DoorY; BotUser.SetPos(Model.DoorX, Model.DoorY, Model.DoorZ); BotUser.SetRot(Model.DoorOrientation, false); } BotUser.BotData = Bot; BotUser.BotAI = Bot.GenerateBotAI(BotUser.VirtualId); if (BotUser.IsPet) { BotUser.BotAI.Init((int)Bot.BotId, BotUser.VirtualId, room.RoomId, BotUser, room); BotUser.PetData = PetData; BotUser.PetData.VirtualId = BotUser.VirtualId; } else { BotUser.BotAI.Init(-1, BotUser.VirtualId, room.RoomId, BotUser, room); } UpdateUserStatus(BotUser, false); BotUser.UpdateNeeded = true; ServerMessage EnterMessage = new ServerMessage(28); EnterMessage.AppendInt32(1); BotUser.Serialize(EnterMessage, room.GetGameMap().gotPublicPool); room.SendMessage(EnterMessage); BotUser.BotAI.OnSelfEnterRoom(); if (BotUser.BotData.AiType == AIType.Guide) { room.guideBotIsCalled = true; } if (BotUser.IsPet) { if (pets.ContainsKey(BotUser.PetData.PetId)) //Pet allready placed { pets[BotUser.PetData.PetId] = BotUser; } else { pets.Add(BotUser.PetData.PetId, BotUser); } petCount++; } return(BotUser); }
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet) { if (!Session.GetHabbo().InRoom) { return; } Room Room = null; if (!PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(Session.GetHabbo().CurrentRoomId, out Room)) { return; } if ((Room.AllowPets == 0 && !Room.CheckRights(Session, true)) || !Room.CheckRights(Session, true)) { Session.SendPacket(new RoomErrorNotifComposer(1)); return; } if (Room.GetRoomUserManager().PetCount > Convert.ToInt32(PlusEnvironment.GetSettingsManager().TryGetValue("room.pets.placement_limit"))) { Session.SendPacket(new RoomErrorNotifComposer(2));//5 = I have too many. return; } Pet Pet = null; if (!Session.GetHabbo().GetInventoryComponent().TryGetPet(Packet.PopInt(), out Pet)) { return; } if (Pet == null) { return; } if (Pet.PlacedInRoom) { Session.SendNotification("This pet is already in the room?"); return; } int X = Packet.PopInt(); int Y = Packet.PopInt(); if (!Room.GetGameMap().CanWalk(X, Y, false)) { Session.SendPacket(new RoomErrorNotifComposer(4)); return; } RoomUser OldPet = null; if (Room.GetRoomUserManager().TryGetPet(Pet.PetId, out OldPet)) { Room.GetRoomUserManager().RemoveBot(OldPet.VirtualId, false); } Pet.X = X; Pet.Y = Y; Pet.PlacedInRoom = true; Pet.RoomId = Room.RoomId; List <RandomSpeech> RndSpeechList = new List <RandomSpeech>(); RoomBot RoomBot = new RoomBot(Pet.PetId, Pet.RoomId, "pet", "freeroam", Pet.Name, "", Pet.Look, X, Y, 0, 0, 0, 0, 0, 0, ref RndSpeechList, "", 0, Pet.OwnerId, false, 0, false, 0); if (RoomBot == null) { return; } Room.GetRoomUserManager().DeployBot(RoomBot, Pet); Pet.DBState = DatabaseUpdateState.NeedsUpdate; Room.GetRoomUserManager().UpdatePets(); Pet ToRemove = null; if (!Session.GetHabbo().GetInventoryComponent().TryRemovePet(Pet.PetId, out ToRemove)) { log.Error("Error whilst removing pet: " + ToRemove.PetId); return; } Session.SendPacket(new PetInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetPets())); }
public void Parse(GameClient Session, ClientPacket Packet) { if (!Session.GetHabbo().InRoom) { return; } Room Room = Session.GetHabbo().CurrentRoom; if (Room == null || !Room.CheckRights(Session, true)) { return; } int BotId = Packet.PopInt(); int ActionId = Packet.PopInt(); string DataString = Packet.PopString(); if (BotId <= 0) { return; } if (ActionId < 1 || ActionId > 5) { return; } RoomUser Bot = null; if (!Room.GetRoomUserManager().TryGetBot(BotId, out Bot)) { return; } RoomBot RoomBot = Bot.BotData; if (RoomBot == null) { return; } /* 1 = Copy looks * 2 = Setup Speech * 3 = Relax * 4 = Dance * 5 = Change Name */ switch (ActionId) { #region Copy Looks (1) case 1: { //Change the defaults Bot.BotData.Look = Session.GetHabbo().Look; Bot.BotData.Gender = Session.GetHabbo().Gender; Room.SendPacket(new UserChangeComposer(Bot)); using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `bots` SET `look` = @look, `gender` = '" + Session.GetHabbo().Gender + "' WHERE `id` = '" + Bot.BotData.Id + "' LIMIT 1"); dbClient.AddParameter("look", Session.GetHabbo().Look); dbClient.RunQuery(); } break; } #endregion #region Setup Speech (2) case 2: { string[] ConfigData = DataString.Split(new string[] { ";#;" }, StringSplitOptions.None); string[] SpeechData = ConfigData[0].Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); string AutomaticChat = Convert.ToString(ConfigData[1]); string SpeakingInterval = Convert.ToString(ConfigData[2]); string MixChat = Convert.ToString(ConfigData[3]); if (String.IsNullOrEmpty(SpeakingInterval) || Convert.ToInt32(SpeakingInterval) <= 0 || Convert.ToInt32(SpeakingInterval) < 7) { SpeakingInterval = "7"; } RoomBot.AutomaticChat = Convert.ToBoolean(AutomaticChat); RoomBot.SpeakingInterval = Convert.ToInt32(SpeakingInterval); RoomBot.MixSentences = Convert.ToBoolean(MixChat); string Text = ""; string Phrase = ""; for (int i = 0; i <= SpeechData.Length - 1; i++) { Phrase = SpeechData[i]; if (Phrase.Length > 150) { Phrase.Substring(0, 150); } Text += SpeechData[i] + "\r"; } RoomBot.ChatText = Text; RoomBot.LoadRandomSpeech(Text); using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `bots` SET `chat_enabled` = @AutomaticChat, `chat_seconds` = @SpeakingInterval, `is_mixchat` = @MixChat, `chat_text` = @ChatText WHERE `id` = @id LIMIT 1"); dbClient.AddParameter("id", BotId); dbClient.AddParameter("AutomaticChat", ButterflyEnvironment.BoolToEnum(Convert.ToBoolean(AutomaticChat))); dbClient.AddParameter("SpeakingInterval", Convert.ToInt32(SpeakingInterval)); dbClient.AddParameter("MixChat", ButterflyEnvironment.BoolToEnum(Convert.ToBoolean(MixChat))); dbClient.AddParameter("ChatText", Text); dbClient.RunQuery(); } break; } #endregion #region Relax (3) case 3: { Bot.BotData.WalkingEnabled = !Bot.BotData.WalkingEnabled; using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) { queryreactor.RunQuery("UPDATE bots SET walk_enabled = '" + ButterflyEnvironment.BoolToEnum(Bot.BotData.WalkingEnabled) + "' WHERE id = " + Bot.BotData.Id); } break; } #endregion #region Dance (4) case 4: { if (Bot.DanceId > 0) { Bot.DanceId = 0; Bot.BotData.IsDancing = false; } else { Random RandomDance = new Random(); Bot.DanceId = RandomDance.Next(1, 4); Bot.BotData.IsDancing = true; } Room.SendPacket(new DanceComposer(Bot, Bot.DanceId)); using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) queryreactor.RunQuery("UPDATE bots SET is_dancing = '" + ButterflyEnvironment.BoolToEnum(Bot.BotData.IsDancing) + "' WHERE id = " + Bot.BotData.Id); break; } #endregion #region Change Name (5) case 5: { if (DataString.Length == 0) { return; } else if (DataString.Length >= 16) { return; } if (DataString.Contains("<img src") || DataString.Contains("<font ") || DataString.Contains("</font>") || DataString.Contains("</a>") || DataString.Contains("<i>")) { return; } Bot.BotData.Name = DataString; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `bots` SET `name` = @name WHERE `id` = '" + Bot.BotData.Id + "' LIMIT 1"); dbClient.AddParameter("name", DataString); dbClient.RunQuery(); } Room.SendPacket(new UserNameChangeMessageComposer(Bot.BotData.Name, Bot.VirtualId)); break; } #endregion } }
public UserChangeComposer(int VirtualId, RoomBot BotData) : base(ServerPacketHeader.UserChangeMessageComposer) { this.VirtualId = VirtualId; this.BotData = BotData; }
public void Parse(Player session, ClientPacket packet) { if (!session.GetHabbo().InRoom) { return; } if (!Program.GameContext.GetRoomManager().TryGetRoom(session.GetHabbo().CurrentRoomId, out var room)) { return; } if (room.AllowPets == 0 && !room.CheckRights(session, true) || !room.CheckRights(session, true)) { session.SendPacket(new RoomErrorNotifComposer(1)); return; } if (room.GetRoomUserManager().PetCount > Convert.ToInt32(Program.SettingsManager.TryGetValue("room.pets.placement_limit"))) { session.SendPacket(new RoomErrorNotifComposer(2));//5 = I have too many. return; } if (!session.GetHabbo().GetInventoryComponent().TryGetPet(packet.PopInt(), out var pet)) { return; } if (pet == null) { return; } if (pet.PlacedInRoom) { session.SendNotification("This pet is already in the room?"); return; } var x = packet.PopInt(); var y = packet.PopInt(); if (!room.GetGameMap().CanWalk(x, y, false)) { session.SendPacket(new RoomErrorNotifComposer(4)); return; } if (room.GetRoomUserManager().TryGetPet(pet.PetId, out var oldPet)) { room.GetRoomUserManager().RemoveBot(oldPet.VirtualId, false); } pet.X = x; pet.Y = y; pet.PlacedInRoom = true; pet.RoomId = room.RoomId; var rndSpeechList = new List <RandomSpeech>(); var roomBot = new RoomBot(pet.PetId, pet.RoomId, "pet", "freeroam", pet.Name, "", pet.Look, x, y, 0, 0, 0, 0, 0, 0, ref rndSpeechList, "", 0, pet.OwnerId, false, 0, false, 0); room.GetRoomUserManager().DeployBot(roomBot, pet); pet.DBState = PetDatabaseUpdateState.NeedsUpdate; room.GetRoomUserManager().UpdatePets(); if (!session.GetHabbo().GetInventoryComponent().TryRemovePet(pet.PetId, out var toRemove)) { Logger.Error("Error whilst removing pet: " + toRemove.PetId); return; } session.SendPacket(new PetInventoryComposer(session.GetHabbo().GetInventoryComponent().GetPets())); }
/// <summary> /// Delivers the items. /// </summary> /// <param name="session">The session.</param> /// <param name="item">The item.</param> /// <param name="amount">The amount.</param> /// <param name="extraData">The extra data.</param> /// <param name="limno">The limno.</param> /// <param name="limtot">The limtot.</param> /// <param name="songCode">The song code.</param> /// <returns>List<UserItem>.</returns> internal List <UserItem> DeliverItems(GameClient session, Item item, uint amount, string extraData, uint limno, uint limtot, string songCode) { List <UserItem> list = new List <UserItem>(); if (item.InteractionType == Interaction.PostIt) { amount = amount * 20; } char a = item.Type; switch (a) { case 'i': case 's': int i = 0; while (i < amount) { Interaction interactionType = item.InteractionType; switch (interactionType) { case Interaction.Dimmer: UserItem userItem33 = session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, extraData, 0u, true, false, 0, 0); uint id33 = userItem33.Id; list.Add(userItem33); using (IQueryAdapter queryreactor2 = Yupi.GetDatabaseManager().GetQueryReactor()) queryreactor2.RunFastQuery( $"INSERT INTO items_moodlight (item_id,enabled,current_preset,preset_one,preset_two,preset_three) VALUES ({id33},'0',1,'#000000,255,0','#000000,255,0','#000000,255,0')"); break; case Interaction.Trophy: case Interaction.Bed: case Interaction.PressurePadBed: case Interaction.Guillotine: case Interaction.ScoreBoard: case Interaction.VendingMachine: case Interaction.Alert: case Interaction.OneWayGate: case Interaction.LoveShuffler: case Interaction.HabboWheel: case Interaction.Dice: case Interaction.Bottle: case Interaction.Hopper: case Interaction.Rentals: case Interaction.Pet: case Interaction.Pool: case Interaction.Roller: case Interaction.FootballGate: list.Add(session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, extraData, 0u, true, false, limno, limtot)); break; case Interaction.Teleport: case Interaction.QuickTeleport: UserItem userItem = session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, "0", 0u, true, false, 0, 0); uint id = userItem.Id; UserItem userItem2 = session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, "0", 0u, true, false, 0, 0); uint id2 = userItem2.Id; list.Add(userItem); list.Add(userItem2); using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) queryReactor.RunFastQuery($"INSERT INTO items_teleports (tele_one_id,tele_two_id) VALUES ('{id}','{id2}');" + $"INSERT INTO items_teleports (tele_one_id,tele_two_id) VALUES ('{id2}','{id}')"); break; case Interaction.PetDog: case Interaction.PetCat: case Interaction.PetCrocodile: case Interaction.PetTerrier: case Interaction.PetBear: case Interaction.PetPig: case Interaction.PetLion: case Interaction.PetRhino: case Interaction.PetSpider: case Interaction.PetTurtle: case Interaction.PetChick: case Interaction.PetFrog: case Interaction.PetDragon: case Interaction.PetHorse: case Interaction.PetMonkey: case Interaction.PetGnomo: case Interaction.PetMonsterPlant: case Interaction.PetWhiteRabbit: case Interaction.PetEvilRabbit: case Interaction.PetLoveRabbit: case Interaction.PetPigeon: case Interaction.PetEvilPigeon: case Interaction.PetDemonMonkey: case Interaction.Pet24: case Interaction.Pet25: case Interaction.Pet26: case Interaction.Pet27: case Interaction.Pet28: case Interaction.Pet29: case Interaction.Pet30: case Interaction.Pet31: case Interaction.Pet32: case Interaction.Pet33: case Interaction.Pet34: string[] petData = extraData.Split('\n'); int petId = int.Parse(item.Name.Replace("a0 pet", string.Empty)); Pet generatedPet = CreatePet(session.GetHabbo().Id, petData[0], petId, petData[1], petData[2]); session.GetHabbo().GetInventoryComponent().AddPet(generatedPet); list.Add(session.GetHabbo().GetInventoryComponent().AddNewItem(0, item.Name, "0", 0u, true, false, 0, 0, string.Empty)); break; case Interaction.MusicDisc: list.Add(session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, extraData, 0u, true, false, 0, 0, songCode)); break; case Interaction.PuzzleBox: list.Add(session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, extraData, 0u, true, false, limno, limtot)); break; case Interaction.RoomBg: UserItem userItem44 = session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, extraData, 0u, true, false, 0, 0, string.Empty); uint id44 = userItem44.Id; list.Add(userItem44); using (IQueryAdapter queryreactor3 = Yupi.GetDatabaseManager().GetQueryReactor()) queryreactor3.RunFastQuery($"INSERT INTO items_toners VALUES ({id44},'0',0,0,0)"); break; case Interaction.GuildItem: case Interaction.GuildGate: case Interaction.GroupForumTerminal: list.Add(session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, "0", Convert.ToUInt32(extraData), true, false, 0, 0, string.Empty)); break; case Interaction.GuildForum: uint groupId; uint.TryParse(extraData, out groupId); Group group = Yupi.GetGame().GetGroupManager().GetGroup(groupId); if (group != null) { if (group.CreatorId == session.GetHabbo().Id) { group.UpdateForum(true); } else { session.SendNotif(Yupi.GetLanguage().GetVar("user_group_owner_error")); } } list.Add(session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, "0", Convert.ToUInt32(extraData), true, false, 0, 0, string.Empty)); break; default: list.Add(session.GetHabbo().GetInventoryComponent().AddNewItem(0u, item.Name, extraData, 0u, true, false, limno, limtot)); break; } i++; } return(list); case 'e': for (int j = 0; j < amount; j++) { session.GetHabbo().GetAvatarEffectsInventoryComponent().AddNewEffect(item.SpriteId, 7200, 0); } break; case 'r': RoomBot bot = BotManager.CreateBotFromCatalog(item.Name, session.GetHabbo().Id); session.GetHabbo().GetInventoryComponent().AddBot(bot); session.SendMessage(session.GetHabbo().GetInventoryComponent().SerializeBotInventory()); break; } return(list); }
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet) { if (!Session.GetHabbo().InRoom) { return; } Room Room = null; if (!PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(Session.GetHabbo().CurrentRoomId, out Room)) { return; } if ((Room.AllowPets == 0 && !Room.CheckRights(Session, true)) || !Room.CheckRights(Session, true)) { Session.SendMessage(new RoomErrorNotifComposer(1)); return; } if (Room.GetRoomUserManager().PetCount > PlusStaticGameSettings.RoomPetPlacementLimit) { Session.SendMessage(new RoomErrorNotifComposer(2));//5 = I have too many. return; } Pet Pet = null; if (!Session.GetHabbo().GetInventoryComponent().TryGetPet(Packet.PopInt(), out Pet)) { return; } if (Pet == null) { return; } if (Pet.PlacedInRoom) { Session.SendNotification("Este animal de estimação já está no quarto"); return; } int X = Packet.PopInt(); int Y = Packet.PopInt(); if (!Room.GetGameMap().CanWalk(X, Y, false)) { Session.SendMessage(new RoomErrorNotifComposer(4)); return; } RoomUser OldPet = null; if (Room.GetRoomUserManager().TryGetPet(Pet.PetId, out OldPet)) { Room.GetRoomUserManager().RemoveBot(OldPet.VirtualId, false); } Pet.X = X; Pet.Y = Y; Pet.PlacedInRoom = true; Pet.RoomId = Room.RoomId; List <RandomSpeech> RndSpeechList = new List <RandomSpeech>(); RoomBot RoomBot = new RoomBot(Pet.PetId, Pet.RoomId, "pet", "freeroam", Pet.Name, "", Pet.Look, X, Y, 0, 0, 0, 0, 0, 0, ref RndSpeechList, "", 0, Pet.OwnerId, false, 0, false, 0); if (RoomBot == null) { return; } //old//Room.GetRoomUserManager().DeployBot(RoomBot, Pet); RoleplayBotManager.DeployBotByID(RoomBot.Id, "owner", Room.Id); Pet.DBState = DatabaseUpdateState.NeedsUpdate; Room.GetRoomUserManager().UpdatePets(); Pet ToRemove = null; if (!Session.GetHabbo().GetInventoryComponent().TryRemovePet(Pet.PetId, out ToRemove)) { log.Error("Erro ao remover o animal de estimação: " + ToRemove.PetId); return; } Session.SendMessage(new PetInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetPets())); }
internal RoomBot DeployBotToRoom(GameClient Session, string PetName, uint RoomId) { if (!Session.GetRoleplay().MyPets.ContainsKey(PetName.ToLower())) { return(null); } Session.GetHabbo().GetInventoryComponent().RefreshPets(); uint petId = Session.GetRoleplay().MyPets[PetName.ToLower()]; var pet = Session.GetHabbo().GetInventoryComponent().GetPet(petId); if (pet == null) { Session.GetRoleplay().LastPetName = null; // Console.WriteLine("Pet was null"); return(null); } #region Conditions if (Session.GetHabbo().CurrentRoom.RoomData.Description.Contains("NOPET")) { Session.GetRoleplay().LastPetName = null; Session.GetHabbo().GetRoomUser().LastBubble = 34; Session.SendWhisper("Sorry but this room doesnt allow pets!"); Session.GetHabbo().GetRoomUser().LastBubble = 0; return(null); } #endregion Room room = Plus.GetGame().GetRoomManager().GetRoom(RoomId); int x = Session.GetHabbo().GetRoomUser().X; int y = Session.GetHabbo().GetRoomUser().Y; if (!room.GetGameMap().CanWalk(x, y, false, 0u)) { // Console.WriteLine("spawnpoint was shit"); return(null); } AIType Type = AIType.Pet; string PetType = "pet"; using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor()) { queryReactor.RunFastQuery("UPDATE bots SET room_id = '" + room.RoomId + "', x = '" + x + "', y = '" + y + "' WHERE id = '" + petId + "'"); queryReactor.SetQuery("SELECT ai_type FROM bots WHERE id = " + petId + ""); DataRow Row = queryReactor.GetRow(); if (Row != null) { PetType = Convert.ToString(Row["ai_type"]); } } switch (PetType) { case "fight_pet": case "fightpet": Type = AIType.FightPet; break; case "pet": Type = AIType.Pet; break; } if (Type == AIType.FightPet) { x = Session.GetHabbo().GetRoomUser().SquareBehind.X; y = Session.GetHabbo().GetRoomUser().SquareBehind.Y; if (Session.GetHabbo().GetRoomUser().MyPet != null) { Session.SendWhisper("Please pickup your current pet!"); return(null); } // RoleplayManager.Shout(Session, "*Places their pet down*"); Session.GetRoleplay().UsingPet = true; Session.GetRoleplay().mPetID = petId; } pet.PlacedInRoom = true; pet.RoomId = room.RoomId; RoomBot newRoomBot = new RoomBot(pet.PetId, Convert.ToUInt32(pet.OwnerId), pet.RoomId, Type, "freeroam", pet.Name, "", pet.Look, x, y, 0.0, 4, 0, 0, 0, 0, null, null, "", 0, false); room.GetRoomUserManager() .DeployBot(newRoomBot, pet); Session.GetHabbo().GetInventoryComponent().MovePetToRoom(pet.PetId); if (pet.DbState != DatabaseUpdateState.NeedsInsert) { pet.DbState = DatabaseUpdateState.NeedsUpdate; } using (var queryreactor2 = Plus.GetDatabaseManager().GetQueryReactor()) room.GetRoomUserManager().SavePets(queryreactor2); Session.SendMessage(Session.GetHabbo().GetInventoryComponent().SerializePetInventory()); Session.GetHabbo().GetRoomUser().MyPet = newRoomBot.RoomUser; Session.GetHabbo().GetRoomUser().MyPet.FollowingOwner = Session.GetHabbo().GetRoomUser(); Session.GetRoleplay().LastPetName = pet.Name; //Session.SendWhisper("Your bot should be here..."); return(newRoomBot); }
internal RoomUser DeployBot(RoomBot Bot) { return(roomUserManager.DeployBot(Bot, null)); }
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet) { if (!Session.GetHabbo().InRoom) { return; } Room Room = null; if (!QuasarEnvironment.GetGame().GetRoomManager().TryGetRoom(Session.GetHabbo().CurrentRoomId, out Room)) { return; } if ((Room.AllowPets == 0 && !Room.CheckRights(Session, true)) || !Room.CheckRights(Session, true)) { Session.SendMessage(new RoomErrorNotifComposer(1)); return; } if (Room.GetRoomUserManager().PetCount > QuasarStaticGameSettings.RoomPetPlacementLimit) { Session.SendMessage(new RoomErrorNotifComposer(2));//5 = I have too many. return; } Pet Pet = null; if (!Session.GetHabbo().GetInventoryComponent().TryGetPet(Packet.PopInt(), out Pet)) { return; } if (Pet == null) { return; } if (Pet.PlacedInRoom) { Session.SendNotification("Oeps! Er is wat mis gegaan, de huisdier is al in de kamer."); return; } int X = Packet.PopInt(); int Y = Packet.PopInt(); if (!Room.GetGameMap().CanWalk(X, Y, false)) { Session.SendMessage(new RoomErrorNotifComposer(4)); return; } RoomUser OldPet = null; if (Room.GetRoomUserManager().TryGetPet(Pet.PetId, out OldPet)) { Room.GetRoomUserManager().RemoveBot(OldPet.VirtualId, false); } Pet.X = X; Pet.Y = Y; Pet.PlacedInRoom = true; Pet.RoomId = Room.RoomId; List <RandomSpeech> RndSpeechList = new List <RandomSpeech>(); RoomBot RoomBot = new RoomBot(Pet.PetId, Pet.RoomId, "pet", "freeroam", Pet.Name, "", Pet.Look, X, Y, 0, 0, 0, 0, 0, 0, ref RndSpeechList, "", 0, Pet.OwnerId, false, 0, false, 0); if (RoomBot == null) { return; } Room.GetRoomUserManager().DeployBot(RoomBot, Pet); Pet.DBState = DatabaseUpdateState.NeedsUpdate; Room.GetRoomUserManager().UpdatePets(); Pet ToRemove = null; if (!Session.GetHabbo().GetInventoryComponent().TryRemovePet(Pet.PetId, out ToRemove)) { string CurrentTime = DateTime.Now.ToString("HH:mm:ss" + " | "); Console.WriteLine(CurrentTime + "Fout bij het verwijderen van huisdier: " + ToRemove.PetId); return; } Session.SendMessage(new PetInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetPets())); }
internal static UserData GetUserData(string sessionTicket, string ip, out byte errorCode) { DataTable dataTable = null; DataRow dataRow; uint Userid; DataTable dataTable2; DataTable table; DataRow row; DataTable dataTable3; DataTable dataTable4; DataTable dataTable5; DataRow dataRow2; DataTable dataTable6; DataTable dataTable7; DataTable dataTable8; DataTable dataTable9; DataTable dataTable10; DataTable dataTable11; DataTable dataTable12; DataTable dataTable13; DataTable table2; DataTable dataTable14; DataTable dataTable15; using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor.setQuery("SELECT * FROM users WHERE auth_ticket = @sso "); queryreactor.addParameter("sso", sessionTicket); queryreactor.addParameter("ipaddress", ip); dataRow = queryreactor.getRow(); if (dataRow == null) { errorCode = 1; throw new UserDataNotFoundException(string.Format("No user found with ip {0} and sso {1}.", ip, sessionTicket)); } Userid = Convert.ToUInt32(dataRow["id"]); queryreactor.runFastQuery("UPDATE users SET online='1' WHERE id=" + Userid + " LIMIT 1"); if (CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(Userid) != null) { errorCode = 2; CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(Userid).Disconnect(); return(null); } queryreactor.setQuery("SELECT * FROM user_achievement WHERE userid = " + Userid); dataTable2 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_talents WHERE userid = " + Userid); table = queryreactor.getTable(); queryreactor.setQuery("SELECT COUNT(*) FROM user_stats WHERE id=" + Userid); if (int.Parse(queryreactor.getString()) == 0) { queryreactor.runFastQuery("INSERT INTO user_stats (id) VALUES (" + Userid + ");"); } queryreactor.setQuery("SELECT * FROM user_stats WHERE id=" + Userid + " LIMIT 1"); row = queryreactor.getRow(); queryreactor.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + Userid); dataTable3 = queryreactor.getTable(); queryreactor.setQuery("SELECT ignore_id FROM user_ignores WHERE user_id = " + Userid); dataTable4 = queryreactor.getTable(); queryreactor.setQuery("SELECT tag FROM user_tags WHERE user_id = " + Userid); dataTable5 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_subscriptions WHERE user_id = " + Userid + " AND timestamp_expire > UNIX_TIMESTAMP() ORDER BY subscription_id DESC LIMIT 1"); dataRow2 = queryreactor.getRow(); queryreactor.setQuery("SELECT * FROM user_badges WHERE user_id = " + Userid); dataTable6 = queryreactor.getTable(); queryreactor.setQuery("SELECT `items`.* , COALESCE(`items_groups`.`group_id`, 0) AS group_id FROM `items` LEFT OUTER JOIN `items_groups` ON `items`.`id` = `items_groups`.`id` WHERE room_id='0' AND user_id=" + Userid + " LIMIT 8000"); dataTable7 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_effects WHERE user_id = " + Userid); dataTable8 = queryreactor.getTable(); queryreactor.setQuery("SELECT poll_id FROM user_polldata WHERE user_id = " + Userid + " GROUP BY poll_id;"); dataTable9 = queryreactor.getTable(); queryreactor.setQuery(string.Concat(new object[] { "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ", Userid, " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ", Userid })); dataTable10 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_stats WHERE id=" + Userid + " LIMIT 1"); row = queryreactor.getRow(); queryreactor.setQuery("SELECT messenger_requests.from_id,messenger_requests.to_id,users.username FROM users JOIN messenger_requests ON users.id = messenger_requests.from_id WHERE messenger_requests.to_id = " + Userid); dataTable11 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM rooms WHERE owner = @name LIMIT 150"); queryreactor.addParameter("name", (string)dataRow["username"]); dataTable12 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM bots WHERE user_id = " + Userid + " AND room_id = 0 AND ai_type='pet'"); dataTable13 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM user_quests WHERE user_id = " + Userid); table2 = queryreactor.getTable(); queryreactor.setQuery("SELECT * FROM bots WHERE user_id=" + Userid + " AND room_id=0 AND ai_type='generic'"); dataTable14 = queryreactor.getTable(); queryreactor.setQuery("SELECT group_id,rank FROM group_memberships WHERE user_id=" + Userid); dataTable = queryreactor.getTable(); queryreactor.setQuery(string.Concat(new object[] { "UPDATE user_info SET login_timestamp = '", CyberEnvironment.GetUnixTimestamp(), "' WHERE user_id = ", Userid, " ; " })); queryreactor.addParameter("ip", ip); queryreactor.runQuery(); queryreactor.setQuery("SELECT * FROM user_relationships WHERE user_id=@id"); queryreactor.addParameter("id", Userid); dataTable15 = queryreactor.getTable(); queryreactor.runFastQuery("UPDATE users SET online='1' WHERE id=" + Userid + " LIMIT 1"); } Dictionary <string, UserAchievement> dictionary = new Dictionary <string, UserAchievement>(); foreach (DataRow dataRow3 in dataTable2.Rows) { string text = (string)dataRow3["group"]; int level = (int)dataRow3["level"]; int progress = (int)dataRow3["progress"]; UserAchievement value = new UserAchievement(text, level, progress); dictionary.Add(text, value); } Dictionary <int, UserTalent> dictionary2 = new Dictionary <int, UserTalent>(); foreach (DataRow dataRow4 in table.Rows) { int num2 = (int)dataRow4["talent_id"]; int state = (int)dataRow4["talent_state"]; UserTalent value2 = new UserTalent(num2, state); dictionary2.Add(num2, value2); } List <uint> list = new List <uint>(); foreach (DataRow dataRow5 in dataTable3.Rows) { uint item = Convert.ToUInt32(dataRow5["room_id"]); list.Add(item); } List <uint> list2 = new List <uint>(); foreach (DataRow dataRow6 in dataTable4.Rows) { uint item2 = Convert.ToUInt32(dataRow6["ignore_id"]); list2.Add(item2); } List <string> list3 = new List <string>(); foreach (DataRow dataRow7 in dataTable5.Rows) { string item3 = dataRow7["tag"].ToString().Replace(" ", ""); list3.Add(item3); } Subscription sub = null; if (dataRow2 != null) { sub = new Subscription((int)dataRow2["subscription_id"], (int)dataRow2["timestamp_activated"], (int)dataRow2["timestamp_expire"], (int)dataRow2["timestamp_lastgift"]); } Dictionary <uint, RoomBot> dictionary3 = new Dictionary <uint, RoomBot>(); foreach (DataRow row2 in dataTable14.Rows) { RoomBot roomBot = BotManager.GenerateBotFromRow(row2); dictionary3.Add(roomBot.BotId, roomBot); } List <Badge> list4 = new List <Badge>(); foreach (DataRow dataRow8 in dataTable6.Rows) { string code = (string)dataRow8["badge_id"]; int slot = (int)dataRow8["badge_slot"]; list4.Add(new Badge(code, slot)); } int miniMailCount = 0; try { DataRow Rowi; using (IQueryAdapter dbClient = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { dbClient.setQuery("SELECT Count( IsReaded ) FROM xdrcms_minimail WHERE InBin = 0 AND IsReaded = 0 AND SenderId != " + Userid + " AND OwnerId = " + Userid); Rowi = dbClient.getRow(); } if (Rowi != null) { // We are using aXDR CMS with MiniMail! miniMailCount = int.Parse(Rowi[0].ToString()); } } catch { } List <UserItem> list5 = new List <UserItem>(); foreach (DataRow dataRow9 in dataTable7.Rows) { uint id = Convert.ToUInt32(dataRow9[0]); uint baseItem = Convert.ToUInt32(dataRow9[3]); string extraData; if (!DBNull.Value.Equals(dataRow9[4])) { extraData = (string)dataRow9[4]; } else { extraData = string.Empty; } uint group = Convert.ToUInt32(dataRow9["group_id"]); string songCode = (string)dataRow9["songcode"]; list5.Add(new UserItem(id, baseItem, extraData, group, songCode)); } List <AvatarEffect> list6 = new List <AvatarEffect>(); foreach (DataRow dataRow10 in dataTable8.Rows) { int effectId = (int)dataRow10["effect_id"]; int totalDuration = (int)dataRow10["total_duration"]; bool activated = CyberEnvironment.EnumToBool((string)dataRow10["is_activated"]); double activateTimestamp = (double)dataRow10["activated_stamp"]; list6.Add(new AvatarEffect(effectId, totalDuration, activated, activateTimestamp)); } HashSet <uint> pollSuggested = new HashSet <uint>(); foreach (DataRow Row in dataTable9.Rows) { uint pId = (uint)Row["poll_id"]; pollSuggested.Add(pId); } Dictionary <uint, MessengerBuddy> dictionary4 = new Dictionary <uint, MessengerBuddy>(); string arg_A3D_0 = (string)dataRow["username"]; int num3 = checked (dataTable10.Rows.Count - 700); if (num3 > 0) { using (IQueryAdapter queryreactor2 = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor2.runFastQuery(string.Concat(new object[] { "DELETE FROM messenger_friendships WHERE user_one_id=", Userid, " OR user_two_id=", Userid, " LIMIT ", num3 })); queryreactor2.setQuery(string.Concat(new object[] { "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ", Userid, " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ", Userid })); dataTable10 = queryreactor2.getTable(); } } foreach (DataRow dataRow12 in dataTable10.Rows) { uint num4 = Convert.ToUInt32(dataRow12["id"]); string pUsername = (string)dataRow12["username"]; string pLook = (string)dataRow12["look"]; string pMotto = (string)dataRow12["motto"]; int pLastOnline = Convert.ToInt32(dataRow12["last_online"]); bool pAppearOffline = CyberEnvironment.EnumToBool(dataRow12["hide_online"].ToString()); bool pHideInroom = CyberEnvironment.EnumToBool(dataRow12["hide_inroom"].ToString()); if (num4 != Userid && !dictionary4.ContainsKey(num4)) { dictionary4.Add(num4, new MessengerBuddy(num4, pUsername, pLook, pMotto, pLastOnline, pAppearOffline, pHideInroom)); } } Dictionary <uint, MessengerRequest> dictionary5 = new Dictionary <uint, MessengerRequest>(); foreach (DataRow dataRow13 in dataTable11.Rows) { uint num5 = Convert.ToUInt32(dataRow13["from_id"]); uint num6 = Convert.ToUInt32(dataRow13["to_id"]); string pUsername2 = (string)dataRow13["username"]; if (num5 != Userid) { if (!dictionary5.ContainsKey(num5)) { dictionary5.Add(num5, new MessengerRequest(Userid, num5, pUsername2)); } } else { if (!dictionary5.ContainsKey(num6)) { dictionary5.Add(num6, new MessengerRequest(Userid, num6, pUsername2)); } } } HashSet <RoomData> list8 = new HashSet <RoomData>(); foreach (DataRow dataRow14 in dataTable12.Rows) { uint roomId = Convert.ToUInt32(dataRow14["id"]); list8.Add(CyberEnvironment.GetGame().GetRoomManager().FetchRoomData(roomId, dataRow14)); } Dictionary <uint, Pet> dictionary6 = new Dictionary <uint, Pet>(); foreach (DataRow dataRow15 in dataTable13.Rows) { using (IQueryAdapter queryreactor3 = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor3.setQuery("SELECT * FROM bots_petdata WHERE id=" + dataRow15[0] + " LIMIT 1"); DataRow row3 = queryreactor3.getRow(); if (row3 != null) { Pet pet = Catalog.GeneratePetFromRow(dataRow15, row3); dictionary6.Add(pet.PetId, pet); } } } Dictionary <uint, int> dictionary7 = new Dictionary <uint, int>(); foreach (DataRow dataRow16 in table2.Rows) { uint key = Convert.ToUInt32(dataRow16["quest_id"]); int value3 = (int)dataRow16["progress"]; if (dictionary7.ContainsKey(key)) { dictionary7.Remove(key); } dictionary7.Add(key, value3); } HashSet <GroupUser> list9 = new HashSet <GroupUser>(); foreach (DataRow dataRow17 in dataTable.Rows) { list9.Add(new GroupUser(Userid, (uint)dataRow17[0], (int)Convert.ToInt16(dataRow17[1]))); } Dictionary <int, Relationship> dictionary8 = new Dictionary <int, Relationship>(); foreach (DataRow dataRow18 in dataTable15.Rows) { dictionary8.Add((int)dataRow18[0], new Relationship((int)dataRow18[0], (int)dataRow18[2], Convert.ToInt32(dataRow18[3].ToString()))); } Habbo user = HabboFactory.GenerateHabbo(dataRow, row, list9); dataRow = null; dataTable2 = null; dataTable3 = null; dataTable4 = null; dataTable5 = null; dataRow2 = null; dataTable6 = null; dataTable7 = null; dataTable8 = null; dataTable10 = null; dataTable11 = null; dataTable12 = null; dataTable13 = null; dataTable14 = null; dataTable15 = null; dataTable9 = null; errorCode = 0; return(new UserData(Userid, dictionary, dictionary2, list, list2, list3, sub, list4, list5, list6, dictionary4, dictionary5, list8, dictionary6, dictionary7, user, dictionary3, dictionary8, pollSuggested, miniMailCount)); }
public RoomUser method_3(RoomBot class34_0) { return this.method_4(class34_0, null); }
public RoomUser method_4(RoomBot Bot, Pet PetData) { int num = this.method_5(); RoomUser user = new RoomUser(Convert.ToUInt32(num + 100000), this.Id, this.int_7++, true); user.int_20 = num; this.RoomUser_0[num] = user; if (Bot.x > 0 && Bot.y > 0 && Bot.x < this.Class28_0.int_4 && Bot.y < this.Class28_0.int_5) { user.method_7(Bot.x, Bot.y, Bot.z); user.method_9(Bot.Rotation); } else { Bot.x = this.Class28_0.int_0; Bot.y = this.Class28_0.int_1; user.method_7(this.Class28_0.int_0, this.Class28_0.int_1, this.Class28_0.double_0); user.method_9(this.Class28_0.int_2); } user.class34_0 = Bot; user.BotAI = Bot.method_4(user.VirtualId); if (user.isPet) { user.BotAI.Init((int)Bot.Id, user.VirtualId, this.Id); user.PetData = PetData; user.PetData.VirtualId = user.VirtualId; } else { user.BotAI.Init(-1, user.VirtualId, this.Id); } this.method_87(user, true, true); user.UpdateNeeded = true; ServerMessage Message = new ServerMessage(28u); Message.AppendInt32(1); user.method_14(Message); this.SendMessage(Message, null); user.BotAI.OnSelfEnterRoom(); return user; }
public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet) { if (!Session.GetHabbo().InRoom) { return; } Room Room = Session.GetHabbo().CurrentRoom; if (Room == null) { return; } int BotId = Packet.PopInt(); int ActionId = Packet.PopInt(); string DataString = Packet.PopString(); if (ActionId < 1 || ActionId > 5) { return; } if (!Room.GetRoomUserManager().TryGetBot(BotId, out RoomUser Bot)) { return; } if ((Bot.BotData.ownerID != Session.GetHabbo().Id&& !Session.GetHabbo().GetPermissions().HasRight("bot_edit_any_override"))) { return; } RoomBot RoomBot = Bot.BotData; if (RoomBot == null) { return; } /* 1 = Copy looks * 2 = Setup Speech * 3 = Relax * 4 = Dance * 5 = Change Name */ switch (ActionId) { #region Copy Looks (1) case 1: { ServerPacket UserChangeComposer = new ServerPacket(ServerPacketHeader.UserChangeMessageComposer); UserChangeComposer.WriteInteger(Bot.VirtualId); UserChangeComposer.WriteString(Session.GetHabbo().Look); UserChangeComposer.WriteString(Session.GetHabbo().Gender); UserChangeComposer.WriteString(Bot.BotData.Motto); UserChangeComposer.WriteInteger(0); Room.SendMessage(UserChangeComposer); //Change the defaults Bot.BotData.Look = Session.GetHabbo().Look; Bot.BotData.Gender = Session.GetHabbo().Gender; using (IQueryAdapter dbClient = NeonEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `bots` SET `look` = @look, `gender` = '" + Session.GetHabbo().Gender + "' WHERE `id` = '" + Bot.BotData.Id + "' LIMIT 1"); dbClient.AddParameter("look", Session.GetHabbo().Look); dbClient.RunQuery(); } //Room.SendMessage(new UserChangeComposer(BotUser.GetClient(), true)); break; } #endregion #region Setup Speech (2) case 2: { string[] ConfigData = DataString.Split(new string[] { ";#;" }, StringSplitOptions.None); string[] SpeechData = ConfigData[0].Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); string AutomaticChat = Convert.ToString(ConfigData[1]); string SpeakingInterval = Convert.ToString(ConfigData[2]); string MixChat = Convert.ToString(ConfigData[3]); if (string.IsNullOrEmpty(SpeakingInterval) || Convert.ToInt32(SpeakingInterval) <= 0 || Convert.ToInt32(SpeakingInterval) < 7) { SpeakingInterval = "7"; } RoomBot.AutomaticChat = Convert.ToBoolean(AutomaticChat); RoomBot.SpeakingInterval = Convert.ToInt32(SpeakingInterval); RoomBot.MixSentences = Convert.ToBoolean(MixChat); using (IQueryAdapter dbClient = NeonEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("DELETE FROM `bots_speech` WHERE `bot_id` = '" + Bot.BotData.Id + "'"); } #region Save Data - TODO: MAKE METHODS FOR THIS. for (int i = 0; i <= SpeechData.Length - 1; i++) { SpeechData[i] = Regex.Replace(SpeechData[i], "<(.|\\n)*?>", string.Empty); using (IQueryAdapter dbClient = NeonEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("INSERT INTO `bots_speech` (`bot_id`, `text`) VALUES (@id, @data)"); dbClient.AddParameter("id", BotId); dbClient.AddParameter("data", SpeechData[i]); dbClient.RunQuery(); dbClient.SetQuery("UPDATE `bots` SET `automatic_chat` = @AutomaticChat, `speaking_interval` = @SpeakingInterval, `mix_sentences` = @MixChat WHERE `id` = @id LIMIT 1"); dbClient.AddParameter("id", BotId); dbClient.AddParameter("AutomaticChat", AutomaticChat.ToLower()); dbClient.AddParameter("SpeakingInterval", Convert.ToInt32(SpeakingInterval)); dbClient.AddParameter("MixChat", NeonEnvironment.BoolToEnum(Convert.ToBoolean(MixChat))); dbClient.RunQuery(); } } #endregion #region Handle Speech RoomBot.RandomSpeech.Clear(); using (IQueryAdapter dbClient = NeonEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("SELECT `text` FROM `bots_speech` WHERE `bot_id` = @id"); dbClient.AddParameter("id", BotId); DataTable BotSpeech = dbClient.getTable(); List <RandomSpeech> Speeches = new List <RandomSpeech>(); foreach (DataRow Speech in BotSpeech.Rows) { RoomBot.RandomSpeech.Add(new RandomSpeech(Convert.ToString(Speech["text"]), BotId)); } } #endregion break; } #endregion #region Relax (3) case 3: { if (Bot.BotData.WalkingMode == "stand") { Bot.BotData.WalkingMode = "freeroam"; } else { Bot.BotData.WalkingMode = "stand"; } using (IQueryAdapter dbClient = NeonEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.RunQuery("UPDATE `bots` SET `walk_mode` = '" + Bot.BotData.WalkingMode + "' WHERE `id` = '" + Bot.BotData.Id + "' LIMIT 1"); } break; } #endregion #region Dance (4) case 4: { if (Bot.BotData.DanceId > 0) { Bot.BotData.DanceId = 0; } else { Random RandomDance = new Random(); Bot.BotData.DanceId = RandomDance.Next(1, 4); } Room.SendMessage(new DanceComposer(Bot, Bot.BotData.DanceId)); break; } #endregion #region Change Name (5) case 5: { if (DataString.Length == 0) { Session.SendWhisper("Vamos, ponle algun nombre al bot"); return; } else if (DataString.Length >= 16) { Session.SendWhisper("Vamos.. necesitas un nombre mas corto!"); return; } if (DataString.Contains("<img src") || DataString.Contains("<font ") || DataString.Contains("</font>") || DataString.Contains("</a>") || DataString.Contains("<i>")) { Session.SendWhisper("¿Qué intentas, crack?", 34); return; } Bot.BotData.Name = DataString; using (IQueryAdapter dbClient = NeonEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("UPDATE `bots` SET `name` = @name WHERE `id` = '" + Bot.BotData.Id + "' LIMIT 1"); dbClient.AddParameter("name", DataString); dbClient.RunQuery(); } Room.SendMessage(new UsersComposer(Bot)); break; } #endregion } }
internal static bool ExecuteAttackBot(GameClient User1, RoomUser RoomUser2, Pet Pet, RoomBot BotData) { Room Room = User1.GetHabbo().CurrentRoom; RoomUser RoomUser1 = User1.GetHabbo().GetRoomUser(); Vector2D Pos1 = new Vector2D(RoomUser1.X, RoomUser1.Y); Vector2D Pos2 = new Vector2D(RoomUser2.X, RoomUser2.Y); bool canattack = false; #region Cooldown if (User1.GetRoleplay().CoolDown > 0) { User1.SendWhisper("Cooling down [" + User1.GetRoleplay().CoolDown + "/3]"); return(false); } #endregion #region Distance if (RoleplayManager.WithinAttackDistance(RoomUser1, RoomUser2)) { canattack = true; } else if (RoleplayManager.Distance(Pos1, Pos2) > 1 && RoleplayManager.Distance(Pos1, Pos2) <= 4) { User1.Shout("*Swings at " + BotData.Name + ", but misses*"); return(false); } else if (RoleplayManager.Distance(Pos1, Pos2) >= 5) { User1.SendWhisper("You are too far away!"); return(false); } #endregion #region Status Conditions if (Room.RoomData.Description.Contains("NOHIT") && RoleplayManager.PurgeTime == false) { User1.SendWhisper("Sorry, but this is a no hitting zone!"); User1.GetRoleplay().CoolDown = 3; return(false); } if (Room.RoomData.Description.Contains("SAFEZONE")) { User1.SendWhisper("Sorry, but this is a safezone!"); User1.GetRoleplay().CoolDown = 3; return(false); } if (User1.GetRoleplay().Energy <= 0) { User1.SendWhisper("You do not have enough energy to do this!"); return(false); } if (User1.GetRoleplay().Dead) { User1.SendWhisper("Cannot complete this action while you are dead!"); User1.GetRoleplay().CoolDown = 3; return(false); } if (User1.GetRoleplay().Jailed) { User1.SendWhisper("Cannot complete this action while you are jailed!"); User1.GetRoleplay().CoolDown = 3; return(false); } if (RoomUser1.Stunned) { User1.SendWhisper("Cannot complete this action while you are stunned!"); User1.GetRoleplay().CoolDown = 3; return(false); } #endregion if (canattack) { GameClient Session = User1; int Damage = CombatManager.DamageCalculator(User1); BotData.cur_Health -= Damage; if (BotData.cur_Health <= 0) { if (RoomUser2.BotData != null && RoomUser2.BotData._Boss) { Session.GetRoleplay().GiveMafiaWarPoints(MafiaWarManager.BossKillPoints); User1.Shout("*Swings at " + BotData.Name + ", causing " + Damage + " damage and killing them and winning the Game! [+ " + MafiaWarManager.BossKillPoints + " Mafia Wars Pts]*"); } else if (!RoomUser2.BotData._Boss) { Session.GetRoleplay().GiveMafiaWarPoints(MafiaWarManager.ThugKillPoints); User1.Shout("*Swings at " + BotData.Name + ", causing " + Damage + " damage and killing them! [+ " + MafiaWarManager.ThugKillPoints + " Mafia Wars Pts]*"); } RoomUser2.Chat(null, "*Passes out*", true, 1); User1.GetHabbo().GetRoomUser().Attacker = null; RoomUser2.BotAI._Victim = null; if (RoomUser2.IsPet) { if (RoomUser2.FollowingOwner != null) { RoomUser2.FollowingOwner.GetClient().GetMessageHandler().PickUpPet(RoomUser2.FollowingOwner.GetClient(), RoomUser2.PetData.PetId, true); return(true); } else { Room.GetRoomUserManager().RemoveBot(RoomUser2.VirtualId, true); } } else { Room.GetRoomUserManager().RemoveBot(RoomUser2.VirtualId, true); } if (RoomUser2.BotData != null && RoomUser2.BotData._Boss) { Session.GetRoleplay().GiveMafiaWarPoints(MafiaWarManager.BossKillPoints); if (RoomUser2.BotData._Team.TeamName == "Green") { Plus.GetGame().MafiaWars.TeamWon("Blue"); } else { Plus.GetGame().MafiaWars.TeamWon("Green"); } } } else { User1.Shout("*Swings at " + BotData.Name + ", causing " + Damage + " damage*"); RoomUser2.Chat(null, "[" + BotData.cur_Health + "/" + BotData.max_Health + "]", true, 1); if (User1.GetHabbo().GetRoomUser().Attacker != null) { User1.GetHabbo().GetRoomUser().Attacker = null; RoomUser2.BotAI._Victim = User1.GetHabbo().GetRoomUser(); } User1.GetRoleplay().LastHitBot = RoomUser2; } Session.GetRoleplay().CoolDown = 3; } return(true); }