// File: src/FloridaManFlip.sol



// SPDX-License-Identifier: UNLICENSED

/*
IN DUANE WE TRUST

https://t.me/fmantoken
https://www.floridamantoken.com
https://x.com/floridamantoken

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWWNNNNNNNNNNNNNNNNWWWWWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWNNXKKKK0000OOOOOOOOOOOOOO0000KKKKXXXNNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXXK00OOOkxxdddoolllccccccccccccclllooddxkkO00KKXXNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXK00Okkxddolc::;;;:::ccccccccllccccclcc::::;;::cloddkOO00KXNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWXK0Okkxdolc:;;:cccllloodollllooloddoollodxoodxdolcccc::;:clodxkO0KXNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNK0Okxxdlc:;;clllodxkdooolodoccolcccllllllcclolldxdooooodxxdocc:;;:loxkO0KXNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNKOkxxdoc;;:ccloxxxoodxxxl::;coooodc,',::ccoxxxxdddxxoodxxdxkxdoddxdlc:;;:ldxOO0XNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNKOkxxol:;:clldxxoloodolool;'',:clollc;..''''',:oxkkkxdkkxddddddoclddxxodxllc:;;coxOO0XNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMWXOkxxdl:;:cclooodxkxooooll:,,,,,;ldxkxxd;........';cokOkoldkOkxolldoloddodxddoooolc;;cdkOOKXWMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMWKkxxdl:;;codddollodxxxolool;'.';lodxkkxxdddc'.......',:okOkdodxxkOkdoooolloxddoooodxxol:;:ldkO0XWMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMN0kxxoc;;:cloddxxxdoloooddodo;....;ldddddoollcc:.....'''',:okkdocloxxddddoodoolollooddddoollc;,:okOOKNMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMW0xddo:,;coddlllooddddooodxxxo;.....,cloddoolccc:;'.'''',;ccclxkoloccdxlccododxkkxddoododddxdoodl:,:oxkOKNMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMW0xddo:,;:codddoccllllldxkxxxxo,''....,;:loool::cll:'';,,',',lllodol::cool:;:looodkkkkxddlldxxdooxdol:,;lxkOKWMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMWXkddo:,;loollloddlldxdxxkkkkkxc,'''....',;lll::clllcc:';c:,';,;oollllc;:ol:;;;;:ccldxkkkkkxoooooodddoooo:,:oxkOXWMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMNOdddc,;clloddoclooloxkkkkkkkkd:''',:'.....':cc::cododxkc'.,l;.;;cdoc:clccllc;;:cccccloxkkkkkkkxxdddoodxxdoc;,:dkkONMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMKxddl;,:odlccccclccodkkkkkkkkkd;...';'.......';cl::looxkkl,'':l,':col;;::clollol:clc::cloxkkkkkkkkxoloxxddocclc;,cxkkKWMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMW0ddo:,,:loddocccllldxxkkkkkkkkx:....''..........,;:::ldxkkl,,;:c:',cooc;cc;;oxddxddddoloddooxkkkOOkkkxdlllllclloo:,;okxONMMMMMMMMMMMMMM
MMMMMMMMMMMMMNkodl;,;:cccloolccoddxxxxkkkkkkkd,.................';;;oxxkxc,;coc:,.;odl;:lc,,:lodxkkOkoccc:;:ldkOOOkkkkdollllloddoc,,lxxkXMMMMMMMMMMMMM
MMMMMMMMMMMMXxodc,;clccc::ccccoddxxxxxkkkkkkkd,......';,'........;,;dxxkx;,:ldl:;'':lc:::c::;,,;:c::;;::;,'',lxkkOkkkkkkdloxxddlllc;,:dxxKWMMMMMMMMMMM
MMMMMMMMMMMXdodc,;cooolccccclodddxxxxxxxkkkkkd;......,,,.........''cxxkkd;''cxxl;,'',;::;::::clcc:;;:c:;,...':lxkkkkkkkxxdollllooddl;,:dxxKWMMMMMMMMMM
MMMMMMMMMMXdoo:,;:clooooollloddddddxdddxxxxxxo,......','.........,lxkk0kl::;;cxko;,'''',:cllcclc:::::::;'....,lxkkkkkkxxxxxocoddddocc;';oxx0WMMMMMMMMM
MMMMMMMMMXdoo:,;::::clllooooooodddddddxxxxxxxc...........''''..':oxkO00kc:oxdlldkxl;,;,',cloooolccc;;:;;,'...,okkkkkkkxxxxxxdolllllooo:';oxdKMMMMMMMMM
MMMMMMMMXdlo:,;clcccc:ccloooooodddddddddxxxxx:...........,:::;;:codxkO0xlcodxxl:cooc;:clccc:::;,'''';:;;;;;,,:dkkkkkkxxxxxxxxdlcodxxdol;';dddKMMMMMMMM
MMMMMMMNxloc,;:;:::clc:clloooodddddddddddxxxxl...........;clcc:;;::;;:lc::cc:;,,'...';clool:,,'...',,'',;:cc;;oxkkkkxxxxxxxxddddodddoc::;':ddxXMMMMMMM
MMMMMMWOloc,,:clccccccclllooooooodddodddddxxxd;....''....'''.....';;,';oddl:;...    .;:clllllcc:,.,;,'',;::c:,cxxkkxxxxxdddddddocccccccll,'cdokNMMMMMM
MMMMMMKlll;,;::looolcclllllllooooooooddddddxxd;...''........     .,::,':ddc:'.       ....'',,,c:.';;:ll:,'''..;lddddddddddddddddoccoooool:',ldo0MMMMMM
MMMMMNxcl:,;:::::ccccllllllloodddodddddoddxddl'......'....        ....';kd;''...    ........ .....:c:colllc;,;::llllooddddddddddddollc:cc:;';dodXMMMMM
MMMMM0llc,;:ccccc::::ccloooooddxxxxxxxdooodddc.......'. ..     ........;kk:'''...   ..........','..,:lllccc:::;;:::cloddddddddddddc;;:::clc,'cdoOWMMMM
MMMMNdcl:,:cclllc:::::ccooddddxxddddddooodddd:.........................;kkl;,'...............'::,.....,;::cc::;,,;:cooooooddddddoooc::ccooo:';oodXMMMM
MMMM0lcc;;cccclllcccccloodoooooollllllooddddo;.........................;xkoll:,'............,ldc,.......'',;,,'.,:looooooooodooooddddddooooc,,ldlOMMMM
MMMWk:c:,:c:,:lc:ccccloooolccccclllllloooddo:........................ .;xkdooolcc:;'''',,:coxkd:'.......',;;;,'':ooollllooooooooodddoolcclc:,':olxNMMM
MMMNo:c;,:cc;,;;::::::cccccccllllllooooooodc........... ..'''''',,;,...:xOxodkOxllodddxkO00Okoc,''...:c,''..''..;lollloooooooooooooooc::::,;;',oooKMMM
MMMKc:c;;:clccccccccccc::cclooooollodddddddl...........  .':loooool'. .':cc:;;::;,,lkO00Okkdc;;::;..':cc:'......'clodddooooooolooooool;,;;:c:''lol0MMM
MMM0:::;;:::cloooooooolllllloooooooodddxxxdd:...........  ..;loodol,.......',,,:dxl;:dkkxxo:;coooc,'okxo;......,coooddooooooollloooooolllcllc,'cockWMM
MMMO;::;;,,,;clcllllollooooooooodoooddxxxxxxdl;.........    .':lol:;,,',;'...',;:coolcoxxxc;ldxxdl,.:oc,..''..;looooooooooooollloooooollclllc,':ocxWMM
MMMk;::;;,'';::;:::clllooooodddddddddddxxxxxxxdo:'.. ....    .,c:,.....;oo,'......',:ccodo:cxxxxdc','.....'',cooooooooooddolccloooooolcc:ccc:,.;ocdNMM
MMMk;;;;;;;,'',;:::clloooodddddddddddddxxxxxxxxxdl:,.....    .','......,;;;;;;,.......,:c::oxxxdo;,c;.....',:lolllllooooddol::looooooc::::;,,'.;lcdNMM
MMMk;;;;;;;;;;;:::cclloooodddddoddddddxxxxxxxxxxxdoooc;...    ......',:clllodxxxdolc:'..,,cdxxddl,:o,..',,;:cclllcllooooddlc;;coooollc;,,,,,;'.:lcdNMM
MMMO;,;;;;;:::::::;;;;:cllooooollloodddxddddxxxxxxddoo:....     .','',:clllllldxkkOOOxl:,;ldddol;;dd'..,::;;,,;;:llloooollc:;;clllllccc:::::;'':lcxWMM
MMMK:,;;;,,,;;;;;;;:::;::::::llllcclddollclloodddxddl:,....     .c:....'....',:oxkkOkkdc:ldddol:;dkl...',;''....,cllllllcllcc:cccccccccc::::;''clckWMM
MMMXl';;;,'''''''',,;;;:looollool::ccloooooooooooddddol;....     .,'..','....,oxkOOOOkxooddolc;:dOx:...'..'''...:ooollllllllllcccccccccc::::;',ccc0MMM
MMMWd,,;;,........'',,,,;clodxxxxddddxxxxxxxxxxxxdddoc;'.....     ..',;cllllldkO0000Okdlllc;,;lkOkdc...''......,lolc:::ccccc:::cc::::::::;;;,.;c:lXMMM
MMMMO;',;;'.........'',,'',,:clodxxdooxxxxxxxxxxddool;........     ..';coxxxdoxOOOOkxo:;,'.':dkOkxdc..........'clcc::::::;;;;;;::;;;;,;,,,;,'':c:xNMMM
MMMMXl',;;,............''''''',,;:cllc:codxdddoollllc;'.......       .';coxxo:coddolc,....;oxkkkxdd:'..''.....;cccccccccc::::::::;;;;,,,,,;,.,c:c0MMMM
MMMMWk,',;;...................'''''',;,'';::::ccllllc:'.......        ...',,,'..''......;ldxxkkxxdo:,,'.....';cc::::::::::;;;;;;;;,,,,,,,,,'';c;oNMMMM
MMMMMXl'';:,..........'''''''''''''''''',,,,,,,;;:::c:... ....  ..                ...,;ldxxxxkxxxdoc:;'....',;;:;;:cc::::::::;;;:::;;;;;;;,',:;:OWMMMM
MMMMMWO;',;:;;;;;;:::::::::::cccccccccccllllllllllollc'....,,..  ...    ...''',;:ccloodxxxxxxxxxdxo:lo;.   ...',,,cllccccccc:::::::::;;;,,'';:;dNMMMMM
MMMMMMNd'',:;,,,,,,,,;;;;;;;;;;;;;::::::::::::cc::::::,.'...,'.  ..'.  ..,:cllloodddddddddxxxxxxxxoclxdc..   . ..';;;;::::;;;,,,,,,,,,,'''',:;cKMMMMMM
MMMMMMMKc.',:,''''..''''''''',,,,,,,,;;;;;;;;;;;;;;;::;,''.....   .''.  ..,;:clooodddddddddxxxxxxxdcldxdc,..'....',;;::;;,,'',,;;;;,,'....,;,:OWMMMMMM
MMMMMMMW0:.',;'..'''''''',,,,,'''''''',,,,,,,;;;;:;;,,,,,,''...   .','. ..'',;clloooodoodddddddddddllolccol;:oc;'..'''''.................,;,;xNMMMMMMM
MMMMMMMMWk;.';;'.'''..'',,,,,,;;;;;;;;,,,,,;;;::;;;;,,,,,;;;;,'.   .,,....''',;:cllodooooodddoodddolcc:looc:lllclc;,'...'',,,,,,,,,''...';,,dNMMMMMMMM
MMMMMMMMMNk,.';:;'''..''''.......''',,,,,,;;;,,,,'..'',,;;;;,,'..  .';,....'',,;:loddoolloooolooolc:::lc:;:llc:cclllc:;,....'.........',,,,dXMMMMMMMMM
MMMMMMMMMMNk;.';:,..........'',;:cc::;;;;,,,,;;:::::;;;,,,,''....  ..;;,......',:clollllllccccccc;;;;::;;:llcc:cllcclllc:;,'....''....',,,dXMMMMMMMMMM
MMMMMMMMMMMNk;..,;,........''',,''..........',;:::;;,,,,;,''.. ..   .,:;,.....'',::ccccccc:;;::;,,,',,;;:cccc:cllllodddooolc:;;,,,''',,,,dXMMMMMMMMMMM
MMMMMMMMMMMMWO:..,;,...........................''''',;;;;'.... ..    .;:;,'''''',,;;;::::;,,,,,,,'',,,;:lc::::lollooddxxxxxololc,..',,';xNMMMMMMMMMMMM
MMMMMMMMMMMMMW0l'.';:,....................''',,,,,;::,,,..'... ...   .,cc;,''''''''';:::;,,,;,,,'',;,,:cc::::lllcccclooodooddo:;,,,,,':ONMMMMMMMMMMMMM
MMMMMMMMMMMMMMWXd,..,:;'..............'',,,;;;,,,;::,.''.';c;. .'..   .coc,''......';cc;,,,;,,,',,;;;;::::::clol::ccccccccc:,...',,',oKWMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMNOc..';:,............',,,;;;,,'.'''...'.'cxkdc'''.    .:do:,'......,cc;,;:;;,'';::;;::;;;::::lolc:::::::;;'..',,''':xXMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMWKd;..';;..  .......''',;;'............';dxxdc;::'.   'ldoc;.....':c::clc;,;::c:;;:::,,;;::;cl:::;;::::,..',,''',o0WMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMN0l'..,::,.......''..........'.........,:cc;,codo:'..:dol:'...':oddol:::ccc:;;::;:;,'',;;;:::::::,,;,..,,,'''ckNMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMWNkc'..,::,..........',,,''.............''.';;:looolclooc'..';:clc;;;ccc:;,,;;,;;;,,;,'';:c:;,;;'''.',,''':xXWMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMWXkc'..,;:,.......',''....................,'',,;cooolc,...'',,,',;;;;;,,,;;,,;;,''cl:'..';;,,,,,,,,''':xKWMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMWXkc,..';;,.....','..............'.... .''.'',:odo;...',,,,'''',,;;,',;;,,;;,,..;lcc;'...',;,,''',cxKWMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMWXOo;...',,,...'...............';;'. ..'..'';co:'.'',,'''...',,,,,;;;;,;:,,'...;:;;,..',,,'.';lOXWMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMNKxc,...,,,,,................':c:'..'..'',;:;,,,,''......','',,;:;',;,'''...',,;;,,,'.',cx0NWMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWX0d:'...,;;;,'.....'. .....'';;,',;,''''''''......'...''.';,,;,,,''',,'..,;;,,'.',:dOXWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWX0dc,....,;;;,,,,'.......''........................'...,'',''',',;::;,,'..',cdOXWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWN0xl;'....,,;::;,,,'...',...........'''.............''.',;;:;;,,'..',:lx0XWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWNX0xl:,'....',;;;;;;;:;;;,,''........'''''',,;;,,;;;;,,'....',:lx0XNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWXKOxl:;'......',,;;;;;;;;;;;;;;;;;;;;;;;;,,'.....',;:ldOKXNWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWNK0kxoc:;,'.........................'',;:codk0KNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWNXXK0OkxdollccccccccccclloodxkO0KXXNWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWWWWWNNNNNNNNNNNNWWWWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM                            
*/

