| 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 | |
| 20 | constructor( |
| 21 | address initialOwner, |
| 22 | address _cosmicCowboys, |
| 23 | address _goldenCorn, |
| 24 | address _spaceSlop, |
| 25 | address _jupiterJunk |
| 26 | ) Ownable(initialOwner) { |
| 27 | cosmicCowboys = CosmicCowboys(_cosmicCowboys); |
| 28 | goldenCorn = GoldenCorn(_goldenCorn); |
| 29 | spaceSlop = SpaceSlop(_spaceSlop); |
| 30 | jupiterJunk = JupiterJunk(_jupiterJunk); |
| 31 | } |
| 32 | |
| 33 | function createNPC(address to, string memory uri) public { |
| 34 | cosmicCowboys.safeMint(to, uri); |
| 35 | } |
| 36 | |
| 37 | function getLatestTokenId() external view returns (uint256) { |
| 38 | return cosmicCowboys.latestTokenId(); |
| 39 | } |
| 40 | |
| 41 | function fundNPC(address to, uint256 amount) public { |
| 42 | goldenCorn.mint(to, amount); |
| 43 | } |
| 44 | |
| 45 | function feedNPC(address to, uint256 amount) public { |
| 46 | spaceSlop.mint(to, amount); |
| 47 | } |
| 48 | |
| 49 | function supplyNPC(address to, uint256 amount) public { |
| 50 | jupiterJunk.mint(to, amount); |
| 51 | } |
| 52 | |
| 53 | function getNPCStats( |
| 54 | uint256 tokenId |
| 55 | ) external view returns (uint8, string memory) { |
| 56 | uint8 health = cosmicCowboys.getHealth(tokenId); |
| 57 | string memory location = cosmicCowboys.getCurrentLocation(tokenId); |
| 58 | return (health, location); |
| 59 | } |
| 60 | |
| 61 | function launchSupplyMission(uint256 tokenId) public { |
| 62 | uint8 newHealth = cosmicCowboys.getHealth(tokenId) - 2; |
| 63 | cosmicCowboys.setHealth(tokenId, newHealth); |
| 64 | } |
| 65 | |
| 66 | function goToBar(uint256 tokenId) public { |
| 67 | cosmicCowboys.goToBar(tokenId); |
| 68 | } |
| 69 | |
| 70 | function goToSupplyDepot(uint256 tokenId) public { |
| 71 | cosmicCowboys.goToSupplyDepot(tokenId); |
| 72 | } |
| 73 | |
| 74 | function goToHome(uint256 tokenId) public { |
| 75 | //require(cosmicCowboys.ownerOf(tokenId) == tba, "Not owner"); // Check OwnershipTransferred |
| 76 | cosmicCowboys.goToHome(tokenId); |
| 77 | uint8 newHealth = cosmicCowboys.getHealth(tokenId) + 2; |
| 78 | cosmicCowboys.setHealth(tokenId, newHealth); |
| 79 | } |
| 80 | |
| 81 | function getOwner() external view returns (address) { |
| 82 | return owner(); |
| 83 | } |
| 84 | } |