diff --git a/.gitmodules b/.gitmodules index 85a808c165..07eb162f5a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "mods/ctf/ctf_map/maps"] path = mods/ctf/ctf_map/maps - url = https://github.com/MT-CTF/maps.git + url = https://github.com/MT-CTF/maps [submodule "mods/other/lib_chatcmdbuilder"] path = mods/other/lib_chatcmdbuilder url = https://github.com/rubenwardy/ChatCmdBuilder.git @@ -15,3 +15,5 @@ path = mods/apis/mhud url = https://github.com/LoneWolfHT/mhud.git branch = main +[submodule "maps~up_master"] + url = https://github.com/MT-CTF/maps diff --git a/mods/ctf/ctf_map/maps b/mods/ctf/ctf_map/maps index e9edb40ace..b76a07779a 160000 --- a/mods/ctf/ctf_map/maps +++ b/mods/ctf/ctf_map/maps @@ -1 +1 @@ -Subproject commit e9edb40acea702cccbe806c09249c776e49af0f8 +Subproject commit b76a07779afffd349c8dd01afa805e8e7a6483f8 diff --git a/mods/ctf/ctf_modebase/register.lua b/mods/ctf/ctf_modebase/register.lua index e346adaaeb..4121ec537f 100644 --- a/mods/ctf/ctf_modebase/register.lua +++ b/mods/ctf/ctf_modebase/register.lua @@ -185,5 +185,6 @@ function ctf_modebase.match_mode(param) return opt_param, mode_param end + --- end -- diff --git a/mods/ctf/ctf_modes/ctf_mode_classic/README.md b/mods/ctf/ctf_modes/ctf_mode_classic/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mods/ctf/ctf_modes/ctf_mode_classic/init.lua b/mods/ctf/ctf_modes/ctf_mode_classic/init.lua index 419eeda6a3..12d7cfd874 100644 --- a/mods/ctf/ctf_modes/ctf_mode_classic/init.lua +++ b/mods/ctf/ctf_modes/ctf_mode_classic/init.lua @@ -1,6 +1,13 @@ +ctf_mode_classic = {} + + local rankings = ctf_rankings.init() local recent_rankings = ctf_modebase.recent_rankings(rankings) local features = ctf_modebase.features(rankings, recent_rankings) +local teamchest_open = false +local number_of_openers = 0 +local job = nil + local old_bounty_reward_func = ctf_modebase.bounties.bounty_reward_func local old_get_next_bounty = ctf_modebase.bounties.get_next_bounty @@ -58,11 +65,21 @@ ctf_modebase.register_mode("classic", { ctf_modebase.bounties.get_next_bounty = old_get_next_bounty end, on_new_match = features.on_new_match, - on_match_end = features.on_match_end, + on_match_end = function() + openers = {} + teamchest_open = false + features.on_match_end() + end, team_allocator = features.team_allocator, on_allocplayer = features.on_allocplayer, - on_leaveplayer = features.on_leaveplayer, - on_dieplayer = features.on_dieplayer, + on_leaveplayer = function(player) + openers[player:get_player_name()] = nil + features.on_leaveplayer(player) + end, + on_dieplayer = function(player, reason) + openers[player:get_player_name()] = nil + features.on_dieplayer(player, reason) + end, on_respawnplayer = features.on_respawnplayer, can_take_flag = features.can_take_flag, on_flag_take = features.on_flag_take, @@ -77,3 +94,13 @@ ctf_modebase.register_mode("classic", { return 0 end, }) + + +ctf_teams.can_access_chest = function(team, player) + local number_of_openers = 0 + for _, __ in pairs(ctf_teams.team_chests[team]) do + number_of_openers = number_of_openers + 1 + end + minetest.chat_send_all(tostring(number_of_openers)) + return number_of_openers > 0 +end diff --git a/mods/ctf/ctf_modes/ctf_mode_classic/mod.conf b/mods/ctf/ctf_modes/ctf_mode_classic/mod.conf index c853921880..cbb97dd869 100644 --- a/mods/ctf/ctf_modes/ctf_mode_classic/mod.conf +++ b/mods/ctf/ctf_modes/ctf_mode_classic/mod.conf @@ -1,2 +1,2 @@ name = ctf_mode_classic -depends = ctf_modebase +depends = ctf_modebase, ctf_teams diff --git a/mods/ctf/ctf_teams/README.md b/mods/ctf/ctf_teams/README.md new file mode 100644 index 0000000000..66c9a980ce --- /dev/null +++ b/mods/ctf/ctf_teams/README.md @@ -0,0 +1 @@ + - the stealing sound is from https://soundbible.com/1540-Computer-Error-Alert.html under CC BY 3.0 with some modifications(converted to ogg and mono) diff --git a/mods/ctf/ctf_teams/functions.lua b/mods/ctf/ctf_teams/functions.lua index c9638c98e7..a72464f406 100644 --- a/mods/ctf/ctf_teams/functions.lua +++ b/mods/ctf/ctf_teams/functions.lua @@ -128,3 +128,13 @@ function ctf_teams.chat_send_team(teamname, message) minetest.chat_send_player(player, message) end end + + +---@praram player string The player who tries to access teamchest +---@param teamchest string The team of teamchest +---@returns bool True if the player can access teamchest +--- e.g. if the player is a teammate or +--- if the chest is open in classic +function ctf_teams.can_access_chest(teamchest, player) + return ctf_teams.get(player) == teamchest +end diff --git a/mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg b/mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg new file mode 100644 index 0000000000..c1f33ad438 Binary files /dev/null and b/mods/ctf/ctf_teams/sounds/ctf_teams_teamchest_steal.ogg differ diff --git a/mods/ctf/ctf_teams/team_chest.lua b/mods/ctf/ctf_teams/team_chest.lua index 5b273c3a6d..5d52b0a646 100644 --- a/mods/ctf/ctf_teams/team_chest.lua +++ b/mods/ctf/ctf_teams/team_chest.lua @@ -3,6 +3,14 @@ local blacklist = { ".*leaves$", } +ctf_teams.team_chests = {} + +for team, _ in pairs(ctf_teams.team) do + ctf_teams.team_chests[team] = { + openers = {}, + } +end + local function get_chest_access(name) local current_mode = ctf_modebase:get_current_mode() if not current_mode then return false, false end @@ -73,7 +81,9 @@ for _, team in ipairs(ctf_teams.teamlist) do local name = player:get_player_name() local flag_captured = ctf_modebase.flag_captured[team] - if not flag_captured and team ~= ctf_teams.get(name) then + + minetest.chat_send_all(minetest.serialize(ctf_teams.teamchests)) + if not flag_captured and not ctf_teams.can_access_chest(team, name) then hud_events.new(player, { quick = true, text = "You're not on team " .. team, @@ -131,7 +141,15 @@ for _, team in ipairs(ctf_teams.teamlist) do formspec = formspec .. "listring[" .. chestinv ..";main]" .. "listring[current_player;main]" - + if team == ctf_teams.get(name) then + minetest.after(5, function() + for opener_name, open_time in pairs(ctf_teams.team_chests[team].openers) do + if (minetest.get_gametime() - open_time) >= 5 then + ctf_teams.team_chests[team].openers[opener_name] = nil + end + end + end) + end minetest.show_formspec(name, "ctf_teams:chest", formspec) end @@ -220,7 +238,7 @@ for _, team in ipairs(ctf_teams.teamlist) do local name = player:get_player_name() - if team ~= ctf_teams.get(name) then + if not ctf_teams.can_access_chest(team, name) then hud_events.new(player, { quick = true, text = "You're not on team " .. team, @@ -252,7 +270,12 @@ for _, team in ipairs(ctf_teams.teamlist) do stack:to_string(), minetest.pos_to_string(pos) )) + if ctf_teams.get(player:get_player_name()) ~= team then + minetest.sound_play({ + pos = pos, + name = "ctf_teams_teamchest_steal", + }) + end end - minetest.register_node("ctf_teams:chest_" .. team, def) end