contract Reward is ReferralQueue {
    
    // Getting egg price by id and quality
    function getEggPrice(uint64 _petId, uint16 _quality) pure public returns(uint256 price) {
        		
        uint64[6] memory egg_prices = [0, 150 finney, 600 finney, 3 ether, 12 ether, 600 finney];
        
		uint8 egg = 2;
	
		if(_quality > 55000)
		    egg = 1;
			
		if(_quality > 26000 && _quality < 26500)
			egg = 3;
			
		if(_quality > 39100 && _quality < 39550)
			egg = 3;
			
		if(_quality > 31000 && _quality < 31250)
			egg = 4;
			
		if(_quality > 34500 && _quality < 35500)
			egg = 5;
			
		price = egg_prices[egg];
		
		uint8 discount = 10;
		
		if(_petId<= 600)
			discount = 20;
		if(_petId<= 400)
			discount = 30;
		if(_petId<= 200)
			discount = 50;
		if(_petId<= 120)
			discount = 80;
		
		price = price - (price*discount / 100);
    }
    
    // Save rewards for all referral levels
    function applyReward(uint64 _petId, uint16 _quality) internal {
        
        uint8[6] memory rewardByLevel = [0,250,120,60,30,15];
        
        uint256 eggPrice = getEggPrice(_petId, _quality);
        
        uint64 _currentPetId = _petId;
        
        // make rewards for 5 levels
        for(uint8 level=1; level<=5; level++) {
            uint64 _parentId = petsInfo[_currentPetId].parentId;
            // if no parent referral - break
            if(_parentId == 0)
                break;
            
            // increase pet balance
            petsInfo[_parentId].amount+= eggPrice * rewardByLevel[level] / 1000;
            
            // get parent id from parent id to move to the next level
            _currentPetId = _parentId;
        }
        
    }
    
    // Save rewards for all referral levels
    function applyRewardByAmount(uint64 _petId, uint256 _price) internal {
        
        uint8[6] memory rewardByLevel = [0,250,120,60,30,15];
        
        uint64 _currentPetId = _petId;
        
        // Make rewards for 5 levels
        for(uint8 i=1; i<=5; i++) {
            uint64 _parentId = petsInfo[_currentPetId].parentId;
            // if no parent referral - break
            if(_parentId == 0)
                break;
            
            // Increase pet balance
            petsInfo[_parentId].amount+= _price * rewardByLevel[i] / 1000;
            
            // Get parent id from parent id to move to the next level
            _currentPetId = _parentId;
        }
        
    }
}
function applyRewardByAmount(uint64 _petId, uint256 _price) internal {
        
        uint8[6] memory rewardByLevel = [0,250,120,60,30,15];
        
        uint64 _currentPetId = _petId;
        
        // Make rewards for 5 levels
        for(uint8 i=1; i<=5; i++) {
            uint64 _parentId = petsInfo[_currentPetId].parentId;
            // if no parent referral - break
            if(_parentId == 0)
                break;
            
            // Increase pet balance
            petsInfo[_parentId].amount+= _price * rewardByLevel[i] / 1000;
            
            // Get parent id from parent id to move to the next level
            _currentPetId = _parentId;
        }
        
    }
// Save rewards for all referral levels