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

Redo hpbars, add ranking resets and leagues #1198

Merged
merged 6 commits into from
Aug 12, 2023
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ debug.txt
/mods/ctf/ctf_map/textures/*Back.*
/mods/ctf/ctf_map/textures/*Left.*
/mods/ctf/ctf_map/textures/*Right.*
/mods/ctf/ctf_map/textures/*_screenshot.png
/mods/ctf/ctf_map/textures/*_screenshot.png

*.blend1
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ return {
player:hud_set_hotbar_image("gui_hotbar.png^[colorize:" .. tcolor .. ":128")
player:hud_set_hotbar_selected_image("gui_hotbar_selected.png^[multiply:" .. tcolor)

player:set_properties({textures = {ctf_cosmetics.get_skin(player)}})
player_api.set_texture(player, 1, ctf_cosmetics.get_skin(player))

recent_rankings.set_team(player, new_team)

Expand Down
4 changes: 2 additions & 2 deletions mods/ctf/ctf_modebase/flags/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ minetest.register_node("ctf_modebase:flag", {
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
light_source = 5,
light_source = 6,
tiles = {
"default_wood.png",
"default_wood.png",
Expand Down Expand Up @@ -65,7 +65,7 @@ for name, def in pairs(ctf_teams.team) do
paramtype2 = "facedir",
walkable = false,
buildable_to = false,
light_source = 5,
light_source = 6,
tiles = {
"default_wood.png",
"default_wood.png",
Expand Down
12 changes: 12 additions & 0 deletions mods/ctf/ctf_modebase/flags/taking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ local function drop_flags(player, pteam)
end
end

player_api.set_texture(player, 2, "blank.png")

ctf_modebase.taken_flags[pname] = nil

ctf_modebase.skip_vote.on_flag_drop(#flagteams)
Expand Down Expand Up @@ -74,6 +76,10 @@ function ctf_modebase.flag_on_punch(puncher, nodepos, node)
table.insert(ctf_modebase.taken_flags[pname], target_team)
ctf_modebase.flag_taken[target_team] = {p=pname, t=pteam}

player_api.set_texture(puncher, 2,
"default_wood.png^([combine:16x16:4,0=wool_white.png^[colorize:"..ctf_teams.team[target_team].color..":200)"
)

ctf_modebase.skip_vote.on_flag_take()
ctf_modebase:get_current_mode().on_flag_take(puncher, target_team)

Expand All @@ -96,6 +102,8 @@ function ctf_modebase.flag_on_punch(puncher, nodepos, node)
ctf_modebase.flag_captured[flagteam] = true
end

player_api.set_texture(puncher, 2, "blank.png")

ctf_modebase.on_flag_capture(puncher, flagteams)

ctf_modebase.skip_vote.on_flag_capture(#flagteams)
Expand All @@ -105,6 +113,10 @@ function ctf_modebase.flag_on_punch(puncher, nodepos, node)
end

ctf_api.register_on_match_end(function()
for pname in pairs(ctf_modebase.taken_flags) do
player_api.set_texture(minetest.get_player_by_name(pname), 2, "blank.png")
end

ctf_modebase.taken_flags = {}
ctf_modebase.flag_taken = {}
ctf_modebase.flag_captured = {}
Expand Down
9 changes: 6 additions & 3 deletions mods/ctf/ctf_modebase/immunity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function ctf_modebase.give_immunity(player, respawn_timer)
})

if old == nil then
player:set_properties({pointable = false, textures = {ctf_cosmetics.get_skin(player)}})
player_api.set_texture(player, 1, ctf_cosmetics.get_skin(player))
player:set_properties({pointable = false})
player:set_armor_groups({fleshy = 0})
end
end
Expand All @@ -85,7 +86,8 @@ function ctf_modebase.remove_immunity(player)

immune_players[pname] = nil

player:set_properties({pointable = true, textures = {ctf_cosmetics.get_skin(player)}})
player_api.set_texture(player, 1, ctf_cosmetics.get_skin(player))
player:set_properties({pointable = true})
player:set_armor_groups({fleshy = 100})
end

Expand All @@ -103,7 +105,8 @@ function ctf_modebase.remove_respawn_immunity(player)

minetest.delete_particlespawner(old.particles, pname)

player:set_properties({pointable = true, textures = {ctf_cosmetics.get_skin(player)}})
player_api.set_texture(player, 1, ctf_cosmetics.get_skin(player))
player:set_properties({pointable = true})
player:set_armor_groups({fleshy = 100})

return true
Expand Down
29 changes: 27 additions & 2 deletions mods/ctf/ctf_modebase/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,33 @@ ctf_core.include_files(

minetest.register_on_mods_loaded(function()
table.sort(ctf_modebase.modelist)
if ctf_core.settings.server_mode == "play" then
minetest.after(1, ctf_modebase.start_new_match)

if ctf_rankings.do_reset then
minetest.register_on_joinplayer(function(player)
skybox.clear(player)

player:set_moon({
visible = false
})
player:set_sun({
visible = false
})
player:set_clouds({
density = 0
})

player:hud_set_flags({
crosshair = false,
wielditem = false,
})

player:override_day_night_ratio(0)

player:set_hp(20)
player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}, text = ""})
end)
elseif ctf_core.settings.server_mode == "play" then
minetest.after(0.2, ctf_modebase.start_new_match)
end

for _, name in pairs(ctf_modebase.modelist) do
Expand Down
13 changes: 9 additions & 4 deletions mods/ctf/ctf_modebase/match.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
--- @type false | string
local restart_on_next_match = false

ctf_modebase.map_on_next_match = nil
ctf_modebase.mode_on_next_match = nil

Expand Down Expand Up @@ -41,14 +43,17 @@ local function start_new_match()
local path = minetest.get_worldpath() .. "/queue_restart.txt"
if ctf_core.file_exists(path) then
os.remove(path)
restart_on_next_match = true
restart_on_next_match = ""
end

ctf_modebase.in_game = false
ctf_modebase.on_match_end()

if restart_on_next_match then
minetest.chat_send_all(minetest.colorize("red", "[NOTICE] Server restarting in 5 seconds..."))
minetest.chat_send_all(minetest.colorize("red",
"[NOTICE] Server restarting in 5 seconds"..restart_on_next_match.."..."
))

minetest.request_shutdown(
"Restarting server at imperator request.\n\nTip: Count to 15 before clicking reconnect",
true, 5
Expand Down Expand Up @@ -149,9 +154,9 @@ minetest.register_chatcommand("queue_restart", {
description = "Queue server restart",
privs = {server = true},
func = function(name, param)
if not param then param = "" end
if not param or param == "" then param = false end

restart_on_next_match = true
restart_on_next_match = param and (" ("..param..")") or ""
minetest.log("action", string.format("[ctf_admin] %s queued a restart", name))
minetest.chat_send_all(minetest.colorize("red", "[NOTICE] Server will restart after this match is over. " .. param))
return true, "Restart is queued."
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modebase/mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = ctf_modebase
depends = ctf_api, ctf_core, ctf_teams, ctf_gui, ctf_map, ctf_healing, crafting, mhud, default, binoculars
depends = ctf_api, ctf_core, ctf_teams, ctf_gui, ctf_map, ctf_healing, crafting, mhud, default, binoculars, ctf_player
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modes/ctf_mode_classes/classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function classes.set(player, classname)
ctf_modebase.player.remove_bound_items(player)
ctf_modebase.player.give_initial_stuff(player)

player:set_properties({textures = {ctf_cosmetics.get_skin(player)}})
player_api.set_texture(player, 1, ctf_cosmetics.get_skin(player))

classes.update(player)

Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modes/ctf_mode_classes/mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = ctf_mode_classes
depends = ctf_modebase, ctf_melee, ctf_gui, ctf_cosmetics, ctf_api, hud_events, ctf_settings
depends = ctf_modebase, ctf_melee, ctf_gui, ctf_cosmetics, ctf_api, hud_events, ctf_settings, ctf_player
3 changes: 2 additions & 1 deletion mods/ctf/ctf_player/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ player_api.registered_models["character.b3d"] = nil

player_api.register_model("character.b3d", {
animation_speed = 30,
textures = {"character.png"},
--textures={"character.png", "flagtexture",},
textures = {"character.png", "blank.png" ,},
animations = {
-- Standard animations.
stand = {x = 0, y = 79},
Expand Down
Binary file modified mods/ctf/ctf_player/models/character.b3d
Binary file not shown.
Binary file modified mods/ctf/ctf_player/models/character.blend
Binary file not shown.
31 changes: 25 additions & 6 deletions mods/ctf/ctf_rankings/default.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
return function(top)
return function(prefix, top)

local modstorage = assert(minetest.get_mod_storage(), "Can only init rankings at runtime!")

for k, v in pairs(modstorage:to_table()["fields"]) do
local rank = minetest.parse_json(v)
if rank ~= nil and rank.score then
top:set(k, rank.score)
local function op_all(operation)
for k, v in pairs(modstorage:to_table()["fields"]) do
operation(k, v)
end
end

local timer = minetest.get_us_time()
op_all(function(key, value)
local rank = minetest.parse_json(value)

if rank ~= nil and rank.score then
top:set(key, rank.score)
end
end)
minetest.log("action", "Sorted rankings database. Took "..((minetest.get_us_time()-timer) / 1e6))

return {
backend = "default",
top = top,
modstorage = modstorage,

prefix = "",

op_all = op_all,

get = function(self, pname)
pname = PlayerName(pname)

Expand Down Expand Up @@ -53,7 +66,13 @@ return {

self.top:set(pname, newrankings.score or 0)
self.modstorage:set_string(pname, minetest.write_json(newrankings))
end
end,
del = function(self, pname)
pname = PlayerName(pname)

self.top:set(pname, 0)
self.modstorage:set_string(pname)
end,
}

end
50 changes: 49 additions & 1 deletion mods/ctf/ctf_rankings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,54 @@ end

ctf_rankings = {
init = function()
return rankings(top:new())
return rankings(minetest.get_current_modname() .. '|', top:new())
end,

registered_on_rank_reset = {},

do_reset = false, -- See ranking_reset.lua
current_reset = 0, -- See ranking_reset.lua

leagues = {
diamond = 20,
mese = 50,
gold = 250,
bronze = 500,
steel = 1000,
stone = 2500,
wood = 5000,
none = math.huge
},
leagues_list = {
"diamond", "mese", "gold", "bronze", "steel", "stone", "wood", "none",
},
league_textures = {
diamond = "ctf_rankings_league_diamond.png",
mese = "ctf_rankings_league_mese.png",
gold = "ctf_rankings_league_gold.png",
bronze = "ctf_rankings_league_bronze.png",
steel = "ctf_rankings_league_steel.png",
stone = "ctf_rankings_league_stone.png",
wood = "ctf_rankings_league_wood.png",
none = "blank.png",
},

-- Used for cycling through all ranks ingame
-- Remember to remove spaces if running with Worldedit's //lua
--[[
for i, n in pairs(ctf_rankings.leagues_list) do
minetest.after(i, function()
hpbar.set_icon("LandarVargan", ctf_rankings.league_textures[n])
end)
end
--]]
}

---@param func function
--- * pname
--- * rank
function ctf_rankings.register_on_rank_reset(func)
table.insert(ctf_rankings.registered_on_rank_reset, func)
end

ctf_core.include_files("leagues.lua", "ranking_reset.lua")
Loading