contract FootballerAction is FootballerOwnership {
  //创建球星
  function createFootballerStar(uint _price,uint _defend,uint _attack, uint _quality) public returns(uint) {
      return _createFootballerStar(_price,_defend,_attack,_quality);
  }

  //抽卡包得球星
  function CardFootballers() public payable returns (uint) {
      uint price = 4000000000000 wei; //0.04 eth
      require(msg.value >= price);
      uint ballerCount = 14;
      uint newFootballerId = 0;
      for (uint i = 0; i < ballerCount; i++) {
         newFootballerId = createFootballer();
      }
      managerAddress.transfer(msg.value);
      return price;
  }

  function buyStar(uint footballerId,uint price) public payable  {
    require(msg.value >= price);
    //将球星的拥有权 交给 购买的用户
    address holder = footballerToApproved[footballerId];
    require(holder != address(0));
    _transfer(holder,msg.sender,footballerId);
    //给卖家转钱
    holder.transfer(msg.value);
  }

  //用户出售自己拥有的球员或球星
  function sell(uint footballerId,uint price) public returns(uint) {
    require(footballerToOwner[footballerId] == msg.sender);
    require(footballerToApproved[footballerId] == address(0));
    footballerToApproved[footballerId] = msg.sender;
    footballers[footballerId].price = price;
  }

  //显示球队
  function getTeamBallers(address actor) public view returns (uint[]) {
    uint len = footballers.length;
    uint count=0;
    for(uint i = 0; i < len; i++) {
        if(_owns(actor, i)){
          if(footballerToApproved[i] == address(0)){
            count++;
          }
       }
    }
    uint[] memory res = new uint256[](count);
    uint index = 0;
    for(i = 0; i < len; i++) {
      if(_owns(actor, i)){
          if(footballerToApproved[i] == address(0)){
            res[index] = i;
            index++;
          }
        }
    }
    return res;
  }

  //显示出售的球星+球员
  function getSellBallers() public view returns (uint[]) {
    uint len = footballers.length;
    uint count = 0;
    for(uint i = 0; i < len; i++) {
        if(footballerToApproved[i] != address(0)){
          count++;
        }
    }
    uint[] memory res = new uint256[](count);
    uint index = 0;
    for( i = 0; i < len; i++) {
        if(footballerToApproved[i] != address(0)){
          res[index] = i;
          index++;
        }
    }
    return res;
  }

  //获得球员+球星的总数量
  function getAllBaller() public view returns (uint) {
    uint len = totalSupply();
    return len;
  }

}
function getTeamBallers(address actor) public view returns (uint[]) {
  uint len = footballers.length;
  uint count=0;
  for(uint i = 0; i < len; i++) {
      if(_owns(actor, i)){
        if(footballerToApproved[i] == address(0)){
          count++;
        }
     }
  }
  uint[] memory res = new uint256[](count);
  uint index = 0;
  for(i = 0; i < len; i++) {
    if(_owns(actor, i)){
        if(footballerToApproved[i] == address(0)){
          res[index] = i;
          index++;
        }
      }
  }
  return res;
}

//显示球队