-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
290 lines (232 loc) · 7.7 KB
/
init.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
else
S = function(s) return s end
end
if not minetest.get_modpath("sys4_achievements") or not minetest.get_modpath("awards") then return end
sys4_quest = {}
function sys4_quest.getQuestIndex(questname)
for i=1, #sys4_quest.quests do
local quest = sys4_quest.quests[i][1]
if quest == questname then
return i
end
end
return nil
end
function sys4_quest.next_quest(playername, questname)
if questname ~= "" then
local quest = string.split(questname, ":")[2]
if quest and quest ~= nil and quest ~= "" and sys4_quest.hasDependencies(quest) then
local nextQuest = nil
for name,award in pairs(awards.def) do
local award_req = award.award_req
if award_req and award_req ~= nil and award_req == quest then
nextQuest = sys4_quest.getQuestIndex(name)
sys4_quest.current_quest[playername] = nextQuest
minetest.after(1, function() quests.start_quest(playername, "sys4_quest:"..name) end)
end
end
if nextQuest == nil then
return
end
end
end
end
function sys4_quest.hasDependencies(award_name)
for name, award in pairs(awards.def) do
local award_req = award.award_req
if award_req and award_req ~= nil and award_req == award_name then
return true
end
end
return false
end
-- Make Quests from sys4 achievements. Not included secret and original awards from awards mod except 'award_mesefind'
function sys4_quest.make_initial_quests()
local i = 1
local initialQuests = {}
for name, award in pairs(awards.def) do
if not award.secret
and (
string.split(name, "_")[1] ~= "award"
or (
sys4_achievements.awards ~= "sys4"
and name == "award_mesefind"
)
or (
sys4_achievements.awards == "sys4"
and (
name == "award_lumberjack"
or name == "award_youre_winner"
or name == "award_mine2"
or name == "award_marchand_de_sable"
)
)
)
then
table.insert(initialQuests, i, {
name,
award.title,
award.trigger.target,
award.description,
sys4_quest.hasDependencies(name)
})
i = i + 1
end
end
return initialQuests
end
function sys4_quest.isInSameGroup(node1, node2, quest)
local items = {}
local mod = ""
if node1 == 'default:tree'
and ( quest == "award_lumberjack"
or quest == "award_lumberjack_semipro"
or quest == "award_lumberjack_professional"
or quest == "award_lumberjack_leet")
then
mod = 'default'
items = {'tree', 'pine_tree', 'acacia_tree'}
elseif node1 == 'default:tree' then
mod = 'default'
items = {'tree', 'pine_tree', 'acacia_tree', 'jungletree'}
elseif node1 == 'default:leaves' then
mod = 'default'
items = {'leaves', 'jungleleaves', 'pine_needles', 'acacia_leaves'}
elseif node1 == 'default:sand' then
mod = 'default'
items = {'sand', 'desert_sand'}
elseif node1 == 'default:snow' then
mod = 'default'
items = {'snow', 'snowblock'}
elseif node1 == 'default:stone' then
mod = 'default'
items = {'stone', 'desert_stone', 'cobble', 'desert_cobble', 'mossycobble'}
elseif node1 == 'default:wood' then
mod = 'default'
items = {'wood', 'junglewood', 'pine_wood', 'acacia_wood'}
elseif node1 == 'default:cobble' then
mod = 'default'
items = {'cobble', 'desert_cobble'}
elseif node1 == 'default:stonebrick' then
mod = 'default'
items = {'stonebrick', 'desert_stonebrick'}
elseif node1 == 'dye:black' then
mod = "dye"
items = {'red', 'blue', 'yellow', 'white', 'orange', 'violet', 'black'}
elseif node1 == 'wool:black' then
mod = 'wool'
items = {'red', 'blue', 'yellow', 'white', 'orange', 'violet', 'black'}
elseif node1 == 'vessels:glass_bottle' then
mod = 'vessels'
items = {'glass_bottle', 'steel_bottle', 'drinking_glass', 'glass_fragments'}
elseif node1 == 'beds:bed_bottom' then
mod = 'beds'
items = {'bed_bottom', 'fancy_bed_bottom'}
elseif node1 == node2 then
return true
end
for _,item in pairs(items) do
if mod..":"..item == node2 then
return true
end
end
return false
end
sys4_quest.quests = sys4_quest.make_initial_quests()
sys4_quest.current_quest = {}
-- Register the quests defined above
for _,quest in ipairs(sys4_quest.quests) do
quests.register_quest("sys4_quest:" .. quest[1],
{ title = quest[2],
description = quest[4],
max = quest[3],
autoaccept = quest[5],
callback = sys4_quest.next_quest })
end
local isNewPlayer = false
minetest.register_on_newplayer(
function(player)
isNewPlayer = true
end)
local oldpos = {}
minetest.register_on_joinplayer(
function(player)
local playern = player:get_player_name()
if (isNewPlayer) then
for _,quest in ipairs(sys4_quest.quests) do
if not awards.def[quest[1] ].award_req then
quests.start_quest(playern, "sys4_quest:"..quest[1])
end
end
end
oldpos[playern] = player:getpos() -- remember the current location for movement based quests
end)
-- For quests where you have to dig something, the updates happen here
minetest.register_on_dignode(
function(pos, oldnode, digger)
local playern = digger:get_player_name()
for _,quest in ipairs(sys4_quest.quests) do
local questname = quest[1]
local award = awards.def[questname]
local node = award.trigger.node
if award.trigger.type == "dig" and sys4_quest.isInSameGroup(node, oldnode.name, questname) then
if quests.update_quest(playern, "sys4_quest:"..questname, 1) then
minetest.after(1, quests.accept_quest, playern, "sys4_quest:"..questname)
end
end
end
end)
minetest.register_on_craft(
function(itemstack, player, old_craft_grid, craft_inv)
local playern = player:get_player_name()
for _,quest in ipairs(sys4_quest.quests) do
local questname = quest[1]
local award = awards.def[questname]
local node = award.trigger.node
if award.trigger.type == "craft" and sys4_quest.isInSameGroup(node, itemstack:get_name(), questname) then
if quests.update_quest(playern, "sys4_quest:"..questname, itemstack:get_count()) then
minetest.after(1, quests.accept_quest, playern, "sys4_quest:"..questname)
end
end
end
return nil
end)
function sys4_quest.register_on_placenode(pos, node, placer)
local playern = placer:get_player_name()
for _,quest in ipairs(sys4_quest.quests) do
local questname = quest[1]
local award = awards.def[questname]
local awardnode = award.trigger.node
if award.trigger.type == "place" and sys4_quest.isInSameGroup(awardnode, node.name, questname) then
if quests.update_quest(playern, "sys4_quest:"..questname, 1) then
minetest.after(1, quests.accept_quest, playern, "sys4_quest:"..questname)
end
end
end
end
minetest.register_on_placenode(sys4_quest.register_on_placenode)
local tree_on_place = sys4_achievements.register_on_place
sys4_achievements.register_on_place = function (itemstack, placer, pointed_thing)
local node = {}
node.name = itemstack:get_name()
sys4_quest.register_on_placenode(pointed_thing, node, placer)
return tree_on_place(itemstack, placer, pointed_thing)
end
local nodes = {
minetest.registered_nodes["default:tree"],
minetest.registered_nodes["default:jungletree"],
minetest.registered_nodes["default:acacia_tree"],
minetest.registered_nodes["default:pine_tree"],
}
for i=1, #nodes do
nodes[i].on_place = sys4_achievements.register_on_place
end
--[[minetest.register_chatcommand("next_quest",{
func = function(name, param)
sys4_quest.next_quest(name)
end
})
--]]