-
Notifications
You must be signed in to change notification settings - Fork 1
/
rps-game-bot.lua
155 lines (139 loc) · 3.5 KB
/
rps-game-bot.lua
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
153
154
155
-- Bot Variables
BotName = "RockPaperScissorsBot"
local stepNumber = 1
local stopNumber = 9
local runStatus = 'disable'
local currentNumber = 0
local GameTarget = 'io9gWQrlmyMeF3HS20GgbMkxokjJKAIeZMGa8180efw'
local function sendChoice()
local choices = { "Rock", "Paper", "Scissor" }
local choice = choices[math.random(1, #choices)]
log("Sending choice: " .. choice)
ao.send({
Target = GameTarget,
Action = "UserChoice",
Data = choice
})
end
local function finishGame()
ao.send({
Target = GameTarget,
Action = "FinishPoints",
Data = BotName
})
currentNumber = 0
end
local function log(message)
print("[Bot Log] " .. message)
end
local function handleResult(Msg)
currentNumber = currentNumber + 1
log('Round Result: ' .. Msg.Data)
if (currentNumber >= stepNumber) then
stepNumber = stepNumber + 1
finishGame()
else
sendChoice()
end
end
local function handleFinish(Msg)
log(Msg.Data)
if stopNumber < stepNumber then
stopPlaying()
return
end
sendChoice()
end
function startPlaying()
runStatus = 'enable'
stepNumber = 1
currentNumber = 0
log('Bot started playing')
sendChoice()
end
function stopPlaying()
runStatus = 'disable'
log('The bot has finished running')
end
-- User Choice Result Handler
Handlers.add(
"HandlerUserChoiceResult",
Handlers.utils.hasMatchingTag("Action", "UserChoiceResult"),
function(Msg)
if runStatus == 'disable' then
log("HandlerUserChoiceResult ignored: Bot is disabled")
return
end
log("HandlerUserChoiceResult called with Data: " .. Msg.Data)
handleResult(Msg)
end
)
-- Finish Points Result Handler
Handlers.add(
"HandlerFinishPointsResult",
Handlers.utils.hasMatchingTag("Action", "FinishPointsResult"),
function(Msg)
if runStatus == 'disable' then
log("HandlerFinishPointsResult ignored: Bot is disabled")
return
end
log("HandlerFinishPointsResult called with Data: " .. Msg.Data)
handleFinish(Msg)
end
)
-- Current Points Handler
Handlers.add(
"HandlerCurrentPoints",
Handlers.utils.hasMatchingTag("Action", "CurrentPoints"),
function(Msg)
log("Current Points: " .. Msg.Data)
end
)
-- Rank List Handler
Handlers.add(
"HandlerRankList",
Handlers.utils.hasMatchingTag("Action", "RankList"),
function(Msg)
log("Rank List: " .. Msg.Data)
end
)
-- Your Turn Handler for Bot
Handlers.add(
"HandlerYourTurn",
Handlers.utils.hasMatchingTag("Action", "YourTurn"),
function(Msg)
if runStatus == 'enable' then
log("Bot's turn to play.")
sendChoice()
end
end
)
Handlers.add(
"HandlerJoinGameResult",
Handlers.utils.hasMatchingTag("Action", "JoinGameResult"),
function(Msg)
log("HandlerJoinGameResult called")
log(Msg.Data) -- Gelen veriyi logla
enableBot() -- Botu etkinleştir
end
)
Handlers.add(
"HandlerUserChoice",
Handlers.utils.hasMatchingTag("Action", "UserChoice"),
function(Msg)
log("HandlerUserChoice called")
-- Kalan işlev kodları
end
)
-- Bu işlev botun durumunu etkinleştirir
function enableBot()
runStatus = 'enable'
log("Bot is enabled.")
end
Handlers.add(
"HandlerGetMembers",
Handlers.utils.hasMatchingTag("Action", "MembersList"),
function(Msg)
log("Members List: " .. Msg.Data)
end
)