mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Feature Update (#237)
See PR for details, there are too many to be included here.
This commit is contained in:
24
modules/commands/bot-queue.lua
Normal file
24
modules/commands/bot-queue.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
--[[-- Commands Module - Bot queue
|
||||
- Adds a command that allows changing bot queue
|
||||
@commands Bot Queue
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('bot-queue-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', s, f}
|
||||
end)
|
||||
|
||||
Commands.new_command('bot-queue-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
|
||||
return Commands.success{'expcom-bot-queue.result', 3 * amount, 1 * amount}
|
||||
end)
|
||||
@@ -17,4 +17,27 @@ end}
|
||||
:set_flag('admin_only')
|
||||
:register(function(_, player)
|
||||
player.cheat_mode = not player.cheat_mode
|
||||
end)
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Commands.new_command('research-all', '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(_, force)
|
||||
force.research_all_technologies()
|
||||
return Commands.success
|
||||
end)
|
||||
|
||||
Commands.new_command('toggle-always-day', 'Toggles always day in surface')
|
||||
:set_flag('admin_only')
|
||||
:add_param('surface', true, 'surface')
|
||||
:set_defaults{surface=function(player)
|
||||
return player.surface
|
||||
end}
|
||||
:register(function(_, surface)
|
||||
surface.always_day = not surface.always_day
|
||||
return Commands.success{'expcom-cheat.day', surface.always_day}
|
||||
end)
|
||||
|
||||
30
modules/commands/enemy.lua
Normal file
30
modules/commands/enemy.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
--[[-- Commands Module - Enemy
|
||||
- Adds a command of handling enemy
|
||||
@commands Enemy
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('kill-biters', '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', 'Remove biters and prevent generation')
|
||||
:set_flag('admin_only')
|
||||
:add_param('surface', true, 'surface')
|
||||
:set_defaults{surface=function(player)
|
||||
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)
|
||||
|
||||
18
modules/commands/friendly-fire.lua
Normal file
18
modules/commands/friendly-fire.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
--[[-- Commands Module - Toggle Friendly Fire
|
||||
- Adds a command that toggle all friendly fire
|
||||
@commands Toggle Friendly Fire
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
-- For Modded Server Use
|
||||
Commands.new_command('toggle-friendly-fire', 'Toggle Friendly Fire')
|
||||
:add_param('force', true, 'force')
|
||||
:set_defaults{force=function(player)
|
||||
return player.force
|
||||
end}
|
||||
:register(function(_, force)
|
||||
force.friendly_fire = not force.friendly_fire
|
||||
return Commands.success{'expcom-ff.ff', force.friendly_fire}
|
||||
end)
|
||||
31
modules/commands/lawnmower.lua
Normal file
31
modules/commands/lawnmower.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
--[[-- Commands Module - Lawnmower
|
||||
- Adds a command that clean up biter corpse and nuclear hole
|
||||
@commands Lawnmower
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require '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 = {}
|
||||
|
||||
player.surface.destroy_decoratives({position=player.position, radius=range})
|
||||
|
||||
local entities = player.surface.find_entities_filtered{position=player.position, radius=range, type='corpse', name={'transport-caution-corpse', 'invisible-transport-caution-corpse'}}
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
entity.destroy()
|
||||
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)
|
||||
32
modules/commands/pollution.lua
Normal file
32
modules/commands/pollution.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
--[[-- Commands Module - Pollution Handle
|
||||
- Adds a command that allows modifying pollution
|
||||
@commands Pollution Handle
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('pollution-clear', 'Clear pollution')
|
||||
:set_flag('admin_only')
|
||||
:add_alias('pol-clr')
|
||||
:add_param('surface', true, 'surface')
|
||||
:set_defaults{surface=function(player)
|
||||
return player.surface
|
||||
end}
|
||||
:register(function(player, surface)
|
||||
surface.clear_pollution()
|
||||
return Commands.success{'expcom-pol.clr', player}
|
||||
end)
|
||||
|
||||
Commands.new_command('pollution-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
|
||||
|
||||
return Commands.success{'expcom-pol.off', player.name}
|
||||
end)
|
||||
@@ -36,8 +36,8 @@ 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) }
|
||||
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
|
||||
|
||||
@@ -51,7 +51,6 @@ 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)
|
||||
|
||||
@@ -12,7 +12,7 @@ local max_time_to_live = 4294967295 -- unit32 max
|
||||
-- @command repair
|
||||
-- @tparam number range the range to repair stuff in, there is a max limit to this
|
||||
Commands.new_command('repair', 'Repairs entities on your force around you')
|
||||
:add_param('range', false, 'integer-range', 1,config.max_range)
|
||||
:add_param('range', false, 'integer-range', 1, config.max_range)
|
||||
:register(function(player, range)
|
||||
local revive_count = 0
|
||||
local heal_count = 0
|
||||
|
||||
94
modules/commands/research.lua
Normal file
94
modules/commands/research.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local Common = require 'expcore.common' --- @dep utils.event
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
local config = require 'config.research' --- @dep config.research
|
||||
local config_bonus = Common.opt_require 'config.bonus' --- @dep config.bonus
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local format_time = _C.format_time --- @dep expcore.common
|
||||
|
||||
local research = {}
|
||||
Global.register(research, function(tbl)
|
||||
research = tbl
|
||||
end)
|
||||
|
||||
local research_time_format = {hours=true, minutes=true, seconds=true, time=true, string=true}
|
||||
research.res_queue_enable = false
|
||||
local base_rate = 0
|
||||
|
||||
if config.bonus.enabled then
|
||||
for k, _ in pairs(config_bonus.force_bonus) do
|
||||
if config_bonus.force_bonus[k].name == config.bonus.name then
|
||||
base_rate = config_bonus.force_bonus[k].max
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function research_notification(event)
|
||||
local is_inf_res = false
|
||||
|
||||
for i=1, #config.inf_res do
|
||||
if (event.research.name == config.inf_res[i].name) and (event.research.level >= config.inf_res[i].level) then
|
||||
is_inf_res = true
|
||||
end
|
||||
end
|
||||
|
||||
if config.bonus_inventory.enabled then
|
||||
if (event.research.force.mining_drill_productivity_bonus * 10) <= (config.bonus_inventory.limit / config.bonus_inventory.rate) then
|
||||
if event.research.force.technologies['toolbelt'].researched then
|
||||
event.research.force[config.bonus_inventory.name] = (math.floor(event.research.force.mining_drill_productivity_bonus * 10) * config.bonus_inventory.rate) + 10
|
||||
else
|
||||
event.research.force[config.bonus_inventory.name] = math.floor(event.research.force.mining_drill_productivity_bonus * 10) * config.bonus_inventory.rate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if is_inf_res then
|
||||
if config.bonus.enabled then
|
||||
if event.research.name == 'mining-productivity-4' and event.research.force.technologies['mining-productivity-4'].level > 4 then
|
||||
event.research.force[config.bonus.name] = base_rate + event.research.force.technologies['mining-productivity-4'].level * config.bonus.rate
|
||||
end
|
||||
end
|
||||
|
||||
if not (event.by_script) then
|
||||
game.print{'expcom-res.inf', format_time(game.tick, research_time_format), event.research.name, event.research.level}
|
||||
end
|
||||
else
|
||||
if not (event.by_script) then
|
||||
game.print{'expcom-res.msg', format_time(game.tick, research_time_format), event.research.name}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function res_queue(force)
|
||||
if force.rockets_launched == 0 or force.technologies['mining-productivity-4'].level <= 4 then
|
||||
return
|
||||
end
|
||||
|
||||
local res_q = force.research_queue
|
||||
|
||||
if #res_q < config.queue_amount then
|
||||
for i=1, config.queue_amount - #res_q do
|
||||
force.add_research(force.technologies['mining-productivity-4'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_research_finished, function(event)
|
||||
research_notification(event)
|
||||
|
||||
if research.res_queue_enable then
|
||||
res_queue(event.research.force)
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.new_command('auto-research', '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)
|
||||
end
|
||||
|
||||
return Commands.success{'expcom-res.res', research.res_queue_enable}
|
||||
end)
|
||||
@@ -10,9 +10,29 @@ 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)
|
||||
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(position, surface)
|
||||
-- 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
|
||||
|
||||
|
||||
15
modules/commands/speed.lua
Normal file
15
modules/commands/speed.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
--[[-- Commands Module - Set game speed
|
||||
- Adds a command that allows changing game speed
|
||||
@commands Set game speed
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
Commands.new_command('game-speed', 'Set game speed')
|
||||
:add_param('amount', 'number-range', 0.2, 1)
|
||||
:set_flag('admin_only')
|
||||
:register(function(_, amount)
|
||||
game.speed = math.round(amount, 3)
|
||||
return Commands.success{'expcom-speed.result', string.format('%.3f', amount)}
|
||||
end)
|
||||
@@ -9,9 +9,31 @@ require 'config.expcore.command_general_parse'
|
||||
local function teleport(from_player, to_player)
|
||||
local surface = to_player.surface
|
||||
local position = surface.find_non_colliding_position('character', to_player.position, 32, 1)
|
||||
if not position then return false end -- return false if no new position
|
||||
if from_player.driving then from_player.driving = false end -- kicks a player out a vehicle if in one
|
||||
from_player.teleport(position, surface)
|
||||
|
||||
-- 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
|
||||
|
||||
@@ -50,6 +72,7 @@ Commands.new_command('bring', 'Teleports a player to you.')
|
||||
-- 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.
|
||||
@@ -58,7 +81,6 @@ end)
|
||||
Commands.new_command('goto', 'Teleports you to a player.')
|
||||
:add_param('player', false, 'player-online')
|
||||
:add_alias('tp-me', 'tpme')
|
||||
:set_flag('admin_only')
|
||||
:register(function(player, to_player)
|
||||
if to_player.index == player.index then
|
||||
-- return if attempting to teleport to self
|
||||
@@ -68,4 +90,4 @@ Commands.new_command('goto', 'Teleports you to a player.')
|
||||
-- return if the teleport failed
|
||||
return Commands.error{'expcom-tp.no-position-found'}
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
22
modules/commands/train.lua
Normal file
22
modules/commands/train.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
--[[-- Commands Module - Set Automatic Train
|
||||
- Adds a command that set all train back to automatic
|
||||
@commands Set Automatic Train
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
local format_number = require('util').format_number
|
||||
|
||||
Commands.new_command('set-trains-to-automatic', '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
|
||||
|
||||
return Commands.success{'expcom-train.manual-result', format_number(count)}
|
||||
end)
|
||||
28
modules/commands/vlayer.lua
Normal file
28
modules/commands/vlayer.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
--- Adds a virtual layer to store power to save space.
|
||||
-- @addon Virtual Layer
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
local vlayer = require 'modules.control.vlayer'
|
||||
|
||||
Commands.new_command('personal-battery-recharge', 'Recharge Player Battery upto a portion with vlayer')
|
||||
:add_param('amount', 'number-range', 0.2, 1)
|
||||
:register(function(player, amount)
|
||||
local armor = player.get_inventory(defines.inventory.character_armor)[1].grid
|
||||
|
||||
for i=1, #armor.equipment do
|
||||
if armor.equipment[i].energy < (armor.equipment[i].max_energy * amount) then
|
||||
local energy_required = (armor.equipment[i].max_energy * amount) - armor.equipment[i].energy
|
||||
|
||||
if vlayer.power.energy >= energy_required then
|
||||
armor.equipment[i].energy = armor.equipment[i].max_energy * amount
|
||||
vlayer.power.energy = vlayer.power.energy - energy_required
|
||||
else
|
||||
armor.equipment[i].energy = armor.equipment[i].energy + vlayer.power.energy
|
||||
vlayer.power.energy = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Commands.success
|
||||
end)
|
||||
64
modules/commands/waterfill.lua
Normal file
64
modules/commands/waterfill.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
--- Adds a waterfill
|
||||
-- @addon Virtual Waterfill
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
local Selection = require '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', '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.get_player(event.player_index)
|
||||
|
||||
local entities = player.surface.find_entities_filtered{area=area, name='steel-chest'}
|
||||
local tiles_to_make = {}
|
||||
local inv = player.get_main_inventory()
|
||||
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
|
||||
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)
|
||||
Reference in New Issue
Block a user