public void parse(GameClient Session, ClientPacket Packet) { Room Room = UberEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId); if (Room == null || !Room.CheckRights(Session)) { return; } string PlacementData = Packet.PopFixedString(); string[] DataBits = PlacementData.Split(' '); uint ItemId = uint.Parse(DataBits[0]); UserItem Item = Session.GetHabbo().GetInventoryComponent().GetItem(ItemId); if (Item == null) { return; } switch (Item.GetBaseItem().InteractionType.ToLower()) { case "dimmer": if (Room.ItemCountByType("dimmer") >= 1) { Session.SendNotif("You can only have one moodlight in a room."); return; } break; } // Wall Item if (DataBits[1].StartsWith(":")) { string WallPos = Room.WallPositionCheck(":" + PlacementData.Split(':')[1]); if (WallPos == null) { ServerPacket packet = new ServerPacket(516); packet.AppendInt32(11); Session.SendPacket(packet); return; } RoomItem RoomItem = new RoomItem(Item.Id, Room.RoomId, Item.BaseItem, Item.ExtraData, 0, 0, 0.0, 0, WallPos); if (Room.SetWallItem(Session, RoomItem)) { Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId); } } // Floor Item else { int X = int.Parse(DataBits[1]); int Y = int.Parse(DataBits[2]); int Rot = int.Parse(DataBits[3]); RoomItem RoomItem = new RoomItem(Item.Id, Room.RoomId, Item.BaseItem, Item.ExtraData, 0, 0, 0, 0, ""); if (Room.SetFloorItem(Session, RoomItem, X, Y, Rot, true)) { Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId); } } }
public void BallProcess(RoomItem ItemNow, RoomUser UserNow) { Thread.Sleep(500); int NewX = 0; int NewY = 0; int Rot = UserNow.RotBody; if (Rot == 3) { NewX = UserNow.X + 2; NewY = UserNow.Y + 2; } if (Rot == 4) { NewX = UserNow.X; NewY = UserNow.Y + 2; } if (Rot == 1) { NewX = UserNow.X + 2; NewY = UserNow.Y - 2; } if (Rot == 2) { NewX = UserNow.X + 2; NewY = UserNow.Y; } if (Rot == 0) { NewX = UserNow.X; NewY = UserNow.Y - 2; } if (Rot == 5) { NewX = UserNow.X - 2; NewY = UserNow.Y + 2; } if (Rot == 6) { NewX = UserNow.X - 2; NewY = UserNow.Y; } if (Rot == 7) { NewX = UserNow.X - 2; NewY = UserNow.Y - 2; } SetFloorItem(UserNow.GetClient(), ItemNow, NewX, NewY, ItemNow.Rot, false); }
public bool SetWallItem(GameClient Session, RoomItem Item) { Item.Interactor.OnPlace(Session, Item); switch (Item.GetBaseItem().InteractionType.ToLower()) { case "dimmer": if (MoodlightData == null) { MoodlightData = new MoodlightData(Item.Id); Item.ExtraData = MoodlightData.GenerateExtraData(); } break; } using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient()) { dbClient.AddParamWithValue("extra_data", Item.ExtraData); dbClient.ExecuteQuery("INSERT INTO room_items (id,room_id,base_item,extra_data,x,y,z,rot,wall_pos) VALUES ('" + Item.Id + "','" + RoomId + "','" + Item.BaseItem + "',@extra_data,'0','0','0','0','" + Item.WallPos + "')"); } Items.Add(Item); ServerPacket Message = new ServerPacket(83); Item.Serialize(Message); SendMessage(Message); return true; }
public bool SetFloorItem(GameClient Session, RoomItem Item, int newX, int newY, int newRot, bool newItem) { // Find affected tiles Dictionary<int, AffectedTile> AffectedTiles = GetAffectedTiles(Item.GetBaseItem().Length, Item.GetBaseItem().Width, newX, newY, newRot); // Verify tiles are valid if (!ValidTile(newX, newY)) { return false; } foreach (AffectedTile Tile in AffectedTiles.Values) { if (!ValidTile(Tile.X, Tile.Y)) { return false; } } // Start calculating new Z coordinate Double newZ = Model.SqFloorHeight[newX, newY]; // Is the item trying to stack on itself!? if (Item.Rot == newRot && Item.X == newX && Item.Y == newY && Item.Z != newZ) { return false; } // Make sure this tile is open and there are no users here if (Model.SqState[newX, newY] != SquareState.OPEN) { return false; } foreach (AffectedTile Tile in AffectedTiles.Values) { if (Model.SqState[Tile.X, Tile.Y] != SquareState.OPEN) { return false; } } // And that we have no users if (!Item.GetBaseItem().IsSeat) { if (SquareHasUsers(newX, newY)) { return false; } foreach (AffectedTile Tile in AffectedTiles.Values) { if (SquareHasUsers(Tile.X, Tile.Y)) { return false; } } } // Find affected objects List<RoomItem> ItemsOnTile = GetFurniObjects(newX, newY); List<RoomItem> ItemsAffected = new List<RoomItem>(); List<RoomItem> ItemsComplete = new List<RoomItem>(); foreach (AffectedTile Tile in AffectedTiles.Values) { List<RoomItem> Temp = GetFurniObjects(Tile.X, Tile.Y); if (Temp != null) { ItemsAffected.AddRange(Temp); } } if (ItemsOnTile == null) ItemsOnTile = new List<RoomItem>(); ItemsComplete.AddRange(ItemsOnTile); ItemsComplete.AddRange(ItemsAffected); // Check for items in the stack that do not allow stacking on top of them foreach (RoomItem I in ItemsComplete) { if (I.Id == Item.Id) { continue; } if (!I.GetBaseItem().Stackable) { return false; } } // If this is a rotating action, maintain item at current height if (Item.Rot != newRot && Item.X == newX && Item.Y == newY) { newZ = Item.Z; } // Are there any higher objects in the stack!? foreach (RoomItem I in ItemsComplete) { if (I.Id == Item.Id) { continue; // cannot stack on self } if (I.TotalHeight > newZ) { newZ = I.TotalHeight; } } // Verify the rotation is correct if (newRot != 0 && newRot != 2 && newRot != 4 && newRot != 6 && newRot != 8) { newRot = 0; } Item.X = newX; Item.Y = newY; Item.Z = newZ; Item.Rot = newRot; Item.Interactor.OnPlace(Session, Item); if (newItem) { using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient()) { dbClient.AddParamWithValue("extra_data", Item.ExtraData); dbClient.ExecuteQuery("INSERT INTO room_items (id,room_id,base_item,extra_data,x,y,z,rot,wall_pos) VALUES ('" + Item.Id + "','" + RoomId + "','" + Item.BaseItem + "',@extra_data,'" + Item.X + "','" + Item.Y + "','" + Item.Z + "','" + Item.Rot + "','')"); } Items.Add(Item); ServerPacket Message = new ServerPacket(93); Item.Serialize(Message); SendMessage(Message); } else { using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient()) { dbClient.ExecuteQuery("UPDATE room_items SET x = '" + Item.X + "', y = '" + Item.Y + "', z = '" + Item.Z + "', rot = '" + Item.Rot + "', wall_pos = '' WHERE id = '" + Item.Id + "' LIMIT 1"); } ServerPacket Message = new ServerPacket(95); Item.Serialize(Message); SendMessage(Message); } GenerateMaps(); UpdateUserStatusses(); return true; }
public void RollerProcess(RoomItem ItemNow, RoomUser UserNow) { Thread.Sleep(2000); int nextx = 0; int nexty = 0; int Rot = ItemNow.Rot; if (Rot == 4) { nextx = ItemNow.X; nexty = ItemNow.Y + 1; } if (Rot == 2) { nextx = ItemNow.X + 1; nexty = ItemNow.Y; } if (Rot == 0) { nextx = ItemNow.X; nexty = ItemNow.Y - 1; } if (Rot == 6) { nextx = ItemNow.X - 1; nexty = ItemNow.Y; } UserNow.MoveTo(nextx, nexty); /* ServerMessage Message = new ServerMessage(230); Message.AppendString("QAPAQAKHs_[@@BJH0.450.0"); SendMessage(Message); UserNow.UpdateNeeded = false; */ }
public void LoadFurniture() { this.Items.Clear(); DataTable Data = null; using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient()) { Data = dbClient.ReadDataTable("SELECT * FROM room_items WHERE room_id = '" + Id + "'"); } if (Data == null) { return; } foreach (DataRow Row in Data.Rows) { RoomItem Item = new RoomItem((uint)Row["id"], RoomId, (uint)Row["base_item"], (string)Row["extra_data"], (int)Row["x"], (int)Row["y"], (Double)Row["z"], (int)Row["rot"], (string)Row["wall_pos"]); switch (Item.GetBaseItem().InteractionType.ToLower()) { case "dimmer": if (MoodlightData == null) { MoodlightData = new MoodlightData(Item.Id); } break; } this.Items.Add(Item); } }