Migrate all commands to new lib

This commit is contained in:
Cooldude2606
2024-11-08 12:59:46 +00:00
parent c9bf85835f
commit 4b6872c14c
103 changed files with 2415 additions and 3694 deletions

View File

@@ -1,60 +0,0 @@
--[[-- Addon Lawnmower
- Adds a command that clean up biter corpse and nuclear hole
@addon Lawnmower
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local config = require("modules.exp_legacy.config.lawnmower") --- @dep config.lawnmower
require("modules.exp_legacy.config.expcore.command_general_parse")
Commands.new_command("lawnmower", "Clean up biter corpse, decoratives and nuclear hole")
:add_param("range", false, "integer-range", 1, 200)
:register(function(player, range)
local tile_to_do = {}
-- Intentionally left as player.position to allow use in remote view
player.surface.destroy_decoratives{ position = player.position, radius = range }
local entities = player.surface.find_entities_filtered{ position = player.position, radius = range, type = "corpse" }
for _, entity in pairs(entities) do
if (entity.name ~= "transport-caution-corpse" and entity.name ~= "invisible-transport-caution-corpse") then
entity.destroy()
end
end
local tiles = player.surface.find_tiles_filtered{ position = player.position, radius = range, name = { "nuclear-ground" } }
for _, tile in pairs(tiles) do
table.insert(tile_to_do, { name = "grass-1", position = tile.position })
end
player.surface.set_tiles(tile_to_do)
return Commands.success
end)
local function destroy_decoratives(entity)
if entity.type ~= "entity-ghost" and entity.type ~= "tile-ghost" and entity.prototype.selectable_in_game then
entity.surface.destroy_decoratives{ area = entity.selection_box }
end
end
if config.destroy_decoratives then
Event.add(defines.events.on_built_entity, function(event)
destroy_decoratives(event.created_entity)
end)
Event.add(defines.events.on_robot_built_entity, function(event)
destroy_decoratives(event.created_entity)
end)
Event.add(defines.events.script_raised_built, function(event)
destroy_decoratives(event.entity)
end)
Event.add(defines.events.script_raised_revive, function(event)
destroy_decoratives(event.entity)
end)
end

View File

@@ -1,28 +0,0 @@
--[[-- Commands Module - Admin Chat
- Adds a command that allows admins to talk in a private chat
@commands Admin-Chat
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common
require("modules.exp_legacy.config.expcore.command_general_parse")
--- Sends a message in chat that only admins can see
-- @command admin-chat
-- @tparam string message the message to send in the admin chat
Commands.new_command("admin-chat", { "expcom-admin-chat.description" }, "Sends a message in chat that only admins can see.")
:add_param("message", false)
:enable_auto_concat()
:set_flag("admin_only")
:add_alias("ac")
:register(function(player, message)
local player_name_colour = format_player_name(player)
for _, return_player in pairs(game.connected_players) do
if return_player.admin then
return_player.print{ "expcom-admin-chat.format", player_name_colour, message }
end
end
return Commands.success -- prevents command complete message from showing
end)

View File

@@ -1,88 +0,0 @@
--[[-- Commands Module - Admin Markers
- Adds a command that creates map markers which can only be edited by admins
@commands Admin-Markers
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Storage = require("modules/exp_util/storage")
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local admins = {} -- Stores all players in admin marker mode
local markers = {} -- Stores all admin markers
--- Storage variables
Storage.register({
admins = admins,
markers = markers,
}, function(tbl)
admins = tbl.admins
markers = tbl.markers
end)
--- Toggle admin marker mode, can only be applied to yourself
-- @command admin-marker
Commands.new_command("admin-marker", { "expcom-admin-marker.description" }, "Toggles admin marker mode, new markers can only be edited by admins")
:set_flag("admin_only")
:add_alias("am", "admin-markers")
:register(function(player)
if admins[player.name] then
-- Exit admin mode
admins[player.name] = nil
return Commands.success{ "expcom-admin-marker.exit" }
else
-- Enter admin mode
admins[player.name] = true
return Commands.success{ "expcom-admin-marker.enter" }
end
end)
--- Listen for new map markers being added, add admin marker if done by player in admin mode
Event.add(defines.events.on_chart_tag_added, function(event)
if not event.player_index then return end
local player = game.players[event.player_index]
if not admins[player.name] then return end
local tag = event.tag
markers[tag.force.name .. tag.tag_number] = true
Commands.print({ "expcom-admin-marker.place" }, nil, player)
end)
--- Listen for players leaving the game, leave admin mode to avoid unexpected admin markers
Event.add(defines.events.on_player_left_game, function(event)
if not event.player_index then return end
local player = game.players[event.player_index]
admins[player.name] = nil
end)
--- Listen for tags being removed or edited, maintain tags edited by non admins
local function maintain_tag(event)
local tag = event.tag
if not event.player_index then return end
if not markers[tag.force.name .. tag.tag_number] then return end
local player = game.players[event.player_index]
if player.admin then
-- Player is admin, tell them it was an admin marker
Commands.print({ "expcom-admin-marker.edit" }, nil, player)
elseif event.name == defines.events.on_chart_tag_modified then
-- Tag was modified, revert the changes
tag.text = event.old_text
tag.last_user = event.old_player
if event.old_icon then tag.icon = event.old_icon end
player.play_sound{ path = "utility/wire_pickup" }
Commands.print({ "expcom-admin-marker.revert" }, nil, player)
else
-- Tag was removed, remake the tag
player.play_sound{ path = "utility/wire_pickup" }
Commands.print({ "expcom-admin-marker.revert" }, "orange_red", player)
local new_tag = tag.force.add_chart_tag(tag.surface, {
last_user = tag.last_user,
position = tag.position,
icon = tag.icon,
text = tag.text,
})
markers[tag.force.name .. tag.tag_number] = nil
markers[new_tag.force.name .. new_tag.tag_number] = true
end
end
Event.add(defines.events.on_chart_tag_modified, maintain_tag)
Event.add(defines.events.on_chart_tag_removed, maintain_tag)

View File

@@ -1,81 +0,0 @@
--[[-- Commands Module - Artillery
- Adds a command that help shot artillery
@commands Artillery
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection
local SelectionArtyArea = "ArtyArea"
local function location_break(player, pos)
-- Intentionally left as player.surface to allow use in remote view
if player.force.is_chunk_charted(player.surface, { x = math.floor(pos.left_top.x / 32), y = math.floor(pos.left_top.y / 32) }) then
return true
elseif player.force.is_chunk_charted(player.surface, { x = math.floor(pos.left_top.x / 32), y = math.floor(pos.right_bottom.y / 32) }) then
return true
elseif player.force.is_chunk_charted(player.surface, { x = math.floor(pos.right_bottom.x / 32), y = math.floor(pos.left_top.y / 32) }) then
return true
elseif player.force.is_chunk_charted(player.surface, { x = math.floor(pos.right_bottom.x / 32), y = math.floor(pos.right_bottom.y / 32) }) then
return true
else
return false
end
end
--- align an aabb to the grid by expanding it
local function aabb_align_expand(aabb)
return {
left_top = { x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y) },
right_bottom = { x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y) },
}
end
--- when an area is selected to add protection to the area
Selection.on_selection(SelectionArtyArea, function(event)
local area = aabb_align_expand(event.area)
local player = game.players[event.player_index]
if player == nil then
return
end
if not (game.players[event.player_index].cheat_mode or location_break(player, event.area)) then
return Commands.error
end
local count = 0
local hit = {}
for _, e in pairs(player.surface.find_entities_filtered{ area = area, type = { "unit-spawner", "turret" }, force = "enemy" }) do
local skip = false
for _, pos in ipairs(hit) do
if math.sqrt(math.abs(e.position.x - pos.x) ^ 2 + math.abs(e.position.y - pos.y) ^ 2) < 6 then
skip = true
break
end
end
if not skip then
player.surface.create_entity{ name = "artillery-flare", position = e.position, force = player.force, life_time = 240, movement = { 0, 0 }, height = 0, vertical_speed = 0, frame_speed = 0 }
table.insert(hit, e.position)
count = count + 1
if count > 400 then
break
end
end
end
end)
Commands.new_command("artillery-target-remote", { "expcom-artillery.description" }, "Artillery Target Remote")
:register(function(player)
if Selection.is_selecting(player, SelectionArtyArea) then
Selection.stop(player)
else
Selection.start(player, SelectionArtyArea)
end
return Commands.success
end)

View File

@@ -1,25 +0,0 @@
--[[-- Commands Module - Bot queue
- Adds a command that allows changing bot queue
@commands Bot Queue
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
Commands.new_command("bot-queue-get", { "expcom-bot-queue.description-get" }, "Get bot queue")
:set_flag("admin_only")
:register(function(player)
local s = player.force.max_successful_attempts_per_tick_per_construction_queue
local f = player.force.max_failed_attempts_per_tick_per_construction_queue
return Commands.success{ "expcom-bot-queue.result", player.name, s, f }
end)
Commands.new_command("bot-queue-set", { "expcom-bot-queue.description-set" }, "Set bot queue")
:add_param("amount", "integer-range", 1, 20)
:set_flag("admin_only")
:register(function(player, amount)
player.force.max_successful_attempts_per_tick_per_construction_queue = 3 * amount
player.force.max_failed_attempts_per_tick_per_construction_queue = 1 * amount
game.print{ "expcom-bot-queue.result", player.name, 3 * amount, 1 * amount }
return Commands.success
end)

View File

@@ -1,46 +0,0 @@
--[[-- Commands Module - Cheat Mode
- Adds a command that allows players to enter cheat mode
@commands Cheat-Mode
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
--- Toggles cheat mode for your player, or another player.
-- @command toggle-cheat-mode
-- @tparam[opt=self] LuaPlayer player player to toggle chest mode of, can be nil for self
Commands.new_command("toggle-cheat-mode", { "expcom-cheat.description-cheat" }, "Toggles cheat mode for your player, or another player.")
:add_param("player", true, "player")
:set_defaults{ player = function(player)
return player -- default is the user using the command
end }
:set_flag("admin_only")
:register(function(_, player)
player.cheat_mode = not player.cheat_mode
return Commands.success
end)
Commands.new_command("research-all", { "expcom-cheat.description-res" }, "Set all research for your force.")
:set_flag("admin_only")
:add_param("force", true, "force")
:set_defaults{ force = function(player)
return player.force
end }
:register(function(player, force)
force.research_all_technologies()
game.print{ "expcom-cheat.res", player.name }
return Commands.success
end)
Commands.new_command("toggle-always-day", { "expcom-cheat.description-day" }, "Toggles always day in surface.")
:set_flag("admin_only")
:add_param("surface", true, "surface")
:set_defaults{ surface = function(player)
-- Intentionally left as player.surface to allow use in remote view
return player.surface
end }
:register(function(player, surface)
surface.always_day = not surface.always_day
game.print{ "expcom-cheat.day", player.name, surface.always_day }
return Commands.success
end)

View File

@@ -1,28 +0,0 @@
--[[-- Commands Module - Clear Inventory
- Adds a command that allows admins to clear people's inventorys
@commands Clear-Inventory
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_role_parse")
--- Clears a players inventory
-- @command clear-inventory
-- @tparam LuaPlayer player the player to clear the inventory of
Commands.new_command("clear-inventory", { "expcom-clr-inv.description" }, "Clears a players inventory")
:add_param("player", false, "player-role")
:add_alias("clear-inv", "move-inventory", "move-inv")
:register(function(_, player)
local inventory = player.get_main_inventory()
if not inventory then
return Commands.error{ "expcore-commands.reject-player-alive" }
end
ExpUtil.transfer_inventory_to_surface{
inventory = inventory,
surface = game.planets.nauvis.surface,
name = "iron-chest",
allow_creation = true,
}
end)

View File

@@ -1,107 +0,0 @@
--[[-- Commands Module - Connect
- Adds a commands that allows you to request a player move to another server
@commands Connect
]]
local Async = require("modules/exp_util/async")
local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_role_parse")
local concat = table.concat
local request_connection_async = Async.register(External.request_connection)
local function get_server_id(server)
local current_server = External.get_current_server()
local current_version = current_server.version
local servers = External.get_servers_filtered(server)
local server_names_before, server_names = {}, {}
local server_count_before, server_count = 0, 0
for next_server_id, server_details in pairs(servers) do
server_count_before = server_count_before + 1
server_names_before[server_count_before] = server_details.name
if server_details.version == current_version then
server_count = server_count + 1
server_names[server_count] = server_details.name
else
servers[next_server_id] = nil
end
end
if server_count > 1 then
return false, Commands.error{ "expcom-connect.too-many-matching", concat(server_names, ", ") }
elseif server_count == 1 then
local server_id, server_details = next(servers)
local status = External.get_server_status(server_id)
if server_id == current_server.id then
return false, Commands.error{ "expcom-connect.same-server", server_details.name }
elseif status == "Offline" then
return false, Commands.error{ "expcom-connect.offline", server_details.name }
end
return true, server_id
elseif server_count_before > 0 then
return false, Commands.error{ "expcom-connect.wrong-version", concat(server_names_before, ", ") }
else
return false, Commands.error{ "expcom-connect.none-matching" }
end
end
--- Connect to a different server
-- @command connect
-- @tparam string server The address or name of the server to connect to
-- @tparam[opt=false] boolean is_address If an address was given for the server param
Commands.new_command("connect", { "expcom-connect.description" }, "Connect to another server")
:add_param("server")
:add_param("is_address", true, "boolean")
:add_alias("join", "server")
:register(function(player, server, is_address)
local server_id = server
if not is_address and External.valid() then
local success, new_server_id = get_server_id(server)
if not success then return new_server_id end
server_id = new_server_id
end
request_connection_async(player, server_id, true)
end)
--- Connect a player to a different server
-- @command connect-player
-- @tparam string address The address or name of the server to connect to
-- @tparam LuaPlayer player The player to connect to a different server
-- @tparam[opt=false] boolean is_address If an address was given for the server param
Commands.new_command("connect-player", { "expcom-connect.description-player" }, "Send a player to a different server")
:add_param("player", "player-role")
:add_param("server")
:add_param("is_address", true, "boolean")
:register(function(_, player, server, is_address)
local server_id = server
if not is_address and External.valid() then
local success, new_server_id = get_server_id(server)
if not success then return new_server_id end
server_id = new_server_id
end
External.request_connection(player, server_id)
end)
--- Connect all players to a different server
-- @command connect-all
-- @tparam string address The address or name of the server to connect to
-- @tparam[opt=false] boolean is_address If an address was given for the server param
Commands.new_command("connect-all", { "expcom-connect.description-all" }, "Connect all players to another server")
:add_param("server")
:add_param("is_address", true, "boolean")
:register(function(_, server, is_address)
local server_id = server
if not is_address and External.valid() then
local success, new_server_id = get_server_id(server)
if not success then return new_server_id end
server_id = new_server_id
end
for _, player in pairs(game.connected_players) do
External.request_connection(player, server_id)
end
end)

View File

@@ -1,14 +0,0 @@
--[[-- Commands Module - Debug
- Adds a command that opens the debug frame
@commands Debug
]]
local DebugView = require("modules.exp_legacy.modules.gui.debug.main_view") --- @dep modules.gui.debug.main_view
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
--- Opens the debug pannel for viewing tables.
-- @command debug
Commands.new_command("debug", { "expcom-debug.description" }, "Opens the debug pannel for viewing tables.")
:register(function(player)
DebugView.open_dubug(player)
end)

View File

@@ -1,30 +0,0 @@
--[[-- Commands Module - Enemy
- Adds a command of handling enemy
@commands Enemy
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
Commands.new_command("kill-biters", { "expcom-enemy.description-kill" }, "Kill all biters only")
:set_flag("admin_only")
:register(function(_, _)
game.forces["enemy"].kill_all_units()
return Commands.success
end)
Commands.new_command("remove-biters", { "expcom-enemy.description-remove" }, "Remove biters and prevent generation")
:set_flag("admin_only")
:add_param("surface", true, "surface")
:set_defaults{ surface = function(player)
-- Intentionally left as player.surface to allow use in remote view
return player.surface
end }
:register(function(_, surface)
for _, entity in pairs(surface.find_entities_filtered{ force = "enemy" }) do
entity.destroy()
end
surface.map_gen_settings.autoplace_controls["enemy-base"].size = "none"
return Commands.success
end)

View File

@@ -1,19 +0,0 @@
--[[-- Commands Module - Find
- Adds a command that zooms in on the given player
@commands Find
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
--- Find a player on your map.
-- @command find-on-map
-- @tparam LuaPlayer the player to find on the map
Commands.new_command("find-on-map", { "expcom-find.description" }, "Find a player on your map.")
:add_param("player", false, "player-online")
:add_alias("find", "zoom-to")
:register(function(player, action_player)
local position = action_player.physical_position
player.zoom_to_world(position, 1.75)
return Commands.success -- prevents command complete message from showing
end)

View File

@@ -1,19 +0,0 @@
--[[-- Commands Module - Toggle Friendly Fire
- Adds a command that toggle all friendly fire
@commands Toggle Friendly Fire
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
-- For Modded Server Use
Commands.new_command("toggle-friendly-fire", { "expcom-ff.description" }, "Toggle friendly fire")
:add_param("force", true, "force")
:set_defaults{ force = function(player)
return player.force
end }
:register(function(player, force)
force.friendly_fire = not force.friendly_fire
game.print{ "expcom-ff.ff", player.name, force.friendly_fire }
return Commands.success
end)

View File

@@ -1,95 +0,0 @@
--[[-- Commands Module - Help
- Adds a better help command that allows searching of descriotions and names
@commands Help
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Storage = require("modules/exp_util/storage")
require("modules.exp_legacy.config.expcore.command_general_parse")
local results_per_page = 5
local search_cache = {}
Storage.register(search_cache, function(tbl)
search_cache = tbl
end)
--- Searches for a keyword in all commands you are allowed to use.
-- @command chelp
-- @tparam string keyword the keyword that will be looked for
-- @tparam number page the page of help to view, must be in range of pages
Commands.new_command("search-help", { "expcom-chelp.description" }, "Searches for a keyword in all commands you are allowed to use.")
:add_alias("chelp", "shelp", "commands")
:add_param("keyword", true)
:add_param("page", true, "integer")
:set_defaults{ keyword = "", page = 1 }
:register(function(player, keyword, page)
local player_index = player and player.index or 0
-- if keyword is a number then treat it as page number
if tonumber(keyword) then
--- @diagnostic disable-next-line: param-type-mismatch
page = math.floor(tonumber(keyword))
keyword = ""
end
-- gets a value for pages, might have result in cache
local pages
local found = 0
if search_cache[player_index] and search_cache[player_index].keyword == keyword:lower() then
pages = search_cache[player_index].pages
found = search_cache[player_index].found
else
pages = { {} }
local current_page = 1
local page_count = 0
local commands = Commands.search(keyword, player)
-- loops other all commands returned by search, includes game commands
for _, command_data in pairs(commands) do
-- if the number of results if greater than the number already added then it moves onto a new page
if page_count >= results_per_page then
page_count = 0
current_page = current_page + 1
table.insert(pages, {})
end
-- adds the new command to the page
page_count = page_count + 1
found = found + 1
local alias_format = #command_data.aliases > 0 and { "expcom-chelp.alias", table.concat(command_data.aliases, ", ") } or ""
table.insert(pages[current_page], {
"expcom-chelp.format",
command_data.name,
command_data.description,
command_data.help,
alias_format,
})
end
-- adds the result to the cache
search_cache[player_index] = {
keyword = keyword:lower(),
pages = pages,
found = found,
}
end
-- print the requested page
keyword = keyword == "" and "<all>" or keyword
Commands.print({ "expcom-chelp.title", keyword }, "cyan")
if pages[page] then
for _, command in pairs(pages[page]) do
Commands.print(command)
end
Commands.print({ "expcom-chelp.footer", found, page, #pages }, "cyan")
else
Commands.print({ "expcom-chelp.footer", found, page, #pages }, "cyan")
return Commands.error{ "expcom-chelp.out-of-range", page }
end
-- blocks command complete message
return Commands.success
end)
-- way to access global
return search_cache

View File

@@ -1,83 +0,0 @@
--[[-- Commands Module - Home
- Adds a command that allows setting and teleporting to your home position
@commands Home
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Storage = require("modules/exp_util/storage")
require("modules.exp_legacy.config.expcore.command_general_parse")
local homes = {}
Storage.register(homes, function(tbl)
homes = tbl
end)
local function teleport(player, position)
local surface = player.physical_surface
local pos = surface.find_non_colliding_position("character", position, 32, 1)
if not position then return false end
if player.driving then player.driving = false end -- kicks a player out a vehicle if in one
player.teleport(pos, surface)
return true
end
local function floor_pos(position)
return {
x = math.floor(position.x),
y = math.floor(position.y),
}
end
--- Teleports you to your home location
-- @command home
Commands.new_command("home", { "expcom-home.description-home" }, "Teleports you to your home location")
:register(function(player)
local home = homes[player.index]
if not home or not home[1] then
return Commands.error{ "expcom-home.no-home" }
end
local rtn = floor_pos(player.physical_position)
teleport(player, home[1])
home[2] = rtn
Commands.print{ "expcom-home.return-set", rtn.x, rtn.y }
end)
--- Sets your home location to your current position
-- @command home-set
Commands.new_command("home-set", { "expcom-home.description-home-set" }, "Sets your home location to your current position")
:register(function(player)
local home = homes[player.index]
if not home then
home = {}
homes[player.index] = home
end
local pos = floor_pos(player.physical_position)
home[1] = pos
Commands.print{ "expcom-home.home-set", pos.x, pos.y }
end)
--- Returns your current home location
-- @command home-get
Commands.new_command("home-get", { "expcom-home.description-home-get" }, "Returns your current home location")
:register(function(player)
local home = homes[player.index]
if not home or not home[1] then
return Commands.error{ "expcom-home.no-home" }
end
local pos = home[1]
Commands.print{ "expcom-home.home-get", pos.x, pos.y }
end)
--- Teleports you to previous location
-- @command return
Commands.new_command("return", { "expcom-home.description-return" }, "Teleports you to previous location")
:register(function(player)
local home = homes[player.index]
if not home or not home[2] then
return Commands.error{ "expcom-home.no-return" }
end
local rtn = floor_pos(player.physical_position)
teleport(player, home[2])
home[2] = rtn
Commands.print{ "expcom-home.return-set", rtn.x, rtn.y }
end)

View File

@@ -1,117 +0,0 @@
--[[-- Commands Module - Interface
- Adds a command that acts as a direct link to the the active softmod, for debug use
@commands Interface
]]
local ExpUtil = require("modules/exp_util")
local Storage = require("modules/exp_util/storage")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
-- modules that are loaded into the interface env to be accessed
local interface_modules = {
["Commands"] = Commands,
["output"] = Commands.print,
["Group"] = "modules.exp_legacy.expcore.permission_groups",
["Roles"] = "modules.exp_legacy.expcore.roles",
["Gui"] = "modules.exp_legacy.expcore.gui",
["Datastore"] = "modules.exp_legacy.expcore.datastore",
["External"] = "modules.exp_legacy.expcore.external",
}
-- loads all the modules given in the above table
for key, value in pairs(interface_modules) do
if type(value) == "string" then
interface_modules[key] = ExpUtil.optional_require(value)
end
end
local interface_env = {} -- used as a persistent sandbox for interface commands
local interface_callbacks = {} -- saves callbacks which can load new values per use
Storage.register(interface_env, function(tbl)
interface_env = tbl
end)
--- Adds a static module that can be accessed with the interface
-- @tparam string name The name that the value is assigned to
-- @tparam any value The value that will be accessible in the interface env
-- callback param - player: LuaPlayer - the player who used the command
local function add_interface_module(name, value)
interface_modules[name] = value
end
--- Adds a dynamic value that is calculated when the interface is used
-- @tparam string name The name that the value is assigned to
-- @tparam function callback The function that will be called to get the value
local function add_interface_callback(name, callback)
if type(callback) == "function" then
interface_callbacks[name] = callback
end
end
--- Internal, this is a meta function for __index when self[key] is nil
local function get_index(_, key)
if interface_env[key] then
return interface_env[key]
elseif interface_modules[key] then
return interface_modules[key]
elseif _G[key] then
return _G[key]
end
end
--- Sends an invocation to be ran and returns the result.
-- @command interface
-- @tparam string invocation the command that will be run
Commands.new_command("interface", { "expcom-interface.description" }, "Sends an invocation to be ran and returns the result.")
:add_param("invocation", false)
:enable_auto_concat()
:set_flag("admin_only")
:register(function(player, invocation)
-- If the invocation has no white space then prepend return to it
if not invocation:find("%s") and not invocation:find("return") then
invocation = "return " .. invocation
end
-- _env will be the new _ENV that the invocation will run inside of
local _env = setmetatable({}, {
__index = get_index,
__newindex = interface_env,
})
-- If the command is ran by a player then load the dynamic values
if player then
for name, callback in pairs(interface_callbacks) do
local _, rtn = pcall(callback, player)
rawset(_env, name, rtn)
end
end
-- Compile the invocation with the custom _env value
local invocation_func, compile_error = load(invocation, "interface", nil, _env)
if compile_error then return Commands.error(compile_error) end
--- @cast invocation_func -nil
-- Run the invocation
local success, rtn = pcall(invocation_func)
if not success then
local err = rtn:gsub("%.%.%..-/temp/currently%-playing", "")
return Commands.error(err)
end
return Commands.success(rtn)
end)
-- Adds some basic callbacks for the interface
add_interface_callback("player", function(player) return player end)
add_interface_callback("surface", function(player) return player.surface end)
add_interface_callback("force", function(player) return player.force end)
add_interface_callback("position", function(player) return player.position end)
add_interface_callback("entity", function(player) return player.selected end)
add_interface_callback("tile", function(player) return player.surface.get_tile(player.position) end)
-- Module Return
return {
add_interface_module = add_interface_module,
add_interface_callback = add_interface_callback,
interface_env = interface_env,
clean_stack_trace = function(str) return str:gsub("%.%.%..-/temp/currently%-playing", "") end,
}

View File

@@ -1,48 +0,0 @@
--[[-- Commands Module - Jail
- Adds a commands that allow admins to jail and unjail
@commands Jail
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common
require("modules.exp_legacy.config.expcore.command_role_parse")
--- Puts a player into jail and removes all other roles.
-- @command jail
-- @tparam LuaPlayer player the player that will be jailed
-- @tparam[opt] string reason the reason why the player is being jailed
Commands.new_command("jail", { "expcom-jail.description-jail" }, "Puts a player into jail and removes all other roles.")
:add_param("player", false, "player-role")
:add_param("reason", true)
:enable_auto_concat()
:register(function(player, action_player, reason)
reason = reason or "Non Given."
local action_player_name_color = format_player_name(action_player)
local by_player_name_color = format_player_name(player)
local player_name = player and player.name or "<server>"
if Jail.jail_player(action_player, player_name, reason) then
game.print{ "expcom-jail.give", action_player_name_color, by_player_name_color, reason }
else
return Commands.error{ "expcom-jail.already-jailed", action_player_name_color }
end
end)
--- Removes a player from jail.
-- @command unjail
-- @tparam LuaPlayer the player that will be unjailed
Commands.new_command("unjail", { "expcom-jail.description-unjail" }, "Removes a player from jail.")
:add_param("player", false, "player-role")
:add_alias("clear-jail", "remove-jail")
:enable_auto_concat()
:register(function(player, action_player)
local action_player_name_color = format_player_name(action_player)
local by_player_name_color = format_player_name(player)
local player_name = player and player.name or "<server>"
if Jail.unjail_player(action_player, player_name) then
game.print{ "expcom-jail.remove", action_player_name_color, by_player_name_color }
else
return Commands.error{ "expcom-jail.not-jailed", action_player_name_color }
end
end)

View File

@@ -1,34 +0,0 @@
--[[-- Commands Module - Kill
- Adds a command that allows players to kill them selfs and others
@commands Kill
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
require("modules.exp_legacy.config.expcore.command_general_parse")
require("modules.exp_legacy.config.expcore.command_role_parse")
--- Kills yourself or another player.
-- @command kill
-- @tparam[opt=self] LuaPlayer player the player to kill, must be alive to be valid
Commands.new_command("kill", { "expcom-kill.description" }, "Kills yourself or another player.")
:add_param("player", true, "player-role-alive")
:set_defaults{ player = function(player)
-- default is the player unless they are dead
if player.character and player.character.health > 0 then
return player
end
end }
:register(function(player, action_player)
if not action_player then
-- can only be nil if no player given and the user is dead
return Commands.error{ "expcom-kill.already-dead" }
end
if player == action_player then
action_player.character.die()
elseif Roles.player_allowed(player, "command/kill/always") then
action_player.character.die()
else
return Commands.error{ "expcore-commands.unauthorized" }
end
end)

View File

@@ -1,20 +0,0 @@
--[[-- Commands Module - Last location
- Adds a command that will return the last location of a player
@commands LastLocation
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common
require("modules.exp_legacy.config.expcore.command_general_parse")
--- Get the last location of a player.
-- @command last-location
-- @tparam LuaPlayer player the player that you want a location of
Commands.new_command("last-location", { "expcom-lastlocation.description" }, "Sends you the last location of a player")
:add_alias("location")
:add_param("player", false, "player")
:register(function(_, action_player)
local action_player_name_color = format_player_name(action_player)
return Commands.success{ "expcom-lastlocation.response", action_player_name_color, string.format("%.1f", action_player.physical_position.x), string.format("%.1f", action_player.physical_position.y) }
end)

View File

@@ -1,17 +0,0 @@
--[[-- Commands Module - Me
- Adds a command that adds * around your message in the chat
@commands Me
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
--- Sends an action message in the chat
-- @command me
-- @tparam string action the action that follows your name in chat
Commands.new_command("me", { "expcom-me.description" }, "Sends an action message in the chat")
:add_param("action", false)
:enable_auto_concat()
:register(function(player, action)
local player_name = player and player.name or "<Server>"
game.print(string.format("* %s %s *", player_name, action), player.chat_color)
end)

View File

@@ -1,35 +0,0 @@
--[[-- Commands Module - Pollution Handle
- Adds a command that allows modifying pollution
@commands Pollution Handle
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
Commands.new_command("pollution-clear", { "expcom-pol.description-clr" }, "Clear pollution")
:set_flag("admin_only")
:add_alias("pol-clr")
:add_param("surface", true, "surface")
:set_defaults{ surface = function(player)
-- Intentionally left as player.surface to allow use in remote view
return player.surface
end }
:register(function(player, surface)
surface.clear_pollution()
game.print{ "expcom-pol.clr", player.name }
return Commands.success
end)
Commands.new_command("pollution-off", { "expcom-pol.description-off" }, "Disable pollution")
:set_flag("admin_only")
:add_alias("pol-off")
:register(function(player)
game.map_settings.pollution.enabled = false
for _, v in pairs(game.surfaces) do
v.clear_pollution()
end
game.print{ "expcom-pol.off", player.name }
return Commands.success
end)

View File

@@ -1,222 +0,0 @@
--[[-- Commands Module - Protection
- Adds commands that can add and remove protection
@commands Protection
]]
local ExpUtil = require("modules/exp_util")
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Storage = require("modules/exp_util/storage")
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common
local EntityProtection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection
local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection
local SelectionProtectEntity = "ProtectEntity"
local SelectionProtectArea = "ProtectArea"
local renders = {} -- Stores all renders for a player
Storage.register({
renders = renders,
}, function(tbl)
renders = tbl.renders
end)
--- Test if a point is inside an aabb
local function aabb_point_enclosed(point, aabb)
return point.x >= aabb.left_top.x and point.y >= aabb.left_top.y
and point.x <= aabb.right_bottom.x and point.y <= aabb.right_bottom.y
end
--- Test if an aabb is inside another aabb
local function aabb_area_enclosed(aabb_one, aabb_two)
return aabb_point_enclosed(aabb_one.left_top, aabb_two)
and aabb_point_enclosed(aabb_one.right_bottom, aabb_two)
end
--- Align an aabb to the grid by expanding it
local function aabb_align_expand(aabb)
return {
left_top = { x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y) },
right_bottom = { x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y) },
}
end
--- Get the key used in protected_entities
local function get_entity_key(entity)
return string.format("%i,%i", math.floor(entity.position.x), math.floor(entity.position.y))
end
--- Get the key used in protected_areas
local function get_area_key(area)
return string.format("%i,%i", math.floor(area.left_top.x), math.floor(area.left_top.y))
end
--- Show a protected entity to a player
local function show_protected_entity(player, entity)
local key = get_entity_key(entity)
if renders[player.index][key] then return end
local rb = entity.selection_box.right_bottom
local render_id = rendering.draw_sprite{
sprite = "utility/notification",
target = entity,
target_offset = {
(rb.x - entity.position.x) * 0.75,
(rb.y - entity.position.y) * 0.75,
},
x_scale = 2,
y_scale = 2,
surface = entity.surface,
players = { player },
}
renders[player.index][key] = render_id
end
--- Show a protected area to a player
local function show_protected_area(player, surface, area)
local key = get_area_key(area)
if renders[player.index][key] then return end
local render_id = rendering.draw_rectangle{
color = { 1, 1, 0, 0.5 },
filled = false,
width = 3,
left_top = area.left_top,
right_bottom = area.right_bottom,
surface = surface,
players = { player },
}
renders[player.index][key] = render_id
end
--- Remove a render object for a player
local function remove_render(player, key)
local render = renders[player.index][key] --[[@as LuaRenderObject]]
if render and render.valid then render.destroy() end
renders[player.index][key] = nil
end
--- Toggles entity protection selection
-- @command protect-entity
Commands.new_command("protect-entity", { "expcom-protection.description-pe" }, "Toggles entity protection selection, hold shift to remove protection")
:add_alias("pe")
:register(function(player)
if Selection.is_selecting(player, SelectionProtectEntity) then
Selection.stop(player)
else
Selection.start(player, SelectionProtectEntity)
return Commands.success{ "expcom-protection.entered-entity-selection" }
end
end)
--- Toggles area protection selection
-- @command protect-area
Commands.new_command("protect-area", { "expcom-protection.description-pa" }, "Toggles area protection selection, hold shift to remove protection")
:add_alias("pa")
:register(function(player)
if Selection.is_selecting(player, SelectionProtectArea) then
Selection.stop(player)
else
Selection.start(player, SelectionProtectArea)
return Commands.success{ "expcom-protection.entered-area-selection" }
end
end)
--- When an area is selected to add protection to entities
Selection.on_selection(SelectionProtectEntity, function(event)
local player = game.players[event.player_index]
for _, entity in ipairs(event.entities) do
EntityProtection.add_entity(entity)
show_protected_entity(player, entity)
end
player.print{ "expcom-protection.protected-entities", #event.entities }
end)
--- When an area is selected to remove protection from entities
Selection.on_alt_selection(SelectionProtectEntity, function(event)
local player = game.players[event.player_index]
for _, entity in ipairs(event.entities) do
EntityProtection.remove_entity(entity)
remove_render(player, get_entity_key(entity))
end
player.print{ "expcom-protection.unprotected-entities", #event.entities }
end)
--- When an area is selected to add protection to the area
Selection.on_selection(SelectionProtectArea, function(event)
local area = aabb_align_expand(event.area)
local areas = EntityProtection.get_areas(event.surface)
local player = game.players[event.player_index]
for _, next_area in pairs(areas) do
if aabb_area_enclosed(area, next_area) then
return player.print{ "expcom-protection.already-protected" }
end
end
EntityProtection.add_area(event.surface, area)
show_protected_area(player, event.surface, area)
player.print{ "expcom-protection.protected-area" }
end)
--- When an area is selected to remove protection from the area
Selection.on_alt_selection(SelectionProtectArea, function(event)
local area = aabb_align_expand(event.area)
local areas = EntityProtection.get_areas(event.surface)
local player = game.players[event.player_index]
for _, next_area in pairs(areas) do
if aabb_area_enclosed(next_area, area) then
EntityProtection.remove_area(event.surface, next_area)
player.print{ "expcom-protection.unprotected-area" }
remove_render(player, get_area_key(next_area))
end
end
end)
--- When selection starts show all protected entities and protected areas
Event.add(Selection.events.on_player_selection_start, function(event)
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end
local player = game.players[event.player_index]
-- Intentionally left as player.surface to allow use in remote view
local surface = player.surface
renders[player.index] = {}
-- Show protected entities
local entities = EntityProtection.get_entities(surface)
for _, entity in pairs(entities) do
show_protected_entity(player, entity)
end
-- Show always protected entities by name
if #EntityProtection.protected_entity_names > 0 then
for _, entity in pairs(surface.find_entities_filtered{ name = EntityProtection.protected_entity_names, force = player.force }) do
show_protected_entity(player, entity)
end
end
-- Show always protected entities by type
if #EntityProtection.protected_entity_types > 0 then
for _, entity in pairs(surface.find_entities_filtered{ type = EntityProtection.protected_entity_types, force = player.force }) do
show_protected_entity(player, entity)
end
end
-- Show protected areas
local areas = EntityProtection.get_areas(surface)
for _, area in pairs(areas) do
show_protected_area(player, surface, area)
end
end)
--- When selection ends hide protected entities and protected areas
Event.add(Selection.events.on_player_selection_end, function(event)
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end
for _, render in pairs(renders[event.player_index]) do
if render.valid then render.destroy() end
end
renders[event.player_index] = nil
end)
--- When there is a repeat offence print it in chat
Event.add(EntityProtection.events.on_repeat_violation, function(event)
local player_name = format_player_name(event.player_index)
Roles.print_to_roles_higher("Regular", { "expcom-protection.repeat-offence", player_name, event.entity.localised_name, event.entity.position.x, event.entity.position.y })
end)

View File

@@ -1,63 +0,0 @@
--[[-- Commands Module - Rainbow
- Adds a command that prints your message in rainbow font
@commands Rainbow
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local format_chat_colour = ExpUtil.format_rich_text_color --- @dep expcore.common
local function step_component(c1, c2)
if c1 < 0 then
return 0, c2 + c1
elseif c1 > 1 then
return 1, c2 - c1 + 1
else
return c1, c2
end
end
local function step_color(color)
color.r, color.g = step_component(color.r, color.g)
color.g, color.b = step_component(color.g, color.b)
color.b, color.r = step_component(color.b, color.r)
color.r = step_component(color.r, 0)
return color
end
local function next_color(color, step)
step = step or 0.1
local new_color = { r = 0, g = 0, b = 0 }
if color.b == 0 and color.r ~= 0 then
new_color.r = color.r - step
new_color.g = color.g + step
elseif color.r == 0 and color.g ~= 0 then
new_color.g = color.g - step
new_color.b = color.b + step
elseif color.g == 0 and color.b ~= 0 then
new_color.b = color.b - step
new_color.r = color.r + step
end
return step_color(new_color)
end
--- Sends an rainbow message in the chat
-- @command rainbow
-- @tparam string message the message that will be printed in chat
Commands.new_command("rainbow", { "expcom-rainbow.description" }, "Sends an rainbow message in the chat")
:add_param("message", false)
:enable_auto_concat()
:register(function(player, message)
local player_name = player and player.name or "<Server>"
local player_color = player and player.color or nil
local color_step = 3 / message:len()
if color_step > 1 then color_step = 1 end
local current_color = { r = 1, g = 0, b = 0 }
local output = format_chat_colour(player_name .. ": ", player_color)
output = output .. message:gsub("%S", function(letter)
local rtn = format_chat_colour(letter, current_color)
current_color = next_color(current_color, color_step)
return rtn
end)
game.print(output)
end)

View File

@@ -1,83 +0,0 @@
local Commands = require("modules.exp_legacy.expcore.commands")
local function Modules(moduleInventory) -- returns the multiplier of the modules
local effect1 = moduleInventory.get_item_count("productivity-module") -- type 1
local effect2 = moduleInventory.get_item_count("productivity-module-2") -- type 2
local effect3 = moduleInventory.get_item_count("productivity-module-3") -- type 3
local multi = effect1 * 4 + effect2 * 6 + effect3 * 10
return multi / 100 + 1
end
local function AmountOfMachines(itemsPerSecond, output)
if (itemsPerSecond) then
return itemsPerSecond / output
end
end
Commands.new_command("ratio", { "expcom-ratio.description" },
"This command will give the input and output ratios of the selected machine. Use the parameter for calculating the machines needed for that amount of items per second.")
:add_param("itemsPerSecond", true, "number")
:register(function(player, itemsPerSecond)
local machine = player.selected -- selected machine
if not machine then -- nil check
return Commands.error{ "expcom-ratio.notSelecting" }
end
if machine.type ~= "assembling-machine" and machine.type ~= "furnace" then
return Commands.error{ "expcom-ratio.notSelecting" }
end
local recipe = machine.get_recipe() -- recipe
if not recipe then -- nil check
return Commands.error{ "expcom-ratio.notSelecting" }
end
local items = recipe.ingredients -- items in that recipe
local products = recipe.products -- output items
local amountOfMachines
local moduleInventory = machine.get_module_inventory() -- the module Inventory of the machine
local multi = Modules(moduleInventory) -- function for the productively modals
if itemsPerSecond then
amountOfMachines = math.ceil(AmountOfMachines(itemsPerSecond, 1 / recipe.energy * machine.crafting_speed * products[1].amount * multi)) -- amount of machines
end
if not amountOfMachines then
amountOfMachines = 1 -- set to 1 to make it not nil
end
----------------------------items----------------------------
for i, item in ipairs(items) do
local sprite -- string to make the icon work either fluid ore item
if item.type == "item" then
sprite = "expcom-ratio.item-in"
else
sprite = "expcom-ratio.fluid-in"
end
local ips = item.amount / recipe.energy * machine.crafting_speed * amountOfMachines -- math on the items/fluids per second
Commands.print{ sprite, math.round(ips, 3), item.name } -- full string
end
----------------------------products----------------------------
for i, product in ipairs(products) do
local sprite -- string to make the icon work either fluid ore item
if product.type == "item" then
sprite = "expcom-ratio.item-out"
else
sprite = "expcom-ratio.fluid-out"
end
local output = 1 / recipe.energy * machine.crafting_speed * product.amount * multi -- math on the outputs per second
Commands.print{ sprite, math.round(output * amountOfMachines, 3), product.name } -- full string
end
if amountOfMachines ~= 1 then
Commands.print{ "expcom-ratio.machines", amountOfMachines }
end
end)

View File

@@ -1,54 +0,0 @@
--[[-- Commands Module - Repair
- Adds a command that allows an admin to repair and revive a large area
@commands Repair
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local config = require("modules.exp_legacy.config.repair") --- @dep config.repair
require("modules.exp_legacy.config.expcore.command_general_parse")
local max_time_to_live = 4294967295 -- unit32 max
--- Repairs entities on your force around you
-- @command repair
-- @tparam number range the range to repair stuff in, there is a max limit to this
Commands.new_command("repair", { "expcom-repair.description" }, "Repairs entities on your force around you")
:add_param("range", false, "integer-range", 1, config.max_range)
:register(function(player, range)
local revive_count = 0
local heal_count = 0
local range2 = range ^ 2
-- Intentionally left as player.surface to allow use in remote view
local surface = player.surface
-- Intentionally left as player.position to allow use in remote view
local center = player.position
local area = { { x = center.x - range, y = center.y - range }, { x = center.x + range, y = center.y + range } }
if config.allow_ghost_revive then
local ghosts = surface.find_entities_filtered{ area = area, type = "entity-ghost", force = player.force }
for _, ghost in pairs(ghosts) do
if ghost.valid then
local x = ghost.position.x - center.x
local y = ghost.position.y - center.y
if x ^ 2 + y ^ 2 <= range2 then
if config.allow_blueprint_repair or ghost.time_to_live ~= max_time_to_live then
revive_count = revive_count + 1
if not config.disallow[ghost.ghost_name] then ghost.revive() end
end
end
end
end
end
if config.allow_heal_entities then
local entities = surface.find_entities_filtered{ area = area, force = player.force }
for _, entity in pairs(entities) do
if entity.valid then
local x = entity.position.x - center.x
local y = entity.position.y - center.y
if entity.health and entity.get_health_ratio() ~= 1 and x ^ 2 + y ^ 2 <= range2 then
heal_count = heal_count + 1
entity.health = max_time_to_live
end
end
end
end
return Commands.success{ "expcom-repair.result", revive_count, heal_count }
end)

View File

@@ -1,99 +0,0 @@
--[[-- Commands Module - Reports
- Adds a commands that allow players to report other players
@commands Reports
]]
local ExpUtil = require("modules/exp_util")
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common
require("modules.exp_legacy.config.expcore.command_general_parse")
--- Print a message to all players who match the value of admin
local function print_to_players(admin, message)
for _, player in ipairs(game.connected_players) do
if player.admin == admin then
player.print(message)
end
end
end
--- Reports a player and notifies moderators
-- @command report
-- @tparam LuaPlayer player the player to report, some players are immune
-- @tparam string reason the reason the player is being reported
Commands.new_command("report", { "expcom-report.description-report" }, "Reports a player and notifies moderators")
:add_param("player", false, function(input, player, reject)
input = Commands.parse("player", input, player, reject)
if not input then return end
if Roles.player_has_flag(input, "report-immune") then
return reject{ "expcom-report.player-immune" }
elseif player == input then
return reject{ "expcom-report.self-report" }
else
return input
end
end)
:add_param("reason", false)
:add_alias("report-player")
:enable_auto_concat()
:register(function(player, action_player, reason)
local action_player_name_color = format_player_name(action_player)
local by_player_name_color = format_player_name(player)
if Reports.report_player(action_player, player.name, reason) then
print_to_players(false, { "expcom-report.non-admin", action_player_name_color, reason })
print_to_players(true, { "expcom-report.admin", action_player_name_color, by_player_name_color, reason })
else
return Commands.error{ "expcom-report.already-reported" }
end
end)
--- Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.
-- @command get-reports
-- @tparam LuaPlayer player the player to get the report for
Commands.new_command("get-reports", { "expcom-report.description-get-reports" },
"Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.")
:add_param("player", true, "player")
:add_alias("reports", "list-reports")
:register(function(_, player)
if player then
local reports = Reports.get_reports(player)
local player_name_color = format_player_name(player)
Commands.print{ "expcom-report.player-report-title", player_name_color }
for player_name, reason in pairs(reports) do
local by_player_name_color = format_player_name(player_name)
Commands.print{ "expcom-report.list", by_player_name_color, reason }
end
else
local user_reports = Reports.user_reports
Commands.print{ "expcom-report.player-count-title" }
for player_name in pairs(user_reports) do
local player_name_color = format_player_name(player_name)
local report_count = Reports.count_reports(player_name)
Commands.print{ "expcom-report.list", player_name_color, report_count }
end
end
end)
--- Clears all reports from a player or just the report from one player.
-- @command clear-reports
-- @tparam LuaPlayer player the player to clear the report(s) from
-- @tparam[opt=all] LuaPlayer from-player remove only the report made by this player
Commands.new_command("clear-reports", { "expcom-report.description-clear-reports" }, "Clears all reports from a player or just the report from one player.")
:add_param("player", false, "player")
:add_param("from-player", true, "player")
:register(function(player, action_player, from_player)
if from_player then
if not Reports.remove_report(action_player, from_player.name, player.name) then
return Commands.error{ "expcom-report.not-reported" }
end
else
if not Reports.remove_all(action_player, player.name) then
return Commands.error{ "expcom-report.not-reported" }
end
end
local action_player_name_color = format_player_name(action_player)
local by_player_name_color = format_player_name(player)
game.print{ "expcom-report.removed", action_player_name_color, by_player_name_color }
end)

View File

@@ -1,45 +0,0 @@
local Storage = require("modules/exp_util/storage")
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local config = require("modules.exp_legacy.config.research") --- @dep config.research
local research = {}
Storage.register(research, function(tbl)
research = tbl
end)
local function res_queue(force, by_script)
local res_q = force.research_queue
local res = force.technologies["mining-productivity-4"]
if #res_q < config.queue_amount then
for i = 1, config.queue_amount - #res_q do
force.add_research(res)
if not (by_script) then
game.print{ "expcom-res.inf-q", res.name, res.level + i }
end
end
end
end
Commands.new_command("auto-research", { "expcom-res.description-ares" }, "Automatically queue up research")
:add_alias("ares")
:register(function(player)
research.res_queue_enable = not research.res_queue_enable
if research.res_queue_enable then
res_queue(player.force, true)
end
game.print{ "expcom-res.res", player.name, research.res_queue_enable }
return Commands.success
end)
Event.add(defines.events.on_research_finished, function(event)
if research.res_queue_enable then
if event.research.force.rockets_launched > 0 and event.research.force.technologies["mining-productivity-4"].level > 4 then
res_queue(event.research.force, event.by_script)
end
end
end)

View File

@@ -1,80 +0,0 @@
--[[-- Commands Module - Roles
- Adds a commands that allow interaction with the role system
@commands Roles
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Colours = require("modules/exp_util/include/color")
local format_player_name, format_color = ExpUtil.format_player_name_locale, ExpUtil.format_rich_text_color
--- Assigns a role to a player
-- @command assign-role
-- @tparam LuaPlayer player the player to assign the role to
-- @tparam string role the name of the role to assign to the player, supports auto complete after enter
Commands.new_command("assign-role", { "expcom-roles.description-assign-role" }, "Assigns a role to a player")
:add_param("player", false, "player-role")
:add_param("role", false, "role")
:set_flag("admin-only")
:add_alias("rpromote", "assign", "role", "add-role")
:register(function(player, action_player, role)
local player_highest = Roles.get_player_highest_role(player)
if player_highest.index < role.index then
Roles.assign_player(action_player, role, player.name)
else
return Commands.error{ "expcom-roles.higher-role" }
end
end)
--- Unassigns a role from a player
-- @command unassign-role
-- @tparam LuaPlayer player the player to unassign the role from
-- @tparam string role the name of the role to unassign from the player, supports auto complete after enter
Commands.new_command("unassign-role", { "expcom-roles.description-unassign-role" }, "Unassigns a role from a player")
:add_param("player", false, "player-role")
:add_param("role", false, "role")
:set_flag("admin-only")
:add_alias("rdemote", "unassign", "rerole", "remove-role")
:register(function(player, action_player, role)
local player_highest = Roles.get_player_highest_role(player)
if player_highest.index < role.index then
Roles.unassign_player(action_player, role, player.name)
else
return Commands.error{ "expcom-roles.higher-role" }
end
end)
--- Lists all roles in they correct order
-- @command list-roles
-- @tparam[opt=all] LuaPlayer player list only the roles which this player has
Commands.new_command("list-roles", { "expcom-roles.description-list-roles" }, "Lists all roles in they correct order")
:add_param("player", true, "player")
:add_alias("lsroles", "roles")
:register(function(_, player)
local roles = Roles.config.order
local message = { "expcom-roles.list" }
if player then
roles = Roles.get_player_roles(player)
end
for index, role in pairs(roles) do
role = Roles.get_role_from_any(role)
local colour = role.custom_color or Colours.white
local role_name = format_color(role.name, colour)
if index == 1 then
message = { "expcom-roles.list", role_name }
if player then
local player_name_colour = format_player_name(player)
message = { "expcom-roles.list-player", player_name_colour, role_name }
end
else
message = { "expcom-roles.list-element", message, role_name }
end
end
return Commands.success(message)
end)

View File

@@ -1,170 +0,0 @@
--[[-- Commands Module - Inventory Search
- Adds commands that will search all players inventories for an item
@commands InventorySearch
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local format_number = require("util").format_number --- @dep util
local format_player_name = ExpUtil.format_player_name_locale
require("modules.exp_legacy.config.expcore.command_general_parse")
--- Input parse for items by name
local function item_parse(input, _, reject)
if input == nil then return end
local lower_input = input:lower():gsub(" ", "-")
-- Simple Case - internal name is given
local item = prototypes.item[lower_input]
if item then return item end
-- Second Case - rich text is given
local item_name = input:match("%[item=([0-9a-z-]+)%]")
item = prototypes.item[item_name]
if item then return item end
-- No item found, we do not attempt to search all prototypes as this will be expensive
return reject{ "expcom-inv-search.reject-item", lower_input }
end
--- Search all players for this item
local function search_players(players, item)
local head = 1
local found = {}
-- Check the item count of all players
for _, player in pairs(players) do
local item_count = player.get_item_count(item.name)
if item_count > 0 then
-- Add the player to the array as they have the item
found[head] = { player = player, count = item_count, online_time = player.online_time }
head = head + 1
end
end
return found
end
--- Custom sort function which only retains 5 greatest values
local function sort_players(players, func)
local sorted = {}
local values = {}
local threshold = nil
-- Loop over all provided players
for index, player in ipairs(players) do
local value = func(player)
-- Check if the item will make the top 5 elements
if index <= 5 or value > threshold then
local inserted = false
values[player] = value
-- Find where in the top 5 to insert the element
for next_index, next_player in ipairs(sorted) do
if value > values[next_player] then
table.insert(sorted, next_index, player)
inserted = true
break
end
end
-- Insert the element, this can only be called when index <= 5
if not inserted then
sorted[#sorted + 1] = player
end
-- Update the threshold
if sorted[6] then
threshold = values[sorted[5]]
values[sorted[6]] = nil
sorted[6] = nil
else
threshold = values[sorted[#sorted]]
end
end
end
return sorted
end
local display_players_time_format = ExpUtil.format_time_factory_locale{ format = "short", hours = true, minutes = true }
--- Display to the player the top players which were found
local function display_players(player, players, item)
player.print{ "expcom-inv-search.results-heading", item.name }
for index, data in ipairs(players) do
local player_name_color = format_player_name(data.player)
local amount = format_number(data.count)
local time = display_players_time_format(data.online_time)
player.print{ "expcom-inv-search.results-item", index, player_name_color, amount, time }
end
end
--- Return the amount of an item a player has
local function amount_sort(data)
return data.count
end
--- Get a list of players sorted by the quantity of an item in their inventory
-- @command search-amount
-- @tparam LuaItemPrototype item The item to search for in players inventories
Commands.new_command("search-amount", { "expcom-inv-search.description-ia" }, "Display players sorted by the quantity of an item held")
:add_alias("ia")
:add_param("item", false, item_parse)
:enable_auto_concat()
:register(function(player, item)
local players = search_players(game.players, item)
if #players == 0 then return { "expcom-inv-search.results-none", item.name } end
local top_players = sort_players(players, amount_sort)
display_players(player, top_players, item)
end)
--- Return the index of the player, higher means they joined more recently
local function recent_sort(data)
return data.player.index
end
--- Get a list of players who have the given item, sorted by how recently they joined
-- @command search-recent
-- @tparam LuaItemPrototype item The item to search for in players inventories
Commands.new_command("search-recent", { "expcom-inv-search.description-ir" }, "Display players who hold an item sorted by join time")
:add_alias("ir")
:add_param("item", false, item_parse)
:enable_auto_concat()
:register(function(player, item)
local players = search_players(game.players, item)
if #players == 0 then return { "expcom-inv-search.results-none", item.name } end
local top_players = sort_players(players, recent_sort)
display_players(player, top_players, item)
end)
--- Return the the amount of an item a player has divided by their playtime
local function combined_sort(data)
return data.count / data.online_time
end
--- Get a list of players sorted by quantity held and play time
-- @command search
-- @tparam LuaItemPrototype item The item to search for in players inventories
Commands.new_command("search", { "expcom-inv-search.description-i" }, "Display players sorted by the quantity of an item held and playtime")
:add_alias("i")
:add_param("item", false, item_parse)
:enable_auto_concat()
:register(function(player, item)
local players = search_players(game.players, item)
if #players == 0 then return { "expcom-inv-search.results-none", item.name } end
local top_players = sort_players(players, combined_sort)
display_players(player, top_players, item)
end)
--- Get a list of online players sorted by quantity held and play time
-- @command search-online
-- @tparam LuaItemPrototype item The item to search for in players inventories
Commands.new_command("search-online", { "expcom-inv-search.description-io" }, "Display online players sorted by the quantity of an item held and playtime")
:add_alias("io")
:add_param("item", false, item_parse)
:enable_auto_concat()
:register(function(player, item)
local players = search_players(game.connected_players, item)
if #players == 0 then return { "expcom-inv-search.results-none", item.name } end
local top_players = sort_players(players, combined_sort)
display_players(player, top_players, item)
end)

View File

@@ -1,66 +0,0 @@
--[[-- Commands Module - Spawn
- Adds a command that allows players to teleport to their spawn point
@commands Spawn
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local function teleport(player)
local surface = player.surface
local spawn = player.force.get_spawn_position(surface)
local position = surface.find_non_colliding_position("character", spawn, 32, 1)
-- return false if no new position
if not position then
return false
end
if player.vehicle then
-- Teleport the entity
local entity = player.vehicle
local goto_position = surface.find_non_colliding_position(entity.name, position, 32, 1)
-- Surface teleport can only be done for players and cars at the moment. (with surface as an peramitor it gives this error)
if entity.type == "car" then
entity.teleport(goto_position, surface)
elseif surface.index == entity.surface.index then
-- Try teleport the entity
if not entity.teleport(goto_position) then
player.driving = false
player.teleport(position, surface)
end
end
else
-- Teleport the player
player.teleport(position, surface)
end
return true
end
--- Teleport to spawn
-- @command go-to-spawn
-- @tparam[opt=self] LuaPlayer player the player to teleport to their spawn point
Commands.new_command("go-to-spawn", { "expcom-spawn.description" }, "Teleport to spawn")
:add_param("player", true, "player-role-alive")
:set_defaults{
player = function(player)
if player.connected and player.character and player.character.health > 0 then
return player
end
end,
}
:add_alias("spawn", "tp-spawn")
:register(function(player, action_player)
if not action_player then
return Commands.error{ "expcom-spawn.unavailable" }
elseif action_player == player then
if not teleport(player) then
return Commands.error{ "expcom-spawn.unavailable" }
end
elseif Roles.player_allowed(player, "command/go-to-spawn/always") then
if not teleport(action_player) then
return Commands.error{ "expcom-spawn.unavailable" }
end
else
return Commands.error{ "expcore-commands.unauthorized" }
end
end)

View File

@@ -1,33 +0,0 @@
--[[-- Commands Module - Spectate
- Adds commands relating to spectate and follow
@commands Spectate
]]
local Spectate = require("modules.exp_legacy.modules.control.spectate") --- @dep modules.control.spectate
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
--- Toggles spectator mode for the caller
-- @command spectate
Commands.new_command("spectate", { "expcom-spectate.description-spectate" }, "Toggles spectator mode")
:register(function(player)
if Spectate.is_spectating(player) then
Spectate.stop_spectate(player)
else
Spectate.start_spectate(player)
end
end)
--- Enters follow mode for the caller, following the given player.
-- @command follow
-- @tparam LuaPlayer player The player that will be followed
Commands.new_command("follow", { "expcom-spectate.description-follow" }, "Start following a player in spectator")
:add_alias("f")
:add_param("player", false, "player-online")
:register(function(player, action_player)
if player == action_player then
return Commands.error{ "expcom-spectate.follow-self" }
else
Spectate.start_follow(player, action_player)
end
end)

View File

@@ -1,16 +0,0 @@
--[[-- Commands Module - Set game speed
- Adds a command that allows changing game speed
@commands Set game speed
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
Commands.new_command("game-speed", { "expcom-speed.description" }, "Set game speed")
:add_param("amount", "number-range", 0.2, 8)
:set_flag("admin_only")
:register(function(player, amount)
game.speed = math.round(amount, 3)
game.print{ "expcom-speed.result", player.name, string.format("%.3f", amount) }
return Commands.success
end)

View File

@@ -1,41 +0,0 @@
--[[-- Commands Module - Clear Item On Ground
- Adds a command that clear item on ground so blueprint can deploy safely
@commands Clear Item On Ground
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
Commands.new_command("clear-item-on-ground", { "expcom-surface-clearing.description-ci" }, "Clear Item On Ground")
:add_param("range", false, "integer-range", 1, 1000)
:register(function(player, range)
local items = {} --- @type LuaItemStack[]
-- Intentionally left as player.position to allow use in remote view
local entities = player.surface.find_entities_filtered{ position = player.position, radius = range, name = "item-on-ground" }
for _, e in pairs(entities) do
if e.stack then
items[#items + 1] = e.stack
end
end
ExpUtil.move_items_to_surface{
items = items,
surface = player.surface,
allow_creation = true,
name = "iron-chest",
}
return Commands.success
end)
Commands.new_command("clear-blueprint", { "expcom-surface-clearing.description-cb" }, "Clear Blueprint")
:add_param("range", false, "integer-range", 1, 1000)
:register(function(player, range)
-- Intentionally left as player.position to allow use in remote view
for _, e in pairs(player.surface.find_entities_filtered{ position = player.position, radius = range, type = "entity-ghost" }) do
e.destroy()
end
return Commands.success
end)

View File

@@ -1,93 +0,0 @@
--[[-- Commands Module - Teleport
- Adds a command that allows players to teleport to other players
@commands Teleport
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local function teleport(from_player, to_player)
local surface = to_player.physical_surface
local position = surface.find_non_colliding_position("character", to_player.physical_position, 32, 1)
-- return false if no new position
if not position then
return false
end
if from_player.vehicle then
-- Teleport the entity
local entity = from_player.vehicle
local goto_position = surface.find_non_colliding_position(entity.name, position, 32, 1)
-- Surface teleport can only be done for players and cars at the moment. (with surface as an peramitor it gives this error)
if entity.type == "car" then
entity.teleport(goto_position, surface)
elseif surface.index == entity.surface.index then
-- Try teleport the entity
if not entity.teleport(goto_position) then
from_player.driving = false
from_player.teleport(position, surface)
end
end
else
-- Teleport the player
from_player.teleport(position, surface)
end
return true
end
--- Teleports a player to another player.
-- @command teleport
-- @tparam LuaPlayer from_player the player that will be teleported, must be alive
-- @tparam LuaPlayer to_player the player to teleport to, must be online (if dead goes to where they died)
Commands.new_command("teleport", { "expcom-tp.description-tp" }, "Teleports a player to another player.")
:add_param("from_player", false, "player-alive")
:add_param("to_player", false, "player-online")
:add_alias("tp")
:set_flag("admin_only")
:register(function(_, from_player, to_player)
if from_player.index == to_player.index then
-- return if attempting to teleport to self
return Commands.error{ "expcom-tp.to-self" }
end
if not teleport(from_player, to_player) then
-- return if the teleport failed
return Commands.error{ "expcom-tp.no-position-found" }
end
end)
--- Teleports a player to you.
-- @command bring
-- @tparam LuaPlayer player the player that will be teleported, must be alive
Commands.new_command("bring", { "expcom-tp.description-bring" }, "Teleports a player to you.")
:add_param("player", false, "player-alive")
:set_flag("admin_only")
:register(function(player, from_player)
if from_player.index == player.index then
-- return if attempting to teleport to self
return Commands.error{ "expcom-tp.to-self" }
end
if not teleport(from_player, player) then
-- return if the teleport failed
return Commands.error{ "expcom-tp.no-position-found" }
end
from_player.print("Come here my friend")
end)
--- Teleports you to a player.
-- @command goto
-- @tparam LuaPlayer player the player to teleport to, must be online (if dead goes to where they died)
Commands.new_command("goto", { "expcom-tp.description-goto" }, "Teleports you to a player.")
:add_param("player", false, "player-online")
:add_alias("tp-me", "tpme")
:register(function(player, to_player)
if to_player.index == player.index then
-- return if attempting to teleport to self
return Commands.error{ "expcom-tp.to-self" }
end
if not teleport(player, to_player) then
-- return if the teleport failed
return Commands.error{ "expcom-tp.no-position-found" }
end
end)

View File

@@ -1,23 +0,0 @@
--[[-- Commands Module - Set Automatic Train
- Adds a command that set all train back to automatic
@commands Set Automatic Train
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local format_number = require("util").format_number
Commands.new_command("set-trains-to-automatic", { "expcom-train.description" }, "Set All Trains to Automatic")
:register(function(player)
local count = 0
for _, v in pairs(player.force.get_trains()) do
if v.manual_mode then
count = count + 1
v.manual_mode = false
end
end
game.print{ "expcom-train.manual-result", player.name, format_number(count) }
return Commands.success
end)

View File

@@ -1,15 +0,0 @@
--- Adds a virtual layer to store power to save space.
-- @commands Vlayer
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local vlayer = require("modules.exp_legacy.modules.control.vlayer")
Commands.new_command("vlayer-info", { "vlayer.description-vi" }, "Vlayer Info")
:register(function(_)
local c = vlayer.get_circuits()
for k, v in pairs(c) do
Commands.print(v .. " : " .. k)
end
end)

View File

@@ -1,77 +0,0 @@
--[[-- Commands Module - Warnings
- Adds a commands that allow admins to warn other players
@commands Warnings
]]
local ExpUtil = require("modules/exp_util")
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Warnings = require("modules.exp_legacy.modules.control.warnings") --- @dep modules.control.warnings
local format_player_name = ExpUtil.format_player_name_locale
local config = require("modules.exp_legacy.config.warnings") --- @dep config.warnings
require("modules.exp_legacy.config.expcore.command_role_parse")
--- Gives a warning to a player; may lead to automatic script action.
-- @command give-warning
-- @tparam LuaPlayer player the player the will recive a warning
-- @tparam string reason the reason the player is being given a warning
Commands.new_command("give-warning", { "expcom-warnings.description-give" }, "Gives a warning to a player; may lead to automatic script action.")
:add_param("player", false, "player-role")
:add_param("reason", false)
:add_alias("warn")
:enable_auto_concat()
:register(function(player, action_player, reason)
Warnings.add_warning(action_player, player.name, reason)
local action_player_name_color = format_player_name(action_player)
local by_player_name_color = format_player_name(player)
game.print{ "expcom-warnings.received", action_player_name_color, by_player_name_color, reason }
end)
--- Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have.
-- @command get-warnings
-- @tparam[opt=list] LuaPlayer player the player to get the warning for, if nil all players are listed
Commands.new_command("get-warnings", { "expcom-warnings.description-get" }, "Gets the number of warnings a player has. If no player then lists all players and the number of warnings they have.")
:add_param("player", true, "player")
:add_alias("warnings", "list-warnings")
:register(function(_, player)
if player then
local warnings = Warnings.get_warnings(player)
local script_warnings = Warnings.get_script_warnings(player)
local player_name_color = format_player_name(player)
Commands.print{ "expcom-warnings.player", player_name_color, #warnings, #script_warnings, config.temp_warning_limit }
for _, warning in ipairs(warnings) do
Commands.print{ "expcom-warnings.player-detail", format_player_name(warning.by_player_name), warning.reason }
end
else
local rtn = {}
local user_script_warnings = Warnings.user_script_warnings
for player_name, warnings in pairs(Warnings.user_warnings:get_all()) do
rtn[player_name] = { #warnings, 0 }
end
for player_name, warnings in pairs(user_script_warnings) do
if not rtn[player_name] then
rtn[player_name] = { 0, 0 }
end
rtn[player_name][2] = #warnings
end
Commands.print{ "expcom-warnings.list-title" }
for player_name, warnings in pairs(rtn) do
local player_name_color = format_player_name(player_name)
Commands.print{ "expcom-warnings.list", player_name_color, warnings[1], warnings[2], config.temp_warning_limit }
end
end
end)
--- Clears all warnings (and script warnings) from a player
-- @command clear-warnings
-- @tparam LuaPlayer player the player to clear the warnings from
Commands.new_command("clear-warnings", { "expcom-warnings.description-clear" }, "Clears all warnings (and script warnings) from a player")
:add_param("player", false, "player")
:register(function(player, action_player)
Warnings.clear_warnings(action_player, player.name)
Warnings.clear_script_warnings(action_player)
local action_player_name_color = format_player_name(action_player)
local by_player_name_color = format_player_name(player)
game.print{ "expcom-warnings.cleared", action_player_name_color, by_player_name_color }
end)

View File

@@ -1,80 +0,0 @@
--- Adds a waterfill
-- @commands Waterfill
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local Selection = require("modules.exp_legacy.modules.control.selection") --- @dep modules.control.selection
local SelectionConvertArea = "ConvertArea"
--- Align an aabb to the grid by expanding it
local function aabb_align_expand(aabb)
return {
left_top = { x = math.floor(aabb.left_top.x), y = math.floor(aabb.left_top.y) },
right_bottom = { x = math.ceil(aabb.right_bottom.x), y = math.ceil(aabb.right_bottom.y) },
}
end
Commands.new_command("waterfill", { "expcom-waterfill.description" }, "Change tile to water")
:register(function(player)
local inv = player.get_main_inventory()
if (inv.get_item_count("cliff-explosives")) == 0 then
return player.print{ "expcom-waterfill.waterfill-cliff" }
end
if Selection.is_selecting(player, SelectionConvertArea) then
Selection.stop(player)
else
Selection.start(player, SelectionConvertArea)
return Commands.success{ "expcom-waterfill.entered-area-selection" }
end
return Commands.success
end)
--- When an area is selected to add protection to the area
Selection.on_selection(SelectionConvertArea, function(event)
local area = aabb_align_expand(event.area)
local player = game.players[event.player_index]
if not player then
return
end
local entities = event.surface.find_entities_filtered{ area = area, name = "steel-chest" }
if #entities == 0 then
player.print("No steel chest found")
return
end
local tiles_to_make = {}
local inv = player.get_main_inventory()
if not inv then
return
end
local clf_exp = inv.get_item_count("cliff-explosives")
for _, entity in pairs(entities) do
if clf_exp >= 1 then
if entity.get_inventory(defines.inventory.chest).is_empty() then
-- Intentionally left as player.position to allow use in report view
if (math.floor(player.position.x) ~= math.floor(entity.position.x)) or (math.floor(player.position.y) ~= math.floor(entity.position.y)) then
table.insert(tiles_to_make, { name = "water-mud", position = entity.position })
entity.destroy()
else
player.print{ "expcom-waterfill.waterfill-distance" }
end
end
clf_exp = clf_exp - 1
inv.remove{ name = "cliff-explosives", count = 1 }
else
break
end
end
event.surface.set_tiles(tiles_to_make)
end)

View File

@@ -123,8 +123,8 @@ function Selection.is_selecting(player, selection_name)
end
--- Filter on_player_selected_area to this custom selection, appends the selection arguments
-- @tparam string selection_name The name of the selection to listen for
-- @tparam function handler The event handler
-- @param string selection_name The name of the selection to listen for
-- @param function handler The event handler
function Selection.on_selection(selection_name, handler)
Event.add(defines.events.on_player_selected_area, function(event)
local selection = selections[event.player_index]

View File

@@ -31,9 +31,11 @@ WrapData:set_serializer(function(raw_key) return raw_key.warp_id end)
local Warps = {}
--- @class ExpScenario_Warps.force_warps: { spawn: string, [number]: string }
-- Storage lookup table for force name to task ids
local force_warps = { _uid = 1 }
--- @cast force_warps table<string, { spawn: string, [number]: string }>
--- @cast force_warps table<string, ExpScenario_Warps.force_warps>
Storage.register(force_warps, function(tbl)
force_warps = tbl
end)
@@ -61,7 +63,7 @@ WrapData:on_update(function(warp_id, warp, old_warp)
local warp_ids = force_warps[force_name]
local spawn_id = warp_ids.spawn
local warp_names = {}
local warp_names = {} --- @type table<string, string>
for _, next_warp_id in pairs(warp_ids) do
local next_warp = WrapData:get(next_warp_id)
if next_warp_id ~= spawn_id then
@@ -71,6 +73,7 @@ WrapData:on_update(function(warp_id, warp, old_warp)
-- Sort the warp names in alphabetical order
local new_warp_ids = table.get_values(table.key_sort(warp_names))
--- @cast new_warp_ids ExpScenario_Warps.force_warps
table.insert(new_warp_ids, 1, spawn_id)
new_warp_ids.spawn = spawn_id
force_warps[force_name] = new_warp_ids

View File

@@ -6,8 +6,7 @@
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local config = require("modules.exp_legacy.config.bonus") --- @dep config.bonuses
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local Commands = require("modules/exp_commands")
-- Stores the bonus for the player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
@@ -47,19 +46,16 @@ PlayerBonus:on_update(function(player_name, player_bonus)
end)
--- Changes the amount of bonus you receive
-- @command bonus
-- @tparam number amount range 0-10 the increase for your bonus
Commands.new_command("bonus", "Changes the amount of bonus you receive")
:add_param("amount", "integer-range", 0, 10)
Commands.new("bonus", { "bonus.description" })
:optional("amount", { "bonus.arg-amount" }, Commands.types.integer_range(0, 10))
:register(function(player, amount)
if not Roles.player_allowed(player, "command/bonus") then
Commands.print{ "expcom-bonus.perm", 1 }
return
--- @cast amount number?
if amount then
PlayerBonus:set(player, amount)
return Commands.status.success{ "bonus.set", amount }
else
return Commands.status.success{ "bonus.get", PlayerBonus:get(player) }
end
PlayerBonus:set(player, amount)
Commands.print{ "expcom-bonus.set", amount }
end)
--- When a player respawns re-apply bonus

View File

@@ -2,8 +2,7 @@
-- @data Greetings
local config = require("modules.exp_legacy.config.join_messages") --- @dep config.join_messages
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
require("modules.exp_legacy.config.expcore.command_general_parse")
local Commands = require("modules/exp_commands")
--- Stores the join message that the player have
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
@@ -24,20 +23,23 @@ CustomMessages:on_load(function(player_name, player_message)
end)
--- Set your custom join message
-- @command join-message
-- @tparam string message The custom join message that will be used
Commands.new_command("join-message", "Sets your custom join message")
:add_param("message", false, "string-max-length", 255)
:enable_auto_concat()
Commands.new("set-join-message", { "join-message.description-add" })
:optional("message", false, Commands.types.string_max_length(255))
:enable_auto_concatenation()
:add_aliases{ "join-message" }
:register(function(player, message)
if not player then return end
CustomMessages:set(player, message)
return { "join-message.message-set" }
--- @cast message string?
if message then
CustomMessages:set(player, message)
return Commands.status.success{ "join-message.message-set" }
else
return Commands.status.success{ "join-message.message-get", CustomMessages:get(player) }
end
end)
Commands.new_command("join-message-clear", "Clear your join message")
--- Removes your custom join message
Commands.new("remove-join-message", { "join-message.description-remove" })
:register(function(player)
if not player then return end
CustomMessages:remove(player)
return { "join-message.message-cleared" }
return Commands.status.success{ "join-message.message-cleared" }
end)

View File

@@ -1,4 +1,4 @@
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.personal_logistic") --- @dep config.personal-logistic
local function pl(type, target, amount)
@@ -66,21 +66,20 @@ local function pl(type, target, amount)
end
end
Commands.new_command("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)")
:add_param("amount", "integer-range", -1, 10)
:add_alias("pl")
Commands.new("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)")
:argument("amount", "", Commands.types.integer_range(-1, 10))
:add_aliases{ "pl" }
:register(function(player, amount)
--- @cast amount number
if player.force.technologies["logistic-robotics"].researched then
if player.selected ~= nil then
if player.selected.name == "spidertron" then
pl("s", player.selected, amount / 10)
return Commands.success
end
else
pl("p", player, amount / 10)
return Commands.success
end
else
player.print("Personal Logistic not researched")
return Commands.status.error("Personal Logistic not researched")
end
end)

View File

@@ -3,7 +3,7 @@
@data Quickbar
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.preset_player_quickbar") --- @dep config.preset_player_quickbar
--- Stores the quickbar filters for a player
@@ -32,7 +32,7 @@ PlayerFilters:on_load(function(player_name, filters)
end
end)
local ignoredItems = {
local ignored_items = {
["blueprint"] = true,
["blueprint-book"] = true,
["deconstruction-planner"] = true,
@@ -41,9 +41,8 @@ local ignoredItems = {
}
--- Saves your quickbar preset to the script-output folder
-- @command save-quickbar
Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file")
:add_alias("save-toolbar")
Commands.new("save-quickbar", "Saves your Quickbar preset items to file")
:add_aliases{ "save-toolbar" }
:register(function(player)
local filters = {}
@@ -51,7 +50,7 @@ Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file"
local slot = player.get_quick_bar_slot(i)
-- Need to filter out blueprint and blueprint books because the slot is a LuaItemPrototype and does not contain a way to export blueprint data
if slot ~= nil then
local ignored = ignoredItems[slot.name]
local ignored = ignored_items[slot.name]
if ignored ~= true then
filters[i] = slot.name
end
@@ -64,5 +63,5 @@ Commands.new_command("save-quickbar", "Saves your Quickbar preset items to file"
PlayerFilters:remove(player)
end
return { "quickbar.saved" }
return Commands.status.success{ "quickbar.saved" }
end)

View File

@@ -3,11 +3,8 @@
@data Tag
]]
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local Commands = require("modules/exp_commands")
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
require("modules.exp_legacy.config.expcore.command_general_parse")
require("modules.exp_legacy.config.expcore.command_role_parse")
require("modules.exp_legacy.config.expcore.command_color_parse")
--- Stores the tag for a player
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
@@ -47,42 +44,39 @@ PlayerTagColors:on_update(function(player_name, player_tag_color)
end)
--- Sets your player tag.
-- @command tag
-- @tparam string tag the tag that will be after the name, there is a max length
Commands.new_command("tag", "Sets your player tag.")
:add_param("tag", false, "string-max-length", 20)
:enable_auto_concat()
Commands.new("tag", "Sets your player tag.")
:argument("tag", "", Commands.types.string_max_length(20))
:enable_auto_concatenation()
:register(function(player, tag)
--- @cast tag string
PlayerTags:set(player, tag)
end)
--- Sets your player tag color.
-- @command tag
-- @tparam string color name.
Commands.new_command("tag-color", "Sets your player tag color.")
:add_param("color", false, "color")
:enable_auto_concat()
Commands.new("tag-color", "Sets your player tag color.")
:argument("color", "", Commands.types.color)
:enable_auto_concatenation()
:register(function(player, color)
--- @cast color Color
PlayerTagColors:set(player, color)
end)
--- Clears your tag. Or another player if you are admin.
-- @command tag-clear
-- @tparam[opt=self] LuaPlayer player the player to remove the tag from, nil will apply to self
Commands.new_command("tag-clear", "Clears your tag. Or another player if you are admin.")
:add_param("player", true, "player-role")
:set_defaults{ player = function(player)
return player -- default is the user using the command
end }
:register(function(player, action_player)
if action_player.index == player.index then
-- no player given so removes your tag
PlayerTags:remove(action_player)
Commands.new("tag-clear", "Clears your tag. Or another player if you are admin.")
:optional("player", "", Commands.types.lower_role_player)
:defaults{
player = function(player) return player end
}
:register(function(player, other_player)
--- @cast other_player LuaPlayer
if other_player == player then
-- No player given so removes your tag
PlayerTags:remove(other_player)
elseif Roles.player_allowed(player, "command/clear-tag/always") then
-- player given and user is admin so clears that player's tag
PlayerTags:remove(action_player)
-- Player given and user is admin so clears that player's tag
PlayerTags:remove(other_player)
else
-- user is not admin and tried to clear another users tag
return Commands.error{ "expcore-commands.unauthorized" }
-- User is not admin and tried to clear another users tag
return Commands.status.unauthorised()
end
end)

View File

@@ -42,6 +42,7 @@ end
Event.add(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
--- @diagnostic disable-next-line param-type-mismatch
util.insert_safe(player, global.created_items)
local r = global.chart_distance or 200
@@ -65,6 +66,7 @@ end)
Event.add(defines.events.on_player_respawned, function(event)
local player = game.players[event.player_index]
--- @diagnostic disable-next-line param-type-mismatch
util.insert_safe(player, global.respawn_items)
if use_silo_script then
silo_script.on_event(event)

View File

@@ -1,4 +1,4 @@
local Commands = require("modules.exp_legacy.expcore.commands")
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.graftorio")
local statics = require("modules.exp_legacy.modules.graftorio.statics")
local general = require("modules.exp_legacy.modules.graftorio.general")
@@ -10,8 +10,8 @@ if config.modules.forcestats then
forcestats = require("modules.exp_legacy.modules.graftorio.forcestats")
end
Commands.new_command("collectdata", "Collect data for RCON usage")
:add_param("location", true)
Commands.new("collectdata", "Collect data for RCON usage")
:optional("location", "", Commands.types.string) -- Not sure what this is for, i didn't write this
:register(function()
-- this must be first as it overwrites the stats
-- also makes the .other table for all forces
@@ -24,6 +24,5 @@ Commands.new_command("collectdata", "Collect data for RCON usage")
forcestats.collect_production()
forcestats.collect_loginet()
end
rcon.print(table_to_json(general.data.output))
return Commands.success()
return Commands.status.success(table_to_json(general.data.output))
end)

View File

@@ -17,7 +17,7 @@ local main_frame_name = Gui.uid_name()
local close_name = Gui.uid_name()
local tab_name = Gui.uid_name()
function Public.open_dubug(player)
function Public.open_debug(player)
for i = 1, #pages do
local page = pages[i]
local callback = page.on_open_debug

View File

@@ -24,7 +24,8 @@ function Public.show(container)
local left_panel_style = left_panel.style
left_panel_style.width = 300
for token_id in pairs(Storage.registered) do
--- @diagnostic disable-next-line invisible
for token_id in pairs(Storage._registered) do
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = token_id }
Gui.set_data(header, token_id)
end

View File

@@ -60,9 +60,10 @@ local elem_filter = {
}
local function clear_module(player, area, machine)
-- Intentionally left as player.surface to allow use in remote view
for _, entity in pairs(player.surface.find_entities_filtered{ area = area, name = machine, force = player.force }) do
for _, r in pairs(player.surface.find_entities_filtered{ position = entity.position, name = "item-request-proxy", force = player.force }) do
local force = player.force
local surface = player.surface -- Allow remote view
for _, entity in pairs(surface.find_entities_filtered{ area = area, name = machine, force = force }) do
for _, r in pairs(surface.find_entities_filtered{ position = entity.position, name = "item-request-proxy", force = force }) do
if r then
r.destroy{ raise_destroy = true }
end
@@ -75,7 +76,7 @@ local function clear_module(player, area, machine)
if m_current_module_content then
for k, m in pairs(m_current_module_content) do
player.surface.spill_item_stack(entity.bounding_box.left_top, { name = k, count = m }, true, player.force, false)
surface.spill_item_stack(entity.bounding_box.left_top, { name = k, count = m }, true, force, false)
end
end

View File

@@ -129,8 +129,7 @@ end)
Event.on_nth_tick(60, function()
for _, player in pairs(game.connected_players) do
local frame = Gui.get_left_element(player, production_container)
-- Intentionally left as player.surface to allow use in remote view
local stat = player.force.get_item_production_statistics(player.surface)
local stat = player.force.get_item_production_statistics(player.surface) -- Allow remote view
local precision_value = precision[frame.container["production_st"].disp.table["production_0_e"].selected_index]
local table = frame.container["production_st"].disp.table

View File

@@ -107,12 +107,12 @@ local function research_notification(event)
end
else
if not (event.by_script) then
game.print{ "expcom-res.inf", research_time_format(game.tick), event.research.name, event.research.level - 1 }
game.print{ "research.inf", research_time_format(game.tick), event.research.name, event.research.level - 1 }
end
end
else
if not (event.by_script) then
game.print{ "expcom-res.msg", research_time_format(game.tick), event.research.name }
game.print{ "research.msg", research_time_format(game.tick), event.research.name }
end
if config.bonus_inventory.enabled then
@@ -139,7 +139,7 @@ local function research_gui_update()
local res_i = res_n + i - 3
if res["disp"][res_i] then
res_disp[i]["name"] = { "expcom-res.res-name", res["disp"][res_i]["raw_name"], prototypes.technology[res["disp"][res_i]["raw_name"]].localised_name }
res_disp[i]["name"] = { "research.res-name", res["disp"][res_i]["raw_name"], prototypes.technology[res["disp"][res_i]["raw_name"]].localised_name }
if research.time[res_i] == 0 then
res_disp[i]["target"] = res["disp"][res_i].target_disp
@@ -237,10 +237,10 @@ local research_data_set =
local res_disp = research_gui_update()
research_data_group(disp, 0)
disp["research_0_name"].caption = { "expcom-res.name" }
disp["research_0_target"].caption = { "expcom-res.target" }
disp["research_0_attempt"].caption = { "expcom-res.attempt" }
disp["research_0_difference"].caption = { "expcom-res.difference" }
disp["research_0_name"].caption = { "research.name" }
disp["research_0_target"].caption = { "research.target" }
disp["research_0_attempt"].caption = { "research.attempt" }
disp["research_0_difference"].caption = { "research.difference" }
for i = 1, 8, 1 do
research_data_group(disp, i)
@@ -269,7 +269,7 @@ local research_container =
:static_name(Gui.unique_static_name)
:add_to_left_flow()
Gui.left_toolbar_button("item/space-science-pack", { "expcom-res.main-tooltip" }, research_container, function(player)
Gui.left_toolbar_button("item/space-science-pack", { "research.main-tooltip" }, research_container, function(player)
return Roles.player_allowed(player, "gui/research")
end)

View File

@@ -6,8 +6,8 @@
local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
local Commands = require("modules.exp_legacy.expcore.commands") --- @dep expcore.commands
local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external
local Commands = require("modules/exp_commands")
--- Stores the visible state of server ups
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
@@ -34,19 +34,19 @@ local server_ups =
UsesServerUps:on_load(function(player_name, visible)
local player = game.players[player_name]
local label = player.gui.screen[server_ups.name]
--- @diagnostic disable-next-line undefined-field
if not External.valid() or not global.ext.var.server_ups then visible = false end
label.visible = visible
end)
--- Toggles if the server ups is visbile
-- @command server-ups
Commands.new_command("server-ups", "Toggle the server UPS display")
:add_alias("sups", "ups")
Commands.new("server-ups", { "server-ups.description" })
:add_aliases{ "sups", "ups" }
:register(function(player)
local label = player.gui.screen[server_ups.name]
if not External.valid() then
label.visible = false
return Commands.error{ "expcom-server-ups.no-ext" }
return Commands.status.error{ "server-ups.no-ext" }
end
label.visible = not label.visible
UsesServerUps:set(player, label.visible)