pragma solidity  ^0.4.24;
/**
1.	Scope

    All Yours is a distributed application running on the Ethereum network. By using the specially developed smart contract (“smart contract”), users can use Ethereum or other methods approved by the application to secure participation opportunities, thus randomly obtaining a certain quantity of Ether (ETH) or other rewards approved by the application. This smart contract, DAPP and our website (website: allyoursluck.com) are collectively referred to as the “application.”
    Before using the application, please read the following terms carefully and abide by them, especially terms for exemption or limitation of liability, and by applicable laws. Such terms are highlighted in bold and should be paid special attention to. For us to provide you (or the “user”) the service, we also need you to comply with other terms and the game rules (including but not limited to the instructions and User Help that have been released and will be released in the future), which you should read, understand, and accept as well. Your continuous use of the application constitutes your agreement on these terms and other rules provided by us. If you do not agree with any of the terms, you should immediately stop using the application.

2.	Application

    (1) User transfers ETH to the smart contract address (hereafter referred to as “game account”) and if the transfer is successful, the smart contract will be automatically triggered and executed.
    When the quantity of ETH in a game account reaches or exceeds the number specified in the smart contract, the smart contract will select one account address from all account addresses which have transferred ETH to the game account, according to the game rules we have released, and automatically distribute the ETH in the game account to the user whose account address has been chosen. The user whose account address has been chosen voluntarily and unconditionally donates 30% of the ETH obtained to the DREAMS COME TRUE FOUNDATION.
    The smart contract will automatically transfer 70% of the ETH to the account address selected, and 30% of them to the DREAMS COME TRUE FOUNDATION. After the transfer, the game account balance will return to zero.
    (2) In order for you to successfully use the application, you can participate in the game by using browsers that support web 3 or All Yours Dapp, or making direct transfer to an Ethereum account address in the game.
    (3) The transaction occurring in the application will be managed and confirmed by the Ethereum. Any financial transaction you participate in will be confirmed through Ethereum. Once the smart contract is triggered, we cannot control or cancel any transaction. Taking that into consideration, we shall not be liable to you or any third party for any claims or damages caused by any transaction you conduct through Ethereum, or other applications, or by using the smart contract.
    
3.	Participant

    If you have not reached the age of majority in your region, you may only use this service upon the agreement of your parents or guardian, unless there is another, looser restriction within the applicable law.
    The applications, games, and other related services we provide may fall into the areas which require special supervision or licensing in some countries and regions, and we may not have been able to obtain the relevant license or qualification. You should prudently check relevant laws, regulations, and regulatory documents of your region before you participate in the application, and should use our service and participate in the games only with regulatory permission. Your participation in the application should be limited to personal entertainment and leisure. If you violate laws and regulations in using the service we provide, you will be deemed to be in breach of the contract, and we shall have the right to terminate the service we provide to you at any time. We shall still have the right to donate all the gains from your activities or games confirmed as of the date the service is terminated to the relevant foundation pursuant to this agreement. The losses caused by your breach of contract both to you and us shall be borne by you. You shall ensure that the country you are in allows transactions conducted by means of blockchain technology (for example, you should not be a resident of the People’s Republic of China). Otherwise, your use will constitute a major breach of contract, and we shall have the right to terminate the service provided to you, and you shall bear any losses we incur due to your breach of contract.
    You guarantee that you shall not use the application to engage in any illegal and improper conduct, including theft, fraud, money laundering, or other activity that violates laws and regulations, or damages the interests of others and us.

4.	Service Content and Limited Liability

    Once you agree to these service rules, you are deemed aware that participating in the application may cause a decrease in your assets. We shall not be liable for any financial losses caused by your participation in the application.
    We will provide relevant technical support in the service so that you can use your ETH account to participate in the games or other activities that we provide. We will ensure the organization of relevant activities and the security of your ETH account with smart contract technology generally accepted in the industry. All the smart contracts are signed and occur in the decentralized ledger on the Ethereum network. We cannot control smart contracts, and will not make any guarantee or promise with regards to smart contracts.
    We do not own nor control the browser, or the Ethereum network, or any other third-party website and application you may access or use for the purpose of using the application. We shall not bear any liability or assume any obligation for any loss caused by your use of the Ethereum network or the electronic wallet, including but not limited to any loss, damage or claim resulting from the following: (A) user error, such as failure to remember the password, improperly constituted smart contract, or other transaction; (B) server failure or data loss; (C) corrupted wallet file; and (D) unauthorized access or activity by a third party, including but not limited to using viruses, fishing, loophole attacks, brute force, or other ways to attack the application, the Ethereum network, or the electronic wallet. Neither shall we guarantee that any virtual asset gained from your participation in the application will be equal in value to real money or can be exchanged with real money.
    You shall make sure that the fund, digital assets, or tokens you used in this service all come from legal sources recognized by the applicable law of the place where you are located, and the use of such assets by you in this service does not violate relevant regulations regarding money laundering, fraud, terrorism, and tax evasion. Otherwise, any abovementioned conduct by you will be deemed as a material violation, and you shall independently bear any regulatory penalty and relevant loss thus incurred, whether for you or us.
    You understand that relevant activities and your gains are of an unpredictable and random nature. You promise that you will not claim any compensation or damages from us for the reduction or loss of your expected income caused by the randomness and unpredictability of the activities.
    You understand that there are technical limitations to the service we provide; we shall not be responsible for the storage, modification, deletion, or failure in storage of the data or information released or provided by you, and you shall bear any personal losses thus incurred.
    We shall not be responsible for any delay, lag, or errors in the information and data provided in this service due to force majeure that affects the normal operation of the network, such as a change in government policies or regulations, natural disaster or war, interruption of communication lines, hacker attacks, computer virus invasion or attack, technical adjustment of the telecommunications department, or temporary closure of services due to government regulation, as well as the disruption in the provision of this service caused by sabotage by others, normal system maintenance or system upgrade, or network congestion. Neither shall we be liable for any losses thus incurred for the user.

5.	Fees

    You should understand that Ethereum charges a transaction fee for each transaction occurring on the Ethereum network (“miner fees”). Miner fees provide support for the operation of the computer network of the decentralized Ethereum network. This means that you need to pay miner fees for each transaction conducted through the application.
    You agree that 30% of all your gains from your participation in the games or activities as described in this agreement will be donated through us to the DREAMS COME TRUE FOUNDATION. The foundation shall have the right to use part or all of your donation according to its own Articles of Association and rules, including but not limited to making donation to charity projects and supporting blockchain innovation projects. The abovementioned donation shall take effect immediately upon your receipt of the game or activity awards. You agree that by confirming your participation in the application, you are deemed to have irrevocably authorized the smart contract to automatically trigger the abovementioned donation; the transfer will be completed immediately, and you shall not have the right to revoke the donation.
    Except for the fees mentioned above, we will not charge any commission for your participation in the application.
    You shall be responsible for the payment of any and all sales tax, use tax, added-value tax, or other taxes any governmental authority claims or imposes now or in the future for the use of the application.

6.	Personal Information Protection

    We promise to guarantee the security of your personal information within the scope of the applicable law.
    You agree that we shall have the right to record your digital asset account address and its transaction information generated from your use of our service, and such digital asset account address and transaction information shall not be deemed as your personal information, unless otherwise provided for by applicable law.
    You understand that as long as you conduct transactions in the application, your Ethereum public broadcasting address will be shown publicly. You shall be solely responsible for the security of your wallet and account. If you are aware of any unauthorized use, you agree that you shall immediately notify us via service(a)allyoursluck.com.

7.	Change or Termination of Service

    We continually upgrade the application to provide the best experience, and may do so without further notice. We may change these terms from time to time. When making any change, we will provide updated terms in the application, and update the “last update” date at the beginning of these terms accordingly. After the terms are updated, your continued access to or use of the application shall constitute your binding acceptance of various updates.
    If you violate this agreement, we shall have the right to suspend or terminate the service we provide to you as penalty. If we therefore terminate the service, we shall still have the right to donate your gains from activities or games confirmed as of the date of service termination to the relevant foundation according to this agreement, and you shall be responsible for both your and our losses caused by your breach of contract.
    You can terminate these terms at any time by ceasing to access and use the application. If you terminate usage, you will not receive any refund.

8.	Intellectual Property

    You need to download and install the software we provide before you can use our service. We hereby grant you free, non-transferable, non-exclusive, global personal permission to use the software contained in the service provided by us for non-commercial purposes. However, you shall not copy, modify, release, sell, or lease any part of our service or the software therein; you shall not delete any information about copyright in the software and/or other copies; you shall not use plug-in, add-on, or other third-party tools unauthorized by us to obstruct, sabotage, modify, or exert other influence on the service and the software program, nor shall you carry out reverse engineering or try to extract the source code of the software, unless the law forbids the aforementioned restriction or you have obtained our written consent.
    All the contents contained in or provided by the service we provide, such as text, graphs, signs, button icons, images, voice file clips, digital downloads, data editing, software, and software data, are our property or that of the content providers, and are protected by international copyright law. All the software contained in the service we provide is our property or property of our software suppliers, and is protected by international copyright law.
    Meanwhile, we respect the intellectual property of others. If you believe that relevant information constitutes copyright infringement on the use of your work, please notify us in a timely manner through the email address of our customer service, and we will process the complaint according to the copyright infringement complaint procedure specified in existing laws and regulations. At the same time, you agree to compensate us for any potential third-party claim against us incurred by the notice you submit, including but not limited to all the reasonable costs we have paid.


 * */

