@Override
	public ServerModel buyDevCard(BuyDevCardRequest request, CookieParams cookie) throws InvalidMovesRequest {
		if(request == null) {
			throw new InvalidMovesRequest("Error: invalid buy dev card request");
		} 
		ServerModel serverGameModel = serverModels.get(cookie.getGameID());
		int owner=request.getPlayerIndex();
		Player player = serverGameModel.getPlayers().get(owner);

		DevCards card=serverGameModel.getDeck();
		Bank bank = serverGameModel.getBank();
		Random rand=new Random();
		
		if(player.getSheep() > 0 && player.getWheat() > 0 && player.getOre() > 0 && 
				card.getTotalDevCardCount() > 0){
			int c=rand.nextInt(card.getTotalDevCardCount());
			if(c<card.getSoldier()){
				player.getNewDevCards().setSoldier(player.getNewDevCards().getSoldier()+1);
				card.setSoldier(card.getSoldier()-1);
			}else if(c<card.getSoldier()+card.getMonument()){
				player.getOldDevCards().setMonument(player.getOldDevCards().getMonument()+1);
				card.setMonument(card.getMonument()-1);
			}else if(c<card.getSoldier()+card.getMonument()+card.getMonopoly()){
				player.getNewDevCards().setMonopoly(player.getNewDevCards().getMonopoly()+1);
				card.setMonopoly(card.getMonopoly()-1);
			}else if(c<card.getSoldier()+card.getMonument()+card.getMonopoly()+card.getRoadBuilding()){
				player.getNewDevCards().setRoadBuilding(player.getNewDevCards().getRoadBuilding()+1);
				card.setRoadBuilding(card.getRoadBuilding()-1);
			}else{
				player.getNewDevCards().setYearOfPlenty(player.getNewDevCards().getYearOfPlenty()+1);
				card.setYearOfPlenty(card.getYearOfPlenty()-1);
			}
			
			player.setSheep(player.getSheep()-1);
			player.setWheat(player.getWheat()-1);
			player.setOre(player.getOre()-1);
			bank.setSheep(bank.getSheep()+1);
			bank.setWheat(bank.getWheat()+1);
			bank.setOre(bank.getOre()+1);
			
		}
		else{
			throw new InvalidMovesRequest("Error: invalid buy dev card request-not enought resources or not any monument cards in deck");
		}
		serverGameModel.incrementVersion();
		return serverGameModel;
	}