Debian Codegraph @

data/storyline/act1/dialogs/Dude.lua

raw
1 ---------------------------------------------------------------------
2 -- This file is part of Freedroid
3 --
4 -- Freedroid is free software; you can redistribute it and/or modify
5 -- it under the terms of the GNU General Public License as published by
6 -- the Free Software Foundation; either version 2 of the License, or
7 -- (at your option) any later version.
8 --
9 -- Freedroid is distributed in the hope that it will be useful,
10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- GNU General Public License for more details.
13 --
14 -- You should have received a copy of the GNU General Public License
15 -- along with Freedroid; see the file COPYING. If not, write to the
16 -- Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17 -- MA 02111-1307 USA
18 ----------------------------------------------------------------------
19 --[[WIKI
20 PURPOSE = "$$NAME$$ is a character used for Debug purposes"
21 WIKI]]--
22
23 local Npc = FDrpg.get_npc()
24 local Tux = FDrpg.get_tux()
25
26 local function dude_dialog_name(filename)
27 return string.sub(filename, 1, -(string.len(".lua") + 1))
28 end
29
30 local function dude_create_node(dialogname)
31 return {
32 id = dialogname,
33 text = dialogname,
34 enabled = true,
35 code = function()
36 Tux:says("Starting " .. dialogname)
37 start_chat(dialogname)
38 end,
39 }
40 end
41
42 local function dude_choose_action(this_dialog)
43 local actionname = user_input_string("Please enter the dialog name of the desired NPC (Chandra, Bender...) " ..
44 "or other action to jump to (redguard, craft, upgrade, shop or exit). " ..
45 "If the input is invalid, the game will crash! To abort, enter " ..
46 "'continue' or press enter or escape.")
47 if (not (actionname == "continue" or actionname == "")) then
48 local actionnode = this_dialog:find_node(actionname)
49 if (actionnode and actionnode.code) then
50 actionnode:code(this_dialog)
51 end
52 end
53 end
54
55 return {
56 FirstTime = function()
57 level24obstacles()
58 get_town_score()
59 Dude_exit_node_count = 0
60 end,
61
62 EveryTime = function(this_node, this_dialog)
63 Npc:says("Hello.")
64 if (tux_has_joined_guard) then
65 Npc:says("Red Guard membership: [b]true[/b]")
66 else
67 Npc:says("Red Guard membership: [b]false[/b]")
68 end
69 Npc:says("Here you'll be able to access all dialogs that are available ingame.", "NO_WAIT")
70 Npc:says("Take care, this may be a little buggy.", "NO_WAIT")
71 Npc:says("Don't do this if you are just normally playing.", "NO_WAIT")
72 Npc:says("These dialogs can currently be accessed:", "NO_WAIT")
73 local node_list = ""
74 for idx,node in ipairs(this_dialog.nodes) do
75 if (node.id ~= "node0") then
76 node_list = node_list .. node.id .. ", "
77 end
78 end
79 Npc:says(string.sub(node_list, 1, -2))
80
81 dude_choose_action(this_dialog)
82 end,
83
84 {
85 id = "node0",
86 enabled = true,
87 text = "Show input field again.",
88 code = function(this_node, this_dialog)
89 dude_choose_action(this_dialog)
90 hide("node0")
91 show("node0") -- done on purpose
92 end,
93 },
94
95 {
96 id ="switchact",
97 enabled = true,
98 text = "Test Game Act switching",
99 code = function()
100 jump_to_game_act("act2")
101 Npc:says("Will switch to Act 2. Closing...")
102 end_dialog()
103 end,
104 },
105
106 {
107 id = "delayedevent1",
108 enabled = true,
109 text = "Test Delayed Events",
110 code = function()
111 dispatch_event("24 Test Delayed Event 2", 7)
112 dispatch_event("24 Test Delayed Event 1", 3)
113 end,
114 },
115
116 {
117 id = "l10n",
118 enabled = true,
119 text = "Test l10n",
120 code = function()
121 --; TRANSLATORS: Used to test l10n, so put here anything you want in your language
122 --; TRANSLATORS: (can also be used to test non ASCII characters).
123 Npc:says("Untranslated reply.")
124 end,
125 },
126
127 {
128 id = "redguard",
129 enabled = true,
130 text = "Become Red Guard",
131 code = function()
132 tux_has_joined_guard = true
133 Npc:says("You are now a member of the Red Guard.")
134 end,
135 },
136
137 {
138 id = "craft",
139 enabled = true,
140 text = "Craft addons",
141 code = function()
142 craft_addons()
143 end,
144 },
145
146 {
147 id = "upgrade",
148 enabled = true,
149 text = "Upgrade items",
150 code = function()
151 upgrade_items()
152 end,
153 },
154
155 {
156 id = "shop",
157 enabled = true,
158 text = "Shop",
159 code = function()
160 trade_with("Dude")
161 end,
162 },
163
164 {
165 id = "spam",
166 enabled = true,
167 text = "Spam",
168 code = function()
169 for spam_number=1,10000 do
170 Npc:says(spam_number, "NO_WAIT")
171 end
172 end,
173 },
174
175 {
176 generator = function()
177 local nodes = {}
178 local exclude = {
179 -- "subdialogs" can not be run solely
180 "614_sub.lua", "c-net-nethack_sub.lua",
181 -- dialog of terminals can not be run, currently, because they have no associated 'bot'
182 "Cryo-Terminal.lua", "c-net.lua", "DSB-MachineDeckControl.lua",
183 "DSB-PowerControlGate1.lua", "HF-FirmwareUpdateServer.lua",
184 "MO-HFGateAccessServer.lua", "MS-Factory-Addon-Terminal.lua",
185 "Maintenance-Terminal.lua", "MiniFactory-Terminal.lua",
186 "Terminal.lua", "TutorialTerminal.lua", "Vending-Machine.lua",
187 "DSB-PowerControl.lua" }
188
189 local dircontent = FDutils.system.scandir(FDdialog.dialogs_dirs, ".*%.lua", exclude)
190 if (dircontent) then
191 for none,filename in ipairs(dircontent) do
192 nodes[#nodes + 1] = dude_create_node(dude_dialog_name(filename))
193 end
194 end
195
196 return nodes
197 end
198 },
199
200 {
201 id = "exit",
202 enabled = true,
203 text = function()
204 return string.format( "Exit this dialog for the %sth time", Dude_exit_node_count + 1)
205 end,
206 code = function()
207 Npc:says("Closing...")
208 Dude_exit_node_count = Dude_exit_node_count + 1 -- do the computation of the var now
209 end_dialog()
210 end,
211 },
212 }