Fix some bugs in created in ctf_stats rewrite

This commit is contained in:
rubenwardy 2017-10-13 00:57:09 +01:00
parent fb8195b5dd
commit 13bd6fb832
2 changed files with 29 additions and 21 deletions

View file

@ -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.

View file

@ -31,6 +31,26 @@ function ctf_stats.load()
for _, key in pairs(data_to_persist) do for _, key in pairs(data_to_persist) do
ctf_stats[key] = minetest.parse_json(storage:get_string(key)) ctf_stats[key] = minetest.parse_json(storage:get_string(key))
end 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 end
ctf_stats.matches = ctf_stats.matches or { 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) local main, match = ctf_stats.player(name)
if main and match then if main and match then
main.captures = main.captures + 1 main.captures = main.captures + 1
main.score = main.score + 20 main.score = main.score + 25
match.captures = match.captures + 1 match.captures = match.captures + 1
match.score = match.score + 20 match.score = match.score + 25
ctf.needs_save = true ctf.needs_save = true
end end
end) end)
@ -134,7 +154,7 @@ ctf_flag.register_on_pick_up(function(name, flag)
main.attempts = main.attempts + 1 main.attempts = main.attempts + 1
main.score = main.score + 5 main.score = main.score + 5
match.attempts = match.attempts + 1 match.attempts = match.attempts + 1
match.score = match.score + 5 match.score = match.score + 10
ctf.needs_save = true ctf.needs_save = true
end end
end) end)
@ -170,10 +190,11 @@ local function calculateKillReward(victim, killer)
-- +5 for every kill they've made since last death in this match. -- +5 for every kill they've made since last death in this match.
local reward = victim_match.kills_since_death * 5 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 -- 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 local max = vmain.score / 10
if kdreward > max then if kdreward > max then
kdreward = max kdreward = max
@ -181,12 +202,13 @@ local function calculateKillReward(victim, killer)
if kdreward > 40 then if kdreward > 40 then
kdreward = 40 kdreward = 40
end end
reward = reward + kdreward
-- Limited to 0 <= X <= 100 -- Limited to 0 <= X <= 100
if reward > 100 then if reward > 100 then
reward = 100 reward = 100
elseif reward < 0 then elseif reward < 10 then
reward = 0 reward = 10
end end
-- Half if no good weapons -- Half if no good weapons