forked from mtcontrib/factions
Fixed power exploit, added usedpower, cannot attack parcels with negative power
This commit is contained in:
parent
b763015f3d
commit
82ff53a133
@ -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
|
||||||
})
|
})
|
||||||
|
32
factions.lua
32
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
|
||||||
@ -716,7 +737,8 @@ 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]
|
||||||
|
return not player_faction:has_permission(player, "claim") and player_faction.power > 0.
|
||||||
end
|
end
|
||||||
-- no faction
|
-- no faction
|
||||||
if not parcel_faction then
|
if not parcel_faction then
|
||||||
|
Loading…
Reference in New Issue
Block a user