forked from mtcontrib/factions
commit
8ffa199f3f
@ -419,8 +419,8 @@ factions.register_command("delrank", {
|
|||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local rank = args.strings[1]
|
local rank = args.strings[1]
|
||||||
local newrank = args.strings[2]
|
local newrank = args.strings[2]
|
||||||
if not faction.ranks[rank] or not faction.ranks[rank] then
|
if not faction.ranks[rank] or not faction.ranks[newrank] then
|
||||||
--TODO: error (one of either ranks do not exist)
|
send_error(player, "One of the specified ranks do not exist.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
faction:delete_rank(rank, newrank)
|
faction:delete_rank(rank, newrank)
|
||||||
@ -488,7 +488,7 @@ factions.register_command("promote", {
|
|||||||
factions.register_command("power", {
|
factions.register_command("power", {
|
||||||
description = "Display your faction's power",
|
description = "Display your faction's power",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower)
|
minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
55
factions.lua
55
factions.lua
@ -76,6 +76,8 @@ function factions.Faction:new(faction)
|
|||||||
power = 0.,
|
power = 0.,
|
||||||
--! @brief maximum power of a faction
|
--! @brief maximum power of a faction
|
||||||
maxpower = 0.,
|
maxpower = 0.,
|
||||||
|
--! @brief power currently in use
|
||||||
|
usedpower = 0.,
|
||||||
--! @brief list of player names
|
--! @brief list of player names
|
||||||
players = {},
|
players = {},
|
||||||
--! @brief table of ranks/permissions
|
--! @brief table of ranks/permissions
|
||||||
@ -123,8 +125,8 @@ end
|
|||||||
|
|
||||||
function factions.Faction.increase_power(self, power)
|
function factions.Faction.increase_power(self, power)
|
||||||
self.power = self.power + power
|
self.power = self.power + power
|
||||||
if self.power > self.maxpower then
|
if self.power > self.maxpower - self.usedpower then
|
||||||
self.power = self.maxpower
|
self.power = self.maxpower - self.usedpower
|
||||||
end
|
end
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
@ -146,6 +148,25 @@ function factions.Faction.decrease_maxpower(self, power)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.increase_usedpower(self, power)
|
||||||
|
self.usedpower = self.usedpower + power
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.decrease_usedpower(self, power)
|
||||||
|
self.usedpower = self.usedpower - power
|
||||||
|
if self.usedpower < 0. then
|
||||||
|
self.usedpower = 0.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.count_land(self)
|
||||||
|
local count = 0.
|
||||||
|
for k, v in pairs(self.land) do
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.add_player(self, player, rank)
|
function factions.Faction.add_player(self, player, rank)
|
||||||
self:on_player_join(player)
|
self:on_player_join(player)
|
||||||
self.players[player] = rank or self.default_rank
|
self.players[player] = rank or self.default_rank
|
||||||
@ -188,7 +209,7 @@ function factions.Faction.claim_parcel(self, parcelpos)
|
|||||||
factions.parcels[parcelpos] = self.name
|
factions.parcels[parcelpos] = self.name
|
||||||
self.land[parcelpos] = true
|
self.land[parcelpos] = true
|
||||||
self:decrease_power(factions.power_per_parcel)
|
self:decrease_power(factions.power_per_parcel)
|
||||||
self:decrease_maxpower(factions.power_per_parcel)
|
self:increase_usedpower(factions.power_per_parcel)
|
||||||
self:on_claim_parcel(parcelpos)
|
self:on_claim_parcel(parcelpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
@ -198,7 +219,7 @@ function factions.Faction.unclaim_parcel(self, parcelpos)
|
|||||||
factions.parcels[parcelpos] = nil
|
factions.parcels[parcelpos] = nil
|
||||||
self.land[parcelpos] = nil
|
self.land[parcelpos] = nil
|
||||||
self:increase_power(factions.power_per_parcel)
|
self:increase_power(factions.power_per_parcel)
|
||||||
self:increase_maxpower(factions.power_per_parcel)
|
self:decrease_usedpower(factions.power_per_parcel)
|
||||||
self:on_unclaim_parcel(parcelpos)
|
self:on_unclaim_parcel(parcelpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
@ -385,7 +406,8 @@ function factions.Faction.stop_attack(self, parcelpos)
|
|||||||
attacked_faction = factions.factions[attacked_faction]
|
attacked_faction = factions.factions[attacked_faction]
|
||||||
if attacked_faction.attacked_parcels[parcelpos] then
|
if attacked_faction.attacked_parcels[parcelpos] then
|
||||||
attacked_faction.attacked_parcels[parcelpos][self.name] = nil
|
attacked_faction.attacked_parcels[parcelpos][self.name] = nil
|
||||||
attacked_faction:broadcast("Parcel ("..self.name..") is no longer under attack.")
|
attacked_faction:broadcast("Parcel ("..parcelpos..") is no longer under attack from "..self.name..".")
|
||||||
|
self:broadcast("Parcel ("..parcelpos..") has been reconquered by "..attacked_faction.name..".")
|
||||||
end
|
end
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
@ -694,6 +716,13 @@ minetest.register_on_respawnplayer(
|
|||||||
|
|
||||||
local default_is_protected = minetest.is_protected
|
local default_is_protected = minetest.is_protected
|
||||||
minetest.is_protected = function(pos, player)
|
minetest.is_protected = function(pos, 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
|
||||||
|
|
||||||
local parcelpos = factions.get_parcel_pos(pos)
|
local parcelpos = factions.get_parcel_pos(pos)
|
||||||
local parcel_faction = factions.parcels[parcelpos]
|
local parcel_faction = factions.parcels[parcelpos]
|
||||||
local player_faction = factions.players[player]
|
local player_faction = factions.players[player]
|
||||||
@ -708,26 +737,22 @@ minetest.is_protected = function(pos, player)
|
|||||||
end
|
end
|
||||||
local player_wield = player_info:get_wielded_item()
|
local player_wield = player_info:get_wielded_item()
|
||||||
if player_wield:get_name() == "banners:death_banner" and player_faction then --todo: check for allies, maybe for permissions
|
if player_wield:get_name() == "banners:death_banner" and player_faction then --todo: check for allies, maybe for permissions
|
||||||
return not factions.factions[player_faction]:has_permission(player, "claim")
|
player_faction = factions.factions[player_faction]
|
||||||
end
|
return not player_faction:has_permission(player, "claim") and player_faction.power > 0.
|
||||||
if pos.y < factions.protection_max_depth then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
if factions.disallow_edit_nofac and not player_faction then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
-- no faction
|
||||||
if not parcel_faction then
|
if not parcel_faction then
|
||||||
return default_is_protected(pos, player)
|
return default_is_protected(pos, player)
|
||||||
else
|
else
|
||||||
parcel_faction = factions.factions[parcel_faction]
|
parcel_faction = factions.factions[parcel_faction]
|
||||||
if parcel_faction.attacked_parcels[parcelpos] then -- chunk is being attacked
|
if parcel_faction.name == player_faction then
|
||||||
|
return not parcel_faction:has_permission(player, "build")
|
||||||
|
elseif 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
|
if parcel_faction.attacked_parcels[parcelpos][player_faction] then -- attacked by the player's faction
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
else
|
|
||||||
return not parcel_faction:has_permission(player, "build")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user