mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
.
This commit is contained in:
@@ -164,7 +164,7 @@ Commands.server = setmetatable({
|
|||||||
--- @param msg LocalisedString? An optional message to be included when a command completes (only has an effect in command callbacks)
|
--- @param msg LocalisedString? An optional message to be included when a command completes (only has an effect in command callbacks)
|
||||||
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
||||||
function Commands.status.success(msg)
|
function Commands.status.success(msg)
|
||||||
return Commands.status.success, msg or { "exp-commands.success" }
|
return Commands.status.success, msg == nil and { "exp-commands.success" } or msg
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to signal an error has occurred in a command, data type parser, or permission authority
|
--- Used to signal an error has occurred in a command, data type parser, or permission authority
|
||||||
@@ -172,7 +172,7 @@ end
|
|||||||
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
|
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
|
||||||
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
||||||
function Commands.status.error(msg)
|
function Commands.status.error(msg)
|
||||||
return Commands.status.error, { "exp-commands.error", msg or { "exp-commands.error-default" } }
|
return Commands.status.error, { "exp-commands.error", msg == nil and { "exp-commands.error-default" } or msg }
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to signal the player is unauthorised to use a command, primarily used by permission authorities but can be used in a command callback
|
--- Used to signal the player is unauthorised to use a command, primarily used by permission authorities but can be used in a command callback
|
||||||
@@ -180,7 +180,7 @@ end
|
|||||||
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
|
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
|
||||||
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
||||||
function Commands.status.unauthorised(msg)
|
function Commands.status.unauthorised(msg)
|
||||||
return Commands.status.unauthorised, msg or { "exp-commands.unauthorized", msg or { "exp-commands.unauthorized-default" } }
|
return Commands.status.unauthorised, { "exp-commands.unauthorized", msg == nil and { "exp-commands.unauthorized-default" } or msg }
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to signal the player provided invalid input to an command, primarily used by data type parsers but can be used in a command callback
|
--- Used to signal the player provided invalid input to an command, primarily used by data type parsers but can be used in a command callback
|
||||||
@@ -188,7 +188,7 @@ end
|
|||||||
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
|
--- @param msg LocalisedString? An optional error message to be included in the output, a generic message is used if not provided
|
||||||
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
--- @return Commands.Status, LocalisedString # Should be returned directly without modification
|
||||||
function Commands.status.invalid_input(msg)
|
function Commands.status.invalid_input(msg)
|
||||||
return Commands.status.invalid_input, msg or { "exp-commands.invalid-input" }
|
return Commands.status.invalid_input, msg == nil and { "exp-commands.invalid-input" } or msg
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to signal an internal error has occurred, this is reserved for internal use only
|
--- Used to signal an internal error has occurred, this is reserved for internal use only
|
||||||
@@ -702,7 +702,7 @@ function Commands._event_handler(event)
|
|||||||
-- Parse the raw argument to get the correct data type
|
-- Parse the raw argument to get the correct data type
|
||||||
local success, status, parsed = Commands.parse_input(input, player, argument.input_parser)
|
local success, status, parsed = Commands.parse_input(input, player, argument.input_parser)
|
||||||
if success == false then
|
if success == false then
|
||||||
log_command("Input parse failed", command, player, event.parameter, { status = valid_command_status[status], index = index, argument = argument, reason = parsed })
|
log_command("Input parse failed", command, player, event.parameter, { status = valid_command_status[status], index = index, argument = argument.name, reason = parsed })
|
||||||
return Commands.error{ "exp-commands.invalid-argument", argument.name, parsed }
|
return Commands.error{ "exp-commands.invalid-argument", argument.name, parsed }
|
||||||
else
|
else
|
||||||
arguments[index] = parsed
|
arguments[index] = parsed
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ function External.get_current_server()
|
|||||||
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
||||||
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
||||||
local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
||||||
return servers[server_id]
|
return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets the details of the given server
|
--[[-- Gets the details of the given server
|
||||||
@@ -97,7 +97,7 @@ local server = External.get_server_details('eu-01')
|
|||||||
function External.get_server_details(server_id)
|
function External.get_server_details(server_id)
|
||||||
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
||||||
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
||||||
return servers[server_id]
|
return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets the status of the given server
|
--[[-- Gets the status of the given server
|
||||||
@@ -113,7 +113,7 @@ function External.get_server_status(server_id, raw)
|
|||||||
assert(var, "No external data was found, use External.valid() to ensure external data exists.")
|
assert(var, "No external data was found, use External.valid() to ensure external data exists.")
|
||||||
local servers = assert(var.status, "No server status was found, please ensure that the external service is running")
|
local servers = assert(var.status, "No server status was found, please ensure that the external service is running")
|
||||||
local current = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
local current = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
||||||
return not raw and server_id == current and "Current" or servers[server_id]
|
return not raw and server_id == current and "Current" or assert(servers[server_id], "No status found for server with id: " .. tostring(server_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets the ups of the current server
|
--[[-- Gets the ups of the current server
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ Storage.register({
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- Gets the silo data for a given silo entity
|
--- Gets the silo data for a given silo entity
|
||||||
-- @tparam LuaEntity silo the rocket silo entity
|
--- @param silo LuaEntity Rocket silo entity
|
||||||
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
|
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
|
||||||
function Rockets.get_silo_data(silo)
|
function Rockets.get_silo_data(silo)
|
||||||
local position = silo.position
|
local position = silo.position
|
||||||
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
|
local silo_name = math.floor(position.x) .. ":" .. math.floor(position.y)
|
||||||
@@ -68,30 +68,30 @@ function Rockets.get_silo_data(silo)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the silo data for a given silo entity
|
--- Gets the silo data for a given silo entity
|
||||||
-- @tparam string silo_name the silo name that is stored in its data
|
--- @param silo_name string Silo name that is stored in its data
|
||||||
-- @treturn table the data table for this silo, contains rockets launch, silo status, and its force
|
--- @return table # Data table for this silo, contains rockets launch, silo status, and its force
|
||||||
function Rockets.get_silo_data_by_name(silo_name)
|
function Rockets.get_silo_data_by_name(silo_name)
|
||||||
return rocket_silos[silo_name]
|
return rocket_silos[silo_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the silo entity from its silo name, reverse to get_silo_data
|
--- Gets the silo entity from its silo name, reverse to get_silo_data
|
||||||
-- @tparam string silo_name the silo name that is stored in its data
|
--- @param silo_name string Silo name that is stored in its data
|
||||||
-- @treturn LuaEntity the rocket silo entity
|
--- @return LuaEntity # Rocket silo entity
|
||||||
function Rockets.get_silo_entity(silo_name)
|
function Rockets.get_silo_entity(silo_name)
|
||||||
local data = rocket_silos[silo_name]
|
local data = rocket_silos[silo_name]
|
||||||
return data.entity
|
return data.entity
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the rocket stats for a force
|
--- Gets the rocket stats for a force
|
||||||
-- @tparam string force_name the name of the force to get the stats for
|
--- @param force_name string Name of the force to get the stats for
|
||||||
-- @treturn table the table of stats for the force
|
--- @return table # Stats for the force
|
||||||
function Rockets.get_stats(force_name)
|
function Rockets.get_stats(force_name)
|
||||||
return rocket_stats[force_name] or {}
|
return rocket_stats[force_name] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets all the rocket silos that belong to a force
|
--- Gets all the rocket silos that belong to a force
|
||||||
-- @tparam string force_name the name of the force to get the silos for
|
--- @param force_name string Name of the force to get the silos for
|
||||||
-- @treturn table an array of silo data that all belong to this force
|
--- @return table # Array of silo data that all belong to this force
|
||||||
function Rockets.get_silos(force_name)
|
function Rockets.get_silos(force_name)
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for _, silo_data in pairs(rocket_silos) do
|
for _, silo_data in pairs(rocket_silos) do
|
||||||
@@ -104,23 +104,23 @@ function Rockets.get_silos(force_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the launch time of a given rocket, due to cleaning not all counts are valid
|
--- Gets the launch time of a given rocket, due to cleaning not all counts are valid
|
||||||
-- @tparam string force_name the name of the force to get the count for
|
--- @param force_name string Name of the force to get the count for
|
||||||
-- @tparam number rocket_number the number of the rocket to get the launch time for
|
--- @param rocket_number number Number of the rocket to get the launch time for
|
||||||
-- @treturn number the game tick that the rocket was lanuched on
|
--- @return number? # Game tick that the rocket was launched on
|
||||||
function Rockets.get_rocket_time(force_name, rocket_number)
|
function Rockets.get_rocket_time(force_name, rocket_number)
|
||||||
return rocket_times[force_name] and rocket_times[force_name][rocket_number] or nil
|
return rocket_times[force_name] and rocket_times[force_name][rocket_number] or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the number of rockets that a force has launched
|
--- Gets the number of rockets that a force has launched
|
||||||
-- @tparam string force_name the name of the force to get the count for
|
--- @param force_name string the name of the force to get the count for
|
||||||
-- @treturn number the number of rockets that the force has launched
|
--- @return number # Number of rockets that the force has launched
|
||||||
function Rockets.get_rocket_count(force_name)
|
function Rockets.get_rocket_count(force_name)
|
||||||
local force = game.forces[force_name]
|
local force = game.forces[force_name]
|
||||||
return force.rockets_launched
|
return force.rockets_launched
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the total number of rockets launched by all forces
|
--- Gets the total number of rockets launched by all forces
|
||||||
-- @treturn number the total number of rockets launched this game
|
--- @return number # Total number of rockets launched this game
|
||||||
function Rockets.get_game_rocket_count()
|
function Rockets.get_game_rocket_count()
|
||||||
local rtn = 0
|
local rtn = 0
|
||||||
for _, force in pairs(game.forces) do
|
for _, force in pairs(game.forces) do
|
||||||
@@ -131,9 +131,9 @@ function Rockets.get_game_rocket_count()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Gets the rolling average time to launch a rocket
|
--- Gets the rolling average time to launch a rocket
|
||||||
-- @tparam string force_name the name of the force to get the average for
|
--- @param force_name string Name of the force to get the average for
|
||||||
-- @tparam number count the distance to get the rolling average over
|
--- @param count number Distance to get the rolling average over
|
||||||
-- @treturn number the number of ticks required to launch one rocket
|
--- @return number # Number of ticks required to launch one rocket
|
||||||
function Rockets.get_rolling_average(force_name, count)
|
function Rockets.get_rolling_average(force_name, count)
|
||||||
local force = game.forces[force_name]
|
local force = game.forces[force_name]
|
||||||
local rocket_count = force.rockets_launched
|
local rocket_count = force.rockets_launched
|
||||||
@@ -147,14 +147,20 @@ function Rockets.get_rolling_average(force_name, count)
|
|||||||
return math.floor((last_launch_time - start_rocket_time) / rocket_count)
|
return math.floor((last_launch_time - start_rocket_time) / rocket_count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- When a launch is trigger it will wait for the silo to reset
|
||||||
|
--- @param event EventData.on_rocket_launch_ordered
|
||||||
|
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
||||||
|
local silo_data = Rockets.get_silo_data(event.rocket_silo)
|
||||||
|
silo_data.launched = silo_data.launched + 1
|
||||||
|
silo_data.awaiting_reset = true
|
||||||
|
end)
|
||||||
|
|
||||||
--- Event used to update the stats and the hui when a rocket is launched
|
--- Event used to update the stats and the hui when a rocket is launched
|
||||||
--- @param event EventData.on_rocket_launched
|
--- @param event EventData.on_cargo_pod_finished_ascending
|
||||||
Event.add(defines.events.on_rocket_launched, function(event)
|
Event.add(defines.events.on_cargo_pod_finished_ascending, function(event)
|
||||||
local entity = event.rocket_silo
|
local force = event.cargo_pod.force
|
||||||
local silo_data = Rockets.get_silo_data(entity)
|
|
||||||
local force = event.rocket_silo.force
|
|
||||||
local force_name = force.name
|
local force_name = force.name
|
||||||
local rockets_launched = force.rockets_launched + 1 -- Hasn't updated when this event fires
|
local rockets_launched = force.rockets_launched
|
||||||
|
|
||||||
--- Handles updates to the rocket stats
|
--- Handles updates to the rocket stats
|
||||||
local stats = rocket_stats[force_name]
|
local stats = rocket_stats[force_name]
|
||||||
@@ -183,16 +189,6 @@ Event.add(defines.events.on_rocket_launched, function(event)
|
|||||||
if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then
|
if remove_rocket > 0 and not table.contains(config.milestones, remove_rocket) then
|
||||||
rocket_times[force_name][remove_rocket] = nil
|
rocket_times[force_name][remove_rocket] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Adds this 1 to the launch count for this silo
|
|
||||||
silo_data.launched = silo_data.launched + 1
|
|
||||||
end)
|
|
||||||
|
|
||||||
--- When a launch is reiggered it will await reset
|
|
||||||
Event.add(defines.events.on_rocket_launch_ordered, function(event)
|
|
||||||
local entity = event.rocket_silo
|
|
||||||
local silo_data = Rockets.get_silo_data(entity)
|
|
||||||
silo_data.awaiting_reset = true
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Adds a silo to the list when it is built
|
--- Adds a silo to the list when it is built
|
||||||
|
|||||||
@@ -451,6 +451,7 @@ end
|
|||||||
|
|
||||||
--- @class Common.copy_items_to_surface_param: Common.get_or_create_storage_param
|
--- @class Common.copy_items_to_surface_param: Common.get_or_create_storage_param
|
||||||
--- @field items ItemStackIdentification[] | LuaInventory The item stacks to copy
|
--- @field items ItemStackIdentification[] | LuaInventory The item stacks to copy
|
||||||
|
--- @field item ItemStackIdentification? Overwritten internally
|
||||||
|
|
||||||
--- Insert a copy of the given items into the found entities. If no entities are found then they will be created if possible.
|
--- Insert a copy of the given items into the found entities. If no entities are found then they will be created if possible.
|
||||||
--- @param options Common.copy_items_to_surface_param
|
--- @param options Common.copy_items_to_surface_param
|
||||||
@@ -467,6 +468,7 @@ end
|
|||||||
|
|
||||||
--- @class Common.move_items_to_surface_param: Common.get_or_create_storage_param
|
--- @class Common.move_items_to_surface_param: Common.get_or_create_storage_param
|
||||||
--- @field items LuaItemStack[] The item stacks to move
|
--- @field items LuaItemStack[] The item stacks to move
|
||||||
|
--- @field item ItemStackIdentification? Overwritten internally
|
||||||
|
|
||||||
--- Insert a copy of the given items into the found entities. If no entities are found then they will be created if possible.
|
--- Insert a copy of the given items into the found entities. If no entities are found then they will be created if possible.
|
||||||
--- @param options Common.move_items_to_surface_param
|
--- @param options Common.move_items_to_surface_param
|
||||||
@@ -484,6 +486,7 @@ end
|
|||||||
|
|
||||||
--- @class Common.transfer_inventory_to_surface_param: Common.copy_items_to_surface_param
|
--- @class Common.transfer_inventory_to_surface_param: Common.copy_items_to_surface_param
|
||||||
--- @field inventory LuaInventory The inventory to transfer
|
--- @field inventory LuaInventory The inventory to transfer
|
||||||
|
--- @field items (ItemStackIdentification[] | LuaInventory)? Overwritten internally
|
||||||
|
|
||||||
--- Move the given inventory into the found entities. If no entities are found then they will be created if possible.
|
--- Move the given inventory into the found entities. If no entities are found then they will be created if possible.
|
||||||
--- @param options Common.transfer_inventory_to_surface_param
|
--- @param options Common.transfer_inventory_to_surface_param
|
||||||
|
|||||||
Reference in New Issue
Block a user