forked from mtcontrib/factions
commit
bd3c2b4432
114
chatcommands.lua
114
chatcommands.lua
@ -100,10 +100,10 @@ factions.register_command = function(cmd_name, cmd)
|
||||
|
||||
-- get some more data
|
||||
local pos = minetest.get_player_by_name(player):getpos()
|
||||
local chunkpos = factions.get_chunk_pos(pos)
|
||||
return self.on_success(player, player_faction, pos, chunkpos, args)
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
return self.on_success(player, player_faction, pos, parcelpos, args)
|
||||
end,
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
minetest.chat_send_player(player, "Not implemented yet!")
|
||||
end
|
||||
}
|
||||
@ -159,22 +159,22 @@ end
|
||||
factions.register_command ("claim", {
|
||||
faction_permissions = {"claim"},
|
||||
description = "Claim the plot of land you're on.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
local can_claim = faction:can_claim_chunk(chunkpos)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local can_claim = faction:can_claim_parcel(parcelpos)
|
||||
if can_claim then
|
||||
minetest.chat_send_player(player, "Claming chunk "..chunkpos)
|
||||
faction:claim_chunk(chunkpos)
|
||||
minetest.chat_send_player(player, "Claming parcel "..parcelpos)
|
||||
faction:claim_parcel(parcelpos)
|
||||
return true
|
||||
else
|
||||
local chunk = factions.chunks[chunkpos]
|
||||
if not chunk then
|
||||
send_error(player, "You faction cannot claim any (more) chunk(s).")
|
||||
local parcel = factions.parcels[parcelpos]
|
||||
if not parcel then
|
||||
send_error(player, "You faction cannot claim any (more) parcel(s).")
|
||||
return false
|
||||
elseif chunk == faction.name then
|
||||
send_error(player, "This chunk already belongs to your faction.")
|
||||
elseif parcel == faction.name then
|
||||
send_error(player, "This parcel already belongs to your faction.")
|
||||
return false
|
||||
else
|
||||
send_error(player, "This chunk belongs to another faction.")
|
||||
send_error(player, "This parcel belongs to another faction.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -184,13 +184,13 @@ factions.register_command ("claim", {
|
||||
factions.register_command("unclaim", {
|
||||
faction_permissions = {"claim"},
|
||||
description = "Unclaim the plot of land you're on.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
local chunk = factions.chunks[chunkpos]
|
||||
if chunk ~= faction.name then
|
||||
send_error(player, "This chunk does not belong to you.")
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local parcel = factions.parcels[parcelpos]
|
||||
if parcel ~= faction.name then
|
||||
send_error(player, "This parcel does not belong to you.")
|
||||
return false
|
||||
else
|
||||
faction:unclaim_chunk(chunkpos)
|
||||
faction:unclaim_parcel(parcelpos)
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -200,7 +200,7 @@ factions.register_command("unclaim", {
|
||||
factions.register_command("list", {
|
||||
description = "List all registered factions.",
|
||||
infaction = false,
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local list = factions.get_faction_list()
|
||||
local tosend = "Existing factions:"
|
||||
|
||||
@ -219,7 +219,7 @@ factions.register_command("list", {
|
||||
--show factions mod version
|
||||
factions.register_command("version", {
|
||||
description = "Displays mod version.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
minetest.chat_send_player(player, "factions: version " .. factions_version , false)
|
||||
end
|
||||
})
|
||||
@ -228,7 +228,7 @@ factions.register_command("version", {
|
||||
factions.register_command("info", {
|
||||
format = {"faction"},
|
||||
description = "Shows a faction's description.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
minetest.chat_send_player(player,
|
||||
"factions: " .. args.factions[1].name .. ": " ..
|
||||
args.factions[1].description, false)
|
||||
@ -238,7 +238,7 @@ factions.register_command("info", {
|
||||
|
||||
factions.register_command("leave", {
|
||||
description = "Leave your faction.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:remove_player(player)
|
||||
return true
|
||||
end
|
||||
@ -248,7 +248,7 @@ factions.register_command("kick", {
|
||||
faction_permissions = {"playerslist"},
|
||||
format = {"player"},
|
||||
description = "Kick a player from your faction.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local victim = args.players[1]
|
||||
if factions.players[victim.name] == faction.name
|
||||
and victim.name ~= faction.leader then -- can't kick da king
|
||||
@ -266,7 +266,7 @@ factions.register_command("create", {
|
||||
format = {"string"},
|
||||
infaction = false,
|
||||
description = "Create a new faction.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if faction then
|
||||
send_error(player, "You are already in a faction.")
|
||||
return false
|
||||
@ -287,11 +287,11 @@ factions.register_command("join", {
|
||||
format = {"faction"},
|
||||
description = "Join a faction.",
|
||||
infaction = false,
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local new_faction = args.factions[1]
|
||||
if new_faction:can_join(player) then
|
||||
if player_faction then -- leave old faction
|
||||
player_faction:remove_player(player)
|
||||
if faction then -- leave old faction
|
||||
faction:remove_player(player)
|
||||
end
|
||||
new_faction:add_player(player)
|
||||
else
|
||||
@ -305,7 +305,7 @@ factions.register_command("join", {
|
||||
factions.register_command("disband", {
|
||||
faction_permissions = {"disband"},
|
||||
description = "Disband your faction.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:disband()
|
||||
return true
|
||||
end
|
||||
@ -314,7 +314,7 @@ factions.register_command("disband", {
|
||||
factions.register_command("close", {
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Make your faction invite-only.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:toggle_join_free(false)
|
||||
--TODO: message
|
||||
return true
|
||||
@ -324,7 +324,7 @@ factions.register_command("close", {
|
||||
factions.register_command("open", {
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Allow any player to join your faction.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:toggle_join_free(true)
|
||||
--TODO: message
|
||||
return true
|
||||
@ -334,7 +334,7 @@ factions.register_command("open", {
|
||||
factions.register_command("description", {
|
||||
faction_permissions = {"description"},
|
||||
description = "Set your faction's description",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:set_description(table.concat(args.other," "))
|
||||
--TODO: message
|
||||
return true
|
||||
@ -345,7 +345,7 @@ factions.register_command("invite", {
|
||||
format = {"player"},
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Invite a player to your faction.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:invite_player(args.players[1]:get_player_name())
|
||||
--TODO: message
|
||||
return true
|
||||
@ -356,7 +356,7 @@ factions.register_command("uninvite", {
|
||||
format = {"player"},
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Revoke a player's invite.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:revoke_invite(args.players[1]:get_player_name())
|
||||
--TODO: message
|
||||
return true
|
||||
@ -368,7 +368,7 @@ factions.register_command("delete", {
|
||||
format = {"faction"},
|
||||
infaction = false,
|
||||
description = "Delete a faction.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
args.factions[1]:disband()
|
||||
--TODO: message
|
||||
return true
|
||||
@ -377,7 +377,7 @@ factions.register_command("delete", {
|
||||
|
||||
factions.register_command("ranks", {
|
||||
description = "List ranks within your faction",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
for rank, permissions in pairs(faction.ranks) do
|
||||
minetest.chat_send_player(player, rank..": "..table.concat(permissions, " "))
|
||||
end
|
||||
@ -387,14 +387,14 @@ factions.register_command("ranks", {
|
||||
|
||||
factions.register_command("who", {
|
||||
description = "List players in your faction, and their ranks.",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if not faction.players then
|
||||
minetest.chat_send_player(player, "There is nobody in this faction ("..faction.name..")")
|
||||
return true
|
||||
end
|
||||
minetest.chat_send_player(player, "Players in faction "..faction.name..": ")
|
||||
for player, rank in pairs(faction.players) do
|
||||
minetest.chat_send_player(player, player.." ("..rank..")")
|
||||
for p, rank in pairs(faction.players) do
|
||||
minetest.chat_send_player(player, p.." ("..rank..")")
|
||||
end
|
||||
return true
|
||||
end
|
||||
@ -404,7 +404,7 @@ factions.register_command("newrank", {
|
||||
description = "Add a new rank.",
|
||||
format = {"string"},
|
||||
faction_permissions = {"ranks"},
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local rank = args.strings[1]
|
||||
if faction.ranks[rank] then
|
||||
--TODO: rank already exists
|
||||
@ -419,7 +419,7 @@ factions.register_command("delrank", {
|
||||
description = "Replace and delete a rank.",
|
||||
format = {"string", "string"},
|
||||
faction_permissions = {"ranks"},
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local rank = args.strings[1]
|
||||
local newrank = args.strings[2]
|
||||
if not faction.ranks[rank] or not faction.ranks[rank] then
|
||||
@ -434,18 +434,18 @@ factions.register_command("delrank", {
|
||||
factions.register_command("setspawn", {
|
||||
description = "Set the faction's spawn",
|
||||
faction_permissions = {"spawn"},
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:set_spawn(pos)
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
factions.register_command("where", {
|
||||
description = "See whose chunk you stand on.",
|
||||
description = "See whose parcel you stand on.",
|
||||
infaction = false,
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
local chunk = factions.chunks[chunkpos]
|
||||
minetest.chat_send_player(player, "You are standing on chunk "..chunkpos..", part of "..(chunk or "Wilderness"))
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local parcel = factions.parcels[parcelpos]
|
||||
minetest.chat_send_player(player, "You are standing on parcel "..parcelpos..", part of "..(parcel or "Wilderness"))
|
||||
return true
|
||||
end
|
||||
})
|
||||
@ -453,7 +453,7 @@ factions.register_command("where", {
|
||||
factions.register_command("help", {
|
||||
description = "Shows help for commands.",
|
||||
infaction = false,
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
factions_chat.show_help(player)
|
||||
return true
|
||||
end
|
||||
@ -461,7 +461,7 @@ factions.register_command("help", {
|
||||
|
||||
factions.register_command("spawn", {
|
||||
description = "Shows your faction's spawn",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if faction.spawn then
|
||||
minetest.chat_send_player(player, "Spawn is at ("..table.concat(faction.spawn, ", ")..")")
|
||||
return true
|
||||
@ -476,7 +476,7 @@ factions.register_command("promote", {
|
||||
description = "Promotes a player to a rank",
|
||||
format = {"player", "string"},
|
||||
faction_permissions = {"promote"},
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local rank = args.strings[1]
|
||||
if faction.ranks[rank] then
|
||||
faction:promote(args.players[1], rank)
|
||||
@ -490,7 +490,7 @@ factions.register_command("promote", {
|
||||
|
||||
factions.register_command("power", {
|
||||
description = "Display your faction's power",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
minetest.chat_send_player(player, "Power: "..faction.power)
|
||||
return true
|
||||
end
|
||||
@ -499,7 +499,7 @@ factions.register_command("power", {
|
||||
factions.register_command("setbanner", {
|
||||
description = "Sets the banner you're on as the faction's banner.",
|
||||
faction_permissions = {"banner"},
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local meta = minetest.get_meta({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||
local banner = meta:get_string("banner")
|
||||
if not banner then
|
||||
@ -515,7 +515,7 @@ factions.register_command("convert", {
|
||||
infaction = false,
|
||||
global_privileges = {"faction_admin"},
|
||||
format = {"string"},
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if factions.convert(args.strings[1]) then
|
||||
minetest.chat_send_player(player, "Factions successfully converted.")
|
||||
else
|
||||
@ -526,23 +526,23 @@ factions.register_command("convert", {
|
||||
})
|
||||
|
||||
factions.register_command("free", {
|
||||
description = "Forcefully frees a chunk",
|
||||
description = "Forcefully frees a parcel",
|
||||
infaction = false,
|
||||
global_privileges = {"faction_admin"},
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
local fac = factions.chunks[chunkpos]
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local fac = factions.parcels[parcelpos]
|
||||
if not fac then
|
||||
send_error(player, "No claim at this position")
|
||||
return false
|
||||
end
|
||||
faction:unclaim_chunk(chunkpos)
|
||||
faction:unclaim_parcel(parcelpos)
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
factions.register_command("chat", {
|
||||
description = "Send a message to your faction's members",
|
||||
on_success = function(player, faction, pos, chunkpos, args)
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local msg = table.concat(args.other, " ")
|
||||
faction:broadcast(msg, player)
|
||||
end
|
||||
@ -562,7 +562,7 @@ factions_chat.cmdhandler = function (playername,parameter)
|
||||
|
||||
local player = minetest.env:get_player_by_name(playername)
|
||||
local params = parameter:split(" ")
|
||||
local player_faction = factions.players[playersname]
|
||||
local player_faction = factions.players[playername]
|
||||
|
||||
if parameter == nil or
|
||||
parameter == "" then
|
||||
|
142
factions.lua
142
factions.lua
@ -21,14 +21,14 @@ factions = {}
|
||||
|
||||
--! @brief runtime data
|
||||
factions.factions = {}
|
||||
factions.chunks = {}
|
||||
factions.parcels = {}
|
||||
factions.players = {}
|
||||
|
||||
|
||||
factions.factions = {}
|
||||
--- settings
|
||||
factions.lower_laimable_height = -512
|
||||
factions.power_per_chunk = .5
|
||||
factions.protection_max_depth = -512
|
||||
factions.power_per_parcel = .5
|
||||
|
||||
---------------------
|
||||
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
||||
@ -57,7 +57,7 @@ factions.Faction.__index = factions.Faction
|
||||
-- Faction permissions:
|
||||
--
|
||||
-- disband: disband the faction
|
||||
-- claim: (un)claim chunks
|
||||
-- claim: (un)claim parcels
|
||||
-- playerslist: invite/kick players and open/close the faction
|
||||
-- build: dig and place nodes
|
||||
-- description: set the faction's description
|
||||
@ -68,7 +68,7 @@ factions.Faction.__index = factions.Faction
|
||||
|
||||
function factions.Faction:new(faction)
|
||||
faction = {
|
||||
--! @brief power of a faction (needed for chunk claiming)
|
||||
--! @brief power of a faction (needed for parcel claiming)
|
||||
power = 0.,
|
||||
--! @brief maximum power of a faction
|
||||
maxpower = 0.,
|
||||
@ -89,14 +89,14 @@ function factions.Faction:new(faction)
|
||||
description = "Default faction description.",
|
||||
--! @brief list of players currently invited (can join with /f join)
|
||||
invited_players = {},
|
||||
--! @brief table of claimed chunks (keys are chunkpos strings)
|
||||
--! @brief table of claimed parcels (keys are parcelpos strings)
|
||||
land = {},
|
||||
--! @brief table of allies
|
||||
allies = {},
|
||||
--! @brief table of enemies
|
||||
enemies = {},
|
||||
--! @brief table of chunks/factions that are under attack
|
||||
attacked_chunks = {},
|
||||
--! @brief table of parcels/factions that are under attack
|
||||
attacked_parcels = {},
|
||||
--! @brief whether faction is closed or open (boolean)
|
||||
join_free = false,
|
||||
--! @brief banner texture string
|
||||
@ -112,6 +112,7 @@ factions.new_faction = function(name)
|
||||
local faction = factions.Faction:new(nil)
|
||||
faction.name = name
|
||||
factions.factions[name] = faction
|
||||
faction:on_create()
|
||||
factions.save()
|
||||
return faction
|
||||
end
|
||||
@ -141,52 +142,53 @@ function factions.Faction.remove_player(self, player)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @param chunkpos position of the wanted chunk
|
||||
--! @return whether this faction can claim a chunkpos
|
||||
function factions.Faction.can_claim_chunk(self, chunkpos)
|
||||
local fac = factions.chunks[chunkpos]
|
||||
--! @param parcelpos position of the wanted parcel
|
||||
--! @return whether this faction can claim a parcelpos
|
||||
function factions.Faction.can_claim_parcel(self, parcelpos)
|
||||
local fac = factions.parcels[parcelpos]
|
||||
if fac then
|
||||
if factions.factions[fac].power < 0. and self.power >= factions.power_per_chunk then
|
||||
if factions.factions[fac].power < 0. and self.power >= factions.power_per_parcel then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
elseif self.power < factions.power_per_chunk then
|
||||
elseif self.power < factions.power_per_parcel then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--! @brief claim a chunk, update power and update global chunks table
|
||||
function factions.Faction.claim_chunk(self, chunkpos)
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.Faction.claim_parcel(self, parcelpos)
|
||||
-- check if claiming over other faction's territory
|
||||
local otherfac = factions.chunks[chunkpos]
|
||||
local otherfac = factions.parcels[parcelpos]
|
||||
if otherfac then
|
||||
local faction = factions.factions[otherfac]
|
||||
faction:unclaim_chunk(chunkpos)
|
||||
faction:unclaim_parcel(parcelpos)
|
||||
end
|
||||
factions.chunks[chunkpos] = self.name
|
||||
self.land[chunkpos] = true
|
||||
self:decrease_power(factions.power_per_chunk)
|
||||
self:on_claim_chunk(chunkpos)
|
||||
factions.save()
|
||||
end
|
||||
--! @brief claim a chunk, update power and update global chunks table
|
||||
function factions.Faction.unclaim_chunk(self, chunkpos)
|
||||
factions.chunks[chunkpos] = nil
|
||||
self.land[chunkpos] = nil
|
||||
self:increase_power(factions.power_per_chunk)
|
||||
self:on_unclaim_chunk(chunkpos)
|
||||
factions.parcels[parcelpos] = self.name
|
||||
self.land[parcelpos] = true
|
||||
self:decrease_power(factions.power_per_parcel)
|
||||
self:on_claim_parcel(parcelpos)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @brief disband faction, updates global players and chunks table
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.Faction.unclaim_parcel(self, parcelpos)
|
||||
factions.parcels[parcelpos] = nil
|
||||
self.land[parcelpos] = nil
|
||||
self:increase_power(factions.power_per_parcel)
|
||||
self:on_unclaim_parcel(parcelpos)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @brief disband faction, updates global players and parcels table
|
||||
function factions.Faction.disband(self)
|
||||
for k, _ in pairs(self.players) do -- remove players affiliation
|
||||
factions.players[k] = nil
|
||||
end
|
||||
for k, v in pairs(self.land) do -- remove chunk claims
|
||||
factions.chunks[k] = nil
|
||||
for k, v in pairs(self.land) do -- remove parcel claims
|
||||
factions.parcels[k] = nil
|
||||
end
|
||||
self:on_disband()
|
||||
factions.factions[self.name] = nil
|
||||
@ -303,16 +305,19 @@ function factions.Faction.delete_rank(self, rank, newrank)
|
||||
self:on_delete_rank(rank, newrank)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @param newbanner texture string of the new banner
|
||||
function factions.Faction.set_banner(self, newbanner)
|
||||
self.banner = newbanner
|
||||
self:on_new_banner()
|
||||
end
|
||||
|
||||
--! @brief set a player's rank
|
||||
function factions.Faction.promote(self, member, rank)
|
||||
self.players[member] = rank
|
||||
self:on_promote(member)
|
||||
end
|
||||
|
||||
--! @brief send a message to all members
|
||||
function factions.Faction.broadcast(self, msg, sender)
|
||||
local message = self.name.."> "..msg
|
||||
@ -330,61 +335,78 @@ end
|
||||
function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list
|
||||
minetest.chat_send_all("Faction "..self.name.." has been created.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_player_leave(self, player)
|
||||
self:broadcast(player.." has left this faction.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_player_join(self, player)
|
||||
self:broadcast(player.." has joined this faction.")
|
||||
end
|
||||
function factions.Faction.on_claim_chunk(self, pos)
|
||||
self:broadcast("Chunk ("..pos..") has been claimed.")
|
||||
|
||||
function factions.Faction.on_claim_parcel(self, pos)
|
||||
self:broadcast("Parcel ("..pos..") has been claimed.")
|
||||
end
|
||||
function factions.Faction.on_unclaim_chunk(self, pos)
|
||||
self:broadcast("Chunk ("..pos..") has been unclaimed.")
|
||||
|
||||
function factions.Faction.on_unclaim_parcel(self, pos)
|
||||
self:broadcast("Parcel ("..pos..") has been unclaimed.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_disband(self, pos)
|
||||
minetest.chat_send_all("Faction "..self.name.." has been disbanded.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_new_leader(self)
|
||||
self:broadcast(self.leader.." is now the leader of this faction.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_change_description(self)
|
||||
self:broadcast("Faction description has been modified to: "..self.description)
|
||||
end
|
||||
|
||||
function factions.Faction.on_player_invited(self, player)
|
||||
minetest.chat_send_player(player, "You have been invited to faction "..self.name)
|
||||
end
|
||||
|
||||
function factions.Faction.on_toggle_join_free(self, player)
|
||||
self:broadcast("This faction is now invite-free.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_new_alliance(self, faction)
|
||||
self:broadcast("This faction is now allied with "..faction)
|
||||
end
|
||||
|
||||
function factions.Faction.on_end_alliance(self, faction)
|
||||
self:broadcast("This faction is no longer allied with "..faction.."!")
|
||||
end
|
||||
|
||||
function factions.Faction.on_set_spawn(self)
|
||||
self:broadcast("The faction spawn has been set to ("..util.coords3D_string(pos)..").")
|
||||
end
|
||||
|
||||
function factions.Faction.on_add_rank(self, rank)
|
||||
self:broadcast("The rank "..rank.." has been created with privileges: "..table.concat(self.ranks[rank], ", "))
|
||||
end
|
||||
|
||||
function factions.Faction.on_delete_rank(self, rank, newrank)
|
||||
self:broadcast("The rank "..rank.." has been deleted and replaced by "..newrank)
|
||||
end
|
||||
|
||||
function factions.Faction.on_new_banner(self)
|
||||
self:broadcast("A new banner has been set.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_promote(self, member)
|
||||
minetest.chat_send_player(player, "You have been promoted to "..self.players[member])
|
||||
minetest.chat_send_player(member, "You have been promoted to "..self.players[member])
|
||||
end
|
||||
|
||||
function factions.Faction.on_revoke_invite(self, player)
|
||||
minetest.chat_send_player(player, "You are no longer invited to faction "..self.name)
|
||||
end
|
||||
|
||||
--??????????????
|
||||
|
||||
function factions.get_chunk_pos(pos)
|
||||
function factions.get_parcel_pos(pos)
|
||||
return math.floor(pos.x / 16.)..","..math.floor(pos.z / 16.)
|
||||
end
|
||||
|
||||
@ -471,15 +493,18 @@ function factions.load()
|
||||
local raw_data = file:read("*a")
|
||||
factions.factions = minetest.deserialize(raw_data)
|
||||
for facname, faction in pairs(factions.factions) do
|
||||
faction.attacked_parcels = {}
|
||||
faction.maxpower = 0.
|
||||
minetest.log("action", facname..","..faction.name)
|
||||
for player, rank in pairs(faction.players) do
|
||||
minetest.log("action", player..","..rank)
|
||||
factions.players[player] = facname
|
||||
end
|
||||
for chunkpos, val in pairs(faction.land) do
|
||||
factions.chunks[chunkpos] = facname
|
||||
for parcelpos, val in pairs(faction.land) do
|
||||
factions.parcels[parcelpos] = facname
|
||||
end
|
||||
setmetatable(faction, factions.Faction)
|
||||
-- compatiblity and later additions
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
@ -506,9 +531,9 @@ function factions.convert(filename)
|
||||
for player, _ in pairs(attrs.invitations) do
|
||||
newfac:invite_player(player)
|
||||
end
|
||||
for i in ipairs(attrs.chunk) do
|
||||
local chunkpos = table.concat(attrs.chunk[i],",")
|
||||
newfac:claim_chunk(chunkpos)
|
||||
for i in ipairs(attrs.parcel) do
|
||||
local parcelpos = table.concat(attrs.parcel[i],",")
|
||||
newfac:claim_parcel(parcelpos)
|
||||
end
|
||||
end
|
||||
for player, attrs in pairs(objects) do
|
||||
@ -535,8 +560,8 @@ minetest.register_globalstep(
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
local player = playerslist[i]
|
||||
local chunkpos = factions.get_chunk_pos(player:getpos())
|
||||
local faction = factions.chunks[chunkpos]
|
||||
local parcelpos = factions.get_parcel_pos(player:getpos())
|
||||
local faction = factions.parcels[parcelpos]
|
||||
player:hud_remove("factionLand")
|
||||
player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
@ -576,13 +601,28 @@ minetest.register_on_respawnplayer(
|
||||
|
||||
local default_is_protected = minetest.is_protected
|
||||
minetest.is_protected = function(pos, player)
|
||||
local chunkpos = factions.get_chunk_pos(pos)
|
||||
local faction = factions.chunks[chunkpos]
|
||||
if not faction then
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
local parcel_faction = factions.parcels[parcelpos]
|
||||
local player_faction = factions.players[player]
|
||||
if pos.y < factions.protection_max_depth then
|
||||
return false
|
||||
end
|
||||
if factions.disallow_edit_nofac and not player_faction then
|
||||
return true
|
||||
end
|
||||
if not parcel_faction then
|
||||
return default_is_protected(pos, player)
|
||||
else
|
||||
faction = factions.factions[faction]
|
||||
return not faction:has_permission(player, "build")
|
||||
parcel_faction = factions.factions[parcel_faction]
|
||||
if parcel_faction.attacked_parcels[parcelpos] then -- chunk is being attacked
|
||||
if parcel_faction.attacked_parcels[parcelpos][player_faction] then -- attacked by the player's faction
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
else
|
||||
return not parcel_faction:has_permission(player, "build")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user