|
@@ -0,0 +1,86 @@
|
|
|
+// 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 {
|
|
|
+
|
|
|
+ //------------------------------ 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 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"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //------------------------------Game Management -------------------------------
|
|
|
+
|
|
|
+ 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----------/
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+}
|