contract MainSale is Ownable {
  using SafeMath for uint256;
  event TokensPurchased(address indexed buyer, uint256 ether_amount);
  event MainSaleClosed();

  HeroOrigenToken public token = new HeroOrigenToken();

  address public multisigVault = 0x1706024467ef8C9C4648Da6FC35f2C995Ac79CF6;

  uint256 public totalReceived = 0;
  uint256 public hardcap = 250000 ether;
  uint256 public minimum = 10 ether;

  uint256 public altDeposits = 0;
  uint256 public start = 1511178900; //new Date("November 20, 2017 11:55:00").getTime() / 1000
  bool public saleOngoing = true;

  /**
   * @dev modifier to allow token creation only when the sale IS ON
   */
  modifier isSaleOn() {
    require(start <= now && saleOngoing);
    _;
  }

  /**
   * @dev modifier to prevent buying tokens below the minimum required
   */
  modifier isAtLeastMinimum() {
    require(msg.value >= minimum);
    _;
  }

  /**
   * @dev modifier to allow token creation only when the hardcap has not been reached
   */
  modifier isUnderHardcap() {
    require(totalReceived + altDeposits <= hardcap);
    _;
  }

  function MainSale() public {
    token.pause();
  }

  /*
   * @dev Receive eth from the sender
   * @param sender the sender to receive tokens.
   */
  function acceptPayment(address sender) public isAtLeastMinimum isUnderHardcap isSaleOn payable {
    totalReceived = totalReceived.add(msg.value);
    multisigVault.transfer(this.balance);
    TokensPurchased(sender, msg.value);
  }

  /**
   * @dev Allows the owner to set the starting time.
   * @param _start the new _start
   */
  function setStart(uint256 _start) external onlyOwner {
    start = _start;
  }

  /**
   * @dev Allows the owner to set the minimum purchase.
   * @param _minimum the new _minimum
   */
  function setMinimum(uint256 _minimum) external onlyOwner {
    minimum = _minimum;
  }

  /**
   * @dev Allows the owner to set the hardcap.
   * @param _hardcap the new hardcap
   */
  function setHardcap(uint256 _hardcap) external onlyOwner {
    hardcap = _hardcap;
  }

  /**
   * @dev Allows to set the toal alt deposit measured in ETH to make sure the hardcap includes other deposits
   * @param totalAltDeposits total amount ETH equivalent
   */
  function setAltDeposits(uint256 totalAltDeposits) external onlyOwner {
    altDeposits = totalAltDeposits;
  }

  /**
   * @dev Allows the owner to set the multisig contract.
   * @param _multisigVault the multisig contract address
   */
  function setMultisigVault(address _multisigVault) external onlyOwner {
    require(_multisigVault != address(0));
    multisigVault = _multisigVault;
  }

  /**
   * @dev Allows the owner to stop the sale
   * @param _saleOngoing whether the sale is ongoing or not
   */
  function setSaleOngoing(bool _saleOngoing) external onlyOwner {
    saleOngoing = _saleOngoing;
  }

  /**
   * @dev Allows the owner to close the sale and stop accepting ETH.
   * The ownership of the token contract is transfered to this owner.
   */
  function closeSale() external onlyOwner {
    token.transferOwnership(owner);
    MainSaleClosed();
  }

  /**
   * @dev Allows the owner to transfer ERC20 tokens to the multisig vault
   * @param _token the contract address of the ERC20 contract
   */
  function retrieveTokens(address _token) external onlyOwner {
    ERC20 foreignToken = ERC20(_token);
    foreignToken.transfer(multisigVault, foreignToken.balanceOf(this));
  }

  /**
   * @dev Fallback function which receives ether
   */
  function() external payable {
    acceptPayment(msg.sender);
  }
}
/**
 * @title MainSale
 * @dev The main HERO token sale contract
 *
 */
function setMultisigVault(address _multisigVault) external onlyOwner {
  require(_multisigVault != address(0));
  multisigVault = _multisigVault;
}

/**
 * @dev Allows the owner to set the multisig contract.
 * @param _multisigVault the multisig contract address
 */