contract EtheremonBurnReward is BasicAccessControl {
    
    struct MonsterObjAcc {
        uint64 monsterId;
        uint32 classId;
        address trainer;
        string name;
        uint32 exp;
        uint32 createIndex;
        uint32 lastClaimIndex;
        uint createTime;
    }
    
    // address
    mapping(uint => uint) public requests; // mapping burn_id => monster_id
    address public tradeContract;
    address public dataContract;
    address public monsterNFTContract;
    
    function setContract(address _monsterNFTContract, address _dataContract, address _tradeContract) onlyModerators public {
        monsterNFTContract = _monsterNFTContract;
        dataContract = _dataContract;
        tradeContract = _tradeContract;
    }
    
    // public api
    function burnForReward(uint64 _monsterId, uint _burnId) isActive external {
        if (_burnId == 0 || _monsterId == 0 || requests[_burnId] > 0) revert();
        
        EtheremonDataBase data = EtheremonDataBase(dataContract);
        MonsterObjAcc memory obj;
        (obj.monsterId, obj.classId, obj.trainer, obj.exp, obj.createIndex, obj.lastClaimIndex, obj.createTime) = data.getMonsterObj(_monsterId);
        if (obj.trainer == address(0) || obj.trainer != msg.sender) revert();
        
        EtheremonTradeInterface trade = EtheremonTradeInterface(tradeContract);
        if (trade.isOnTrading(_monsterId)) revert();
        
        EtheremonMonsterNFTInterface monsterNFT = EtheremonMonsterNFTInterface(monsterNFTContract);
        monsterNFT.burnMonster(_monsterId);
        
        requests[_burnId] = _monsterId;
    }
    
    function getBurnInfo(uint _burnId) constant external returns(uint) {
        return requests[_burnId];
    }
}
function burnForReward(uint64 _monsterId, uint _burnId) isActive external {
    if (_burnId == 0 || _monsterId == 0 || requests[_burnId] > 0) revert();
        
    EtheremonDataBase data = EtheremonDataBase(dataContract);
    MonsterObjAcc memory obj;
    (obj.monsterId, obj.classId, obj.trainer, obj.exp, obj.createIndex, obj.lastClaimIndex, obj.createTime) = data.getMonsterObj(_monsterId);
    if (obj.trainer == address(0) || obj.trainer != msg.sender) revert();
        
    EtheremonTradeInterface trade = EtheremonTradeInterface(tradeContract);
    if (trade.isOnTrading(_monsterId)) revert();
        
    EtheremonMonsterNFTInterface monsterNFT = EtheremonMonsterNFTInterface(monsterNFTContract);
    monsterNFT.burnMonster(_monsterId);
        
    requests[_burnId] = _monsterId;
}

// public api