Merge pull request #19 from shamoanjac/master

ebin war fixes
This commit is contained in:
agrecascino 2016-08-16 15:54:21 -04:00 committed by GitHub
commit 8ffa199f3f
2 changed files with 43 additions and 18 deletions

View File

@ -419,8 +419,8 @@ 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
--TODO: error (one of either ranks do not exist)
if not faction.ranks[rank] or not faction.ranks[newrank] then
send_error(player, "One of the specified ranks do not exist.")
return false
end
faction:delete_rank(rank, newrank)
@ -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
})

View File

@ -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
@ -385,7 +406,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 +716,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]
@ -708,26 +737,22 @@ 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")
end
if pos.y < factions.protection_max_depth then
return false
end
if factions.disallow_edit_nofac and not player_faction then
return true
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
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