pragma solidity ^0.8.19;

import "v2-periphery/interfaces/IUniswapV2Router02.sol";
import "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/contracts/utils/Counters.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";
import "openzeppelin-contracts/contracts/utils/math/SafeMath.sol";
import "chainlink-brownie-contracts/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "chainlink-brownie-contracts/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "./IFloridaManCard.sol";

contract FloridaManFlip is VRFConsumerBaseV2, Ownable {
    using Counters for Counters.Counter;
    using SafeMath for uint256;

    Counters.Counter public gameId;

    struct Game {
        uint256 id;
        uint256 cardId;
        uint256 bet;
        bool exists;
        bool finished;
        bool heads;
        bool fman;
        address payable player;
        address payable winner;
        uint256[] randomWords;
    }

    uint256 public minimumETHBetUSD = 20;
    uint256 public maximumETHBetUSD = 100;
    uint256 public minimumFMANBetUSD = 20;
    uint256 public maximumFMANBetUSD = 100;

    mapping(uint256 => Game) public gameMapping;
    mapping(uint256 => uint256) public requestIdToGameId;

    VRFCoordinatorV2Interface _vrfCoordinator;
    uint64 private _vrfSubscriptionId;
    bytes32 private _vrfKeyHash;
    uint32 private _vrfGasLimit = 200000;
    uint16 private _vrfRequestConfirmations = 3;

    uint16 private _maxWinPercentage = 35;
    uint16 private _maxWinDropPercentage = 45;

    address payable private _developerAddress;
    address private _cardAddress = 0x4fA9616AbBbFaf2EC503ade5FA3622b3604e5232;
    address private _tokenAddress = 0xD56990D60A7Abf3a7945F0565A98A708234b802C;
    address private _wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    address private _usdcAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
    address private _routerAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;

    event GameStarted(address indexed creator, uint256 indexed gameId, uint256 requestId);
    event GameFinished(uint256 indexed gameId, address indexed winner, uint256 result);
    event RandomnessFulfilled(uint256 requestId, uint256[] randomWords);
    event MinimumBetChanged(uint256 newBet, address changedBy);
    event MaximumBetChanged(uint256 newBet, address changedBy);

    constructor(address __developerAddress, address _coordinator, bytes32 _keyHash, uint64 _subscriptionId)
        VRFConsumerBaseV2(_coordinator)
    {
        _developerAddress = payable(__developerAddress);
        _vrfCoordinator = VRFCoordinatorV2Interface(_coordinator);
        _vrfKeyHash = _keyHash;
        _vrfSubscriptionId = _subscriptionId;
    }

    // //////////////////////////////////////////
    // PUBLIC
    // //////////////////////////////////////////
    function getMinimumETHBet() public view returns (uint256) {
        return _getETHFromUSD(minimumETHBetUSD);
    }

    function getMinimumFMANBet() public view returns (uint256) {
        return _getFMANFromUSD(minimumETHBetUSD);
    }

    function getMaximumETHBet() public view returns (uint256) {
        return _getETHFromUSD(maximumETHBetUSD);
    }

    function getMaximumFMANBet() public view returns (uint256) {
        return _getFMANFromUSD(maximumFMANBetUSD);
    }

    function play(uint256 _cardId, bool _heads) external payable returns (uint256) {
        require(msg.value <= address(this).balance, "Bet must less than contract balance");

        uint256 minBet = getMinimumETHBet();
        require(msg.value >= minBet, "Bet must be more than minimum");
        uint256 maxBet = getMaximumETHBet();
        require(msg.value <= maxBet, "Bet must be less than maximum");

        require(IERC1155(_cardAddress).balanceOf(msg.sender, _cardId) > 0, "Must own at least 1 card");
        IFloridaManCard(_cardAddress).safeTransferFrom(msg.sender, address(this), _cardId, 1, "");

        return _play(_cardId, _heads, msg.value, false);
    }

    function playFMAN(uint256 _cardId, bool _heads, uint256 _bet) external payable returns (uint256) {
        require(_bet <= IERC20(_tokenAddress).balanceOf(address(this)), "Bet must less than contract FMAN balance");

        uint256 minBet = getMinimumFMANBet();
        require(_bet >= minBet, "Bet must be more than minimum");
        uint256 maxBet = getMaximumFMANBet();
        require(_bet <= maxBet, "Bet must be less than maximum");

        require(IERC20(_tokenAddress).balanceOf(_msgSender()) >= _bet, "Bet is greater than FMAN balance");
        require(IERC20(_tokenAddress).transferFrom(_msgSender(), address(this), _bet), "Failed to transfer FMAN");

        require(IERC1155(_cardAddress).balanceOf(msg.sender, _cardId) > 0, "Must own at least 1 card");
        IFloridaManCard(_cardAddress).safeTransferFrom(msg.sender, address(this), _cardId, 1, "");

        return _play(_cardId, _heads, _bet, true);
    }

    function getGame(uint256 _id) external view returns (Game memory) {
        return gameMapping[_id];
    }

    function isGamePending(uint256 _id) external view returns (bool) {
        return gameMapping[_id].exists && !gameMapping[_id].finished;
    }

    function isGameComplete(uint256 _id) external view returns (bool) {
        return gameMapping[_id].exists && gameMapping[_id].finished;
    }

    function onERC1155Received(address, address, uint256, uint256, bytes memory) public virtual returns (bytes4) {
        return this.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory)
        public
        virtual
        returns (bytes4)
    {
        return this.onERC1155BatchReceived.selector;
    }

    function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
        return this.onERC721Received.selector;
    }

    // //////////////////////////////////////////
    // VRF
    // //////////////////////////////////////////
    function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override {
        emit RandomnessFulfilled(_requestId, _randomWords);

        uint256 _gameId = requestIdToGameId[_requestId];

        require(gameMapping[_gameId].exists, "Game does not exist");
        require(!gameMapping[_gameId].finished, "Game is not in the right state");

        bool isCardDroppable = IFloridaManCard(_cardAddress).isMintDroppable(gameMapping[_gameId].cardId);

        uint256 seed = (_randomWords[0] % 100) + 1;
        uint256 maxWinPercentage = _maxWinPercentage;

        if (isCardDroppable) {
            maxWinPercentage = _maxWinDropPercentage;
        }

        if (seed <= maxWinPercentage) {
            gameMapping[_gameId].winner = gameMapping[_gameId].player;

            if (gameMapping[_gameId].fman) {
                require(
                    IERC20(_tokenAddress).transfer(gameMapping[_gameId].player, gameMapping[_gameId].bet * 2),
                    "Failed to transfer winnings"
                );
            } else {
                payable(gameMapping[_gameId].player).transfer(gameMapping[_gameId].bet * 2);
            }
        } else {
            gameMapping[_gameId].winner = payable(address(this));
        }

        gameMapping[_gameId].randomWords = _randomWords;
        gameMapping[_gameId].finished = true;

        emit GameFinished(_gameId, gameMapping[_gameId].winner, seed);
    }

    // //////////////////////////////////////////
    // OWNER
    // //////////////////////////////////////////
    function changeKeyHash(bytes32 _newHash) external onlyOwner {
        _vrfKeyHash = _newHash;
    }

    function changeMinimumFMANBet(uint256 _usd) external onlyOwner {
        minimumFMANBetUSD = _usd;

        emit MinimumBetChanged(_usd, msg.sender);
    }

    function changeMinimumETHBet(uint256 _usd) external onlyOwner {
        minimumETHBetUSD = _usd;

        emit MinimumBetChanged(_usd, msg.sender);
    }

    function changeMaximumFMANBet(uint256 _usd) external onlyOwner {
        maximumFMANBetUSD = _usd;

        emit MaximumBetChanged(_usd, msg.sender);
    }

    function changeMaximumETHBet(uint256 _usd) external onlyOwner {
        maximumETHBetUSD = _usd;

        emit MaximumBetChanged(_usd, msg.sender);
    }

    function withdrawCards() external onlyOwner {
        uint256[] memory ids = IFloridaManCard(_cardAddress).getCardIds();
        uint256[] memory quantities = new uint256[](ids.length);

        for (uint256 i = 0; i < ids.length; i++) {
            quantities[i] = IFloridaManCard(_cardAddress).balanceOf(address(this), ids[i]);
        }

        IERC1155(_cardAddress).safeBatchTransferFrom(address(this), owner(), ids, quantities, "");
    }

    function withdrawETH() external onlyOwner {
        uint256 balance = address(this).balance;

        uint256 developerBalance = balance.mul(1000).div(10000);
        uint256 ownerBalance = balance.sub(developerBalance);

        payable(_developerAddress).transfer(developerBalance);
        payable(owner()).transfer(ownerBalance);
    }

    function withdrawFMAN() external onlyOwner {
        IERC20(_tokenAddress).transfer(msg.sender, IERC20(_tokenAddress).balanceOf(address(this)));
    }

    // //////////////////////////////////////////
    // PRIVATE
    // //////////////////////////////////////////
    function _play(uint256 _cardId, bool _heads, uint256 _bet, bool _fman) private returns (uint256) {
        uint256 _id = gameId.current();
        gameId.increment();
        Game memory _game = Game({
            id: _id,
            cardId: _cardId,
            player: payable(msg.sender),
            bet: _bet,
            heads: _heads,
            fman: _fman,
            finished: false,
            winner: payable(address(0)),
            randomWords: new uint256[](0),
            exists: true
        });
        gameMapping[_id] = _game;

        uint256 requestId = _vrfCoordinator.requestRandomWords(
            _vrfKeyHash, _vrfSubscriptionId, _vrfRequestConfirmations, _vrfGasLimit, 1
        );
        requestIdToGameId[requestId] = _id;

        emit GameStarted(msg.sender, _id, requestId);

        return _id;
    }

    function _getETHFromUSD(uint256 _usd) internal view returns (uint256 amount) {
        address[] memory path = new address[](2);
        path[0] = _usdcAddress;
        path[1] = _wethAddress;

        uint256[] memory amounts = IUniswapV2Router02(_routerAddress).getAmountsOut(_usd * (10 ** 6), path);

        return amounts[1];
    }

    function _getFMANFromUSD(uint256 _usd) internal view returns (uint256 amount) {
        address[] memory path = new address[](3);
        path[0] = _usdcAddress;
        path[1] = _wethAddress;
        path[2] = _tokenAddress;

        uint256[] memory amounts = IUniswapV2Router02(_routerAddress).getAmountsOut(_usd * (10 ** 6), path);

        return amounts[2];
    }
}

