contract RetirePets is AccessControl, SafeMath {

  
   
    address public petCardDataContract = 0xB340686da996b8B3d486b4D27E38E38500A9E926;


   
    // events
   
    event EventNewPet(uint64 petID);

  



    // write functions
    function DataContacts( address _petCardDataContract) onlyCREATOR external {
        petCardDataContract = _petCardDataContract;
      
    }
    

       
    function checkPet (uint64  petID) private constant returns (uint8) {
              IPetCardData petCardData = IPetCardData(petCardDataContract);
              
        //check if a pet both exists and is owned by the message sender.
        // This function also returns the petcardSeriesID. 
     
        if ((petID <= 0) || (petID > petCardData.getTotalPets())) {return 0;}
        
        address petowner;
        uint8 petcardSeriesID;
     
      (,petcardSeriesID,,,,,,,,petowner) = petCardData.getPet(petID);
    
         if  (petowner != msg.sender)  {return 0;}
        
        return petcardSeriesID;
        
        
}
     function retireWildEasy(uint64 pet1, uint64 pet2, uint64 pet3, uint64 pet4, uint64 pet5, uint64 pet6) public {
            IPetCardData petCardData = IPetCardData(petCardDataContract);
         // Send this function the petIds of 6 of your Wild Easy (2 star pets) to receive 1 3 star pet. 
         
         //won't throw an error if you send a level3 pet, but will still recycle. This is to reduce gas costs for everyone. 
         if (checkPet(pet1) <5) {revert();}
         if (checkPet(pet2) <5) {revert();}
         if (checkPet(pet3) <5) {revert();}
         if (checkPet(pet4) <5) {revert();}
         if (checkPet(pet5) <5) {revert();}
         if (checkPet(pet6) <5) {revert();}
         
       petCardData.transferPet(msg.sender, address(0), pet1);
       petCardData.transferPet(msg.sender, address(0), pet2);
       petCardData.transferPet(msg.sender, address(0), pet3);
       petCardData.transferPet(msg.sender, address(0), pet4);
       petCardData.transferPet(msg.sender, address(0), pet5);
       petCardData.transferPet(msg.sender, address(0), pet6);
         uint8 _newLuck = getRandomNumber(39,30,msg.sender);
        getNewPetCard(getRandomNumber(12,9,msg.sender), _newLuck);
         
     }

    function retireWildHard(uint64 pet1, uint64 pet2, uint64 pet3, uint64 pet4, uint64 pet5, uint64 pet6) public {
            IPetCardData petCardData = IPetCardData(petCardDataContract);
         // Send this function the petIds of 6 of your Wild Hard (3 star pets) to receive 1 four star pet. 
         
        
         if (checkPet(pet1) <9) {revert();}
         if (checkPet(pet2) <9) {revert();}
         if (checkPet(pet3) <9) {revert();}
         if (checkPet(pet4) <9) {revert();}
         if (checkPet(pet5) <9) {revert();}
         if (checkPet(pet6) <9) {revert();}
         
       petCardData.transferPet(msg.sender, address(0), pet1);
       petCardData.transferPet(msg.sender, address(0), pet2);
       petCardData.transferPet(msg.sender, address(0), pet3);
       petCardData.transferPet(msg.sender, address(0), pet4);
       petCardData.transferPet(msg.sender, address(0), pet5);
       petCardData.transferPet(msg.sender, address(0), pet6);
       uint8 _newLuck = getRandomNumber(49,40,msg.sender);
        getNewPetCard(getRandomNumber(16,13,msg.sender), _newLuck);
         
     }


    
   function getNewPetCard(uint8 opponentId, uint8 _luck) private {
        uint16 _auraRed = 0;
        uint16 _auraYellow = 0;
        uint16 _auraBlue = 0;
        
        uint32 _auraColor = getRandomNumber(2,0,msg.sender);
        if (_auraColor == 0) { _auraRed = 14;}
        if (_auraColor == 1) { _auraYellow = 14;}
        if (_auraColor == 2) { _auraBlue = 14;}
        
      
        IPetCardData petCardData = IPetCardData(petCardDataContract);
        uint64 petId = petCardData.setPet(opponentId, msg.sender, 'Rover', _luck, _auraRed, _auraYellow, _auraBlue);
        EventNewPet(petId);
        }


 
      function kill() onlyCREATOR external {
        selfdestruct(creatorAddress);
    }
}
function DataContacts( address _petCardDataContract) onlyCREATOR external {
    petCardDataContract = _petCardDataContract;
      
}

// write functions