contract LootPebble is ERC721, ReentrancyGuard, Ownable {
    using SafeMath for uint256;

    uint256 public publicPrice = 25000000000000000; //0.025 ETH
    uint256 public nextId = 1001;
    uint256 public freerollId = 9801;
    
    constructor() ERC721("LootPebble (for Adventurers)", "LootPebble (for Adventurers)") {
    }
    
    //Loot Contract
    address public lootAddress = 0xeC43a2546625c4C82D905503bc83e66262f0EF84;
    LootInterface lootContract = LootInterface(lootAddress);

    function withdraw() public onlyOwner {
        uint balance = address(this).balance;
        msg.sender.transfer(balance);
    }

    function setBaseURI(string memory baseURI) public onlyOwner {
        _setBaseURI(baseURI);
    }
    
    //LootRock
    function mintWithRock(uint rockId) public payable nonReentrant {
        require(lootContract.ownerOf(rockId) == msg.sender, "Not the owner of this loot");
        require(!_exists(rockId), "This token has already been minted");
        for (uint i=rockId; i<1001; i+=100) {
            _safeMint(msg.sender, i);
        }
    }
    
    function multiMint(uint count) public payable nonReentrant {
        require((publicPrice * count) <= msg.value, "Ether value sent is not correct");
        require(count < 21, "Only 20 NFT are allowed to be minted");
        require(nextId + count < 9801, "Supply exhausted");
        for (uint i=0; i<count; i++) {
            _safeMint(msg.sender, nextId);
            nextId++;
        }
    }
    
    function freeroll(address[] memory addresses) public payable nonReentrant onlyOwner {
        require(freerollId + addresses.length < 10001, "Supply exhausted");
        for (uint i=0; i<addresses.length; i++) {
            _safeMint(addresses[i], freerollId);
            freerollId++;
        }
    }
    
}
/**
 * @title LootPebble contract
 * @dev Extends ERC721 Non-Fungible Token Standard basic implementation
 */
function mintWithRock(uint rockId) public payable nonReentrant {
    require(lootContract.ownerOf(rockId) == msg.sender, "Not the owner of this loot");
    require(!_exists(rockId), "This token has already been minted");
    for (uint i=rockId; i<1001; i+=100) {
        _safeMint(msg.sender, i);
    }
}

//LootRock