-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.lua
More file actions
152 lines (119 loc) · 2.93 KB
/
Copy pathGame.lua
File metadata and controls
152 lines (119 loc) · 2.93 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- 引入 json 和 token 模块
local json = require('json')
local token = require('token')
-- 从 token.lua 获取代币实例
local bullCoin = token.BullCoin
local daiCoin = token.DaiCoin
-- 将用户传入的dai换为游戏币bullCoin
function Swap_dai_To_bullCoin(user,daiAmountin)
if token.swapDaiForBullCoin(user, daiAmountin) then
return true
end
return false
end
-- 用户提现
function Withdraw(user)
if token.withdrawBullCoin(user) then
return true
end
return false
end
-- 初始化随机数种子
math.randomseed(os.time())
-- 定义一个函数,生成 1 到 9 的随机整数列表
function Generate_random_numbers()
local numbers = {}
for i = 1, 9 do
numbers[i] = math.random(1, 9)
end
return numbers
end
-- 定义转账函数,模拟向调用者转账
function Transfer_funds(recipient, amount)
-- 使用 token.lua 中的转账函数
if token.TransferBullCoin(ao.id, recipient, amount) then
return true
end
return false
end
-- 定义成功率函数
function Random_percentage()
return math.random(100)
end
-- 定义 6 个不同成功率的函数
-- 成功率 50%
function Function1(recipient)
if Random_percentage() <= 50 then
Transfer_funds(recipient, 1)
return true
end
return false
end
-- 成功率 25%
function Function2(recipient)
if Random_percentage() <= 25 then
Transfer_funds(recipient, 2)
return true
end
return false
end
-- 成功率 14%
function Function3(recipient)
if Random_percentage() <= 14 then
Transfer_funds(recipient, 3)
return true
end
return false
end
-- 成功率 11%
function Function4(recipient)
if Random_percentage() <= 11 then
Transfer_funds(recipient, 4)
return true
end
return false
end
-- 成功率 8%
function Function5(recipient)
if Random_percentage() <= 8 then
Transfer_funds(recipient, 5)
return true
end
return false
end
-- 成功率 1%
function Function6(recipient)
if Random_percentage() <= 1 then
Transfer_funds(recipient, 6)
return true
end
return false
end
-- 提供调用接口
function Get_random_numbers()
return Generate_random_numbers()
end
function Get_bull_1(recipient)
return Function1(recipient)
end
function Get_bull_2(recipient)
return Function2(recipient)
end
function Get_bull_3(recipient)
return Function3(recipient)
end
function Get_bull_4(recipient)
return Function4(recipient)
end
function Get_bull_5(recipient)
return Function5(recipient)
end
function Get_bull_6(recipient)
return Function6(recipient)
end
function Swap(user,daiAmountin)
return Swap_dai_To_bullCoin(user,daiAmountin)
end
function Withdraw(user)
return Withdraw(user)
end