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

Make stealing from enemy teamchest(s) possible while they are open #1071

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions mods/ctf/ctf_modebase/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,6 @@ function ctf_modebase.match_mode(param)
return opt_param, mode_param
end


--- end
--
Empty file.
33 changes: 30 additions & 3 deletions mods/ctf/ctf_modes/ctf_mode_classic/init.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modes/ctf_mode_classic/mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = ctf_mode_classic
depends = ctf_modebase
depends = ctf_modebase, ctf_teams
1 change: 1 addition & 0 deletions mods/ctf/ctf_teams/README.md
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions mods/ctf/ctf_teams/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file not shown.
31 changes: 27 additions & 4 deletions mods/ctf/ctf_teams/team_chest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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