Added triple registrering of runes
- Runes are registered three times with tree levels : minor, medium, major
@ -19,122 +19,150 @@ runes.functions.register_rune = function(parameters)
|
||||
runedef.name = parameters.name
|
||||
runedef.desc = parameters.description or ""
|
||||
runedef.img = parameters.img or "default_stone.png"
|
||||
if type(runedef.img) ~= "table" then
|
||||
runedef.img = {
|
||||
["minor"] = runedef.img .. "_minor.png",
|
||||
["medium"] = runedef.img .. "_medium.png",
|
||||
["major"] = runedef.img .. "_major.png",
|
||||
}
|
||||
end
|
||||
runedef.type = parameters.type or "craftitem"
|
||||
runedef.needed_mana = parameters.needed_mana or 0
|
||||
runedef.needed_mana = parameters.needed_mana or {["minor"] = 0, ["medium"] = 5, ["major"] = 10}
|
||||
|
||||
runes.datas.handlers[runedef.name] = {}
|
||||
|
||||
if runedef.type == "cube" then
|
||||
minetest.register_node("runes:rune_" .. runedef.name, {
|
||||
description = runedef.desc,
|
||||
tiles = {runedef.img},
|
||||
groups = {oddly_breakable_by_hand = 2, rune = 1},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if placer and placer:is_player() then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name())
|
||||
end
|
||||
if runes.datas.handlers[runedef.name].on_place then
|
||||
if mana.get(placer:get_player_name()) >= runedef.needed_mana then
|
||||
runes.datas.handlers[runedef.name].on_place(pos, placer, itemstack, pointed_thing)
|
||||
mana.subtract(placer:get_player_name(),runedef.needed_mana)
|
||||
else
|
||||
minetest.chat_send_player(placer:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")")
|
||||
for _, level in pairs({"minor", "medium", "major"}) do
|
||||
minetest.register_node("runes:rune_" .. runedef.name .. "_" .. level, {
|
||||
description = runedef.desc .. " ("..level..")",
|
||||
tiles = {runedef.img[level]},
|
||||
groups = {oddly_breakable_by_hand = 2, rune = 1},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if placer and placer:is_player() then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name())
|
||||
end
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
if runes.datas.handlers[runedef.name].can_dig then
|
||||
return runes.datas.handlers[runedef.name].can_dig(pos, player)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end,
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
if runes.datas.handlers[runedef.name].on_punch then
|
||||
if mana.get(puncher:get_player_name()) >= runedef.needed_mana then
|
||||
runes.datas.handlers[runedef.name].on_punch(pos, node, puncher, pointed_thing)
|
||||
mana.subtract(puncher:get_player_name(),runedef.needed_mana)
|
||||
else
|
||||
minetest.chat_send_player(puncher:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")")
|
||||
end
|
||||
end
|
||||
end,
|
||||
--[[after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
--if runes.datas.handlers[runedef.name].can_dig and runes.datas.handlers[runedef.name].can_dig(pos, digger) then
|
||||
if runes.datas.handlers[runedef.name].on_dig then
|
||||
if mana.get(digger:get_player_name()) >= runedef.needed_mana then
|
||||
runes.datas.handlers[runedef.name].on_dig(pos, oldnode, digger)
|
||||
mana.subtract(digger:get_player_name(),runedef.needed_mana)
|
||||
if runes.datas.handlers[runedef.name].on_place then
|
||||
if mana.get(placer:get_player_name()) >= runedef.needed_mana[level] then
|
||||
local answer = runes.datas.handlers[runedef.name].on_place(level, pos, placer, itemstack, pointed_thing)
|
||||
-- True answer leads to no dicrease (generally because the handler did it itself)
|
||||
if not answer then
|
||||
mana.subtract(placer:get_player_name(),runedef.needed_mana[level])
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(digger:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")")
|
||||
minetest.chat_send_player(placer:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana[level] ..")")
|
||||
end
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
if runes.datas.handlers[runedef.name].can_dig then
|
||||
return runes.datas.handlers[runedef.name].can_dig(level, pos, player)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end,
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
if runes.datas.handlers[runedef.name].on_punch then
|
||||
if mana.get(puncher:get_player_name()) >= runedef.needed_mana[level] then
|
||||
runes.datas.handlers[runedef.name].on_punch(level, pos, node, puncher, pointed_thing)
|
||||
mana.subtract(puncher:get_player_name(),runedef.needed_mana[level])
|
||||
else
|
||||
minetest.chat_send_player(puncher:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana[level] ..")")
|
||||
end
|
||||
end
|
||||
end,
|
||||
--[[after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
--if runes.datas.handlers[runedef.name].can_dig and runes.datas.handlers[runedef.name].can_dig(pos, digger) then
|
||||
if runes.datas.handlers[runedef.name].on_dig then
|
||||
if mana.get(digger:get_player_name()) >= runedef.needed_mana[level] then
|
||||
runes.datas.handlers[runedef.name].on_dig(pos, oldnode, digger)
|
||||
mana.subtract(digger:get_player_name(),runedef.needed_mana)
|
||||
else
|
||||
minetest.chat_send_player(digger:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana[level] ..")")
|
||||
end
|
||||
end
|
||||
end
|
||||
end,]]
|
||||
})
|
||||
end
|
||||
|
||||
elseif runedef.type == "plate" then
|
||||
for _, level in pairs({"minor", "medium", "major"}) do
|
||||
minetest.register_node("runes:rune_" .. runedef.name .. "_" .. level, {
|
||||
description = runedef.desc .. " (" .. level .. ")",
|
||||
paramtype = "light",
|
||||
inventory_image = runedef.img[level],
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
tiles = {runedef.img[level]},
|
||||
groups = {rune = 1, oddly_breakable_by_hand = 2},
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.499, 0.5},
|
||||
}
|
||||
},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if placer and placer:is_player() then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name())
|
||||
end
|
||||
if runes.datas.handlers[runedef.name].on_place then
|
||||
if mana.get(placer:get_player_name()) >= runedef.needed_mana[level] then
|
||||
local answer = runes.datas.handlers[runedef.name].on_place(level, pos, placer, itemstack, pointed_thing)
|
||||
if not answer then
|
||||
mana.subtract(placer:get_player_name(),runedef.needed_mana[level])
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(placer:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana[level] ..")")
|
||||
end
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
if runes.datas.handlers[runedef.name].can_dig then
|
||||
return runes.datas.handlers[runedef.name].can_dig(level, pos, player)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end,
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
if runes.datas.handlers[runedef.name].on_punch then
|
||||
if mana.get(placer:get_player_name()) >= runedef.needed_mana[level] then
|
||||
local answer = runes.datas.handlers[runedef.name].on_punch(level, pos, node, puncher, pointed_thing)
|
||||
if not answer then
|
||||
mana.subtract(placer:get_player_name(),runedef.needed_mana[level])
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(placer:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana[level] ..")")
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
elseif runedef.type == "craftitem" then
|
||||
for _, level in pairs({"minor", "medium", "major"}) do
|
||||
minetest.register_craftitem("runes:rune_" .. runedef.name .. "_" .. level, {
|
||||
description = runedef.desc .. " (" .. level ..")",
|
||||
inventory_image = runedef.img[level],
|
||||
groups = {rune = 1},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
-- Let the handler do its job
|
||||
if runes.datas.handlers[runedef.name].on_use then
|
||||
if mana.get(user:get_player_name()) >= runedef.needed_mana[level] then
|
||||
local answer = runes.datas.handlers[runedef.name].on_use(level, itemstack, user, pointed_thing)
|
||||
if not answer then
|
||||
mana.subtract(user:get_player_name(),runedef.needed_mana[level])
|
||||
user:get_inventory():remove_item("main",{name = runedef.name .. "_" .. level})
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(user:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana[level] ..")")
|
||||
end
|
||||
end
|
||||
end
|
||||
end,]]
|
||||
})
|
||||
|
||||
elseif runedef.type == "plate" then
|
||||
minetest.register_node("runes:rune_" .. runedef.name, {
|
||||
description = runedef.desc,
|
||||
paramtype = "light",
|
||||
inventory_image = runedef.img,
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
tiles = {runedef.img},
|
||||
groups = {rune = 1, oddly_breakable_by_hand = 2},
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.499, 0.5},
|
||||
}
|
||||
},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if placer and placer:is_player() then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name())
|
||||
end
|
||||
if runes.datas.handlers[runedef.name].on_place then
|
||||
if mana.get(placer:get_player_name()) >= runedef.needed_mana then
|
||||
runes.datas.handlers[runedef.name].on_place(pos, placer, itemstack, pointed_thing)
|
||||
mana.subtract(placer:get_player_name(),runedef.needed_mana)
|
||||
else
|
||||
minetest.chat_send_player(placer:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")")
|
||||
end
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
if runes.datas.handlers[runedef.name].can_dig then
|
||||
return runes.datas.handlers[runedef.name].can_dig(pos, player)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end,
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
if runes.datas.handlers[runedef.name].on_punch then
|
||||
runes.datas.handlers[runedef.name].on_punch(pos, node, puncher, pointed_thing)
|
||||
end
|
||||
end,
|
||||
})
|
||||
elseif runedef.type == "craftitem" then
|
||||
minetest.register_craftitem("runes:rune_" .. runedef.name, {
|
||||
description = runedef.desc,
|
||||
inventory_image = runedef.img,
|
||||
groups = {rune = 1},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
-- Let the handler do its job
|
||||
if runes.datas.handlers[runedef.name].on_use then
|
||||
if mana.get(user:get_player_name()) >= runedef.needed_mana then
|
||||
runes.datas.handlers[runedef.name].on_use(itemstack, user, pointed_thing)
|
||||
mana.subtract(user:get_player_name(),runedef.needed_mana)
|
||||
user:get_inventory():remove_item("main",{name = runedef.name})
|
||||
else
|
||||
minetest.chat_send_player(user:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")")
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,8 +1,14 @@
|
||||
-- Use handlers for runes
|
||||
|
||||
-- Every handler must receive as arguments the default callback arguments and
|
||||
-- as first argument the power level of the rune as a string which can be :
|
||||
-- `minor` : Low level
|
||||
-- `medium` : Medium level
|
||||
-- `major` : High level
|
||||
|
||||
-- First, the functions
|
||||
|
||||
projection = function(itemstack, user, pointed_thing)
|
||||
projection = function(runelevel, itemstack, user, pointed_thing)
|
||||
if pointed_thing.type == "object" then
|
||||
local dir = vector.direction(user:getpos(),pointed_thing.ref:getpos())
|
||||
local v = pointed_thing.ref:getvelocity() or {x=0,y=0,z=0}
|
||||
@ -12,7 +18,7 @@ projection = function(itemstack, user, pointed_thing)
|
||||
end
|
||||
end
|
||||
|
||||
damage_around = function(itemstack, user, pointed_thing)
|
||||
damage_around = function(runelevel, itemstack, user, pointed_thing)
|
||||
for name,entity in pairs(minetest.get_objects_inside_radius(user:getpos(),10)) do
|
||||
if true and (entity:is_player() and entity:get_player_name() ~= user:get_player_name()) then
|
||||
entity:set_hp(1)
|
||||
@ -20,21 +26,21 @@ damage_around = function(itemstack, user, pointed_thing)
|
||||
end
|
||||
end
|
||||
|
||||
earthquake = function(itemstack, user, pointed_thing)
|
||||
earthquake = function(runelevel, itemstack, user, pointed_thing)
|
||||
for name,entity in pairs(minetest.get_objects_inside_radius(user:getpos(),10)) do
|
||||
local v = entity:getvelocity() or {x=0,y=0,z=0}
|
||||
entity:setvelocity({x=v.x, y=v.y+50, z=v.z})
|
||||
end
|
||||
end
|
||||
|
||||
add_owner = function(pos, placer, itemstack, pointed_thing)
|
||||
add_owner = function(runelevel, pos, placer, itemstack, pointed_thing)
|
||||
if placer and placer:is_player() then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner",placer:get_player_name())
|
||||
end
|
||||
end
|
||||
|
||||
is_owner_online = function(pos)
|
||||
is_owner_online = function(runelevel, pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_string("owner") ~= nil then
|
||||
return minetest.get_player_by_name(meta:get_string("owner")) ~= nil
|
||||
@ -43,7 +49,7 @@ is_owner_online = function(pos)
|
||||
end
|
||||
end
|
||||
|
||||
is_owner = function(pos, player)
|
||||
is_owner = function(runelevel, pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_string("owner") ~= nil and player:get_player_name() then
|
||||
return meta:get_string("owner") == player:get_player_name()
|
||||
@ -52,7 +58,7 @@ is_owner = function(pos, player)
|
||||
end
|
||||
end
|
||||
|
||||
go_to_me = function(pos, node, digger)
|
||||
go_to_me = function(runelevel, pos, node, digger)
|
||||
if digger and is_owner_online(pos) and not (minetest.get_meta(pos):get_string("owner") == digger:get_player_name()) then
|
||||
digger:setpos(minetest.get_player_by_name(minetest.get_meta(pos):get_string("owner")):getpos())
|
||||
mana.subtract(minetest.get_meta(pos):get_string("owner"), 5)
|
||||
@ -61,7 +67,7 @@ go_to_me = function(pos, node, digger)
|
||||
end
|
||||
end
|
||||
|
||||
set_manamax = function(itemstack, user, pointed_thing)
|
||||
set_manamax = function(runelevel, itemstack, user, pointed_thing)
|
||||
if user and user:is_player() then
|
||||
mana.set(user:get_player_name(),mana.getmax(user:get_player_name()))
|
||||
if not minetest.get_player_privs(user:get_player_name()).server then
|
||||
|
@ -3,51 +3,65 @@
|
||||
runes.datas.items = {
|
||||
["project"] = {
|
||||
description = "Projection rune",
|
||||
img = "runes_projection.png",
|
||||
img = "runes_projection",
|
||||
type = "craftitem",
|
||||
needed_mana = 30
|
||||
needed_mana = {
|
||||
["minor"] = 15,
|
||||
["medium"] = 30,
|
||||
["major"] = 45,
|
||||
},
|
||||
},
|
||||
["damager"] = {
|
||||
description = "Damaging rune",
|
||||
img = "runes_damaging.png",
|
||||
img = "runes_damaging",
|
||||
type = "craftitem",
|
||||
needed_mana = 190
|
||||
needed_mana = {
|
||||
["minor"] = 180,
|
||||
["medium"] = 190,
|
||||
["major"] = 230
|
||||
}
|
||||
},
|
||||
["earthquake"] = {
|
||||
description = "Earth Quake rune",
|
||||
img = "runes_earthquake.png",
|
||||
img = "runes_earthquake",
|
||||
type = "craftitem",
|
||||
needed_mana = 80
|
||||
needed_mana = {
|
||||
["minor"] = 70,
|
||||
["medium"] = 80,
|
||||
["major"] = 90
|
||||
}
|
||||
},
|
||||
["simple_heal"] = {
|
||||
description = "Simple healing rune",
|
||||
img = "runes_simple_heal.png",
|
||||
type = "cube"
|
||||
},
|
||||
["improved_heal"] = {
|
||||
description = "Improved healing rune",
|
||||
img = "runes_improved_heal.png",
|
||||
type = "cube"
|
||||
},
|
||||
["perfect_heal"] = {
|
||||
description = "Perfect healing rune",
|
||||
img = "runes_perfect_heal.png",
|
||||
["heal"] = {
|
||||
description = "Healing rune",
|
||||
img = "runes_heal",
|
||||
type = "cube"
|
||||
},
|
||||
["gotome"] = {
|
||||
description = "Go to me rune",
|
||||
img = "runes_go_to_me.png",
|
||||
img = "runes_go_to_me",
|
||||
type = "cube",
|
||||
needed_mana = 50
|
||||
needed_mana = {
|
||||
["minor"] = 40,
|
||||
["medium"] = 50,
|
||||
["major"] = 75
|
||||
}
|
||||
},
|
||||
["megamana"] = {
|
||||
description = "Mega Mana",
|
||||
img = "default_diamond.png",
|
||||
img = {
|
||||
["minor"] = "default_diamond.png",
|
||||
["medium"] = "default_diamond.png",
|
||||
["major"] = "default_diamond.png"
|
||||
},
|
||||
type = "craftitem"
|
||||
},
|
||||
["popper"] = {
|
||||
description = "Popper",
|
||||
img = "default_grass.png",
|
||||
img = {
|
||||
["minor"] = "default_grass.png",
|
||||
["medium"] = "default_grass.png",
|
||||
["major"] = "default_grass.png"
|
||||
},
|
||||
type = "plate"
|
||||
},
|
||||
}
|
||||
|
BIN
mods/runes/textures/runes_damaging_major.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
mods/runes/textures/runes_damaging_medium.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
mods/runes/textures/runes_damaging_minor.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
mods/runes/textures/runes_earthquake_major.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
mods/runes/textures/runes_earthquake_medium.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
mods/runes/textures/runes_earthquake_minor.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
mods/runes/textures/runes_go_to_me_major.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
mods/runes/textures/runes_go_to_me_medium.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
mods/runes/textures/runes_go_to_me_minor.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
@ -31,9 +31,9 @@ local time_next_regen_check = time_total_regen_check
|
||||
-- TODO: make this globally accessible
|
||||
local mana_from_node = {
|
||||
['default:goldblock'] = 5,
|
||||
['runes:rune_simple_heal'] = 1,
|
||||
['runes:rune_improved_heal'] = 3,
|
||||
['runes:rune_perfect_heal'] = 8,
|
||||
['runes:rune_heal_minor'] = 1,
|
||||
['runes:rune_heal_medium'] = 3,
|
||||
['runes:rune_heal_major'] = 8,
|
||||
['default:wood'] = 1,
|
||||
['default:junglewood'] = 1,
|
||||
['default:pinewood'] = 1,
|
||||
@ -92,14 +92,13 @@ minetest.register_globalstep(function(dtime)
|
||||
|
||||
for key, value in pairs(mana_from_node) do
|
||||
if key:split(":")[1] == "group" then
|
||||
groupname = key:split(":")[2]
|
||||
local groupname = key:split(":")[2]
|
||||
if minetest.get_node_group(node.name, groupname) > 0 then
|
||||
regen_to = math.max(regen_to, value) -- We get the greater one (if the node is part of 2 or more groups)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
mana.setregen(name, regen_to)
|
||||
--print("Regen to "..regen_to.." : "..light_day.."/"..light_now.."/"..light_night)
|
||||
end
|
||||
|