forked from mtcontrib/factions
commit
c2cef304da
@ -160,16 +160,17 @@ factions.register_command ("claim", {
|
|||||||
faction_permissions = {"claim"},
|
faction_permissions = {"claim"},
|
||||||
description = "Claim the plot of land you're on.",
|
description = "Claim the plot of land you're on.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local chunk = factions.chunks[chunkpos]
|
local can_claim = faction:can_claim_chunk(chunkpos)
|
||||||
if not chunk and faction:can_claim_chunk(chunkpos) then
|
if can_claim then
|
||||||
minetest.chat_send_player(player, "Claming chunk "..chunkpos)
|
minetest.chat_send_player(player, "Claming chunk "..chunkpos)
|
||||||
faction:claim_chunk(chunkpos)
|
faction:claim_chunk(chunkpos)
|
||||||
return true
|
return true
|
||||||
elseif not faction:can_claim_chunk(chunkpos) then
|
|
||||||
send_error(player, "Chunk cannot be claimed.")
|
|
||||||
return false
|
|
||||||
else
|
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.")
|
send_error(player, "This chunk already belongs to your faction.")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
|
71
factions.lua
71
factions.lua
@ -44,6 +44,15 @@ end
|
|||||||
factions.Faction = {
|
factions.Faction = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util = {
|
||||||
|
coords2D_string = function(coords)
|
||||||
|
return coords.x..", "..coords.y
|
||||||
|
end
|
||||||
|
coords3D_string = function(coords)
|
||||||
|
return coords.x..", "..coords.y..", "..coords.z
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
factions.Faction.__index = factions.Faction
|
factions.Faction.__index = factions.Faction
|
||||||
|
|
||||||
function factions.Faction:new(faction)
|
function factions.Faction:new(faction)
|
||||||
@ -105,13 +114,26 @@ function factions.Faction.remove_player(self, player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function factions.Faction.can_claim_chunk(self, chunkpos)
|
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
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.Faction.claim_chunk(self, chunkpos)
|
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
|
factions.chunks[chunkpos] = self.name
|
||||||
self.land[chunkpos] = true
|
self.land[chunkpos] = true
|
||||||
self:decrease_power(factions.power_per_chunk)
|
self:decrease_power(factions.power_per_chunk)
|
||||||
@ -235,59 +257,72 @@ function factions.Faction.promote(self, member, rank)
|
|||||||
self.players[member] = rank
|
self.players[member] = rank
|
||||||
self:on_promote(member)
|
self:on_promote(member)
|
||||||
end
|
end
|
||||||
|
function factions.Faction.broadcast(self, msg, sender)
|
||||||
|
local message = "self.name> "..msg
|
||||||
|
if sender then
|
||||||
|
message = sender.."@"..message
|
||||||
|
end
|
||||||
|
message = "<"..message
|
||||||
|
for k, _ in pairs(self.players) do
|
||||||
|
minetest.chat_send_player(k, message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------
|
--------------------------
|
||||||
-- callbacks for events --
|
-- callbacks for events --
|
||||||
function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list
|
function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list
|
||||||
--TODO: implement
|
minetest.chat_send_all("Faction "..self.name" has been created.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_player_leave(self, player)
|
function factions.Faction.on_player_leave(self, player)
|
||||||
--TODO: implement
|
self:broadcast(player.." has left this faction.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_player_join(self, player)
|
function factions.Faction.on_player_join(self, player)
|
||||||
--TODO: implement
|
self:broadcast(player.." has joined this faction.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_claim_chunk(self, pos)
|
function factions.Faction.on_claim_chunk(self, pos)
|
||||||
--TODO: implement
|
self:broadcast("Chunk ("..util.coords2D_string(pos)..") has been claimed.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_unclaim_chunk(self, pos)
|
function factions.Faction.on_unclaim_chunk(self, pos)
|
||||||
--TODO: implement
|
self:broadcast("Chunk ("..util.coords2D_string(pos)..") has been unclaimed.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_disband(self, pos)
|
function factions.Faction.on_disband(self, pos)
|
||||||
--TODO: implement
|
minetest.chat_send_all("Faction "..self.name.."has been disbanded.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_new_leader(self)
|
function factions.Faction.on_new_leader(self)
|
||||||
--TODO: implement
|
self:broadcast(self.leader.." is now the leader of this faction.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_change_description(self)
|
function factions.Faction.on_change_description(self)
|
||||||
--TODO: implement
|
self:broadcast("Faction description has been modified to: "..self.description)
|
||||||
end
|
end
|
||||||
function factions.Faction.on_player_invited(self, player)
|
function factions.Faction.on_player_invited(self, player)
|
||||||
--TODO: implement
|
minetest.chat_send_player(player, "You have been invited to faction "..self.name)
|
||||||
end
|
end
|
||||||
function factions.Faction.on_toggle_join_free(self, player)
|
function factions.Faction.on_toggle_join_free(self, player)
|
||||||
--TODO: implement
|
self:broadcast("This faction is now invite-free.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_new_alliance(self, faction)
|
function factions.Faction.on_new_alliance(self, faction)
|
||||||
--TODO: implement
|
self:broadcast("This faction is now allied with "..faction)
|
||||||
end
|
end
|
||||||
function factions.Faction.on_end_alliance(self, faction)
|
function factions.Faction.on_end_alliance(self, faction)
|
||||||
--TODO: implement
|
self:broadcast("This faction is no longer allied with "..faction.."!")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_set_spawn(self)
|
function factions.Faction.on_set_spawn(self)
|
||||||
--TODO: implement
|
self:broadcast("The faction spawn has been set to ("..util.coords2D_string(pos)..").")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_add_rank(self, rank)
|
function factions.Faction.on_add_rank(self, rank)
|
||||||
--TODO: implement
|
self:broadcast("The rank "..rank.." has been created with privileges: "..table.concat(self.rank[rank]))
|
||||||
end
|
end
|
||||||
function factions.Faction.on_delete_rank(self, rank, newrank)
|
function factions.Faction.on_delete_rank(self, rank, newrank)
|
||||||
--TODO: implement
|
self:broadcast("The rank "..rank.." has been deleted and replaced by "..newrank)
|
||||||
end
|
end
|
||||||
function factions.Faction.on_new_banner(self)
|
function factions.Faction.on_new_banner(self)
|
||||||
--TODO: implement
|
self:broadcast("A new banner has been set.")
|
||||||
end
|
end
|
||||||
function factions.Faction.on_promote(self, member)
|
function factions.Faction.on_promote(self, member)
|
||||||
--TODO: implement
|
minetest.chat_send_player(player, "You have been promoted to "..self.players[member])
|
||||||
|
end
|
||||||
|
function factions.Faction.on_revoke_invite(self, player)
|
||||||
|
minetest.chat_send_player(player, "You are no longer invited to faction "..self.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
--??????????????
|
--??????????????
|
||||||
|
Loading…
Reference in New Issue
Block a user