forked from CryptoSenju/BattleHeroContract-NFT-Game-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleHeroBreeder.sol
57 lines (51 loc) · 2.15 KB
/
BattleHeroBreeder.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
import "../node_modules/@openzeppelin/contracts/utils/Strings.sol";
import "../node_modules/@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "./shared/IBattleHeroFactory.sol";
import "./shared/IBattleHero.sol";
import "./shared/IBattleHeroGenScience.sol";
contract BattleHeroBreeder is
AccessControlEnumerable {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant BREED_ROLE = keccak256("BREED_ROLE");
IBattleHeroGenScience _genScience;
IBattleHeroFactory _erc721factory;
using Strings for uint256;
constructor(
address genScience,
address erc721) {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(BREED_ROLE, _msgSender());
setGenScience(genScience);
setERC721Factory(erc721);
}
modifier isSetup() {
require(address(_genScience) != address(0), "Setup not correctly");
require(address(_erc721factory) != address(0), "Setup not correctly");
_;
}
function setGenScience(address genScience) public{
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()));
_genScience = IBattleHeroGenScience(genScience);
}
function setERC721Factory(address erc721) public{
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()));
_erc721factory = IBattleHeroFactory(erc721);
}
function addBreeder(address breeder) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "Invalid role for add breder");
_setupRole(BREED_ROLE, breeder);
}
function breed(address to, string memory gen) isSetup public returns(uint) {
require(hasRole(BREED_ROLE, _msgSender()), "Invalid role for breed");
uint tokenId = _erc721factory.mint(to, gen);
return tokenId;
}
function breedRandom() isSetup public returns (uint){
require(hasRole(BREED_ROLE, _msgSender()), "Invalid role for breed random");
string memory randomGen = _genScience.generate();
return breed(msg.sender, randomGen);
}
}