// File: lib/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol



pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

// File: lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

// File: lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

// File: lib/openzeppelin-contracts/contracts/utils/Counters.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

// File: lib/openzeppelin-contracts/contracts/access/Ownable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: lib/openzeppelin-contracts/contracts/utils/math/SafeMath.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

// File: lib/chainlink-brownie-contracts/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol



// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface VRFCoordinatorV2Interface {
  /**
   * @notice Get configuration relevant for making requests
   * @return minimumRequestConfirmations global min for request confirmations
   * @return maxGasLimit global max for request gas limit
   * @return s_provingKeyHashes list of registered key hashes
   */
  function getRequestConfig()
    external
    view
    returns (
      uint16,
      uint32,
      bytes32[] memory
    );

  /**
   * @notice Request a set of random words.
   * @param keyHash - Corresponds to a particular oracle job which uses
   * that key for generating the VRF proof. Different keyHash's have different gas price
   * ceilings, so you can select a specific one to bound your maximum per request cost.
   * @param subId  - The ID of the VRF subscription. Must be funded
   * with the minimum subscription balance required for the selected keyHash.
   * @param minimumRequestConfirmations - How many blocks you'd like the
   * oracle to wait before responding to the request. See SECURITY CONSIDERATIONS
   * for why you may want to request more. The acceptable range is
   * [minimumRequestBlockConfirmations, 200].
   * @param callbackGasLimit - How much gas you'd like to receive in your
   * fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords
   * may be slightly less than this amount because of gas used calling the function
   * (argument decoding etc.), so you may need to request slightly more than you expect
   * to have inside fulfillRandomWords. The acceptable range is
   * [0, maxGasLimit]
   * @param numWords - The number of uint256 random values you'd like to receive
   * in your fulfillRandomWords callback. Note these numbers are expanded in a
   * secure way by the VRFCoordinator from a single random value supplied by the oracle.
   * @return requestId - A unique identifier of the request. Can be used to match
   * a request to a response in fulfillRandomWords.
   */
  function requestRandomWords(
    bytes32 keyHash,
    uint64 subId,
    uint16 minimumRequestConfirmations,
    uint32 callbackGasLimit,
    uint32 numWords
  ) external returns (uint256 requestId);

  /**
   * @notice Create a VRF subscription.
   * @return subId - A unique subscription id.
   * @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.
   * @dev Note to fund the subscription, use transferAndCall. For example
   * @dev  LINKTOKEN.transferAndCall(
   * @dev    address(COORDINATOR),
   * @dev    amount,
   * @dev    abi.encode(subId));
   */
  function createSubscription() external returns (uint64 subId);

  /**
   * @notice Get a VRF subscription.
   * @param subId - ID of the subscription
   * @return balance - LINK balance of the subscription in juels.
   * @return reqCount - number of requests for this subscription, determines fee tier.
   * @return owner - owner of the subscription.
   * @return consumers - list of consumer address which are able to use this subscription.
   */
  function getSubscription(uint64 subId)
    external
    view
    returns (
      uint96 balance,
      uint64 reqCount,
      address owner,
      address[] memory consumers
    );

  /**
   * @notice Request subscription owner transfer.
   * @param subId - ID of the subscription
   * @param newOwner - proposed new owner of the subscription
   */
  function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;

  /**
   * @notice Request subscription owner transfer.
   * @param subId - ID of the subscription
   * @dev will revert if original owner of subId has
   * not requested that msg.sender become the new owner.
   */
  function acceptSubscriptionOwnerTransfer(uint64 subId) external;

  /**
   * @notice Add a consumer to a VRF subscription.
   * @param subId - ID of the subscription
   * @param consumer - New consumer which can use the subscription
   */
  function addConsumer(uint64 subId, address consumer) external;

  /**
   * @notice Remove a consumer from a VRF subscription.
   * @param subId - ID of the subscription
   * @param consumer - Consumer to remove from the subscription
   */
  function removeConsumer(uint64 subId, address consumer) external;

  /**
   * @notice Cancel a subscription
   * @param subId - ID of the subscription
   * @param to - Where to send the remaining LINK to
   */
  function cancelSubscription(uint64 subId, address to) external;

  /*
   * @notice Check to see if there exists a request commitment consumers
   * for all consumers and keyhashes for a given sub.
   * @param subId - ID of the subscription
   * @return true if there exists at least one unfulfilled request for the subscription, false
   * otherwise.
   */
  function pendingRequestExists(uint64 subId) external view returns (bool);
}

