contract FULLMETALINU is Context, IERC20, Ownable {
    using SafeMath for uint256;
    using Address for address;

    mapping (address => uint256) private _rOwned;
    mapping (address => uint256) private _tOwned;
    mapping (address => mapping (address => uint256)) private _allowances;
    mapping (address => uint256) private lastTrade;

    mapping (address => bool) private _isExcludedFromFee;
    mapping (address => bool) private _isExcluded;
    address[] private _excluded;

    mapping (address => bool) private _isBlacklisted;
    mapping (address => bool) private _liquidityHolders;
   
    uint256 private startingSupply = 1_000_000_000_000_000; //1 Quadrillion, underscores aid readability
   
    uint256 private constant MAX = ~uint256(0);
    uint8 private _decimals = 9;
    uint256 private _decimalsMul = _decimals;
    uint256 private _tTotal = startingSupply * 10**_decimalsMul;
    uint256 private _rTotal = (MAX - (MAX % _tTotal));
    uint256 private _tFeeTotal;

    string private _name = "FullMetal Inu";
    string private _symbol = "FMA";
    
    uint256 public _reflectFee = 0; // All taxes are divided by 100 for more accuracy.
    uint256 private _previousReflectFee = _reflectFee;
    uint256 private maxReflectFee = 800;
    
    uint256 public _liquidityFee = 300; // All taxes are divided by 100 for more accuracy.
    uint256 private _previousLiquidityFee = _liquidityFee;
    uint256 private maxLiquidityFee = 800;

    uint256 public _marketingFee = 500; // All taxes are divided by 100 for more accuracy.
    uint256 private _previousMarketingFee = _marketingFee;
    uint256 private maxMarketingFee = 800;

    uint256 private masterTaxDivisor = 10000; // All tax calculations are divided by this number.

    IUniswapV2Router02 public dexRouter;
    address public lpPair;

    // Uniswap Router
    address private _routerAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;

    address public burnAddress = 0x000000000000000000000000000000000000dEaD;
    address payable private _marketingWallet = payable(0x2c97E684751b7bfEf540DA13DEd685d59cF0262A);
    
    bool inSwapAndLiquify;
    bool public swapAndLiquifyEnabled = true;
    
    // Max TX amount is 0.5% of the total supply.
    uint256 private maxTxPercent = 5; // Less fields to edit
    uint256 private maxTxDivisor = 1000;
    uint256 private _maxTxAmount = (_tTotal * maxTxPercent) / maxTxDivisor;
    uint256 private _previousMaxTxAmount = _maxTxAmount;
    uint256 public maxTxAmountUI = (startingSupply * maxTxPercent) / maxTxDivisor; // Actual amount for UI's
    // Maximum wallet size is 2% of the total supply.
    uint256 private maxWalletPercent = 2; // Less fields to edit
    uint256 private maxWalletDivisor = 100;
    uint256 private _maxWalletSize = (_tTotal * maxWalletPercent) / maxWalletDivisor;
    uint256 private _previousMaxWalletSize = _maxWalletSize;
    uint256 public maxWalletSizeUI = (startingSupply * maxWalletPercent) / maxWalletDivisor; // Actual amount for UI's
    // 0.05% of Total Supply
    uint256 private numTokensSellToAddToLiquidity = (_tTotal * 5) / 10000;

    bool private sniperProtection = true;
    bool public _hasLiqBeenAdded = false;
    uint256 private _liqAddBlock = 0;
    uint256 private _liqAddStamp = 0;
    uint256 private immutable snipeBlockAmt;
    uint256 public snipersCaught = 0;
    bool private gasLimitActive = true;
    uint256 private gasPriceLimit;
    bool private sameBlockActive = true;
    
    event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
    event SwapAndLiquifyEnabledUpdated(bool enabled);
    event SwapAndLiquify(
        uint256 tokensSwapped,
        uint256 ethReceived,
        uint256 tokensIntoLiqudity
    );
    event SniperCaught(address sniperAddress);
    
    modifier lockTheSwap {
        inSwapAndLiquify = true;
        _;
        inSwapAndLiquify = false;
    }
    
    constructor (uint256 _snipeBlockAmt, uint256 _gasPriceLimit) payable {
        _tOwned[_msgSender()] = _tTotal;
        _rOwned[_msgSender()] = _rTotal;

        // Set the amount of blocks to count a sniper.
        snipeBlockAmt = _snipeBlockAmt;
        gasPriceLimit = _gasPriceLimit * 1 gwei;

        IUniswapV2Router02 _dexRouter = IUniswapV2Router02(_routerAddress);
        lpPair = IUniswapV2Factory(_dexRouter.factory())
            .createPair(address(this), _dexRouter.WETH());

        dexRouter = _dexRouter;
        
        _isExcludedFromFee[owner()] = true;
        _isExcludedFromFee[address(this)] = true;
        _liquidityHolders[owner()] = true;
        _isExcluded[address(this)] = true;
        _excluded.push(address(this));
        _isExcluded[owner()] = true;
        _excluded.push(owner());
        _isExcluded[burnAddress] = true;
        _excluded.push(burnAddress);
        _isExcluded[_marketingWallet] = true;
        _excluded.push(_marketingWallet);
        _isExcluded[lpPair] = true;
        _excluded.push(lpPair);
        // DxLocker Address (BSC)
        _isExcludedFromFee[0x8BF418C4C734F85A8D0b51c37B2d92373906fEb2] = true;
        _isExcluded[0x8BF418C4C734F85A8D0b51c37B2d92373906fEb2] = true;
        _excluded.push(0x8BF418C4C734F85A8D0b51c37B2d92373906fEb2);

        // Approve the owner for PancakeSwap, timesaver.
        _approve(_msgSender(), _routerAddress, _tTotal);

        // Ever-growing sniper/tool blacklist
	_isBlacklisted[0xE4882975f933A199C92b5A925C9A8fE65d599Aa8] = true;
        _isBlacklisted[0x86C70C4a3BC775FB4030448c9fdb73Dc09dd8444] = true;
        _isBlacklisted[0xa4A25AdcFCA938aa030191C297321323C57148Bd] = true;
        _isBlacklisted[0x20C00AFf15Bb04cC631DB07ee9ce361ae91D12f8] = true;
        _isBlacklisted[0x0538856b6d0383cde1709c6531B9a0437185462b] = true;
        _isBlacklisted[0xa76e2294d3FeEfaCd17e1ad4d0971a50685FF3A5] = true;
        _isBlacklisted[0xB995Ec6e8292C1b4ff1e2E0D354789a5A136DcfA] = true;
        _isBlacklisted[0x9b61312263D804F7bcCC66492BAc6eDE8bE2DFb6] = true;
        _isBlacklisted[0x0E388888309d64e97F97a4740EC9Ed3DADCA71be] = true;
        _isBlacklisted[0x93a2d57088BC7ad7C69feEE402E753606d045237] = true;
        _isBlacklisted[0x6932a1C9276b0dF81edadC818c9D5157f1Bbc6E0] = true;
        _isBlacklisted[0x3233b0919fe9BE5E289446c26C7322Cbc464838b] = true;
        _isBlacklisted[0xed0c2fFAfbF2e337680CcB6255C44b19C8F586e5] = true;
        _isBlacklisted[0x925ED3529f6fF3913278C5B3B1C103dD3c4Bdd16] = true;
        _isBlacklisted[0x9e1a9C8202777B251A17bf288A2a0903EF5d9885] = true;
        _isBlacklisted[0xA94E56EFc384088717bb6edCccEc289A72Ec2381] = true;
        _isBlacklisted[0x9560A38F4F7E52AF49B0BE4033450198Ca88d81b] = true;
        _isBlacklisted[0xA62c5bA4D3C95b3dDb247EAbAa2C8E56BAC9D6dA] = true;
        _isBlacklisted[0x6077831872bbB434960a28991B941cC2f26a84Aa] = true;
        _isBlacklisted[0x2336b2eCE8103c80fA823C9387de8Da8Cce7E2a4] = true;
        _isBlacklisted[0x2336b2eCE8103c80fA823C9387de8Da8Cce7E2a4] = true;
        _isBlacklisted[0xde594D578E98533D3663027E4AA3Ba976442dB40] = true;
        _isBlacklisted[0x3DfbbFDBD20754BB3489dC4FD955719be61FF755] = true;
        _isBlacklisted[0x549cdf92D66C648A563CAC307Ea03F12E3835d8C] = true;
        _isBlacklisted[0x6faA2Bb2f1125A1AD4a6551631C1f85DDD39b21a] = true;
        _isBlacklisted[0x4Db61B50607086483eA59810e05f3E2F2384a748] = true;
        _isBlacklisted[0xeA1079a114afCD0d7Ffe2171A070D93191913bc6] = true;
        _isBlacklisted[0x6077831872bbB434960a28991B941cC2f26a84Aa] = true;
        _isBlacklisted[0x2336b2eCE8103c80fA823C9387de8Da8Cce7E2a4] = true;
        _isBlacklisted[0xde594D578E98533D3663027E4AA3Ba976442dB40] = true;
        _isBlacklisted[0xeA1079a114afCD0d7Ffe2171A070D93191913bc6] = true;
        _isBlacklisted[0x93a2d57088BC7ad7C69feEE402E753606d045237] = true;
        _isBlacklisted[0x4Db61B50607086483eA59810e05f3E2F2384a748] = true;
        _isBlacklisted[0x6faA2Bb2f1125A1AD4a6551631C1f85DDD39b21a] = true;
        _isBlacklisted[0x3DfbbFDBD20754BB3489dC4FD955719be61FF755] = true;
        _isBlacklisted[0x2AC6C749B0d9a4908D935Bb26B0dDCbc7a9F76C6] = true;
        _isBlacklisted[0xde594D578E98533D3663027E4AA3Ba976442dB40] = true;
        _isBlacklisted[0x50A77964D208b5cA4B86B8EaB5E9b8C10bb70390] = true;
        _isBlacklisted[0xeA1079a114afCD0d7Ffe2171A070D93191913bc6] = true;
        _isBlacklisted[0x93a2d57088BC7ad7C69feEE402E753606d045237] = true;
        _isBlacklisted[0x4Db61B50607086483eA59810e05f3E2F2384a748] = true;
        _isBlacklisted[0x6faA2Bb2f1125A1AD4a6551631C1f85DDD39b21a] = true;
        _isBlacklisted[0x3DfbbFDBD20754BB3489dC4FD955719be61FF755] = true;
        _isBlacklisted[0x00000000003b3cc22aF3aE1EAc0440BcEe416B40] = true;
        _isBlacklisted[0x90484Bb9bc05fD3B5FF1fe412A492676cd81790C] = true;
        _isBlacklisted[0xA62c5bA4D3C95b3dDb247EAbAa2C8E56BAC9D6dA] = true;
        _isBlacklisted[0xA94E56EFc384088717bb6edCccEc289A72Ec2381] = true;
        _isBlacklisted[0x3066Cc1523dE539D36f94597e233719727599693] = true;
        _isBlacklisted[0xf13FFadd3682feD42183AF8F3f0b409A9A0fdE31] = true;
        _isBlacklisted[0x376a6EFE8E98f3ae2af230B3D45B8Cc5e962bC27] = true;
        _isBlacklisted[0x201044fa39866E6dD3552D922CDa815899F63f20] = true;
        _isBlacklisted[0x6F3aC41265916DD06165b750D88AB93baF1a11F8] = true;
        _isBlacklisted[0x27C71ef1B1bb5a9C9Ee0CfeCEf4072AbAc686ba6] = true;
        _isBlacklisted[0xDEF441C00B5Ca72De73b322aA4e5FE2b21D2D593] = true;
        _isBlacklisted[0x5668e6e8f3C31D140CC0bE918Ab8bB5C5B593418] = true;
        _isBlacklisted[0x4b9BDDFB48fB1529125C14f7730346fe0E8b5b40] = true;
        _isBlacklisted[0x7e2b3808cFD46fF740fBd35C584D67292A407b95] = true;
        _isBlacklisted[0xe89C7309595E3e720D8B316F065ecB2730e34757] = true;
        _isBlacklisted[0x725AD056625326B490B128E02759007BA5E4eBF1] = true;

        emit Transfer(address(0), _msgSender(), _tTotal);
    }

    function totalSupply() external view override returns (uint256) { return _tTotal; }
    function decimals() external view override returns (uint8) { return _decimals; }
    function symbol() external view override returns (string memory) { return _symbol; }
    function name() external view override returns (string memory) { return _name; }
    function getOwner() external view override returns (address) { return owner(); }
    function allowance(address holder, address spender) external view override returns (uint256) { return _allowances[holder][spender]; }

    function balanceOf(address account) public view override returns (uint256) {
        if (_isExcluded[account]) return _tOwned[account];
        return tokenFromReflection(_rOwned[account]);
    }

    function transfer(address recipient, uint256 amount) public override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    function approve(address spender, uint256 amount) public override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    function isExcludedFromReward(address account) public view returns (bool) {
        return _isExcluded[account];
    }

    function isExcludedFromFee(address account) public view returns(bool) {
        return _isExcludedFromFee[account];
    }

    function isBlacklisted(address account) public view returns (bool) {
        return _isBlacklisted[account];
    }

    function setBlacklistEnabled(address account, bool enabled) external onlyOwner() {
        _isBlacklisted[account] = enabled;
    }

    function setProtectionSettings(bool antiSnipe, bool antiGas, bool antiBlock) external onlyOwner() {
        sniperProtection = antiSnipe;
        gasLimitActive = antiGas;
        sameBlockActive = antiBlock;
    }
    
    function setTaxFeePercent(uint256 reflectFee) external onlyOwner() {
        _reflectFee = reflectFee;
    }
    
    function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() {
        _liquidityFee = liquidityFee;
    }

    function setMarketingFeePercent(uint256 marketingFee) external onlyOwner() {
        _marketingFee = marketingFee;
    }

    function setMaxTxPercent(uint256 percent, uint256 divisor) external onlyOwner() {
        _maxTxAmount = _tTotal.mul(percent).div(divisor);
        maxTxAmountUI = startingSupply.mul(percent).div(divisor);
    }

    function setMaxWalletSize(uint256 percent, uint256 divisor) external onlyOwner() {
        _maxWalletSize = _tTotal.mul(percent).div(divisor);
        maxWalletSizeUI = startingSupply.mul(percent).div(divisor);
    }

    function setMarketingWallet(address payable newWallet) external onlyOwner {
        _marketingWallet = payable(newWallet);
    }

    function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
        swapAndLiquifyEnabled = _enabled;
        emit SwapAndLiquifyEnabledUpdated(_enabled);
    }

    function excludeFromFee(address account) public onlyOwner {
        _isExcludedFromFee[account] = true;
    }
    
    function includeInFee(address account) external onlyOwner {
        _isExcludedFromFee[account] = false;
    }

    function totalFees() public view returns (uint256) {
        return _tFeeTotal;
    }

    function setGasPriceLimit(uint256 gas) external onlyOwner {
        require(gas >= 150);
        gasPriceLimit = gas * 1 gwei;
    }

    function _hasLimits(address from, address to) private view returns (bool) {
        return from != owner()
            && to != owner()
            && !_liquidityHolders[to]
            && !_liquidityHolders[from]
            && to != burnAddress
            && to != address(0)
            && from != address(this);
    }

    function deliver(uint256 tAmount) public {
        address sender = _msgSender();
        require(!_isExcluded[sender], "Excluded addresses cannot call this function");
        (uint256 rAmount,,,,,) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rTotal = _rTotal.sub(rAmount);
        _tFeeTotal = _tFeeTotal.add(tAmount);
    }

    function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
        require(tAmount <= _tTotal, "Amount must be less than supply");
        if (!deductTransferFee) {
            (uint256 rAmount,,,,,) = _getValues(tAmount);
            return rAmount;
        } else {
            (,uint256 rTransferAmount,,,,) = _getValues(tAmount);
            return rTransferAmount;
        }
    }

    function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
        require(rAmount <= _rTotal, "Amount must be less than total reflections");
        uint256 currentRate =  _getRate();
        return rAmount.div(currentRate);
    }

    function excludeFromReward(address account) public onlyOwner() {
        // require(account != 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 'We can not exclude Uniswap router.');
        require(!_isExcluded[account], "Account is already excluded");
        if(_rOwned[account] > 0) {
            _tOwned[account] = tokenFromReflection(_rOwned[account]);
        }
        _isExcluded[account] = true;
        _excluded.push(account);
    }

    function includeInReward(address account) external onlyOwner() {
        require(_isExcluded[account], "Account is already excluded");
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_excluded[i] == account) {
                _excluded[i] = _excluded[_excluded.length - 1];
                _tOwned[account] = 0;
                _isExcluded[account] = false;
                _excluded.pop();
                break;
            }
        }
    }
    
     //to recieve ETH from dexRouter when swaping
    receive() external payable {}

    function _approve(address owner, address spender, uint256 amount) private {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    function _transfer(
        address from
,        address to,
        uint256 amount
    ) private {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");
        require(amount > 0, "Transfer amount must be greater than zero");
        if (gasLimitActive) {
            require(tx.gasprice <= gasPriceLimit, "Gas price exceeds limit.");
        }
        if(_hasLimits(from, to)) {
            if (sameBlockActive) {
                if (from == lpPair){
                    require(lastTrade[to] != block.number);
                    lastTrade[to] = block.number;
                } else {
                    require(lastTrade[from] != block.number);
                    lastTrade[from] = block.number;
                }
            }
            require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
            if(to != _routerAddress && to != lpPair) {
                uint256 contractBalanceRecepient = balanceOf(to);
                require(contractBalanceRecepient + amount <= _maxWalletSize, "Transfer amount exceeds the maxWalletSize.");
            }
        }


        uint256 contractTokenBalance = balanceOf(address(this));
        
        if(contractTokenBalance >= _maxTxAmount)
        {
            contractTokenBalance = _maxTxAmount;
        }
        
        bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity;
        if (!inSwapAndLiquify
            && to == lpPair
            && swapAndLiquifyEnabled
        ) {
            if (overMinTokenBalance) {
                contractTokenBalance = numTokensSellToAddToLiquidity;
                swapAndLiquify(contractTokenBalance);
            }
        }
        
        bool takeFee = true;
        
        if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
            takeFee = false;
        }
        
        _tokenTransfer(from,to,amount,takeFee);
    }

    function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap {
        if (_marketingFee + _liquidityFee == 0)
            return;
        uint256 toMarketing = contractTokenBalance.mul(_marketingFee).div(_marketingFee.add(_liquidityFee));
        uint256 toLiquify = contractTokenBalance.sub(toMarketing);

        // split the contract balance into halves
        uint256 half = toLiquify.div(2);
        uint256 otherHalf = toLiquify.sub(half);

        // capture the contract's current ETH balance.
        // this is so that we can capture exactly the amount of ETH that the
        // swap creates, and not make the liquidity event include any ETH that
        // has been manually sent to the contract
        uint256 initialBalance = address(this).balance;

        // swap tokens for ETH
        uint256 toSwapForEth = half.add(toMarketing);
        swapTokensForEth(toSwapForEth);

        // how much ETH did we just swap into?
        uint256 fromSwap = address(this).balance.sub(initialBalance);
        uint256 liquidityBalance = fromSwap.mul(half).div(toSwapForEth);

        addLiquidity(otherHalf, liquidityBalance);

        emit SwapAndLiquify(half, liquidityBalance, otherHalf);

        _marketingWallet.transfer(fromSwap.sub(liquidityBalance));
    }

    function swapTokensForEth(uint256 tokenAmount) private {
        // generate the uniswap lpPair path of token -> weth
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = dexRouter.WETH();

        _approve(address(this), address(dexRouter), tokenAmount);

        // make the swap
        dexRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
            tokenAmount,
            0, // accept any amount of ETH
            path,
            address(this),
            block.timestamp
        );
    }

    function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
        // approve token transfer to cover all possible scenarios
        _approve(address(this), address(dexRouter), tokenAmount);

        // add the liquidity
        dexRouter.addLiquidityETH{value: ethAmount}(
            address(this),
            tokenAmount,
            0, // slippage is unavoidable
            0, // slippage is unavoidable
            burnAddress,
            block.timestamp
        );
    }

    function _checkLiquidityAdd(address from, address to) private {
        require(!_hasLiqBeenAdded, "Liquidity already added and marked.");
        if (!_hasLimits(from, to) && to == lpPair) {
            _liquidityHolders[from] = true;
            _hasLiqBeenAdded = true;
            _liqAddBlock = block.number;
            _liqAddStamp = block.timestamp;

            swapAndLiquifyEnabled = true;
            emit SwapAndLiquifyEnabledUpdated(true);
        }
    }

    //this method is responsible for taking all fee, if takeFee is true
    function _tokenTransfer(address from, address to, uint256 amount,bool takeFee) private {
        // Failsafe, disable the whole system if needed.
        if (sniperProtection){
            // If sender is a sniper address, reject the transfer.
            if (isBlacklisted(from) || isBlacklisted(to)) {
                revert("Sniper rejected.");
            }

            // Check if this is the liquidity adding tx to startup.
            if (!_hasLiqBeenAdded) {
                _checkLiquidityAdd(from, to);
                    if (!_hasLiqBeenAdded && _hasLimits(from, to)) {
                        revert("Only owner can transfer at this time.");
                    }
            } else {
                if (_liqAddBlock > 0 
                    && from == lpPair 
                    && _hasLimits(from, to)
                ) {
                    if (block.number - _liqAddBlock < snipeBlockAmt) {
                        _isBlacklisted[to] = true;
                        snipersCaught ++;
                        emit SniperCaught(to);
                    }
                }
            }
        }

        if(!takeFee)
            removeAllFee();
        
        _finalizeTransfer(from, to, amount);
        
        if(!takeFee)
            restoreAllFee();
    }

    function _finalizeTransfer(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);

        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);

        if (_isExcluded[sender] && !_isExcluded[recipient]) {
            _tOwned[sender] = _tOwned[sender].sub(tAmount);
        } else if (!_isExcluded[sender] && _isExcluded[recipient]) {
            _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);  
        } else if (_isExcluded[sender] && _isExcluded[recipient]) {
            _tOwned[sender] = _tOwned[sender].sub(tAmount);
            _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
        }

        if (tLiquidity > 0)
            _takeLiquidity(sender, tLiquidity);
        if (rFee > 0 || tFee > 0)
            _takeReflect(rFee, tFee);

        emit Transfer(sender, recipient, tTransferAmount);
    }

    function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
        (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount);
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate());
        return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity);
    }

    function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) {
        uint256 tFee = calculateTaxFee(tAmount);
        uint256 tLiquidity = calculateLiquidityFee(tAmount);
        uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
        return (tTransferAmount, tFee, tLiquidity);
    }

    function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
        uint256 rAmount = tAmount.mul(currentRate);
        uint256 rFee = tFee.mul(currentRate);
        uint256 rLiquidity = tLiquidity.mul(currentRate);
        uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
        return (rAmount, rTransferAmount, rFee);
    }


    function _getRate() private view returns(uint256) {
        (uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
        return rSupply.div(tSupply);
    }

    function _getCurrentSupply() private view returns(uint256, uint256) {
        uint256 rSupply = _rTotal;
        uint256 tSupply = _tTotal;      
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
            rSupply = rSupply.sub(_rOwned[_excluded[i]]);
            tSupply = tSupply.sub(_tOwned[_excluded[i]]);
        }
        if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
        return (rSupply, tSupply);
    }

    function _takeReflect(uint256 rFee, uint256 tFee) private {
        _rTotal = _rTotal.sub(rFee);
        _tFeeTotal = _tFeeTotal.add(tFee);
    }
    
    function _takeLiquidity(address sender, uint256 tLiquidity) private {
        uint256 currentRate =  _getRate();
        uint256 rLiquidity = tLiquidity.mul(currentRate);
        _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
        emit Transfer(sender, address(this), tLiquidity); // Transparency is the key to success.
    }

    function calculateTaxFee(uint256 _amount) private view returns (uint256) {
        return _amount.mul(_reflectFee).div(masterTaxDivisor);
    }

    function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
        return _amount.mul(_liquidityFee.add(_marketingFee)).div(masterTaxDivisor);
    }

    function removeAllFee() private {
        if(_reflectFee == 0 && _liquidityFee == 0) return;
        
        _previousReflectFee = _reflectFee;
        _previousLiquidityFee = _liquidityFee;
        _previousMarketingFee = _marketingFee;

        _reflectFee = 0;
        _liquidityFee = 0;
        _marketingFee = 0;
    }
    
    function restoreAllFee() private {
        _reflectFee = _previousReflectFee;
        _liquidityFee = _previousLiquidityFee;
        _marketingFee = _previousMarketingFee;
    }
}
receive() external payable {}
//to recieve ETH from dexRouter when swaping