Make: mod into modpack
This commit is contained in:
375
fac_events/claim_events.lua
Normal file
375
fac_events/claim_events.lua
Normal file
@ -0,0 +1,375 @@
|
||||
--! @param parcelpos position of the wanted parcel
|
||||
--! @return whether this faction can claim a parcelpos
|
||||
function factions.can_claim_parcel(name, parcelpos)
|
||||
local fn = factions.parcels.get(parcelpos)
|
||||
if fn == nil then
|
||||
return true
|
||||
end
|
||||
local faction = factions.factions.get(name)
|
||||
if fn then
|
||||
local fac = factions.factions.get(fn.faction)
|
||||
if fac.power < 0. and faction.power >= factions_config.power_per_parcel and not faction.allies[fn] and not faction.neutral[fn] then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
elseif faction.power < factions_config.power_per_parcel then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.claim_parcel(name, parcelpos)
|
||||
-- check if claiming over other faction's territory
|
||||
local otherfac = factions.parcels.get(parcelpos)
|
||||
if otherfac then
|
||||
local otherfac_name = otherfac.faction
|
||||
factions.unclaim_parcel(otherfac_name, parcelpos)
|
||||
factions.parcelless_check(otherfac_name)
|
||||
end
|
||||
local data = factions.create_parcel_table()
|
||||
data.faction = name
|
||||
factions.parcels.set(parcelpos, data)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.land[parcelpos] = true
|
||||
factions.factions.set(name, faction)
|
||||
factions.decrease_power(name, factions_config.power_per_parcel)
|
||||
factions.increase_usedpower(name, factions_config.power_per_parcel)
|
||||
factions.on_claim_parcel(name, parcelpos)
|
||||
factions.parcelless_check(name)
|
||||
end
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.unclaim_parcel(name, parcelpos)
|
||||
factions.remove_key(factions.parcels, parcelpos, nil, "faction", true)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.land[parcelpos] = nil
|
||||
factions.factions.set(name, faction)
|
||||
factions.increase_power(name, factions_config.power_per_parcel)
|
||||
factions.decrease_usedpower(name, factions_config.power_per_parcel)
|
||||
factions.on_unclaim_parcel(name, parcelpos)
|
||||
factions.parcelless_check(name)
|
||||
end
|
||||
|
||||
function factions.parcelless_check(name)
|
||||
local faction = factions.factions.get(name)
|
||||
if faction.land then
|
||||
local count = 0
|
||||
for index, value in pairs(faction.land) do
|
||||
count = count + 1
|
||||
break
|
||||
end
|
||||
if count > 0 then
|
||||
if faction.no_parcel ~= -1 then
|
||||
factions.broadcast(name, "Faction " .. name .. " will not be disbanded because it now has parcels.")
|
||||
end
|
||||
faction.no_parcel = -1
|
||||
else
|
||||
faction.no_parcel = os.time()
|
||||
factions.on_no_parcel(name)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
end
|
||||
|
||||
function factions.get_parcel_faction(parcelpos)
|
||||
local data = factions.parcels.get(parcelpos)
|
||||
if data then
|
||||
local facname = data.faction
|
||||
local faction = factions.factions.get(facname)
|
||||
return faction, facname
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function claim_helper(player, faction, parcelpos, no_msgs)
|
||||
faction = factions.factions.get(faction.name)
|
||||
if not faction then
|
||||
return false
|
||||
end
|
||||
if faction.power < factions_config.power_per_parcel then
|
||||
if not no_msgs then
|
||||
minetest.chat_send_player(player, "Not enough power.")
|
||||
end
|
||||
return false
|
||||
end
|
||||
local p = parcelpos
|
||||
local can_claim = factions.can_claim_parcel(faction.name, p)
|
||||
|
||||
if can_claim then
|
||||
minetest.chat_send_player(player, "Claming parcel " .. p)
|
||||
factions.claim_parcel(faction.name, p)
|
||||
return true
|
||||
else
|
||||
local parcel_faction = factions.get_parcel_faction(p)
|
||||
if parcel_faction and parcel_faction.name == faction.name then
|
||||
if not no_msgs then
|
||||
minetest.chat_send_player(player, "This parcel already belongs to your faction")
|
||||
end
|
||||
return false
|
||||
elseif parcel_faction and parcel_faction.name ~= faction.name then
|
||||
if not no_msgs then
|
||||
minetest.chat_send_player(player, "This parcel belongs to another faction")
|
||||
end
|
||||
return false
|
||||
else
|
||||
if not no_msgs then
|
||||
minetest.chat_send_player(player, "Your faction cannot claim any (more) parcel(s).")
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function unclaim_helper(player, faction, parcelpos, no_msgs)
|
||||
faction = factions.factions.get(faction.name)
|
||||
if not faction then
|
||||
return false
|
||||
end
|
||||
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||
if not parcel_faction then
|
||||
if not no_msgs then
|
||||
minetest.chat_send_player(player, "This parcel does not exist.")
|
||||
end
|
||||
return false
|
||||
end
|
||||
if parcel_faction.name ~= faction.name then
|
||||
if not no_msgs then
|
||||
minetest.chat_send_player(player, "This parcel does not belong to you.")
|
||||
end
|
||||
return false
|
||||
else
|
||||
factions.unclaim_parcel(faction.name, parcelpos)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local parcel_size = factions_config.parcel_size
|
||||
|
||||
function factions.claim_square(player, faction, r)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
pos.x = pos.x - (parcel_size * (r - math.floor(r / 2)))
|
||||
pos.z = pos.z - (parcel_size * (r - math.floor(r / 2)))
|
||||
local timer = 0
|
||||
for i = 1, r do
|
||||
for l = 1, r do
|
||||
local p = {x = pos.x + (parcel_size * l), y = pos.y, z = pos.z + (parcel_size * i)}
|
||||
minetest.after(timer, claim_helper, player, faction, factions.get_parcel_pos(p), true)
|
||||
|
||||
timer = timer + 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
local auto_list = {}
|
||||
local function _claim_auto(player, faction)
|
||||
if auto_list[player] then
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local parcelpos = vector.round(rplayer:get_pos())
|
||||
claim_helper(player, faction, factions.get_parcel_pos(parcelpos), true)
|
||||
minetest.after(0.1, _claim_auto, player, faction)
|
||||
end
|
||||
end
|
||||
function factions.claim_auto(player, faction)
|
||||
if auto_list[player] then
|
||||
auto_list[player] = nil
|
||||
minetest.chat_send_player(player, "Auto claim disabled.")
|
||||
else
|
||||
auto_list[player] = true
|
||||
minetest.chat_send_player(player, "Auto claim enabled.")
|
||||
_claim_auto(player, faction)
|
||||
end
|
||||
end
|
||||
local function _claim_fill(player, faction, pos)
|
||||
if claim_helper(player, faction, factions.get_parcel_pos(pos), true) then
|
||||
local pos1 = {x = pos.x - parcel_size, y = pos.y, z = pos.z}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_fill, player, faction, pos1)
|
||||
local pos2 = {x = pos.x + parcel_size, y = pos.y, z = pos.z}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_fill, player, faction, pos2)
|
||||
local pos3 = {x = pos.x, y = pos.y, z = pos.z - parcel_size}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_fill, player, faction, pos3)
|
||||
local pos4 = {x = pos.x, y = pos.y, z = pos.z + parcel_size}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_fill, player, faction, pos4)
|
||||
end
|
||||
end
|
||||
function factions.claim_fill(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
|
||||
_claim_fill(player, faction, pos)
|
||||
end
|
||||
|
||||
local parcel_size_center = parcel_size / 2
|
||||
|
||||
function factions.claim_circle(player, faction, r)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = (math.floor(pos.x / parcel_size) * parcel_size) + parcel_size_center
|
||||
pos.z = (math.floor(pos.z / parcel_size) * parcel_size) + parcel_size_center
|
||||
|
||||
for i = 1, 360 do
|
||||
local angle = i * math.pi / 180
|
||||
local rpos = {x = pos.x + r * math.cos(angle), y = pos.y, z = pos.z + r * math.sin(angle)}
|
||||
claim_helper(player, faction, factions.get_parcel_pos(rpos), true)
|
||||
end
|
||||
end
|
||||
|
||||
local function _claim_all(player, faction, pos)
|
||||
if faction.power >= factions_config.power_per_parcel then
|
||||
claim_helper(player, faction, factions.get_parcel_pos(pos), true)
|
||||
local pos1 = {x = pos.x - parcel_size, y = pos.y, z = pos.z}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_all, player, faction, pos1)
|
||||
local pos2 = {x = pos.x + parcel_size, y = pos.y, z = pos.z}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_all, player, faction, pos2)
|
||||
local pos3 = {x = pos.x, y = pos.y, z = pos.z - parcel_size}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_all, player, faction, pos3)
|
||||
local pos4 = {x = pos.x, y = pos.y, z = pos.z + parcel_size}
|
||||
minetest.after(math.random(0, 11) / 10, _claim_all, player, faction, pos4)
|
||||
end
|
||||
end
|
||||
|
||||
function factions.claim_all(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
_claim_all(player, faction, pos)
|
||||
end
|
||||
|
||||
function factions.claim_help(player, func)
|
||||
local text = "All params for /f claim: <o,one, a,auto, f,fill, s,square, c,circle, all, l,list, h,help>, <none, number>"
|
||||
if func == "o" or func == "one" then
|
||||
text = "/f claim o\n/f claim one\n Claim one parcel."
|
||||
elseif func == "a" or func == "auto" then
|
||||
text = "/f claim a\n/f claim auto\nClaim as you walk around."
|
||||
elseif func == "f" or func == "fill" then
|
||||
text = "/f claim f\n/f claim fill\nClaim by filling."
|
||||
elseif func == "s" or func == "square" then
|
||||
text = "/f claim s <number>\n/f claim square <number>\nClaim by square and radius."
|
||||
elseif func == "c" or func == "circle" then
|
||||
text = "/f claim c <number>\n/f claim circle <number>\nClaim by circle and radius."
|
||||
elseif func == "l" or func == "list" then
|
||||
text = "/f claim l\n/f claim list\nList all the faction's claimed land."
|
||||
elseif func == "all" then
|
||||
text = "/f claim all\nClaim all faction land."
|
||||
end
|
||||
minetest.chat_send_player(player, text)
|
||||
end
|
||||
|
||||
function factions.unclaim_square(player, faction, r)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
pos.x = pos.x - (parcel_size * (r - math.floor(r / 2)))
|
||||
pos.z = pos.z - (parcel_size * (r - math.floor(r / 2)))
|
||||
local timer = 0
|
||||
for i = 1, r do
|
||||
for l = 1, r do
|
||||
local p = {x = pos.x + (parcel_size * l), y = pos.y, z = pos.z + (parcel_size * i)}
|
||||
minetest.after(timer, unclaim_helper, player, faction, factions.get_parcel_pos(p), true)
|
||||
|
||||
timer = timer + 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function _unclaim_auto(player, faction)
|
||||
if auto_list[player] then
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local parcelpos = vector.round(rplayer:get_pos())
|
||||
unclaim_helper(player, faction, factions.get_parcel_pos(parcelpos), true)
|
||||
minetest.after(0.1, _unclaim_auto, player, faction)
|
||||
end
|
||||
end
|
||||
|
||||
function factions.unclaim_auto(player, faction)
|
||||
if auto_list[player] then
|
||||
auto_list[player] = nil
|
||||
minetest.chat_send_player(player, "Auto unclaim disabled.")
|
||||
else
|
||||
auto_list[player] = true
|
||||
minetest.chat_send_player(player, "Auto unclaim enabled.")
|
||||
_unclaim_auto(player, faction)
|
||||
end
|
||||
end
|
||||
|
||||
local function _unclaim_fill(player, faction, pos)
|
||||
if unclaim_helper(player, faction, factions.get_parcel_pos(pos), true) then
|
||||
local pos1 = {x = pos.x - parcel_size, y = pos.y, z = pos.z}
|
||||
minetest.after(math.random(0, 11) / 10, _unclaim_fill, player, faction, pos1)
|
||||
local pos2 = {x = pos.x + parcel_size, y = pos.y, z = pos.z}
|
||||
minetest.after(math.random(0, 11) / 10, _unclaim_fill, player, faction, pos2)
|
||||
local pos3 = {x = pos.x, y = pos.y, z = pos.z - parcel_size}
|
||||
minetest.after(math.random(0, 11) / 10, _unclaim_fill, player, faction, pos3)
|
||||
local pos4 = {x = pos.x, y = pos.y, z = pos.z + parcel_size}
|
||||
minetest.after(math.random(0, 11) / 10, _unclaim_fill, player, faction, pos4)
|
||||
end
|
||||
end
|
||||
|
||||
function factions.unclaim_fill(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
_unclaim_fill(player, faction, pos)
|
||||
end
|
||||
|
||||
local parcel_size_center = parcel_size / 2
|
||||
|
||||
function factions.unclaim_circle(player, faction, r)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
pos.x = (math.floor(pos.x / parcel_size) * parcel_size) + parcel_size_center
|
||||
pos.z = (math.floor(pos.z / parcel_size) * parcel_size) + parcel_size_center
|
||||
for i = 1, 360 do
|
||||
local angle = i * math.pi / 180
|
||||
local rpos = {x = pos.x + r * math.cos(angle), y = pos.y, z = pos.z + r * math.sin(angle)}
|
||||
unclaim_helper(player, faction, factions.get_parcel_pos(rpos), true)
|
||||
end
|
||||
end
|
||||
|
||||
local function _unclaim_all(player, faction)
|
||||
local timer = 0
|
||||
for i in pairs(faction.land) do
|
||||
minetest.after(timer, factions.unclaim_parcel, faction.name, i)
|
||||
timer = timer + 0.1
|
||||
end
|
||||
end
|
||||
|
||||
function factions.unclaim_all(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
_unclaim_all(player, faction, pos)
|
||||
end
|
||||
|
||||
function factions.unclaim_help(player, func)
|
||||
local text = "All params for /f unclaim: <o,one, a,auto, f,fill, s,square, c,circle, all, l,list, h,help>, <none, number>"
|
||||
if func == "o" or func == "one" then
|
||||
text = "/f unclaim o\n/f unclaim one\n Unclaim one parcel."
|
||||
elseif func == "a" or func == "auto" then
|
||||
text = "/f unclaim a\n/f unclaim auto\nUnclaim as you walk around."
|
||||
elseif func == "f" or func == "fill" then
|
||||
text = "/f unclaim f\n/f unclaim fill\nUnclaim by filling."
|
||||
elseif func == "s" or func == "square" then
|
||||
text = "/f unclaim s <number>\n/f unclaim square <number>\nUnclaim by square and radius."
|
||||
elseif func == "c" or func == "circle" then
|
||||
text = "/f unclaim c <number>\n/f unclaim circle <number>\nUnclaim by circle and radius."
|
||||
elseif func == "l" or func == "list" then
|
||||
text = "/f claim l\n/f claim list\nList all the faction's claimed land."
|
||||
elseif func == "all" then
|
||||
text = "/f unclaim all\nUnclaim all faction land."
|
||||
end
|
||||
minetest.chat_send_player(player, text)
|
||||
end
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
auto_list[player:get_player_name()] = nil
|
||||
end)
|
74
fac_events/diplomacy_events.lua
Normal file
74
fac_events/diplomacy_events.lua
Normal file
@ -0,0 +1,74 @@
|
||||
function factions.start_diplomacy(name, faction)
|
||||
for l, i in factions.factions.iterate() do
|
||||
local fac = factions.factions.get(l)
|
||||
if l ~= name and not (faction.neutral[l] or faction.allies[l] or faction.enemies[l]) then
|
||||
if factions_config.faction_diplomacy == true then
|
||||
factions.new_neutral(name, l)
|
||||
factions.new_neutral(l, name)
|
||||
else
|
||||
factions.new_enemy(name, l)
|
||||
factions.new_enemy(l, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function factions.new_alliance(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
bfaction.allies[faction] = true
|
||||
factions.on_new_alliance(name, faction)
|
||||
if bfaction.enemies[faction] then
|
||||
factions.end_enemy(name, faction)
|
||||
end
|
||||
if bfaction.neutral[faction] then
|
||||
factions.end_neutral(name, faction)
|
||||
end
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.end_alliance(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
bfaction.allies[faction] = nil
|
||||
factions.on_end_alliance(name, faction)
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.new_neutral(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
bfaction.neutral[faction] = true
|
||||
factions.on_new_neutral(name, faction)
|
||||
if bfaction.allies[faction] then
|
||||
factions.end_alliance(name, faction)
|
||||
end
|
||||
if bfaction.enemies[faction] then
|
||||
factions.end_enemy(name, faction)
|
||||
end
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.end_neutral(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
bfaction.neutral[faction] = nil
|
||||
factions.on_end_neutral(name, faction)
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.new_enemy(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
bfaction.enemies[faction] = true
|
||||
factions.on_new_enemy(name, faction)
|
||||
if bfaction.allies[faction] then
|
||||
factions.end_alliance(name, faction)
|
||||
end
|
||||
if bfaction.neutral[faction] then
|
||||
factions.end_neutral(name, faction)
|
||||
end
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.end_enemy(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
bfaction.enemies[faction] = nil
|
||||
factions.on_end_enemy(name, faction)
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
106
fac_events/eventcallbacks.lua
Normal file
106
fac_events/eventcallbacks.lua
Normal file
@ -0,0 +1,106 @@
|
||||
function factions.on_create(name) --! @brief called when the faction is added to the global faction list
|
||||
minetest.chat_send_all("Faction " .. name .. " has been created.")
|
||||
end
|
||||
function factions.on_set_name(name, oldname)
|
||||
minetest.chat_send_all("Faction " .. oldname .. " has been changed its name to ".. name ..".")
|
||||
end
|
||||
function factions.on_no_parcel(name)
|
||||
local faction = factions.factions.get(name)
|
||||
local now = os.time() - faction.no_parcel
|
||||
local l = factions_config.maximum_parcelless_faction_time
|
||||
factions.broadcast(name, "This faction will disband in " .. l - now .. " seconds, because it has no parcels.")
|
||||
end
|
||||
function factions.on_player_leave(name, player)
|
||||
factions.broadcast(name, player .. " has left this faction")
|
||||
end
|
||||
function factions.on_player_join(name, player)
|
||||
factions.broadcast(name, player .. " has joined this faction")
|
||||
end
|
||||
function factions.on_claim_parcel(name, pos)
|
||||
factions.broadcast(name, "Parcel (" .. pos .. ") has been claimed.")
|
||||
end
|
||||
function factions.on_unclaim_parcel(name, pos)
|
||||
factions.broadcast(name, "Parcel ("..pos..") has been unclaimed.")
|
||||
end
|
||||
function factions.on_disband(name, reason)
|
||||
local msg = "Faction " .. name .. " has been disbanded."
|
||||
if reason then
|
||||
msg = msg .. " (" .. reason .. ")"
|
||||
end
|
||||
minetest.chat_send_all(msg)
|
||||
end
|
||||
function factions.on_new_leader(name)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, faction.leader .. " is now the leader of this faction")
|
||||
end
|
||||
function factions.on_change_description(name)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "Faction description has been modified to: " .. faction.description)
|
||||
end
|
||||
function factions.on_player_invited(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
minetest.chat_send_player(player, "You have been invited to faction " .. faction.name)
|
||||
end
|
||||
function factions.on_toggle_join_free(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
if faction.join_free then
|
||||
factions.broadcast(name, "This faction is now invite-free.")
|
||||
else
|
||||
factions.broadcast(name, "This faction is no longer invite-free.")
|
||||
end
|
||||
end
|
||||
function factions.on_new_alliance(name, faction)
|
||||
factions.broadcast(name, "This faction is now allied with " .. faction)
|
||||
end
|
||||
function factions.on_end_alliance(name, faction)
|
||||
factions.broadcast(name, "This faction is no longer allied with " .. faction .. "!")
|
||||
end
|
||||
function factions.on_new_neutral(name, faction)
|
||||
factions.broadcast(name, "This faction is now neutral with ".. faction)
|
||||
end
|
||||
function factions.on_end_neutral(name, faction)
|
||||
factions.broadcast(name, "This faction is no longer neutral with " .. faction .. "!")
|
||||
end
|
||||
function factions.on_new_enemy(name, faction)
|
||||
factions.broadcast(name, "This faction is now at war with " .. faction)
|
||||
end
|
||||
function factions.on_end_enemy(name, faction)
|
||||
factions.broadcast(name, "This faction is no longer at war with " .. faction .. "!")
|
||||
end
|
||||
function factions.on_set_spawn(name)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "The faction spawn has been set to (" .. util.coords3D_string(faction.spawn) .. ").")
|
||||
end
|
||||
function factions.on_add_rank(name, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "The rank " .. rank .. " has been created with privileges: " .. table.concat(faction.ranks[rank], ", "))
|
||||
end
|
||||
function factions.on_replace_privs(name, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "The privileges in rank " .. rank .. " have been delete and changed to: " .. table.concat(faction.ranks[rank], ", "))
|
||||
end
|
||||
function factions.on_remove_privs(name, rank, privs)
|
||||
factions.broadcast(name, "The privileges in rank " .. rank .. " have been revoked: " .. table.concat(privs, ", "))
|
||||
end
|
||||
function factions.on_add_privs(name, rank, privs)
|
||||
factions.broadcast(name, "The privileges in rank " .. rank .. " have been added: " .. table.concat(privs, ", "))
|
||||
end
|
||||
function factions.on_set_rank_name(name, rank,newrank)
|
||||
factions.broadcast(name, "The name of rank " .. rank .. " has been changed to " .. newrank)
|
||||
end
|
||||
function factions.on_delete_rank(name, rank, newrank)
|
||||
factions.broadcast(name, "The rank " .. rank .. " has been deleted and replaced by " .. newrank)
|
||||
end
|
||||
function factions.on_set_def_rank(name, rank)
|
||||
factions.broadcast(name, "The default rank given to new players has been changed to " .. rank)
|
||||
end
|
||||
function factions.on_reset_ranks(name)
|
||||
factions.broadcast(name, "All of the faction's ranks have been reset to the default ones.")
|
||||
end
|
||||
function factions.on_promote(name, member)
|
||||
local faction = factions.factions.get(name)
|
||||
minetest.chat_send_player(member, "You have been promoted to " .. faction.players[member])
|
||||
end
|
||||
function factions.on_revoke_invite(name, player)
|
||||
minetest.chat_send_player(player, "You are no longer invited to faction " .. name)
|
||||
end
|
8
fac_events/init.lua
Normal file
8
fac_events/init.lua
Normal file
@ -0,0 +1,8 @@
|
||||
local path = minetest.get_modpath("fac_events")
|
||||
dofile (path .. "/claim_events.lua")
|
||||
dofile (path .. "/diplomacy_events.lua")
|
||||
dofile (path .. "/eventcallbacks.lua")
|
||||
dofile (path .. "/invite_events.lua")
|
||||
dofile (path .. "/player_events.lua")
|
||||
dofile (path .. "/power_events.lua")
|
||||
dofile (path .. "/rank_events.lua")
|
15
fac_events/invite_events.lua
Normal file
15
fac_events/invite_events.lua
Normal file
@ -0,0 +1,15 @@
|
||||
--! @brief places player in invite list
|
||||
function factions.invite_player(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.invited_players[player] = true
|
||||
factions.on_player_invited(name, player)
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
--! @brief removes player from invite list (can no longer join via /f join)
|
||||
function factions.revoke_invite(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.invited_players[player] = nil
|
||||
factions.on_revoke_invite(name, player)
|
||||
factions.factions.set(name, faction)
|
||||
end
|
2
fac_events/mod.conf
Normal file
2
fac_events/mod.conf
Normal file
@ -0,0 +1,2 @@
|
||||
name = fac_events
|
||||
depends = fac
|
85
fac_events/player_events.lua
Normal file
85
fac_events/player_events.lua
Normal file
@ -0,0 +1,85 @@
|
||||
local on_death = {}
|
||||
|
||||
minetest.register_on_prejoinplayer(function(name, ip)
|
||||
local data = factions.create_ip_table()
|
||||
data.ip = ip
|
||||
factions.player_ips.set(name, data)
|
||||
end)
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
minetest.after(5, createHudfactionLand, player)
|
||||
local faction, facname = factions.get_player_faction(name)
|
||||
if faction then
|
||||
if factions.onlineplayers[facname] == nil then
|
||||
factions.onlineplayers[facname] = {}
|
||||
end
|
||||
factions.onlineplayers[facname][name] = true
|
||||
faction.last_logon = os.time()
|
||||
factions.factions.set(facname, faction)
|
||||
minetest.after(5, createHudFactionName, player, facname)
|
||||
minetest.after(5, createHudPower, player, faction)
|
||||
if faction.no_parcel ~= -1 then
|
||||
local now = os.time() - faction.no_parcel
|
||||
local l = factions_config.maximum_parcelless_faction_time
|
||||
minetest.chat_send_player(name, "This faction will disband in " .. l - now .. " seconds, because it has no parcels.")
|
||||
end
|
||||
|
||||
if factions.has_permission(facname, 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
|
||||
|
||||
if faction.message_of_the_day and (faction.message_of_the_day ~= "" or faction.message_of_the_day ~= " ") then
|
||||
minetest.chat_send_player(name, faction.message_of_the_day)
|
||||
end
|
||||
end
|
||||
end)
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local faction, facname = factions.get_player_faction(name)
|
||||
local id_name1 = name .. "factionLand"
|
||||
if hud_ids[id_name1] then
|
||||
hud_ids[id_name1] = nil
|
||||
end
|
||||
if faction then
|
||||
faction.last_logon = os.time()
|
||||
factions.factions.set(facname, faction)
|
||||
factions.onlineplayers[facname][name] = nil
|
||||
|
||||
hud_ids[name .. "factionName"] = nil
|
||||
hud_ids[name .. "powerWatch"] = nil
|
||||
else
|
||||
factions.remove_key(factions.player_ips, name, nil, "ip", true)
|
||||
end
|
||||
on_death[name] = nil
|
||||
end)
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local faction, facname = factions.get_player_faction(name)
|
||||
if not faction then
|
||||
return false
|
||||
else
|
||||
on_death[name] = nil
|
||||
if not faction.spawn then
|
||||
return false
|
||||
else
|
||||
player:set_pos(faction.spawn)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
if on_death[pname] then
|
||||
return
|
||||
end
|
||||
local faction, name = factions.get_player_faction(pname)
|
||||
if not faction then
|
||||
return
|
||||
end
|
||||
factions.decrease_power(name, factions_config.power_per_death)
|
||||
on_death[pname] = true
|
||||
return
|
||||
end
|
||||
)
|
62
fac_events/power_events.lua
Normal file
62
fac_events/power_events.lua
Normal file
@ -0,0 +1,62 @@
|
||||
function factions.increase_power(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.power = faction.power + power
|
||||
if faction.power > faction.maxpower - faction.usedpower then
|
||||
faction.power = faction.maxpower - faction.usedpower
|
||||
end
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.decrease_power(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.power = faction.power - power
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.increase_maxpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.maxpower = faction.maxpower + power
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.decrease_maxpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.maxpower = faction.maxpower - power
|
||||
if faction.maxpower < 0 then -- should not happen
|
||||
faction.maxpower = 0
|
||||
end
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.increase_usedpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.usedpower = faction.usedpower + power
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.decrease_usedpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.usedpower = faction.usedpower - power
|
||||
if faction.usedpower < 0 then
|
||||
faction.usedpower = 0
|
||||
end
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
138
fac_events/rank_events.lua
Normal file
138
fac_events/rank_events.lua
Normal file
@ -0,0 +1,138 @@
|
||||
--! @brief create a new rank with permissions
|
||||
--! @param rank the name of the new rank
|
||||
--! @param rank a list with the permissions of the new rank
|
||||
function factions.add_rank(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.ranks[rank] = perms
|
||||
factions.on_add_rank(name, rank)
|
||||
factions.factions.set(name, faction)
|
||||
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.replace_privs(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.ranks[rank] = perms
|
||||
factions.on_replace_privs(name, rank)
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.remove_privs(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
local revoked = false
|
||||
local p = faction.ranks[rank]
|
||||
for index, perm in pairs(p) do
|
||||
if table_Contains(perms, perm) then
|
||||
revoked = true
|
||||
table.remove(p, index)
|
||||
end
|
||||
end
|
||||
faction.ranks[rank] = p
|
||||
if revoked then
|
||||
factions.on_remove_privs(name, rank, perms)
|
||||
else
|
||||
factions.broadcast(name, "No privilege was revoked from rank " .. rank .. ".")
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.add_privs(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
local added = false
|
||||
local p = faction.ranks[rank]
|
||||
for index, perm in pairs(perms) do
|
||||
if not table_Contains(p, perm) then
|
||||
added = true
|
||||
table.insert(p, perm)
|
||||
end
|
||||
end
|
||||
faction.ranks[rank] = p
|
||||
if added then
|
||||
factions.on_add_privs(name, rank, perms)
|
||||
else
|
||||
factions.broadcast(name, "The rank " .. rank .. " already has these privileges.")
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.set_rank_name(name, oldrank, newrank)
|
||||
local faction = factions.factions.get(name)
|
||||
local copyrank = faction.ranks[oldrank]
|
||||
faction.ranks[newrank] = copyrank
|
||||
faction.ranks[oldrank] = nil
|
||||
for player, r in pairs(faction.players) do
|
||||
if r == oldrank then
|
||||
faction.players[player] = newrank
|
||||
end
|
||||
end
|
||||
if oldrank == faction.default_leader_rank then
|
||||
faction.default_leader_rank = newrank
|
||||
factions.broadcast(name, "The default leader rank has been set to " .. newrank)
|
||||
end
|
||||
if oldrank == faction.default_rank then
|
||||
faction.default_rank = newrank
|
||||
factions.broadcast(name, "The default rank given to new players is set to " .. newrank)
|
||||
end
|
||||
factions.on_set_rank_name(name, oldrank, newrank)
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.set_def_rank(name, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
for player, r in pairs(faction.players) do
|
||||
if r == rank or r == nil or not faction.ranks[r] then
|
||||
faction.players[player] = rank
|
||||
end
|
||||
end
|
||||
faction.default_rank = rank
|
||||
factions.on_set_def_rank(name, rank)
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.reset_ranks(name)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.ranks = starting_ranks
|
||||
faction.default_rank = "member"
|
||||
faction.default_leader_rank_rank = "leader"
|
||||
for player, r in pairs(faction.players) do
|
||||
if not player == leader and (r == nil or not faction.ranks[r]) then
|
||||
faction.players[player] = faction.default_rank
|
||||
elseif player == leader then
|
||||
faction.players[player] = faction.default_leader_rank_rank
|
||||
end
|
||||
end
|
||||
factions.on_reset_ranks(name)
|
||||
factions.factions.set(name, faction)
|
||||
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"
|
||||
function factions.delete_rank(name, rank, newrank)
|
||||
local faction = factions.factions.get(name)
|
||||
for player, r in pairs(faction.players) do
|
||||
if r == rank then
|
||||
faction.players[player] = newrank
|
||||
end
|
||||
end
|
||||
faction.ranks[rank] = nil
|
||||
factions.on_delete_rank(name, rank, newrank)
|
||||
if rank == faction.default_leader_rank then
|
||||
faction.default_leader_rank = newrank
|
||||
factions.broadcast(name, "The default leader rank has been set to "..newrank)
|
||||
end
|
||||
if rank == faction.default_rank then
|
||||
faction.default_rank = newrank
|
||||
factions.broadcast(name, "The default rank given to new players is set to "..newrank)
|
||||
end
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
--! @brief set a player's rank
|
||||
function factions.promote(name, member, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
faction.players[member] = rank
|
||||
factions.on_promote(name, member)
|
||||
factions.factions.set(name, faction)
|
||||
end
|
Reference in New Issue
Block a user