-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.7; | ||
|
||
import "./rarity.sol"; | ||
import "./Rarity.sol"; | ||
import "./RarityGold.sol"; | ||
import "./Ownable.sol"; | ||
|
||
contract AdventureParty is Ownable { | ||
rarity public Rarity = rarity(0xce761D788DF608BD21bdd59d6f4B54b2e27F25Bb); | ||
Rarity public rarity = Rarity(0xce761D788DF608BD21bdd59d6f4B54b2e27F25Bb); | ||
RarityGold public rarityGold = RarityGold(0x2069B76Afe6b734Fb65D1d099E7ec64ee9CC76B2); | ||
uint[] public adventurers; | ||
|
||
constructor(uint[] memory classes) { | ||
Rarity.setApprovalForAll(msg.sender, true); | ||
rarity.setApprovalForAll(msg.sender, true); | ||
for (uint i = 0; i < classes.length; i++) { | ||
adventurers.push(Rarity.next_summoner()); | ||
Rarity.summon(classes[i]); | ||
adventurers.push(rarity.next_summoner()); | ||
rarity.summon(classes[i]); | ||
} | ||
} | ||
|
||
function adventureAll() external { | ||
for (uint i = 0; i < adventurers.length; i++) { | ||
Rarity.adventure(adventurers[i]); | ||
rarity.adventure(adventurers[i]); | ||
} | ||
} | ||
|
||
function levelUpAll() external { | ||
for (uint i = 0; i < adventurers.length; i++) { | ||
Rarity.level_up(adventurers[i]); | ||
rarity.level_up(adventurers[i]); | ||
rarityGold.claim(adventurers[i]); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.7; | ||
|
||
interface IRarity { | ||
function level(uint) external view returns (uint); | ||
function getApproved(uint) external view returns (address); | ||
function ownerOf(uint) external view returns (address); | ||
} | ||
|
||
contract RarityGold { | ||
string public constant name = "Rarity Gold"; | ||
string public constant symbol = "gold"; | ||
uint8 public constant decimals = 18; | ||
|
||
uint public totalSupply = 0; | ||
|
||
IRarity constant rm = IRarity(0xce761D788DF608BD21bdd59d6f4B54b2e27F25Bb); | ||
|
||
mapping(uint => mapping (uint => uint)) public allowance; | ||
mapping(uint => uint) public balanceOf; | ||
|
||
mapping(uint => uint) public claimed; | ||
|
||
event Transfer(uint indexed from, uint indexed to, uint amount); | ||
event Approval(uint indexed from, uint indexed to, uint amount); | ||
|
||
function wealth_by_level(uint level) public pure returns (uint wealth) { | ||
for (uint i = 1; i < level; i++) { | ||
wealth += i * 1000e18; | ||
} | ||
} | ||
|
||
function _isApprovedOrOwner(uint _summoner) internal view returns (bool) { | ||
return rm.getApproved(_summoner) == msg.sender || rm.ownerOf(_summoner) == msg.sender; | ||
} | ||
|
||
|
||
function claimable(uint summoner) external view returns (uint amount) { | ||
require(_isApprovedOrOwner(summoner)); | ||
uint _current_level = rm.level(summoner); | ||
uint _claimed_for = claimed[summoner]+1; | ||
for (uint i = _claimed_for; i <= _current_level; i++) { | ||
amount += wealth_by_level(i); | ||
} | ||
} | ||
|
||
function claim(uint summoner) external { | ||
require(_isApprovedOrOwner(summoner)); | ||
uint _current_level = rm.level(summoner); | ||
uint _claimed_for = claimed[summoner]+1; | ||
for (uint i = _claimed_for; i <= _current_level; i++) { | ||
_mint(summoner, wealth_by_level(i)); | ||
} | ||
claimed[summoner] = _current_level; | ||
} | ||
|
||
function _mint(uint dst, uint amount) internal { | ||
totalSupply += amount; | ||
balanceOf[dst] += amount; | ||
emit Transfer(dst, dst, amount); | ||
} | ||
|
||
function approve(uint from, uint spender, uint amount) external returns (bool) { | ||
require(_isApprovedOrOwner(from)); | ||
allowance[from][spender] = amount; | ||
|
||
emit Approval(from, spender, amount); | ||
return true; | ||
} | ||
|
||
function transfer(uint from, uint to, uint amount) external returns (bool) { | ||
require(_isApprovedOrOwner(from)); | ||
_transferTokens(from, to, amount); | ||
return true; | ||
} | ||
|
||
function transferFrom(uint executor, uint from, uint to, uint amount) external returns (bool) { | ||
require(_isApprovedOrOwner(executor)); | ||
uint spender = executor; | ||
uint spenderAllowance = allowance[from][spender]; | ||
|
||
if (spender != from && spenderAllowance != type(uint).max) { | ||
uint newAllowance = spenderAllowance - amount; | ||
allowance[from][spender] = newAllowance; | ||
|
||
emit Approval(from, spender, newAllowance); | ||
} | ||
|
||
_transferTokens(from, to, amount); | ||
return true; | ||
} | ||
|
||
function _transferTokens(uint from, uint to, uint amount) internal { | ||
balanceOf[from] -= amount; | ||
balanceOf[to] += amount; | ||
|
||
emit Transfer(from, to, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters