| 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity ^0.8.20; |
| 3 | |
| 4 | import "@openzeppelin/contracts/access/Ownable.sol"; |
| 5 | import "./CosmicCowboy.sol"; |
| 6 | import "./ERC6551Account.sol"; |
| 7 | import "./ERC6551Registry.sol"; |
| 8 | import "./GoldenCorn.sol"; |
| 9 | import "./SpaceSlop.sol"; |
| 10 | import "./JupiterJunk.sol"; |
| 11 | |
| 12 | contract Operator is Ownable { |
| 13 | CosmicCowboys public cosmicCowboys; |
| 14 | GoldenCorn public goldenCorn; |
| 15 | SpaceSlop public spaceSlop; |
| 16 | JupiterJunk public jupiterJunk; |
| 17 | |
| 18 | uint256 public newTokenId; |
| 19 | uint256 public constant donationAmount = 10 ** 15; |
| 20 | |
| 21 | constructor( |
| 22 | address initialOwner, |
| 23 | address _cosmicCowboys, |
| 24 | address _goldenCorn, |
| 25 | address _spaceSlop, |
| 26 | address _jupiterJunk |
| 27 | ) Ownable(initialOwner) { |
| 28 | cosmicCowboys = CosmicCowboys(_cosmicCowboys); |
| 29 | goldenCorn = GoldenCorn(_goldenCorn); |
| 30 | spaceSlop = SpaceSlop(_spaceSlop); |
| 31 | jupiterJunk = JupiterJunk(_jupiterJunk); |
| 32 | } |
| 33 | |
| 34 | function createNPC(address to, string memory uri) public { |
| 35 | cosmicCowboys.safeMint(to, uri); |
| 36 | } |
| 37 | |
| 38 | function getLatestTokenId() external view returns (uint256) { |
| 39 | return cosmicCowboys.latestTokenId(); |
| 40 | } |
| 41 | |
| 42 | function fundNPC(address to, uint256 amount) public { |
| 43 | goldenCorn.mint(to, amount); |
| 44 | } |
| 45 | |
| 46 | function feedNPC(address to, uint256 amount) public { |
| 47 | spaceSlop.mint(to, amount); |
| 48 | } |
| 49 | |
| 50 | function supplyNPC(address to, uint256 amount) public { |
| 51 | jupiterJunk.mint(to, amount); |
| 52 | } |
| 53 | |
| 54 | function getNPCStats( |
| 55 | uint256 tokenId |
| 56 | ) external view returns (uint8, string memory) { |
| 57 | uint8 health = cosmicCowboys.getHealth(tokenId); |
| 58 | string memory location = cosmicCowboys.getCurrentLocation(tokenId); |
| 59 | return (health, location); |
| 60 | } |
| 61 | |
| 62 | function launchSupplyMission(uint256 tokenId) public { |
| 63 | uint8 newHealth = cosmicCowboys.getHealth(tokenId) - 2; |
| 64 | cosmicCowboys.setHealth(tokenId, newHealth); |
| 65 | } |
| 66 | |
| 67 | function goToBar(uint256 tokenId) public { |
| 68 | cosmicCowboys.goToBar(tokenId); |
| 69 | } |
| 70 | |
| 71 | function goToSupplyDepot(uint256 tokenId) public { |
| 72 | cosmicCowboys.goToSupplyDepot(tokenId); |
| 73 | } |
| 74 | |
| 75 | function goToHome(uint256 tokenId) public { |
| 76 | //require(cosmicCowboys.ownerOf(tokenId) == tba, "Not owner"); // Check OwnershipTransferred |
| 77 | cosmicCowboys.goToHome(tokenId); |
| 78 | uint8 newHealth = cosmicCowboys.getHealth(tokenId) + 2; |
| 79 | cosmicCowboys.setHealth(tokenId, newHealth); |
| 80 | } |
| 81 | |
| 82 | function donate(address tba) external payable { |
| 83 | require( |
| 84 | msg.value == donationAmount, |
| 85 | "Donation amount must be exactly 0.001 Ether" |
| 86 | ); |
| 87 | |
| 88 | goldenCorn.mint(tba, 5); |
| 89 | } |
| 90 | } |