// File: lib/chainlink-brownie-contracts/contracts/src/v0.8/VRFConsumerBaseV2.sol



// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/** ****************************************************************************
 * @notice Interface for contracts using VRF randomness
 * *****************************************************************************
 * @dev PURPOSE
 *
 * @dev Reggie the Random Oracle (not his real job) wants to provide randomness
 * @dev to Vera the verifier in such a way that Vera can be sure he's not
 * @dev making his output up to suit himself. Reggie provides Vera a public key
 * @dev to which he knows the secret key. Each time Vera provides a seed to
 * @dev Reggie, he gives back a value which is computed completely
 * @dev deterministically from the seed and the secret key.
 *
 * @dev Reggie provides a proof by which Vera can verify that the output was
 * @dev correctly computed once Reggie tells it to her, but without that proof,
 * @dev the output is indistinguishable to her from a uniform random sample
 * @dev from the output space.
 *
 * @dev The purpose of this contract is to make it easy for unrelated contracts
 * @dev to talk to Vera the verifier about the work Reggie is doing, to provide
 * @dev simple access to a verifiable source of randomness. It ensures 2 things:
 * @dev 1. The fulfillment came from the VRFCoordinator
 * @dev 2. The consumer contract implements fulfillRandomWords.
 * *****************************************************************************
 * @dev USAGE
 *
 * @dev Calling contracts must inherit from VRFConsumerBase, and can
 * @dev initialize VRFConsumerBase's attributes in their constructor as
 * @dev shown:
 *
 * @dev   contract VRFConsumer {
 * @dev     constructor(<other arguments>, address _vrfCoordinator, address _link)
 * @dev       VRFConsumerBase(_vrfCoordinator) public {
 * @dev         <initialization with other arguments goes here>
 * @dev       }
 * @dev   }
 *
 * @dev The oracle will have given you an ID for the VRF keypair they have
 * @dev committed to (let's call it keyHash). Create subscription, fund it
 * @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface
 * @dev subscription management functions).
 * @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations,
 * @dev callbackGasLimit, numWords),
 * @dev see (VRFCoordinatorInterface for a description of the arguments).
 *
 * @dev Once the VRFCoordinator has received and validated the oracle's response
 * @dev to your request, it will call your contract's fulfillRandomWords method.
 *
 * @dev The randomness argument to fulfillRandomWords is a set of random words
 * @dev generated from your requestId and the blockHash of the request.
 *
 * @dev If your contract could have concurrent requests open, you can use the
 * @dev requestId returned from requestRandomWords to track which response is associated
 * @dev with which randomness request.
 * @dev See "SECURITY CONSIDERATIONS" for principles to keep in mind,
 * @dev if your contract could have multiple requests in flight simultaneously.
 *
 * @dev Colliding `requestId`s are cryptographically impossible as long as seeds
 * @dev differ.
 *
 * *****************************************************************************
 * @dev SECURITY CONSIDERATIONS
 *
 * @dev A method with the ability to call your fulfillRandomness method directly
 * @dev could spoof a VRF response with any random value, so it's critical that
 * @dev it cannot be directly called by anything other than this base contract
 * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).
 *
 * @dev For your users to trust that your contract's random behavior is free
 * @dev from malicious interference, it's best if you can write it so that all
 * @dev behaviors implied by a VRF response are executed *during* your
 * @dev fulfillRandomness method. If your contract must store the response (or
 * @dev anything derived from it) and use it later, you must ensure that any
 * @dev user-significant behavior which depends on that stored value cannot be
 * @dev manipulated by a subsequent VRF request.
 *
 * @dev Similarly, both miners and the VRF oracle itself have some influence
 * @dev over the order in which VRF responses appear on the blockchain, so if
 * @dev your contract could have multiple VRF requests in flight simultaneously,
 * @dev you must ensure that the order in which the VRF responses arrive cannot
 * @dev be used to manipulate your contract's user-significant behavior.
 *
 * @dev Since the block hash of the block which contains the requestRandomness
 * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful
 * @dev miner could, in principle, fork the blockchain to evict the block
 * @dev containing the request, forcing the request to be included in a
 * @dev different block with a different hash, and therefore a different input
 * @dev to the VRF. However, such an attack would incur a substantial economic
 * @dev cost. This cost scales with the number of blocks the VRF oracle waits
 * @dev until it calls responds to a request. It is for this reason that
 * @dev that you can signal to an oracle you'd like them to wait longer before
 * @dev responding to the request (however this is not enforced in the contract
 * @dev and so remains effective only in the case of unmodified oracle software).
 */
