-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameCenter.sol
95 lines (82 loc) · 2.59 KB
/
gameCenter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
import "./gashaponContract.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract GameCenter is Ownable {
struct Item {
address machineAddrs;
uint256 timestamp;
uint256 blockNo;
string prize;
uint256 paid;
}
struct Gashapon {
address gashaAddress;
string gashaName;
}
// FIX VALUE (For simplicity)
string[5] ITEMS = ["gold", "silver", "blue", "red", "yellow"];
mapping(address => Item[]) public gashaReceive;
mapping(address => Gashapon[]) public gashaList;
event ShowItem(address player, string item);
// GETTER
function getAllGashaBalls(address gashaAddress)
public
view
returns (uint256)
{
GashaponContract gashaGen = GashaponContract(gashaAddress);
return gashaGen.getBallsLeft();
}
function getCurrentGashaPrice(address gashaAddress)
public
view
returns (uint256)
{
GashaponContract gashaGen = GashaponContract(gashaAddress);
return gashaGen.getCurrentPrice();
}
function getNumberOfEachGashaBall(address gashaAddress)
public
view
returns (uint256[5] memory)
{
GashaponContract gashaGen = GashaponContract(gashaAddress);
return gashaGen.getNumberOfEachBall();
}
function createGasha(
string memory _name,
uint256 _totalBalls,
uint256[5] memory _numberOfEachBall,
uint256 _initPrice,
uint256 _bidIncrement
) public returns (address) {
GashaponContract newGashapon = new GashaponContract(
_totalBalls,
_numberOfEachBall,
_initPrice,
_bidIncrement
);
gashaList[msg.sender].push(Gashapon(address(newGashapon), _name));
return address(newGashapon);
}
function playGasha(address gashaAddress) public payable {
GashaponContract gashaGen = GashaponContract(gashaAddress);
string memory itemName = ITEMS[gashaGen.playGasha(msg.value)];
gashaReceive[msg.sender].push(
Item(
address(gashaGen),
block.timestamp,
block.number,
itemName,
msg.value
)
);
emit ShowItem(msg.sender, itemName);
}
function withdrawMoney(address gashaAddress) public onlyOwner {
GashaponContract gashaGen = GashaponContract(gashaAddress);
uint256 amount = gashaGen.getWithdrawBalance();
payable(Ownable.owner()).transfer(amount);
}
}