falling_light/staves.lua

365 lines
10 KiB
Lua
Raw Normal View History

2016-08-21 16:25:45 +01:00
minetest.register_privilege("staffer","Trust players to use staves")
vivarium.forbidden_nodes = {
"default:stone_with",
"moreores:mineral_",
"default:nyancat",
".+steelblock", -- lua does not include the "|" operator which is a PAIN.
".+copperblock",
".+bronzeblock",
".+goldblock",
".+diamondblock",
".+tin_block",
".+silver_block",
".+mithril_block",
"default:mese",
"protector:",
2016-08-21 16:27:37 +01:00
"basic_machines:",
2016-08-21 16:25:45 +01:00
"ethereal:crystal_spike",
".+crystal_block",
"mobs:beehive",
"mobs:spawner",
"more_chests:"
}
function vivarium:tellem(player,message)
minetest.chat_send_player(player:get_player_name() , message)
end
function vivarium:wearitem(itemstack,maxuses)
itemstack:add_wear(math.ceil(65536/maxuses))
return itemstack
end
2016-08-21 16:25:45 +01:00
function staffcheck(player)
local stafflevel = 0
if minetest.check_player_privs(player:get_player_name(), {staffer=true}) then stafflevel = 1; end
if minetest.check_player_privs(player:get_player_name(), {creative=true}) then stafflevel = 100; end
2016-08-21 19:17:07 +01:00
--minetest.chat_send_all("Staff level : "..stafflevel)
2016-08-21 16:25:45 +01:00
return stafflevel
end
function isforbidden(nodename)
for _,pat in pairs(vivarium.forbidden_nodes) do
if string.match(nodename,pat) then
2016-08-21 19:17:07 +01:00
--minetest.chat_send_all("Forbidden : "..nodename)
2016-08-21 16:25:45 +01:00
return true
end
end
return false
end
function bomf(pos,radius)
minetest.add_particlespawner(
200, --amount
0.1, --time
{x=pos.x-radius/2, y=pos.y-radius/2, z=pos.z-radius/2}, --minpos
{x=pos.x+radius/2, y=pos.y+radius/2, z=pos.z+radius/2}, --maxpos
{x=-0, y=-0, z=-0}, --minvel
{x=1, y=1, z=1}, --maxvel
{x=-0.5,y=5,z=-0.5}, --minacc
{x=0.5,y=5,z=0.5}, --maxacc
0.1, --minexptime
1, --maxexptime
3, --minsize
4, --maxsize
false, --collisiondetection
"tnt_smoke.png" --texture
)
minetest.sound_play("vivarium_pom", {
pos = pos,
max_hear_distance = 10
})
end
function vivarium:mobheal(user,luae)
if not luae.owner or user:get_player_name() ~= luae.owner then
vivarium:tellem(user,"This " ..luae.name .. " is not yours.")
return
end
if luae.health < luae.hp_min then
luae.health = luae.hp_min
vivarium:tellem(user,"Your " ..luae.name .. " has been healed.")
else
vivarium:tellem(user,"This " ..luae.name .. " does not need healing.")
end
end
function vivarium:mobtransform(user,luae, forced)
if not forced and math.random(1,20) > 1 then return ; end -- 1:20 chance of transforming
luae.state="walk"
if luae.type == "monster" then
luae.type="npc"
luae.attacks_monsters=true
vivarium:tellem(user,luae.name .. " became a friendly NPC")
elseif luae.type == "npc" then
luae.type = "animal"
vivarium:tellem(user,luae.name .. " became a docile animal")
elseif luae.type == "animal" then
luae.type = "monster"
luae.passive = false
vivarium:tellem(user,luae.name .. " became a vicious monster")
end
end
-- Staff of X (based on Staff of Light by Xanthin)
2016-08-20 12:00:03 +01:00
2016-08-18 18:46:04 +01:00
minetest.register_tool("vivarium:staff_stack", { -- this will be the wall staff
2016-08-21 16:25:45 +01:00
description = "Column Staff (make walls)",
2016-08-18 18:35:39 +01:00
inventory_image = "water_staff.png^[colorize:yellow:90",
wield_image = "water_staff.png^[colorize:yellow:90",
range = 12,
2016-08-18 18:35:39 +01:00
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
2016-08-21 16:25:45 +01:00
local stafflevel = staffcheck(user)
if stafflevel < 1 then return; end
2016-08-18 18:35:39 +01:00
if pointed_thing.type ~= "node" then
2016-08-21 16:25:45 +01:00
if stafflevel < 2 then return; end
if pointed_thing.type == "object" then
local newpos = pointed_thing.ref:getpos()
bomf(newpos,2 )
local luae = pointed_thing.ref:get_luaentity()
2016-08-20 13:53:06 +01:00
vivarium:mobtransform(user,luae,true)
end
2016-08-18 18:35:39 +01:00
return
end
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
local height = 5
2016-08-18 18:35:39 +01:00
local targetnode = minetest.get_node(pos).name
local userpos = user:getpos()
2016-08-18 18:46:04 +01:00
2016-08-18 18:35:39 +01:00
local relpos = (userpos.y - pos.y)/math.sqrt((userpos.y - pos.y)^2)
2016-08-18 18:46:04 +01:00
local lower = 0 ; local higher = 0
2016-08-21 16:25:45 +01:00
if isforbidden(targetnode) and stafflevel < 2 then
targetnode = "default:dirt"
end
2016-08-18 18:46:04 +01:00
if relpos < 0 then
2016-08-18 20:47:32 +01:00
-- minetest.chat_send_player(pname, "Stack down")
2016-08-18 18:46:04 +01:00
lower = -1*height
2016-08-21 16:25:45 +01:00
elseif relpos >= 0 then
2016-08-18 20:47:32 +01:00
-- minetest.chat_send_player(pname, "Stack up")
2016-08-18 18:46:04 +01:00
higher = height
end
2016-08-18 18:35:39 +01:00
local airnodes = minetest.find_nodes_in_area(
2016-08-18 18:46:04 +01:00
{x = pos.x, y = pos.y+lower, z = pos.z},
{x = pos.x, y = pos.y+higher, z = pos.z},
2016-08-21 16:25:45 +01:00
{"air","default:water_source","default:lava_source","default:river_water_source"}
2016-08-18 18:35:39 +01:00
)
bomf(pos,2)
2016-08-18 18:35:39 +01:00
for _,fpos in pairs(airnodes) do
minetest.swap_node(fpos, {name = targetnode })
end
if staffcheck(user) < 90 then itemstack = vivarium:wearitem(itemstack,50); end
2016-08-18 18:35:39 +01:00
return itemstack
end,
})
2016-08-16 18:57:33 +01:00
minetest.register_tool("vivarium:staff_clone", { -- this will be the floor staff
2016-08-21 16:25:45 +01:00
description = "Staff of Cloning (make floors)",
2016-08-18 18:35:39 +01:00
inventory_image = "water_staff.png^[colorize:green:90",
wield_image = "water_staff.png^[colorize:green:90",
range = 12,
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
2016-08-21 16:25:45 +01:00
local stafflevel = staffcheck(user)
if stafflevel < 1 then return; end
if pointed_thing.type ~= "node" then
2016-08-21 16:25:45 +01:00
if stafflevel < 2 then -- can only clone mobs if super staffer else abuse
return
end
if pointed_thing.type == "object" then
local newpos = pointed_thing.ref:getpos()
newpos = {x=newpos.x+math.random(-1,1), y=newpos.y+0.5, z=newpos.z+math.random(-1,1)}
bomf(newpos,2 )
minetest.add_entity(newpos, pointed_thing.ref:get_luaentity().name)
end
return
end
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
2016-08-16 18:57:33 +01:00
local breadth = 2 -- full square is 2*breadth+1 on side
local targetnode = minetest.get_node(pos).name
local userpos = user:getpos()
--[[
2016-08-16 18:57:33 +01:00
local relpos = 0
if (userpos.y - pos.y)^2 > 2 then -- if clearly above/below
relpos = (userpos.y - pos.y)/math.sqrt((userpos.y - pos.y)^2)
end
--]]
2016-08-21 16:25:45 +01:00
if isforbidden(targetnode) and stafflevel < 2 then
targetnode = "default:dirt"
end
2016-08-16 18:57:33 +01:00
local airnodes = minetest.find_nodes_in_area(
{x = pos.x - breadth, y = pos.y, z = pos.z - breadth},
{x = pos.x + breadth, y = pos.y, z = pos.z + breadth},
2016-08-21 16:25:45 +01:00
{"air","default:water_source","default:lava_source","default:river_water_source"}
2016-08-16 18:57:33 +01:00
)
bomf(pos,breadth*2)
2016-08-16 18:57:33 +01:00
for _,fpos in pairs(airnodes) do
minetest.swap_node(fpos, {name = targetnode })
end
if staffcheck(user) < 90 then itemstack = vivarium:wearitem(itemstack,50); end
2016-08-16 18:57:33 +01:00
return itemstack
end,
})
2016-08-21 16:25:45 +01:00
minetest.register_tool("vivarium:staff_boom", {
description = "Bomf Staff (delete nodes)",
inventory_image = "water_staff.png^[colorize:black:140",
wield_image = "water_staff.png^[colorize:black:140",
range = 12,
2016-08-18 19:35:08 +01:00
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
2016-08-21 16:25:45 +01:00
local stafflevel = staffcheck(user)
if stafflevel < 2 then return; end
2016-08-18 19:35:08 +01:00
if pointed_thing.type ~= "node" then
if pointed_thing.type == "object" then
bomf(pointed_thing.ref:getpos(),1 )
pointed_thing.ref:remove()
end
2016-08-18 19:35:08 +01:00
return
end
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
local radius = 3
local targetnode = minetest.get_node(pos).name
local userpos = user:getpos()
local targetnodes = minetest.find_nodes_in_area(
{x = pos.x - radius, y = pos.y-radius, z = pos.z - radius},
{x = pos.x + radius, y = pos.y+radius, z = pos.z + radius},
{targetnode}
)
bomf(pos,radius)
2016-08-18 19:35:08 +01:00
for _,fpos in pairs(targetnodes) do
minetest.swap_node(fpos, {name = "air" })
end
return itemstack
end,
})
2016-08-16 18:57:33 +01:00
-- quick and dirty tool to repair carnage caused by NSSM ice mobs
minetest.register_tool("vivarium:staff_melt", {
2016-08-21 18:11:32 +01:00
description = "Staff of Melting (Fix Ice Mobs damage)",
2016-08-18 18:35:39 +01:00
inventory_image = "water_staff.png^[colorize:blue:90",
wield_image = "water_staff.png^[colorize:blue:90",
2016-08-16 18:57:33 +01:00
range = 12,
stack_max = 1,
on_use = function(itemstack, user, pointed_thing)
2016-08-16 18:57:33 +01:00
if pointed_thing.type ~= "node" then
if pointed_thing.type == "object" then
local newpos = pointed_thing.ref:getpos()
bomf(newpos,2 )
local luae = pointed_thing.ref:get_luaentity()
vivarium:mobheal(user,luae)
vivarium:mobtransform(user,luae)
end
2016-08-16 18:57:33 +01:00
return
end
2016-08-16 18:57:33 +01:00
local pos = pointed_thing.under
local pname = user:get_player_name()
if minetest.is_protected(pos, pname) then
minetest.record_protection_violation(pos, pname)
return
end
local breadth = 2 -- full square is 2*breadth+1 on side
2016-08-18 18:35:39 +01:00
local frostarea = minetest.find_nodes_in_area(
2016-08-16 18:57:33 +01:00
{x = pos.x - breadth, y = pos.y, z = pos.z - breadth},
{x = pos.x + breadth, y = pos.y, z = pos.z + breadth},
{"default:ice","default:snowblock"}
)
bomf(pos,breadth*2)
2016-08-18 18:35:39 +01:00
for _,fpos in pairs(frostarea) do
2016-08-16 18:57:33 +01:00
local replname = minetest.get_node({x=fpos.x,y=fpos.y-1,z=fpos.z}).name
if replname == "default:ice" or replname == "default:snowblock" then
2016-08-18 18:35:39 +01:00
local newreplname = minetest.get_node({x=fpos.x,y=fpos.y+1,z=fpos.z}).name
if newreplname ~= "air" then -- don't dig down so much
-- TODO if replname == air, then get average node around that is not air, use that
replname = newreplname
end
2016-08-16 18:57:33 +01:00
end
2016-08-18 18:35:39 +01:00
local sealevel = 0 -- TODO get the custom setting for sealevel
if fpos.y > 0 and replname == "default:water_source" then -- don't bother with water above sea level
2016-08-16 18:57:33 +01:00
replname = "air"
end
2016-08-21 19:17:07 +01:00
--minetest.chat_send_all("Replicating "..replname)
2016-08-21 19:14:27 +01:00
if isforbidden(replname) then
replname = "default:dirt"
2016-08-21 18:54:00 +01:00
end
2016-08-16 18:57:33 +01:00
minetest.swap_node(fpos, {name = replname })
end
if staffcheck(user) < 90 then itemstack = vivarium:wearitem(itemstack,50); end
2016-08-16 18:57:33 +01:00
return itemstack
end,
})
2016-08-16 18:57:33 +01:00
minetest.register_craft(
{
output = "vivarium:staff_melt",
recipe = {
{"default:mese_crystal_fragment","bucket:bucket_lava","default:mese_crystal_fragment"},
{"","default:obsidian_shard",""},
{"","default:obsidian_shard",""},
}
}
)