Add wards.

master
Beha 2017-01-03 23:23:06 -05:00
parent 4d97feb048
commit 4047375d69
4 changed files with 92 additions and 5 deletions

View File

@ -37,6 +37,24 @@ function kingdoms.can_dig(r, pos, name)
return true
end
function kingdoms.check_claimward(r, pos, name)
if not name or not pos then return false end
local kingdom = kingdoms.player.kingdom(name)
local positions = minetest.find_nodes_in_area(
{x = pos.x - r, y = pos.y - r, z = pos.z - r},
{x = pos.x + r, y = pos.y + r, z = pos.z + r},
{"kingdoms:claimward"})
for _, pos in ipairs(positions) do
local nodename = minetest.get_node(pos).name
local meta = minetest.get_meta(pos)
local kid = meta:get_string("kingdom.id")
if (not kingdom or kid ~= kingdom.id) and kingdoms.db.kingdoms[kid] then
return false
end
end
return true
end
function kingdoms.check_pos_level(pos, name, level, message)
local akingdom = kingdoms.bypos(pos)
local pkingdom = kingdoms.player.kingdom(name)
@ -149,12 +167,17 @@ minetest.register_node("kingdoms:corestone", {
local radius = kingdoms.config.corestone_radius * kingdoms.config.corestone_overlap_multiplier
kingdoms.spm(false)
local canplace = not kingdoms.can_dig(radius, pointed_thing.under, placer:get_player_name()) or not kingdoms.can_dig(radius, pointed_thing.above, placer:get_player_name())
local cantplace = not kingdoms.can_dig(radius, pointed_thing.under, placer:get_player_name()) or not kingdoms.can_dig(radius, pointed_thing.above, placer:get_player_name())
local cantplaceward = not kingdoms.check_claimward(kingdoms.config.corestone_radius, pointed_thing.above, placer:get_player_name()) or not kingdoms.check_claimward(kingdoms.config.corestone_radius, pointed_thing.under, placer:get_player_name())
kingdoms.spm(true)
if canplace then
if cantplace then
minetest.chat_send_player(placer:get_player_name(), "You cannot place a corestone this close to another.")
return itemstack
end
if cantplaceward then
minetest.chat_send_player(placer:get_player_name(), "You cannot place a corestone this close to an opposing claim ward.")
return itemstack
end
kingdom.corestone.pos = pointed_thing.above
kingdom.corestone.placed = os.time()
@ -200,6 +223,62 @@ minetest.register_abm{
action = function(pos) build_infotext(pos, "Corestone") end,
}
minetest.register_node("kingdoms:claimward", {
description = "Claim Ward",
drawtype = "nodebox",
tiles = {"kingdoms_claimward.png"},
sounds = default.node_sound_stone_defaults(),
groups = {oddly_breakable_by_hand = 2, unbreakable = 1},
is_ground_content = false,
paramtype = "light",
light_source = 0,
node_box = {
type = "fixed",
fixed = {
{-0.5 ,-0.5, -0.5, 0.5, 0.5, 0.5},
}
},
on_place = function(itemstack, placer, pointed_thing)
if not placer or pointed_thing.type ~= "node" then
return itemstack
end
local kingdom = kingdoms.player.kingdom(placer:get_player_name())
if not kingdom then
minetest.chat_send_player(placer:get_player_name(), "You cannot place a ward if you are not a member of a kingdom.")
return itemstack
end
local radius = kingdoms.config.corestone_radius
kingdoms.spm(false)
local cantplace = not kingdoms.can_dig(radius, pointed_thing.under, placer:get_player_name()) or not kingdoms.can_dig(radius, pointed_thing.above, placer:get_player_name())
kingdoms.spm(true)
if cantplace then
minetest.chat_send_player(placer:get_player_name(), "You cannot place a ward this close to another corestone.")
return itemstack
end
return minetest.item_place(itemstack, placer, pointed_thing)
end,
after_place_node = function(pos, placer)
local kingdom = kingdoms.player.kingdom(placer:get_player_name())
local meta = minetest.get_meta(pos)
meta:set_string("kingdom.id", kingdom.id)
build_infotext(pos, "Claim ward")
end,
})
minetest.register_abm{
nodenames = {"kingdoms:claimward"},
interval = 1,
chance = 1,
action = function(pos) build_infotext(pos, "Claim ward") end,
}
minetest.register_node("kingdoms:servercorestone", {
description = "Server Core",
drawtype = "nodebox",
@ -240,12 +319,17 @@ minetest.register_node("kingdoms:servercorestone", {
local radius = kingdoms.config.corestone_radius * kingdoms.config.corestone_overlap_multiplier
kingdoms.spm(false)
local canplace = not kingdoms.can_dig(radius, pointed_thing.under, placer:get_player_name()) or not kingdoms.can_dig(radius, pointed_thing.above, placer:get_player_name())
local cantplace = not kingdoms.can_dig(radius, pointed_thing.under, placer:get_player_name()) or not kingdoms.can_dig(radius, pointed_thing.above, placer:get_player_name())
local cantplaceward = not kingdoms.check_claimward(kingdoms.config.corestone_radius, pointed_thing.above, placer:get_player_name()) or not kingdoms.check_claimward(kingdoms.config.corestone_radius, pointed_thing.under, placer:get_player_name())
kingdoms.spm(true)
if canplace then
if cantplace then
minetest.chat_send_player(placer:get_player_name(), "You cannot place a corestone this close to another.")
return itemstack
end
if cantplaceward then
minetest.chat_send_player(placer:get_player_name(), "You cannot place a corestone this close to an opposing claim ward.")
return itemstack
end
kingdoms.db.servercorestone = pointed_thing.above

View File

@ -4,3 +4,6 @@ minetest.register_craft({
{'default:chest_locked', 'default:steel_ingot'},
}
})
-- kingdoms:corestone
-- kingdoms:claimward

View File

@ -13,7 +13,7 @@ minetest.register_globalstep(function(dtime)
local akingdom = kingdoms.bypos(pos)
kingdoms.spm(false)
local infostrings = {
akingdom and ("This area is owned by %s"):format(akingdom.longname) or ((kingdoms.can_dig(kingdoms.config.corestone_radius * kingdoms.config.corestone_overlap_multiplier, pos, "") and pos.y >= kingdoms.config.corestone_miny) and "This area is neutral and available." or "This area is neutral."),
akingdom and ("This area is owned by %s"):format(akingdom.longname) or ((kingdoms.can_dig(kingdoms.config.corestone_radius * kingdoms.config.corestone_overlap_multiplier, pos, "") and pos.y >= kingdoms.config.corestone_miny and kingdoms.check_claimward(kingdoms.config.corestone_radius, pos, name)) and "This area is neutral and available for " ..(kingdoms.check_claimward(kingdoms.config.corestone_radius, pos, "") and "all" or "you").."." or "This area is neutral."),
pkingdom and ("You are a level %d member of %s"):format(kingdoms.player.kingdom_state(name).level, pkingdom.longname) or "You are neutral with "..kingdoms.utils.s("invitation", kingdoms.db.invitations[name] and #kingdoms.db.invitations[name] or 0)..".",
kingdoms.is_protected(pos, name) and "You cannot dig here." or "You can dig here.",
"Your current chat channel is: "..kingdoms.chat_channels[kingdoms.current_chat_channel(name)].name,

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B