From 13bd6fb832b600771dc083af4c531d848b892c72 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 13 Oct 2017 00:57:09 +0100 Subject: [PATCH] Fix some bugs in created in ctf_stats rewrite --- mods/ctf_stats/README.md | 14 -------------- mods/ctf_stats/init.lua | 36 +++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 21 deletions(-) delete mode 100644 mods/ctf_stats/README.md diff --git a/mods/ctf_stats/README.md b/mods/ctf_stats/README.md deleted file mode 100644 index c51d254..0000000 --- a/mods/ctf_stats/README.md +++ /dev/null @@ -1,14 +0,0 @@ -## Score - -* +5 for picking up a flag. -* +20 for then capturing the flag. -* +X for killing someone, where X is: - * +5 for every kill they've made since last death in this match. - * `15 * kd` ratio, with variable cap based on player's score: - * capped at X * 10 for < X * 100 player score - (eg 10 for 100, 20 for 200, 40 for 400+). - * capped to 40. - * deaths > kills gives 0 score - * Limited to 0 ≤ X ≤ 100 - * If they don't have a good weapon: half given score. - A good weapon is a non-default one which is not a pistol, stone sword, or crossbow. diff --git a/mods/ctf_stats/init.lua b/mods/ctf_stats/init.lua index 22eb450..52e1881 100644 --- a/mods/ctf_stats/init.lua +++ b/mods/ctf_stats/init.lua @@ -31,6 +31,26 @@ function ctf_stats.load() for _, key in pairs(data_to_persist) do ctf_stats[key] = minetest.parse_json(storage:get_string(key)) end + + ctf_stats.matches.wins = ctf_stats.matches.wins or { + red = ctf_stats.matches.red_wins or 0, + blue = ctf_stats.matches.blue_wins or 0, + } + + for name, player_stats in pairs(ctf_stats.players) do + player_stats.wins = player_stats.wins or {} + if player_stats.blue_wins then + player_stats.wins.blue = player_stats.blue_wins + player_stats.blue_wins = nil + end + if player_stats.red_wins then + player_stats.wins.red = player_stats.red_wins + player_stats.red_wins = nil + end + player_stats.wins.blue = player_stats.wins.blue or 0 + player_stats.wins.red = player_stats.wins.red or 0 + end + ctf.needs_save = true end ctf_stats.matches = ctf_stats.matches or { @@ -102,9 +122,9 @@ ctf_flag.register_on_capture(function(name, flag) local main, match = ctf_stats.player(name) if main and match then main.captures = main.captures + 1 - main.score = main.score + 20 + main.score = main.score + 25 match.captures = match.captures + 1 - match.score = match.score + 20 + match.score = match.score + 25 ctf.needs_save = true end end) @@ -134,7 +154,7 @@ ctf_flag.register_on_pick_up(function(name, flag) main.attempts = main.attempts + 1 main.score = main.score + 5 match.attempts = match.attempts + 1 - match.score = match.score + 5 + match.score = match.score + 10 ctf.needs_save = true end end) @@ -170,10 +190,11 @@ local function calculateKillReward(victim, killer) -- +5 for every kill they've made since last death in this match. local reward = victim_match.kills_since_death * 5 - ctf.log("ctf_stats", "Player " .. victim .. " has made " .. reward .. " kills since last death") + ctf.log("ctf_stats", "Player " .. victim .. " has made " .. reward .. + " score worth of kills since last death") -- 15 * kd ration, with variable based on player's score - local kdreward = 15 * vmain.kills / (vmain.deaths + 1) + local kdreward = 20 * vmain.kills / (vmain.deaths + 1) local max = vmain.score / 10 if kdreward > max then kdreward = max @@ -181,12 +202,13 @@ local function calculateKillReward(victim, killer) if kdreward > 40 then kdreward = 40 end + reward = reward + kdreward -- Limited to 0 <= X <= 100 if reward > 100 then reward = 100 - elseif reward < 0 then - reward = 0 + elseif reward < 10 then + reward = 10 end -- Half if no good weapons