-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathEtheremonTransformData.sol
More file actions
195 lines (158 loc) · 5.64 KB
/
EtheremonTransformData.sol
File metadata and controls
195 lines (158 loc) · 5.64 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
pragma solidity ^0.4.16;
// copyright contact@Etheremon.com
contract SafeMath {
/* function assert(bool assertion) internal { */
/* if (!assertion) { */
/* throw; */
/* } */
/* } // assert no longer needed once solidity is on 0.4.10 */
function safeAdd(uint256 x, uint256 y) pure internal returns(uint256) {
uint256 z = x + y;
assert((z >= x) && (z >= y));
return z;
}
function safeSubtract(uint256 x, uint256 y) pure internal returns(uint256) {
assert(x >= y);
uint256 z = x - y;
return z;
}
function safeMult(uint256 x, uint256 y) pure internal returns(uint256) {
uint256 z = x * y;
assert((x == 0)||(z/x == y));
return z;
}
}
contract BasicAccessControl {
address public owner;
// address[] public moderators;
uint16 public totalModerators = 0;
mapping (address => bool) public moderators;
bool public isMaintaining = true;
function BasicAccessControl() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
modifier onlyModerators() {
require(msg.sender == owner || moderators[msg.sender] == true);
_;
}
modifier isActive {
require(!isMaintaining);
_;
}
function ChangeOwner(address _newOwner) onlyOwner public {
if (_newOwner != address(0)) {
owner = _newOwner;
}
}
function AddModerator(address _newModerator) onlyOwner public {
if (moderators[_newModerator] == false) {
moderators[_newModerator] = true;
totalModerators += 1;
}
}
function RemoveModerator(address _oldModerator) onlyOwner public {
if (moderators[_oldModerator] == true) {
moderators[_oldModerator] = false;
totalModerators -= 1;
}
}
function UpdateMaintaining(bool _isMaintaining) onlyOwner public {
isMaintaining = _isMaintaining;
}
}
contract EtheremonEnum {
enum ResultCode {
SUCCESS,
ERROR_CLASS_NOT_FOUND,
ERROR_LOW_BALANCE,
ERROR_SEND_FAIL,
ERROR_NOT_TRAINER,
ERROR_NOT_ENOUGH_MONEY,
ERROR_INVALID_AMOUNT
}
enum ArrayType {
CLASS_TYPE,
STAT_STEP,
STAT_START,
STAT_BASE,
OBJ_SKILL
}
}
contract EtheremonTransformData is EtheremonEnum, BasicAccessControl, SafeMath {
struct MonsterEgg {
uint64 eggId;
uint64 objId;
uint32 classId;
address trainer;
uint hatchTime;
uint64 newObjId;
}
uint64 public totalEgg = 0;
mapping(uint64 => MonsterEgg) public eggs; // eggId
mapping(address => uint64) public hatchingEggs;
mapping(uint64 => uint64[]) public eggList; // objId -> [eggId]
mapping(uint64 => uint64) public transformed; //objId -> newObjId
// only moderators
/*
TO AVOID ANY BUGS, WE ALLOW MODERATORS TO HAVE PERMISSION TO ALL THESE FUNCTIONS AND UPDATE THEM IN EARLY BETA STAGE.
AFTER THE SYSTEM IS STABLE, WE WILL REMOVE OWNER OF THIS SMART CONTRACT AND ONLY KEEP ONE MODERATOR WHICH IS ETHEREMON BATTLE CONTRACT.
HENCE, THE DECENTRALIZED ATTRIBUTION IS GUARANTEED.
*/
function addEgg(uint64 _objId, uint32 _classId, address _trainer, uint _hatchTime) onlyModerators external returns(uint64) {
totalEgg += 1;
MonsterEgg storage egg = eggs[totalEgg];
egg.objId = _objId;
egg.eggId = totalEgg;
egg.classId = _classId;
egg.trainer = _trainer;
egg.hatchTime = _hatchTime;
egg.newObjId = 0;
hatchingEggs[_trainer] = totalEgg;
// increase count
if (_objId > 0) {
eggList[_objId].push(totalEgg);
}
return totalEgg;
}
function setHatchedEgg(uint64 _eggId, uint64 _newObjId) onlyModerators external {
MonsterEgg storage egg = eggs[_eggId];
if (egg.eggId != _eggId)
revert();
egg.newObjId = _newObjId;
hatchingEggs[egg.trainer] = 0;
}
function setHatchTime(uint64 _eggId, uint _hatchTime) onlyModerators external {
MonsterEgg storage egg = eggs[_eggId];
if (egg.eggId != _eggId)
revert();
egg.hatchTime = _hatchTime;
}
function setTranformed(uint64 _objId, uint64 _newObjId) onlyModerators external {
transformed[_objId] = _newObjId;
}
function getHatchingEggId(address _trainer) constant external returns(uint64) {
return hatchingEggs[_trainer];
}
function getEggDataById(uint64 _eggId) constant external returns(uint64, uint64, uint32, address, uint, uint64) {
MonsterEgg memory egg = eggs[_eggId];
return (egg.eggId, egg.objId, egg.classId, egg.trainer, egg.hatchTime, egg.newObjId);
}
function getHatchingEggData(address _trainer) constant external returns(uint64, uint64, uint32, address, uint, uint64) {
MonsterEgg memory egg = eggs[hatchingEggs[_trainer]];
return (egg.eggId, egg.objId, egg.classId, egg.trainer, egg.hatchTime, egg.newObjId);
}
function getTranformedId(uint64 _objId) constant external returns(uint64) {
return transformed[_objId];
}
function countEgg(uint64 _objId) constant external returns(uint) {
return eggList[_objId].length;
}
function getEggIdByObjId(uint64 _objId, uint _index) constant external returns(uint64, uint64, uint32, address, uint, uint64) {
MonsterEgg memory egg = eggs[eggList[_objId][_index]];
return (egg.eggId, egg.objId, egg.classId, egg.trainer, egg.hatchTime, egg.newObjId);
}
}