/// <summary> /// Generates the bot from row. /// </summary> /// <param name="row">The row.</param> /// <returns>RoomBot.</returns> internal static RoomBot GenerateBotFromRow(DataRow row) { if (row == null) { return(null); } uint id = Convert.ToUInt32(row["id"]); List <string> speeches = null; if (!row.IsNull("speech") && !string.IsNullOrEmpty(row["speech"].ToString())) { speeches = row["speech"].ToString().Split(';').ToList(); } RoomBot bot = new RoomBot(id, (uint)row["user_id"], AiType.Generic, row["bot_type"].ToString()); bot.Update((uint)row["room_id"], row["walk_mode"].ToString(), (string)row["name"], (string)row["motto"], (string)row["look"], int.Parse(row["x"].ToString()), int.Parse(row["y"].ToString()), int.Parse(row["z"].ToString()), 4, 0, 0, 0, 0, speeches, null, row["gender"].ToString(), (uint)row["dance"], (uint)row["speaking_interval"], (int)row["automatic_chat"] == 1, (int)row["mix_phrases"] == 1); return(bot); }
/// <summary> /// Generates the bot from row. /// </summary> /// <param name="row">The row.</param> /// <returns>RoomBot.</returns> internal static RoomBot GenerateBotFromRow(DataRow row) { if (row == null) return null; uint id = Convert.ToUInt32(row["id"]); List<string> speeches = null; if (!row.IsNull("speech") && !string.IsNullOrEmpty(row["speech"].ToString())) speeches = row["speech"].ToString().Split(';').ToList(); RoomBot bot = new RoomBot(id, (uint)row["user_id"], AiType.Generic, row["bot_type"].ToString()); bot.Update((uint)row["room_id"], row["walk_mode"].ToString(), (string) row["name"], (string) row["motto"], (string) row["look"], int.Parse(row["x"].ToString()), int.Parse(row["y"].ToString()), int.Parse(row["z"].ToString()), 4, 0, 0, 0, 0, speeches, null, row["gender"].ToString(), (uint) row["dance"], (uint) row["speaking_interval"], (int)row["automatic_chat"] == 1, (int)row["mix_phrases"] == 1); return bot; }
/// <summary> /// Deploys the bot. /// </summary> /// <param name="bot">The bot.</param> /// <param name="petData">The pet data.</param> /// <returns>RoomUser.</returns> internal RoomUser DeployBot(RoomBot bot, Pet petData) { int virtualId = _primaryPrivateUserId++; RoomUser roomUser = new RoomUser(0u, _userRoom.RoomId, virtualId, _userRoom, false); int num = _secondaryPrivateUserId++; roomUser.InternalRoomId = num; UserList.TryAdd(num, roomUser); OnUserAdd(roomUser); DynamicRoomModel model = _userRoom.GetGameMap().Model; Point coord = new Point(bot.X, bot.Y); if ((bot.X > 0) && (bot.Y >= 0) && (bot.X < model.MapSizeX) && (bot.Y < model.MapSizeY)) { _userRoom.GetGameMap().AddUserToMap(roomUser, coord); roomUser.SetPos(bot.X, bot.Y, bot.Z); roomUser.SetRot(bot.Rot, false); } else { bot.X = model.DoorX; bot.Y = model.DoorY; roomUser.SetPos(model.DoorX, model.DoorY, model.DoorZ); roomUser.SetRot(model.DoorOrientation, false); } bot.RoomUser = roomUser; roomUser.BotData = bot; roomUser.BotAi = bot.GenerateBotAi(roomUser.VirtualId, (int) bot.BotId); if (roomUser.IsPet) { roomUser.BotAi.Init(bot.BotId, roomUser.VirtualId, _userRoom.RoomId, roomUser, _userRoom); roomUser.PetData = petData; roomUser.PetData.VirtualId = roomUser.VirtualId; } else roomUser.BotAi.Init(bot.BotId, roomUser.VirtualId, _userRoom.RoomId, roomUser, _userRoom); UpdateUserStatus(roomUser, false); roomUser.UpdateNeeded = true; ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("SetRoomUserMessageComposer")); serverMessage.AppendInteger(1); roomUser.Serialize(serverMessage, _userRoom.GetGameMap().GotPublicPool); _userRoom.SendMessage(serverMessage); roomUser.BotAi.OnSelfEnterRoom(); if (roomUser.IsPet) { if (_pets.Contains(roomUser.PetData.PetId)) _pets[roomUser.PetData.PetId] = roomUser; else _pets.Add(roomUser.PetData.PetId, roomUser); PetCount++; } roomUser.BotAi.Modified(); if (roomUser.BotData.AiType != AiType.Generic) return roomUser; if (_bots.Contains(roomUser.BotData.BotId)) _bots[roomUser.BotData.BotId] = roomUser; else _bots.Add(roomUser.BotData.BotId, roomUser); serverMessage.Init(LibraryParser.OutgoingRequest("DanceStatusMessageComposer")); serverMessage.AppendInteger(roomUser.VirtualId); serverMessage.AppendInteger(roomUser.BotData.DanceId); _userRoom.SendMessage(serverMessage); PetCount++; return roomUser; }
/// <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> /// Deploys the bot. /// </summary> /// <param name="bot">The bot.</param> /// <returns>RoomUser.</returns> internal RoomUser DeployBot(RoomBot bot) { return _roomUserManager.DeployBot(bot, null); }
/// <summary> /// Initializes the pets. /// </summary> internal void InitPets() { using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery($"SELECT * FROM pets_data WHERE room_id = {RoomId}"); DataTable table = queryReactor.GetTable(); if (table == null) return; foreach (DataRow dataRow in table.Rows) { Pet pet = CatalogManager.GeneratePetFromRow(dataRow); RoomBot bot = new RoomBot(pet.PetId, Convert.ToUInt32(RoomData.OwnerId), AiType.Pet, string.Empty); bot.Update(RoomId, "freeroam", pet.Name, string.Empty, pet.Look, pet.X, pet.Y, (int) pet.Z, 4, 0, 0, 0, 0, null, null, string.Empty, 0, 0, false, false); _roomUserManager.DeployBot(bot, pet); } } }
/// <summary> /// Initializes the pets. /// </summary> internal void InitPets() { using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery($"SELECT * FROM bots_data WHERE room_id = '{RoomId}' AND ai_type='pet'"); DataTable table = queryReactor.GetTable(); if (table == null) return; foreach (DataRow dataRow in table.Rows) { queryReactor.SetQuery($"SELECT * FROM pets_data WHERE id = '{dataRow["id"]}' LIMIT 1"); DataRow row = queryReactor.GetRow(); if (row == null) continue; Pet pet = CatalogManager.GeneratePetFromRow(dataRow, row); RoomBot bot = new RoomBot(pet.PetId, Convert.ToUInt32(RoomData.OwnerId), AiType.Pet, ""); bot.Update(RoomId, "freeroam", pet.Name, "", pet.Look, pet.X, pet.Y, (int) pet.Z, 4, 0, 0, 0, 0, null, null, "", 0, 0, false, false); _roomUserManager.DeployBot(bot, pet); } } }
internal void PlantMonsterplant(RoomItem mopla, Room room) { int rarity = 0, internalRarity; if (room == null || mopla == null) return; if ((mopla.GetBaseItem().InteractionType != Interaction.Moplaseed) && (mopla.GetBaseItem().InteractionType != Interaction.RareMoplaSeed)) return; if (string.IsNullOrEmpty(mopla.ExtraData) || mopla.ExtraData == "0") rarity = 1; if (!string.IsNullOrEmpty(mopla.ExtraData) && mopla.ExtraData != "0") rarity = int.TryParse(mopla.ExtraData, out internalRarity) ? internalRarity : 1; int getX = mopla.X; int getY = mopla.Y; room.GetRoomItemHandler().RemoveFurniture(Session, mopla.Id, false); Pet pet = CatalogManager.CreatePet(Session.GetHabbo().Id, "Monsterplant", "pet_monster", "0", "0", rarity); Response.Init(LibraryParser.OutgoingRequest("SendMonsterplantIdMessageComposer")); Response.AppendInteger(pet.PetId); SendResponse(); using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) queryReactor.RunFastQuery(string.Concat("UPDATE pets_data SET room_id = '", room.RoomId, "', x = '", getX, "', y = '", getY, "' WHERE id = '", pet.PetId, "'")); pet.PlacedInRoom = true; pet.RoomId = room.RoomId; RoomBot bot = new RoomBot(pet.PetId, pet.OwnerId, pet.RoomId, AiType.Pet, "freeroam", pet.Name, "", pet.Look, getX, getY, 0.0, 4, null, null, "", 0, ""); room.GetRoomUserManager().DeployBot(bot, pet); if (pet.DbState != DatabaseUpdateState.NeedsInsert) pet.DbState = DatabaseUpdateState.NeedsUpdate; using (IQueryAdapter queryreactor2 = Yupi.GetDatabaseManager().GetQueryReactor()) { queryreactor2.RunFastQuery($"DELETE FROM items_rooms WHERE id = {mopla.Id}"); room.GetRoomUserManager().SavePets(queryreactor2); } }