setup leaderboard

master
lza_menace 1 year ago
parent 779788c006
commit 71403a41c7

@ -58,6 +58,12 @@ import {Mailbomb} from "./Mailbomb.sol";
contract Main is Owned {
/// Track the number of kills for each address
mapping(address => uint256) public killCount;
/// Index the number of kills to form a basic leaderboard
mapping(uint256 => address) public leaderboard;
/// Point to the latest leaderboard update
uint256 public leaderboardPointer;
/// Price of the Unaboomer ERC-721 token
uint256 public unaboomerPrice = 0.01 ether;
/// Price of the Mailbomb ERC-1155 token
@ -67,7 +73,7 @@ contract Main is Owned {
/// Mailbomb contract
Mailbomb public mailbomb;
/// SendBomb event is for recording the results of sendBombs
/// SentBomb event is for recording the results of sendBombs
/// @param from Sender of the bombs
/// @param tokenId Unaboomer token which was targeted
/// @param hit Whether or not the bomb killed the token or not (was a dud / already killed)
@ -118,7 +124,7 @@ contract Main is Owned {
/// The game stops.
modifier missionNotCompleted {
require(
unaboomer.killCount() <= (unaboomer.MAX_SUPPLY() - unaboomer.SURVIVOR_COUNT()),
unaboomer.totalKillCount() <= (unaboomer.MAX_SUPPLY() - unaboomer.SURVIVOR_COUNT()),
"mission already completed"
);
_;
@ -141,7 +147,7 @@ contract Main is Owned {
/// Get BOOMR kill count (unaboomers killed)
function unaboomersKilled() public view returns (uint256) {
return unaboomer.killCount();
return unaboomer.totalKillCount();
}
/// Get BOOMR token max supply
@ -191,6 +197,7 @@ contract Main is Owned {
/// Send N bombs to pseudo-random Unaboomer tokenIds to kill them.
/// If the Unaboomer is already dead, the bomb is considered a dud.
/// Update a leaderboard with updated kill counts.
/// @dev Pick a pseudo-random tokenID from Unaboomer contract and toggle a mapping value
/// @dev The likelihood of killing a boomer decreases as time goes on - i.e. more duds
/// @param _amount Amount of bombs to send to kill Unaboomers
@ -204,6 +211,17 @@ contract Main is Owned {
unaboomer.die(randomBoomer);
bool senderOwned = msg.sender == unaboomer.ownerOf(randomBoomer);
emit SentBomb(msg.sender, randomBoomer, !dud, senderOwned);
if(!dud && !senderOwned) {
killCount[msg.sender]++;
}
}
uint256 kills = killCount[msg.sender];
address leader = leaderboard[leaderboardPointer];
if (kills > killCount[leader]) {
if (leader != msg.sender) {
leaderboardPointer++;
leaderboard[leaderboardPointer] = msg.sender;
}
}
mailbomb.explode(msg.sender, _amount);
}

@ -13,7 +13,7 @@ contract Unaboomer is ERC721A, Owned {
uint256 public constant MAX_SUPPLY = 10000;
uint256 public constant SURVIVOR_COUNT = 1000;
uint256 public killCount;
uint256 public totalKillCount;
uint256 public minted;
string public aliveURI;
string public deadURI;
@ -70,7 +70,7 @@ contract Unaboomer is ERC721A, Owned {
function die(uint256 tokenId) external onlyMain {
require(tokenId < totalSupply(), "invalid token id");
if (tokenDead[tokenId] == false) {
killCount++;
totalKillCount++;
tokenDead[tokenId] = true;
}
}

@ -47,8 +47,8 @@ contract UnaboomerTest is Test {
hoax(t1);
main.sendBombs(40);
assertEq(bomb.balanceOf(t1, 1), 20);
assertEq(boomr.killCount() > 0, true);
console.log(boomr.killCount());
assertEq(boomr.totalKillCount() > 0, true);
console.log(boomr.totalKillCount());
}
function testKilling() public {

Loading…
Cancel
Save