Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce flagwars game mode #1115

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
117 changes: 117 additions & 0 deletions mods/ctf/ctf_modes/ctf_mode_flagwars/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
local rankings = ctf_rankings.init()
local recent_rankings = ctf_modebase.recent_rankings(rankings)
local features = ctf_modebase.features(rankings, recent_rankings)

ctf_core.include_files("shop.lua", "spawners.lua")

local old_bounty_reward_func = ctf_modebase.bounties.bounty_reward_func
local old_get_next_bounty = ctf_modebase.bounties.get_next_bounty
local old_get_skin = ctf_cosmetics.get_skin
local custom_item_levels = table.copy(features.initial_stuff_item_levels)

ctf_modebase.register_mode("flagwars", {
treasures = {
["default:ladder_wood"] = {
max_count = 20,
rarity = 0.3,
max_stacks = 5
},
["default:torch"] = {
max_count = 10,
rarity = 0.3,
max_stacks = 5,
},
["default:cobble"] = {
max_count = 20,
min_count = 2,
max_stacks = 2,
rarity = 0.15,
},
["default:wood"] = {
max_count = 20,
min_count = 2,
max_stacks = 2,
rarity = 0.15,
},
},
crafts = {},
physics = {
sneak_glitch = true,
new_move = false,
},
team_chest_items = {
"default:cobble 40",
"default:wood 40",
"ctf_map:damage_cobble 20",
"ctf_map:rinforcedc_cobble 20",
"default:torch 10",
"ctf_teams:door_steel 1",
},
rankings = rankings,
recent_rankings = recent_rankings,
summary_ranks = {
_sort = "score",
"score",
"flag_captures",
"flag_attempts",
"kills",
"kill_assits",
"bounty_kills",
"deaths",
"hp_healed",
},
build_timer = 90,
is_bound_item = function(_, name)
return false
end,
stuff_provider = function(player)
local initial_stuff = {
"default:sword_stone",
"default:torch 10",
"default:cobble 10",
}

return initial_stuff
end,
initial_stuff_item_levels = custom_item_levels,
is_restricted_item = function(player, name)
return false
end,
on_mode_start = function()
ctf_modebase.bounties.bounty_reward_func = ctf_modebase.bounty_algo.kd.bounty_reward_func
ctf_modebase.bounties.get_next_bounty = ctf_modebase.bounty_algo.kd.get_next_bounty
ctf_cosmetics.get_skin = function(player)
if not ctf_teams.get(player) then
return old_get_skin(player)
end

return old_get_skin(player)
end
end,
on_mode_end = function()
ctf_modebase.bounties.bounty.bounty_reward_func = old_bounty_reward_func
ctf_modebase.bounties.get_next_bounty = old_get_next_bounty
ctf_cosmetics.get_skin = old_get_skin
end,
on_new_match = features.on_new_match,
on_match_end = features.on_match_end,
team_allocator = features.team_allocator,
on_allocplayer = features.on_allocplayer,
on_leaveplayer = features.on_leaveplayer,
on_dieplayer = features.on_dieplayer,
on_respawn_player = features.on_respawnplayer,
can_take_flag = features.can_take_flag,
on_flag_take = function(player)
ctf_modebase.capture_flag(player)
end,
on_flag_drop = function() end,
on_flag_capture = features.on_flag_capture,
on_flag_rightclick = function() end,
get_chest_access = features.get_chest_access,
can_punchplayer = features.can_punchplayer,
on_punchplayer = features.on_punchplayer,
on_healplayer = features.on_healplayer,
calculate_knockback = function()
return 0
end,
})
2 changes: 2 additions & 0 deletions mods/ctf/ctf_modes/ctf_mode_flagwars/mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = ctf_mode_flagwars
depends = ctf_modebase, ctf_teams, ctf_api, ctf_melee, ctf_gui, ctf_cosmetics, ctf_rankings, ctf_map, default
68 changes: 68 additions & 0 deletions mods/ctf/ctf_modes/ctf_mode_flagwars/shop.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
local items_to_sell = {
{ "default:sword_diamond 1", "default:gold_ingot 6" },
{ "default:sword_mese 1", "default:gold_ingot 5" },
}

local function get_shop_formspec()
local result = ""
local size_w = 0
local size_h = 0
for _, trade in pairs(items_to_sell) do
result = result ..
string.format("item_image_button[%d,%d;%d,%d;%s;%s;]", size_w + 1, size_h + 1, 1, 1, trade[2], trade[2])
result = result ..
string.format("item_image[%d,%d;%d,%d;%s]", size_w + 2, size_h + 1, 1, 1, trade[1])
size_h = size_h + 1
if size_h >= 5 then
size_w = size_w + 3
size_h = 0
end
end
return string.format("size[%d,%d]", size_w + 2, 5)
end


minetest.register_node("ctf_mode_flagwars:shop", {
walkable = true,
pointable = true,
diggable = false,
on_rightclick = function(pos, node, clicker, itemstack)
local pname = clicker:get_player_name()
if pname == "" then
return
end
local team = ctf_teams.get_team(pname)
local meta = minetest.get_meta(pos)
if team ~= meta:get_string("team") then
minetest.chat_send_player(pname, "You are not on this shop's team")
return itemstack
end

minetest.show_formspec(pname, "ctf_modes_flagwars:shop", get_shop_formspec())
return itemstack
end,
on_construct = function(pos)
if not ctf_map.current_map then
return
end
local closest_team = { team = "none", distance = -1 }
for team, team_props in pairs(ctf_map.current_map.teams) do
local dist = vector.distance(team_props.flag_pos, pos)
if dist < closest_team["distance"] then
closest_team["distance"] = dist
closest_team["team"] = team
end
end
local team_number = string.match(closest_team["team"], "team.(.*)")
local team_color
local i = 0
for team, _ in pairs(ctf_teams["team"]) do
if i == team_number then
team_color = team
end
i = i + 1
end
local meta = minetest.get_meta(pos)
meta:set_string("team", team_color)
end
})
26 changes: 26 additions & 0 deletions mods/ctf/ctf_modes/ctf_mode_flagwars/spawners.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local function register_spawner(tiles, item, node_suffix, interval)
local spawn = false
minetest.register_node("ctf_mode_flagwars:spawner_"..node_suffix, {
tiles = tiles,
overlay_tiles = { name = "ctf_mode_flagwars_spawner_overlay.png" },
walkable = true,
pointable = true,
diggable = false,
on_construct = function(pos)
local function spawnfn()
pos.y = pos.y + 1
minetest.add_item(pos, item)
if spawn then
minetest.after(interval, spawnfn)
end
end
spawn = true
spawnfn()
end,
on_destruct = function(pos)
spawn = false
end,
})
end

register_spawner({ name = "default_gold_block.png" }, "default:ingot_gold", "gold", 1)