void GuardRoom::Execute( ExamineCommand & cmd ) { Room & room = *this; if ( cmd.m_strTarget == "guard") { m_numSearches++; m_numTotalSearches++; // Three consequtive searches wake guard if ( m_numSearches >= 3 ) { // Report death message attached to room cout << GetProperty("deathmessage").As<string>() << "\n"; g_Game.SetProperty("running", false); } else if ( m_numTotalSearches == 4 && g_Game.GetPlayer().GetItems()["key"] == NULL ) { cout << GetProperty("key_found_message").As<string>() << ". "; GameObject *pKey = new GameObject(); pKey->SetId("ID_KEY"); pKey->SetName("key"); pKey->SetDescription("key you pick-pocketed from guard"); g_Game.GetPlayer().GetItems().push_back( pKey); } else { cout << GetProperty("guard_search_msg").As<string>() << ". "; } } else if ( cmd.m_strTarget == "room" ) { cout << room.GetDescription() << "\n"; list<string> items; for(auto item : room.GetItems()) { items.push_back(item->GetName()); } if ( items.empty()) { cout << "There seems to be nothing in the room. "; } else { cout << "You can see " << Game::MakeReadable(items) << " in here."; } cout << "\n"; } else { // examining room items. GameObject * item = GetItems()[cmd.m_strTarget]; if ( item ) cout << item->GetDescription() << ". "; else cout << "I do not know how to examine " << cmd.m_strTarget << ". "; cout << "\n"; } }
void Player::Execute( ExamineCommand & cmd ) { GameObject * item = GetItems()[cmd.m_strTarget]; if ( !item ) throw ExamineCommandFailOnPlayerException(""); cout << "After taking a closer look, you see " << item->GetDescription() << ". "; }