mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Merge pull request #935 from linaori/cleanup-player-stats
Cleanup player stats
This commit is contained in:
commit
99890acdc2
12
config.lua
12
config.lua
@ -283,7 +283,17 @@ global.config = {
|
||||
},
|
||||
-- adds many commands for users and admins alike
|
||||
redmew_commands = {
|
||||
enabled = true
|
||||
enabled = true,
|
||||
whois = {
|
||||
player_data_to_show = {
|
||||
'player-distance-walked',
|
||||
'coins-earned',
|
||||
'coins-spent',
|
||||
'player-deaths',
|
||||
'player-items-crafted',
|
||||
'player-console-chats'
|
||||
}
|
||||
}
|
||||
},
|
||||
-- adds many commands for admins
|
||||
admin_commands = {
|
||||
|
@ -9,11 +9,24 @@ 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 pairs = pairs
|
||||
local abs = math.abs
|
||||
local round = math.round
|
||||
local remove = table.remove
|
||||
local insert = table.insert
|
||||
local concat = table.concat
|
||||
local get_rank_color = Rank.get_rank_color
|
||||
local get_rank_name = Rank.get_rank_name
|
||||
local get_player_rank = Rank.get_player_rank
|
||||
@ -38,6 +51,7 @@ local player_poke_cooldown = {}
|
||||
local player_pokes = {}
|
||||
local player_settings = {}
|
||||
local no_notify_players = {}
|
||||
local prototype_locale_string_cache = {}
|
||||
|
||||
Global.register(
|
||||
{
|
||||
@ -86,7 +100,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 +273,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 +302,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)
|
||||
@ -316,7 +330,7 @@ local column_builders = {
|
||||
return label
|
||||
end,
|
||||
draw_cell = function(parent, cell_data)
|
||||
local text = table.concat({cell_data.coin_earned, '/', cell_data.coin_spent})
|
||||
local text = concat({cell_data.coin_earned, '/', cell_data.coin_spent})
|
||||
|
||||
local label = parent.add {type = 'label', name = coin_cell_name, caption = text}
|
||||
local label_style = label.style
|
||||
@ -330,7 +344,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,
|
||||
@ -347,15 +361,24 @@ local column_builders = {
|
||||
return label
|
||||
end,
|
||||
draw_cell = function(parent, cell_data)
|
||||
local tooltip = {}
|
||||
local tooltip = {''}
|
||||
for name, count in pairs(cell_data.causes) do
|
||||
table.insert(tooltip, name)
|
||||
table.insert(tooltip, ': ')
|
||||
table.insert(tooltip, count)
|
||||
table.insert(tooltip, '\n')
|
||||
if not prototype_locale_string_cache[name] then
|
||||
local prototype = game.entity_prototypes[name]
|
||||
if not prototype then
|
||||
prototype = game.item_prototypes[name]
|
||||
end
|
||||
prototype_locale_string_cache[name] = prototype and prototype.localised_name or {name}
|
||||
end
|
||||
|
||||
insert(tooltip, prototype_locale_string_cache[name])
|
||||
insert(tooltip, ': ')
|
||||
insert(tooltip, count)
|
||||
insert(tooltip, '\n')
|
||||
end
|
||||
if #tooltip > 1 then
|
||||
remove(tooltip)
|
||||
end
|
||||
table.remove(tooltip)
|
||||
tooltip = table.concat(tooltip)
|
||||
|
||||
local label =
|
||||
parent.add {type = 'label', name = deaths_cell_name, caption = cell_data.count, tooltip = tooltip}
|
||||
@ -486,7 +509,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 +518,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 +542,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
|
||||
|
||||
@ -545,10 +568,10 @@ local function redraw_cells(data)
|
||||
|
||||
for _, c in ipairs(columns) do
|
||||
local cell_data = column_builders[c].create_data(p)
|
||||
table.insert(row, cell_data)
|
||||
insert(row, cell_data)
|
||||
end
|
||||
|
||||
table.insert(list_data, row)
|
||||
insert(list_data, row)
|
||||
end
|
||||
|
||||
table.sort(list_data, comp)
|
||||
@ -703,7 +726,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
|
||||
@ -742,7 +765,7 @@ Gui.on_click(
|
||||
player_pokes[poke_player_index] = count
|
||||
|
||||
local poke_str = poke_messages[random(#poke_messages)]
|
||||
local message = table.concat({'>> ', player.name, ' has poked ', poke_player.name, ' with ', poke_str, ' <<'})
|
||||
local message = concat({'>> ', player.name, ' has poked ', poke_player.name, ' with ', poke_str, ' <<'})
|
||||
|
||||
for _, p in ipairs(game.connected_players) do
|
||||
local frame = p.gui.left[main_frame_name]
|
||||
@ -756,7 +779,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
|
||||
|
@ -115,7 +115,7 @@ local function draw_main_frame(center, player)
|
||||
for name, setting in pairs(settings) do
|
||||
local label = setting_grid.add({
|
||||
type = 'label',
|
||||
caption = setting.localised_string,
|
||||
caption = setting.locale_string,
|
||||
})
|
||||
|
||||
local label_style = label.style
|
||||
|
@ -6,7 +6,9 @@ local Gui = require 'utils.gui'
|
||||
local Color = require 'resources.color_presets'
|
||||
local Server = require 'features.server'
|
||||
local ScoreTracker = require 'utils.score_tracker'
|
||||
local format_number = require 'util'.format_number
|
||||
local pairs = pairs
|
||||
local concat = table.concat
|
||||
local scores_to_show = global.config.score.global_to_show
|
||||
local set_timeout_in_ticks = Schedule.set_timeout_in_ticks
|
||||
local main_frame_name = Gui.uid_name()
|
||||
@ -22,27 +24,18 @@ Global.register(memory, function(tbl) memory = tbl end)
|
||||
|
||||
---Creates a map of score name => {captain, tooltip}
|
||||
local function get_global_score_labels()
|
||||
local metadata = ScoreTracker.get_score_metadata()
|
||||
local scores = {}
|
||||
local scores = ScoreTracker.get_global_scores_with_metadata(scores_to_show)
|
||||
local score_labels = {}
|
||||
|
||||
for index = 1, #scores_to_show do
|
||||
local score_name = scores_to_show[index]
|
||||
local score_metadata = metadata[score_name]
|
||||
if score_metadata then
|
||||
local icon = score_metadata.icon
|
||||
local label_text = ''
|
||||
if icon then
|
||||
label_text = icon .. ' '
|
||||
end
|
||||
|
||||
scores[score_name] = {
|
||||
caption = label_text .. ScoreTracker.get_for_global(score_name),
|
||||
tooltip = score_metadata.localised_string
|
||||
}
|
||||
end
|
||||
for index = 1, #scores do
|
||||
local score_data = scores[index]
|
||||
score_labels[score_data.name] = {
|
||||
caption = concat({score_data.icon, format_number(score_data.value, true)}, ' '),
|
||||
tooltip = score_data.locale_string
|
||||
}
|
||||
end
|
||||
|
||||
return scores
|
||||
return score_labels
|
||||
end
|
||||
|
||||
local do_redraw_score = Token.register(function()
|
||||
|
@ -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'
|
||||
@ -79,7 +77,7 @@ local function get_cause_name(cause)
|
||||
return name
|
||||
end
|
||||
end
|
||||
return 'unspecified'
|
||||
return 'player_stats.unknown_death_cause'
|
||||
end
|
||||
|
||||
local function player_died(event)
|
||||
@ -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,19 +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 format_number = require 'util'.format_number
|
||||
local player_data_to_show = global.config.redmew_commands.whois.player_data_to_show
|
||||
local print_to_player = Game.player_print
|
||||
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)
|
||||
Game.player_print({'common.fail_no_target', target_name}, Color.fail)
|
||||
print_to_player({'common.fail_no_target', target_name}, Color.fail)
|
||||
end
|
||||
|
||||
--- Kill a player with fish as the cause of death.
|
||||
@ -50,18 +53,18 @@ local function kill(args, player)
|
||||
if player then
|
||||
if not target or target == player then -- player suicide
|
||||
if not do_fish_kill(player, true) then
|
||||
Game.player_print({'redmew_commands.kill_fail_suicide_no_character'})
|
||||
print_to_player({'redmew_commands.kill_fail_suicide_no_character'})
|
||||
end
|
||||
elseif target and player.admin then -- admin killing target
|
||||
if not do_fish_kill(target) then
|
||||
Game.player_print({'redmew_commands.kill_fail_target_no_character'}, target_name)
|
||||
print_to_player({'redmew_commands.kill_fail_target_no_character'}, target_name)
|
||||
end
|
||||
else -- player failing to kill target
|
||||
Game.player_print({'redmew_commands.kill_fail_no_perm'})
|
||||
print_to_player({'redmew_commands.kill_fail_no_perm'})
|
||||
end
|
||||
elseif target then -- server killing target
|
||||
if not do_fish_kill(target) then
|
||||
Game.player_print({'redmew_commands.kill_fail_target_no_character'}, target_name)
|
||||
print_to_player({'redmew_commands.kill_fail_target_no_character'}, target_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -70,21 +73,22 @@ 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.'
|
||||
Game.player_print(v.name .. ' has been afk for' .. time)
|
||||
time = time .. floor(v.afk_time / 60) % 60 .. ' seconds.'
|
||||
print_to_player(v.name .. ' has been afk for' .. time)
|
||||
end
|
||||
end
|
||||
if count == 0 then
|
||||
Game.player_print({'redmew_commands.afk_no_afk'})
|
||||
print_to_player({'redmew_commands.afk_no_afk'})
|
||||
end
|
||||
end
|
||||
|
||||
@ -94,7 +98,7 @@ local function zoom(args, player)
|
||||
if zoom_val then
|
||||
player.zoom = zoom_val
|
||||
else
|
||||
Game.player_print({'redmew_commands.zoom_fail'})
|
||||
print_to_player({'redmew_commands.zoom_fail'})
|
||||
end
|
||||
end
|
||||
|
||||
@ -110,7 +114,7 @@ local function find_player(args, player)
|
||||
|
||||
target = target.character
|
||||
if not target or not target.valid then
|
||||
Game.player_print({'redmew_commands.find_player_fail_no_character', target_name})
|
||||
print_to_player({'redmew_commands.find_player_fail_no_character', target_name})
|
||||
return
|
||||
end
|
||||
|
||||
@ -123,7 +127,7 @@ local function show_rail_block(_, player)
|
||||
local show = not vs.show_rail_block_visualisation
|
||||
vs.show_rail_block_visualisation = show
|
||||
|
||||
Game.player_print({'redmew_commands.show_rail_block_success', tostring(show)})
|
||||
print_to_player({'redmew_commands.show_rail_block_success', tostring(show)})
|
||||
end
|
||||
|
||||
--- Provides the time on the server
|
||||
@ -158,7 +162,7 @@ local function list_seeds()
|
||||
|
||||
seeds[#seeds] = nil
|
||||
seeds = concat(seeds)
|
||||
Game.player_print(seeds)
|
||||
print_to_player(seeds)
|
||||
end
|
||||
|
||||
local function print_version()
|
||||
@ -168,45 +172,43 @@ local function print_version()
|
||||
else
|
||||
version_str = {'redmew_commands.print_version_from_source'}
|
||||
end
|
||||
Game.player_print(version_str)
|
||||
print_to_player(version_str)
|
||||
end
|
||||
|
||||
--- Prints information about the target player
|
||||
local function print_player_info(args, player)
|
||||
local target_ident = args.player
|
||||
local target, target_name, index = Utils.validate_player(target_ident)
|
||||
local target, target_name, player_index = Utils.validate_player(target_ident)
|
||||
|
||||
if not target then
|
||||
print_no_target(target_ident)
|
||||
return
|
||||
end
|
||||
|
||||
local info_t = {
|
||||
'redmew_commands.whois_formatter',
|
||||
{'format.1_colon_2', 'Name', target_name},
|
||||
{'format.single_item', target.connected and 'Online: yes' or 'Online: no'},
|
||||
{'format.1_colon_2', 'Index', target.index},
|
||||
{'format.1_colon_2', 'Rank', Rank.get_player_rank_name(target_name)},
|
||||
{'format.single_item', Donator.is_donator(target.name) and 'Donator: yes' or 'Donator: no'},
|
||||
{'format.1_colon_2', 'Time played', Utils.format_time(target.online_time)},
|
||||
{'format.1_colon_2', 'AFK time', Utils.format_time(target.afk_time or 0)},
|
||||
{'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)}
|
||||
}
|
||||
Game.player_print(info_t)
|
||||
local sep = ': '
|
||||
print_to_player({'', {'common.player_name'}, sep, target_name})
|
||||
print_to_player({'', {'common.connection_status'}, sep, {target.connected and 'common.online' or 'common.offline'}})
|
||||
print_to_player({'', {'common.player_index'}, sep, target.index})
|
||||
print_to_player({'', {'common.player_rank'}, sep, Rank.get_player_rank_name(target_name)})
|
||||
print_to_player({'', {'ranks.donator'}, sep, {Donator.is_donator(target.name) and 'common.yes' or 'common.no'}})
|
||||
print_to_player({'', {'common.time_played'}, sep, Utils.format_time(target.online_time)})
|
||||
print_to_player({'', {'common.afk_time'}, sep, Utils.format_time(target.afk_time or 0)})
|
||||
print_to_player({'', {'common.current_force'}, sep, target.force.name})
|
||||
print_to_player({'', {'common.current_surface'}, sep, target.surface.name})
|
||||
print_to_player({'', {'common.player_tag'}, sep, target.tag})
|
||||
|
||||
local scores = ScoreTracker.get_player_scores_with_metadata(player_index, player_data_to_show)
|
||||
|
||||
for i = 1, #scores do
|
||||
local score_data = scores[i]
|
||||
print_to_player({'', score_data.locale_string, sep, format_number(score_data.value, true)})
|
||||
end
|
||||
|
||||
if (not player or player.admin) and args.inventory then
|
||||
local m_inventory = target.get_inventory(defines.inventory.character_main)
|
||||
m_inventory = m_inventory.get_contents()
|
||||
Game.player_print('Main and hotbar inventories: ')
|
||||
Game.player_print(serpent.line(m_inventory))
|
||||
print_to_player('Main and hotbar inventories: ')
|
||||
print_to_player(serpent.line(m_inventory))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
@ -567,7 +570,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, {
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=Žádný hráč se jménem __1__ se nenašel
|
||||
warn_no_target=Varování: hráč __1__ nebyl nalezen, ale příkaz bude stále vykonán.
|
||||
|
@ -30,7 +30,6 @@ mention_not_found_plural=__1__ Hráči nebyli nalezeni: __2__
|
||||
mention_not_found_singular=__1__ Hráč nebyl nalezen: __2__
|
||||
|
||||
[redmew_commands]
|
||||
whois_formatter=__1__\n__2__\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__\n__9__\n__10__\n__11__\n__12__\n__13__\n__14__\n__15__\n__16__\n
|
||||
kill_fail_suicide_no_character=Promiňte, ale nemáte postavu, kterou byste zabili.
|
||||
kill_fail_target_no_character=Promiň, ale __1__ nemá postavu, kterou by zabil.
|
||||
kill_fail_no_perm=Nemáte oprávnění použít /kill na ostatních hráčích.
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=Inger spiller fundet med navn: __1__
|
||||
warn_no_target=Advarsel: spiller __1__ er ikke fundet, men kommandoen bliver stadig udført.
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=Kein Spieler mit Name __1__ gefunden.
|
||||
warn_no_target=Warnung: Spieler __1__ konnte nicht gefunden werden, der Befehl wird trotzdem ausgeführt.
|
||||
|
@ -5,6 +5,19 @@ fail_no_target=No player found with name: __1__
|
||||
warn_no_target=Warning: player __1__ is not found, but the command will still be executed.
|
||||
close_button=Close
|
||||
server_unavailable=The server is currently unavailable.
|
||||
player_name=Player name
|
||||
connection_status=Connection status
|
||||
online=online
|
||||
offline=offline
|
||||
player_index=Player index
|
||||
player_rank=Player rank
|
||||
yes=yes
|
||||
no=no
|
||||
time_played=Time played
|
||||
afk_time=AFK time
|
||||
current_force=Current force
|
||||
current_surface=Current surface
|
||||
player_tag=Player tag
|
||||
|
||||
[ranks]
|
||||
probation=Probation
|
||||
@ -14,7 +27,3 @@ regular=Regular
|
||||
admin=Admin
|
||||
donator=Donator
|
||||
donator_abbreviation=D
|
||||
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
@ -33,7 +33,6 @@ destroy_success=__1__ destroyed
|
||||
destroy_fail=Nothing found to destroy. (You must have an entity under your cursor when you hit enter)
|
||||
|
||||
[redmew_commands]
|
||||
whois_formatter=__1__\n__2__\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__\n__9__\n__10__\n__11__\n__12__\n__13__\n__14__\n__15__\n__16__\n
|
||||
kill_fail_suicide_no_character=Sorry, you don't have a character to kill.
|
||||
kill_fail_target_no_character=Sorry, __1__ doesn't have a character to kill.
|
||||
kill_fail_no_perm=Sorry you don't have permission to use the kill command on other players.
|
||||
@ -136,4 +135,5 @@ player_deaths=Player deaths
|
||||
player_console_chats=Player console chats
|
||||
player_items_crafted=Player items crafted
|
||||
player_distance_walked=Distance walked
|
||||
satellites_launched=satellites launched
|
||||
satellites_launched=Satellites launched
|
||||
unknown_death_cause=Unknown
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=Pelaajaa ei löydy nimellä __1__
|
||||
warn_no_target=Varoitus: pelaaja __1__ ei löydy, mutta komento on suoritettu.
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=Non jouer avec le nom: __1__
|
||||
warn_no_target=Attention! Jouer __1__ ne trouvé pas. L'execution de le commandement aller continu.
|
||||
|
@ -23,7 +23,6 @@ mention_not_found_plural=__1__ Joueurs introuvables : __2__
|
||||
mention_not_found_singular=__1__ Joueur introuvable : __2__
|
||||
|
||||
[redmew_commands]
|
||||
whois_formatter=__1__\n__2__\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__\n__9__\n__10__\n__11__\n__12__\n__13__\n__14__\n__15__\n__16__\n
|
||||
kill_fail_suicide_no_character=Désolé, vous n'avez pas de personnage à tuer.
|
||||
kill_fail_target_no_character=Désolé, __1__ n'a pas de caractère à tuer.
|
||||
kill_fail_no_perm=Désolé vous n'avez pas la permission d'utiliser la commande ""tuer"" sur les autres joueurs.
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=이름 __1__ 을 가진 플레이어를 찾지 못했습니다.
|
||||
warn_no_target=경고: 이름 __1__ 을 가진 플레이어를 찾지 못했지만, 명령은 실행 될 것입니다.
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=Ingen spiller funnet med navnet: __1__
|
||||
warn_no_target=Advarsel: spiller __1__ er ikke funnet, men kommando vil fortsatt bli utført.
|
||||
|
@ -30,7 +30,6 @@ mention_not_found_plural=__1__ Spillere ikke funnet: __2__
|
||||
mention_not_found_singular=__1__ Spiller ikke funnet: __2__
|
||||
|
||||
[redmew_commands]
|
||||
whois_formatter=__1__\n__2__\n__3__\n__4__\n__5__\n__6__\n__7__\n__8__\n__9__\n__10__\n__11__\n__12__\n__13__\n__14__\n__15__\n__16__\n
|
||||
kill_fail_suicide_no_character=Beklager, du har ikke et character å drepe.
|
||||
kill_fail_target_no_character=Sorry, __1__ har ikke en character å drepe.
|
||||
kill_fail_no_perm=Beklager at du ikke har tillatelse til å bruke kill kommandoen på andre spillere.
|
||||
|
@ -1,7 +1,3 @@
|
||||
[format]
|
||||
1_colon_2=__1__: __2__
|
||||
single_item=__1__
|
||||
|
||||
[common]
|
||||
fail_no_target=Nenhum jogador encontrado com nome: __1__
|
||||
warn_no_target=Aviso: o jogador __1__ não foi encontrado, mas o comando ainda será executado.
|
||||
|
@ -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,5 +1,6 @@
|
||||
local Global = require 'utils.global'
|
||||
local Color = require 'resources.color_presets'
|
||||
local print = print
|
||||
|
||||
local Game = {}
|
||||
|
||||
@ -31,8 +32,9 @@ end
|
||||
-- @param color <table> defaults to white
|
||||
function Game.player_print(msg, color)
|
||||
color = color or Color.white
|
||||
if game.player then
|
||||
game.player.print(msg, color)
|
||||
local player = game.player
|
||||
if player then
|
||||
player.print(msg, color)
|
||||
else
|
||||
print(msg)
|
||||
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
|
||||
|
@ -82,7 +82,7 @@ function Public.register(name, setting_type, default, localisation_key)
|
||||
type = setting_type,
|
||||
default = default,
|
||||
data_transformation = data_transformation,
|
||||
localised_string = localisation_key and {localisation_key} or name,
|
||||
locale_string = localisation_key and {localisation_key} or name,
|
||||
}
|
||||
|
||||
settings[name] = setting
|
||||
|
@ -39,9 +39,9 @@ local on_global_score_changed = Public.events.on_global_score_changed
|
||||
--- This function must be called in the control stage, i.e. not inside an event.
|
||||
---
|
||||
---@param name string
|
||||
---@param localisation_string table
|
||||
---@param locale_string table
|
||||
---@param icon string
|
||||
function Public.register(name, localisation_string, icon)
|
||||
function Public.register(name, locale_string, icon)
|
||||
if _LIFECYCLE ~= _STAGE.control then
|
||||
error(format('You can only register score types in the control stage, i.e. not inside events. Tried setting "%s".', name), 2)
|
||||
end
|
||||
@ -53,7 +53,7 @@ function Public.register(name, localisation_string, icon)
|
||||
local score = {
|
||||
name = name,
|
||||
icon = icon,
|
||||
localised_string = localisation_string
|
||||
locale_string = locale_string
|
||||
}
|
||||
|
||||
score_metadata[name] = score
|
||||
@ -147,6 +147,56 @@ function Public.get_for_global(score_name)
|
||||
return memory_global[score_name] or 0
|
||||
end
|
||||
|
||||
---Returns all metadata merged with the values for this player for the given score names.
|
||||
---
|
||||
---@param player_index number
|
||||
---@param score_names table
|
||||
function Public.get_player_scores_with_metadata(player_index, score_names)
|
||||
local scores = {}
|
||||
local size = 0
|
||||
for i = 1, #score_names do
|
||||
local score_name = score_names[i]
|
||||
local metadata = score_metadata[score_name]
|
||||
if metadata then
|
||||
local player_scores = memory_players[player_index]
|
||||
if player_scores then
|
||||
size = size + 1
|
||||
scores[size] = {
|
||||
name = metadata.name,
|
||||
locale_string = metadata.locale_string,
|
||||
icon = metadata.icon,
|
||||
value = player_scores[score_name] or 0
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return scores
|
||||
end
|
||||
|
||||
---Returns all metadata merged with the values of the global scores for the given score names.
|
||||
---
|
||||
---@param score_names table
|
||||
function Public.get_global_scores_with_metadata(score_names)
|
||||
local scores = {}
|
||||
local size = 0
|
||||
for i = 1, #score_names do
|
||||
local score_name = score_names[i]
|
||||
local metadata = score_metadata[score_name]
|
||||
if metadata then
|
||||
size = size + 1
|
||||
scores[size] = {
|
||||
name = metadata.name,
|
||||
locale_string = metadata.locale_string,
|
||||
icon = metadata.icon,
|
||||
value = memory_global[score_name] or 0
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return scores
|
||||
end
|
||||
|
||||
---Returns the full score metadata, note that this is a reference, do not modify
|
||||
---this data unless you know what you're doing!
|
||||
function Public.get_score_metadata()
|
||||
|
Loading…
Reference in New Issue
Block a user