GameData.sol 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.0;
  3. import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
  4. import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
  5. import "@openzeppelin/contracts/utils/Strings.sol";
  6. import "@openzeppelin/contracts/access/Ownable.sol";
  7. contract GameData is ERC1155, Ownable, ERC1155Burnable {
  8. string public name = "Sekret Game Launcher";
  9. string public symbol = "SGL";
  10. //------------------------------ ERC1155 COLLECTION-------------------------------
  11. uint256 public constant TOURNAMENT_TICKETS = 0;
  12. uint256 public constant SafeCoins = 1;
  13. uint256 public constant PP = 2;
  14. uint256 public constant TOURNAMENT_TROPHIES = 3;
  15. uint256 public nextUserId = 100; //Dynamically change with user count, hence: new id for new player
  16. uint256 public ticketPrice = 0.0001 ether; // Price for each ticket
  17. constructor() ERC1155("http://linode.playpoolstudios.com/begula/nft_data/{id}.json") Ownable(msg.sender){
  18. _mint(msg.sender, TOURNAMENT_TICKETS, 10**27, "");
  19. _mint(msg.sender, SafeCoins, 10**27,"");
  20. _mint(msg.sender, PP, 10**27, "");
  21. _mint(msg.sender, TOURNAMENT_TROPHIES, 36000, "");
  22. }
  23. function buyTickets(uint256 amount) external payable {
  24. require(msg.value >= ticketPrice * amount, "Not enough Ether sent");
  25. //_mint(msg.sender, TOURNAMENT_TICKETS, amount, "");
  26. _safeTransferFrom(owner(), msg.sender, 0, amount, '');
  27. }
  28. function setTicketPrice(uint256 newPrice) public onlyOwner {
  29. ticketPrice = newPrice;
  30. }
  31. function withdraw() external onlyOwner {
  32. payable(owner()).transfer(address(this).balance);
  33. }
  34. function uri(uint256 _tokenid) public pure override returns (string memory) {
  35. return string(abi.encodePacked("http://linode.playpoolstudios.com/begula/nft_data/", Strings.toString(_tokenid), ".json"));
  36. }
  37. function setCollectionName(string memory _name) public{
  38. name= _name;
  39. }
  40. //------------------------------Game Management -------------------------------
  41. //-----------setters and getters--------------------/
  42. address public operator = 0x05Ed0E0905979682bBD13A4524B2B1300153847e;
  43. function setOperator(address newOp) external onlyOwner{
  44. operator = newOp;
  45. }
  46. mapping(uint256 => address[]) tournamentParticipants;
  47. function getTournamentParticipants(uint256 tournamentId) public view returns(address[] memory) {
  48. return tournamentParticipants[tournamentId];
  49. }
  50. function getTournamentParticipentsCount(uint256 tournamentId) public view returns(uint256){
  51. return tournamentParticipants[tournamentId].length;
  52. }
  53. uint256[] expiredTournaments;
  54. function getExpiredTournaments() public view returns(uint256[] memory){
  55. return expiredTournaments;
  56. }
  57. mapping(address=> uint256[]) ticketOwnerships;
  58. function getUserTickets(address user) public view returns(uint256[] memory){
  59. return ticketOwnerships[user];
  60. }
  61. //-----------end of Setters and getters----------/
  62. //----------User Management--------------------/
  63. uint256[] public userMintedIds;
  64. function GetUserMintedIds() public view returns(uint256[] memory){
  65. return userMintedIds;
  66. }
  67. function GetCurrentUserIndex() public view returns(uint256){
  68. return nextUserId;
  69. }
  70. function MintUser(uint256 newUserId,address newUserAddress) public{
  71. require(msg.sender == operator || msg.sender == owner(), "Only the operator can do this");
  72. _mint(newUserAddress, newUserId, 1, "");
  73. userMintedIds.push(newUserId);
  74. nextUserId++;
  75. }
  76. //------------------------------/
  77. //----------Tourneys and tickets--------------------/
  78. function useTicket(address user, uint256 tournament_id) public {
  79. require(balanceOf(user, 0) > 0, "Purchase tickets to participate in this");
  80. _burn(user, 0, 1);
  81. tournamentParticipants[tournament_id].push(user);
  82. ticketOwnerships[user].push(tournament_id);
  83. }
  84. function startTournament(uint256 tournament_id) public{
  85. require(msg.sender == operator , "Only the operator can do this");
  86. expiredTournaments.push(tournament_id);
  87. }
  88. //------------------------------/
  89. }