123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- // SPDX-License-Identifier: MIT
- pragma solidity ^0.8.0;
- import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
- import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
- import "@openzeppelin/contracts/utils/Strings.sol";
- import "@openzeppelin/contracts/access/Ownable.sol";
- contract GameData is ERC1155, Ownable, ERC1155Burnable {
- string public name = "Sekret Game Launcher";
- string public symbol = "SGL";
- //------------------------------ ERC1155 COLLECTION-------------------------------
- uint256 public constant TOURNAMENT_TICKETS = 0;
- uint256 public constant SafeCoins = 1;
- uint256 public constant PP = 2;
- uint256 public constant TOURNAMENT_TROPHIES = 3;
- uint256 public nextUserId = 100; //Dynamically change with user count, hence: new id for new player
- uint256 public ticketPrice = 0.0001 ether; // Price for each ticket
- constructor() ERC1155("http://linode.playpoolstudios.com/begula/nft_data/{id}.json") Ownable(msg.sender){
- _mint(msg.sender, TOURNAMENT_TICKETS, 10**27, "");
- _mint(msg.sender, SafeCoins, 10**27,"");
- _mint(msg.sender, PP, 10**27, "");
- _mint(msg.sender, TOURNAMENT_TROPHIES, 36000, "");
- }
- function buyTickets(uint256 amount) external payable {
- require(msg.value >= ticketPrice * amount, "Not enough Ether sent");
- //_mint(msg.sender, TOURNAMENT_TICKETS, amount, "");
- _safeTransferFrom(owner(), msg.sender, 0, amount, '');
- }
- function setTicketPrice(uint256 newPrice) public onlyOwner {
- ticketPrice = newPrice;
- }
- function withdraw() external onlyOwner {
- payable(owner()).transfer(address(this).balance);
- }
- function uri(uint256 _tokenid) public pure override returns (string memory) {
- return string(abi.encodePacked("http://linode.playpoolstudios.com/begula/nft_data/", Strings.toString(_tokenid), ".json"));
- }
- function setCollectionName(string memory _name) public{
- name= _name;
- }
- //------------------------------Game Management -------------------------------
- //-----------setters and getters--------------------/
- address public operator = 0x05Ed0E0905979682bBD13A4524B2B1300153847e;
- function setOperator(address newOp) external onlyOwner{
- operator = newOp;
- }
- mapping(uint256 => address[]) tournamentParticipants;
- function getTournamentParticipants(uint256 tournamentId) public view returns(address[] memory) {
- return tournamentParticipants[tournamentId];
- }
- function getTournamentParticipentsCount(uint256 tournamentId) public view returns(uint256){
- return tournamentParticipants[tournamentId].length;
- }
- uint256[] expiredTournaments;
- function getExpiredTournaments() public view returns(uint256[] memory){
- return expiredTournaments;
- }
- mapping(address=> uint256[]) ticketOwnerships;
- function getUserTickets(address user) public view returns(uint256[] memory){
- return ticketOwnerships[user];
- }
- //-----------end of Setters and getters----------/
- //----------User Management--------------------/
- uint256[] public userMintedIds;
- function GetUserMintedIds() public view returns(uint256[] memory){
- return userMintedIds;
- }
- function GetCurrentUserIndex() public view returns(uint256){
- return nextUserId;
- }
- function MintUser(uint256 newUserId,address newUserAddress) public{
- require(msg.sender == operator || msg.sender == owner(), "Only the operator can do this");
- _mint(newUserAddress, newUserId, 1, "");
- userMintedIds.push(newUserId);
- nextUserId++;
- }
- //------------------------------/
- //----------Tourneys and tickets--------------------/
- function useTicket(address user, uint256 tournament_id) public {
- require(balanceOf(user, 0) > 0, "Purchase tickets to participate in this");
- _burn(user, 0, 1);
- tournamentParticipants[tournament_id].push(user);
- ticketOwnerships[user].push(tournament_id);
- }
- function startTournament(uint256 tournament_id) public{
- require(msg.sender == operator , "Only the operator can do this");
- expiredTournaments.push(tournament_id);
- }
- //------------------------------/
- }
|