From b763015f3d2c0a2013d019ea722ca8f0bea97d75 Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Mon, 15 Aug 2016 23:52:12 +0200 Subject: [PATCH 1/4] Fixed members of the attacked faction not being able to edit their chunk --- factions.lua | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/factions.lua b/factions.lua index 1af0ddd..5de9a5a 100644 --- a/factions.lua +++ b/factions.lua @@ -385,7 +385,8 @@ function factions.Faction.stop_attack(self, parcelpos) attacked_faction = factions.factions[attacked_faction] if attacked_faction.attacked_parcels[parcelpos] then 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 factions.save() end @@ -694,6 +695,13 @@ minetest.register_on_respawnplayer( local default_is_protected = minetest.is_protected 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 parcel_faction = factions.parcels[parcelpos] local player_faction = factions.players[player] @@ -710,24 +718,19 @@ minetest.is_protected = function(pos, player) 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") end - if pos.y < factions.protection_max_depth then - return false - end - if factions.disallow_edit_nofac and not player_faction then - return true - end + -- no faction if not parcel_faction then return default_is_protected(pos, player) else 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 return false else return true end - else - return not parcel_faction:has_permission(player, "build") end end end From 82ff53a1337b647dcd9f08e5e5b30208e643ace4 Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Tue, 16 Aug 2016 15:44:19 +0200 Subject: [PATCH 2/4] Fixed power exploit, added usedpower, cannot attack parcels with negative power --- chatcommands.lua | 2 +- factions.lua | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 9a82737..2107ecc 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -488,7 +488,7 @@ factions.register_command("promote", { factions.register_command("power", { description = "Display your faction's power", 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 end }) diff --git a/factions.lua b/factions.lua index 5de9a5a..eec10d4 100644 --- a/factions.lua +++ b/factions.lua @@ -76,6 +76,8 @@ function factions.Faction:new(faction) power = 0., --! @brief maximum power of a faction maxpower = 0., + --! @brief power currently in use + usedpower = 0., --! @brief list of player names players = {}, --! @brief table of ranks/permissions @@ -123,8 +125,8 @@ end function factions.Faction.increase_power(self, power) self.power = self.power + power - if self.power > self.maxpower then - self.power = self.maxpower + if self.power > self.maxpower - self.usedpower then + self.power = self.maxpower - self.usedpower end factions.save() end @@ -146,6 +148,25 @@ function factions.Faction.decrease_maxpower(self, power) 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) self:on_player_join(player) self.players[player] = rank or self.default_rank @@ -188,7 +209,7 @@ function factions.Faction.claim_parcel(self, parcelpos) factions.parcels[parcelpos] = self.name self.land[parcelpos] = true 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) factions.save() end @@ -198,7 +219,7 @@ function factions.Faction.unclaim_parcel(self, parcelpos) factions.parcels[parcelpos] = nil self.land[parcelpos] = nil 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) factions.save() end @@ -716,7 +737,8 @@ minetest.is_protected = function(pos, player) end 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 - return not factions.factions[player_faction]:has_permission(player, "claim") + player_faction = factions.factions[player_faction] + return not player_faction:has_permission(player, "claim") and player_faction.power > 0. end -- no faction if not parcel_faction then From 6deb78483e4d887dd192afbd87d4ceb5f5599cbb Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Tue, 16 Aug 2016 21:05:41 +0200 Subject: [PATCH 3/4] Fixed delrank checking --- chatcommands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatcommands.lua b/chatcommands.lua index 2107ecc..ab42e5c 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -419,7 +419,7 @@ factions.register_command("delrank", { 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 + if not faction.ranks[rank] or not faction.ranks[newrank] then --TODO: error (one of either ranks do not exist) return false end From 006c0329526ec9423d91ad23b62acf0498db98b2 Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Tue, 16 Aug 2016 21:08:44 +0200 Subject: [PATCH 4/4] Added error message to /f delrank --- chatcommands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatcommands.lua b/chatcommands.lua index ab42e5c..f17bbd6 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -420,7 +420,7 @@ factions.register_command("delrank", { local rank = args.strings[1] local newrank = args.strings[2] 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 end faction:delete_rank(rank, newrank)