comments, events

master
lza_menace 2 years ago
parent 0734b527c7
commit 16eb64dc9d

@ -49,17 +49,30 @@ pragma solidity ^0.8.13;
// x x xxxxx xxxx
// x x x.xxx x x
// This contract is the main logic interface for the Unaboomer NFT project.
import {Owned} from "solmate/auth/Owned.sol";
import {Unaboomer} from "./Unaboomer.sol";
import {Mailbomb} from "./Mailbomb.sol";
contract Main is Owned {
/// Price of the Unaboomer ERC-721 token
uint256 public unaboomerPrice = 0.01 ether;
/// Price of the Mailbomb ERC-1155 token
uint256 public bombPrice = 0.01 ether;
/// Unaboomer contract
Unaboomer public unaboomer;
/// Mailbomb contract
Mailbomb public mailbomb;
/// SendBomb 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)
event SentBomb(address indexed from, uint256 indexed tokenId, bool hit);
constructor() Owned(msg.sender) {}
// =========================================================================
@ -72,22 +85,26 @@ contract Main is Owned {
payable(msg.sender).transfer(balance);
}
/// Set price for 1 BOMB
function setBombPrice(uint256 _price) external onlyOwner {
bombPrice = _price;
}
/// Set price for 1 BOOMR
/// @param _price Price in wei to mint BOOMR token
function setBoomerPrice(uint256 _price) external onlyOwner {
unaboomerPrice = _price;
}
/// Set price for 1 BOMB
/// @param _price Price in wei to mint BOMB token
function setBombPrice(uint256 _price) external onlyOwner {
bombPrice = _price;
}
/// Set contract address for Unaboomer tokens
/// @param _address Address of the Unaboomer / BOOMR contract
function setUnaboomerContract(address _address) external onlyOwner {
unaboomer = Unaboomer(_address);
}
/// Set contract address for Mailbomb tokens
/// @param _address Address of the Mailbomb / BOMB contract
function setMailbombContract(address _address) external onlyOwner {
mailbomb = Mailbomb(_address);
}
@ -96,6 +113,8 @@ contract Main is Owned {
// Modifiers
// =========================================================================
/// This modifier prevents actions once the Unaboomer survivor count is breached.
/// The game stops.
modifier missionNotCompleted {
require(
unaboomer.killCount() <= (unaboomer.MAX_SUPPLY() - unaboomer.SURVIVOR_COUNT()),
@ -109,6 +128,7 @@ contract Main is Owned {
// =========================================================================
/// Get BOOMR token balance of wallet
/// @param _address Wallet address to query balance of BOOMR token
function unaboomerBalance(address _address) public view returns (uint256) {
return unaboomer.balanceOf(_address);
}
@ -134,6 +154,7 @@ contract Main is Owned {
}
/// Get BOMB token balance of wallet
/// @param _address Wallet address to query balance of BOMB token
function bombBalance(address _address) public view returns (uint256) {
return mailbomb.balanceOf(_address, 1);
}
@ -153,6 +174,7 @@ contract Main is Owned {
// =========================================================================
/// Radicalize a boomer to become a Unaboomer - start with 2 bombs
/// @param _amount Amount of Unaboomers to radicalize (mint)
function radicalizeBoomers(uint256 _amount) external payable missionNotCompleted {
require(msg.value >= _amount * unaboomerPrice, "not enough ether");
unaboomer.radicalize(msg.sender, _amount);
@ -160,6 +182,7 @@ contract Main is Owned {
}
/// Assemble additional mailbombs to kill targets
/// @param _amount Amount of bombs to assemble (mint)
function assembleBombs(uint256 _amount) external payable missionNotCompleted {
require(msg.value >= _amount * bombPrice, "not enough ether");
mailbomb.create(msg.sender, _amount);
@ -169,23 +192,17 @@ contract Main is Owned {
/// If the Unaboomer is already dead, the bomb is considered a dud.
/// @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
function sendBombs(uint256 _amount) external missionNotCompleted returns (
bool[] memory results,
uint256[] memory tokensKilled
) {
/// @param _amount Amount of bombs to send to kill Unaboomers
function sendBombs(uint256 _amount) external missionNotCompleted {
require(_amount <= bombBalance(msg.sender), "not enough bombs");
require(_amount <= unaboomer.totalSupply(), "not enough supply");
bool[] memory res = new bool[](_amount);
uint256[] memory killed = new uint256[](_amount);
uint256 supply = unaboomer.totalSupply();
for (uint256 i; i < _amount; i++) {
uint256 randomBoomer = uint256(keccak256(abi.encodePacked(i, block.timestamp, msg.sender))) % supply;
bool dud = unaboomer.tokenDead(randomBoomer);
unaboomer.die(randomBoomer);
res[i] = dud;
killed[i] = randomBoomer;
emit SentBomb(msg.sender, randomBoomer, !dud);
}
mailbomb.explode(msg.sender, _amount);
return (res, killed);
}
}
Loading…
Cancel
Save