From af3bb78c3fbb1b0d208259a33932ea1043853bee Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Thu, 23 Apr 2015 18:04:58 +0200 Subject: [PATCH] Added base of runes mod - Added rune API's first implementation - Added basic cubic runes in solarmana --- mods/runes/README.md | 11 ++++ mods/runes/api.lua | 113 ++++++++++++++++++++++++++++++++++++ mods/runes/depends.txt | 2 + mods/runes/handlers.lua | 59 +++++++++++++++++++ mods/runes/init.lua | 15 +++++ mods/runes/registration.lua | 48 +++++++++++++++ mods/solarmana/init.lua | 5 +- 7 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 mods/runes/README.md create mode 100644 mods/runes/api.lua create mode 100644 mods/runes/depends.txt create mode 100644 mods/runes/handlers.lua create mode 100644 mods/runes/init.lua create mode 100644 mods/runes/registration.lua diff --git a/mods/runes/README.md b/mods/runes/README.md new file mode 100644 index 00000000..fb3678b6 --- /dev/null +++ b/mods/runes/README.md @@ -0,0 +1,11 @@ +Rune mod by Mg +############## + +# Purpose +This mod proposes 3 runes used in the balance of solarmana. + +# Authors + - Mg (@LeMagnesium) + +# Medias + diff --git a/mods/runes/api.lua b/mods/runes/api.lua new file mode 100644 index 00000000..2e348e66 --- /dev/null +++ b/mods/runes/api.lua @@ -0,0 +1,113 @@ +-- API of the rune mod -- + +-- Global namespace +runes = {} +runes.datas = {} +runes.datas.handlers = {} +runes.datas.items = {} +runes.functions = {} + +-- Simple rune register function +runes.functions.register_rune = function(parameters) + local runedef = {} + + if not parameters.name then + minetest.log("ERROR","[runes] Cannot register rune : no name") + return + end + + runedef.name = parameters.name + runedef.desc = parameters.description or "" + runedef.img = parameters.img or "default_stone.png" + runedef.type = parameters.type or "craftitem" + runedef.needed_mana = parameters.needed_mana or 0 + + 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 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) + print(runes.datas.handlers[runedef.name].can_dig) + if runes.datas.handlers[runedef.name].can_dig then + return runes.datas.handlers[runedef.name].can_dig(pos, player) + else + return true + 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) + else + minetest.chat_send_player(digger:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")") + end + end + end + end,]] + }) + + elseif runedef.type == "plate" then + + 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) + else + minetest.chat_send_player(user:get_player_name(),"Not enough mana (needed : " .. runedef.needed_mana ..")") + end + end + end + }) + end +end + + +-- Handler connector +runes.functions.connect = function(itemname, callback, handler) + --[[ Available callback : + use + place + dig + can_dig + ]] + + if not runes.datas.items[itemname] then + minetest.log("error","[runes] Cannot connect handler at " .. handler .. " to unknown item " .. itemname) + return + end + + if callback == "use" then + runes.datas.handlers[itemname].on_use = handler + elseif callback == "place" then + runes.datas.handlers[itemname].on_place = handler + elseif callback == "dig" then + runes.datas.handlers[itemname].on_dig = handler + elseif callback == "can_dig" then + runes.datas.handlers[itemname].can_dig = handler + else + minetest.log("error","[runes] Cannot connect handler at " .. handler .. " to item's " .. itemname .. " unknown " .. callback .. " callback") + return + end +end diff --git a/mods/runes/depends.txt b/mods/runes/depends.txt new file mode 100644 index 00000000..49bb81b0 --- /dev/null +++ b/mods/runes/depends.txt @@ -0,0 +1,2 @@ +default +mana diff --git a/mods/runes/handlers.lua b/mods/runes/handlers.lua new file mode 100644 index 00000000..e0c72395 --- /dev/null +++ b/mods/runes/handlers.lua @@ -0,0 +1,59 @@ +-- Use handlers for runes + +-- First, the functions + +projection = function(itemstack, user, pointed_thing) + if pointed_thing.type == "object" then + local dir = vector.direction(user:getpos(),pointed_thing.ref:getpos()) + local ykb = 10 + if v.y ~= 0 then ykb = 0 end + pointed_thing.ref:setvelocity({x=dir.x*50,y=ykb,z=dir.z*50}) + end +end + +damage_around = function(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) + end + end +end + +earthquake = function(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) + 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) + local meta = minetest.get_meta(pos) + print(meta:get_string("owner")) + if meta:get_string("owner") ~= nil then + return minetest.get_player_by_name(meta:get_string("owner")) ~= nil + else + return true + end +end + +go_to_me = function(pos, node, digger) + if digger then + digger:setpos(minetest.get_player_by_name(minetest.get_meta(pos):get_string("owner")):getpos()) + end +end + +-- Then, connect + +runes.functions.connect("project","use",projection) +runes.functions.connect("damager","use",damage_around) +runes.functions.connect("earthquake","use",earthquake) +runes.functions.connect("gotome","place",add_owner) +runes.functions.connect("gotome","dig",go_to_me) +runes.functions.connect("gotome","can_dig",is_owner_online) diff --git a/mods/runes/init.lua b/mods/runes/init.lua new file mode 100644 index 00000000..9ab1219c --- /dev/null +++ b/mods/runes/init.lua @@ -0,0 +1,15 @@ +-- Rune mod by Mg +-- License GPLv3 + +local modpath = minetest.get_modpath("runes") + +-- API first +dofile(modpath.."/api.lua") + +-- Then the rune themselves +dofile(modpath.."/registration.lua") + +-- And the handlers +dofile(modpath.."/handlers.lua") + +minetest.log("action","[runes] Mod loaded") diff --git a/mods/runes/registration.lua b/mods/runes/registration.lua new file mode 100644 index 00000000..4ad771a2 --- /dev/null +++ b/mods/runes/registration.lua @@ -0,0 +1,48 @@ +-- Rune definitions : registration.lua + +runes.datas.items = { + ["project"] = { + description = "Projection rune", + img = "default_dirt.png", + type = "craftitem", + needed_mana = 30 + }, + ["damager"] = { + description = "Damaging rune", + img = "default_lava.png", + type = "craftitem", + needed_mana = 190 + }, + ["earthquake"] = { + description = "Earth Quake rune", + img = "default_apple.png", + type = "craftitem", + needed_mana = 80 + }, + ["simple_heal"] = { + description = "Simple healing rune", + img = "default_water.png", + type = "cube" + }, + ["improved_heal"] = { + description = "Improved healing rune", + img = "default_acid.png", + type = "cube" + }, + ["perfect_heal"] = { + description = "Perfect healing rune", + img = "default_lava.png", + type = "cube" + }, + ["gotome"] = { + description = "Go to me rune", + img = "default_wood.png", + type = "cube" + } +} + +for key, value in pairs(runes.datas.items) do + local runereg = table.copy(value) + runereg.name = key + runes.functions.register_rune(runereg) +end diff --git a/mods/solarmana/init.lua b/mods/solarmana/init.lua index 97d94b48..ecafaf61 100644 --- a/mods/solarmana/init.lua +++ b/mods/solarmana/init.lua @@ -30,7 +30,10 @@ local time_next_regen_check = time_total_regen_check -- TODO: make this globally accessible local mana_from_node = { - ['default:goldblock'] = 2, + ['default:goldblock'] = 5, + ['runes:rune_simple_heal'] = 1, + ['runes:rune_improved_heal'] = 3, + ['runes:rune_perfect_heal'] = 8, ['default:wood'] = 1, ['default:junglewood'] = 1, ['default:pinewood'] = 1,