/// <summary> /// Loads the furniture. /// </summary> internal void LoadFurniture() { if (FloorItems == null) FloorItems = new ConcurrentDictionary<uint, RoomItem>(); else FloorItems.Clear(); if (WallItems == null) WallItems = new ConcurrentDictionary<uint, RoomItem>(); else WallItems.Clear(); using (var queryReactor = Azure.GetDatabaseManager().GetQueryReactor()) { queryReactor.RunFastQuery("SELECT items_rooms.* , COALESCE(items_groups.group_id, 0) AS group_id FROM items_rooms LEFT OUTER JOIN items_groups ON items_rooms.id = items_groups.id WHERE items_rooms.room_id = " + _room.RoomId + " LIMIT 5000"); var table = queryReactor.GetTable(); if (table.Rows.Count >= 5000) { var clientByUserId = Azure.GetGame().GetClientManager().GetClientByUserId((uint) _room.RoomData.OwnerId); clientByUserId?.SendNotif("Your room has more than 5000 items in it. The current limit of items per room is 5000.\nTo view the rest, pick some of these items up!"); } foreach (DataRow dataRow in table.Rows) { try { var id = Convert.ToUInt32(dataRow["id"]); var x = Convert.ToInt32(dataRow["x"]); var y = Convert.ToInt32(dataRow["y"]); var z = Convert.ToDouble(dataRow["z"]); var rot = Convert.ToSByte(dataRow["rot"]); var ownerId = Convert.ToUInt32(dataRow["user_id"]); var baseItemId = Convert.ToUInt32(dataRow["base_item"]); var item = Azure.GetGame().GetItemManager().GetItem(baseItemId); if (item == null) continue; if (ownerId == 0) queryReactor.RunFastQuery("UPDATE items_rooms SET user_id = " + _room.RoomData.OwnerId + " WHERE id = " + id); var locationData = item.Type == 'i' && string.IsNullOrWhiteSpace(dataRow["wall_pos"].ToString()) ? ":w=0,2 l=11,53 l" : dataRow["wall_pos"].ToString(); string extraData; if (DBNull.Value.Equals(dataRow["extra_data"])) extraData = string.Empty; else extraData = (string)dataRow["extra_data"]; string songCode; if (DBNull.Value.Equals(dataRow["songcode"])) songCode = string.Empty; else songCode = (string)dataRow["songcode"]; var groupId = Convert.ToUInt32(dataRow["group_id"]); if (item.Type == 'i') { var wallCoord = new WallCoordinate(':' + locationData.Split(':')[1]); var value = new RoomItem(id, _room.RoomId, baseItemId, extraData, wallCoord, _room, ownerId, groupId, item.FlatId, Azure.EnumToBool((string)dataRow["builders"])); WallItems.TryAdd(id, value); } else { var roomItem = new RoomItem(id, _room.RoomId, baseItemId, extraData, x, y, z, rot, _room, ownerId, groupId, item.FlatId, songCode, Azure.EnumToBool((string)dataRow["builders"])); if (!_room.GetGameMap().ValidTile(x, y)) { var clientByUserId2 = Azure.GetGame().GetClientManager().GetClientByUserId(ownerId); if (clientByUserId2 != null) { clientByUserId2.GetHabbo() .GetInventoryComponent() .AddNewItem(roomItem.Id, roomItem.BaseItem, roomItem.ExtraData, groupId, true, true, 0, 0); clientByUserId2.GetHabbo().GetInventoryComponent().UpdateItems(true); } queryReactor.RunFastQuery("UPDATE items_rooms SET room_id = 0 WHERE id = " + roomItem.Id); } else { if (item.InteractionType == Interaction.Hopper) HopperCount++; FloorItems.TryAdd(id, roomItem); } } } catch (Exception e) { Console.WriteLine(e); } } foreach (var current in FloorItems.Values) { if (current.IsWired) _room.GetWiredHandler().LoadWired(_room.GetWiredHandler().GenerateNewItem(current)); if (current.IsRoller) GotRollers = true; else if (current.GetBaseItem().InteractionType == Interaction.Dimmer) { if (_room.MoodlightData == null) _room.MoodlightData = new MoodlightData(current.Id); } else if (current.GetBaseItem().InteractionType == Interaction.RoomBg && _room.TonerData == null) _room.TonerData = new TonerData(current.Id); } } }
internal void PlacePostIt() { var room = AzureEmulator.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId); if (room == null || !room.CheckRights(Session)) return; var id = Request.GetUInteger(); var locationData = Request.GetString(); var item = Session.GetHabbo().GetInventoryComponent().GetItem(id); if (item == null) return; try { var wallCoord = new WallCoordinate(":" + locationData.Split(':')[1]); var item2 = new RoomItem(item.Id, room.RoomId, item.BaseItemId, item.ExtraData, wallCoord, room, Session.GetHabbo().Id, item.GroupId, item.BaseItem.FlatId, false); if (room.GetRoomItemHandler().SetWallItem(Session, item2)) Session.GetHabbo().GetInventoryComponent().RemoveItem(id, true); } catch { } }
internal void MoveWallItem() { var room = AzureEmulator.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId); if (room == null || !room.CheckRights(Session)) return; var id = Request.GetUInteger(); var locationData = Request.GetString(); var item = room.GetRoomItemHandler().GetItem(id); if (item == null) return; try { var wallCoord = new WallCoordinate(":" + locationData.Split(':')[1]); item.WallCoord = wallCoord; } catch { return; } room.GetRoomItemHandler().AddOrUpdateItem(id); var message = new ServerMessage(LibraryParser.OutgoingRequest("UpdateRoomWallItemMessageComposer")); item.Serialize(message); room.SendMessage(message); }
internal void PlaceItem() { if (Session == null || Session.GetHabbo() == null) return; try { var room = AzureEmulator.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId); if (room == null || AzureEmulator.GetDbConfig().DbData["placing_enabled"] != "1") return; if (!room.CheckRights(Session, false, true)) { Session.SendMessage(StaticMessage.ErrorCantSetNotOwner); return; } var placementData = Request.GetString(); var dataBits = placementData.Split(' '); var itemId = uint.Parse(dataBits[0].Replace("-", string.Empty)); var item = Session.GetHabbo().GetInventoryComponent().GetItem(itemId); if (item == null) return; var type = dataBits[1].StartsWith(":") ? "wall" : "floor"; int x, y, rot; double z; switch (type) { case "wall": { switch (item.BaseItem.InteractionType) { case Interaction.Dimmer: { if (room.MoodlightData != null && room.GetRoomItemHandler().GetItem(room.MoodlightData.ItemId) != null) Session.SendNotif(TextManager.GetText("room_moodlight_one_allowed")); goto PlaceWall; } default: { goto PlaceWall; } } } case "floor": { x = int.Parse(dataBits[1]); y = int.Parse(dataBits[2]); rot = int.Parse(dataBits[3]); z = room.GetGameMap().SqAbsoluteHeight(x, y); if (z >= 100) goto CannotSetItem; switch (item.BaseItem.InteractionType) { case Interaction.BreedingTerrier: case Interaction.BreedingBear: { var roomItemBreed = new RoomItem(item.Id, room.RoomId, item.BaseItemId, item.ExtraData, x, y, z, rot, room, Session.GetHabbo().Id, 0, 0, string.Empty, false); if (item.BaseItem.InteractionType == Interaction.BreedingTerrier) if (!room.GetRoomItemHandler().BreedingTerrier.ContainsKey(roomItemBreed.Id)) room.GetRoomItemHandler().BreedingTerrier.Add(roomItemBreed.Id, roomItemBreed); else if (!room.GetRoomItemHandler().BreedingBear.ContainsKey(roomItemBreed.Id)) room.GetRoomItemHandler().BreedingBear.Add(roomItemBreed.Id, roomItemBreed); goto PlaceFloor; } case Interaction.Alert: case Interaction.VendingMachine: case Interaction.ScoreBoard: case Interaction.Bed: case Interaction.PressurePadBed: case Interaction.Trophy: case Interaction.RoomEffect: case Interaction.PostIt: case Interaction.Gate: case Interaction.None: case Interaction.HCGate: case Interaction.Teleport: case Interaction.QuickTeleport: case Interaction.Guillotine: { goto PlaceFloor; } case Interaction.Hopper: { if (room.GetRoomItemHandler().HopperCount > 0) return; goto PlaceFloor; } case Interaction.FreezeTile: { if (!room.GetGameMap().SquareHasFurni(x, y, Interaction.FreezeTile)) goto PlaceFloor; goto CannotSetItem; } case Interaction.FreezeTileBlock: { if (!room.GetGameMap().SquareHasFurni(x, y, Interaction.FreezeTileBlock)) goto PlaceFloor; goto CannotSetItem; } case Interaction.Toner: { var tonerData = room.TonerData; if (tonerData != null && room.GetRoomItemHandler().GetItem(tonerData.ItemId) != null) { Session.SendNotif(TextManager.GetText("room_toner_one_allowed")); return; } goto PlaceFloor; } default: { goto PlaceFloor; } } } } PlaceWall: var coordinate = new WallCoordinate(":" + placementData.Split(':')[1]); var roomItemWall = new RoomItem(item.Id, room.RoomId, item.BaseItemId, item.ExtraData, coordinate, room, Session.GetHabbo().Id, item.GroupId, 0, false); if (room.GetRoomItemHandler().SetWallItem(Session, roomItemWall)) Session.GetHabbo().GetInventoryComponent().RemoveItem(itemId, true); return; PlaceFloor: if (room.CheckRights(Session)) AzureEmulator.GetGame().GetQuestManager().ProgressUserQuest(Session, QuestType.FurniPlace, 0u); var roomItem = new RoomItem(item.Id, room.RoomId, item.BaseItemId, item.ExtraData, x, y, z, rot, room, Session.GetHabbo().Id, item.GroupId, item.BaseItem.FlatId, item.SongCode, false); if (room.GetRoomItemHandler().SetFloorItem(Session, roomItem, x, y, rot, true, false, true)) { Session.GetHabbo().GetInventoryComponent().RemoveItem(itemId, true); if (roomItem.IsWired) { var item5 = room.GetWiredHandler().GenerateNewItem(roomItem); room.GetWiredHandler().AddWired(item5); WiredHandler.SaveWired(item5); } } AzureEmulator.GetGame().GetQuestManager().ProgressUserQuest(Session, QuestType.FurniPlace, 0u); AzureEmulator.GetGame().GetAchievementManager().ProgressUserAchievement(Session, "ACH_RoomDecoFurniCount", 1, false); return; CannotSetItem: Session.SendMessage(StaticMessage.ErrorCantSetItem); } catch (Exception e) { Session.SendMessage(StaticMessage.ErrorCantSetItem); Writer.Writer.LogException(e.ToString()); } }