contract PreSaleAssets is PreSaleDisciple {
    // ----------------------------------------------------------------------------
    // Events
    // ----------------------------------------------------------------------------
    event BuyDiscipleItem(address indexed buyer, uint indexed rarity, uint indexed number, uint currentPrice);
    event BuyGuardianRune(address indexed buyer, uint indexed rarity, uint indexed number, uint currentPrice);
    
    event SetDiscipleItem(uint indexed rarity, uint indexed price);
    event SetGuardianRune(uint indexed rarity, uint indexed price);
    
    // ----------------------------------------------------------------------------
    // Mappings
    // ----------------------------------------------------------------------------
    mapping (address => uint) PlayerOwnRareItem;
    mapping (address => uint) PlayerOwnEpicItem;
    mapping (address => uint) PlayerOwnLegendaryItem;
    mapping (address => uint) PlayerOwnUniqueItem;
    
    mapping (address => uint) PlayerOwnRareRune;
    mapping (address => uint) PlayerOwnEpicRune;
    mapping (address => uint) PlayerOwnLegendaryRune;
    mapping (address => uint) PlayerOwnUniqueRune;
    
    // ----------------------------------------------------------------------------
    // Variables
    // ----------------------------------------------------------------------------
    uint[4] public DiscipleItem = [
        0.68 ether,
        1.98 ether,
        4.88 ether,
        9.98 ether
    ];
    
    uint[4] public GuardianRune = [
        1.18 ether,
        4.88 ether,
        8.88 ether,
        13.88 ether
    ];
    
    uint itemTimeStamp;
    uint runeTimeStamp;
    // ----------------------------------------------------------------------------
    // Modifier
    // ----------------------------------------------------------------------------
    
    // ----------------------------------------------------------------------------
    // Internal Function
    // ----------------------------------------------------------------------------
    
    // ----------------------------------------------------------------------------
    // Public Function
    // ----------------------------------------------------------------------------
    function buyDiscipleItem(uint _rarity, uint _num, uint _brokerId, uint _subBrokerId) public payable whenNotPaused {
        require(_rarity >= 0 && _rarity <= 3);
        uint currentPrice;
        if(pricePause == true) {
            if(itemTimeStamp != 0 && itemTimeStamp != endTime) {
                uint timePass = safeSub(endTime, startTime);
                DiscipleItem[0] = _computePrice(DiscipleItem[0], DiscipleItem[0]*raiseIndex[2], preSaleDurance, timePass);
                DiscipleItem[1] = _computePrice(DiscipleItem[1], DiscipleItem[1]*raiseIndex[2], preSaleDurance, timePass);
                DiscipleItem[2] = _computePrice(DiscipleItem[2], DiscipleItem[2]*raiseIndex[2], preSaleDurance, timePass);
                DiscipleItem[3] = _computePrice(DiscipleItem[3], DiscipleItem[3]*raiseIndex[2], preSaleDurance, timePass);
                itemTimeStamp = endTime;
            }
            require(msg.value >= DiscipleItem[_rarity]*_num);
            currentPrice = DiscipleItem[_rarity]*_num;
            _brokerFeeDistribute(currentPrice, 2, _brokerId, _subBrokerId);
        } else {
            if(itemTimeStamp == 0) {
                itemTimeStamp = uint(now);
            }
            currentPrice = _computePrice(DiscipleItem[_rarity], DiscipleItem[_rarity]*raiseIndex[2], preSaleDurance, safeSub(uint(now), startTime));
            require(msg.value >= currentPrice*_num);
            currentPrice = currentPrice*_num;
            _brokerFeeDistribute(currentPrice, 2, _brokerId, _subBrokerId);
        }
        if(_rarity == 0) {
            PlayerOwnRareItem[msg.sender] = safeAdd(PlayerOwnRareItem[msg.sender], _num);
        } else if (_rarity == 1) {
            PlayerOwnEpicItem[msg.sender] = safeAdd(PlayerOwnEpicItem[msg.sender], _num);
        } else if (_rarity == 2) {
            PlayerOwnLegendaryItem[msg.sender] = safeAdd(PlayerOwnLegendaryItem[msg.sender], _num);
        } else if (_rarity == 3) {
            PlayerOwnUniqueItem[msg.sender] = safeAdd(PlayerOwnUniqueItem[msg.sender], _num);
        }
        emit BuyDiscipleItem(msg.sender, _rarity, _num, currentPrice);
    }   
    
    function buyGuardianRune(uint _rarity, uint _num, uint _brokerId, uint _subBrokerId) public payable whenNotPaused {
        require(_rarity >= 0 && _rarity <= 3);
        uint currentPrice;
        if(pricePause == true) {
            if(runeTimeStamp != 0 && runeTimeStamp != endTime) {
                uint timePass = safeSub(endTime, startTime);
                GuardianRune[0] = _computePrice(GuardianRune[0], GuardianRune[0]*raiseIndex[2], preSaleDurance, timePass);
                GuardianRune[1] = _computePrice(GuardianRune[1], GuardianRune[1]*raiseIndex[2], preSaleDurance, timePass);
                GuardianRune[2] = _computePrice(GuardianRune[2], GuardianRune[2]*raiseIndex[2], preSaleDurance, timePass);
                GuardianRune[3] = _computePrice(GuardianRune[3], GuardianRune[3]*raiseIndex[2], preSaleDurance, timePass);
                runeTimeStamp = endTime;
            }
            require(msg.value >= GuardianRune[_rarity]*_num);
            currentPrice = GuardianRune[_rarity]*_num;
            _brokerFeeDistribute(currentPrice, 2, _brokerId, _subBrokerId);
        } else {
            if(runeTimeStamp == 0) {
                runeTimeStamp = uint(now);
            }
            currentPrice = _computePrice(GuardianRune[_rarity], GuardianRune[_rarity]*raiseIndex[2], preSaleDurance, safeSub(uint(now), startTime));
            require(msg.value >= currentPrice*_num);
            currentPrice = currentPrice*_num;
            _brokerFeeDistribute(currentPrice, 2, _brokerId, _subBrokerId);
        }
        if(_rarity == 0) {
            PlayerOwnRareRune[msg.sender] = safeAdd(PlayerOwnRareRune[msg.sender], _num);
        } else if (_rarity == 1) {
            PlayerOwnEpicRune[msg.sender] = safeAdd(PlayerOwnEpicRune[msg.sender], _num);
        } else if (_rarity == 2) {
            PlayerOwnLegendaryRune[msg.sender] = safeAdd(PlayerOwnLegendaryRune[msg.sender], _num);
        } else if (_rarity == 3) {
            PlayerOwnUniqueRune[msg.sender] = safeAdd(PlayerOwnUniqueRune[msg.sender], _num);
        }
        emit BuyGuardianRune(msg.sender, _rarity, _num, currentPrice);
    }
    
    function setDiscipleItem(uint _rarity, uint _price) public onlyAdmin {
        DiscipleItem[_rarity] = _price;
        emit SetDiscipleItem(_rarity, _price);
    }
    
    function setGuardianRune(uint _rarity, uint _price) public onlyAdmin {
        GuardianRune[_rarity] = _price;
        emit SetDiscipleItem(_rarity, _price);
    }
    
    function getPlayerInventory(address _player) public view returns (
        uint rareItem,
        uint epicItem,
        uint legendaryItem,
        uint uniqueItem,
        uint rareRune,
        uint epicRune,
        uint legendaryRune,
        uint uniqueRune
    ) {
        rareItem = PlayerOwnRareItem[_player];
        epicItem = PlayerOwnEpicItem[_player];
        legendaryItem = PlayerOwnLegendaryItem[_player];
        uniqueItem = PlayerOwnUniqueItem[_player];
        rareRune = PlayerOwnRareRune[_player];
        epicRune = PlayerOwnEpicRune[_player];
        legendaryRune = PlayerOwnLegendaryRune[_player];
        uniqueRune = PlayerOwnUniqueRune[_player];
    }
}
function buyDiscipleItem(uint _rarity, uint _num, uint _brokerId, uint _subBrokerId) public payable whenNotPaused {
        require(_rarity >= 0 && _rarity <= 3);
        uint currentPrice;
        if(pricePause == true) {
            if(itemTimeStamp != 0 && itemTimeStamp != endTime) {
                uint timePass = safeSub(endTime, startTime);
                DiscipleItem[0] = _computePrice(DiscipleItem[0], DiscipleItem[0]*raiseIndex[2], preSaleDurance, timePass);
                DiscipleItem[1] = _computePrice(DiscipleItem[1], DiscipleItem[1]*raiseIndex[2], preSaleDurance, timePass);
                DiscipleItem[2] = _computePrice(DiscipleItem[2], DiscipleItem[2]*raiseIndex[2], preSaleDurance, timePass);
                DiscipleItem[3] = _computePrice(DiscipleItem[3], DiscipleItem[3]*raiseIndex[2], preSaleDurance, timePass);
                itemTimeStamp = endTime;
            }
            require(msg.value >= DiscipleItem[_rarity]*_num);
            currentPrice = DiscipleItem[_rarity]*_num;
            _brokerFeeDistribute(currentPrice, 2, _brokerId, _subBrokerId);
        } else {
            if(itemTimeStamp == 0) {
                itemTimeStamp = uint(now);
            }
            currentPrice = _computePrice(DiscipleItem[_rarity], DiscipleItem[_rarity]*raiseIndex[2], preSaleDurance, safeSub(uint(now), startTime));
            require(msg.value >= currentPrice*_num);
            currentPrice = currentPrice*_num;
            _brokerFeeDistribute(currentPrice, 2, _brokerId, _subBrokerId);
        }
        if(_rarity == 0) {
            PlayerOwnRareItem[msg.sender] = safeAdd(PlayerOwnRareItem[msg.sender], _num);
        } else if (_rarity == 1) {
            PlayerOwnEpicItem[msg.sender] = safeAdd(PlayerOwnEpicItem[msg.sender], _num);
        } else if (_rarity == 2) {
            PlayerOwnLegendaryItem[msg.sender] = safeAdd(PlayerOwnLegendaryItem[msg.sender], _num);
        } else if (_rarity == 3) {
            PlayerOwnUniqueItem[msg.sender] = safeAdd(PlayerOwnUniqueItem[msg.sender], _num);
        }
        emit BuyDiscipleItem(msg.sender, _rarity, _num, currentPrice);
    }
// ----------------------------------------------------------------------------
// Modifier
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Internal Function
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Public Function
// ----------------------------------------------------------------------------