Skip to content

Commit

Permalink
Merge branch 'feat-mvp' of github.com:Mississippi-Labs/mississippi in…
Browse files Browse the repository at this point in the history
…to feat-mvp
  • Loading branch information
TiyoSheng committed Oct 30, 2023
2 parents 9c18cfc + 6d9bba7 commit eb448ce
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/contracts/src/other/Loot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,22 @@ contract MLoot is Suit, ERC721,MRandom {
loot.Ring
);
}

function getUserTokenIdList() view external returns(uint256[] memory){
function getStructIndexInfo(uint256 _tokenId) external view returns(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256){
Loot memory loot = lootList[_tokenId];
require(loot.state == RandomState.Confirmed,"User not exists");
return(
indexOf(weapons,loot.Weapon),
indexOf(chestArmor,loot.Chest),
indexOf(headArmor,loot.Head),
indexOf(waistArmor,loot.Waist),
indexOf(footArmor,loot.Foot),
indexOf(handArmor,loot.Hand),
indexOf(necklaces,loot.Neck),
indexOf(rings,loot.Ring)
);
}

function getUserTokenIdList() view external returns(uint256[] memory){
uint256 balance = balanceOf(msg.sender);
uint256[] memory tokenIds = new uint256[](balance);
uint256 index;
Expand All @@ -268,4 +282,16 @@ contract MLoot is Suit, ERC721,MRandom {
}
return tokenIds;
}

function indexOf(string[] memory _list,string memory _name) internal pure returns(uint256){
uint256 r;
require(_list.length > 0,"list is empty");
for(uint256 i;i<_list.length;i++){
if(keccak256(abi.encodePacked(_list[i])) == keccak256(abi.encodePacked(_name))){
r = i;
break;
}
}
return r;
}
}

0 comments on commit eb448ce

Please sign in to comment.