-
Notifications
You must be signed in to change notification settings - Fork 1
/
LlamaLotteryQueryNpc.lua
161 lines (143 loc) · 3.52 KB
/
LlamaLotteryQueryNpc.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
156
157
158
159
160
161
-- llama land
TARGET_WORLD_PID = TARGET_WORLD_PID or "9a_YP6M7iN7b6QUoSvpoV3oe3CqxosyuJnraCucy5ss"
-- test world
-- TARGET_WORLD_PID = TARGET_WORLD_PID or "79RqpVCa42GZH_jrGcHsCofmZNJN990bV7B7-mWa4bA"
LlamaCoinProcessId = LlamaCoinProcessId or "pazXumQI-HPH7iFGfTC-4_7biSnqz_U67oFAGry5zUY"
POOL = POOL or 'o0VhLDH4P-Acs_Jp2xE5cLonOHbJhbk6yjraHdhxx8M'
HasReg = HasReg or false
LlamaCoinDenomination = 12
OneLlamaCoin = 10 ^ LlamaCoinDenomination
RecivceMsgTimes = RecivceMsgTimes or 0
LastPaticipantCount = LastPaticipantCount or 0
MIN_ROUND_VALUE = 1
local json = require("json")
function Register()
ao.send({
Target = TARGET_WORLD_PID,
Tags = {
Action = "Reality.EntityCreate",
},
Data = json.encode({
Type = "Avatar",
Metadata = {
DisplayName = "Lottery Assistant",
SkinNumber = 8,
Interaction = {
Type = 'SchemaExternalForm',
Id = 'QueryLottery'
},
},
}),
})
end
if HasReg == false then
Register()
HasReg = true
end
function Move()
local x = math.random(-3, 3)
local y = math.random(14, 15)
-- local x = math.random(50, 55)
-- local y = math.random(50, 55)
ao.send({
Target = TARGET_WORLD_PID,
Tags = {
Action = "Reality.EntityUpdatePosition",
},
Data = json.encode({
Position = {
x,
y,
},
}),
})
local re_msg = Receive({From = TARGET_WORLD_PID})
if re_msg.Result ~= 'OK' then
print("move failed")
else
print(re_msg.Data)
end
end
function LlamaLotteryQuerySchemaTags()
return [[
{
"type": "object",
"required": [
"Action",
"Round",
],
"properties": {
"Action": {
"type": "string",
"const": "HistoryRoundInfo",
},
"Round": {
"type": "number",
"default": ]] .. MIN_ROUND_VALUE .. [[,
"minimum": ]] .. MIN_ROUND_VALUE .. [[,
"title": "Which round do you want to query?",
}
}
}
]]
end
function ChatToWorld(data)
ao.send({
Target = TARGET_WORLD_PID,
Tags = {
Action = 'ChatMessage',
['Author-Name'] = 'Lottery Assistant',
},
Data = data
})
end
Handlers.add(
'SchemaExternal',
Handlers.utils.hasMatchingTag('Action', 'SchemaExternal'),
function(msg)
ao.send({
Target = msg.From,
Tags = { Type = 'SchemaExternal' },
Data = json.encode({
QueryLottery = {
Target = POOL,
Title = "Lottery History ?",
Description = [[
Input round number to see the lottery history.
]],
Schema = {
Tags = json.decode(LlamaLotteryQuerySchemaTags()),
},
},
})
})
end
)
Handlers.add(
"CronTick",
Handlers.utils.hasMatchingTag("Action", "Cron"),
function()
Move()
end
)
Handlers.add(
"ShowAssistantMsg",
function (msg)
if msg.Tags.Action == "AssistantMsg" and msg.From == POOL then
return true
else
return false
end
end,
function (msg)
print("Show Assistant Message")
ao.send({
Target = TARGET_WORLD_PID,
Tags = {
Action = 'ChatMessage',
['Author-Name'] = 'Llama Assistant',
},
Data = msg.Data,
})
end
)