1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-11-23 22:22:34 +02:00

Various changes

This commit is contained in:
Gerkiz
2025-05-10 12:43:38 +02:00
parent 1327fc711d
commit 613bd5fc9c
26 changed files with 1077 additions and 793 deletions

View File

@@ -257,6 +257,6 @@ Tabs.on_click(
module_name,
function (event)
local player = event.player
Tabs.reload_active_tab(player)
Tabs.reload_active_tab(player, nil, 'MutagenLog')
end
)

View File

@@ -237,7 +237,7 @@ Gui.on_click(
module_name,
function(event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'ChronoTrain')
end
)

View File

@@ -144,6 +144,7 @@ local random = math.random
local floor = math.floor
local blacklist = {
['atomic-bomb'] = true,
['cargo-wagon'] = true,
['locomotive'] = true,
['artillery-wagon'] = true,

View File

@@ -19,7 +19,8 @@ local function draw_charging_gui(player, activate_custom_buttons)
type = 'sprite-button',
name = charging_station_name,
sprite = 'item/battery-mk2-equipment',
tooltip = {
tooltip =
{
'modules.charging_station_tooltip'
},
style = Gui.button_style
@@ -36,7 +37,7 @@ local function draw_charging_gui(player, activate_custom_buttons)
end
local function discharge_accumulators(surface, position, force, power_needs)
local accumulators = surface.find_entities_filtered { name = 'accumulator', force = force, position = position, radius = 13 }
local accumulators = surface.find_entities_filtered { type = 'accumulator', force = force, position = position, radius = 13 }
local power_drained = 0
power_needs = power_needs * 1
for _, accu in pairs(accumulators) do
@@ -59,6 +60,7 @@ local function discharge_accumulators(surface, position, force, power_needs)
end
local function charge(player)
local warn = module_name .. 'No valid armor to charge was found.'
if not player.character then
return player.print(module_name .. 'It seems that you are not in the realm of living.', { color = Color.warning })
end
@@ -67,15 +69,15 @@ local function charge(player)
end
local armor_inventory = player.get_inventory(defines.inventory.character_armor)
if not armor_inventory.valid then
return player.print(module_name .. 'No valid armor to charge was found.', { color = Color.warning })
return player.print(warn, { color = Color.warning })
end
local armor = armor_inventory[1]
if not armor.valid_for_read then
return player.print(module_name .. 'No valid armor to charge was found.', { color = Color.warning })
return player.print(warn, { color = Color.warning })
end
local grid = armor.grid
if not grid or not grid.valid then
return player.print(module_name .. 'No valid armor to charge was found.', { color = Color.warning })
return player.print(warn, { color = Color.warning })
end
local ents = player.physical_surface.find_entities_filtered { name = 'accumulator', force = player.force, position = player.physical_position, radius = 13 }
@@ -115,7 +117,8 @@ local function on_player_joined_game(event)
{
player = player,
element_name = charging_station_name,
tooltip = {
tooltip =
{
'modules.charging_station_tooltip'
},
sprite = 'item/battery-mk2-equipment'

File diff suppressed because it is too large Load Diff

View File

@@ -17,7 +17,8 @@ local try_get_data = Server.try_get_data
local insert = table.insert
local random = math.random
local this = {
local this =
{
score_table = {},
sort_by = {}
}
@@ -29,7 +30,8 @@ Global.register(
end
)
local biters = {
local biters =
{
'small-biter',
'medium-biter',
'big-biter',
@@ -139,7 +141,8 @@ local function contains(tbl, key, string, rtn)
end
local function sort_list(method, column_name, score_list)
local comparators = {
local comparators =
{
['ascending'] = function (a, b)
return a[column_name] < b[column_name]
end,
@@ -461,7 +464,8 @@ local function get_score_list()
remove_non_top_10(whitelisted_score_tbl, score_force.players)
local score_list = {}
if not score_force then
score_list[#score_list + 1] = {
score_list[#score_list + 1] =
{
name = 'Nothing here yet',
killscore = 0,
built_entities = 0,
@@ -574,9 +578,10 @@ local function show_score(data)
local t = frame.add { type = 'table', column_count = 4 }
-- Score headers
local headers = {
{ name = 'score_player', caption = 'Player' },
{ column = 'killscore', name = 'score_killscore', caption = 'Killscore' },
local headers =
{
{ name = 'score_player', caption = 'Player' },
{ column = 'killscore', name = 'score_killscore', caption = 'Killscore' },
{ column = 'built_entities', name = 'score_built_entities', caption = 'Built structures' },
{ column = 'mined_entities', name = 'score_mined_entities', caption = 'Mined entities' }
}
@@ -593,7 +598,8 @@ local function show_score(data)
-- Header
local label =
t.add {
t.add
{
type = 'label',
caption = cap,
name = header.name
@@ -638,7 +644,8 @@ local function show_score(data)
p = { color = { r = random(1, 255), g = random(1, 255), b = random(1, 255) } }
end
end
local special_color = {
local special_color =
{
r = p.color.r * 0.6 + 0.4,
g = p.color.g * 0.6 + 0.4,
b = p.color.b * 0.6 + 0.4,
@@ -649,7 +656,8 @@ local function show_score(data)
local b = entry.built_entities > 0 and entry.built_entities or ''
local m = entry.mined_entities > 0 and entry.mined_entities or ''
line = {
line =
{
{ caption = entry.name, color = special_color },
{ caption = tostring(k) },
{ caption = tostring(b) },
@@ -659,7 +667,8 @@ local function show_score(data)
for _, column in ipairs(line) do
local label =
t.add {
t.add
{
type = 'label',
caption = column.caption,
color = column.color or default_color
@@ -669,7 +678,7 @@ local function show_score(data)
label.style.maximal_width = 150
label.style.horizontal_align = 'right'
end -- foreach column
end -- foreach entry
end -- foreach entry
end
local show_score_token = Task.register(show_score)
@@ -701,7 +710,8 @@ local function on_gui_click(event)
local name = event.element.name
-- Handles click on a score header
local element_to_column = {
local element_to_column =
{
['score_killscore'] = 'killscore',
['score_built_entities'] = 'built_entities',
['score_mined_entities'] = 'mined_entities'
@@ -751,7 +761,7 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Highscore')
end
)

View File

@@ -58,8 +58,10 @@ Gui.button_style = 'mod_gui_button'
Gui.set_toggle_button(true)
Gui.set_mod_gui_top_frame(true)
local collapse_kill = {
entities = {
local collapse_kill =
{
entities =
{
['laser-turret'] = true,
['flamethrower-turret'] = true,
['gun-turret'] = true,
@@ -196,7 +198,8 @@ local collapse_message =
function (data)
local pos = data.position
local message = data.message
local collapse_position = {
local collapse_position =
{
position = pos
}
Alert.alert_all_players_location(collapse_position, message)
@@ -304,7 +307,8 @@ local collapse_after_wave_200 = function ()
if wave_number >= 200 and not Collapse.has_collapse_started() then
Collapse.start_now(true)
local data = {
local data =
{
position = Collapse.get_position()
}
data.message = ({ 'breached_wall.collapse_start' })
@@ -581,11 +585,11 @@ function Public.init_stateful(current_task)
Public.stateful.reset_stateful(false, true)
Public.stateful.apply_startup_settings()
if Public.is_modded then
for _, player in pairs(game.connected_players) do
Public.on_player_created({ player_index = player.index })
end
end
-- if Public.is_modded then
-- for _, player in pairs(game.connected_players) do
-- Public.on_player_created({ player_index = player.index })
-- end
-- end
current_task.message = 'Initialized stateful!'
current_task.state = 'clear_fortress'
@@ -806,7 +810,8 @@ function Public.init_mtn()
Public.create_landing_surface()
local tooltip = {
local tooltip =
{
[1] = ({ 'main.diff_tooltip', '500', '50%', '15%', '15%', '1', '12', '50', '10000', '100%', '15', '10' }),
[2] = ({ 'main.diff_tooltip', '300', '25%', '10%', '10%', '2', '10', '50', '7000', '75%', '8', '8' }),
[3] = ({ 'main.diff_tooltip', '50', '0%', '0%', '0%', '4', '3', '10', '5000', '50%', '5', '6' })

View File

@@ -15,24 +15,26 @@ local try_get_data = Server.try_get_data
local insert = table.insert
local this = {
local this =
{
seasons = {},
sort_by = {}
}
Global.register(
this,
function(t)
function (t)
this = t
end
)
local function sort_list(method, column_name, score_list)
local comparators = {
['ascending'] = function(a, b)
local comparators =
{
['ascending'] = function (a, b)
return a[column_name] < b[column_name]
end,
['descending'] = function(a, b)
['descending'] = function (a, b)
return a[column_name] > b[column_name]
end
}
@@ -59,7 +61,8 @@ local function write_additional_stats(key)
return
end
this.seasons[#this.seasons + 1] = {
this.seasons[#this.seasons + 1] =
{
season_index = season,
rounds_survived = rounds_survived,
buffs_granted = total_buffs,
@@ -76,11 +79,11 @@ end
local get_scores =
Task.register(
function(data)
local value = data.value
this.seasons = value
end
)
function (data)
local value = data.value
this.seasons = value
end
)
function Public.get_season_scores()
local secs = Server.get_current_time()
@@ -119,13 +122,14 @@ local function on_init()
end
end
local sorting_symbol = {ascending = '', descending = ''}
local sorting_symbol = { ascending = '', descending = '' }
local function get_score_list()
local seasons = this.seasons
local score_list = {}
if not seasons then
score_list[#score_list + 1] = {
score_list[#score_list + 1] =
{
season_index = 'N/A',
rounds_survived = 'N/A',
buffs_granted = 'N/A',
@@ -155,22 +159,23 @@ local function show_score(data)
local frame = data.frame
frame.clear()
local flow = frame.add {type = 'flow'}
local flow = frame.add { type = 'flow' }
local sFlow = flow.style
sFlow.horizontally_stretchable = true
sFlow.horizontal_align = 'center'
sFlow.vertical_align = 'center'
-- Score per player
local t = frame.add {type = 'table', column_count = 5}
local t = frame.add { type = 'table', column_count = 5 }
-- Score headers
local headers = {
{column = 'season_index', name = 'season_index', caption = 'Season', tooltip = 'Season index.'},
{column = 'rounds_survived', name = 'rounds_survived', caption = 'Rounds survived', tooltip = 'Rounds survived in the season.'},
{column = 'buffs_granted', name = 'buffs_granted', caption = 'Buffs granted', tooltip = 'Buffs granted to players which is gained each round won.'},
{column = 'started', name = 'started', caption = 'Start date', tooltip = 'Start date of the season.'},
{column = 'ended', name = 'ended', caption = 'Stop date', tooltip = 'Stop date of the season.'}
local headers =
{
{ column = 'season_index', name = 'season_index', caption = 'Season', tooltip = 'Season index.' },
{ column = 'rounds_survived', name = 'rounds_survived', caption = 'Rounds survived', tooltip = 'Rounds survived in the season.' },
{ column = 'buffs_granted', name = 'buffs_granted', caption = 'Buffs granted', tooltip = 'Buffs granted to players which is gained each round won.' },
{ column = 'started', name = 'started', caption = 'Start date', tooltip = 'Start date of the season.' },
{ column = 'ended', name = 'ended', caption = 'Stop date', tooltip = 'Stop date of the season.' }
}
local sorting_pref = this.sort_by[player.index]
@@ -185,14 +190,15 @@ local function show_score(data)
-- Header
local label =
t.add {
type = 'label',
caption = cap,
tooltip = header.tooltip or '',
name = header.name
}
t.add
{
type = 'label',
caption = cap,
tooltip = header.tooltip or '',
name = header.name
}
label.style.font = 'default-listbox'
label.style.font_color = {r = 0.98, g = 0.66, b = 0.22} -- yellow
label.style.font_color = { r = 0.98, g = 0.66, b = 0.22 } -- yellow
label.style.minimal_width = 125
label.style.horizontal_align = 'center'
end
@@ -205,40 +211,42 @@ local function show_score(data)
-- New pane for scores (while keeping headers at same position)
local scroll_pane =
frame.add(
{
type = 'scroll-pane',
name = 'score_scroll_pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
)
{
type = 'scroll-pane',
name = 'score_scroll_pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
)
scroll_pane.style.maximal_height = 400
scroll_pane.style.minimal_width = 700
t = scroll_pane.add {type = 'table', column_count = 5}
t = scroll_pane.add { type = 'table', column_count = 5 }
-- Score entries
local i = 0
for _, score_data in pairs(score_list) do
i = i + 1
local lines = {
{caption = score_data.season_index},
{caption = score_data.rounds_survived},
{caption = score_data.buffs_granted},
{caption = score_data.started},
{caption = score_data.ended}
local lines =
{
{ caption = score_data.season_index },
{ caption = score_data.rounds_survived },
{ caption = score_data.buffs_granted },
{ caption = score_data.started },
{ caption = score_data.ended }
}
local default_color = {r = 0.9, g = 0.9, b = 0.9}
local default_color = { r = 0.9, g = 0.9, b = 0.9 }
for _, column in ipairs(lines) do
local label =
t.add {
type = 'label',
caption = column.caption,
color = column.color or default_color
}
t.add
{
type = 'label',
caption = column.caption,
color = column.color or default_color
}
label.style.font = 'default'
label.style.minimal_width = 125
label.style.maximal_width = 150
@@ -276,7 +284,8 @@ local function on_gui_click(event)
local name = event.element.name
-- Handles click on a score header
local element_to_column = {
local element_to_column =
{
['season_index'] = 'season_index',
['rounds_survived'] = 'rounds_survived',
['buffs_granted'] = 'buffs_granted',
@@ -292,7 +301,7 @@ local function on_gui_click(event)
sorting_pref.method = 'descending'
sorting_pref.column = column
end
show_score({player = player, frame = frame})
show_score({ player = player, frame = frame })
return
end
end
@@ -300,7 +309,7 @@ end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not this.sort_by[player.index] then
this.sort_by[player.index] = {method = 'descending', column = 'season_index'}
this.sort_by[player.index] = { method = 'descending', column = 'season_index' }
end
end
@@ -313,7 +322,7 @@ end
Server.on_data_set_changed(
score_dataset,
function(data)
function (data)
if data.value then
this.seasons = data.value
end
@@ -322,20 +331,20 @@ Server.on_data_set_changed(
Server.on_data_set_changed(
score_key_dev,
function(data)
function (data)
if data.value then
this.seasons = data.value
end
end
)
Gui.add_tab_to_gui({name = module_name, caption = 'Seasons', id = show_score_token, admin = false, only_server_sided = true})
Gui.add_tab_to_gui({ name = module_name, caption = 'Seasons', id = show_score_token, admin = false, only_server_sided = true })
Gui.on_click(
module_name,
function(event)
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Seasons')
end
)

View File

@@ -4,28 +4,33 @@ local Server = require 'utils.server'
local Event = require 'utils.event'
local Task = require 'utils.task_token'
local stateful_settings = {
local stateful_settings =
{
reversed = false
}
local this = {
local this =
{
players = {},
traps = {},
scheduler = {
scheduler =
{
start_after = 0,
surface = nil,
operation = nil,
next_operation = nil
},
-- new initializer for scenario management because the old one sucked hard
current_task = {
current_task =
{
state = 'move_players',
surface_name = 'Init',
default_task = 'move_players',
show_messages = true,
step = 1
},
adjusted_zones = {
adjusted_zones =
{
scrap = {},
forest = {},
size = nil,
@@ -43,7 +48,8 @@ local dataset = 'scenario_settings'
local dataset_key = 'mtn_v3_table'
local dataset_key_dev = 'mtn_v3_table_dev'
Public.events = {
Public.events =
{
reset_map = Event.generate_event_name('reset_map'),
on_entity_mined = Event.generate_event_name('on_entity_mined'),
on_market_item_purchased = Event.generate_event_name('on_market_item_purchased'),
@@ -73,18 +79,21 @@ Global.register(
end
)
Public.zone_settings = {
Public.zone_settings =
{
zone_depth = 704,
zone_width = 510
}
Public.valid_enemy_forces = {
Public.valid_enemy_forces =
{
['enemy'] = true,
['aggressors'] = true,
['aggressors_frenzy'] = true
}
Public.pickaxe_upgrades = {
Public.pickaxe_upgrades =
{
'Wood',
'Plastic',
'Bone',
@@ -162,10 +171,12 @@ function Public.reset_main_table()
this.breach_wall_warning = false
this.icw_locomotive = nil
this.game_lost = false
this.charts = {
this.charts =
{
tags = {}
}
this.statistics = {
this.statistics =
{
surfaces_produced = {}
}
this.death_mode = false
@@ -177,24 +188,28 @@ function Public.reset_main_table()
this.toolbelt_researched_count = 0
this.all_the_fish = false
this.reverse_collapse_warning = false
this.gap_between_zones = {
this.gap_between_zones =
{
set = false,
gap = 900,
neg_gap = 500,
highest_pos = 0
}
this.gap_between_locomotive = {
this.gap_between_locomotive =
{
hinders = {},
gap = 900,
neg_gap = 3520, -- earlier 2112 (3 zones, whereas 704 is one zone)
neg_gap = 3520, -- earlier 2112 (3 zones, whereas 704 is one zone)
neg_gap_collapse = 5520, -- earlier 2112 (3 zones, whereas 704 is one zone)
highest_pos = nil
}
this.force_chunk = false
this.bw = false
this.debug_vars = {
this.debug_vars =
{
enabled = true,
vars = {
vars =
{
mining_chance = {}
}
}
@@ -202,7 +217,7 @@ function Public.reset_main_table()
this.block_non_trusted_opening_trains = true
this.block_non_trusted_trigger_collapse = true
this.allow_decon_main_surface = true
this.spectate_button_disable = true
this.spectate_button_disable = false
this.flamethrower_damage = {}
this.mined_scrap = 0
this.print_tech_to_discord = true
@@ -213,29 +228,35 @@ function Public.reset_main_table()
--!grief prevention
this.enable_arties = 6 -- default to callback 6
--!snip
this.enemy_spawners = {
this.enemy_spawners =
{
spawners = {},
enabled = false
}
this.poison_deployed = false
this.robotics_deployed = false
this.upgrades = {
this.upgrades =
{
showed_text = false,
burner_generator = {
burner_generator =
{
limit = 100,
bought = 0
},
landmine = {
landmine =
{
limit = 25,
bought = 0,
built = 0
},
flame_turret = {
flame_turret =
{
limit = 6,
bought = 0,
built = 0
},
unit_number = {
unit_number =
{
landmine = {},
flame_turret = {}
},
@@ -251,7 +272,8 @@ function Public.reset_main_table()
health_upgrades = 0,
pickaxe_tier = 1
}
this.orbital_strikes = {
this.orbital_strikes =
{
enabled = true
}
this.pickaxe_speed_per_purchase = 0.09
@@ -259,18 +281,21 @@ function Public.reset_main_table()
this.pre_final_battle = false
this.final_battle = false
this.disable_link_chest_cheese_mode = true
this.left_top = {
this.left_top =
{
x = 0,
y = 0
}
this.biters = {
this.biters =
{
amount = 0,
limit = 512
}
this.traps = {}
this.munch_time = true
this.magic_requirement = 50
this.loot_stats = {
this.loot_stats =
{
rare = 48,
normal = 48
}
@@ -280,19 +305,22 @@ function Public.reset_main_table()
this.main_market_items = {}
this.spill_items_to_surface = false
this.spectate = {}
this.placed_trains_in_zone = {
this.placed_trains_in_zone =
{
limit = 1,
randomized = false,
zones = {}
}
this.market_limits = {
this.market_limits =
{
chests_outside_limit = 8,
aura_limit = 100, -- limited to save UPS
pickaxe_tier_limit = 59,
health_upgrades_limit = 100,
xp_points_limit = 40
}
this.marked_fixed_prices = {
this.marked_fixed_prices =
{
chests_outside_cost = 3000,
health_cost = 14000,
pickaxe_cost = 3000,
@@ -315,7 +343,8 @@ function Public.reset_main_table()
this.collapse_amount = false
this.collapse_speed = false
this.y_value_position = 20
this.spawn_near_collapse = {
this.spawn_near_collapse =
{
active = true,
total_pos = 35,
compare = -150,
@@ -335,7 +364,8 @@ function Public.reset_main_table()
this.winter_mode = false
this.sent_to_discord = false
this.random_seed = random(100000000, 1000000000)
this.difficulty = {
this.difficulty =
{
multiply = 0.25,
highest = 10,
lowest = 4
@@ -351,12 +381,14 @@ function Public.reset_main_table()
this.check_if_threat_below_zero = true
this.rocks_to_remove = nil
this.tiles_to_replace = nil
this.mc_rewards = {
this.mc_rewards =
{
current = {},
temp_boosts = {}
}
this.adjusted_zones = {
this.adjusted_zones =
{
scrap = {},
forest = {},
size = nil,
@@ -365,10 +397,11 @@ function Public.reset_main_table()
reversed = stateful_settings.reversed,
disable_terrain = false
}
this.alert_zone_1 = false -- alert the players
this.alert_zone_1 = false -- alert the players
this.radars_reveal_new_chunks = false -- allows for the player to explore the map instead,
this.mining_utils = {
this.mining_utils =
{
rocks_yield_ore_maximum_amount = 500,
type_modifier = 1,
rocks_yield_ore_base_amount = 40,
@@ -378,7 +411,8 @@ function Public.reset_main_table()
this.wagons_in_the_wild = {}
this.player_market_settings = {}
this.quality_list = {
this.quality_list =
{
'normal',
}

View File

@@ -2749,7 +2749,7 @@ end
local function starting_zone(x, y, data, void_or_lab, adjusted_zones)
local p = { x = x, y = y }
local seed = data.seed + 10000
local seed = data.seed + 30000
local buildings = data.buildings
local tiles = data.tiles
local entities = data.entities
@@ -2768,7 +2768,7 @@ local function starting_zone(x, y, data, void_or_lab, adjusted_zones)
if random(1, 32) == 1 then
Public.spawn_random_buildings(buildings, p)
end
if random(1, 128) == 1 then
if random(1, 256) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
entities[#entities + 1] =
{

View File

@@ -25,18 +25,20 @@ local score_key_modded = 'pirate_ship_scores_modded'
local Public = {}
local insert = table.insert
local this = {
local this =
{
score_table = { player = {} },
sort_by = {},
}
Global.register(this, function(t)
Global.register(this, function (t)
this = t
end)
local function sort_list(method, column_name, score_list)
local comparators = {
['ascending'] = function(a, b)
local comparators =
{
['ascending'] = function (a, b)
if column_name == 'completion_time' then
return ((a[column_name] < b[column_name]) and not (a[column_name] == 0 and b[column_name] ~= 0))
or (a[column_name] ~= 0 and b[column_name] == 0) --put all 0s at the end
@@ -49,7 +51,7 @@ local function sort_list(method, column_name, score_list)
end
end,
--nosort
['descending'] = function(a, b)
['descending'] = function (a, b)
if column_name == 'completion_time' then
return ((b[column_name] < a[column_name]) and not (a[column_name] == 0 and b[column_name] ~= 0))
or (a[column_name] ~= 0 and b[column_name] == 0) --put all 0s at the end
@@ -145,7 +147,8 @@ local function get_tables_of_scores_by_type(scores)
table.sort(completion_times_latestv)
table.sort(leagues_travelled_latestv)
return {
return
{
latest_version = latest_version,
completion_times = completion_times,
leagues_travelled = leagues_travelled,
@@ -162,38 +165,39 @@ end
local function get_score_cuttofs(tables_of_scores_by_type)
local completion_times_cutoff = #tables_of_scores_by_type.completion_times > 8
and tables_of_scores_by_type.completion_times[8]
and tables_of_scores_by_type.completion_times[8]
or 9999999
local completion_times_mediump_latestv_cutoff = #tables_of_scores_by_type.completion_times_mediump_latestv > 4
and tables_of_scores_by_type.completion_times_mediump_latestv[4]
and tables_of_scores_by_type.completion_times_mediump_latestv[4]
or 9999999
local completion_times_hard_cutoff = #tables_of_scores_by_type.completion_times_hard > 4
and tables_of_scores_by_type.completion_times_hard[4]
and tables_of_scores_by_type.completion_times_hard[4]
or 9999999
local completion_times_nightmare_cutoff = #tables_of_scores_by_type.completion_times_hard > 2
and tables_of_scores_by_type.completion_times_hard[2]
and tables_of_scores_by_type.completion_times_hard[2]
or 9999999
local completion_times_latestv_cutoff = #tables_of_scores_by_type.completion_times_latestv > 8
and tables_of_scores_by_type.completion_times_latestv[8]
and tables_of_scores_by_type.completion_times_latestv[8]
or 9999999
local leagues_travelled_cutoff = #tables_of_scores_by_type.leagues_travelled > 8
and tables_of_scores_by_type.leagues_travelled[-8]
and tables_of_scores_by_type.leagues_travelled[-8]
or 0
local leagues_travelled_mediump_latestv_cutoff = #tables_of_scores_by_type.leagues_travelled_mediump_latestv > 4
and tables_of_scores_by_type.leagues_travelled_mediump_latestv[-4]
and tables_of_scores_by_type.leagues_travelled_mediump_latestv[-4]
or 0
local leagues_travelled_hard_cutoff = #tables_of_scores_by_type.leagues_travelled_hard > 4
and tables_of_scores_by_type.leagues_travelled_hard[-4]
and tables_of_scores_by_type.leagues_travelled_hard[-4]
or 0
local leagues_travelled_nightmare_cutoff = #tables_of_scores_by_type.leagues_travelled_hard > 2
and tables_of_scores_by_type.leagues_travelled_hard[-2]
and tables_of_scores_by_type.leagues_travelled_hard[-2]
or 0
local leagues_travelled_latestv_cutoff = #tables_of_scores_by_type.leagues_travelled_latestv > 86
and tables_of_scores_by_type.leagues_travelled_latestv[-8]
and tables_of_scores_by_type.leagues_travelled_latestv[-8]
or 0
return {
return
{
completion_times_cutoff = completion_times_cutoff,
completion_times_mediump_latestv_cutoff = completion_times_mediump_latestv_cutoff,
completion_times_hard_cutoff = completion_times_hard_cutoff,
@@ -350,7 +354,8 @@ local function local_highscores_write_stats(
-- end
if crew_secs_id then
t.runs[crew_secs_id] = {
t.runs[crew_secs_id] =
{
name = name,
captain_name = captain_name,
version = version,
@@ -370,7 +375,7 @@ local function local_highscores_write_stats(
-- log(_inspect(t))
end
local load_in_scores = Token.register(function(data)
local load_in_scores = Token.register(function (data)
local value = data.value
if not this.score_table['player'] then
this.score_table['player'] = {}
@@ -460,7 +465,8 @@ local function get_saved_scores_for_displaying()
if score_data and score_data.runs then
for _, score in pairs(score_data.runs or {}) do
insert(score_list, {
insert(score_list,
{
name = score and score.name,
captain_name = score and score.captain_name,
completion_time = score and score.completion_time or 99999,
@@ -471,7 +477,8 @@ local function get_saved_scores_for_displaying()
})
end
else
score_list[#score_list + 1] = {
score_list[#score_list + 1] =
{
name = 'Nothing here yet',
captain_name = '',
completion_time = 0,
@@ -517,7 +524,8 @@ local function score_gui(data)
local t = frame.add({ type = 'table', column_count = 7 })
-- Score headers
local headers = {
local headers =
{
{ name = '_name', caption = { 'pirates.highscore_heading_crew' } },
{
column = 'captain_name',
@@ -565,7 +573,8 @@ local function score_gui(data)
end
-- Header
local label = t.add({
local label = t.add(
{
type = 'label',
caption = cap,
name = header.name,
@@ -592,7 +601,8 @@ local function score_gui(data)
end
-- New pane for scores (while keeping headers at same position)
local scroll_pane = frame.add({
local scroll_pane = frame.add(
{
type = 'scroll-pane',
name = 'score_scroll_pane',
direction = 'vertical',
@@ -614,7 +624,8 @@ local function score_gui(data)
-- p = {color = {r = random(1, 255), g = random(1, 255), b = random(1, 255)}}
-- end
-- end
local special_color = {
local special_color =
{
r = p.color.r * 0.6 + 0.4,
g = p.color.g * 0.6 + 0.4,
b = p.color.b * 0.6 + 0.4,
@@ -626,10 +637,11 @@ local function score_gui(data)
local l = entry.leagues_travelled > 0 and entry.leagues_travelled or '?'
local v = entry.version and entry.version or '?'
local d = entry.difficulty > 0
and CoreData.difficulty_options[CoreData.get_difficulty_option_from_value(entry.difficulty)].text
and CoreData.difficulty_options[CoreData.get_difficulty_option_from_value(entry.difficulty)].text
or '?'
local c = entry.max_players > 0 and entry.max_players or '?'
local line = {
local line =
{
{ caption = entry.name, color = special_color },
{ caption = entry.captain_name or '?' },
{ caption = tostring(n) },
@@ -641,7 +653,8 @@ local function score_gui(data)
local default_color = { r = 0.9, g = 0.9, b = 0.9 }
for _, column in ipairs(line) do
local label = t.add({
local label = t.add(
{
type = 'label',
caption = column.caption,
color = column.color or default_color,
@@ -682,7 +695,8 @@ local function on_gui_click(event)
local name = event.element.name
-- Handles click on a score header
local element_to_column = {
local element_to_column =
{
['_captain_name'] = 'captain_name',
['_version'] = 'version',
['_completion_time'] = 'completion_time',
@@ -725,7 +739,8 @@ end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.index and this.sort_by and not this.sort_by[player.index] then
this.sort_by[player.index] = {
this.sort_by[player.index] =
{
{ method = 'ascending', column = 'completion_time' },
{ method = 'descending', column = 'leagues_travelled' },
{ method = 'descending', column = 'version' },
@@ -742,7 +757,7 @@ local function on_player_left_game(event)
end
end
Server.on_data_set_changed(score_dataset, function(data)
Server.on_data_set_changed(score_dataset, function (data)
local key
if is_game_modded() then
key = score_key_modded
@@ -758,7 +773,8 @@ Server.on_data_set_changed(score_dataset, function(data)
end
end)
Gui.add_tab_to_gui({
Gui.add_tab_to_gui(
{
name = module_name,
caption = 'Highscore',
id = score_gui_token,
@@ -766,9 +782,9 @@ Gui.add_tab_to_gui({
only_server_sided = true,
})
Gui.on_click(module_name, function(event)
Gui.on_click(module_name, function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Highscore')
end)
Event.on_init(on_init)

View File

@@ -3,7 +3,8 @@ local Token = require 'utils.token'
local module_name = Gui.uid_name()
local changelog = {
local changelog =
{
versions = {}
}
@@ -11,11 +12,11 @@ local Public = {}
function Public.SetVersions(versions)
for i = 1, #versions do
local v = versions[i]
if v.ver == nil or v.date == nil or v.desc == nil then
log('ERROR in changelog.SetVersions missing ver, date or desc from version#' .. i .. ' got:\n' .. serpent.line(v))
return
end
local v = versions[i]
if v.ver == nil or v.date == nil or v.desc == nil then
log('ERROR in changelog.SetVersions missing ver, date or desc from version#' .. i .. ' got:\n' .. serpent.line(v))
return
end
end
changelog.versions = versions
end
@@ -27,33 +28,34 @@ local function create_changelog(data)
frame.style.margin = 0
local scroll =
frame.add {
type = 'scroll-pane',
name = 'scroll_changelog',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
frame.add
{
type = 'scroll-pane',
name = 'scroll_changelog',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
for i = 1, #changelog.versions do
local v = changelog.versions[i]
local l = scroll.add {type = 'label', caption = 'Version ' .. v.ver .. ' -- ' .. v.date}
l.style.font = 'heading-1'
l.style.font_color = {r = 0.2, g = 0.9, b = 0.2}
l.style.minimal_width = 780
l.style.horizontal_align = 'center'
l.style.vertical_align = 'center'
local v = changelog.versions[i]
local l = scroll.add { type = 'label', caption = 'Version ' .. v.ver .. ' -- ' .. v.date }
l.style.font = 'heading-1'
l.style.font_color = { r = 0.2, g = 0.9, b = 0.2 }
l.style.minimal_width = 780
l.style.horizontal_align = 'center'
l.style.vertical_align = 'center'
local c = scroll.add {type = 'label', caption = v.desc}
c.style.font = 'heading-2'
c.style.single_line = false
c.style.font_color = {r = 0.85, g = 0.85, b = 0.88}
c.style.minimal_width = 780
c.style.horizontal_align = 'left'
c.style.vertical_align = 'center'
local c = scroll.add { type = 'label', caption = v.desc }
c.style.font = 'heading-2'
c.style.single_line = false
c.style.font_color = { r = 0.85, g = 0.85, b = 0.88 }
c.style.minimal_width = 780
c.style.horizontal_align = 'left'
c.style.vertical_align = 'center'
local line_v = scroll.add {type = 'line'}
line_v.style.top_margin = 4
line_v.style.bottom_margin = 4
local line_v = scroll.add { type = 'line' }
line_v.style.top_margin = 4
line_v.style.bottom_margin = 4
end
end
@@ -61,12 +63,12 @@ local create_changelog_token = Token.register(create_changelog)
Gui.on_click(
module_name,
function(event)
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Changelog')
end
)
Gui.add_tab_to_gui({name = module_name, caption = 'Changelog', id = create_changelog_token, admin = false})
Gui.add_tab_to_gui({ name = module_name, caption = 'Changelog', id = create_changelog_token, admin = false })
return Public

68
modules/corpse_marker.lua Normal file
View File

@@ -0,0 +1,68 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Util = require 'utils.core'
local Task = require 'utils.task_token'
local this =
{
death_tags = {}
}
Global.register(
this,
function (tbl)
this = tbl
end
)
local add_corpse_marker_token =
Task.register(
function (event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
local ents = player.surface.find_entities_filtered
{
name = 'character-corpse',
position = player.position,
radius = 5,
}
if #ents == 0 then
return
end
local entity = ents[1]
if not entity or not entity.valid then
return
end
player.add_pin
{
entity = entity,
}
end
)
Event.add(defines.events.on_pre_player_died, function (event)
local player = game.get_player(event.player_index)
if not player and not player.valid then
return
end
if not player.has_items_inside() then
return
end
local surface = player.surface
Util.iter_players(function (p)
if p.physical_surface_index == surface.index then
Task.set_timeout_in_ticks(10, add_corpse_marker_token, { player_index = p.index })
end
end)
end)

View File

@@ -5,33 +5,34 @@ local Task = require 'utils.task_token'
local module_name = Gui.uid_name()
local map_info = {
local map_info =
{
localised_category = false,
main_caption = nil,
main_caption_color = {r = 0.6, g = 0.3, b = 0.99},
main_caption_color = { r = 0.6, g = 0.3, b = 0.99 },
sub_caption = nil,
sub_caption_color = {r = 0.2, g = 0.9, b = 0.2},
sub_caption_color = { r = 0.2, g = 0.9, b = 0.2 },
text = nil
}
Global.register(
map_info,
function(tbl)
function (tbl)
map_info = tbl
end
)
local call_active_tab_token =
Task.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
function (event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
Gui.call_existing_tab(player, 'Map Info')
end
Gui.call_existing_tab(player, 'Map Info')
end
)
)
local Public = {}
@@ -45,9 +46,9 @@ local function create_map_intro(data)
frame.style.padding = 4
frame.style.margin = 0
local t = frame.add {type = 'table', column_count = 1}
local t = frame.add { type = 'table', column_count = 1 }
local line = t.add {type = 'line'}
local line = t.add { type = 'line' }
line.style.top_margin = 4
line.style.bottom_margin = 4
@@ -55,48 +56,49 @@ local function create_map_intro(data)
return
end
local caption = map_info.main_caption or {map_info.localised_category .. '.map_info_main_caption'}
local sub_caption = map_info.sub_caption or {map_info.localised_category .. '.map_info_sub_caption'}
local text = map_info.text or {map_info.localised_category .. '.map_info_text'}
local caption = map_info.main_caption or { map_info.localised_category .. '.map_info_main_caption' }
local sub_caption = map_info.sub_caption or { map_info.localised_category .. '.map_info_sub_caption' }
local text = map_info.text or { map_info.localised_category .. '.map_info_text' }
if map_info.localised_category then
map_info.main_caption = caption
map_info.sub_caption = sub_caption
map_info.text = text
end
local l = t.add {type = 'label', caption = map_info.main_caption}
local l = t.add { type = 'label', caption = map_info.main_caption }
l.style.font = 'heading-1'
l.style.font_color = map_info.main_caption_color
l.style.minimal_width = 780
l.style.horizontal_align = 'center'
l.style.vertical_align = 'center'
local l_2 = t.add {type = 'label', caption = map_info.sub_caption}
local l_2 = t.add { type = 'label', caption = map_info.sub_caption }
l_2.style.font = 'heading-2'
l_2.style.font_color = map_info.sub_caption_color
l_2.style.minimal_width = 780
l_2.style.horizontal_align = 'center'
l_2.style.vertical_align = 'center'
local line_2 = t.add {type = 'line'}
local line_2 = t.add { type = 'line' }
line_2.style.top_margin = 4
line_2.style.bottom_margin = 4
local scroll_pane =
frame.add {
type = 'scroll-pane',
name = 'scroll_pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
frame.add
{
type = 'scroll-pane',
name = 'scroll_pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
scroll_pane.style.maximal_height = 320
scroll_pane.style.minimal_height = 320
local l_3 = scroll_pane.add {type = 'label', caption = map_info.text}
local l_3 = scroll_pane.add { type = 'label', caption = map_info.text }
l_3.style.font = 'heading-2'
l_3.style.single_line = false
l_3.style.font_color = {r = 0.85, g = 0.85, b = 0.88}
l_3.style.font_color = { r = 0.85, g = 0.85, b = 0.88 }
l_3.style.minimal_width = 780
l_3.style.horizontal_align = 'center'
l_3.style.vertical_align = 'center'
@@ -108,18 +110,18 @@ local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.online_time == 0 then
Gui.call_existing_tab(player, 'Map Info')
Task.set_timeout_in_ticks(5, call_active_tab_token, {player_index = player.index})
Task.set_timeout_in_ticks(5, call_active_tab_token, { player_index = player.index })
end
end
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Gui.add_tab_to_gui({name = module_name, caption = 'Map Info', id = create_map_intro_token, admin = false})
Gui.add_tab_to_gui({ name = module_name, caption = 'Map Info', id = create_map_intro_token, admin = false })
Gui.on_click(
module_name,
function(event)
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Map Info')
end
)

View File

@@ -147,7 +147,8 @@ local function train_type_cause(cause)
return players
end
local get_cause_player = {
local get_cause_player =
{
['character'] = function (cause)
if not cause.player then
return
@@ -471,7 +472,8 @@ local function on_entity_damaged(event)
local position = p.physical_position
local area = {
local area =
{
left_top = { x = position.x - 5, y = position.y - 5 },
right_bottom = { x = position.x + 5, y = position.y + 5 }
}
@@ -609,6 +611,10 @@ local function on_player_rotated_entity(event)
end
local rpg_t = Public.get_value_from_player(player.index)
if not rpg_t then
return
end
if rpg_t.rotated_entity_delay > game.tick then
return
end
@@ -639,7 +645,8 @@ local function on_player_changed_position(event)
Public.gain_xp(player, 1.0)
end
local building_and_mining_blacklist = {
local building_and_mining_blacklist =
{
['tile-ghost'] = true,
['entity-ghost'] = true,
['item-entity'] = true,
@@ -763,7 +770,8 @@ local function on_player_crafted_item(event)
local d = random(0, 2999)
local item_dupe = d < chance
if item_dupe and final_xp < 6 then
local reward = {
local reward =
{
name = item.name,
count = 1
}
@@ -859,7 +867,8 @@ local function floaty_hearts(entity, c)
local position = { x = entity.position.x - 0.75, y = entity.position.y - 1 }
local b = 1.35
for _ = 1, c, 1 do
local p = {
local p =
{
(position.x + 0.4) + (b * -1 + random(0, b * 20) * 0.1),
position.y + (b * -1 + random(0, b * 20) * 0.1)
}
@@ -870,14 +879,17 @@ end
local function tame_unit_effects(player, entity)
floaty_hearts(entity, 7)
rendering.draw_text {
rendering.draw_text
{
text = '~' .. player.name .. "'s pet~",
surface = player.surface,
target = {
target =
{
entity = entity,
offset = { 0, -2.6 },
},
color = {
color =
{
r = player.color.r * 0.6 + 0.25,
g = player.color.g * 0.6 + 0.25,
b = player.color.b * 0.6 + 0.25,
@@ -951,7 +963,8 @@ local function on_player_used_capsule_custom(event)
end
local radius = 15
local area = {
local area =
{
left_top = { x = position.x - radius, y = position.y - radius },
right_bottom = { x = position.x + radius, y = position.y + radius }
}
@@ -995,7 +1008,8 @@ local function on_player_used_capsule_custom(event)
force = 'player'
end
local data = {
local data =
{
self = spell,
player = player,
damage_entity = damage_entity,
@@ -1009,7 +1023,8 @@ local function on_player_used_capsule_custom(event)
rpg_t = rpg_t
}
local funcs = {
local funcs =
{
remove_mana = Public.remove_mana,
damage_player_over_time = Public.damage_player_over_time,
cast_spell = Public.cast_spell
@@ -1128,7 +1143,8 @@ local function on_player_used_capsule(event)
end
local radius = 15
local area = {
local area =
{
left_top = { x = position.x - radius, y = position.y - radius },
right_bottom = { x = position.x + radius, y = position.y + radius }
}
@@ -1172,7 +1188,8 @@ local function on_player_used_capsule(event)
force = 'player'
end
local data = {
local data =
{
self = spell,
player = player,
damage_entity = damage_entity,
@@ -1186,7 +1203,8 @@ local function on_player_used_capsule(event)
rpg_t = rpg_t
}
local funcs = {
local funcs =
{
remove_mana = Public.remove_mana,
damage_player_over_time = Public.damage_player_over_time,
cast_spell = Public.cast_spell

View File

@@ -7,7 +7,8 @@ local Event = require 'utils.event'
local Gui = require 'utils.gui'
local Commands = require 'utils.commands'
local this = {
local this =
{
data = {},
module_disabled = false
}
@@ -22,7 +23,8 @@ Global.register(
local main_frame_name = Gui.uid_name()
local space = {
local space =
{
minimal_height = 10,
top_padding = 0,
bottom_padding = 0
@@ -152,7 +154,8 @@ local function close_player_inventory(player)
end
local function get_inventory_type(player, inventory_type)
local target_types = {
local target_types =
{
['Main'] = function ()
return unpack_inventory(player.get_main_inventory())
end,
@@ -202,6 +205,13 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
local flow = items_table.add({ type = 'flow' })
flow.style.vertical_align = 'bottom'
local tooltip
if quality and quality.name and types and types[name] and types[name].localised_name then
tooltip = { '', (quality.name == 'normal' and '' or { '', quality.localised_name, ' ' }), types[name].localised_name }
else
tooltip = name
end
local button =
flow.add(
{
@@ -209,7 +219,7 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
sprite = 'item/' .. name,
number = count,
name = name,
tooltip = { '', (quality.name == 'normal' and '' or { '', quality.localised_name, ' ' }), types[name].localised_name },
tooltip = tooltip,
style = 'slot_button'
}
)
@@ -225,6 +235,12 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
local p_armor = target.get_inventory(5)[1].grid.get_contents()
local grid_flow = items_table.add({ type = 'table', column_count = 10 })
for _, item in pairs(p_armor) do
local item_tooltip
if item.quality and prototypes.quality and prototypes.quality[item.quality] and types and types[item.name] then
item_tooltip = { '', (item.quality == 'normal' and '' or { '', prototypes.quality[item.quality].localised_name, ' ' }), types[item.name].localised_name }
else
item_tooltip = item.name
end
local armor_gui =
grid_flow.add(
{
@@ -232,7 +248,7 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
sprite = 'item/' .. item.name,
number = item.count,
name = item.name .. item.quality,
tooltip = { '', (item.quality == 'normal' and '' or { '', prototypes.quality[item.quality].localised_name, ' ' }), types[item.name].localised_name },
tooltip = item_tooltip,
style = 'slot_button'
}
)
@@ -254,7 +270,8 @@ local function add_inventory(panel, source, target, caption, panel_type)
data.panel_type = data.panel_type or {}
local pane_name = panel.add({ type = 'tab', caption = caption, name = caption })
local scroll_pane =
panel.add {
panel.add
{
type = 'scroll-pane',
name = caption .. 'tab',
direction = 'vertical',
@@ -331,7 +348,8 @@ local function open_inventory(source, target)
local ammo = unpack_inventory(target.get_inventory(defines.inventory.character_ammo))
local trash = unpack_inventory(target.get_inventory(defines.inventory.character_trash))
local types = {
local types =
{
['Main'] = main,
['Armor'] = armor,
['Guns'] = guns,
@@ -359,7 +377,8 @@ local function on_gui_click(event)
return
end
local types = {
local types =
{
['Main'] = true,
['Armor'] = true,
['Guns'] = true,

View File

@@ -26,12 +26,14 @@ local Server = require 'utils.server'
---@field validate_activated boolean
---@field command_activated boolean
local this = {
local this =
{
commands = {}
}
local trace = debug.traceback
local output = {
local output =
{
backend_is_required = 'No backend is currently available. Please try again later.',
server_is_required = 'This command requires to be run from the server.',
admin_is_required = 'This command requires admin permissions to run.',
@@ -49,7 +51,8 @@ local output = {
command_is_inactive = 'This command is already inactive.'
}
local check_boolean = {
local check_boolean =
{
['true'] = true,
['false'] = true
}
@@ -116,7 +119,8 @@ local function execute(event)
if event.player_index and event.player_index > 0 then
player = game.get_player(event.player_index)
else
player = {
player =
{
name = '<server>',
position = { x = 0, y = 0 },
surface = game.get_surface('nauvis'),
@@ -257,9 +261,6 @@ local function execute(event)
local param = conv(parameters[index])
if param_data.as_type == 'player' and param ~= nil then
local player_name = param
if type(player_name) ~= 'string' then
return reject('Inputted value is not of type string. Valid values are: "string"')
end
local player_data = game.get_player(player_name) --[[@type LuaPlayer]]
if not player_data then
return reject('Player was not found.')
@@ -281,9 +282,6 @@ local function execute(event)
end
if param_data.as_type == 'player-online' and param ~= nil then
local player_name = param
if type(player_name) ~= 'string' then
return reject('Inputted value is not of type string. Valid values are: "string"')
end
local player_data = game.get_player(player_name) --[[@type LuaPlayer]]
if not player_data or not player_data.valid then
return reject('Player was not found.')
@@ -296,9 +294,6 @@ local function execute(event)
end
if param_data.as_type == 'player-admin' and param ~= nil then
local player_name = param
if type(player_name) ~= 'string' then
return reject('Inputted value is not of type string. Valid values are: "string"')
end
local player_data = game.get_player(player_name) --[[@type LuaPlayer]]
if not player_data or not player_data.valid then
return reject('Player was not found.')
@@ -311,9 +306,6 @@ local function execute(event)
end
if param_data.as_type == 'server' and param ~= nil then
local player_name = param
if type(player_name) ~= 'string' then
return reject('Inputted value is not of type string. Valid values are: "string"')
end
local player_data = game.get_player(player_name) --[[@type LuaPlayer]]
if player_data and player_data.valid then
return reject('Not running from server.')
@@ -583,7 +575,8 @@ function Public:callback(func)
end
end
local directions = {
local directions =
{
[0] = 'defines.direction.north',
[1] = 'defines.direction.northnortheast',
[2] = 'defines.direction.northeast',

View File

@@ -30,7 +30,7 @@ local names = {}
local data = {}
local settings =
{
mod_gui_top_frame = false,
mod_gui_top_frame = true,
disabled_tabs = {},
disable_clear_invalid_data = true
}
@@ -298,20 +298,20 @@ function Public.add_main_frame_with_toolbar(player, align, set_frame_name, set_s
if close_main_frame_name then
close_button = titlebar.add
{
type = 'sprite-button',
name = close_main_frame_name,
style = 'frame_action_button',
mouse_button_filter = { 'left' },
sprite = 'utility/close',
hovered_sprite = 'utility/close_fat',
clicked_sprite = 'utility/close_fat',
tooltip = 'Close',
tags =
{
action = 'close_main_frame_gui'
type = 'sprite-button',
name = close_main_frame_name,
style = 'frame_action_button',
mouse_button_filter = { 'left' },
sprite = 'utility/close',
hovered_sprite = 'utility/close_fat',
clicked_sprite = 'utility/close_fat',
tooltip = 'Close',
tags =
{
action = 'close_main_frame_gui'
}
}
}
end
local inside_frame =
@@ -747,12 +747,12 @@ local function top_button(player)
return
end
local button = player.gui.top.add(
{
type = 'sprite-button',
name = main_button_name,
sprite = 'item/raw-fish',
style = Public.button_style
})
{
type = 'sprite-button',
name = main_button_name,
sprite = 'item/raw-fish',
style = Public.button_style
})
button.style.minimal_height = 38
button.style.maximal_height = 38
button.style.minimal_width = 40
@@ -820,28 +820,23 @@ local function draw_main_frame(player)
local tabbed_pane = inside_frame.add({ type = 'tabbed-pane', name = 'tabbed_pane' })
for name, callback in pairs(tabs) do
if not settings.disabled_tabs[name] then
local show = false
local secs = Server.get_current_time()
if callback.only_server_sided then
if secs then
local tab = tabbed_pane.add({ type = 'tab', caption = name, name = callback.name })
local name_frame = tabbed_pane.add({ type = 'frame', name = name, direction = 'vertical' })
tabbed_pane.add_tab(tab, name_frame)
end
if secs then show = true end
elseif callback.admin == true then
if player.admin then
if not secs then
local tab = tabbed_pane.add({ type = 'tab', caption = name, name = callback.name })
local name_frame = tabbed_pane.add({ type = 'frame', name = name, direction = 'vertical' })
tabbed_pane.add_tab(tab, name_frame)
elseif secs and admins[player.name] then
local tab = tabbed_pane.add({ type = 'tab', caption = name, name = callback.name })
local name_frame = tabbed_pane.add({ type = 'frame', name = name, direction = 'vertical' })
tabbed_pane.add_tab(tab, name_frame)
end
if player.admin and (not secs or (secs and admins[player.name])) then
show = true
end
else
local tab = tabbed_pane.add({ type = 'tab', caption = name, name = callback.name })
local name_frame = tabbed_pane.add({ type = 'frame', name = name, direction = 'vertical' })
show = true
end
if show then
local tab = tabbed_pane.add({ type = 'tab', caption = name, name = callback.name, style = 'slightly_smaller_tab' })
local name_frame = tabbed_pane.add({ type = 'frame', name = name, direction = 'vertical', style = 'mod_gui_inside_deep_frame' })
name_frame.style.padding = 8
tabbed_pane.add_tab(tab, name_frame)
end
end

View File

@@ -27,7 +27,8 @@ local count_label_name = Gui.uid_name()
local rows_per_page = 500
local create_admin_panel
local this = {
local this =
{
player_data = {}
}
@@ -50,7 +51,8 @@ local function get_player_data(player, remove)
end
if not this.player_data[player.name] then
this.player_data[player.name] = {
this.player_data[player.name] =
{
selected_history_index = nil,
filter_player = nil,
show_all_players = nil,
@@ -202,7 +204,8 @@ local function free(player, source_player)
clear_validation_action(source_player.name, 'free')
end
local bring_player_messages = {
local bring_player_messages =
{
'Come here my friend!',
'Papers, please.',
'What are you up to?'
@@ -231,7 +234,8 @@ local function bring_player(player, source_player)
end
end
local go_to_player_messages = {
local go_to_player_messages =
{
'Papers, please.',
'What are you up to?'
}
@@ -267,7 +271,8 @@ local function spank(player, source_player)
end
end
local damage_messages = {
local damage_messages =
{
' recieved a love letter from ',
' recieved a strange package from '
}
@@ -285,7 +290,8 @@ local function damage(player, source_player)
end
end
local kill_messages = {
local kill_messages =
{
' did not obey the law.',
' should not have triggered the admins.',
' did not respect authority.',
@@ -309,7 +315,8 @@ local function kill(player, source_player)
end
end
local enemy_messages = {
local enemy_messages =
{
'Shoot on sight!',
'Wanted dead or alive!'
}
@@ -500,7 +507,8 @@ end
local function search_text_locally(history, player_data, callback)
local antigrief = AntiGrief.get()
local history_index = {
local history_index =
{
['Capsule History'] = antigrief.capsule_history,
['Message History'] = antigrief.message_history,
['Friendly Fire History'] = antigrief.friendly_fire_history,
@@ -670,12 +678,14 @@ local function create_pagination_buttons(player_data, frame, table_count)
end
local button_flow =
frame.add {
frame.add
{
type = 'flow',
direction = 'horizontal'
}
local prev_button =
button_flow.add {
button_flow.add
{
type = 'button',
name = prev_button_name,
caption = '◀️',
@@ -686,7 +696,8 @@ local function create_pagination_buttons(player_data, frame, table_count)
prev_button.tooltip = 'Previous page\nHolding [color=yellow]shift[/color] while pressing LMB/RMB will jump to the first page.'
local count_label =
button_flow.add {
button_flow.add
{
type = 'label',
name = count_label_name,
caption = current_page .. '/' .. last_page
@@ -695,7 +706,8 @@ local function create_pagination_buttons(player_data, frame, table_count)
player_data.count_label = count_label
local next_button =
button_flow.add {
button_flow.add
{
type = 'button',
name = next_button_name,
caption = '▶️',
@@ -755,7 +767,8 @@ create_admin_panel = function (data)
drop_down.style.left_padding = 12
local t = frame.add({ type = 'table', column_count = 4 })
local buttons = {
local buttons =
{
t.add(
{
type = 'button',
@@ -835,7 +848,8 @@ create_admin_panel = function (data)
frame.add({ type = 'label', caption = 'Global Actions:' })
local actionTable = frame.add({ type = 'table', column_count = 4 })
local bottomButtons = {
local bottomButtons =
{
actionTable.add(
{
type = 'button',
@@ -940,7 +954,8 @@ create_admin_panel = function (data)
search_text.text = player_data.search_text or ''
search_text.style.width = 140
local btn =
search_table.add {
search_table.add
{
type = 'sprite-button',
tooltip = '[color=blue]Info![/color]\nSearching does not filter the amount of pages shown.\nThis is a limitation in the Factorio engine.\nIterating over the whole table would lag the game.\nSo when searching, you will still see the same amount of pages.\nAnd the results will be "janky".',
sprite = 'utility/questionmark'
@@ -965,7 +980,8 @@ create_admin_panel = function (data)
drop_down_2.style.right_padding = 12
drop_down_2.style.left_padding = 12
local history_index = {
local history_index =
{
['Capsule History'] = antigrief.capsule_history,
['Message History'] = antigrief.message_history,
['Friendly Fire History'] = antigrief.friendly_fire_history,
@@ -990,7 +1006,8 @@ end
local create_admin_panel_token = Token.register(create_admin_panel)
local admin_functions = {
local admin_functions =
{
['jail'] = jail,
['mute'] = mute,
['free'] = free,
@@ -1003,7 +1020,8 @@ local admin_functions = {
['go_to_player'] = go_to_player
}
local admin_global_functions = {
local admin_global_functions =
{
['turn_off_global_speakers'] = turn_off_global_speakers,
['delete_all_blueprints'] = delete_all_blueprints,
['pause_game_tick'] = pause_game_tick,
@@ -1217,13 +1235,14 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Admin')
end
)
function Public.contains_text(history, search_text, target_player_name)
local antigrief = AntiGrief.get()
local history_index = {
local history_index =
{
['Capsule History'] = antigrief.capsule_history,
['Message History'] = antigrief.message_history,
['Friendly Fire History'] = antigrief.friendly_fire_history,

View File

@@ -13,9 +13,12 @@ local module_name = Gui.uid_name()
local Public = {}
local this = {
gui_config = {
spaghett = {
local this =
{
gui_config =
{
spaghett =
{
undo = {}
},
poll_trusted = false
@@ -29,7 +32,8 @@ Global.register(
end
)
local spaghett_entity_blacklist = {
local spaghett_entity_blacklist =
{
['requester-chest'] = true,
['buffer-chest'] = true,
['active-chest-provider'] = true
@@ -118,7 +122,8 @@ local function trust_connected_players()
end
end
local functions = {
local functions =
{
['spectator_switch'] = function (event)
if event.element.switch_state == 'left' then
game.get_player(event.player_index).spectator = true
@@ -243,7 +248,8 @@ local functions = {
end
}
local poll_function = {
local poll_function =
{
['poll_trusted_toggle'] = function (event)
if event.element.switch_state == 'left' then
this.gui_config.poll_trusted = true
@@ -264,7 +270,8 @@ local poll_function = {
end
}
local antigrief_functions = {
local antigrief_functions =
{
['disable_antigrief'] = function (event)
local AG = Antigrief.get()
if event.element.switch_state == 'left' then
@@ -278,7 +285,8 @@ local antigrief_functions = {
end
}
local fortress_functions = {
local fortress_functions =
{
['disable_fullness'] = function (event)
local Fullness = is_loaded('modules.check_fullness')
local Module = Fullness.get()
@@ -431,7 +439,8 @@ local fortress_functions = {
end
}
local pirates_functions = {
local pirates_functions =
{
['toggle_disband'] = function (event)
local players = game.players
local Memory = storage.tokens.maps_pirates_memory
@@ -501,7 +510,8 @@ local function build_config_gui(data)
frame.clear()
local scroll_pane =
frame.add {
frame.add
{
type = 'scroll-pane',
horizontal_scroll_policy = 'never'
}
@@ -892,7 +902,7 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Config')
end
)

View File

@@ -9,10 +9,12 @@ local Color = require 'utils.color_presets'
local module_name = Gui.uid_name()
local this = {
local this =
{
player_group = {},
join_spam_protection = {},
tag_groups = {
tag_groups =
{
['Miner'] = { name = 'Miner', founder = 'script', description = '[img=item/electric-mining-drill]', static = true },
['Smeltery'] = { name = 'Smeltery', founder = 'script', description = '[img=item/stone-furnace]', static = true },
['Power'] = { name = 'Power', founder = 'script', description = '[img=item/big-electric-pole]', static = true },
@@ -50,11 +52,12 @@ local function build_group_gui(data)
local t = frame.add({ type = 'table', column_count = 5 })
local headings = {
{ { 'gui.title' }, group_name_width },
local headings =
{
{ { 'gui.title' }, group_name_width },
{ { 'gui.description' }, description_width },
{ { 'gui.members' }, members_width * member_columns },
{ '', actions_width }
{ { 'gui.members' }, members_width * member_columns },
{ '', actions_width }
}
for _, h in pairs(headings) do
local l = t.add({ type = 'label', caption = h[1] })
@@ -123,7 +126,8 @@ local function build_group_gui(data)
for _, p in pairs(game.connected_players) do
if group.name == this.player_group[p.name] then
l = ttt.add({ type = 'label', caption = p.name })
color = {
color =
{
r = p.color.r * 0.6 + 0.4,
g = p.color.g * 0.6 + 0.4,
b = p.color.b * 0.6 + 0.4,
@@ -303,12 +307,14 @@ local function on_gui_click(event)
return
end
this.tag_groups[new_group_name] = {
this.tag_groups[new_group_name] =
{
name = new_group_name,
description = new_group_description,
founder = player.name
}
local color = {
local color =
{
r = player.color.r * 0.7 + 0.3,
g = player.color.g * 0.7 + 0.3,
b = player.color.b * 0.7 + 0.3,
@@ -345,7 +351,8 @@ local function on_gui_click(event)
str = str .. ']'
player.tag = str
if game.tick - this.join_spam_protection[player.name] > 600 then
local color = {
local color =
{
r = player.color.r * 0.7 + 0.3,
g = player.color.g * 0.7 + 0.3,
b = player.color.b * 0.7 + 0.3,
@@ -417,7 +424,7 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Groups')
end
)

View File

@@ -88,14 +88,16 @@ function Public.get_score(player)
end
function Public.reset_score()
storage.custom_highscore = {
storage.custom_highscore =
{
description = 'Won rounds:',
score_list = {}
}
end
local function on_init()
storage.custom_highscore = {
storage.custom_highscore =
{
description = 'Won rounds:',
score_list = {}
}
@@ -107,7 +109,7 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Map Scores')
end
)

View File

@@ -380,7 +380,7 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, tag)
end
)

View File

@@ -9,7 +9,8 @@ local Token = require 'utils.token'
local format_number = require 'util'.format_number
local Public = {}
local this = {
local this =
{
score_table = {},
sort_by = {}
}
@@ -24,7 +25,8 @@ Global.register(
)
local sorting_symbol = { ascending = '', descending = '' }
local building_and_mining_blacklist = {
local building_and_mining_blacklist =
{
['tile-ghost'] = true,
['entity-ghost'] = true,
['item-entity'] = true
@@ -35,7 +37,8 @@ function Public.get_table()
end
function Public.reset_tbl()
this.score_table['player'] = {
this.score_table['player'] =
{
players = {}
}
end
@@ -50,7 +53,8 @@ function Public.init_player_table(player, reset)
local tbl_force = this.score_table[player.force.name]
if reset then
tbl_force.players[player.name] = {
tbl_force.players[player.name] =
{
built_entities = 0,
deaths = 0,
killscore = 0,
@@ -70,7 +74,8 @@ function Public.init_player_table(player, reset)
if not player.name then return end
if not tbl_force.players[player.name] then
tbl_force.players[player.name] = {
tbl_force.players[player.name] =
{
built_entities = 0,
deaths = 0,
killscore = 0,
@@ -103,7 +108,8 @@ local function get_score_list(force)
end
local function get_sorted_list(method, column_name, score_list)
local comparators = {
local comparators =
{
['ascending'] = function (a, b)
return a[column_name] < b[column_name]
end,
@@ -115,7 +121,8 @@ local function get_sorted_list(method, column_name, score_list)
return score_list
end
local biters = {
local biters =
{
'small-biter',
'medium-biter',
'big-biter',
@@ -178,13 +185,14 @@ local function show_score(data)
local t = frame.add { type = 'table', column_count = 6 }
-- Score headers
local headers = {
{ name = 'score_player', caption = 'Player' },
{ column = 'killscore', name = 'score_killscore', caption = 'Killscore' },
{ column = 'deaths', name = 'score_deaths', caption = 'Deaths' },
local headers =
{
{ name = 'score_player', caption = 'Player' },
{ column = 'killscore', name = 'score_killscore', caption = 'Killscore' },
{ column = 'deaths', name = 'score_deaths', caption = 'Deaths' },
{ column = 'built_entities', name = 'score_built_entities', caption = 'Built structures' },
{ column = 'mined_entities', name = 'score_mined_entities', caption = 'Mined entities' },
{ column = 'crafted_items', name = 'score_crafted_items', caption = 'Crafted Items' }
{ column = 'crafted_items', name = 'score_crafted_items', caption = 'Crafted Items' }
}
local sorting_pref = this.sort_by[player.name]
@@ -199,7 +207,8 @@ local function show_score(data)
-- Header
local label =
t.add {
t.add
{
type = 'label',
caption = cap,
name = header.name
@@ -234,14 +243,16 @@ local function show_score(data)
-- Score entries
for _, entry in pairs(score_list) do
local p = game.players[entry.name or ''] or { color = { r = 0.6, g = 0.6, b = 0.6 } }
local special_color = {
local special_color =
{
r = p.color.r * 0.6 + 0.4,
g = p.color.g * 0.6 + 0.4,
b = p.color.b * 0.6 + 0.4,
a = 1
}
local lines = {
{ caption = entry.name, color = special_color },
local lines =
{
{ caption = entry.name, color = special_color },
{ caption = format_number(tonumber(entry.killscore), true) },
{ caption = format_number(tonumber(entry.deaths), true) },
{ caption = format_number(tonumber(entry.built_entities), true) },
@@ -252,7 +263,8 @@ local function show_score(data)
for _, column in ipairs(lines) do
local label =
column_table.add {
column_table.add
{
type = 'label',
caption = column.caption,
color = column.color or default_color
@@ -262,7 +274,7 @@ local function show_score(data)
label.style.maximal_width = 125
label.style.horizontal_align = 'center'
end -- foreach column
end -- foreach entry
end -- foreach entry
end
local show_score_token = Token.register(show_score)
@@ -304,7 +316,8 @@ local function on_gui_click(event)
end
-- Handles click on a score header
local element_to_column = {
local element_to_column =
{
['score_killscore'] = 'killscore',
['score_deaths'] = 'deaths',
['score_built_entities'] = 'built_entities',
@@ -335,7 +348,8 @@ local function on_rocket_launched()
refresh_score_full()
end
local entity_score_values = {
local entity_score_values =
{
['behemoth-biter'] = 100,
['behemoth-spitter'] = 100,
['behemoth-worm-turret'] = 300,
@@ -366,7 +380,8 @@ local function train_type_cause(event)
return players
end
local kill_causes = {
local kill_causes =
{
['character'] = function (event)
if not event.cause.player then
return
@@ -500,7 +515,7 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Scoreboard')
end
)

View File

@@ -10,7 +10,8 @@ local Public = {}
local module_name = Gui.uid_name()
local ignored_stats = {
local ignored_stats =
{
['name'] = true,
['tick'] = true
}
@@ -31,7 +32,8 @@ local function show_score(data)
end
local label =
t.add {
t.add
{
type = 'label',
caption = tooltip
}
@@ -66,7 +68,8 @@ local function show_score(data)
if stat and type(stat) == 'number' then
c = format_number(stat, true)
end
local lines = {
local lines =
{
{ caption = normalized_names[name] and normalized_names[name].name or name, tooltip = normalized_names[name].tooltip or '' },
{ caption = c }
}
@@ -74,7 +77,8 @@ local function show_score(data)
for _, column in ipairs(lines) do
local l =
column_table.add {
column_table.add
{
type = 'label',
caption = column.caption,
tooltip = column.tooltip,
@@ -97,7 +101,7 @@ Gui.on_click(
module_name,
function (event)
local player = event.player
Gui.reload_active_tab(player)
Gui.reload_active_tab(player, nil, 'Statistics')
end
)

View File

@@ -3,6 +3,7 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Core = require 'utils.core'
local round = math.round
@@ -57,21 +58,6 @@ local modifiers =
[12] = 'character_running_speed_modifier'
}
local function check_inventory_size_limit(player, modifier, value)
if not player or not player.valid then
return
end
if player.character ~= nil then
local total = player.character.character_inventory_slots_bonus + player.force.character_inventory_slots_bonus
if total >= this.rpg_inventory_slot_limit then
player[modifier] = this.rpg_inventory_slot_limit
else
player[modifier] = round(value, 4)
end
end
end
function Public.update_player_modifiers(player)
local player_modifiers = this.modifiers[player.index]
if not player_modifiers then
@@ -92,11 +78,7 @@ function Public.update_player_modifiers(player)
if disabled_modifiers and disabled_modifiers[k] then
player[modifier] = 0
else
if modifiers[k] == 'character_inventory_slots_bonus' and not this.creative_enabled then
check_inventory_size_limit(player, modifier, sum_value)
else
player[modifier] = round(sum_value, 4)
end
player[modifier] = round(sum_value, 4)
end
end
end
@@ -104,26 +86,26 @@ end
function Public.update_single_modifier(player, modifier, category, value)
local player_modifiers = this.modifiers[player.index]
if not player_modifiers then
if not player_modifiers or not modifier then
return
end
if not modifier then
return
end
for k, _ in pairs(player_modifiers) do
if modifiers[k] == modifier and player_modifiers[k] then
for key, _ in pairs(player_modifiers) do
if modifiers[key] == modifier and player_modifiers[key] then
local current_modifier = player_modifiers[key]
if category then
if value then
if modifiers[k] == 'character_inventory_slots_bonus' and not this.creative_enabled then
check_inventory_size_limit(player, modifier, value)
if modifiers[key] == 'character_inventory_slots_bonus' and not this.creative_enabled then
current_modifier[category] = math.min(value, this.rpg_inventory_slot_limit)
else
player_modifiers[k][category] = value
current_modifier[category] = value
end
else
player_modifiers[k][category] = nil
current_modifier[category] = nil
end
else
player_modifiers[k] = value
player_modifiers[key] = value
end
end
end
@@ -235,4 +217,10 @@ Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_respawned, on_player_respawned)
Event.add(defines.events.on_player_removed, on_player_removed)
Event.on_nth_tick(60, function ()
Core.iter_connected_players(function (player)
Public.update_player_modifiers(player)
end)
end)
return Public