void displayRoom(vector<Room> &roomStorage, vector<Item> &itemStorage, vector<Critter> &critterStorage, Player &player, Room &room, int id)
{
	for (int i = 0; i < roomStorage.size(); i++)
	{
		if (roomStorage[i].getRoomId() == id)
		{
			room = roomStorage[i];
			roomStorage[i].setVisited(true);
		}
	}

	room.displayName();
	cout << endl;
	if (!room.getDark() || player.getHasLight())
	{
		room.displayDesc();
		cout << endl;
		room.displayRoomItems(itemStorage);
		room.displayCritter(critterStorage);
		cout << endl;
		room.displayDirections();
		cout << endl;
	}
	else
	{
		cout << "It's dark and you can't see anything!" << endl;
	}
	
}
int main()
{
	Room room;
	vector<Room> roomStorage;

	Item item;
	vector<Item> itemStorage;

	//sample room created by constructor - Room(string name, string roomDescription, int id, int north, int south, int east, int west, bool indoor, bool dark)
	Room room1 = Room("Kitchen", "There's lots of food!", 1, 2, -1, -1, -1, true, false);  //-1 indicates that the player can't go that direction
	Room room2 = Room("Living Room", "There's a big leather couch!", 2, 3, 1, -1, -1, true, false);
	Room room3 = Room("Hall", "Nothing to see here!", 3, 4, 2, -1, -1, true, false);
	Room room4 = Room("Library", "Books, books, and more books!", 4, 5, 3, -1, -1, true, false);
	Room room5 = Room("Billiard Room", "There's a big pool table, duh!", 5, -1, 4, -1, -1, true, false);

	room1.addItem(1);
	room1.addItem(2);
	room2.addItem(3);
	room2.addItem(4);
	room3.addItem(5);
	room3.addItem(1);
	room4.addItem(2);
	room4.addItem(3);
	room5.addItem(4);
	room5.addItem(5);

	roomStorage.push_back(room1);
	roomStorage.push_back(room2);
	roomStorage.push_back(room3);
	roomStorage.push_back(room4);
	roomStorage.push_back(room5);
	
	Item item1 = Item("flashlight", "It's a flashlight stupid", "Thing that shines light", 1, 0, 1, true, false, true);
	Item item2 = Item("book", "It's a book stupid", "Thing that you read", 2, 0, 1, true, false, true);
	Item item3 = Item("candle", "It's a candle stupid", "Thing that has a wick", 3, 0, 1, true, false, true);
	Item item4 = Item("bloody robe", "It's a bloody robe stupid", "Thing that is bloody", 4, 10, 1, true, true, true);
	Item item5 = Item("brick", "It's a brick stupid", "Thing that bricks", 5, 0, 1, true, false, true);

	itemStorage.push_back(item1);
	itemStorage.push_back(item2);
	itemStorage.push_back(item3);
	itemStorage.push_back(item4);
	itemStorage.push_back(item5);

	Player player = Player();

	room = roomStorage[0];
	room.displayName();
	room.displayDesc();
	room.displayRoomItems(itemStorage);
	
	bool gameOver = false;
	string input;
	int filter;

	while (!gameOver)
	{		
		input = getPlayerInput();			
		filter = parseCommand(input);
		gameOver = callFunction(roomStorage, itemStorage, room, player, filter, input);
						
	}
		
	return 0;
}
bool callFunction(vector<Room> roomStorage,vector<Item> itemStorage, Room &room, Player &player, int filter,string command)
{
	int id;
	vector<string> commands;
	vector<string> items;
	string com;
	string com1;
	string com2;
	stringstream ss(command);
	bool gameOver;
	bool itemPresent = false;
	
	
	while (ss >> com)
	{
		commands.push_back(com);
	}

	com1 = commands[0];
	//Basically, if input is not "QUIT", it should be a 2 word command
	if (filter != 9999)
	{
		com2 = commands[1];
	}
			
	switch (filter)
	{
	case -1: 
		gameOver = false;
		break;
	case 1:
		if (com2 == "NORTH")
		{
			id = room.getNorth();
			if (id == -1)
			{
				cout << "You can't " << com1 << " north. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else if (com2 == "SOUTH")
		{
			id = room.getSouth();
			if (id == -1)
			{
				cout << "You can't " << com1 << " south. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else if (com2 == "EAST")
		{
			id = room.getEast();
			if (id == -1)
			{
				cout << "You can't " << com1 << " east. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else if (com2 == "WEST")
		{
			id = room.getWest();
			if (id == -1)
			{
				cout << "You can't " << com1 << " west. Try another command" << endl;
				gameOver = false;
				break;
			}
			else
			{
				displayRoom(roomStorage, room, id);
				gameOver = false;
				break;
			}
		}
		else
		{
			cout << "I don't understand where you want to " << com1 << "." << endl;
			gameOver = false;
			break;
		}
	case 2:
		if (com2 == "INVENTORY")
		{
			player.displayInventory(itemStorage);
			gameOver = false;
			break;
		}
		else
		{
			vector<string> items;
			room.getItems(itemStorage, items);

			for (int i = 0; i < items.size(); i++)
			{
				if (com2 == toUpperStr(items[i]))
				{
					itemPresent = true;
				}
			}

			if (itemPresent)
			{
				id = getItemId(itemStorage, com2);
				player.addInventory(itemStorage, id);
				room.removeItem(id);
				gameOver = false;
				break;
			}
			else
			{
				cout << "I don't know what you what to " << com1 << endl;
				gameOver = false;
				break;
			}	
			
		}
	case 3:
		if (com2 == "ROOM")
		{
			room.displayDesc();
			room.displayRoomItems(itemStorage);
			gameOver = false;
			break;
		}
		else
		{
			cout << "I don't know what you want to " << com1 << " at. Please try again." << endl;
			gameOver = false;
			break;
		}
	case 4:
		
		player.getItems(itemStorage, items);

		for (int i = 0; i < items.size(); i++)
		{
			if (com2 == toUpperStr(items[i]))
			{
				itemPresent = true;
			}
		}

		if (itemPresent)
		{
			id = getItemId(itemStorage, com2);
			player.removeInventory(id);
			room.addItem(id);
			cout << "You dropped" << getItemName(itemStorage, id) << " from your inventory." << endl;
			gameOver = false;
			break;
		}
		else
		{
			cout << "I don't know what you what to " << com1 << endl;
			gameOver = false;
			break;
		}
	case 9999:
		gameOver = quit();
		break;
	default:
		gameOver = false;
		break;
	}
	return gameOver;
}
bool callFunction(vector<Room> &roomStorage,vector<Item> &itemStorage, vector<Critter> &critterStorage, Room &room, Player &player, int filter,string command)
{
	int id;
	vector<string> commands;
	vector<string> items;
	string com;
	string com1;
	string com2;
	stringstream ss(command);
	bool gameOver;
	bool itemPresent = false;
	bool accuseCondition = false;
	
	
	while (ss >> com)
	{
		commands.push_back(com);
	}

	com1 = commands[0];
	//Basically, if input is not "QUIT", it should be a 2 word command and safe to assign com2 to the second element of commands
	if (filter != 9999)
	{
		com2 = commands[1];
	}
			
	switch (filter)
	{
	case -1: //invalid command
		gameOver = false;
		break;
	case 1: //go or move
		if (com2 == "NORTH" || com2 == "SOUTH" || com2 == "EAST" || com2 == "WEST" || com2 == "UP" || com2 == "DOWN")
		{
			if (com2 == "NORTH")
			{
				id = room.getNorth();
			}
			else if (com2 == "SOUTH")
			{
				id = room.getSouth();
			}
			else if (com2 == "EAST")
			{
				id = room.getEast();
			}
			else if (com2 == "WEST")
			{
				id = room.getWest();
			}
			else if (com2 == "UP")
			{
				id = room.getUp();
			}
			else if (com2 == "DOWN")
			{
				id = room.getDown();
			}
			if (id == -1)
			{
				cout << "You can't " << com1 << " "<< com2 << ". Try another command" << endl;
				gameOver = false;
				break;
			}
			else if (checkLock(roomStorage, id))
			{
				cout << "I'm sorry. That room is locked." << endl;
				gameOver = false;
				break;
			}
			else
			{
				if (room.getDark() && !player.getHasLight())
				{
					cout << "You can't see to go anywhere!" << endl;
					gameOver = false;
					break;
				}
				else
				{
					if (id == 43)
					{
						setCritters(roomStorage);
					}
					displayRoom(roomStorage, itemStorage, critterStorage, player, room, id);
					gameOver = false;
					break;
				}
			}
		}
		
		else
		{
			cout << "I don't understand where you want to " << com1 << "." << endl;
			gameOver = false;
			break;
		}
	case 2: //get
		if (com2 == "INVENTORY")
		{
			player.displayInventory(itemStorage);
			gameOver = false;
			break;
		}
		else
		{
			id = getIdGet(itemStorage, room, com2);
			if (id == -1)
			{
				cout << "I don't know what you want to " << com1 << endl;
				gameOver = false;
				break;
			}
			else
			{
				if (canCarry(itemStorage, id))
				{
					player.addInventory(itemStorage, id);
					room.removeItem(roomStorage, id);
					gameOver = false;
					break;
				}
				else
				{
					cout << "And just how do you think you are going to carry that?" << endl;
					gameOver = false;
					break;
				}
			}

		}
	case 3: //look
		if (com2 == "ROOM")
		{
			id = room.getRoomId();
			displayRoom(roomStorage, itemStorage, critterStorage, player, room, id);
			gameOver = false;
			break;
		}
		else
		{
			id = getIdGet(itemStorage, room, com2);
			if (id == -1)
			{
				id = getIdDrop(itemStorage, player, com2);
				if (id == -1)
				{
					cout << "I don't know what you want to " << com1 <<  " (at)" << endl;
					gameOver = false;
					break;
				}
				else
				{
					cout << getItemDescription(itemStorage, id) << endl;
					gameOver = false;
					break;
				}
				
			}
			else
			{	
				if (getIdDrop(itemStorage, player, com2) != -1)
				{
					cout << "Please use a descriptive word with the noun, typed as one word. For example: ritualkey" << endl;
				}
				else
				{
					cout << getItemDescription(itemStorage, id) << endl;
					gameOver = false;
					break;
				}	
			}
		}
	case 4: //drop
		
		id = getIdDrop(itemStorage, player, com2);
		if (id == -1)
		{
			cout << "I don't know what you want to " << com1 << endl;
			gameOver = false;
			break;
		}
		else
		{	
				player.removeInventory(id);
				room.addItem(roomStorage, id);
				cout << "You dropped " << getItemName(itemStorage, id) << " from your inventory." << endl;
				gameOver = false;
				break;
		}
		
	case 5:  //equip
		
		id = getIdDrop(itemStorage, player, com2);

		if (id == -1)
		{
			cout << "I don't know what you want to " << com1 << endl;
			gameOver = false;
			break;
		}
		else
		{		
			if (id == 3 || id == 9 || id == 85)
			{
				player.setEquippedItem(id);
				cout << "You equipped " << getItemName(itemStorage, id) << endl;
				gameOver = false;
				break;
			}
			else
			{
				cout << "You can only equip weapons." << endl;
				gameOver = false;
				break;
			}
		}	
	case 6: //eat 
			
		id = getIdDrop(itemStorage, player, com2 );

		if (id == -1)
		{
			cout << "I don't understand what you want to " << com1 << "." << endl;
			gameOver = false;
			break;
		}
		else if (isEdible(itemStorage, id))
		{
			srand(time(NULL));
			int randomTaunt = rand() % 6 + 1;

			switch (randomTaunt)
			{
			case 1:
				cout << "That really hit the spot!" << endl;
				break;

			case 2:
				cout << "Could have used some ketchup!" << endl;
				break;

			case 3:
				cout << "That was delicious. Do you have any beer?" << endl;
				break;

			case 4:
				cout << "Wow, that was surprisingly good!" << endl;
				break;

			case 5:
				cout << "Just like Momma used to make!" << endl;
				break;

			case 6:
				cout << "Please sir, may I have another?" << endl;
				break;

			default:
				cout << "My writer got bored and forgot to include a taunt here... " << endl;
				break;
			}

			cout << endl;
			cout << "You gained 10 points of health" << endl;
			int health = player.getHealth();
			health = health + 10;
			if (health > 100)
			{
				health = 100;
			}
			player.setHealth(health);
			cout << "Your health is " << health << "/100" << endl;

			cout << "You gained 5 points of sanity" << endl;
			int sanity = player.getSanity();
			sanity = sanity + 5;
			if (sanity > 25)
			{
				sanity = 25;
			}
			player.setSanity(sanity);
			cout << "Your sanity is " << sanity << "/25" << endl;
											
			player.removeInventory(id);
			gameOver = false;
			break;
		}		
		else
		{
			srand(time(NULL));
			int randomTaunt = rand() % 6 + 1;

			switch (randomTaunt)
			{
				case 1:
					cout << "I wouldn't eat that if I were you!" << endl;
					break;

				case 2:
					cout << "I don't think that's on your diet!" << endl;
					break;

				case 3:
					cout << "You're kidding, right?" << endl; ;
					break;

				case 4:
					cout << "I don't think that would taste very good!" << endl;
					break;

				case 5:
					cout << "Ha ha. Very funny!" << endl;
					break;

				case 6:
					cout << "I would never thought of trying to eat that!" << endl;
					break;

				default:
					cout << "My writer got bored and forgot to include a taunt here... " << endl;
					gameOver = false;
					break;
			}
					
			gameOver = false;
			break;
		}
				
	case 7: //use
		
		id = getIdDrop(itemStorage, player, com2);

		if (id == -1)
		{
			cout << "I don't understand what you want to " << com1 << "." << endl;
			gameOver = false;
			break;
		}
		else
		{
			if (id == 5)
			{
				if (player.hasItem(5)) //flashlight
				{
					cout << "You can see a lot better now!" << endl;
					room.displayDesc();
					room.displayRoomItems(itemStorage);
					player.setHasLight(true);

					gameOver = false;
					break;
				}
			}
			else if (id == 209 || id == 210 || id == 214 || id == 217) //These are the 3 game keys + 210 is signet ring
			{
				int lockedRoom = checkLock(roomStorage, room);

				if (lockedRoom != -1)
				{
					bool match = keyMatch(lockedRoom, id);

					if (match)
					{
						unLock(roomStorage, lockedRoom);
						cout << "The door is unlocked!" << endl;
						gameOver = false;
						break;
					}
					else
					{
						cout << "That key(unlocking device) doesn't work. Please try another key(unlocking device)." << endl;
						gameOver = false;
						break;
					}
				}
				else
				{
					cout << "You don't need a key. All the doors are unlocked!" << endl;
					gameOver = false;
					break;
				}
			}
			else if (id == 213)
			{
				if (player.hasItem(205) || player.hasItem(211) || roomStorage[9].getVisited())
				{
					if (player.hasItem(205))
					{
						cout << "You use the note to decode the leather bound book from Mr. Brown's room. You learn..." << endl;
					}
					if (player.hasItem(211))
					{
						cout << "You use the note to decode the strange book from the hidden room. You learn..." << endl;
					}
					if (roomStorage[9].getVisited())
					{
						cout << "You use the note to decode the writing on the wall of that creepy bathroom. It loosely translates, THE ONE WHO SLEEPS COMETH" << endl;
					}
				}
				else
				{
					cout << "It looks like a cypher used for decoding. If only you had a book with strange writing in it!" << endl;
				}
				gameOver = false;
				break;
			}
			else if (id == 32)
			{
				cout << "You gained 25 health." << endl;
				int health = player.getHealth();
				health = health + 25;
				if (health > 100)
				{
					health = 100;
				}
				player.setHealth(health);
				cout << "Your health is " << health << "/100" << endl;
				player.removeInventory(id);

				gameOver = false;
				break;
			}
			else
			{
				cout << "You can't use " << com2 << endl;
				gameOver = false;
				break;
			}
		}
	case 8: //talk, question, interrogate, interogate, grill
		if (room.getCritter() == -1 || (room.getCritter() != 100 && room.getCritter() != 101 && room.getCritter() != 102))
		{
			cout << "I don't understand with whom you wish to " << com1 << endl;
			gameOver = false;
			break;
		}
		else
		{		
			for (int i = 0; i < critterStorage.size(); i++)
			{
				if (critterStorage[i].getId() == room.getCritter())
				{
					critterStorage[i].displayTalk();
				}
			}
			gameOver = false;
			break;
		}
	case 9:
		if (room.getCritter() == -1 || (room.getCritter() != 100 && room.getCritter() != 101 && room.getCritter() != 102))
		{
			cout << "I don't understand with whom you wish to " << com1 << endl;
			gameOver = false;
			break;
		}
		else
		{
			if (room.getCritter() == 100)
			{

			}
			else if (room.getCritter() == 101)
			{
				for (int i = 0; i < critterStorage.size(); i++)
				{
					if (critterStorage[i].getId() == 102)
					{
						if (critterStorage[i].getHealth() <= 0)
						{
							accuseCondition = true;
						}
					}
				}
				if (accuseCondition)
				{
					if (!player.hasItem(207) || !player.hasItem(216) || !player.hasItem(215))
					{
						accuseCondition = false;
					}
				}

			}
			else if (room.getCritter() == 102)
			{
				if (room.getRoomId() == 33)
				{
					accuseCondition = true;
				}
			}

			for (int i = 0; i < critterStorage.size(); i++)
			{
				if (critterStorage[i].getId() == room.getCritter())
				{
					if (!accuseCondition)
					{
						critterStorage[i].displayAccuse1();
					}
					else
					{
						critterStorage[i].displayAccuse2();
					}
				}
			}
			gameOver = false;
			break;
		}
	case 9999: //quit
		gameOver = quit();
		break;
	default:
		gameOver = false;
		break;
	}
	return gameOver;
}