mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-07 19:10:23 +01:00
Added base of runes mod
- Added rune API's first implementation - Added basic cubic runes in solarmana
This commit is contained in:
parent
19374b7057
commit
af3bb78c3f
11
mods/runes/README.md
Normal file
11
mods/runes/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
Rune mod by Mg
|
||||
##############
|
||||
|
||||
# Purpose
|
||||
This mod proposes 3 runes used in the balance of solarmana.
|
||||
|
||||
# Authors
|
||||
- Mg (@LeMagnesium)
|
||||
|
||||
# Medias
|
||||
<none atm>
|
113
mods/runes/api.lua
Normal file
113
mods/runes/api.lua
Normal file
|
@ -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
|
2
mods/runes/depends.txt
Normal file
2
mods/runes/depends.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
mana
|
59
mods/runes/handlers.lua
Normal file
59
mods/runes/handlers.lua
Normal file
|
@ -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)
|
15
mods/runes/init.lua
Normal file
15
mods/runes/init.lua
Normal file
|
@ -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")
|
48
mods/runes/registration.lua
Normal file
48
mods/runes/registration.lua
Normal file
|
@ -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
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user