mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
commit
4e8fa9d54a
@ -3,17 +3,9 @@ local Game = require 'utils.game'
|
||||
local PlayerStats = require 'features.player_stats'
|
||||
local Gui = require 'utils.gui'
|
||||
local Color = require 'resources.color_presets'
|
||||
local Global = require 'utils.global'
|
||||
local Server = require('features.server')
|
||||
|
||||
local data = {rockets_launched = 0}
|
||||
|
||||
Global.register(
|
||||
data,
|
||||
function(tbl)
|
||||
data = tbl
|
||||
end
|
||||
)
|
||||
local concat = table.concat
|
||||
|
||||
local main_frame_name = Gui.uid_name()
|
||||
local main_button_name = Gui.uid_name()
|
||||
@ -27,28 +19,22 @@ local function create_score_gui(event)
|
||||
local top = player.gui.top
|
||||
|
||||
if not top[main_button_name] then
|
||||
local button =
|
||||
top.add({type = 'sprite-button', name = main_button_name, sprite = 'achievement/there-is-no-spoon'})
|
||||
local style = button.style
|
||||
style.minimal_height = 38
|
||||
style.minimal_width = 38
|
||||
style.top_padding = 2
|
||||
style.left_padding = 4
|
||||
style.right_padding = 4
|
||||
style.bottom_padding = 2
|
||||
top.add({type = 'sprite-button', name = main_button_name, sprite = 'achievement/there-is-no-spoon'})
|
||||
end
|
||||
end
|
||||
|
||||
local function refresh_score()
|
||||
local players = game.connected_players
|
||||
local count = game.forces.player.get_item_launched('satellite')
|
||||
|
||||
local rockets_launched = 'Rockets launched: ' .. data.rockets_launched
|
||||
local biters_liberated = 'Biters liberated: ' .. PlayerStats.get_total_biter_kills()
|
||||
local buildings_by_hand = 'Buildings by hand: ' .. PlayerStats.get_total_player_built_entities()
|
||||
local buildings_by_robot = 'Buildings by robots: ' .. PlayerStats.get_total_robot_built_entities()
|
||||
local trees_chopped = 'Trees chopped: ' .. PlayerStats.get_total_player_trees_mined()
|
||||
local rocks_smashed = 'Rocks smashed: ' .. PlayerStats.get_total_player_rocks_mined()
|
||||
local kills_by_train = 'Kills by train: ' .. PlayerStats.get_total_train_kills()
|
||||
local satellites_launched = concat {'Satellites launched: ', count, ' '}
|
||||
local biters_liberated = concat {'Biters liberated: ', PlayerStats.get_total_biter_kills(), ' '}
|
||||
local buildings_by_hand = concat {'Buildings by hand: ', PlayerStats.get_total_player_built_entities(), ' '}
|
||||
local buildings_by_robot = concat {'Buildings by robots: ', PlayerStats.get_total_robot_built_entities(), ' '}
|
||||
local trees_chopped = concat {'Trees chopped: ', PlayerStats.get_total_player_trees_mined(), ' '}
|
||||
local rocks_smashed = concat {'Rocks smashed: ', PlayerStats.get_total_player_rocks_mined(), ' '}
|
||||
local kills_by_train = concat {'Kills by train: ', PlayerStats.get_total_train_kills(), ' '}
|
||||
local coins_spent = concat {'Coins spent: ', PlayerStats.get_total_coins_spent(), ' '}
|
||||
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
@ -56,13 +42,14 @@ local function refresh_score()
|
||||
|
||||
if frame and frame.valid then
|
||||
local score_table = frame.score_table
|
||||
score_table.label_rockets_launched.caption = rockets_launched
|
||||
score_table.label_satellites_launched.caption = satellites_launched
|
||||
score_table.label_biters_killed.caption = biters_liberated
|
||||
score_table.label_player_built_entities.caption = buildings_by_hand
|
||||
score_table.label_robot_built_entities.caption = buildings_by_robot
|
||||
score_table.label_player_mined_trees.caption = trees_chopped
|
||||
score_table.label_player_mined_stones.caption = rocks_smashed
|
||||
score_table.label_kills_by_train.caption = kills_by_train
|
||||
score_table.label_coins_spent.caption = coins_spent
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -71,88 +58,107 @@ local function score_label_style(label, color)
|
||||
local style = label.style
|
||||
style.font = 'default-bold'
|
||||
style.font_color = color
|
||||
style.top_padding = 2
|
||||
style.left_padding = 4
|
||||
style.right_padding = 4
|
||||
end
|
||||
|
||||
local function score_show(top)
|
||||
local count = game.forces.player.get_item_launched('satellite')
|
||||
|
||||
local frame = top.add {type = 'frame', name = main_frame_name}
|
||||
local score_table = frame.add {type = 'table', name = 'score_table', column_count = 8}
|
||||
local score_table = frame.add {type = 'table', name = 'score_table', column_count = 4}
|
||||
local style = score_table.style
|
||||
style.vertical_spacing = 4
|
||||
style.horizontal_spacing = 16
|
||||
|
||||
local label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_rockets_launched',
|
||||
caption = 'Rockets launched: ' .. data.rockets_launched
|
||||
name = 'label_satellites_launched',
|
||||
caption = concat {'Satellites launched: ', count, ' '}
|
||||
}
|
||||
score_label_style(label, Color.orange)
|
||||
score_table.add {type = 'label', caption = ' '}
|
||||
|
||||
label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_biters_killed',
|
||||
caption = 'Biters liberated: ' .. PlayerStats.get_total_biter_kills()
|
||||
caption = concat {'Biters liberated: ', PlayerStats.get_total_biter_kills(), ' '}
|
||||
}
|
||||
score_label_style(label, Color.red)
|
||||
score_table.add {type = 'label', caption = ' '}
|
||||
|
||||
label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_player_built_entities',
|
||||
caption = 'Buildings by hand: ' .. PlayerStats.get_total_player_built_entities()
|
||||
caption = concat {'Buildings by hand: ', PlayerStats.get_total_player_built_entities(), ' '}
|
||||
}
|
||||
score_label_style(label, Color.white)
|
||||
score_table.add {type = 'label', caption = ' '}
|
||||
|
||||
label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_robot_built_entities',
|
||||
caption = 'Buildings by robots: ' .. PlayerStats.get_total_robot_built_entities()
|
||||
caption = concat {'Buildings by robots: ', PlayerStats.get_total_robot_built_entities(), ' '}
|
||||
}
|
||||
score_label_style(label, Color.white)
|
||||
score_table.add {type = 'label', caption = ' '}
|
||||
|
||||
label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_player_mined_trees',
|
||||
caption = 'Trees chopped: ' .. PlayerStats.get_total_player_trees_mined()
|
||||
caption = concat {'Trees chopped: ', PlayerStats.get_total_player_trees_mined(), ' '}
|
||||
}
|
||||
score_label_style(label, Color.lime)
|
||||
score_table.add {type = 'label', caption = ' '}
|
||||
|
||||
label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_player_mined_stones',
|
||||
caption = 'Rocks smashed: ' .. PlayerStats.get_total_player_rocks_mined()
|
||||
caption = concat {'Rocks smashed: ', PlayerStats.get_total_player_rocks_mined(), ' '}
|
||||
}
|
||||
score_label_style(label, Color.lime)
|
||||
score_table.add {type = 'label', caption = ' '}
|
||||
|
||||
label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_kills_by_train',
|
||||
caption = 'Kills by train: ' .. PlayerStats.get_total_train_kills()
|
||||
caption = concat {'Kills by train: ', PlayerStats.get_total_train_kills(), ' '}
|
||||
}
|
||||
score_label_style(label, Color.yellow)
|
||||
|
||||
refresh_score()
|
||||
label =
|
||||
score_table.add {
|
||||
type = 'label',
|
||||
name = 'label_coins_spent',
|
||||
caption = concat {'Coins spent: ', PlayerStats.get_total_coins_spent(), ' '}
|
||||
}
|
||||
score_label_style(label, Color.yellow)
|
||||
end
|
||||
|
||||
local function rocket_launched()
|
||||
local count = data.rockets_launched + 1
|
||||
data.rockets_launched = count
|
||||
local function rocket_launched(event)
|
||||
local entity = event.rocket
|
||||
|
||||
local message = 'A rocket has been launched! Total count: ' .. count
|
||||
if not entity or not entity.valid or not entity.force == 'player' then
|
||||
return
|
||||
end
|
||||
|
||||
game.print(message)
|
||||
Server.to_discord_bold(message)
|
||||
local inventory = entity.get_inventory(defines.inventory.rocket)
|
||||
if not inventory or not inventory.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local count = inventory.get_item_count('satellite')
|
||||
if count == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
count = game.forces.player.get_item_launched('satellite')
|
||||
|
||||
if (count < 10) or ((count < 50) and ((count % 5) == 0)) or ((count % 25) == 0) then
|
||||
local message = 'A satellite has been launched! Total count: ' .. count
|
||||
|
||||
game.print(message)
|
||||
Server.to_discord_bold(message)
|
||||
end
|
||||
|
||||
refresh_score()
|
||||
end
|
||||
|
@ -19,6 +19,7 @@ local total_player_rocks_mined = {0}
|
||||
local total_robot_built_entities = {0}
|
||||
local total_player_built_entities = {0}
|
||||
local total_biter_kills = {0}
|
||||
local total_coins_spent = {0}
|
||||
|
||||
local train_kill_causes = {
|
||||
['locomotive'] = true,
|
||||
@ -42,7 +43,8 @@ Global.register(
|
||||
player_console_chats = player_console_chats,
|
||||
total_robot_built_entities = total_robot_built_entities,
|
||||
total_player_built_entities = total_player_built_entities,
|
||||
total_biter_kills = total_biter_kills
|
||||
total_biter_kills = total_biter_kills,
|
||||
total_coins_spent = total_coins_spent
|
||||
},
|
||||
function(tbl)
|
||||
player_last_position = tbl.player_last_position
|
||||
@ -59,6 +61,7 @@ Global.register(
|
||||
total_robot_built_entities = tbl.total_robot_built_entities
|
||||
total_player_built_entities = tbl.total_player_built_entities
|
||||
total_biter_kills = tbl.total_biter_kills
|
||||
total_coins_spent = tbl.total_coins_spent
|
||||
end
|
||||
)
|
||||
|
||||
@ -204,11 +207,16 @@ function Public.get_coin_spent(player_index)
|
||||
end
|
||||
|
||||
function Public.set_coin_spent(player_index, value)
|
||||
local old_value = player_coin_spent[player_index]
|
||||
player_coin_spent[player_index] = value
|
||||
|
||||
local diff = value - old_value
|
||||
total_coins_spent[1] = total_coins_spent[1] + diff
|
||||
end
|
||||
|
||||
function Public.change_coin_spent(player_index, amount)
|
||||
player_coin_spent[player_index] = player_coin_spent[player_index] + amount
|
||||
total_coins_spent[1] = total_coins_spent[1] + amount
|
||||
end
|
||||
|
||||
function Public.get_death_count(player_index)
|
||||
@ -256,4 +264,8 @@ function Public.get_total_biter_kills()
|
||||
return total_biter_kills[1]
|
||||
end
|
||||
|
||||
function Public.get_total_coins_spent()
|
||||
return total_coins_spent[1]
|
||||
end
|
||||
|
||||
return Public
|
||||
|
Loading…
x
Reference in New Issue
Block a user