master
lza_menace 2 years ago
parent 7e83d0eab6
commit 5245d413e5

@ -21,6 +21,8 @@ contract Unaboomer is ERC721, Owned {
mapping(uint256 => bool) public tokenDead; mapping(uint256 => bool) public tokenDead;
uint256 public constant MAX_SUPPLY = 10000; uint256 public constant MAX_SUPPLY = 10000;
uint256 public constant SURVIVOR_COUNT = 1000;
uint256 public killCount;
uint256 public minted; uint256 public minted;
string public aliveURI; string public aliveURI;
string public deadURI; string public deadURI;
@ -73,8 +75,11 @@ contract Unaboomer is ERC721, Owned {
function kill(uint256 tokenId) external { function kill(uint256 tokenId) external {
require(msg.sender == address(main), "invalid minter"); require(msg.sender == address(main), "invalid minter");
require(tokenId < minted, "invalid token id"); require(tokenId < minted, "invalid token id");
if (tokenDead[tokenId] == false) {
killCount++;
tokenDead[tokenId] = true; tokenDead[tokenId] = true;
} }
}
function totalSupply() public view returns (uint256 supply) { function totalSupply() public view returns (uint256 supply) {
return minted; return minted;

@ -56,12 +56,21 @@ contract UnaboomerCommon is Owned {
mailbomb = Mailbomb(_address); mailbomb = Mailbomb(_address);
} }
// =========================================================================
// Modifiers
// =========================================================================
modifier missionCompleted {
require(unaboomer.killCount() <= unaboomer.SURVIVOR_COUNT(), "mission already completed");
_;
}
// ========================================================================= // =========================================================================
// Tokens // Tokens
// ========================================================================= // =========================================================================
/// Radicalize a boomer to become a Unaboomer /// Radicalize a boomer to become a Unaboomer
function radicalizeBoomer(uint256 _amount) external payable { function radicalizeBoomers(uint256 _amount) external payable missionCompleted {
// check if game halted // check if game halted
require(msg.value >= _amount * boomerPrice, "not enough ether"); require(msg.value >= _amount * boomerPrice, "not enough ether");
unaboomer.mint(msg.sender, _amount); unaboomer.mint(msg.sender, _amount);
@ -69,25 +78,17 @@ contract UnaboomerCommon is Owned {
} }
/// Assemble additional mailbombs to kill targets /// Assemble additional mailbombs to kill targets
function assembleBomb(uint256 _amount) external payable { function assembleBombs(uint256 _amount) external payable missionCompleted {
// check if game halted // check if game halted
require(msg.value >= _amount * bombPrice, "not enough ether"); require(msg.value >= _amount * bombPrice, "not enough ether");
mailbomb.mint(msg.sender, _amount); mailbomb.mint(msg.sender, _amount);
} }
/// Kill random targets with mail bombs
/// @dev Function returns a boolean depending on if Boomer was already killed or not - i.e. if dud
/// @dev The likelihood of killing a boomer decreases as time goes on - i.e. more duds
function killBoomer(uint256 tokenId) private returns (bool isDud) {
bool dud = unaboomer.tokenDead(tokenId);
unaboomer.kill(tokenId);
return dud;
}
/// Send N bombs to pseudo-random Unaboomer tokenIds to potentially kill them. /// Send N bombs to pseudo-random Unaboomer tokenIds to potentially kill them.
/// If the Unaboomer is already dead, the bomb is a dud. /// If the Unaboomer is already dead, the bomb is a dud.
/// @dev Pick a pseudo-random tokenID from Unaboomer contract and toggle a mapping value /// @dev Pick a pseudo-random tokenID from Unaboomer contract and toggle a mapping value
function sendBombs(uint256[] calldata tokenIds) external returns (bool[] memory results) { /// @dev The likelihood of killing a boomer decreases as time goes on - i.e. more duds
function sendBombs(uint256[] calldata tokenIds) external missionCompleted returns (bool[] memory results) {
require(tokenIds.length <= mailbomb.balanceOf(msg.sender)); require(tokenIds.length <= mailbomb.balanceOf(msg.sender));
bool[] memory res = new bool[](tokenIds.length); bool[] memory res = new bool[](tokenIds.length);
uint256 boomerSupply = unaboomer.totalSupply(); uint256 boomerSupply = unaboomer.totalSupply();
@ -95,8 +96,9 @@ contract UnaboomerCommon is Owned {
require(mailbomb.ownerOf(tokenIds[i]) == msg.sender, "token not owned"); require(mailbomb.ownerOf(tokenIds[i]) == msg.sender, "token not owned");
uint256 randomBoomer = uint256(keccak256(abi.encodePacked(tokenIds[i], block.timestamp, msg.sender))) % boomerSupply; uint256 randomBoomer = uint256(keccak256(abi.encodePacked(tokenIds[i], block.timestamp, msg.sender))) % boomerSupply;
mailbomb.burn(tokenIds[i]); mailbomb.burn(tokenIds[i]);
bool _res = killBoomer(randomBoomer); bool dud = unaboomer.tokenDead(randomBoomer);
res[i] = _res; unaboomer.kill(randomBoomer);
res[i] = dud;
} }
return res; return res;
} }

@ -29,7 +29,7 @@ contract UnaboomerTest is Test {
function testMint() public { function testMint() public {
hoax(address(1)); hoax(address(1));
main.radicalizeBoomer{value: 0.05 ether}(5); main.radicalizeBoomers{value: 0.05 ether}(5);
assertEq(boomr.totalSupply(), 5); assertEq(boomr.totalSupply(), 5);
assertEq(boomr.tokenDead(1), false); assertEq(boomr.tokenDead(1), false);
} }

Loading…
Cancel
Save