Add diplomacy feature
This commit is contained in:
parent
8277621575
commit
e6a417feca
@ -172,6 +172,23 @@ end
|
||||
-- R E G I S T E R E D C O M M A N D S |
|
||||
-------------------------------------------
|
||||
|
||||
factions.register_command ("set_name", {
|
||||
faction_permissions = {"description"},
|
||||
format = {"string"},
|
||||
description = "Change the faction's name.",
|
||||
global_privileges = def_global_privileges,
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local factionname = args.strings[1]
|
||||
if factions.can_create_faction(factionname) then
|
||||
faction:set_name(factionname)
|
||||
return true
|
||||
else
|
||||
send_error(player, "Faction cannot be renamed.")
|
||||
return false
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command ("claim", {
|
||||
faction_permissions = {"claim"},
|
||||
description = "Claim the plot of land you're on.",
|
||||
@ -308,6 +325,7 @@ factions.register_command("create", {
|
||||
new_faction = factions.new_faction(factionname, nil)
|
||||
new_faction:add_player(player, new_faction.default_leader_rank)
|
||||
minetest.chat_send_player(player, "Created Faction.")
|
||||
factions.start_diplomacy(factionname,new_faction)
|
||||
return true
|
||||
else
|
||||
send_error(player, "Faction cannot be created.")
|
||||
@ -425,6 +443,245 @@ factions.register_command("ranks", {
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("send_alliance", {
|
||||
description = "Send an alliance request to another faction.",
|
||||
--global_privileges = {"faction_user"},
|
||||
format = {"string"},
|
||||
faction_permissions = {"diplomacy"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if factions.factions[args.strings[1]] then
|
||||
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
|
||||
if faction.allies[args.strings[1]] then
|
||||
send_error(player, "You are already allys.")
|
||||
return false
|
||||
end
|
||||
if faction.enemies[args.strings[1]] then
|
||||
send_error(player, "You need to be neutral in-order to send an alliance request.")
|
||||
return false
|
||||
end
|
||||
if args.strings[1] == faction.name then
|
||||
send_error(player, "You can not send an alliance to your own faction.")
|
||||
return false
|
||||
end
|
||||
if faction.request_inbox[args.strings[1]] then
|
||||
send_error(player, "Faction " .. args.strings[1] .. "has already sent a request to you.")
|
||||
return false
|
||||
end
|
||||
factions.factions[args.strings[1]].request_inbox[faction.name] = "alliance"
|
||||
factions.factions[args.strings[1]]:broadcast("An alliance request from faction " .. faction.name .. " has been sent to you.")
|
||||
faction:broadcast("An alliance request was sent to faction " .. args.strings[1])
|
||||
factions.save()
|
||||
else
|
||||
send_error(player, "You have already sent a request.")
|
||||
end
|
||||
else
|
||||
send_error(player, args.strings[1] .. " is not a name of a faction.")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("send_neutral", {
|
||||
description = "Send neutral to another faction.",
|
||||
--global_privileges = {"faction_user"},
|
||||
format = {"string"},
|
||||
faction_permissions = {"diplomacy"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if factions.factions[args.strings[1]] then
|
||||
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
|
||||
if faction.allies[args.strings[1]] then
|
||||
send_error(player, "You are allys.")
|
||||
return false
|
||||
end
|
||||
if faction.neutral[args.strings[1]] then
|
||||
send_error(player, "You are already neutral with this faction.")
|
||||
return false
|
||||
end
|
||||
if args.strings[1] == faction.name then
|
||||
send_error(player, "You can not send a neutral request to your own faction.")
|
||||
return false
|
||||
end
|
||||
if faction.request_inbox[args.strings[1]] then
|
||||
send_error(player, "Faction " .. args.strings[1] .. "has already sent a request to you.")
|
||||
return false
|
||||
end
|
||||
factions.factions[args.strings[1]].request_inbox[faction.name] = "neutral"
|
||||
factions.factions[args.strings[1]]:broadcast("A neutral request from faction " .. faction.name .. " has been sent to you.")
|
||||
faction:broadcast("A neutral request was sent to faction " .. args.strings[1])
|
||||
factions.save()
|
||||
else
|
||||
send_error(player, "You have already sent a request.")
|
||||
end
|
||||
else
|
||||
send_error(player, args.strings[1] .. " is not a name of a faction.")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("accept", {
|
||||
description = "accept an request from another faction.",
|
||||
--global_privileges = {"faction_user"},
|
||||
format = {"string"},
|
||||
faction_permissions = {"diplomacy"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if faction.request_inbox[args.strings[1]] then
|
||||
if args.strings[1] == faction.name then
|
||||
send_error(player, "You can not accept an request from own faction.")
|
||||
return false
|
||||
end
|
||||
if faction.request_inbox[args.strings[1]] == "alliance" then
|
||||
faction:new_alliance(args.strings[1])
|
||||
factions.factions[args.strings[1]]:new_alliance(faction.name)
|
||||
else
|
||||
if faction.request_inbox[args.strings[1]] == "neutral" then
|
||||
faction:new_neutral(args.strings[1])
|
||||
factions.factions[args.strings[1]]:new_neutral(faction.name)
|
||||
end
|
||||
end
|
||||
faction.request_inbox[args.strings[1]] = nil
|
||||
factions.save()
|
||||
else
|
||||
send_error(player, "No request was sent to you.")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("refuse", {
|
||||
description = "refuse an request from another faction.",
|
||||
--global_privileges = {"faction_user"},
|
||||
format = {"string"},
|
||||
faction_permissions = {"diplomacy"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if faction.request_inbox[args.strings[1]] then
|
||||
if args.strings[1] == faction.name then
|
||||
send_error(player, "You can not refuse an request from your own faction.")
|
||||
return false
|
||||
end
|
||||
faction.request_inbox[args.strings[1]] = nil
|
||||
factions.factions[args.strings[1]]:broadcast("Faction " .. faction.name .. " refuse to be your ally.")
|
||||
faction:broadcast("Refused an request from faction " .. args.strings[1])
|
||||
factions.save()
|
||||
else
|
||||
send_error(player, "No request was sent to you.")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("delcare_war", {
|
||||
description = "Delcare war on a faction.",
|
||||
--global_privileges = {"faction_user"},
|
||||
format = {"string"},
|
||||
faction_permissions = {"diplomacy"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if not faction.enemies[args.strings[1]] then
|
||||
if args.strings[1] == faction.name then
|
||||
send_error(player, "You can not delcare war on your own faction.")
|
||||
return false
|
||||
end
|
||||
if faction.allies[args.strings[1]] then
|
||||
faction:end_alliance(args.strings[1])
|
||||
factions.factions[args.strings[1]]:end_alliance(faction.name)
|
||||
end
|
||||
if faction.neutral[args.strings[1]] then
|
||||
faction:end_neutral(args.strings[1])
|
||||
factions.factions[args.strings[1]]:end_neutral(faction.name)
|
||||
end
|
||||
faction:new_enemy(args.strings[1])
|
||||
factions.factions[args.strings[1]]:new_enemy(faction.name)
|
||||
factions.save()
|
||||
else
|
||||
send_error(player, "You are already at war.")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("break", {
|
||||
description = "Break an alliance.",
|
||||
--global_privileges = {"faction_user"},
|
||||
format = {"string"},
|
||||
faction_permissions = {"diplomacy"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if faction.allies[args.strings[1]] then
|
||||
if args.strings[1] == faction.name then
|
||||
send_error(player, "You can not break an alliance from your own faction.")
|
||||
return false
|
||||
end
|
||||
faction:end_alliance(args.strings[1])
|
||||
factions.factions[args.strings[1]]:end_alliance(faction.name)
|
||||
faction:new_neutral(args.strings[1])
|
||||
factions.factions[args.strings[1]]:new_neutral(faction.name)
|
||||
factions.save()
|
||||
else
|
||||
send_error(player, "You where not allies to begin with.")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("inbox", {
|
||||
description = "Check your diplomacy request inbox.",
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local empty = true
|
||||
for i,k in pairs(faction.request_inbox) do
|
||||
if k == "alliance" then
|
||||
minetest.chat_send_player(player,"Alliance request from faction " .. i .. "\n")
|
||||
else
|
||||
if k == "neutral" then
|
||||
minetest.chat_send_player(player,"neutral request from faction " .. i .. "\n")
|
||||
end
|
||||
end
|
||||
empty = false
|
||||
end
|
||||
if empty then
|
||||
minetest.chat_send_player(player,"none:")
|
||||
end
|
||||
end
|
||||
},false,true)
|
||||
|
||||
factions.register_command("allies", {
|
||||
description = "Shows the factions that are allied to you.",
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local empty = true
|
||||
for i,k in pairs(faction.allies) do
|
||||
minetest.chat_send_player(player,i .. "\n")
|
||||
empty = false
|
||||
end
|
||||
if empty then
|
||||
minetest.chat_send_player(player,"none:")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("neutral", {
|
||||
description = "Shows the factions that are neutral with you.",
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local empty = true
|
||||
for i,k in pairs(faction.neutral) do
|
||||
minetest.chat_send_player(player,i .. "\n")
|
||||
empty = false
|
||||
end
|
||||
if empty then
|
||||
minetest.chat_send_player(player,"none:")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("enemies", {
|
||||
description = "Shows enemies of your faction.",
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local empty = true
|
||||
for i,k in pairs(faction.enemies) do
|
||||
minetest.chat_send_player(player,i .. "\n")
|
||||
empty = false
|
||||
end
|
||||
if empty then
|
||||
minetest.chat_send_player(player,"none:")
|
||||
end
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("who", {
|
||||
description = "List players in your faction, and their ranks.",
|
||||
--global_privileges = {"faction_user"},
|
||||
@ -441,6 +698,27 @@ factions.register_command("who", {
|
||||
end
|
||||
},false)
|
||||
|
||||
-- Save a tiny bit of compute time.
|
||||
local parcel_size_center = 32. / 2
|
||||
|
||||
factions.register_command("show_parcel", {
|
||||
description = "Shows parcel for six seconds.",
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||
if not parcel_faction then
|
||||
send_error(player, "There is no claim here")
|
||||
return false
|
||||
end
|
||||
local psc = parcel_size_center
|
||||
local fps = 32.
|
||||
|
||||
local ppos = {x = (math.floor(pos.x / fps)*fps)+psc,y = (math.floor(pos.y / fps)*fps)+psc,z = (math.floor(pos.z / fps)*fps)+psc}
|
||||
minetest.add_entity(ppos, "factions:display")
|
||||
return true
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("newrank", {
|
||||
description = "Add a new rank.",
|
||||
format = {"string"},
|
||||
@ -461,6 +739,8 @@ factions.register_command("newrank", {
|
||||
if f == r then
|
||||
success = true
|
||||
break
|
||||
else
|
||||
success = false
|
||||
end
|
||||
end
|
||||
if not success and _ ~= 1 then
|
||||
@ -485,6 +765,165 @@ factions.register_command("newrank", {
|
||||
end
|
||||
},true)
|
||||
|
||||
factions.register_command("replace_privs", {
|
||||
description = "Deletes current permissions and replaces them with the ones given.",
|
||||
format = {"string"},
|
||||
faction_permissions = {"ranks"},
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if args.strings[1] then
|
||||
local rank = args.strings[1]
|
||||
if not faction.ranks[rank] then
|
||||
send_error(player, "Rank does not exist")
|
||||
return false
|
||||
end
|
||||
local success = false
|
||||
local failindex = -1
|
||||
for _, f in pairs(args.strings) do
|
||||
if f then
|
||||
for q, r in pairs(factions.permissions) do
|
||||
if f == r then
|
||||
success = true
|
||||
break
|
||||
else
|
||||
success = false
|
||||
end
|
||||
end
|
||||
if not success and _ ~= 1 then
|
||||
failindex = _
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not success then
|
||||
if args.strings[failindex] then
|
||||
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
|
||||
else
|
||||
send_error(player, "No permission was given.")
|
||||
end
|
||||
return false
|
||||
end
|
||||
faction:replace_privs(rank, args.other)
|
||||
return true
|
||||
end
|
||||
send_error(player, "No rank was given.")
|
||||
return false
|
||||
end
|
||||
},true)
|
||||
|
||||
factions.register_command("remove_privs", {
|
||||
description = "Remove permissions from a rank.",
|
||||
format = {"string"},
|
||||
faction_permissions = {"ranks"},
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if args.strings[1] then
|
||||
local rank = args.strings[1]
|
||||
if not faction.ranks[rank] then
|
||||
send_error(player, "Rank does not exist")
|
||||
return false
|
||||
end
|
||||
local success = false
|
||||
local failindex = -1
|
||||
for _, f in pairs(args.strings) do
|
||||
if f then
|
||||
for q, r in pairs(factions.permissions) do
|
||||
if f == r then
|
||||
success = true
|
||||
break
|
||||
else
|
||||
success = false
|
||||
end
|
||||
end
|
||||
if not success and _ ~= 1 then
|
||||
failindex = _
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not success then
|
||||
if args.strings[failindex] then
|
||||
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
|
||||
else
|
||||
send_error(player, "No permission was given.")
|
||||
end
|
||||
return false
|
||||
end
|
||||
faction:remove_privs(rank, args.other)
|
||||
return true
|
||||
end
|
||||
send_error(player, "No rank was given.")
|
||||
return false
|
||||
end
|
||||
},true)
|
||||
|
||||
factions.register_command("add_privs", {
|
||||
description = "add permissions to a rank.",
|
||||
format = {"string"},
|
||||
faction_permissions = {"ranks"},
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if args.strings[1] then
|
||||
local rank = args.strings[1]
|
||||
if not faction.ranks[rank] then
|
||||
send_error(player, "Rank does not exist")
|
||||
return false
|
||||
end
|
||||
local success = false
|
||||
local failindex = -1
|
||||
for _, f in pairs(args.strings) do
|
||||
if f then
|
||||
for q, r in pairs(factions.permissions) do
|
||||
if f == r then
|
||||
success = true
|
||||
break
|
||||
else
|
||||
success = false
|
||||
end
|
||||
end
|
||||
if not success and _ ~= 1 then
|
||||
failindex = _
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not success then
|
||||
if args.strings[failindex] then
|
||||
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
|
||||
else
|
||||
send_error(player, "No permission was given.")
|
||||
end
|
||||
return false
|
||||
end
|
||||
faction:add_privs(rank, args.other)
|
||||
return true
|
||||
end
|
||||
send_error(player, "No rank was given.")
|
||||
return false
|
||||
end
|
||||
},true)
|
||||
|
||||
factions.register_command("set_rank_name", {
|
||||
description = "Change the name of given rank.",
|
||||
format = {"string","string"},
|
||||
faction_permissions = {"ranks"},
|
||||
--global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local rank = args.strings[1]
|
||||
local newrank = args.strings[2]
|
||||
if not faction.ranks[rank] then
|
||||
send_error(player, "The rank does not exist.")
|
||||
return false
|
||||
end
|
||||
if faction.ranks[newrank] then
|
||||
send_error(player, "This rank name was already taken.")
|
||||
return false
|
||||
end
|
||||
faction:set_rank_name(rank, newrank)
|
||||
return true
|
||||
end
|
||||
},false)
|
||||
|
||||
factions.register_command("delrank", {
|
||||
description = "Replace and delete a rank.",
|
||||
format = {"string", "string"},
|
||||
|
@ -72,8 +72,9 @@ factions.Faction.__index = factions.Faction
|
||||
-- spawn: set the faction's spawn
|
||||
-- banner: set the faction's banner
|
||||
-- promote: set a player's rank
|
||||
-- diplomacy: make war, peace, or an alliance.
|
||||
|
||||
factions.permissions = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote"}
|
||||
factions.permissions = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote", "diplomacy"}
|
||||
|
||||
function factions.Faction:new(faction)
|
||||
faction = {
|
||||
@ -86,7 +87,7 @@ function factions.Faction:new(faction)
|
||||
--! @brief list of player names
|
||||
players = {},
|
||||
--! @brief table of ranks/permissions
|
||||
ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote"},
|
||||
ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote", "diplomacy"},
|
||||
["moderator"] = {"claim", "playerslist", "build", "spawn"},
|
||||
["member"] = {"build"}
|
||||
},
|
||||
@ -104,8 +105,12 @@ function factions.Faction:new(faction)
|
||||
land = {},
|
||||
--! @brief table of allies
|
||||
allies = {},
|
||||
--
|
||||
request_inbox = {},
|
||||
--! @brief table of enemies
|
||||
enemies = {},
|
||||
--!
|
||||
neutral = {},
|
||||
--! @brief table of parcels/factions that are under attack
|
||||
attacked_parcels = {},
|
||||
--! @brief whether faction is closed or open (boolean)
|
||||
@ -132,6 +137,58 @@ factions.new_faction = function(name)
|
||||
return faction
|
||||
end
|
||||
|
||||
function factions.start_diplomacy(name,faction)
|
||||
for i,fac in pairs(factions.factions) do
|
||||
if i ~= name and not (faction.neutral[i] or faction.allies[i] or faction.enemies[i]) then
|
||||
faction:new_enemy(i)
|
||||
fac:new_enemy(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function factions.Faction.set_name(self, name)
|
||||
local oldname = self.name
|
||||
local oldfaction = factions.factions[oldname]
|
||||
self.name = name
|
||||
for i,fac in pairs(factions.factions) do
|
||||
if i ~= oldname then
|
||||
if fac.neutral[oldname] then
|
||||
fac.neutral[oldname] = nil
|
||||
fac.neutral[name] = true
|
||||
end
|
||||
if fac.allies[oldname] then
|
||||
fac.allies[oldname] = nil
|
||||
fac.allies[name] = true
|
||||
end
|
||||
if fac.enemies[oldname] then
|
||||
fac.enemies[oldname] = nil
|
||||
fac.enemies[name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
for parcel in pairs(self.land) do
|
||||
factions.parcels[parcel] = self.name
|
||||
end
|
||||
for playername in pairs(self.players) do
|
||||
factions.players[playername] = self.name
|
||||
end
|
||||
factions.factions[oldname] = nil
|
||||
factions.factions[name] = oldfaction
|
||||
factions.factions[name].name = name
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
for player, _ in pairs(self.players) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
removeHud(realplayer,"1")
|
||||
createHudFactionName(realplayer,name)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:on_set_name(oldname)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.increase_power(self, power)
|
||||
self.power = self.power + power
|
||||
if self.power > self.maxpower - self.usedpower then
|
||||
@ -335,7 +392,19 @@ end
|
||||
--! @brief disband faction, updates global players and parcels table
|
||||
function factions.Faction.disband(self, reason)
|
||||
local playerslist = minetest.get_connected_players()
|
||||
|
||||
for i,v in pairs(factions.factions) do
|
||||
if v.name ~= self.name then
|
||||
if v.enemies[self.name] then
|
||||
v:end_enemy(self.name)
|
||||
end
|
||||
if v.allies[self.name] then
|
||||
v:end_alliance(self.name)
|
||||
end
|
||||
if v.neutral[self.name] then
|
||||
v:end_neutral(self.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
for k, _ in pairs(factions.players) do -- remove players affiliation
|
||||
if(factions.players[k] == self.name) then
|
||||
factions.players[k] = nil
|
||||
@ -428,22 +497,49 @@ function factions.Faction.new_alliance(self, faction)
|
||||
self:on_new_alliance(faction)
|
||||
if self.enemies[faction] then
|
||||
self:end_enemy(faction)
|
||||
end
|
||||
if self.neutral[faction] then
|
||||
self:end_neutral(faction)
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.end_alliance(self, faction)
|
||||
self.allies[faction] = nil
|
||||
self:on_end_alliance(faction)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.new_neutral(self, faction)
|
||||
self.neutral[faction] = true
|
||||
self:on_new_neutral(faction)
|
||||
if self.allies[faction] then
|
||||
self:end_alliance(faction)
|
||||
end
|
||||
if self.enemies[faction] then
|
||||
self:end_enemy(faction)
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.end_neutral(self, faction)
|
||||
self.neutral[faction] = nil
|
||||
self:on_end_neutral(faction)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.new_enemy(self, faction)
|
||||
self.enemies[faction] = true
|
||||
self:on_new_enemy(faction)
|
||||
if self.allies[faction] then
|
||||
self:end_alliance(faction)
|
||||
end
|
||||
if self.neutral[faction] then
|
||||
self:end_neutral(faction)
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.end_enemy(self, faction)
|
||||
self.enemies[faction] = nil
|
||||
self:on_end_enemy(faction)
|
||||
@ -466,6 +562,72 @@ function factions.Faction.add_rank(self, rank, perms)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @brief replace an rank's permissions
|
||||
--! @param rank the name of the rank to edit
|
||||
--! @param add or remove permissions to the rank
|
||||
function factions.Faction.replace_privs(self, rank, perms)
|
||||
self.ranks[rank] = perms
|
||||
self:on_replace_privs(rank)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.remove_privs(self, rank, perms)
|
||||
local revoked = false
|
||||
local p = self.ranks[rank]
|
||||
for index, perm in pairs(p) do
|
||||
if table_Contains(perms,perm) then
|
||||
revoked = true
|
||||
table.remove(p,index)
|
||||
end
|
||||
end
|
||||
self.ranks[rank] = p
|
||||
if revoked then
|
||||
self:on_remove_privs(rank,perms)
|
||||
else
|
||||
self:broadcast("No privilege was revoked from rank "..rank..".")
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.add_privs(self, rank, perms)
|
||||
local added = false
|
||||
local p = self.ranks[rank]
|
||||
for index, perm in pairs(perms) do
|
||||
if not table_Contains(p,perm) then
|
||||
added = true
|
||||
table.insert(p,perm)
|
||||
end
|
||||
end
|
||||
self.ranks[rank] = p
|
||||
if added then
|
||||
self:on_add_privs(rank,perms)
|
||||
else
|
||||
self:broadcast("The rank "..rank.." already has these privileges.")
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.set_rank_name(self, oldrank, newrank)
|
||||
local copyrank = self.ranks[oldrank]
|
||||
self.ranks[newrank] = copyrank
|
||||
self.ranks[oldrank] = nil
|
||||
for player, r in pairs(self.players) do
|
||||
if r == oldrank then
|
||||
self.players[player] = newrank
|
||||
end
|
||||
end
|
||||
if oldrank == self.default_leader_rank then
|
||||
self.default_leader_rank = newrank
|
||||
self:broadcast("The default leader rank has been set to "..newrank)
|
||||
end
|
||||
if oldrank == self.default_rank then
|
||||
self.default_rank = newrank
|
||||
self:broadcast("The default rank given to new players is set to "..newrank)
|
||||
end
|
||||
self:on_set_rank_name(oldrank, newrank)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @brief delete a rank and replace it
|
||||
--! @param rank the name of the rank to be deleted
|
||||
--! @param newrank the rank given to players who were previously "rank"
|
||||
@ -477,6 +639,14 @@ function factions.Faction.delete_rank(self, rank, newrank)
|
||||
end
|
||||
self.ranks[rank] = nil
|
||||
self:on_delete_rank(rank, newrank)
|
||||
if rank == self.default_leader_rank then
|
||||
self.default_leader_rank = newrank
|
||||
self:broadcast("The default leader rank has been set to "..newrank)
|
||||
end
|
||||
if rank == self.default_rank then
|
||||
self.default_rank = newrank
|
||||
self:broadcast("The default rank given to new players is set to "..newrank)
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
@ -564,6 +734,10 @@ function factions.Faction.on_create(self) --! @brief called when the faction is
|
||||
minetest.chat_send_all("Faction "..self.name.." has been created.")
|
||||
end
|
||||
|
||||
function factions.Faction.on_set_name(self,oldname)
|
||||
minetest.chat_send_all("Faction "..oldname.." changed its name to "..self.name..".")
|
||||
end
|
||||
|
||||
function factions.Faction.on_player_leave(self, player)
|
||||
self:broadcast(player.." has left this faction.")
|
||||
end
|
||||
@ -616,6 +790,22 @@ function factions.Faction.on_end_alliance(self, faction)
|
||||
self:broadcast("This faction is no longer allied with "..faction.."!")
|
||||
end
|
||||
|
||||
function factions.Faction.on_new_neutral(self, faction)
|
||||
self:broadcast("This faction is now neutral with "..faction)
|
||||
end
|
||||
|
||||
function factions.Faction.on_end_neutral(self, faction)
|
||||
self:broadcast("This faction is no longer neutral with "..faction.."!")
|
||||
end
|
||||
|
||||
function factions.Faction.on_new_enemy(self, faction)
|
||||
self:broadcast("This faction is now at war with "..faction)
|
||||
end
|
||||
|
||||
function factions.Faction.on_end_enemy(self, faction)
|
||||
self:broadcast("This faction is no longer at war with "..faction.."!")
|
||||
end
|
||||
|
||||
function factions.Faction.on_set_spawn(self)
|
||||
self:broadcast("The faction spawn has been set to ("..util.coords3D_string(self.spawn)..").")
|
||||
end
|
||||
@ -624,6 +814,22 @@ function factions.Faction.on_add_rank(self, rank)
|
||||
self:broadcast("The rank "..rank.." has been created with privileges: "..table.concat(self.ranks[rank], ", "))
|
||||
end
|
||||
|
||||
function factions.Faction.on_replace_privs(self, rank)
|
||||
self:broadcast("The privileges in rank "..rank.." have been delete and changed to: "..table.concat(self.ranks[rank], ", "))
|
||||
end
|
||||
|
||||
function factions.Faction.on_remove_privs(self, rank,privs)
|
||||
self:broadcast("The privileges ("..table.concat(privs, ", ")..")".." in rank "..rank.." have been revoked: ")
|
||||
end
|
||||
|
||||
function factions.Faction.on_add_privs(self, rank,privs)
|
||||
self:broadcast("The privileges ("..table.concat(privs, ", ")..")".." in rank "..rank.." have been added: ")
|
||||
end
|
||||
|
||||
function factions.Faction.on_set_rank_name(self, rank,newrank)
|
||||
self:broadcast("The name of rank "..rank.." has been changed to "..newrank)
|
||||
end
|
||||
|
||||
function factions.Faction.on_delete_rank(self, rank, newrank)
|
||||
self:broadcast("The rank "..rank.." has been deleted and replaced by "..newrank)
|
||||
end
|
||||
@ -784,6 +990,13 @@ function factions.load()
|
||||
if not faction.last_logon then
|
||||
faction.last_logon = os.time()
|
||||
end
|
||||
if not faction.request_inbox then
|
||||
faction.request_inbox = {}
|
||||
end
|
||||
if not faction.neutral then
|
||||
faction.neutral = {}
|
||||
end
|
||||
factions.start_diplomacy(facname,faction)
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
@ -978,18 +1191,28 @@ function(player)
|
||||
faction.last_logon = os.time()
|
||||
createHudFactionName(player,faction.name)
|
||||
createHudPower(player,faction)
|
||||
if faction:has_permission(name,"diplomacy") then
|
||||
for _ in pairs(faction.request_inbox) do minetest.chat_send_player(name,"You have diplomatic requests in the inbox.") break end
|
||||
end
|
||||
end
|
||||
|
||||
local pos = player:get_pos()
|
||||
|
||||
local parcel_faction = factions.get_faction_at(pos)
|
||||
-- Login-Time-Stamp
|
||||
|
||||
local key = "LTS:"..name
|
||||
local value = storage:get_int(key)
|
||||
local facname = ""
|
||||
|
||||
if faction then
|
||||
facname = faction.name
|
||||
end
|
||||
|
||||
-- 300 seconds = 5 minutes
|
||||
-- Kill unstamped players.
|
||||
if parcel_faction and parcel_faction.is_admin == false and (value == 0 or os.time() - value >= 300) then
|
||||
if not faction or parcel_faction.name ~= faction.name then
|
||||
if (not faction or parcel_faction.name ~= facname) and parcel_faction.enemies[facname] then
|
||||
minetest.after(1, function()
|
||||
if player then
|
||||
player:set_hp(0)
|
||||
@ -997,11 +1220,7 @@ function(player)
|
||||
end)
|
||||
end
|
||||
end
|
||||
if value == 0 then
|
||||
local v = os.time()
|
||||
storage:set_int(key,v)
|
||||
value = v
|
||||
end
|
||||
storage:set_int(key,os.time())
|
||||
end
|
||||
)
|
||||
|
||||
@ -1070,7 +1289,9 @@ minetest.is_protected = function(pos, player)
|
||||
elseif player_faction then
|
||||
if parcel_faction.name == player_faction.name then
|
||||
return not parcel_faction:has_permission(player, "build")
|
||||
else
|
||||
elseif parcel_faction.allies[player_faction.name] then
|
||||
return not player_faction:has_permission(player, "build")
|
||||
else
|
||||
return not parcel_faction:parcel_is_attacked_by(parcelpos, player_faction)
|
||||
end
|
||||
else
|
||||
|
@ -69,3 +69,56 @@ minetest.register_craft({
|
||||
recipe = {"default:chest_locked", "default:steel_ingot"}
|
||||
})
|
||||
--]]
|
||||
|
||||
-- Code below was copied from TenPlus1's protector mod(MIT) and changed up a bit.
|
||||
|
||||
local x = math.floor(32. / 2.1)
|
||||
|
||||
minetest.register_node("factions:display_node", {
|
||||
tiles = {"factions_display.png"},
|
||||
use_texture_alpha = true,
|
||||
walkable = false,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
-- sides
|
||||
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)},
|
||||
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)},
|
||||
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)},
|
||||
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)},
|
||||
-- top
|
||||
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)},
|
||||
-- bottom
|
||||
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)},
|
||||
-- middle (surround parcel)
|
||||
{-.55,-.55,-.55, .55,.55,.55},
|
||||
},
|
||||
},
|
||||
selection_box = {
|
||||
type = "regular",
|
||||
},
|
||||
paramtype = "light",
|
||||
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
|
||||
drop = "",
|
||||
})
|
||||
|
||||
minetest.register_entity("factions:display", {
|
||||
physical = false,
|
||||
collisionbox = {0, 0, 0, 0, 0, 0},
|
||||
visual = "wielditem",
|
||||
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5},
|
||||
textures = {"factions:display_node"},
|
||||
timer = 0,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
|
||||
self.timer = self.timer + dtime
|
||||
|
||||
if self.timer > 6 then
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- End
|
@ -34,6 +34,11 @@ local function siege_banner_onplace_check(player, pointed_thing, attacking_playe
|
||||
minetest.chat_send_player(player:get_player_name(), "This parcel belongs to your own faction")
|
||||
return false
|
||||
end
|
||||
|
||||
if not defending_faction.enemies[attacking_faction.name] then
|
||||
minetest.chat_send_player(player:get_player_name(), "You are not at war with "..defending_faction.name)
|
||||
return false
|
||||
end
|
||||
|
||||
if attacking_faction.power < config.power_per_parcel then
|
||||
minetest.chat_send_player(player:get_player_name(), "Your faction doesn't have enough power to siege")
|
||||
@ -83,11 +88,12 @@ minetest.register_craftitem("factions:siege_banner", {
|
||||
defending_faction:broadcast(player:get_player_name() .. " is sieging your parcel at " .. format_pos(pointed_thing.above))
|
||||
|
||||
minetest.set_node(pointed_thing.above, {
|
||||
name = "factions:siege_banner_1"
|
||||
name = "factions:siege_banner_sieging"
|
||||
})
|
||||
|
||||
local meta = minetest.get_meta(pointed_thing.above)
|
||||
|
||||
meta:set_int("stage",0)
|
||||
meta:set_string("attacking_faction", attacking_faction.name)
|
||||
meta:set_string("defending_faction", defending_faction.name)
|
||||
|
||||
@ -99,74 +105,51 @@ minetest.register_craftitem("factions:siege_banner", {
|
||||
|
||||
local siege_banner_stages = 4
|
||||
|
||||
for i = 1, siege_banner_stages do
|
||||
minetest.register_node("factions:siege_banner_" .. i, {
|
||||
drawtype = "normal",
|
||||
tiles = {"siege_banner.png"},
|
||||
description = "Siege Banner (" .. i .. "/" .. siege_banner_stages .. ")",
|
||||
groups = {cracky=3},
|
||||
diggable = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "",
|
||||
})
|
||||
end
|
||||
minetest.register_node("factions:siege_banner_sieging", {
|
||||
drawtype = "normal",
|
||||
tiles = {"siege_banner.png"},
|
||||
description = "Siege Banner",
|
||||
groups = {cracky=3},
|
||||
diggable = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
drop = "",
|
||||
on_construct = function(pos)
|
||||
minetest.get_node_timer(pos):start(config.siege_banner_interval)
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local att_fac_name = meta:get_string("attacking_faction")
|
||||
local def_fac_name = meta:get_string("defending_faction")
|
||||
local stage = meta:get_int("stage")
|
||||
stage = stage + 1
|
||||
|
||||
for j = 1, siege_banner_stages - 1 do
|
||||
minetest.register_abm({
|
||||
label = "Siege Banner state change (" .. j .. ")",
|
||||
nodenames = {"factions:siege_banner_" .. j},
|
||||
|
||||
interval = config.siege_banner_interval,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local att_fac_name = meta:get_string("attacking_faction")
|
||||
local def_fac_name = meta:get_string("defending_faction")
|
||||
if stage <= siege_banner_stages then
|
||||
minetest.get_meta(pos):set_string("infotext", "Siege Banner " .. stage .. "/" .. siege_banner_stages .. " (" .. att_fac_name .. " vs " .. def_fac_name .. ")")
|
||||
factions.get_faction(def_fac_name):broadcast("Your parcel at " .. format_pos(pos) .. " is being sieged (" .. stage .. "/" .. siege_banner_stages .. ")")
|
||||
meta:set_int("stage",stage)
|
||||
meta:set_string("attacking_faction", att_fac_name)
|
||||
meta:set_string("defending_faction", def_fac_name)
|
||||
return true
|
||||
else
|
||||
local attacking_faction = factions.get_faction(att_fac_name)
|
||||
local defending_faction = factions.get_faction(def_fac_name)
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
|
||||
minetest.set_node(pos, { name = "factions:siege_banner_" .. j + 1 })
|
||||
minetest.get_meta(pos):set_string("infotext", "Siege Banner " .. j + 1 .. "/" .. siege_banner_stages .. " (" .. att_fac_name .. " vs " .. def_fac_name .. ")")
|
||||
|
||||
factions.get_faction(def_fac_name):broadcast("Your parcel at " .. format_pos(pos) .. "is being sieged (" .. j + 1 .. "/" .. siege_banner_stages .. ")")
|
||||
if defending_faction then
|
||||
defending_faction:bulk_unclaim_parcel(parcelpos)
|
||||
|
||||
meta:set_string("attacking_faction", att_fac_name)
|
||||
meta:set_string("defending_faction", def_fac_name)
|
||||
end
|
||||
})
|
||||
end
|
||||
defending_faction:broadcast(att_fac_name .. " has successfully conquered your parcel at " .. format_pos(pos))
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
label = "Siege Banner state change (4)",
|
||||
nodenames = {"factions:siege_banner_4"},
|
||||
|
||||
interval = config.siege_banner_interval,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if attacking_faction then
|
||||
attacking_faction:bulk_claim_parcel(parcelpos)
|
||||
|
||||
local att_fac_name = meta:get_string("attacking_faction")
|
||||
local def_fac_name = meta:get_string("defending_faction")
|
||||
|
||||
local attacking_faction = factions.get_faction(att_fac_name)
|
||||
local defending_faction = factions.get_faction(def_fac_name)
|
||||
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
|
||||
if defending_faction then
|
||||
defending_faction:bulk_unclaim_parcel(parcelpos)
|
||||
|
||||
defending_faction:broadcast(att_fac_name .. " has successfully conquered your parcel at " .. format_pos(pos))
|
||||
end
|
||||
|
||||
if attacking_faction then
|
||||
attacking_faction:bulk_claim_parcel(parcelpos)
|
||||
|
||||
attacking_faction:broadcast("Successfully conquered parcel at " .. format_pos(pos) .. " !")
|
||||
end
|
||||
|
||||
|
||||
minetest.set_node(pos, { name = "bones:bones" })
|
||||
end
|
||||
attacking_faction:broadcast("Successfully conquered parcel at " .. format_pos(pos) .. " !")
|
||||
end
|
||||
minetest.set_node(pos, { name = "bones:bones" })
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
if minetest.get_modpath("default") and minetest.get_modpath("bones") then
|
||||
|
BIN
mods/factions/textures/factions_display.png
Normal file
BIN
mods/factions/textures/factions_display.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 235 B |
2
mods/factions/textures/license.txt
Normal file
2
mods/factions/textures/license.txt
Normal file
@ -0,0 +1,2 @@
|
||||
following Textures created by Coder12a (CC BY-SA 3.0):
|
||||
factions_display.png
|
Loading…
x
Reference in New Issue
Block a user