mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-10 10:00:00 +02:00
Cleanup of player stats functions
This commit is contained in:
parent
dc78d297b6
commit
8a84ef7504
@ -9,11 +9,20 @@ local Report = require 'features.report'
|
||||
local table = require 'utils.table'
|
||||
local Color = require 'resources.color_presets'
|
||||
local Settings = require 'utils.redmew_settings'
|
||||
|
||||
local poke_messages = require 'resources.poke_messages'
|
||||
local player_sprites = require 'resources.player_sprites'
|
||||
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local get_for_global = ScoreTracker.get_for_global
|
||||
local get_for_player = ScoreTracker.get_for_player
|
||||
local player_count_name = 'player-count'
|
||||
local coins_spent_name = 'coins-spent'
|
||||
local coins_earned_name = 'coins-earned'
|
||||
local player_deaths_name = 'player-deaths'
|
||||
local player_distance_walked_name = 'player-distance-walked'
|
||||
local random = math.random
|
||||
local ipairs = ipairs
|
||||
local abs = math.abs
|
||||
local round = math.round
|
||||
local get_rank_color = Rank.get_rank_color
|
||||
local get_rank_name = Rank.get_rank_name
|
||||
local get_player_rank = Rank.get_player_rank
|
||||
@ -86,7 +95,7 @@ local function lighten_color(color)
|
||||
end
|
||||
|
||||
local function format_distance(tiles)
|
||||
return math.round(tiles * 0.001, 1) .. ' km'
|
||||
return round(tiles * 0.001, 1) .. ' km'
|
||||
end
|
||||
|
||||
local function do_poke_spam_protection(player)
|
||||
@ -259,7 +268,7 @@ local column_builders = {
|
||||
},
|
||||
[distance_heading_name] = {
|
||||
create_data = function(player)
|
||||
return PlayerStats.get_walk_distance(player.index)
|
||||
return get_for_player(player.index, player_distance_walked_name)
|
||||
end,
|
||||
sort = function(a, b)
|
||||
return a < b
|
||||
@ -288,8 +297,8 @@ local column_builders = {
|
||||
create_data = function(player)
|
||||
local index = player.index
|
||||
return {
|
||||
coin_earned = PlayerStats.get_coin_earned(index),
|
||||
coin_spent = PlayerStats.get_coin_spent(index)
|
||||
coin_earned = get_for_player(index, coins_earned_name),
|
||||
coin_spent = get_for_player(index, coins_spent_name)
|
||||
}
|
||||
end,
|
||||
sort = function(a, b)
|
||||
@ -330,7 +339,7 @@ local column_builders = {
|
||||
create_data = function(player)
|
||||
local player_index = player.index
|
||||
return {
|
||||
count = PlayerStats.get_death_count(player_index),
|
||||
count = get_for_player(player_index, player_deaths_name),
|
||||
causes = PlayerStats.get_all_death_causes_by_player(player_index)
|
||||
}
|
||||
end,
|
||||
@ -486,7 +495,7 @@ local function redraw_title(data)
|
||||
local frame = data.frame
|
||||
|
||||
local online_count = #game.connected_players
|
||||
local total_count = PlayerStats.get_total_player_count()
|
||||
local total_count = get_for_global(player_count_name)
|
||||
|
||||
frame.caption = {'player_list.title', online_count, total_count}
|
||||
end
|
||||
@ -495,7 +504,7 @@ local function redraw_headings(data)
|
||||
local settings = data.settings
|
||||
local columns = settings.columns
|
||||
local sort = settings.sort
|
||||
local sort_column = math.abs(sort)
|
||||
local sort_column = abs(sort)
|
||||
|
||||
local heading_table_flow = data.heading_table_flow
|
||||
Gui.clear(heading_table_flow)
|
||||
@ -519,7 +528,7 @@ local function redraw_cells(data)
|
||||
local settings = data.settings
|
||||
local columns = settings.columns
|
||||
local sort = settings.sort
|
||||
local sort_column = math.abs(sort)
|
||||
local sort_column = abs(sort)
|
||||
local column_name = columns[sort_column]
|
||||
local column_sort = column_builders[column_name].sort
|
||||
|
||||
@ -703,7 +712,7 @@ local function headings_click(event)
|
||||
local index = heading_data.index
|
||||
|
||||
local sort = settings.sort
|
||||
local sort_column = math.abs(sort)
|
||||
local sort_column = abs(sort)
|
||||
|
||||
if sort_column == index then
|
||||
sort = -sort
|
||||
@ -756,7 +765,7 @@ Gui.on_click(
|
||||
local columns = settings.columns
|
||||
local sort = settings.sort
|
||||
|
||||
local sorted_column = columns[math.abs(sort)]
|
||||
local sorted_column = columns[abs(sort)]
|
||||
if sorted_column == poke_name_heading_name then
|
||||
redraw_cells(frame_data)
|
||||
else
|
||||
|
@ -2,7 +2,6 @@
|
||||
local Event = require 'utils.event'
|
||||
local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local PlayerStats = require 'features.player_stats'
|
||||
local Command = require 'utils.command'
|
||||
local Global = require 'utils.global'
|
||||
local Retailer = require 'features.retailer'
|
||||
@ -10,6 +9,10 @@ local Ranks = require 'resources.ranks'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local market_items = require 'resources.market_items'
|
||||
local fish_market_bonus_message = require 'resources.fish_messages'
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local change_for_player = ScoreTracker.change_for_player
|
||||
local get_for_player = ScoreTracker.get_for_player
|
||||
local coins_earned_name = 'coins-earned'
|
||||
|
||||
-- localized functions
|
||||
local pairs = pairs
|
||||
@ -127,9 +130,8 @@ local function fish_earned(event, amount)
|
||||
player.surface.spill_item_stack(player.position, stack, true)
|
||||
end
|
||||
|
||||
PlayerStats.change_coin_earned(player_index, amount)
|
||||
|
||||
if PlayerStats.get_coin_earned(player_index) % 70 == 0 and player and player.valid then
|
||||
change_for_player(player_index, coins_earned_name, amount)
|
||||
if get_for_player(player_index, coins_earned_name) % 70 == 0 and player and player.valid then
|
||||
local message = fish_market_bonus_message[random(#fish_market_bonus_message)]
|
||||
player.print(message)
|
||||
end
|
||||
|
@ -5,9 +5,7 @@ require 'utils.table'
|
||||
local pairs = pairs
|
||||
local sqrt = math.sqrt
|
||||
local change_for_global = ScoreTracker.change_for_global
|
||||
local get_for_global = ScoreTracker.get_for_global
|
||||
local change_for_player = ScoreTracker.change_for_player
|
||||
local get_for_player = ScoreTracker.get_for_player
|
||||
|
||||
local rocks_smashed_name = 'rocks-smashed'
|
||||
local trees_cut_down_name = 'trees-cut'
|
||||
@ -190,74 +188,9 @@ Event.on_nth_tick(62, tick)
|
||||
|
||||
local Public = {}
|
||||
|
||||
function Public.get_walk_distance(player_index)
|
||||
return get_for_player(player_index, player_distance_walked_name)
|
||||
end
|
||||
|
||||
function Public.get_coin_earned(player_index)
|
||||
return get_for_player(player_index, coins_earned_name)
|
||||
end
|
||||
|
||||
function Public.change_coin_earned(player_index, amount)
|
||||
change_for_player(player_index, coins_earned_name, amount)
|
||||
end
|
||||
|
||||
function Public.get_coin_spent(player_index)
|
||||
return get_for_player(player_index, coins_spent_name)
|
||||
end
|
||||
|
||||
function Public.change_coin_spent(player_index, amount)
|
||||
change_for_player(player_index, coins_spent_name, amount)
|
||||
change_for_global(coins_spent_name, amount)
|
||||
end
|
||||
|
||||
function Public.get_death_count(player_index)
|
||||
return get_for_player(player_index, player_deaths_name)
|
||||
end
|
||||
|
||||
function Public.get_crafted_item(player_index)
|
||||
return get_for_player(player_index, player_items_crafted_name)
|
||||
end
|
||||
|
||||
function Public.get_console_chat(player_index)
|
||||
return get_for_player(player_index, player_console_chats_name)
|
||||
end
|
||||
|
||||
-- Returns a dictionary of cause_name -> count
|
||||
function Public.get_all_death_causes_by_player(player_index)
|
||||
return player_death_causes[player_index] or {}
|
||||
end
|
||||
|
||||
function Public.get_total_player_count()
|
||||
return get_for_global(player_count_name)
|
||||
end
|
||||
|
||||
function Public.get_total_train_kills()
|
||||
return get_for_global(kills_by_trains_name)
|
||||
end
|
||||
|
||||
function Public.get_total_player_trees_mined()
|
||||
return get_for_global(trees_cut_down_name)
|
||||
end
|
||||
|
||||
function Public.get_total_player_rocks_mined()
|
||||
return get_for_global(rocks_smashed_name)
|
||||
end
|
||||
|
||||
function Public.get_total_robot_built_entities()
|
||||
return get_for_global(built_by_robots_name)
|
||||
end
|
||||
|
||||
function Public.get_total_player_built_entities()
|
||||
return get_for_global(built_by_players_name)
|
||||
end
|
||||
|
||||
function Public.get_total_biter_kills()
|
||||
return get_for_global(aliens_killed_name)
|
||||
end
|
||||
|
||||
function Public.get_total_coins_spent()
|
||||
return get_for_global(coins_spent_name)
|
||||
end
|
||||
|
||||
return Public
|
||||
|
@ -3,15 +3,22 @@ local Timestamp = require 'utils.timestamp'
|
||||
local Command = require 'utils.command'
|
||||
local Utils = require 'utils.core'
|
||||
local Server = require 'features.server'
|
||||
local PlayerStats = require 'features.player_stats'
|
||||
local Rank = require 'features.rank_system'
|
||||
local Donator = require 'features.donator'
|
||||
local Color = require 'resources.color_presets'
|
||||
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local get_for_player = ScoreTracker.get_for_player
|
||||
local coins_spent_name = 'coins-spent'
|
||||
local coins_earned_name = 'coins-earned'
|
||||
local player_deaths_name = 'player-deaths'
|
||||
local player_console_chats_name = 'player-console-chats'
|
||||
local player_items_crafted_name = 'player-items-crafted'
|
||||
local player_distance_walked_name = 'player-distance-walked'
|
||||
local concat = table.concat
|
||||
local tostring = tostring
|
||||
local tonumber = tonumber
|
||||
local pairs = pairs
|
||||
local floor = math.floor
|
||||
|
||||
--- Informs the actor that there is no target. Acts as a central place where this message can be changed.
|
||||
local function print_no_target(target_name)
|
||||
@ -70,16 +77,17 @@ end
|
||||
local function afk()
|
||||
local count = 0
|
||||
for _, v in pairs(game.players) do
|
||||
if v.afk_time > 300 then
|
||||
local afk_time = v.afk_time
|
||||
if afk_time > 300 then
|
||||
count = count + 1
|
||||
local time = ' '
|
||||
if v.afk_time > 21600 then
|
||||
time = time .. math.floor(v.afk_time / 216000) .. ' hours '
|
||||
if afk_time > 21600 then
|
||||
time = time .. floor(afk_time / 216000) .. ' hours '
|
||||
end
|
||||
if v.afk_time > 3600 then
|
||||
time = time .. math.floor(v.afk_time / 3600) % 60 .. ' minutes and '
|
||||
if afk_time > 3600 then
|
||||
time = time .. floor(afk_time / 3600) % 60 .. ' minutes and '
|
||||
end
|
||||
time = time .. math.floor(v.afk_time / 60) % 60 .. ' seconds.'
|
||||
time = time .. floor(v.afk_time / 60) % 60 .. ' seconds.'
|
||||
Game.player_print(v.name .. ' has been afk for' .. time)
|
||||
end
|
||||
end
|
||||
@ -193,12 +201,12 @@ local function print_player_info(args, player)
|
||||
{'format.1_colon_2', 'Force', target.force.name},
|
||||
{'format.1_colon_2', 'Surface', target.surface.name},
|
||||
{'format.1_colon_2', 'Tag', target.tag},
|
||||
{'format.1_colon_2', 'Distance walked', PlayerStats.get_walk_distance(index)},
|
||||
{'format.1_colon_2', 'Coin earned', PlayerStats.get_coin_earned(index)},
|
||||
{'format.1_colon_2', 'Coin spent', PlayerStats.get_coin_spent(index)},
|
||||
{'format.1_colon_2', 'Deaths', PlayerStats.get_death_count(index)},
|
||||
{'format.1_colon_2', 'Crafted items', PlayerStats.get_crafted_item(index)},
|
||||
{'format.1_colon_2', 'Chat messages', PlayerStats.get_console_chat(index)}
|
||||
{'format.1_colon_2', 'Distance walked', get_for_player(index, player_distance_walked_name)},
|
||||
{'format.1_colon_2', 'Coin earned', get_for_player(index, coins_earned_name)},
|
||||
{'format.1_colon_2', 'Coin spent', get_for_player(index, coins_spent_name)},
|
||||
{'format.1_colon_2', 'Deaths', get_for_player(index, player_deaths_name)},
|
||||
{'format.1_colon_2', 'Crafted items', get_for_player(index, player_items_crafted_name)},
|
||||
{'format.1_colon_2', 'Chat messages', get_for_player(index, player_console_chats_name)}
|
||||
}
|
||||
Game.player_print(info_t)
|
||||
|
||||
|
@ -44,14 +44,17 @@ local Gui = require 'utils.gui'
|
||||
local Event = require 'utils.event'
|
||||
local Token = require 'utils.token'
|
||||
local Schedule = require 'utils.task'
|
||||
local PlayerStats = require 'features.player_stats'
|
||||
local math = require 'utils.math'
|
||||
local Color = require 'resources.color_presets'
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local format = string.format
|
||||
local size = table.size
|
||||
local insert = table.insert
|
||||
local pairs = pairs
|
||||
local tonumber = tonumber
|
||||
local change_for_global = ScoreTracker.change_for_global
|
||||
local change_for_player = ScoreTracker.change_for_player
|
||||
local coins_spent_name = 'coins-spent'
|
||||
local set_timeout_in_ticks = Schedule.set_timeout_in_ticks
|
||||
local clamp = math.clamp
|
||||
local floor = math.floor
|
||||
@ -568,7 +571,8 @@ Gui.on_click(item_button_name, function (event)
|
||||
end
|
||||
|
||||
redraw_market_items(data)
|
||||
PlayerStats.change_coin_spent(player.index, cost)
|
||||
change_for_player(player.index, coins_spent_name, cost)
|
||||
change_for_global(coins_spent_name, cost)
|
||||
do_coin_label(coin_count - cost, data.coin_label)
|
||||
|
||||
raise_event(Retailer.events.on_market_purchase, {
|
||||
|
@ -4,11 +4,13 @@ local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
local Task = require 'utils.task'
|
||||
local Retailer = require 'features.retailer'
|
||||
local PlayerStats = require 'features.player_stats'
|
||||
local Donator = require 'features.donator'
|
||||
local RS = require 'map_gen.shared.redmew_surface'
|
||||
local Server = require 'features.server'
|
||||
local CrashSiteToast = require 'map_gen.maps.crash_site.crash_site_toast'
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local change_for_player = ScoreTracker.change_for_player
|
||||
local coins_earned_name = 'coins-earned'
|
||||
|
||||
local table = require 'utils.table'
|
||||
--local next = next
|
||||
@ -1789,7 +1791,7 @@ end
|
||||
local function coin_mined(event)
|
||||
local stack = event.item_stack
|
||||
if stack.name == 'coin' then
|
||||
PlayerStats.change_coin_earned(event.player_index, stack.count)
|
||||
change_for_player(event.player_index, coins_earned_name, stack.count)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
local Global = require 'utils.global'
|
||||
local Game = require 'utils.game'
|
||||
local PlayerStats = require 'features.player_stats'
|
||||
local Command = require 'utils.command'
|
||||
local Ranks = require 'resources.ranks'
|
||||
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local change_for_player = ScoreTracker.change_for_player
|
||||
local coins_earned_name = 'coins-earned'
|
||||
local format = string.format
|
||||
local abs = math.abs
|
||||
local concat = table.concat
|
||||
@ -72,7 +73,7 @@ Public.give_reward = function(player, amount, message)
|
||||
end
|
||||
local coin_difference = player.insert(reward)
|
||||
if reward_token[1] == 'coin' then
|
||||
PlayerStats.change_coin_earned(player_index, coin_difference)
|
||||
change_for_player(player_index, coins_earned_name, coin_difference)
|
||||
end
|
||||
return coin_difference
|
||||
end
|
||||
@ -100,7 +101,7 @@ Public.remove_reward = function(player, amount, message)
|
||||
end
|
||||
local coin_difference = player.remove_item(unreward)
|
||||
if reward_token[1] == 'coin' then
|
||||
PlayerStats.change_coin_earned(player_index, -coin_difference)
|
||||
change_for_player(player_index, coins_earned_name, -coin_difference)
|
||||
end
|
||||
return coin_difference
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user