/// <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 (IQueryAdapter queryReactor = Yupi.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"); DataTable table = queryReactor.GetTable(); if (table.Rows.Count >= 5000) { GameClient clientByUserId = Yupi.GetGame().GetClientManager().GetClientByUserId(_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 { uint id = Convert.ToUInt32(dataRow["id"]); int x = Convert.ToInt32(dataRow["x"]); int y = Convert.ToInt32(dataRow["y"]); double z = Convert.ToDouble(dataRow["z"]); sbyte rot = Convert.ToSByte(dataRow["rot"]); uint ownerId = Convert.ToUInt32(dataRow["user_id"]); string baseItemName = dataRow["item_name"].ToString(); Item item = Yupi.GetGame().GetItemManager().GetItemByName(baseItemName); if (item == null) continue; if (ownerId == 0) queryReactor.RunFastQuery("UPDATE items_rooms SET user_id = " + _room.RoomData.OwnerId + " WHERE id = " + id); string locationData = item.Type == 'i' && string.IsNullOrWhiteSpace(dataRow["wall_pos"].ToString()) ? ":w=0,2 l=11,53 l" : dataRow["wall_pos"].ToString(); string extraData = DBNull.Value.Equals(dataRow["extra_data"]) ? string.Empty : dataRow["extra_data"].ToString(); string songCode = DBNull.Value.Equals(dataRow["songcode"]) ? string.Empty : (string) dataRow["songcode"]; uint groupId = Convert.ToUInt32(dataRow["group_id"]); if (item.Type == 'i') { WallCoordinate wallCoord = new WallCoordinate(':' + locationData.Split(':')[1]); RoomItem value = new RoomItem(id, _room.RoomId, baseItemName, extraData, wallCoord, _room, ownerId, groupId, Yupi.EnumToBool((string) dataRow["builders"])); WallItems.TryAdd(id, value); } else { RoomItem roomItem = new RoomItem(id, _room.RoomId, baseItemName, extraData, x, y, z, rot, _room, ownerId, groupId, songCode, Yupi.EnumToBool((string) dataRow["builders"])); if (!_room.GetGameMap().ValidTile(x, y)) { GameClient clientByUserId2 = Yupi.GetGame().GetClientManager().GetClientByUserId(ownerId); if (clientByUserId2 != null) { clientByUserId2.GetHabbo() .GetInventoryComponent() .AddNewItem(roomItem.Id, roomItem.BaseName, 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 (RoomItem 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 PlaceItem() { if (Session?.GetHabbo() == null) return; try { Room room = Yupi.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId); if (room == null || Yupi.GetDbConfig().DbData["placing_enabled"] != "1") return; if (!room.CheckRights(Session, false, true)) { Session.SendMessage(StaticMessage.ErrorCantSetNotOwner); return; } string placementData = Request.GetString(); string[] dataBits = placementData.Split(' '); uint itemId = uint.Parse(dataBits[0].Replace("-", string.Empty)); UserItem item = Session.GetHabbo().GetInventoryComponent().GetItem(itemId); if (item == null) return; string 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(Yupi.GetLanguage().GetVar("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: { RoomItem roomItemBreed = new RoomItem(item.Id, room.RoomId, item.BaseItem.Name, item.ExtraData, x, y, z, rot, room, Session.GetHabbo().Id, 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: { TonerData tonerData = room.TonerData; if (tonerData != null && room.GetRoomItemHandler().GetItem(tonerData.ItemId) != null) { Session.SendNotif(Yupi.GetLanguage().GetVar("room_toner_one_allowed")); return; } goto PlaceFloor; } default: { goto PlaceFloor; } } } } PlaceWall: WallCoordinate coordinate = new WallCoordinate(":" + placementData.Split(':')[1]); RoomItem roomItemWall = new RoomItem(item.Id, room.RoomId, item.BaseItem.Name, item.ExtraData, coordinate, room, Session.GetHabbo().Id, item.GroupId, false); if (room.GetRoomItemHandler().SetWallItem(Session, roomItemWall)) Session.GetHabbo().GetInventoryComponent().RemoveItem(itemId, true); return; PlaceFloor: RoomItem roomItem = new RoomItem(item.Id, room.RoomId, item.BaseItem.Name, item.ExtraData, x, y, z, rot, room, Session.GetHabbo().Id, item.GroupId, item.SongCode, false); if (room.GetRoomItemHandler().SetFloorItem(Session, roomItem, x, y, rot, true, false, true)) { Session.GetHabbo().GetInventoryComponent().RemoveItem(itemId, true); if (roomItem.IsWired) { IWiredItem item5 = room.GetWiredHandler().GenerateNewItem(roomItem); room.GetWiredHandler().AddWired(item5); WiredHandler.SaveWired(item5); } } Yupi.GetGame() .GetAchievementManager() .ProgressUserAchievement(Session, "ACH_RoomDecoFurniCount", 1, true); return; CannotSetItem: Session.SendMessage(StaticMessage.ErrorCantSetItem); } catch (Exception e) { Session.SendMessage(StaticMessage.ErrorCantSetItem); ServerLogManager.LogException(e.ToString()); } }
internal void MoveWallItem() { Room room = Yupi.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId); if (room == null || !room.CheckRights(Session)) return; uint id = Request.GetUInteger(); string locationData = Request.GetString(); RoomItem item = room.GetRoomItemHandler().GetItem(id); if (item == null) return; try { WallCoordinate wallCoord = new WallCoordinate(":" + locationData.Split(':')[1]); item.WallCoord = wallCoord; } catch { return; } room.GetRoomItemHandler().AddOrUpdateItem(id); ServerMessage message = new ServerMessage(LibraryParser.OutgoingRequest("UpdateRoomWallItemMessageComposer")); item.Serialize(message); room.SendMessage(message); }
internal void PlacePostIt() { Room room = Yupi.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId); if (room == null || !room.CheckRights(Session)) return; uint id = Request.GetUInteger(); string locationData = Request.GetString(); UserItem item = Session.GetHabbo().GetInventoryComponent().GetItem(id); if (item == null) return; try { WallCoordinate wallCoord = new WallCoordinate(":" + locationData.Split(':')[1]); RoomItem item2 = new RoomItem(item.Id, room.RoomId, item.BaseItem.Name, item.ExtraData, wallCoord, room, Session.GetHabbo().Id, item.GroupId, false); if (room.GetRoomItemHandler().SetWallItem(Session, item2)) Session.GetHabbo().GetInventoryComponent().RemoveItem(id, true); } catch { // ignored } }