-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpbx_evenchur.lua
166 lines (149 loc) · 3.47 KB
/
pbx_evenchur.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
162
163
164
165
local evenchur = require('evenchur')
local espeak = require('espeak')
for k, _ in pairs(evenchur.colors) do
evenchur.colors[k] = ""
end
evenchur.state.debug = false
local function go_north() return "go north" end
local function go_west() return "go west" end
local function go_east() return "go east" end
local function go_south() return "go south" end
local function choose_inv(...)
local invs = {...}
local things = {}
for i, inv in ipairs(invs) do
for k, v in pairs(inv) do
table.insert(things, k)
end
end
if #things == 0 then
espeak("there's nothing you can do that to")
return
end
for i, k in ipairs(things) do
espeak("dial " .. tostring(i) .. " for " .. tostring(k))
end
app.read("inv", "" , 1)
local num = tonumber(channel.inv:get())
return things[num]
end
local function take()
local thing = choose_inv(evenchur.state.get_room():get_inv())
if thing ~= nil then
return "take " .. thing
end
end
local function put()
local thing = choose_inv(evenchur.state.inv)
if thing ~= nil then
return "put " .. thing
end
end
local function look()
local thing = choose_inv(evenchur.state.get_room():get_inv(), evenchur.state.inv)
if thing ~= nil then
return "look " .. thing
end
end
local function use()
local thing = choose_inv(evenchur.state.inv)
if thing ~= nil then
return "use " .. thing
end
end
local bad_menu_func = {
["1"] = take,
["2"] = use,
["3"] = look,
["4"] = put,
}
local bad_menu_say = {
take = 1,
use = 2,
look = 3,
put = 4,
}
local function bad_menu()
for k, v in pairs(bad_menu_say) do
espeak("To " .. k .. "............... dial " .. tostring(v))
end
app.read("bad", "", 1)
local num =channel.bad:get()
local f = bad_menu_func[num]
if f == nil then
espeak("bad menu number")
return
end
return f()
end
local function good_help()
espeak("To move, use 2, 4, 6, or 8 to go north, west, east, or south, respectively.")
espeak("To take or put, use 1 or 3, respectively.")
espeak("To use, dial 5; to look, dial 7.")
end
local bad_moves = {north = 1, west = 2, east = 3, south = 4}
local function bad_help()
for k, v in pairs(bad_moves) do
espeak("To go " .. k .. ", dial " .. tostring(v))
end
espeak("For the mmenu with all the other options, dial 6")
end
local commands = {
good = {
["0"] = good_help,
["1"] = take,
["2"] = go_north,
["3"] = put,
["4"] = go_west,
["5"] = use,
["6"] = go_east,
["7"] = look,
["8"] = go_south,
},
bad = {
["0"] = bad_help,
["1"] = go_north,
["2"] = go_west,
["3"] = go_east,
["4"] = go_south,
["6"] = bad_menu,
},
}
function run_game_with(cmds)
espeak("Welcome to COSI evenchur. Dial 0 for help.")
channel.TIMEOUT('response'):set(30)
while evenchur.state.finished == nil do
espeak(evenchur.print_status())
app.read("num", "", 1)
local num = channel.num:get()
if num == "" or num == nil then
app.hangup()
return -- hung up
end
local func = cmds[num]
if func ~= nil then
local cmd = func()
if cmd then
espeak(evenchur.exec(cmd))
local res = evenchur.game.post_tick()
if res then
espeak(res)
end
end
else
espeak("That number is not valid. Dial 0 for help.")
end
end
if type(evenchur.state.finished) == "string" then
espeak(evenchur.state.finished)
end
espeak("The game is over. Goodbye.")
app.hangup()
end
return function(ctx, misc)
misc.help.adventure = function()
espeak('dial 600 or 601')
end
ctx['600'] = function() run_game_with(commands.good) end
ctx['601'] = function() run_game_with(commands.bad) end
end