sorcery  Diff

Differences From Artifact [b21ad56f71]:

To Artifact [89adffa44b]:


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125
126





127
128
129
130
131
132
133
...
135
136
137
138
139
140
141












142
143
144
145
146
147
148
...
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
...
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
...
283
284
285
286
287
288
289

290
291

292
293
294
295
296
297
298
299
300
301
302
303
304
...
312
313
314
315
316
317
318








319
320
321
322
323
324
325
326
327
328
...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
		end
	end
	return names[math.random(#names)]
end end
local find_builtin = function(out)
	local rec = {}
	local i = minetest.get_craft_recipe(out)
	if #i.items == 0 then return nil end
	local w = (i.width == 0) and 3 or i.width
	for j=1,#i.items do
		local row = math.floor((j-1) / w)
		local col = (j-1) % w
		if i.items[j] then
			rec[1 + (row * 3) + col] = i.items[j]
		end
................................................................................
	end
	return i
end
local function desc_builtin(i)
	local desc
	i, desc = group_eval(i)
	-- print('describing ',i,dump(minetest.registered_items[i]))

	if not minetest.registered_items[i] then
		minetest.log('WARNING: unknown item in recipe ' .. i)
		return 'Unknown Item'
	end
	if not desc then desc = minetest.registered_items[i].description end
	if not desc then return 'Peculiar Item' end

	local eol = string.find(desc,'\n')
	if not eol then return desc else return string.sub(desc,1,eol-1) end





end;

local bookadjs = { -- sets are in reverse order!
	{'Celestial', 'Divine', 'Inspired', 'Heavenly';
	 'Mystic', 'Diabolic', 'Luminous', 'Forsaken'};

	{'Dark', 'Perfected', 'Flawless', 'Unthinkable';
................................................................................

	{'Splendid', 'Magnificent', 'Sublime', 'Grand';
	 'Beneficent', 'Mysterious', 'Peculiar', 'Eerie';
	 'Fulsome', 'Fearsome', 'Curious', 'Fascinating';
     'Notorious', 'Infamous'};
}













sorcery.cookbook.classes = {
	craft = {
		name = 'Crafting Guide';
		node = 'xdecor:workbench';
		booksuf = 'Manual';
		w = 3, h = 3;
		chance = 2;
................................................................................
	-- 	slots = slot3x3;
	-- };
	cook = {
		name = 'Cooking Recipe';
		node = 'default:furnace';
		booksuf = 'Cookbook';
		w = 1, h = 1;
		chance = 5;
		slots = {{-0.2,0}};
		pick = pick_builtin('cooking');
		find = find_builtin;
		props = props_builtin;
		apply_exclusions = true;
	};
	infuse = {
		name = 'Infusion Recipe';
		node = 'sorcery:infuser';
		booksuf = 'Pharmacopeia';
		w = 1, h = 2;
		chance = 2;
		slots = {
			{0,0};
			{0,1};
		};
		pick = function(restrict)
			-- TODO make sure affinity restrictions match
			return sorcery.data.infusions[math.random(#sorcery.data.infusions)].output
		end;
		title = function(output)
			for _,i in pairs(sorcery.data.infusions) do
				print(dump(i))
				if i.output == output then
					if i._proto and i._proto.name
						then return i._proto.name
						else break end
				end
			end
			return 'Mysterious Potion'
................................................................................
			for _,i in pairs(sorcery.data.infusions) do
				if i.output == out then
					return { i.infuse, i.into }
				end
			end
		end;
		props = function(out)
			local i = sorcery.cookbook.classes.infuse.find(out)

			if i.recipe then return i.info else return {} end











































		end;
	};
	-- wand = {
	--	booksuf = 'Grimoire';
	-- }
	enchant = {
		name = 'Enchantment Matrix';
		node = 'sorcery:enchanter';
		booksuf = 'Grimoire';
		drawslots = false;
		chance = 1;
		w = 2, h = 2;
		pick = function(restrict)
			-- TODO make sure affinity restrictions match
			local names = {}
			for k,v in pairs(sorcery.data.enchants) do
				if v.recipe then names[#names+1] = k end
			end
................................................................................
sorcery.cookbook.pickrecipe = function(kind,restrict)
	if kind == nil then
		for k,v in pairs(recipe_kinds) do
			if math.random(v.chance) == 1 then
				kind = k break
			end
		end

		-- local rks = sorcery.lib.tbl.keys(recipe_kinds)
		-- kind = rks[math.random(#rks)]

	end

	return recipe_kinds[kind].pick(restrict), kind
end

local render_recipe = function(kind,ingredients,result)
	local k = recipe_kinds[kind]
	local t = ''
	for i=1,#k.slots do
		local x, y = k.slots[i][1], k.slots[i][2]
		if ingredients[i] and ingredients[i] ~= '' then
			local tt
			if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end
................................................................................
				t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
			end
		end
	end
	local img, ot
	local props = k.props(result)
	if props.note then








		t = t .. string.format([[
			textarea[0,3;4,1;;;%s]
		]], minetest.formspec_escape(props.note))
	end
	if k.icon then img = k.icon(result) end
	if k.outdesc then ot = k.outdesc(result) else ot = desc_builtin(result) end
		-- image[%f,%f;1,1;gui_furnace_arrow_bg.png^[transformR270]
	return t .. string.format([[
		item_image[%f,%f;1,1;%s]tooltip[%f,%f;1,1;%s]
		]] --[[box[%f,%f;1,1;#850083A0]] .. [[
................................................................................
		k.w, k.h/2 - 0.5, minetest.formspec_escape(minetest.registered_nodes[k.node].description),
			-- k.w+1, k.h/2 - 0.5,
		img and 'image' or 'item_image',
			k.w+1.1, k.h/2 - 0.5, minetest.formspec_escape(img or result),
			k.w+1.1, k.h/2 - 0.5, minetest.formspec_escape(ot))
end;

local retrieve_recipe = function(kind,out)
	local rec = recipe_kinds[kind]
	local ing = rec.find(out)
	return render_recipe(kind,ing,out), rec.w, rec.h
end

sorcery.cookbook.setrecipe = function(stack,k,r,restrict)
	local meta = stack:get_meta()
	if not r then r,k = sorcery.cookbook.pickrecipe(k,restrict) end
	local t = recipe_kinds[k]
	meta:set_string('recipe_kind', k)
................................................................................
		{2,1.3};
		{2,4.5};
		{2,7.7};
		-- {0,1.3}, {4, 1.3};
		-- {0,4.7}, {4, 4.7};
		-- {0,8.1}, {4, 8.1};
	}
	print('book:',dump(book))
	print('pgofs',pgofs)
	for i=pgofs,(pgofs + constants.recipes_per_cookbook_page-1) do
		local maxw, maxh = 3, 2
		if not book.pages[i+1] then break end
		local nr = 1+(i - pgofs)
		local x,y = coords[nr][1], coords[nr][2]
		local k = recipe_kinds[book.pages[i+1].kind]
		local ox,oy = maxw - k.w, maxh - k.h
		form = form .. string.format('container[%f,%f]%scontainer_end[]',(x+ox)-0.5,y,
			retrieve_recipe(book.pages[i+1].kind, book.pages[i+1].name))
	end

	minetest.show_formspec(user:get_player_name(), 'sorcery:cookbook', form)
end

minetest.register_craftitem('sorcery:cookbook', {
	description = 'Catalog';







|







 







>
|



|



|
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>







 







|











|










<







 







|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










|







 







>
|
|
>





|







 







>
>
>
>
>
>
>
>

|
|







 







|


|







 







<
<








|







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
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
...
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
...
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
...
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
...
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
...
513
514
515
516
517
518
519


520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
		end
	end
	return names[math.random(#names)]
end end
local find_builtin = function(out)
	local rec = {}
	local i = minetest.get_craft_recipe(out)
	if i == nil or i.items == nil or #i.items == 0 then return nil end
	local w = (i.width == 0) and 3 or i.width
	for j=1,#i.items do
		local row = math.floor((j-1) / w)
		local col = (j-1) % w
		if i.items[j] then
			rec[1 + (row * 3) + col] = i.items[j]
		end
................................................................................
	end
	return i
end
local function desc_builtin(i)
	local desc
	i, desc = group_eval(i)
	-- print('describing ',i,dump(minetest.registered_items[i]))
	local s = ItemStack(i)
	if not minetest.registered_items[s:get_name()] then
		minetest.log('WARNING: unknown item in recipe ' .. i)
		return 'Unknown Item'
	end
	if not desc then desc = minetest.registered_items[s:get_name()].description end
	if not desc then return 'Peculiar Item' end

	local eol = string.find(desc,'\n')
	if eol then desc = string.sub(desc,1,eol-1) end

	if s:get_count() > 1 then
		desc = string.format("%s (%u)",desc,s:get_count())
	end
	return desc
end;

local bookadjs = { -- sets are in reverse order!
	{'Celestial', 'Divine', 'Inspired', 'Heavenly';
	 'Mystic', 'Diabolic', 'Luminous', 'Forsaken'};

	{'Dark', 'Perfected', 'Flawless', 'Unthinkable';
................................................................................

	{'Splendid', 'Magnificent', 'Sublime', 'Grand';
	 'Beneficent', 'Mysterious', 'Peculiar', 'Eerie';
	 'Fulsome', 'Fearsome', 'Curious', 'Fascinating';
     'Notorious', 'Infamous'};
}

local cache = {
	populate_grindables = function(cache)
		if not cache.grindables then
			cache.grindables = {}
			for k,v in pairs(minetest.registered_items) do
				if sorcery.itemclass.get(k, 'grindable') then
					cache.grindables[#cache.grindables+1] = k
				end
			end
		end
	end;
}
sorcery.cookbook.classes = {
	craft = {
		name = 'Crafting Guide';
		node = 'xdecor:workbench';
		booksuf = 'Manual';
		w = 3, h = 3;
		chance = 2;
................................................................................
	-- 	slots = slot3x3;
	-- };
	cook = {
		name = 'Cooking Recipe';
		node = 'default:furnace';
		booksuf = 'Cookbook';
		w = 1, h = 1;
		chance = 3;
		slots = {{-0.2,0}};
		pick = pick_builtin('cooking');
		find = find_builtin;
		props = props_builtin;
		apply_exclusions = true;
	};
	infuse = {
		name = 'Infusion Recipe';
		node = 'sorcery:infuser';
		booksuf = 'Pharmacopeia';
		w = 1, h = 2;
		chance = 4;
		slots = {
			{0,0};
			{0,1};
		};
		pick = function(restrict)
			-- TODO make sure affinity restrictions match
			return sorcery.data.infusions[math.random(#sorcery.data.infusions)].output
		end;
		title = function(output)
			for _,i in pairs(sorcery.data.infusions) do

				if i.output == output then
					if i._proto and i._proto.name
						then return i._proto.name
						else break end
				end
			end
			return 'Mysterious Potion'
................................................................................
			for _,i in pairs(sorcery.data.infusions) do
				if i.output == out then
					return { i.infuse, i.into }
				end
			end
		end;
		props = function(out)
			for _,i in pairs(sorcery.data.infusions) do
				if i.output == out then
					if i.recipe then return i.recipe else return {} end
				end
			end
		end;
	};
	grind = {
		name = 'Milling Guide';
		node = 'sorcery:mill';
		booksuf = 'Manual';
		chance = 1;
		w = 1, h = 2;
		pick = function(restrict)
			cache:populate_grindables()
			local i = cache.grindables[math.random(#cache.grindables)]
			local pd = sorcery.itemclass.get(i, 'grindable')
			return pd.powder
		end;
		desc = desc_builtin;
		props = props_builtin;
		slots = {
			{0,1},
			{0,0};
		};
		find = function(out)
			cache:populate_grindables()
			for _,v in pairs(cache.grindables) do
				local g = sorcery.itemclass.get(v,'grindable')
				if g.powder == out then
					if g.grindcost then
						v = v .. ' ' .. tostring(g.grindcost)
					end
					local mbh = sorcery.lib.tbl.keys(sorcery.data.metals)
					table.sort(mbh, function(a,b)
						return sorcery.data.metals[a].hardness < sorcery.data.metals[b].hardness
					end)
					for _,metal in pairs(mbh) do
						local md = sorcery.data.metals[metal]
						if ((not md.no_tools) or md.grindhead) and md.hardness >= g.hardness then
							return {v, 'sorcery:mill_grindhead_' .. metal}
						end
					end
					return {v,''} -- !!
				end
			end
		end;
	};
	-- wand = {
	--	booksuf = 'Grimoire';
	-- }
	enchant = {
		name = 'Enchantment Matrix';
		node = 'sorcery:enchanter';
		booksuf = 'Grimoire';
		drawslots = false;
		chance = 6;
		w = 2, h = 2;
		pick = function(restrict)
			-- TODO make sure affinity restrictions match
			local names = {}
			for k,v in pairs(sorcery.data.enchants) do
				if v.recipe then names[#names+1] = k end
			end
................................................................................
sorcery.cookbook.pickrecipe = function(kind,restrict)
	if kind == nil then
		for k,v in pairs(recipe_kinds) do
			if math.random(v.chance) == 1 then
				kind = k break
			end
		end
		if kind == nil then -- oh well, we tried
			local rks = sorcery.lib.tbl.keys(recipe_kinds)
			kind = rks[math.random(#rks)]
		end
	end

	return recipe_kinds[kind].pick(restrict), kind
end

local render_recipe = function(kind,ingredients,result,notes_right)
	local k = recipe_kinds[kind]
	local t = ''
	for i=1,#k.slots do
		local x, y = k.slots[i][1], k.slots[i][2]
		if ingredients[i] and ingredients[i] ~= '' then
			local tt
			if k.indesc then tt = k.indesc(ingredients[i]) else tt = desc_builtin(ingredients[i]) end
................................................................................
				t = string.format('box[%f,%f;0.1,0.1;#00000060]',x+0.45,y+0.45) .. t
			end
		end
	end
	local img, ot
	local props = k.props(result)
	if props.note then
		local nx, ny, nw, nh
		if notes_right then
			nx = 5 ny = 0
			nw = 3 nh = 3
		else
			nx = 0 ny = 3
			nw = 4 nh = 1
		end
		t = t .. string.format([[
			textarea[%f,%f;%f,%f;;;%s]
		]], nx,ny,nw,nh, minetest.formspec_escape(props.note))
	end
	if k.icon then img = k.icon(result) end
	if k.outdesc then ot = k.outdesc(result) else ot = desc_builtin(result) end
		-- image[%f,%f;1,1;gui_furnace_arrow_bg.png^[transformR270]
	return t .. string.format([[
		item_image[%f,%f;1,1;%s]tooltip[%f,%f;1,1;%s]
		]] --[[box[%f,%f;1,1;#850083A0]] .. [[
................................................................................
		k.w, k.h/2 - 0.5, minetest.formspec_escape(minetest.registered_nodes[k.node].description),
			-- k.w+1, k.h/2 - 0.5,
		img and 'image' or 'item_image',
			k.w+1.1, k.h/2 - 0.5, minetest.formspec_escape(img or result),
			k.w+1.1, k.h/2 - 0.5, minetest.formspec_escape(ot))
end;

local retrieve_recipe = function(kind,out,notes_right)
	local rec = recipe_kinds[kind]
	local ing = rec.find(out)
	return render_recipe(kind,ing,out,notes_right), rec.w, rec.h
end

sorcery.cookbook.setrecipe = function(stack,k,r,restrict)
	local meta = stack:get_meta()
	if not r then r,k = sorcery.cookbook.pickrecipe(k,restrict) end
	local t = recipe_kinds[k]
	meta:set_string('recipe_kind', k)
................................................................................
		{2,1.3};
		{2,4.5};
		{2,7.7};
		-- {0,1.3}, {4, 1.3};
		-- {0,4.7}, {4, 4.7};
		-- {0,8.1}, {4, 8.1};
	}


	for i=pgofs,(pgofs + constants.recipes_per_cookbook_page-1) do
		local maxw, maxh = 3, 2
		if not book.pages[i+1] then break end
		local nr = 1+(i - pgofs)
		local x,y = coords[nr][1], coords[nr][2]
		local k = recipe_kinds[book.pages[i+1].kind]
		local ox,oy = maxw - k.w, maxh - k.h
		form = form .. string.format('container[%f,%f]%scontainer_end[]',(x+ox)-0.5,y,
			retrieve_recipe(book.pages[i+1].kind, book.pages[i+1].name, true))
	end

	minetest.show_formspec(user:get_player_name(), 'sorcery:cookbook', form)
end

minetest.register_craftitem('sorcery:cookbook', {
	description = 'Catalog';