abstract contract VRFConsumerBaseV2 {
  error OnlyCoordinatorCanFulfill(address have, address want);
  address private immutable vrfCoordinator;

  /**
   * @param _vrfCoordinator address of VRFCoordinator contract
   */
  constructor(address _vrfCoordinator) {
    vrfCoordinator = _vrfCoordinator;
  }

  /**
   * @notice fulfillRandomness handles the VRF response. Your contract must
   * @notice implement it. See "SECURITY CONSIDERATIONS" above for important
   * @notice principles to keep in mind when implementing your fulfillRandomness
   * @notice method.
   *
   * @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this
   * @dev signature, and will call it once it has verified the proof
   * @dev associated with the randomness. (It is triggered via a call to
   * @dev rawFulfillRandomness, below.)
   *
   * @param requestId The Id initially returned by requestRandomness
   * @param randomWords the VRF output expanded to the requested number of words
   */
  function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual;

  // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF
  // proof. rawFulfillRandomness then calls fulfillRandomness, after validating
  // the origin of the call
  function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external {
    if (msg.sender != vrfCoordinator) {
      revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator);
    }
    fulfillRandomWords(requestId, randomWords);
  }
}

// File: src/IFloridaManCard.sol



// SPDX-License-Identifier: UNLICENSED

import "openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";

pragma solidity ^0.8.19;

interface IFloridaManCard is IERC1155 {
    function mintMysteryPack(address _to, uint256 _seasonId, uint256 _quantity)
        external
        returns (uint256[] memory minted);

    function withdrawFMAN() external;

    function transfer(address _to, uint256 _id, uint256 _quantity) external;
    function mintBatch(address _to, uint256[] memory _ids, uint256[] memory _amounts) external;

    function isCardValid(uint256 _id) external view returns (bool);
    function isSeasonValid(uint256 _id) external view returns (bool);

    function isMintDroppable(uint256 _id) external view returns (bool);

    function getSeasonCards(uint256 _id) external view returns (uint256[] memory seasonCardIds);
    function getSeasonIds() external view returns (uint256[] memory allSeasonIds);
    function getCardIds() external view returns (uint256[] memory allCardIds);

    function getCard(uint256 _id)
        external
        view
        returns (
            uint256 id,
            uint256 level,
            uint256 usdPrice,
            uint256 totalSupply,
            uint256 maxOwnable,
            uint256 availableAmount,
            uint256 ownedAmount
        );
}

// File: lib/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol



pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

// File: lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

// File: lib/openzeppelin-contracts/contracts/utils/Context.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}