contract AllYours {


    address private _platformAddress = 0x14551DeA29FAe64D84ba5670F7311E71a15e83e2;

    uint private _totalEth = 1 ether;

    uint128 private _oneceEth = 0.1 ether;

    uint32 private _period = 1;

    address private _owner;



    constructor() public{

        _owner = msg.sender;

    }

    address[] private _allAddress;

    uint16 private _currentJoinPersonNumber;


    event drawCallback(address winnerAddress,uint period,uint balance,uint time );



    function getCurrentJoinPersonNumber() view public returns(uint24) {

        return _currentJoinPersonNumber;

    }



    function getPeriod() view public returns(uint32) {

        return _period;

    }

    function getCurrentBalance() view public returns(uint256) {

        return address(this).balance;

    }



    function draw() internal view returns (uint24) {

        bytes32 hash = keccak256(abi.encodePacked(block.number));

        uint256 random = 0;

        for(uint i=hash.length-8;i<hash.length;i++) {

            random += uint256(hash[i])*(10**(hash.length-i));

        }

        random += now;



        bytes memory hashAddress=toBytes(_allAddress[0]);

        for(uint j=0;j<8;j++) {

            random += uint(hashAddress[j])*(10**(8-j));

        }

        uint24 index = uint24(random % _allAddress.length);

        return index;



    }




    function kill() public payable {

        if (_owner == msg.sender) {

            _platformAddress.transfer(address(this).balance);

            selfdestruct(_owner);

        }

    }



    function() public payable {
	require(tx.origin == msg.sender);

        require(msg.value >= _oneceEth);


        uint len = msg.value/_oneceEth;

        for(uint i=0;i<len;i++) {

            _allAddress.push(msg.sender);

        }
        _currentJoinPersonNumber ++;


        if(address(this).balance >= _totalEth) {

            uint24 index = draw();

            address drawAddress = _allAddress[index];

            uint256 b = address(this).balance;

            uint256 pay = b*70/100;

            drawAddress.transfer(pay);

            _platformAddress.transfer(b*30/100);



            emit drawCallback(drawAddress,_period,pay,now);

            _period ++;

            clear();

        }

    }



    function clear() internal {

        _currentJoinPersonNumber = 0;

        delete _allAddress;

    }



    function toBytes(address x) internal pure returns (bytes b) {

        b = new bytes(20);

        for (uint i = 0; i < 20; i++)

            b[i] = byte(uint8(uint(x) / (2**(8*(19 - i)))));

    }



}