2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
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
...
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
-- to generate runes and that wears down over time, to make amulets more
-- expensive than they currently are? the existing system is neat but
-- i think amulets are a little overpowered for something that just
-- passively consumes ley-current
-- -- are phials & rune-wrenches enough for this now?
local constants = {
rune_mine_interval = 240;
-- how often a powered forge rolls for new runes
rune_cache_max = 6;
-- how many runes a runeforge can hold at a time
rune_grades = {'Fragile', 'Weak', 'Ordinary', 'Pristine', 'Sublime'};
-- how many grades of rune quality/power there are
................................................................................
};
}
local calc_phial_props = function(phial) --> mine interval: float, power factor: float
local m = phial:get_meta()
local g = phial:get_definition()._proto.data.grade
local i = constants.rune_mine_interval
local fac = (g-1) / 5
fac = fac + 0.2 * m:get_int('speed')
return math.max(3,i - ((i*0.5) * fac)), 0.5 * fac
end
sorcery.register.runes.foreach('sorcery:generate',{},function(name,rune)
local id = 'sorcery:rune_' .. name
rune.image = rune.image or string.format('sorcery_rune_%s.png',name)
rune.item = id
local c = sorcery.lib.color(rune.tone)
................................................................................
local proto = stack:get_definition()._sorcery.amulet
if not m:contains('amulet_rune') then return nil end
local rune = m:get_string('amulet_rune')
local rg = m:get_int('amulet_rune_grade')
local rd = sorcery.data.runes[rune]
local spell = rd.amulets[proto.base]
if not spell then return nil end
local title,desc,cast,apply,remove,mingrade = spell.name, spell.desc, spell.cast, spell.apply, spell.remove, spell.mingrade -- FIXME in serious need of refactoring
local base_spell = true
if proto.frame and spell.frame and spell.frame[proto.frame] then
local sp = spell.frame[proto.frame]
if not sp.mingrade or rg >= sp.mingrade then
title = sp.name or title
desc = sp.desc or desc
cast = sp.cast or cast
apply = sp.apply or apply
remove = sp.remove or remove
mingrade = sp.mingrade or mingrade
base_spell = false
end
end
return {
rune = rune, grade = rg;
spell = spell, mingrade = mingrade;
name = title, desc = desc;
cast = cast, apply = apply, remove = remove;
frame = proto.frame;
framestats = proto.frame and sorcery.data.metals[proto.frame].amulet;
tone = sorcery.lib.color(rd.tone);
base_spell = base_spell;
}
end
................................................................................
if time and has_phial() and pow_min and not probe.disjunction then -- roll for runes
local phial = i:get_stack('phial',1)
local int, powerfac = calc_phial_props(phial)
local pf = phial:get_meta():get_int('force')
local rolls = math.floor(time/int)
local newrunes = {}
for _=1,rolls do
local choices = {}
for name,rune in pairs(sorcery.data.runes) do
-- print('considering',name)
-- print('-- power',rune.minpower,(rune.minpower*powerfac)*time,'//',l.self.powerdraw,l.self.powerdraw/time,'free',l.freepower,'max',l.maxpower)
if (rune.minpower*powerfac)*time <= l.self.powerdraw and math.random(rune.rarity - pf) == 1 then
choices[#choices + 1] = rune
end
end
if #choices > 0 then
-- if multiple runes were rolled up, be nice to the player
-- and pick the rarest one to give them
local rare, choice = 0
for i,c in pairs(choices) do
if c.rarity > rare then
rare = c.rarity
choice = c
end
end
newrunes[#newrunes + 1] = ItemStack(choice.item)
end
-- print('rune choices:',dump(choices))
-- print('me',dump(l.self))
end
for _,r in pairs(newrunes) do
if i:room_for_item('cache',r) and has_phial() then
................................................................................
local i = m:get_inventory()
i:set_size('cache',constants.rune_cache_max)
i:set_size('wrench',1) i:set_size('phial',1) i:set_size('refuse',1)
i:set_size('amulet',1) i:set_size('active',1)
m:set_string('infotext','Rune Forge')
runeforge_update(pos)
end;
after_dig_node = sorcery.lib.node.purge_only {'amulet','wrench'};
on_timer = runeforge_update;
on_metadata_inventory_move = function(pos, fl,fi, tl,ti, count, user)
local inv = minetest.get_meta(pos):get_inventory()
local wrench if not inv:is_empty('wrench') then
wrench = inv:get_stack('wrench',1):get_definition()._proto
end
local wwear = function(cap)
|
|
|
|
>
>
|
>
<
<
|
>
>
>
>
>
>
<
|
|
|
|
|
|
>
>
>
<
|
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
...
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
...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
-- to generate runes and that wears down over time, to make amulets more
-- expensive than they currently are? the existing system is neat but
-- i think amulets are a little overpowered for something that just
-- passively consumes ley-current
-- -- are phials & rune-wrenches enough for this now?
local constants = {
rune_mine_interval = 180;
-- how often a powered forge rolls for new runes
rune_cache_max = 6;
-- how many runes a runeforge can hold at a time
rune_grades = {'Fragile', 'Weak', 'Ordinary', 'Pristine', 'Sublime'};
-- how many grades of rune quality/power there are
................................................................................
};
}
local calc_phial_props = function(phial) --> mine interval: float, power factor: float
local m = phial:get_meta()
local g = phial:get_definition()._proto.data.grade
local i = constants.rune_mine_interval
local fac = (g-1) / 5
fac = fac + 0.1 * m:get_int('speed')
return math.max(3,i - ((i*0.5) * fac)), 0.5 * fac
end
sorcery.register.runes.foreach('sorcery:generate',{},function(name,rune)
local id = 'sorcery:rune_' .. name
rune.image = rune.image or string.format('sorcery_rune_%s.png',name)
rune.item = id
local c = sorcery.lib.color(rune.tone)
................................................................................
local proto = stack:get_definition()._sorcery.amulet
if not m:contains('amulet_rune') then return nil end
local rune = m:get_string('amulet_rune')
local rg = m:get_int('amulet_rune_grade')
local rd = sorcery.data.runes[rune]
local spell = rd.amulets[proto.base]
if not spell then return nil end
local title,desc,cast,apply,remove,mingrade,sound = spell.name, spell.desc, spell.cast, spell.apply, spell.remove, spell.mingrade,spell.sound -- FIXME in serious need of refactoring
local base_spell = true
if proto.frame and spell.frame and spell.frame[proto.frame] then
local sp = spell.frame[proto.frame]
if not sp.mingrade or rg >= sp.mingrade then
title = sp.name or title
desc = sp.desc or desc
cast = sp.cast or cast
apply = sp.apply or apply
remove = sp.remove or remove
mingrade = sp.mingrade or mingrade
sound = sp.sound or sound
base_spell = false
end
end
-- PLEASE, GOD, REFACTOR ME
return {
rune = rune, grade = rg;
spell = spell, mingrade = mingrade;
name = title, desc = desc, sound = sound;
cast = cast, apply = apply, remove = remove;
frame = proto.frame;
framestats = proto.frame and sorcery.data.metals[proto.frame].amulet;
tone = sorcery.lib.color(rd.tone);
base_spell = base_spell;
}
end
................................................................................
if time and has_phial() and pow_min and not probe.disjunction then -- roll for runes
local phial = i:get_stack('phial',1)
local int, powerfac = calc_phial_props(phial)
local pf = phial:get_meta():get_int('force')
local rolls = math.floor(time/int)
local newrunes = {}
for _=1,rolls do
print('--- rune roll',_,'pf',pf)
local choices = {}
for name,rune in pairs(sorcery.data.runes) do
local powreq = (rune.minpower*powerfac)*time
print('- rune', name)
print('powreq',powreq)
print('power draw',l.self.powerdraw)
if powreq <= l.self.powerdraw then
print(' ! sufficient power for rune')
choices[#choices + 1] = rune
end
end
for k,v in pairs(choices) do print(' * choice',k,v.item) end
if #choices > 0 then
for try = 1,#choices do
print(' -- try',try)
local _, choice = sorcery.lib.tbl.pick(choices)
local adjrare = math.max(2, choice.rarity - pf)
print(choice.item,'rarity',choice.rarity, 'adjusted', adjrare)
if math.random(adjrare) == 1 then
print(' ! picking ', choice.item)
newrunes[#newrunes + 1] = ItemStack(choice.item)
break
end
end
end
-- print('rune choices:',dump(choices))
-- print('me',dump(l.self))
end
for _,r in pairs(newrunes) do
if i:room_for_item('cache',r) and has_phial() then
................................................................................
local i = m:get_inventory()
i:set_size('cache',constants.rune_cache_max)
i:set_size('wrench',1) i:set_size('phial',1) i:set_size('refuse',1)
i:set_size('amulet',1) i:set_size('active',1)
m:set_string('infotext','Rune Forge')
runeforge_update(pos)
end;
after_dig_node = sorcery.lib.node.purge_only {'amulet','wrench','refuse','phial'};
on_timer = runeforge_update;
on_metadata_inventory_move = function(pos, fl,fi, tl,ti, count, user)
local inv = minetest.get_meta(pos):get_inventory()
local wrench if not inv:is_empty('wrench') then
wrench = inv:get_stack('wrench',1):get_definition()._proto
end
local wwear = function(cap)
|