-
Notifications
You must be signed in to change notification settings - Fork 89
/
AxieCore.sol
105 lines (90 loc) · 2.28 KB
/
AxieCore.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
pragma solidity ^0.4.19;
import "./erc721/AxieERC721.sol";
// solium-disable-next-line no-empty-blocks
contract AxieCore is AxieERC721 {
struct Axie {
uint256 genes;
uint256 bornAt;
}
Axie[] axies;
event AxieSpawned(uint256 indexed _axieId, address indexed _owner, uint256 _genes);
event AxieRebirthed(uint256 indexed _axieId, uint256 _genes);
event AxieRetired(uint256 indexed _axieId);
event AxieEvolved(uint256 indexed _axieId, uint256 _oldGenes, uint256 _newGenes);
function AxieCore() public {
axies.push(Axie(0, now)); // The void Axie
_spawnAxie(0, msg.sender); // Will be Puff
_spawnAxie(0, msg.sender); // Will be Kotaro
_spawnAxie(0, msg.sender); // Will be Ginger
_spawnAxie(0, msg.sender); // Will be Stella
}
function getAxie(
uint256 _axieId
)
external
view
mustBeValidToken(_axieId)
returns (uint256 /* _genes */, uint256 /* _bornAt */)
{
Axie storage _axie = axies[_axieId];
return (_axie.genes, _axie.bornAt);
}
function spawnAxie(
uint256 _genes,
address _owner
)
external
onlySpawner
whenSpawningAllowed(_genes, _owner)
returns (uint256)
{
return _spawnAxie(_genes, _owner);
}
function rebirthAxie(
uint256 _axieId,
uint256 _genes
)
external
onlySpawner
mustBeValidToken(_axieId)
whenRebirthAllowed(_axieId, _genes)
{
Axie storage _axie = axies[_axieId];
_axie.genes = _genes;
_axie.bornAt = now;
AxieRebirthed(_axieId, _genes);
}
function retireAxie(
uint256 _axieId,
bool _rip
)
external
onlyByeSayer
whenRetirementAllowed(_axieId, _rip)
{
_burn(_axieId);
if (_rip) {
delete axies[_axieId];
}
AxieRetired(_axieId);
}
function evolveAxie(
uint256 _axieId,
uint256 _newGenes
)
external
onlyGeneScientist
mustBeValidToken(_axieId)
whenEvolvementAllowed(_axieId, _newGenes)
{
uint256 _oldGenes = axies[_axieId].genes;
axies[_axieId].genes = _newGenes;
AxieEvolved(_axieId, _oldGenes, _newGenes);
}
function _spawnAxie(uint256 _genes, address _owner) private returns (uint256 _axieId) {
Axie memory _axie = Axie(_genes, now);
_axieId = axies.push(_axie) - 1;
_mint(_owner, _axieId);
AxieSpawned(_axieId, _owner, _genes);
}
}