Underpowered factions' chunks can now be claimed
This commit is contained in:
parent
b41f7bda72
commit
69ff206590
@ -160,16 +160,17 @@ 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 chunk = factions.chunks[chunkpos]
|
||||
if not chunk and faction:can_claim_chunk(chunkpos) then
|
||||
local can_claim = faction:can_claim_chunk(chunkpos)
|
||||
if can_claim then
|
||||
minetest.chat_send_player(player, "Claming chunk "..chunkpos)
|
||||
faction:claim_chunk(chunkpos)
|
||||
return true
|
||||
elseif not faction:can_claim_chunk(chunkpos) then
|
||||
send_error(player, "Chunk cannot be claimed.")
|
||||
return false
|
||||
else
|
||||
if chunk == faction.name then
|
||||
local chunk = factions.chunks[chunkpos]
|
||||
if not chunk then
|
||||
send_error(player, "You faction cannot claim any (more) chunk(s).")
|
||||
return false
|
||||
elseif chunk == faction.name then
|
||||
send_error(player, "This chunk already belongs to your faction.")
|
||||
return false
|
||||
else
|
||||
|
15
factions.lua
15
factions.lua
@ -105,13 +105,26 @@ function factions.Faction.remove_player(self, player)
|
||||
end
|
||||
|
||||
function factions.Faction.can_claim_chunk(self, chunkpos)
|
||||
if factions.chunks[chunkpos] or self.power < factions.power_per_chunk then
|
||||
local fac = factions.chunks[chunkpos]
|
||||
if fac then
|
||||
if factions.factions[fac].power < 0. and self.power >= factions.power_per_chunk then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
elseif self.power < factions.power_per_chunk then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function factions.Faction.claim_chunk(self, chunkpos)
|
||||
-- check if claiming over other faction's territory
|
||||
local otherfac = factions.chunks[chunkpos]
|
||||
if otherfac then
|
||||
local faction = factions.factions[otherfac]
|
||||
faction:unclaim_chunk(chunkpos)
|
||||
end
|
||||
factions.chunks[chunkpos] = self.name
|
||||
self.land[chunkpos] = true
|
||||
self:decrease_power(factions.power_per_chunk)
|
||||
|
Loading…
Reference in New Issue
Block a user