Commander Riker, Lt. Worf and Lt. Commander Data beam down to a strange building located on an alien planet. Upon entering the building they find themselves trapped in an old earth-style hotel/casino called the Royale.
While exploring the building they find the remains of Col. Steven Richey, a NASA astronaut who had lived to a very old age and a book titled Hotel Royale by Todd Matthews. Upon reading his diary it is revealed his starship was in confrontation with aliens and he was the only survivor. Taking pity on him they created The Royale for him thinking the novel was an instruction of humans preferred way of living. Little did they know Col. Richey's time in The Royale was a living hell. Data, Riker, and Worf eventually discover that they are inside a living version of the book the same as Col. Richey was.
However, their newfound knowledge doesn't get the away team any closer to finding a way out of the building, until a quick read-through of the novel reveals that it had been recreated in detail by the aliens, and its contents played out in its entirety. None of the characters (or the away team) can leave until they are scripted to do so. As such, Riker realizes they have to assume the role of the characters in the novel to escape and, using the building's craps table, raise enough money to become the nondescript "foreign investors" destined to buy out the Royale. They successfully leave after fulfilling their part of the story.