[runes] Add glyphs and stylus
234
mods/runes/glyphs.lua
Normal file
@ -0,0 +1,234 @@
|
||||
-- A stylus to inscribe glyphs
|
||||
-- Part of a Rune Mod Redo
|
||||
-- By Mg, 2016
|
||||
-- License : WTFPL
|
||||
--
|
||||
|
||||
runes.glyphs = {}
|
||||
|
||||
minetest.register_tool("runes:stylus", {
|
||||
description = "Stylus",
|
||||
inventory_image = "runes_stylus.png",
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if not user or pointed_thing.type ~= "node" then return end
|
||||
|
||||
local node = minetest.get_node_or_nil(pointed_thing.under)
|
||||
if not node or not minetest.registered_nodes[node.name].walkable then
|
||||
return
|
||||
end
|
||||
|
||||
node = minetest.get_node_or_nil(pointed_thing.above)
|
||||
if not node or node.name ~= "air" then
|
||||
return
|
||||
end
|
||||
|
||||
local main_inv = user:get_inventory():get_list("main")
|
||||
local scroll = main_inv[user:get_wield_index()-1]
|
||||
if not scroll then
|
||||
minetest.chat_send_player(user:get_player_name(), "There is no scroll before the stylus in your inventory!")
|
||||
return
|
||||
elseif minetest.get_item_group(scroll:get_name(), "scroll") == 0 then
|
||||
minetest.chat_send_player(user:get_player_name(), "The item before your stylus is not a scroll of knowledge!")
|
||||
return
|
||||
end
|
||||
|
||||
local name = scroll:get_name():gsub("runes:scroll_", "")
|
||||
if not runes.scrolls[name] then return end
|
||||
local glyph = runes.scrolls[name].glyph
|
||||
if not glyph then return end
|
||||
|
||||
if mana.get(user:get_player_name()) < runes.glyphs[name].mana_cost then
|
||||
minetest.chat_send_player(user:get_player_name(), "You need " .. runes.glyphs[name].mana_cost .. " of mana to inscribe that glyph")
|
||||
return
|
||||
end
|
||||
|
||||
-- Calculate param2 manually since MineTest doesn't even do it
|
||||
local diff = vector.subtract(pointed_thing.under, pointed_thing.above)
|
||||
|
||||
minetest.add_node(pointed_thing.above, {name = glyph, param2 = minetest.dir_to_wallmounted(diff)})
|
||||
minetest.get_meta(pointed_thing.above):set_string("master", user:get_player_name())
|
||||
|
||||
itemstack:add_wear(65535 / 30)
|
||||
mana.subtract(user:get_player_name(), runes.glyphs[name].mana_cost)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "runes:stylus",
|
||||
recipe = {
|
||||
{"", "default:obsidian_shard", "moreores:mithril_ingot"},
|
||||
{"default:obsidian_shard", "default:nyancat_rainbow", "default:obsidian_shard"},
|
||||
{"default:obsidian_shard", "default:obsidian_shard", ""},
|
||||
},
|
||||
})
|
||||
|
||||
function register_glyph(name, basics, tab)
|
||||
--[[ Basics can contain :
|
||||
- texture = "runes_glyph_unknown.png",
|
||||
- description = "Mysterious Glyph",
|
||||
- initial_charge = 0
|
||||
- mana_cost = 0
|
||||
--]]
|
||||
|
||||
runes.glyphs[name] = {}
|
||||
runes.glyphs[name].mana_cost = basics.mana_cost or 0
|
||||
|
||||
def = table.copy(tab)
|
||||
def.groups.glyph = 1
|
||||
|
||||
def.description = basics.description or "Mysterious Glyph"
|
||||
def.inventory_image = basics.texture or "runes_glyph_unknown.png"
|
||||
def.tiles = {basics.texture or "default_stone.png"}
|
||||
def.on_construct = function(pos)
|
||||
minetest.get_meta(pos):set_int("charge", (basics.initial_charge or 0))
|
||||
tab.on_construct(pos)
|
||||
end
|
||||
|
||||
def.drawtype = "signlike"
|
||||
def.paramtype = "light"
|
||||
def.paramtype2 = "wallmounted"
|
||||
def.selection_box = {
|
||||
type = "wallmounted",
|
||||
wall_top = {-0.5, 0.4, -0.5, 0.5, 0.5, 0.5},
|
||||
wall_bottom = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5},
|
||||
wall_side = {-0.5, -0.5, -0.5, -0.4, 0.5, 0.5},
|
||||
}
|
||||
def.walkable = false
|
||||
|
||||
minetest.register_node("runes:glyph_" .. name, def)
|
||||
end
|
||||
|
||||
|
||||
register_glyph("watchdog", {
|
||||
description = "Watch Dog Glyph",
|
||||
texture = "runes_glyph_watchdog.png",
|
||||
initial_charge = 250,
|
||||
mana_cost = 10,
|
||||
}, {
|
||||
light_source = 8,
|
||||
groups = {snappy = 1},
|
||||
on_construct = function(pos)
|
||||
minetest.get_node_timer(pos):start(0.2)
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("charge") <= 0 then
|
||||
minetest.add_particlespawner({
|
||||
amount = 10,
|
||||
minpos = pos, maxpos = pos,
|
||||
minvel = vel, maxvel = vector.multiply(vel, 3),
|
||||
minacc = 0, maxacc = 0,
|
||||
minexptime = 3, maxexptime = 4,
|
||||
minsize = 1, maxsize = 1,
|
||||
collisiondetection = true,
|
||||
vertical = false,
|
||||
texture = "runes_glyph_watchdog.png",
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
for _, ref in pairs(minetest.get_objects_inside_radius(pos, 3)) do
|
||||
if ref and not ref:get_armor_groups().immortal then
|
||||
if not ref:is_player() or ref.is_fake_player or not meta:get_string("master") or meta:get_string("master") == "" or ref:get_player_name() ~= meta:get_string("master") then
|
||||
ref:set_hp(ref:get_hp() - 1)
|
||||
meta:set_int("charge", (meta:get_int("charge") or 1) - 1)
|
||||
local collisionbox = ref:get_properties().collisionbox
|
||||
local refpos = ref:getpos()
|
||||
refpos.y = refpos.y + (((collisionbox[4] or 0) - (collisionbox[3] or 0)) / 2)
|
||||
|
||||
local vel = vector.subtract(refpos, pos)
|
||||
minetest.add_particlespawner({
|
||||
amount = 30,
|
||||
minpos = pos, maxpos = pos,
|
||||
minvel = vel, maxvel = vector.multiply(vel, 3),
|
||||
minacc = 0, maxacc = 0,--vector.multiply(vel, 3),
|
||||
minexptime = 1, maxexptime = 1,
|
||||
minsize = 2, maxsize = 5,
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = "runes_glyph_watchdog.png",
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
}
|
||||
)
|
||||
|
||||
register_glyph("manasucker", {
|
||||
description = "Mana Sucker Glyph",
|
||||
texture = "runes_glyph_manasucker.png",
|
||||
initial_charge = 100,
|
||||
mana_cost = 20,
|
||||
}, {
|
||||
groups = {snappy = 1},
|
||||
on_construct = function(pos)
|
||||
minetest.get_node_timer(pos):start(3)
|
||||
minetest.get_meta(pos):set_int("mana", 0)
|
||||
end,
|
||||
on_punch = function(pos, _, puncher)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_string("master") and puncher:is_player() and not puncher.is_fake_player and puncher:get_player_name() == meta:get_string("master") then
|
||||
local k = meta:get_int("mana")
|
||||
local name = puncher:get_player_name()
|
||||
local o = mana.getmax(name) - mana.get(name)
|
||||
local u = 0
|
||||
|
||||
if k > o then
|
||||
u = k - mana.getmax(name)
|
||||
mana.set(name, o)
|
||||
else
|
||||
mana.add(name, k)
|
||||
end
|
||||
|
||||
meta:set_int("mana", u)
|
||||
end
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("charge") <= 0 then
|
||||
return true
|
||||
end
|
||||
|
||||
local more_mana = 0
|
||||
for _, ref in pairs(minetest.get_objects_inside_radius(pos, 5)) do
|
||||
if ref and ref:is_player() and not ref.is_fake_player and (not meta:get_string("master") or meta:get_string("master") == "" or meta:get_string("master") ~= ref:get_player_name()) then
|
||||
local burst = math.random(10, 40)
|
||||
local manalevel = mana.get(ref:get_player_name())
|
||||
|
||||
if manalevel > 0 then
|
||||
if manalevel < burst then
|
||||
mana.set(ref:get_player_name(), 0)
|
||||
more_mana = more_mana + manalevel
|
||||
else
|
||||
mana.subtract(ref:get_player_name(), burst)
|
||||
more_mana = more_mana + burst
|
||||
end
|
||||
|
||||
local collisionbox = ref:get_properties().collisionbox
|
||||
local refpos = ref:getpos()
|
||||
refpos.y = refpos.y + (((collisionbox[4] or 0) - (collisionbox[3] or 0)) / 2)
|
||||
|
||||
local vel = vector.subtract(pos, refpos)
|
||||
minetest.add_particlespawner({
|
||||
amount = 30,
|
||||
minpos = refpos, maxpos = refpos,
|
||||
minvel = vel, maxvel = vel,
|
||||
minacc = 0, maxacc = 0,--vector.multiply(vel, 3),
|
||||
minexptime = 1, maxexptime = 1,
|
||||
minsize = 1, maxsize = 1,
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = "runes_glyph_manasucker.png",
|
||||
})
|
||||
meta:set_int("charge", meta:get_int("charge") - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
meta:set_int("mana", meta:get_int("mana") + more_mana)
|
||||
return true
|
||||
end
|
||||
}
|
||||
)
|
@ -3,6 +3,8 @@
|
||||
|
||||
local modpath = minetest.get_modpath("runes")
|
||||
|
||||
runes = {}
|
||||
|
||||
-- API first
|
||||
dofile(modpath.."/api.lua")
|
||||
|
||||
@ -15,4 +17,12 @@ dofile(modpath.."/handlers.lua")
|
||||
-- The amulets
|
||||
dofile(modpath.."/amulets.lua")
|
||||
|
||||
---- From this point everything is redo ----
|
||||
|
||||
-- Stylus
|
||||
dofile(modpath .. "/glyphs.lua")
|
||||
|
||||
-- Scrolls
|
||||
dofile(modpath .. "/scrolls.lua")
|
||||
|
||||
minetest.log("action","[runes] Mod loaded")
|
||||
|
35
mods/runes/scrolls.lua
Normal file
@ -0,0 +1,35 @@
|
||||
-- Scrolls for Runes Redo
|
||||
--
|
||||
|
||||
runes.scrolls = {}
|
||||
|
||||
function register_scroll(name, type, data)
|
||||
if not data then return end
|
||||
|
||||
def = {
|
||||
inventory_image = (data.texture or "runes_scroll_unknown.png"),
|
||||
groups = {scroll = 1},
|
||||
description = (data.description or "Mysterious Scroll"),
|
||||
}
|
||||
|
||||
minetest.register_craftitem("runes:scroll_" .. name, def)
|
||||
runes.scrolls[name] = {}
|
||||
|
||||
if type == "knowledge" and data.glyph then
|
||||
runes.scrolls[name].glyph = data.glyph
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
register_scroll("watchdog", "knowledge", {
|
||||
glyph = "runes:glyph_watchdog",
|
||||
texture = "runes_scroll_watchdog.png",
|
||||
description = "Watch Dog Knowledge Scroll"
|
||||
})
|
||||
|
||||
register_scroll("manasucker", "knowledge", {
|
||||
glyph = "runes:glyph_manasucker",
|
||||
texture = "runes_scroll_manasucker.png",
|
||||
description = "Mana Sucker Knowledge Scroll",
|
||||
})
|
BIN
mods/runes/textures/runes_glyph_deus_ex_machina.png
Normal file
After Width: | Height: | Size: 418 B |
BIN
mods/runes/textures/runes_glyph_manasucker.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
mods/runes/textures/runes_glyph_spontafire.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
mods/runes/textures/runes_glyph_watchdog.png
Normal file
After Width: | Height: | Size: 173 B |
BIN
mods/runes/textures/runes_scroll_deus_ex_machina.png
Normal file
After Width: | Height: | Size: 410 B |
BIN
mods/runes/textures/runes_scroll_manasucker.png
Normal file
After Width: | Height: | Size: 215 B |
BIN
mods/runes/textures/runes_scroll_unknown.png
Normal file
After Width: | Height: | Size: 209 B |
BIN
mods/runes/textures/runes_scroll_watchdog.png
Normal file
After Width: | Height: | Size: 257 B |
BIN
mods/runes/textures/runes_stylus.png
Normal file
After Width: | Height: | Size: 247 B |