parent
f6b490b1fb
commit
e45d99da81
|
@ -0,0 +1 @@
|
|||
Subproject commit 78e4ba828ebe19dc80977ce53ce301d63230b8b8
|
|
@ -1,3 +1,11 @@
|
|||
-----------------------------------------------------------------
|
||||
-- MULTIBLOCK RECIPES -------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
|
||||
function magic.register_recipe(name, recipe, action)
|
||||
magic.recipes[name] = {recipe, action}
|
||||
end
|
||||
|
||||
function magic.do_spell(itemstack, placer, pointed_thing)
|
||||
local name
|
||||
|
||||
|
@ -24,15 +32,6 @@ function magic.do_spell(itemstack, placer, pointed_thing)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- MULTIBLOCK RECIPES -------------------------------------------
|
||||
-----------------------------------------------------------------
|
||||
|
||||
function magic.register_recipe(name, recipe, action)
|
||||
magic.recipes[name] = {recipe, action}
|
||||
end
|
||||
|
||||
function magic.check_recipe(recipe_id, target)
|
||||
local recipe = magic.recipes[recipe_id][1]
|
||||
|
||||
|
@ -127,20 +126,100 @@ function magic.register_ritual(name, ritual, action)
|
|||
magic.rituals[name] = {ritual, action}
|
||||
end
|
||||
|
||||
function magic.check_ritual(things)
|
||||
local list = {}
|
||||
function magic.do_ritual(node, player)
|
||||
local things = magic.get_items(node)
|
||||
|
||||
--for i in ipairs(things) do
|
||||
-- if list[things[i]] then
|
||||
-- list[i] = list[i] + 1
|
||||
-- else
|
||||
-- table.insert(things, {i = 0})
|
||||
-- end
|
||||
--end
|
||||
--
|
||||
--for n, i in pairs(list) do
|
||||
-- minetest.chat_send_all(n .. ", " .. i)
|
||||
--end
|
||||
if #things < 1 then
|
||||
minetest.chat_send_player(player:get_player_name(), "[Mod magic] The altar is empty")
|
||||
return
|
||||
end
|
||||
|
||||
local itemlist = magic.organice_items(things)
|
||||
local n_rit = magic.check_ritual(itemlist)
|
||||
|
||||
if n_rit then
|
||||
magic.rituals[n_rit][2](node, player)
|
||||
end
|
||||
end
|
||||
|
||||
function magic.get_items(node)
|
||||
local pos = node.under
|
||||
local things = {}
|
||||
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
table.insert(things,object:get_luaentity().itemstring)
|
||||
end
|
||||
end
|
||||
|
||||
return things
|
||||
end
|
||||
|
||||
function magic.organice_items(things)
|
||||
local did = false
|
||||
local itemlist = {}
|
||||
|
||||
for i, n in pairs(things) do
|
||||
did = false
|
||||
|
||||
for j in ipairs(itemlist) do
|
||||
if itemlist[j].name == n then
|
||||
itemlist[j].val = itemlist[j].val + 1
|
||||
did = true
|
||||
end
|
||||
end
|
||||
|
||||
if not did then
|
||||
itemlist[#itemlist+1] = {name = n, val = 1}
|
||||
end
|
||||
end
|
||||
|
||||
return itemlist
|
||||
end
|
||||
|
||||
function magic.check_ritual(itemlist)
|
||||
for ritual_id, ritual_content in pairs(magic.rituals) do
|
||||
if #ritual_content[1] == #itemlist then
|
||||
local check = false
|
||||
for i in ipairs(itemlist) do
|
||||
check = magic.check_item_in_ritual(itemlist[i], ritual_content[1])
|
||||
|
||||
if not check then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if check then
|
||||
return ritual_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
function magic.check_item_in_ritual(item, itemlist)
|
||||
for i in ipairs(itemlist) do
|
||||
if itemlist[i].name == item.name and itemlist[i].val == item.val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function magic.clear_altar(node)
|
||||
local pos = node.under
|
||||
local things = {}
|
||||
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
object:get_luaentity().itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
end
|
||||
|
||||
return things
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
function magic.altar_action(node, player)
|
||||
--Comprobamos de qué rito se trata
|
||||
local pos = node.under
|
||||
local things = {}
|
||||
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
||||
table.insert(things,object:get_luaentity().itemstring)
|
||||
end
|
||||
end
|
||||
|
||||
if #things > 0 then
|
||||
magic.check_ritual(things)
|
||||
else
|
||||
minetest.chat_send_player(player:get_player_name(), "[Mod magic] The altar is empty")
|
||||
end
|
||||
end
|
|
@ -8,7 +8,6 @@ magic.worldpath = minetest.get_worldpath()
|
|||
|
||||
-- Load files
|
||||
dofile(magic.path.."/functions/homewarp.lua")
|
||||
dofile(magic.path.."/functions/altar.lua")
|
||||
dofile(magic.path.."/api.lua")
|
||||
|
||||
dofile(magic.path.."/items/wand.lua")
|
||||
|
@ -26,7 +25,10 @@ dofile(magic.path.."/recipes/t1_big_tree.lua")
|
|||
dofile(magic.path.."/recipes/t1_compass.lua")
|
||||
dofile(magic.path.."/recipes/t1_home_stone.lua")
|
||||
dofile(magic.path.."/recipes/t1_home_warp.lua")
|
||||
dofile(magic.path.."/recipes/t2_lightbloom.lua")
|
||||
|
||||
dofile(magic.path.."/tiers.lua")
|
||||
|
||||
magic.loadHomes()
|
||||
magic.loadHomes()
|
||||
|
||||
-- 927 líneas de código
|
|
@ -62,6 +62,6 @@ magic.register_recipe("altar",
|
|||
},
|
||||
},
|
||||
function(node, player)
|
||||
magic.altar_action(node, player)
|
||||
magic.do_ritual(node, player)
|
||||
end
|
||||
)
|
|
@ -0,0 +1,10 @@
|
|||
magic.register_ritual("lightbloom",
|
||||
{
|
||||
{name = "flowers:geranium", val = 1}
|
||||
},
|
||||
|
||||
function(node, player)
|
||||
magic.clear_altar(node)
|
||||
minetest.env:add_item(node.under, "magic:lightbloom")
|
||||
end
|
||||
)
|
Loading…
Reference in New Issue