commit
398162f2c4
@ -25,7 +25,7 @@
|
||||
end
|
||||
minetest.node_dig(pos, n, p)
|
||||
end,
|
||||
})
|
||||
})]]
|
||||
|
||||
minetest.register_node("factions:death_banner", {
|
||||
drawtype = "normal",
|
||||
@ -56,7 +56,7 @@ minetest.register_node("factions:death_banner", {
|
||||
end,
|
||||
})
|
||||
|
||||
after_powerbanner_placed = function(pos, player, itemstack, pointed_thing)
|
||||
--[[after_powerbanner_placed = function(pos, player, itemstack, pointed_thing)
|
||||
--minetest.get_node(pos).param2 = determine_flag_direction(pos, pointed_thing)
|
||||
local faction = factions.players[player:get_player_name()]
|
||||
if not faction then
|
||||
@ -67,7 +67,7 @@ after_powerbanner_placed = function(pos, player, itemstack, pointed_thing)
|
||||
minetest.get_meta(pos):set_string("faction", faction)
|
||||
factions.factions[faction]:increase_maxpower(config.power_per_banner)
|
||||
end
|
||||
end
|
||||
end]]
|
||||
|
||||
after_deathbanner_placed = function(pos, player, itemstack, pointed_thing)
|
||||
-- minetest.get_node(pos).param2 = determine_flag_direction(pos, pointed_thing)
|
||||
@ -81,7 +81,7 @@ after_deathbanner_placed = function(pos, player, itemstack, pointed_thing)
|
||||
minetest.get_meta(pos):set_string("banner", "death_uv.png")
|
||||
end
|
||||
|
||||
if minetest.get_modpath("default") then
|
||||
--[[if minetest.get_modpath("default") then
|
||||
minetest.register_craft({
|
||||
output = 'factions:power_banner',
|
||||
recipe = {
|
||||
@ -90,7 +90,7 @@ if minetest.get_modpath("default") then
|
||||
{'default:mese_crystal','default:mese_crystal','default:mese_crystal'}
|
||||
}
|
||||
})
|
||||
end
|
||||
end]]
|
||||
|
||||
if minetest.get_modpath("default") and minetest.get_modpath("bones") then
|
||||
minetest.register_craft({
|
||||
@ -101,4 +101,4 @@ if minetest.get_modpath("default") and minetest.get_modpath("bones") then
|
||||
{'default:obsidian','default:obsidian','default:obsidian'}
|
||||
}
|
||||
})
|
||||
end--]]
|
||||
end
|
@ -25,4 +25,5 @@ config.maximum_faction_inactivity = tonumber(minetest.setting_get("maximum_facti
|
||||
config.power = tonumber(minetest.setting_get("power")) or 1
|
||||
config.maxpower = tonumber(minetest.setting_get("maxpower")) or 4
|
||||
config.power_per_banner = minetest.settings:get("power_per_banner") or 1
|
||||
config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
|
||||
config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
|
||||
config.siege_banner_interval = minetest.settings:get_bool("siege_banner_interval") or 120
|
35
mods/factions/debug.lua
Normal file
35
mods/factions/debug.lua
Normal file
@ -0,0 +1,35 @@
|
||||
function table.val_to_str ( v )
|
||||
if "string" == type( v ) then
|
||||
v = string.gsub( v, "\n", "\\n" )
|
||||
if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
|
||||
return "'" .. v .. "'"
|
||||
end
|
||||
return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
|
||||
else
|
||||
return "table" == type( v ) and table.tostring( v ) or
|
||||
tostring( v )
|
||||
end
|
||||
end
|
||||
|
||||
function table.key_to_str ( k )
|
||||
if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
|
||||
return k
|
||||
else
|
||||
return "[" .. table.val_to_str( k ) .. "]"
|
||||
end
|
||||
end
|
||||
|
||||
function table.tostring( tbl )
|
||||
local result, done = {}, {}
|
||||
for k, v in ipairs( tbl ) do
|
||||
table.insert( result, table.val_to_str( v ) )
|
||||
done[ k ] = true
|
||||
end
|
||||
for k, v in pairs( tbl ) do
|
||||
if not done[ k ] then
|
||||
table.insert( result,
|
||||
table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
|
||||
end
|
||||
end
|
||||
return "{" .. table.concat( result, "," ) .. "}"
|
||||
end
|
@ -311,6 +311,12 @@ function factions.Faction.claim_parcel(self, parcelpos)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.bulk_claim_parcel(self, parcelpos)
|
||||
factions.parcels[parcelpos] = self.name
|
||||
self.land[parcelpos] = true
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.Faction.unclaim_parcel(self, parcelpos)
|
||||
factions.parcels[parcelpos] = nil
|
||||
@ -321,6 +327,12 @@ function factions.Faction.unclaim_parcel(self, parcelpos)
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.bulk_unclaim_parcel(self, parcelpos)
|
||||
factions.parcels[parcelpos] = nil
|
||||
self.land[parcelpos] = nil
|
||||
factions.save()
|
||||
end
|
||||
|
||||
--! @brief disband faction, updates global players and parcels table
|
||||
function factions.Faction.disband(self, reason)
|
||||
local playerslist = minetest.get_connected_players()
|
||||
|
@ -19,9 +19,11 @@ core.log("action", "MOD: factions (by sapier) loading ...")
|
||||
--!path of mod
|
||||
factions_modpath = minetest.get_modpath("factions")
|
||||
|
||||
dofile (factions_modpath .. "/debug.lua")
|
||||
dofile (factions_modpath .. "/config.lua")
|
||||
dofile (factions_modpath .. "/banner.lua")
|
||||
--dofile (factions_modpath .. "/banner.lua")
|
||||
dofile (factions_modpath .. "/factions.lua")
|
||||
dofile (factions_modpath .. "/siege.lua")
|
||||
dofile (factions_modpath .. "/chatcommands.lua")
|
||||
dofile (factions_modpath .. "/nodes.lua")
|
||||
|
||||
|
@ -11,7 +11,7 @@ power_per_tick (Power-per-tick) float 0.125
|
||||
# Faction timer. This timer regenerates power if the faction members are online.
|
||||
tick_time (Faction timer) float 60
|
||||
# Not in use.
|
||||
power_per_attack (Power-per-attack) float 10
|
||||
power_per_attack (Power-per-attack) float 10
|
||||
# Limit how long a faction name can be.
|
||||
faction_name_max_length (Faction name max) int 50
|
||||
# Limit how long a rank name can be.
|
||||
@ -28,4 +28,4 @@ power_per_banner (power-per-banner) float 10
|
||||
[BoolSettings]
|
||||
|
||||
# Enable or disabled attack_parcel function.
|
||||
attack_parcel (Enable attack parcel) bool false
|
||||
attack_parcel (Enable attack parcel) bool false
|
176
mods/factions/siege.lua
Normal file
176
mods/factions/siege.lua
Normal file
@ -0,0 +1,176 @@
|
||||
factions.sieges = {}
|
||||
|
||||
local function format_pos(pos)
|
||||
return "(" .. pos.x .. ", " .. pos.y .. ", " .. pos.z .. ")"
|
||||
end
|
||||
|
||||
local function siege_banner_onplace_check(player, pointed_thing, attacking_player, attacking_faction, pointedpos, parcelpos, defending_faction)
|
||||
if attacking_player == nil then
|
||||
minetest.chat_send_player(player:get_player_name(), "You don't belong to a faction")
|
||||
return false
|
||||
end
|
||||
|
||||
if not pointed_thing.type == "node" then
|
||||
minetest.chat_send_player(player:get_player_name(), "Point a node to place a Siege Banner")
|
||||
return false
|
||||
end
|
||||
|
||||
if attacking_faction == nil then
|
||||
minetest.chat_send_player(player:get_player_name(), "You don't belong to a faction")
|
||||
return false
|
||||
end
|
||||
|
||||
if pointedpos.y <= config.protection_max_depth then
|
||||
minetest.chat_send_player(player:get_player_name(), "You can't place a Siege Banner that deep")
|
||||
return false
|
||||
end
|
||||
|
||||
if defending_faction == nil then
|
||||
minetest.chat_send_player(player:get_player_name(), "This parcel doesn't belong to a faction")
|
||||
return false
|
||||
end
|
||||
|
||||
if defending_faction == attacking_faction then
|
||||
minetest.chat_send_player(player:get_player_name(), "This parcel belongs to your own faction")
|
||||
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")
|
||||
return false
|
||||
end
|
||||
|
||||
local is_defending_faction_online = false
|
||||
|
||||
for i, _player in pairs(minetest.get_connected_players()) do
|
||||
local playername = _player:get_player_name()
|
||||
|
||||
if factions.get_player_faction(playername) == defending_faction then
|
||||
is_defending_faction_online = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not is_defending_faction_online then
|
||||
minetest.chat_send_player(player:get_player_name(), "There are no players from the defending faction online")
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_craftitem("factions:siege_banner", {
|
||||
description = "Siege Banner",
|
||||
inventory_image = "siege_banner.png",
|
||||
stack_max = 1,
|
||||
groups = {banner = 1},
|
||||
|
||||
on_place = function(itemstack, player, pointed_thing)
|
||||
local attacking_player = factions.players[player:get_player_name()]
|
||||
local attacking_faction = factions.factions[attacking_player]
|
||||
local pointedpos = pointed_thing.above
|
||||
local parcelpos = factions.get_parcel_pos(pointedpos)
|
||||
local defending_faction = factions.get_parcel_faction(parcelpos)
|
||||
|
||||
if not siege_banner_onplace_check(player, pointed_thing, attacking_player, attacking_faction, pointedpos, parcelpos, defending_faction) then
|
||||
return nil
|
||||
end
|
||||
|
||||
minetest.chat_send_player(player:get_player_name(), "Sieging parcel at " .. format_pos(pointed_thing.above))
|
||||
|
||||
local defending_faction = factions.get_faction_at(pointed_thing.above)
|
||||
|
||||
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"
|
||||
})
|
||||
|
||||
local meta = minetest.get_meta(pointed_thing.above)
|
||||
|
||||
meta:set_string("attacking_faction", attacking_faction.name)
|
||||
meta:set_string("defending_faction", defending_faction.name)
|
||||
|
||||
minetest.get_meta(pointed_thing.above):set_string("infotext", "Siege Banner 1/4 (" .. attacking_faction.name .. " vs " .. defending_faction.name .. ")")
|
||||
|
||||
return ""
|
||||
end
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
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")
|
||||
|
||||
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 .. ")")
|
||||
|
||||
meta:set_string("attacking_faction", att_fac_name)
|
||||
meta:set_string("defending_faction", def_fac_name)
|
||||
end
|
||||
})
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
defending_faction:bulk_unclaim_parcel(parcelpos)
|
||||
defending_faction:decrease_usedpower(factions.power_per_parcel)
|
||||
attacking_faction:bulk_claim_parcel(parcelpos)
|
||||
attacking_faction:increase_usedpower(factions.power_per_parcel)
|
||||
|
||||
defending_faction:broadcast(att_fac_name .. " has successfully conquered your parcel at " .. format_pos(pos))
|
||||
attacking_faction:broadcast("Successfully conquered parcel at " .. format_pos(pos) .. " !")
|
||||
|
||||
minetest.set_node(pos, { name = "bones:bones" })
|
||||
end
|
||||
})
|
||||
|
||||
if minetest.get_modpath("default") and minetest.get_modpath("bones") then
|
||||
minetest.register_craft({
|
||||
output = 'factions:siege_banner',
|
||||
recipe = {
|
||||
{'default:obsidian','default:obsidian','default:obsidian'},
|
||||
{'default:obsidian','bones:bones','default:obsidian'},
|
||||
{'default:obsidian','default:obsidian','default:obsidian'}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
BIN
mods/factions/textures/siege_banner.png
Normal file
BIN
mods/factions/textures/siege_banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 657 B |
Loading…
x
Reference in New Issue
Block a user