-
Notifications
You must be signed in to change notification settings - Fork 1
/
FTMGame.sol
127 lines (107 loc) · 5.39 KB
/
FTMGame.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
import "../IAchievement.sol";
import "../AchievementModel.sol";
import "hardhat/console.sol";
/**
@title FTM Contract
@author Emanuele Ricci @StErMi
*/
contract FTMGame is Ownable {
IAchievement private _ac;
uint256 private mobAchievement;
uint256 private miniBossAchievement;
uint256 private bossAchievement;
string constant contractName = "The Fantom Dungeon";
constructor(address achievementContractAddress) {
_ac = IAchievement(achievementContractAddress);
}
/// @dev this function is only made for testing purpose
/// it's needed to send funds to the contract that need to whitelist achievements
/// and unlock them on behalf of summoners
function supplyFunds() public payable {}
function setupAchievementsMetadata() public {
AchievementModel.Metadata[] memory achievements = new AchievementModel.Metadata[](3);
achievements[0] = AchievementModel.Metadata({
id: 0, // ID here is not important, will be replaced by the AchievementContract
source: address(this), // source is not important, will be replaced by the AchievementContract
sourceName: contractName,
rarity: AchievementModel.Rarity.Common,
title: "Defeated first monster",
description: "You have been brave enough to defeat the first monster of 'The Fantom Dungeon'",
points: 5
});
achievements[1] = AchievementModel.Metadata({
id: 0, // ID here is not important, will be replaced by the AchievementContract
source: address(this), // source is not important, will be replaced by the AchievementContract
sourceName: contractName,
rarity: AchievementModel.Rarity.Uncommon,
title: "Defeated first miniboss",
description: "You have been brave enough to defeat the Eruptus, the mini boss of 'The Fantom Dungeon'",
points: 10
});
achievements[2] = AchievementModel.Metadata({
id: 0, // ID here is not important, will be replaced by the AchievementContract
source: address(this), // source is not important, will be replaced by the AchievementContract
sourceName: contractName,
rarity: AchievementModel.Rarity.Epic,
title: "Defeated final boss",
description: "You have been brave enough to defeat Iced Giant, the final boss of 'The Fantom Dungeon'",
points: 50
});
mobAchievement = _ac.registerAchievement(achievements[0]);
miniBossAchievement = _ac.registerAchievement(achievements[1]);
bossAchievement = _ac.registerAchievement(achievements[2]);
}
function setMobAchievement(uint256 metadataId) public onlyOwner {
mobAchievement = metadataId;
}
function setMiniBossAchievement(uint256 metadataId) public onlyOwner {
miniBossAchievement = metadataId;
}
function setBossAchievement(uint256 metadataId) public onlyOwner {
bossAchievement = metadataId;
}
function adventure() public {
// IMPORTANT
// In your contract don't revert if awardAchievement fail, it could be because user
// already own the achievement. Revert only when you are testing this integration
bool success;
string memory revertMessage;
(success, revertMessage) = _ac.awardAchievement(msg.sender, mobAchievement);
require(success, revertMessage);
(success, revertMessage) = _ac.awardAchievement(msg.sender, miniBossAchievement);
require(success, revertMessage);
(success, revertMessage) = _ac.awardAchievement(msg.sender, bossAchievement);
require(success, revertMessage);
}
function awardAchievementMob() public {
// IMPORTANT
// In your contract don't revert if awardAchievement fail, it could be because user
// already own the achievement. Revert only when you are testing this integration
(bool success, string memory revertMessage) = _ac.awardAchievement(msg.sender, mobAchievement);
require(success, revertMessage);
}
function awardAchievementMiniBoss() public {
// IMPORTANT
// In your contract don't revert if awardAchievement fail, it could be because user
// already own the achievement. Revert only when you are testing this integration
(bool success, string memory revertMessage) = _ac.awardAchievement(msg.sender, miniBossAchievement);
require(success, revertMessage);
}
function awardAchievementBoss() public {
// IMPORTANT
// In your contract don't revert if awardAchievement fail, it could be because user
// already own the achievement. Revert only when you are testing this integration
(bool success, string memory revertMessage) = _ac.awardAchievement(msg.sender, bossAchievement);
require(success, revertMessage);
}
function awardAchievementOnlyDev(address receiver, uint256 metadataId) public onlyOwner {
// IMPORTANT
// In your contract don't revert if awardAchievement fail, it could be because user
// already own the achievement. Revert only when you are testing this integration
(bool success, string memory revertMessage) = _ac.awardAchievement(receiver, metadataId);
require(success, revertMessage);
}
}