You've already forked ComfyFactorio
mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-11-25 22:32:18 +02:00
Mass refactor
This PR changes generated events by util modules to bypass the need to require each file to utilize them. Added new module that tracks undo of a player. The config module for GUI has been refactored to add functions/events from the caller instead of having one massive blob inside of the file. The debug module now prints each attribute of an object instead of plain <userdata>.
This commit is contained in:
@@ -4,10 +4,11 @@ _DEBUG = false
|
||||
_DUMP_ENV = false
|
||||
_PROFILE = false
|
||||
|
||||
require 'utils.created_events'
|
||||
require 'utils.server'
|
||||
require 'utils.server_commands'
|
||||
require 'utils.gui.init'
|
||||
require 'utils.command_handler'
|
||||
require 'utils.admin_handler'
|
||||
require 'utils.utils'
|
||||
require 'utils.math.math'
|
||||
require 'utils.pause_game'
|
||||
|
||||
@@ -6,6 +6,7 @@ local SpamProtection = require 'utils.spam_protection'
|
||||
local BottomFrame = require 'utils.gui.bottom_frame'
|
||||
local Gui = require 'utils.gui'
|
||||
local Color = require 'utils.color_presets'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local Public = {}
|
||||
local module_name = '[color=blue][Charging station][/color] '
|
||||
@@ -149,7 +150,7 @@ Gui.on_click(
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
Event.add(
|
||||
BottomFrame.events.bottom_quickbar_location_changed,
|
||||
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||
function (event)
|
||||
local player_index = event.player_index
|
||||
if not player_index then
|
||||
|
||||
@@ -15,13 +15,13 @@ local math2d = require 'math2d'
|
||||
local Misc = require 'utils.commands.misc'
|
||||
local Core = require 'utils.core'
|
||||
local Beams = require 'modules.render_beam'
|
||||
local BottomFrame = require 'utils.gui.bottom_frame'
|
||||
local Modifiers = require 'utils.player_modifiers'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap'
|
||||
local Score = require 'utils.gui.score'
|
||||
local Gui = require 'utils.gui'
|
||||
local FunctionColor = { r = 0.98, g = 0.66, b = 0.22 }
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local zone_settings = Public.zone_settings
|
||||
local remove_boost_movement_speed_on_respawn
|
||||
@@ -3583,7 +3583,7 @@ function Public.set_player_to_god(player)
|
||||
|
||||
|
||||
Event.raise(
|
||||
BottomFrame.events.bottom_quickbar_respawn_raise,
|
||||
CreatedEvents.events.bottom_quickbar_respawn_raise,
|
||||
{
|
||||
player_index = player.index
|
||||
}
|
||||
@@ -3836,7 +3836,7 @@ Event.on_nth_tick(35, do_clear_rocks_slowly)
|
||||
Event.on_nth_tick(35, do_replace_tiles_slowly)
|
||||
Event.on_nth_tick(200, do_custom_surface_funcs)
|
||||
Event.on_nth_tick(60, set_difficulty)
|
||||
Event.add(WD.events.on_wave_created, on_wave_created)
|
||||
Event.add(WD.events.on_primary_target_missing, on_primary_target_missing)
|
||||
Event.add(CreatedEvents.events.on_wave_created, on_wave_created)
|
||||
Event.add(CreatedEvents.events.on_primary_target_missing, on_primary_target_missing)
|
||||
|
||||
return Public
|
||||
|
||||
@@ -8,6 +8,7 @@ local Score = require 'utils.gui.score'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Core = require 'utils.core'
|
||||
local SpamProtection = require 'utils.spam_protection'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local module_name = Gui.uid_name()
|
||||
local score_dataset = 'highscores'
|
||||
@@ -778,6 +779,6 @@ Event.on_init(on_init)
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(Server.events.on_server_started, Public.get_scores)
|
||||
Event.add(CreatedEvents.events.on_server_started, Public.get_scores)
|
||||
|
||||
return Public
|
||||
|
||||
@@ -5,9 +5,9 @@ local Core = require 'utils.core'
|
||||
local JailData = require 'utils.datastore.jail_data'
|
||||
local IC = require 'maps.mountain_fortress_v3.ic.table'
|
||||
local WPT = require 'maps.mountain_fortress_v3.table'
|
||||
local OfflinePlayers = require 'modules.clear_vacant_players'
|
||||
local Event = require 'utils.event'
|
||||
local Server = require 'utils.server'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local Public = {}
|
||||
local main_tile_name = 'black-refined-concrete'
|
||||
@@ -1618,7 +1618,7 @@ Public.kick_players_from_surface = kick_players_from_surface
|
||||
Public.kick_non_trusted_players_from_surface = kick_non_trusted_players_from_surface
|
||||
|
||||
Event.add(
|
||||
OfflinePlayers.events.remove_surface,
|
||||
CreatedEvents.events.remove_surface,
|
||||
function (event)
|
||||
local target = event.target
|
||||
if not target then
|
||||
|
||||
@@ -45,6 +45,7 @@ local OfflinePlayers = require 'modules.clear_vacant_players'
|
||||
local Beam = require 'modules.render_beam'
|
||||
local Commands = require 'utils.commands'
|
||||
local RobotLimits = require 'modules.robot_limits'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local send_ping_to_channel = Discord.channel_names.mtn_channel
|
||||
local role_to_mention = Discord.role_mentions.mtn_fortress
|
||||
@@ -641,7 +642,7 @@ function Public.reset_map(current_task)
|
||||
|
||||
|
||||
-- WD.set_es_unit_limit(400) -- moved to stateful
|
||||
Event.raise(WD.events.on_game_reset, {})
|
||||
Event.raise(CreatedEvents.events.on_game_reset, {})
|
||||
|
||||
Public.set_difficulty()
|
||||
Public.disable_creative()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local Public = require 'maps.mountain_fortress_v3.table'
|
||||
local RPG = require 'modules.rpg.main'
|
||||
local Event = require 'utils.event'
|
||||
local Ai = require 'modules.ai'
|
||||
local Misc = require 'utils.commands.misc'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
require 'modules.check_fullness'
|
||||
|
||||
local random = math.random
|
||||
@@ -502,7 +502,7 @@ Event.add(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Ai.events.on_entity_mined,
|
||||
CreatedEvents.events.on_entity_mined,
|
||||
function (event)
|
||||
if not event then
|
||||
return
|
||||
|
||||
@@ -5,6 +5,7 @@ local Server = require 'utils.server'
|
||||
local Gui = require 'utils.gui'
|
||||
local Task = require 'utils.task_token'
|
||||
local SpamProtection = require 'utils.spam_protection'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local module_name = Gui.uid_name()
|
||||
local score_dataset = 'seasons'
|
||||
@@ -373,6 +374,6 @@ Gui.on_click(
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(Server.events.on_server_started, Public.get_season_scores)
|
||||
Event.add(CreatedEvents.events.on_server_started, Public.get_season_scores)
|
||||
|
||||
return Public
|
||||
|
||||
@@ -2,15 +2,15 @@ local Public = require 'maps.mountain_fortress_v3.stateful.table'
|
||||
local Event = require 'utils.event'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Beam = require 'modules.render_beam'
|
||||
local RPG = require 'modules.rpg.main'
|
||||
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
Public.stateful_gui = require 'maps.mountain_fortress_v3.stateful.gui'
|
||||
Public.stateful_blueprints = require 'maps.mountain_fortress_v3.stateful.blueprints'
|
||||
|
||||
local random = math.random
|
||||
|
||||
local valid_types = {
|
||||
local valid_types =
|
||||
{
|
||||
['unit'] = true,
|
||||
['turret'] = true
|
||||
}
|
||||
@@ -144,7 +144,7 @@ Event.on_nth_tick(
|
||||
WD.set_main_target()
|
||||
WD.build_worm_custom()
|
||||
-- WD.place_custom_nest(locomotive.surface, area[1], 'aggressors_frenzy')
|
||||
Event.raise(WD.events.on_spawn_unit_group_simple, { fs = true, bypass = true, random_bosses = true, scale = 32, force = 'aggressors_frenzy' })
|
||||
Event.raise(CreatedEvents.events.on_spawn_unit_group_simple, { fs = true, bypass = true, random_bosses = true, scale = 32, force = 'aggressors_frenzy' })
|
||||
Public.set_multi_command_final_battle()
|
||||
return
|
||||
end
|
||||
@@ -208,7 +208,7 @@ Event.add(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
RPG.events.on_spell_cast_success,
|
||||
CreatedEvents.events.on_spell_cast_success,
|
||||
function (event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
@@ -271,7 +271,7 @@ Event.on_nth_tick(
|
||||
|
||||
Event.add(defines.events.on_pre_player_died, Public.on_pre_player_died)
|
||||
Event.add(Public.events.on_market_item_purchased, Public.on_market_item_purchased)
|
||||
Event.add(BiterHealthBooster.events.custom_on_entity_died, on_entity_died)
|
||||
Event.add(CreatedEvents.events.custom_on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
|
||||
return Public
|
||||
|
||||
@@ -16,6 +16,7 @@ local RPG = require 'modules.rpg.table'
|
||||
local Beam = require 'modules.render_beam'
|
||||
local Discord = require 'utils.discord'
|
||||
local Difficulty = require 'modules.difficulty_vote_by_amount'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local this =
|
||||
{
|
||||
@@ -2410,14 +2411,14 @@ function Public.increase_enemy_damage_and_health()
|
||||
this.enemies_boosted = true
|
||||
|
||||
if this.rounds_survived == 1 then
|
||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.aggressors })
|
||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.aggressors_frenzy })
|
||||
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
||||
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.aggressors })
|
||||
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.aggressors_frenzy })
|
||||
else
|
||||
for _ = 1, this.rounds_survived do
|
||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.aggressors })
|
||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.aggressors_frenzy })
|
||||
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
||||
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.aggressors })
|
||||
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.aggressors_frenzy })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2483,7 +2484,7 @@ function Public.stateful_on_server_started()
|
||||
end
|
||||
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
CreatedEvents.events.on_server_started,
|
||||
function ()
|
||||
if this.settings_applied then
|
||||
return
|
||||
|
||||
@@ -6,6 +6,7 @@ local Task = require 'utils.task_token'
|
||||
local Config = require 'utils.gui.config'
|
||||
local Fullness = require 'modules.check_fullness'
|
||||
local Color = require 'utils.color_presets'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local stateful_settings =
|
||||
{
|
||||
@@ -845,7 +846,7 @@ local apply_settings_token =
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
CreatedEvents.events.on_server_started,
|
||||
function ()
|
||||
local start_data = Server.get_start_data()
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ local Classes = require('maps.pirates.roles.classes')
|
||||
local Token = require('utils.token')
|
||||
local Task = require('utils.task')
|
||||
local SurfacesCommon = require('maps.pirates.surfaces.common')
|
||||
local BottomFrame = require('utils.gui.bottom_frame')
|
||||
local CreatedEvents = require('utils.created_events')
|
||||
|
||||
local Public = {}
|
||||
local enum = {
|
||||
@@ -437,7 +437,7 @@ function Public.leave_crew(player, to_lobby, quiet)
|
||||
)
|
||||
player.force = Common.lobby_force_name
|
||||
player.create_character()
|
||||
Event.raise(BottomFrame.events.bottom_quickbar_respawn_raise, { player_index = player.index })
|
||||
Event.raise(CreatedEvents.events.bottom_quickbar_respawn_raise, { player_index = player.index })
|
||||
end
|
||||
|
||||
memory.crewplayerindices = Utils.ordered_table_with_values_removed(memory.crewplayerindices, player.index)
|
||||
|
||||
@@ -15,6 +15,7 @@ local SpamProtection = require('utils.spam_protection')
|
||||
local Utils = require('maps.pirates.utils_local')
|
||||
local CoreData = require('maps.pirates.coredata')
|
||||
local Common = require('maps.pirates.common')
|
||||
local CreatedEvents = require('utils.created_events')
|
||||
|
||||
local module_name = Gui.uid_name()
|
||||
-- local module_name = 'Highscore'
|
||||
@@ -791,6 +792,6 @@ Event.on_init(on_init)
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(Server.events.on_server_started, Public.load_in_scores)
|
||||
Event.add(CreatedEvents.events.on_server_started, Public.load_in_scores)
|
||||
|
||||
return Public
|
||||
|
||||
@@ -3,6 +3,7 @@ local Server = require 'utils.server'
|
||||
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
|
||||
local SoftReset = require 'utils.functions.soft_reset'
|
||||
local Token = require 'utils.token'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local math_random = math.random
|
||||
local table_shuffle = table.shuffle_table
|
||||
@@ -285,7 +286,7 @@ end
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
CreatedEvents.events.on_server_started,
|
||||
function ()
|
||||
local this = ScenarioTable.get_table()
|
||||
if this.settings_applied then
|
||||
|
||||
@@ -5,8 +5,10 @@ local Utils = require 'utils.common'
|
||||
local Global = require 'utils.global'
|
||||
local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local this = {
|
||||
local this =
|
||||
{
|
||||
timers = {},
|
||||
characters = {},
|
||||
characters_unit_numbers = {},
|
||||
@@ -20,14 +22,15 @@ Global.register(
|
||||
end
|
||||
)
|
||||
|
||||
local Public = { events = { on_entity_mined = Event.generate_event_name('on_entity_mined') } }
|
||||
local Public = {}
|
||||
|
||||
local max_keepalive = 54000 -- 15 minutes
|
||||
local remove = table.remove
|
||||
local round = math.round
|
||||
local default_radius = 5
|
||||
|
||||
local armor_names = {
|
||||
local armor_names =
|
||||
{
|
||||
'power-armor-mk2',
|
||||
'power-armor',
|
||||
'modular-armor',
|
||||
@@ -35,7 +38,8 @@ local armor_names = {
|
||||
'light-armor'
|
||||
}
|
||||
|
||||
local weapon_names = {
|
||||
local weapon_names =
|
||||
{
|
||||
['rocket-launcher'] = 'rocket',
|
||||
['submachine-gun'] = { 'uranium-rounds-magazine', 'piercing-rounds-magazine', 'firearm-magazine' },
|
||||
['shotgun'] = { 'piercing-shotgun-shell', 'shotgun-shell' },
|
||||
@@ -43,7 +47,8 @@ local weapon_names = {
|
||||
}
|
||||
local remove_character
|
||||
|
||||
Public.command = {
|
||||
Public.command =
|
||||
{
|
||||
noop = 0,
|
||||
seek_and_destroy_cmd = 1,
|
||||
seek_and_mine_cmd = 2
|
||||
@@ -54,7 +59,8 @@ local clear_corpse_token =
|
||||
function (event)
|
||||
local position = event.position
|
||||
local surface = game.get_surface(event.surface_index)
|
||||
local search_info = {
|
||||
local search_info =
|
||||
{
|
||||
type = 'character-corpse',
|
||||
position = position,
|
||||
radius = 1
|
||||
@@ -125,7 +131,8 @@ end
|
||||
local function add_character(player_index, entity, render_id, data)
|
||||
local index = #this.characters + 1
|
||||
if not this.characters[index] then
|
||||
this.characters[index] = {
|
||||
this.characters[index] =
|
||||
{
|
||||
player_index = player_index,
|
||||
index = index,
|
||||
unit_number = entity.unit_number,
|
||||
@@ -185,7 +192,8 @@ local function get_dir(src, dest)
|
||||
local dest_x = Utils.get_axis(dest, 'x')
|
||||
local dest_y = Utils.get_axis(dest, 'y')
|
||||
|
||||
local step = {
|
||||
local step =
|
||||
{
|
||||
x = nil,
|
||||
y = nil
|
||||
}
|
||||
@@ -211,7 +219,8 @@ local function get_dir(src, dest)
|
||||
end
|
||||
|
||||
local function move_to(entity, target, min_distance)
|
||||
local state = {
|
||||
local state =
|
||||
{
|
||||
walking = false
|
||||
}
|
||||
|
||||
@@ -219,7 +228,8 @@ local function move_to(entity, target, min_distance)
|
||||
if min_distance < distance then
|
||||
local dir = get_dir(entity.position, target.position)
|
||||
if dir then
|
||||
state = {
|
||||
state =
|
||||
{
|
||||
walking = true,
|
||||
direction = dir
|
||||
}
|
||||
@@ -269,7 +279,8 @@ end
|
||||
|
||||
local function shoot_at(entity, target)
|
||||
entity.selected = target
|
||||
entity.shooting_state = {
|
||||
entity.shooting_state =
|
||||
{
|
||||
state = defines.shooting.shooting_enemies,
|
||||
position = target.position
|
||||
}
|
||||
@@ -280,7 +291,7 @@ local function check_progress_and_raise_event(data)
|
||||
if not data.raised_event then
|
||||
data.raised_event = true
|
||||
Event.raise(
|
||||
Public.events.on_entity_mined,
|
||||
CreatedEvents.events.on_entity_mined,
|
||||
{
|
||||
player_index = data.player_index,
|
||||
entity = data.entity.selected,
|
||||
@@ -298,7 +309,8 @@ local function mine_entity(data, target)
|
||||
end
|
||||
|
||||
local function shoot_stop(entity)
|
||||
entity.shooting_state = {
|
||||
entity.shooting_state =
|
||||
{
|
||||
state = defines.shooting.not_shooting,
|
||||
position = { 0, 0 }
|
||||
}
|
||||
@@ -395,15 +407,18 @@ local function seek_and_mine(data)
|
||||
position = player.position
|
||||
end
|
||||
|
||||
local search_info = {
|
||||
local search_info =
|
||||
{
|
||||
position = position,
|
||||
radius = data.radius,
|
||||
type = {
|
||||
type =
|
||||
{
|
||||
'simple-entity-with-owner',
|
||||
'simple-entity',
|
||||
'tree'
|
||||
},
|
||||
force = {
|
||||
force =
|
||||
{
|
||||
'neutral'
|
||||
}
|
||||
}
|
||||
@@ -463,7 +478,8 @@ local function seek_enemy_and_destroy(data)
|
||||
return
|
||||
end
|
||||
|
||||
local search_info = {
|
||||
local search_info =
|
||||
{
|
||||
type = { 'unit', 'unit-spawner', 'turret' },
|
||||
position = entity.position,
|
||||
radius = data.radius,
|
||||
@@ -552,10 +568,12 @@ function Public.create_char(data)
|
||||
local index = #this.characters + 1
|
||||
|
||||
local render_id =
|
||||
rendering.draw_text {
|
||||
rendering.draw_text
|
||||
{
|
||||
text = player.name .. "'s drone #" .. index,
|
||||
surface = player.surface,
|
||||
target = {
|
||||
target =
|
||||
{
|
||||
entity = entity,
|
||||
offset = { 0, -2.25 },
|
||||
},
|
||||
|
||||
@@ -9,6 +9,7 @@ local Event = require 'utils.event'
|
||||
local BottomFrame = require 'utils.gui.bottom_frame'
|
||||
local Gui = require 'utils.gui'
|
||||
local Task = require 'utils.task_token'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local auto_stash_button_name = Gui.uid_name()
|
||||
local floor = math.floor
|
||||
@@ -230,7 +231,7 @@ local function get_nearby_chests(player, a, furnace, wagon)
|
||||
|
||||
if furnace then
|
||||
container_type = { 'furnace' }
|
||||
inventory_type = defines.inventory.furnace_source
|
||||
inventory_type = defines.inventory.crafter_input
|
||||
end
|
||||
if wagon then
|
||||
container_type = { 'cargo-wagon', 'logistic-container' }
|
||||
@@ -982,7 +983,7 @@ Event.on_init(do_whitelist)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
Event.add(
|
||||
BottomFrame.events.bottom_quickbar_location_changed,
|
||||
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||
function (event)
|
||||
if not this.enabled then
|
||||
return
|
||||
|
||||
@@ -11,6 +11,7 @@ local Global = require 'utils.global'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Server = require 'utils.server'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local floor = math.floor
|
||||
local insert = table.insert
|
||||
@@ -19,11 +20,6 @@ local sqrt = math.sqrt
|
||||
local round = math.round
|
||||
local Public = {}
|
||||
|
||||
Public.events =
|
||||
{
|
||||
custom_on_entity_died = Event.generate_event_name('custom_on_entity_died')
|
||||
}
|
||||
|
||||
local this =
|
||||
{
|
||||
enabled = true,
|
||||
@@ -369,13 +365,13 @@ local function on_entity_damaged(event)
|
||||
|
||||
if cause then
|
||||
if cause.valid then
|
||||
Event.raise(Public.events.custom_on_entity_died, event)
|
||||
Event.raise(CreatedEvents.events.custom_on_entity_died, event)
|
||||
biter.die(cause.force, cause)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Event.raise(Public.events.custom_on_entity_died, event)
|
||||
Event.raise(CreatedEvents.events.custom_on_entity_died, event)
|
||||
biter.die(biter.force)
|
||||
end
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ local Alert = require 'utils.alert'
|
||||
local Event = require 'utils.event'
|
||||
local Task = require 'utils.task_token'
|
||||
local Config = require 'utils.gui.config'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local this =
|
||||
{
|
||||
@@ -26,7 +27,7 @@ Global.register(
|
||||
end
|
||||
)
|
||||
|
||||
local Public = { events = { remove_surface = Event.generate_event_name('remove_surface') } }
|
||||
local Public = {}
|
||||
local remove = table.remove
|
||||
local insert = table.insert
|
||||
|
||||
@@ -162,7 +163,7 @@ function Public.dump_expired_players()
|
||||
player_inv[4] = target.get_inventory(defines.inventory.character_ammo)
|
||||
player_inv[5] = target.get_inventory(defines.inventory.character_trash)
|
||||
if this.offline_players_surface_removal then
|
||||
Event.raise(this.events.remove_surface, { target = target })
|
||||
Event.raise(CreatedEvents.events.remove_surface, { target = target })
|
||||
end
|
||||
|
||||
local found_items = false
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
--luacheck: ignore
|
||||
local Event = require 'utils.event'
|
||||
local HDT = require 'modules.hidden_dimension.table'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local Public = {}
|
||||
Public.events = {
|
||||
reset_game = Event.generate_event_name('reset_game'),
|
||||
init_surfaces = Event.generate_event_name('init_surfaces')
|
||||
}
|
||||
|
||||
--- If true then surface will be picked to nauvis.
|
||||
Public.enable_auto_init = true
|
||||
@@ -30,7 +27,7 @@ end
|
||||
local function teleport(entity, pos, surface)
|
||||
local sane_pos = surface.find_non_colliding_position(entity.name, pos, 0, 1, 1)
|
||||
if entity.type == 'character' then
|
||||
for k, v in pairs(game.players) do
|
||||
for _, v in pairs(game.players) do
|
||||
if v.character == entity then
|
||||
v.teleport(sane_pos, surface)
|
||||
end
|
||||
@@ -44,7 +41,7 @@ local function clear_surroundings(surface, pos)
|
||||
if entity[i].type ~= 'character' then
|
||||
entity[i].destroy()
|
||||
else
|
||||
teleport(entity[i], {0, 0}, entity[i].surface)
|
||||
teleport(entity[i], { 0, 0 }, entity[i].surface)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -69,13 +66,13 @@ local function transport_resources(container1, container2, transport_type)
|
||||
local temperature = 0
|
||||
|
||||
local function test_for(temp)
|
||||
local count = container.remove_fluid({name = 'steam', amount = 1, temperature = temp})
|
||||
local count = container.remove_fluid({ name = 'steam', amount = 1, temperature = temp })
|
||||
if count ~= 0 then
|
||||
temperature = temp
|
||||
else
|
||||
return
|
||||
end
|
||||
container.insert_fluid({name = 'steam', amount = count, temperature = temp})
|
||||
container.insert_fluid({ name = 'steam', amount = count, temperature = temp })
|
||||
end
|
||||
|
||||
test_for(15)
|
||||
@@ -114,13 +111,13 @@ local function transport_resources(container1, container2, transport_type)
|
||||
temp = math_max(at, bt)
|
||||
container1.clear_fluid_inside()
|
||||
container2.clear_fluid_inside()
|
||||
container1.insert_fluid({name = name1, amount = v, temperature = temp})
|
||||
container2.insert_fluid({name = name2, amount = v, temperature = temp})
|
||||
container1.insert_fluid({ name = name1, amount = v, temperature = temp })
|
||||
container2.insert_fluid({ name = name2, amount = v, temperature = temp })
|
||||
else
|
||||
container1.clear_fluid_inside()
|
||||
container2.clear_fluid_inside()
|
||||
container1.insert_fluid({name = name1, amount = v})
|
||||
container2.insert_fluid({name = name2, amount = v})
|
||||
container1.insert_fluid({ name = name1, amount = v })
|
||||
container2.insert_fluid({ name = name2, amount = v })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -128,10 +125,10 @@ local function transport_resources(container1, container2, transport_type)
|
||||
local chest1 = container1.get_inventory(defines.inventory.chest)
|
||||
local chest2 = container2.get_inventory(defines.inventory.chest)
|
||||
for k, v in pairs(chest1.get_contents()) do
|
||||
local t = {name = k, count = v}
|
||||
local t = { name = k, count = v }
|
||||
local c = chest2.insert(t)
|
||||
if (c > 0) then
|
||||
chest1.remove({name = k, count = c})
|
||||
chest1.remove({ name = k, count = c })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -168,21 +165,21 @@ local function create_underground_floor(surface, size, going_down)
|
||||
local tiles = {}
|
||||
for i = 0, area.x - 1 do
|
||||
for j = 0, area.y - 1 do
|
||||
table_insert(tiles, {name = floor_type, position = {i + pos.x, j + pos.y}})
|
||||
table_insert(tiles, { name = floor_type, position = { i + pos.x, j + pos.y } })
|
||||
end
|
||||
end
|
||||
|
||||
surface.set_tiles(tiles)
|
||||
end
|
||||
tile_generation('tutorial-grid', {x = 0, y = 0}, {x = -size / 2, y = -size / 2}, {x = size - 1, y = size})
|
||||
tile_generation('black-refined-concrete', {x = 0, y = 0}, {x = -size / 2, y = -size / 2}, {x = size - 1, y = size})
|
||||
tile_generation('hazard-concrete-left', {x = 0, y = 0}, {x = -3, y = -7}, {x = 6, y = 3})
|
||||
tile_generation('tutorial-grid', { x = 0, y = 0 }, { x = -size / 2, y = -size / 2 }, { x = size - 1, y = size })
|
||||
tile_generation('black-refined-concrete', { x = 0, y = 0 }, { x = -size / 2, y = -size / 2 }, { x = size - 1, y = size })
|
||||
tile_generation('hazard-concrete-left', { x = 0, y = 0 }, { x = -3, y = -7 }, { x = 6, y = 3 })
|
||||
|
||||
if going_down then
|
||||
tile_generation('hazard-concrete-left', {x = 0, y = 0}, {x = -3, y = 3}, {x = 6, y = 3})
|
||||
tile_generation('hazard-concrete-left', {x = 0, y = 0}, {x = -2, y = -2}, {x = 4, y = 3})
|
||||
tile_generation('hazard-concrete-left', { x = 0, y = 0 }, { x = -3, y = 3 }, { x = 6, y = 3 })
|
||||
tile_generation('hazard-concrete-left', { x = 0, y = 0 }, { x = -2, y = -2 }, { x = 4, y = 3 })
|
||||
else
|
||||
tile_generation('black-refined-concrete', {x = 0, y = 0}, {x = -size / 2, y = -size / 2}, {x = size - 1, y = size})
|
||||
tile_generation('black-refined-concrete', { x = 0, y = 0 }, { x = -size / 2, y = -size / 2 }, { x = size - 1, y = size })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -203,7 +200,8 @@ local function create_main_surface(rebuild)
|
||||
|
||||
if rebuild then
|
||||
hidden_dimension.main_surface.reference =
|
||||
surface.create_entity {
|
||||
surface.create_entity
|
||||
{
|
||||
name = 'car',
|
||||
position = position,
|
||||
force = game.forces.enemy,
|
||||
@@ -212,21 +210,22 @@ local function create_main_surface(rebuild)
|
||||
hidden_dimension.main_surface.reference.minable = false
|
||||
hidden_dimension.main_surface.reference.destructible = false
|
||||
hidden_dimension.main_surface.reference.operable = false
|
||||
hidden_dimension.main_surface.reference.get_inventory(defines.inventory.fuel).insert({name = 'coal', count = 100})
|
||||
hidden_dimension.main_surface.reference.get_inventory(defines.inventory.fuel).insert({ name = 'coal', count = 100 })
|
||||
return
|
||||
end
|
||||
if not hidden_dimension.main_surface.reference or not hidden_dimension.main_surface.reference.valid then
|
||||
hidden_dimension.main_surface.reference =
|
||||
surface.create_entity {
|
||||
surface.create_entity
|
||||
{
|
||||
name = 'car',
|
||||
position = {position.x, position.y - 23},
|
||||
position = { position.x, position.y - 23 },
|
||||
force = game.forces.enemy,
|
||||
create_build_effect_smoke = false
|
||||
}
|
||||
hidden_dimension.main_surface.reference.minable = false
|
||||
hidden_dimension.main_surface.reference.destructible = false
|
||||
hidden_dimension.main_surface.reference.operable = false
|
||||
hidden_dimension.main_surface.reference.get_inventory(defines.inventory.fuel).insert({name = 'coal', count = 100})
|
||||
hidden_dimension.main_surface.reference.get_inventory(defines.inventory.fuel).insert({ name = 'coal', count = 100 })
|
||||
if hidden_dimension.logistic_research_level == 0 then
|
||||
return
|
||||
end
|
||||
@@ -237,10 +236,10 @@ end
|
||||
local function create_underground_surfaces()
|
||||
local function create_underground(floor_table, name, going_down)
|
||||
--local underground_level
|
||||
floor_table.surface = game.create_surface(name, {width = 14, height = 16})
|
||||
floor_table.surface = game.create_surface(name, { width = 14, height = 16 })
|
||||
floor_table.surface.always_day = true
|
||||
floor_table.surface.daytime = 0.5
|
||||
floor_table.surface.request_to_generate_chunks({0, 0}, 10)
|
||||
floor_table.surface.request_to_generate_chunks({ 0, 0 }, 10)
|
||||
floor_table.surface.force_generate_chunk_requests()
|
||||
local clear_ent = floor_table.surface.find_entities()
|
||||
for i, _ in ipairs(clear_ent) do
|
||||
@@ -249,14 +248,15 @@ local function create_underground_surfaces()
|
||||
floor_table.name = name
|
||||
floor_table.size = 16
|
||||
|
||||
floor_table.surface.destroy_decoratives({area = {{-floor_table.size, -floor_table.size}, {floor_table.size, floor_table.size}}})
|
||||
floor_table.surface.destroy_decoratives({ area = { { -floor_table.size, -floor_table.size }, { floor_table.size, floor_table.size } } })
|
||||
|
||||
create_underground_floor(floor_table.surface, floor_table.size, going_down)
|
||||
|
||||
floor_table.going_up.reference =
|
||||
floor_table.surface.create_entity {
|
||||
floor_table.surface.create_entity
|
||||
{
|
||||
name = 'car',
|
||||
position = {0, -6},
|
||||
position = { 0, -6 },
|
||||
force = game.forces.enemy,
|
||||
create_build_effect_smoke = false
|
||||
}
|
||||
@@ -267,7 +267,7 @@ local function create_underground_surfaces()
|
||||
intensity = 1,
|
||||
minimum_darkness = 0,
|
||||
oriented = true,
|
||||
color = {255, 255, 255},
|
||||
color = { 255, 255, 255 },
|
||||
target = floor_table.going_up.reference,
|
||||
surface = floor_table.surface,
|
||||
visible = true,
|
||||
@@ -277,20 +277,21 @@ local function create_underground_surfaces()
|
||||
floor_table.going_up.reference.minable = false
|
||||
floor_table.going_up.reference.destructible = false
|
||||
floor_table.going_up.reference.operable = false
|
||||
floor_table.going_up.reference.get_inventory(defines.inventory.fuel).insert({name = 'coal', count = 100})
|
||||
floor_table.going_up.reference.get_inventory(defines.inventory.fuel).insert({ name = 'coal', count = 100 })
|
||||
|
||||
if going_down then
|
||||
floor_table.going_down.reference =
|
||||
floor_table.surface.create_entity {
|
||||
floor_table.surface.create_entity
|
||||
{
|
||||
name = 'car',
|
||||
position = {0, 4},
|
||||
position = { 0, 4 },
|
||||
force = game.forces.enemy,
|
||||
create_build_effect_smoke = false
|
||||
}
|
||||
floor_table.going_down.reference.minable = false
|
||||
floor_table.going_down.reference.destructible = false
|
||||
floor_table.going_down.reference.operable = false
|
||||
floor_table.going_down.reference.get_inventory(defines.inventory.fuel).insert({name = 'coal', count = 100})
|
||||
floor_table.going_down.reference.get_inventory(defines.inventory.fuel).insert({ name = 'coal', count = 100 })
|
||||
|
||||
rendering.draw_light(
|
||||
{
|
||||
@@ -299,7 +300,7 @@ local function create_underground_surfaces()
|
||||
intensity = 1,
|
||||
minimum_darkness = 0,
|
||||
oriented = true,
|
||||
color = {255, 255, 255},
|
||||
color = { 255, 255, 255 },
|
||||
target = floor_table.going_down.reference,
|
||||
surface = floor_table.surface,
|
||||
visible = true,
|
||||
@@ -350,13 +351,13 @@ local function logistic_update()
|
||||
local function energy_update(t)
|
||||
local g = 0
|
||||
local c = 0
|
||||
for k, v in pairs(t) do
|
||||
for _, v in pairs(t) do
|
||||
if (v.valid) then
|
||||
g = g + v.energy
|
||||
c = c + v.electric_buffer_size
|
||||
end
|
||||
end
|
||||
for k, v in pairs(t) do
|
||||
for _, v in pairs(t) do
|
||||
if (v.valid) then
|
||||
local r = (v.electric_buffer_size / c)
|
||||
v.energy = g * r
|
||||
@@ -439,24 +440,26 @@ local function through_teleporter_update()
|
||||
end
|
||||
|
||||
local function surface_play_sound(sound_path, surface, pos)
|
||||
for k, v in pairs(game.connected_players) do
|
||||
for _, v in pairs(game.connected_players) do
|
||||
if v.surface.name == surface then
|
||||
v.play_sound {path = sound_path, position = pos}
|
||||
v.play_sound { path = sound_path, position = pos }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local to_teleport_out_entity_list =
|
||||
source.surface.find_entities_filtered {
|
||||
area = {
|
||||
{source.position.x - 1.1, source.position.y - 1.1},
|
||||
{source.position.x + 1.1, source.position.y + 1.1}
|
||||
source.surface.find_entities_filtered
|
||||
{
|
||||
area =
|
||||
{
|
||||
{ source.position.x - 1.1, source.position.y - 1.1 },
|
||||
{ source.position.x + 1.1, source.position.y + 1.1 }
|
||||
},
|
||||
type = 'character'
|
||||
}
|
||||
for i, v in ipairs(to_teleport_out_entity_list) do
|
||||
for _, v in ipairs(to_teleport_out_entity_list) do
|
||||
if v.type == 'character' then
|
||||
local pos = {x = destination.position.x, y = destination.position.y}
|
||||
local pos = { x = destination.position.x, y = destination.position.y }
|
||||
if v.position.y < source.position.y then
|
||||
pos.y = pos.y + 2
|
||||
else
|
||||
@@ -487,7 +490,7 @@ end
|
||||
|
||||
local function on_entity_cloned(event)
|
||||
local hidden_dimension = HDT.get('hidden_dimension')
|
||||
for k, v in pairs(hidden_dimension.main_surface.entities) do
|
||||
for _, v in pairs(hidden_dimension.main_surface.entities) do
|
||||
if event.source == v then
|
||||
event.destination.destroy()
|
||||
end
|
||||
@@ -527,11 +530,11 @@ end
|
||||
function Public.init(args)
|
||||
local hidden_dimension = HDT.get('hidden_dimension')
|
||||
if args then
|
||||
hidden_dimension.position = args.position or {x = 0, y = 3}
|
||||
hidden_dimension.position = args.position or { x = 0, y = 3 }
|
||||
hidden_dimension.hd_surface = args.hd_surface or 'nauvis'
|
||||
else
|
||||
hidden_dimension.hd_surface = 'nauvis'
|
||||
hidden_dimension.position = {x = 0, y = 3}
|
||||
hidden_dimension.position = { x = 0, y = 3 }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -576,12 +579,13 @@ function Public.create_chests(surface, level, build_type)
|
||||
|
||||
local function add_container(name, pos, direction, type)
|
||||
local container_entity
|
||||
container_entity = logistic_building.surface.find_entity(name, {logistic_building.position.x + pos.x, logistic_building.position.y + pos.y})
|
||||
container_entity = logistic_building.surface.find_entity(name, { logistic_building.position.x + pos.x, logistic_building.position.y + pos.y })
|
||||
if container_entity == nil then
|
||||
local pos2 = {logistic_building.position.x + pos.x, logistic_building.position.y + pos.y}
|
||||
local pos2 = { logistic_building.position.x + pos.x, logistic_building.position.y + pos.y }
|
||||
if name == 'loader' or name == 'fast-loader' or name == 'express-loader' then
|
||||
container_entity =
|
||||
logistic_building.surface.create_entity {
|
||||
logistic_building.surface.create_entity
|
||||
{
|
||||
name = name,
|
||||
position = pos2,
|
||||
force = game.forces.player,
|
||||
@@ -589,17 +593,17 @@ function Public.create_chests(surface, level, build_type)
|
||||
}
|
||||
container_entity.direction = direction
|
||||
elseif name == 'pipe-to-ground' then
|
||||
container_entity = logistic_building.surface.create_entity {name = name, position = pos2, force = game.forces.player}
|
||||
container_entity = logistic_building.surface.create_entity { name = name, position = pos2, force = game.forces.player }
|
||||
container_entity.direction = direction
|
||||
elseif name == energy then
|
||||
container_entity = logistic_building.surface.create_entity {name = name, position = pos2, force = game.forces.player}
|
||||
container_entity = logistic_building.surface.create_entity { name = name, position = pos2, force = game.forces.player }
|
||||
container_entity.minable = false
|
||||
container_entity.destructible = false
|
||||
container_entity.operable = false
|
||||
container_entity.power_production = 0
|
||||
container_entity.electric_buffer_size = 10000000
|
||||
else
|
||||
container_entity = logistic_building.surface.create_entity {name = name, position = pos2, force = game.forces.player}
|
||||
container_entity = logistic_building.surface.create_entity { name = name, position = pos2, force = game.forces.player }
|
||||
end
|
||||
end
|
||||
container_entity.minable = false
|
||||
@@ -607,20 +611,20 @@ function Public.create_chests(surface, level, build_type)
|
||||
return container_entity
|
||||
end
|
||||
|
||||
surface.entities.loader_1 = add_container(loader, {x = -2, y = 0}, direction1, rotation1)
|
||||
surface.entities.loader_2 = add_container(loader, {x = 1, y = 0}, direction2, rotation2)
|
||||
surface.entities.chest_1 = add_container(chest, {x = -2, y = 1})
|
||||
surface.entities.chest_2 = add_container(chest, {x = 1, y = 1})
|
||||
surface.entities.pipe_1 = add_container('pipe-to-ground', {x = -3, y = 1}, defines.direction.west)
|
||||
surface.entities.pipe_2 = add_container('pipe-to-ground', {x = 2, y = 1}, defines.direction.east)
|
||||
surface.entities.loader_1 = add_container(loader, { x = -2, y = 0 }, direction1, rotation1)
|
||||
surface.entities.loader_2 = add_container(loader, { x = 1, y = 0 }, direction2, rotation2)
|
||||
surface.entities.chest_1 = add_container(chest, { x = -2, y = 1 })
|
||||
surface.entities.chest_2 = add_container(chest, { x = 1, y = 1 })
|
||||
surface.entities.pipe_1 = add_container('pipe-to-ground', { x = -3, y = 1 }, defines.direction.west)
|
||||
surface.entities.pipe_2 = add_container('pipe-to-ground', { x = 2, y = 1 }, defines.direction.east)
|
||||
if level > 1 then
|
||||
surface.entities.pipe_3 = add_container('pipe-to-ground', {x = -3, y = 0}, defines.direction.west)
|
||||
surface.entities.pipe_4 = add_container('pipe-to-ground', {x = 2, y = 0}, defines.direction.east)
|
||||
surface.entities.pipe_3 = add_container('pipe-to-ground', { x = -3, y = 0 }, defines.direction.west)
|
||||
surface.entities.pipe_4 = add_container('pipe-to-ground', { x = 2, y = 0 }, defines.direction.east)
|
||||
if level > 2 then
|
||||
local hidden_dimension = HDT.get('hidden_dimension')
|
||||
hidden_dimension.energy[#hidden_dimension.energy + 1] = add_container(energy, {x = 0, y = 0})
|
||||
surface.entities.pipe_5 = add_container('pipe-to-ground', {x = -3, y = -1}, defines.direction.west)
|
||||
surface.entities.pipe_6 = add_container('pipe-to-ground', {x = 2, y = -1}, defines.direction.east)
|
||||
hidden_dimension.energy[#hidden_dimension.energy + 1] = add_container(energy, { x = 0, y = 0 })
|
||||
surface.entities.pipe_5 = add_container('pipe-to-ground', { x = -3, y = -1 }, defines.direction.west)
|
||||
surface.entities.pipe_6 = add_container('pipe-to-ground', { x = 2, y = -1 }, defines.direction.east)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -629,7 +633,7 @@ function Public.upgrade_transport_buildings(level)
|
||||
local function upgrade(transport, building_type)
|
||||
local function copy_chest_content(content, chest)
|
||||
for k, v in pairs(content) do
|
||||
chest.insert({name = k, count = v})
|
||||
chest.insert({ name = k, count = v })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -644,17 +648,17 @@ function Public.upgrade_transport_buildings(level)
|
||||
local chest_2_inventory = transport.entities.chest_2.get_inventory(defines.inventory.chest).get_contents()
|
||||
|
||||
local pos = transport.reference.position
|
||||
local logistic_bb = {{pos.x - 5, pos.y - 5}, {pos.x + 5, pos.y + 5}}
|
||||
local logistic_bb = { { pos.x - 5, pos.y - 5 }, { pos.x + 5, pos.y + 5 } }
|
||||
|
||||
local surface = transport.reference.surface
|
||||
|
||||
clear_surroundings(transport.reference.surface, logistic_bb)
|
||||
|
||||
transport.reference = surface.create_entity {name = building_type, position = pos, force = game.forces.enemy}
|
||||
transport.reference = surface.create_entity { name = building_type, position = pos, force = game.forces.enemy }
|
||||
transport.reference.minable = false
|
||||
transport.reference.destructible = false
|
||||
transport.reference.operable = false
|
||||
transport.reference.get_inventory(defines.inventory.fuel).insert({name = 'coal', count = 100})
|
||||
transport.reference.get_inventory(defines.inventory.fuel).insert({ name = 'coal', count = 100 })
|
||||
|
||||
Public.create_chests(transport, level, transport.transport_type)
|
||||
|
||||
@@ -687,7 +691,7 @@ Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_tick, on_tick)
|
||||
Event.add(defines.events.on_research_finished, on_research_finished)
|
||||
Event.add(defines.events.on_entity_cloned, on_entity_cloned)
|
||||
Event.add(Public.events.reset_game, reset_surface)
|
||||
Event.add(Public.events.init_surfaces, create_underground_surfaces)
|
||||
Event.add(CreatedEvents.events.reset_game, reset_surface)
|
||||
Event.add(CreatedEvents.events.init_surfaces, create_underground_surfaces)
|
||||
|
||||
return Public
|
||||
|
||||
@@ -10,6 +10,7 @@ local StatData = require 'utils.datastore.statistics'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Math2D = require 'math2d'
|
||||
local Color = require 'utils.color_presets'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
StatData.add_normalize('spells', 'Spells casted')
|
||||
|
||||
@@ -1043,7 +1044,7 @@ local function on_player_used_capsule_custom(event)
|
||||
rpg_t.amount = 1
|
||||
end
|
||||
|
||||
Event.raise(Public.events.on_spell_cast_success, { player_index = player.index, spell_name = spell.entityName, amount = rpg_t.amount })
|
||||
Event.raise(CreatedEvents.events.on_spell_cast_success, { player_index = player.index, spell_name = spell.entityName, amount = rpg_t.amount })
|
||||
|
||||
StatData.get_data(player):increase('spells')
|
||||
|
||||
@@ -1223,7 +1224,7 @@ local function on_player_used_capsule(event)
|
||||
rpg_t.amount = 1
|
||||
end
|
||||
|
||||
Event.raise(Public.events.on_spell_cast_success, { player_index = player.index, spell_name = spell.entityName, amount = rpg_t.amount })
|
||||
Event.raise(CreatedEvents.events.on_spell_cast_success, { player_index = player.index, spell_name = spell.entityName, amount = rpg_t.amount })
|
||||
|
||||
StatData.get_data(player):increase('spells')
|
||||
|
||||
|
||||
@@ -37,11 +37,6 @@ Global.register(
|
||||
)
|
||||
|
||||
local Public = {}
|
||||
Public.events =
|
||||
{
|
||||
on_spell_cast_success = Event.generate_event_name('on_spell_cast_success'),
|
||||
on_spell_cast_failure = Event.generate_event_name('on_spell_cast_failure')
|
||||
}
|
||||
|
||||
Public.points_per_level = 5
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ local Public = require 'modules.wave_defense.table'
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local this = {}
|
||||
|
||||
@@ -23,7 +24,8 @@ for a = 48, 1, -1 do
|
||||
spawn_amount_rolls[#spawn_amount_rolls + 1] = floor(a ^ 5)
|
||||
end
|
||||
|
||||
local random_particles = {
|
||||
local random_particles =
|
||||
{
|
||||
'dirt-2-stone-particle-medium',
|
||||
'dirt-4-dust-particle',
|
||||
'coal-particle'
|
||||
@@ -99,7 +101,7 @@ local function spawn_biters(data)
|
||||
BiterHealthBooster.add_unit(unit, final_health)
|
||||
end
|
||||
|
||||
Event.raise(Public.events.on_entity_created, { entity = unit, boss_unit = false })
|
||||
Event.raise(CreatedEvents.events.on_entity_created, { entity = unit, boss_unit = false })
|
||||
end
|
||||
|
||||
local function spawn_worms(data)
|
||||
@@ -155,7 +157,8 @@ function Public.buried_biter(surface, position, max, entity_name, force)
|
||||
this[game.tick + t] = {}
|
||||
end
|
||||
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] =
|
||||
{
|
||||
callback = 'create_particles',
|
||||
data = { surface = surface, position = { x = position.x, y = position.y }, amount = 4 }
|
||||
}
|
||||
@@ -163,7 +166,8 @@ function Public.buried_biter(surface, position, max, entity_name, force)
|
||||
if t > 90 then
|
||||
if t % 30 == 29 then
|
||||
a = a + 1
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] =
|
||||
{
|
||||
callback = 'spawn_biters',
|
||||
data = { surface = surface, position = { x = position.x, y = position.y }, entity_name = entity_name, force = force or 'enemy' }
|
||||
}
|
||||
@@ -202,13 +206,15 @@ function Public.buried_worm(surface, position)
|
||||
this[game.tick + t] = {}
|
||||
end
|
||||
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] =
|
||||
{
|
||||
callback = 'create_particles',
|
||||
data = { surface = surface, position = { x = position.x, y = position.y }, amount = 4 }
|
||||
}
|
||||
|
||||
if not a then
|
||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
||||
this[game.tick + t][#this[game.tick + t] + 1] =
|
||||
{
|
||||
callback = 'spawn_worms',
|
||||
data = { surface = surface, position = { x = position.x, y = position.y } }
|
||||
}
|
||||
@@ -217,7 +223,8 @@ function Public.buried_worm(surface, position)
|
||||
end
|
||||
end
|
||||
|
||||
local callbacks = {
|
||||
local callbacks =
|
||||
{
|
||||
['create_particles'] = create_particles,
|
||||
['spawn_biters'] = spawn_biters,
|
||||
['spawn_worms'] = spawn_worms
|
||||
|
||||
@@ -6,9 +6,8 @@ local Public = require 'modules.wave_defense.table'
|
||||
local Difficulty = require 'modules.difficulty_vote_by_amount'
|
||||
local Beams = require 'modules.render_beam'
|
||||
local Server = require 'utils.server'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local de = defines.events
|
||||
local ev = Public.events
|
||||
local random = math.random
|
||||
local abs = math.abs
|
||||
local floor = math.floor
|
||||
@@ -1163,7 +1162,7 @@ function Public._esp:work(tick)
|
||||
self.last_command = tick + 500
|
||||
|
||||
if this.target_settings.main_target and this.target_settings.main_target.valid and this.target_settings.main_target.name == 'character' then
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1215,14 +1214,14 @@ function Public._esp:work(tick)
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
Event.add(de.on_entity_died, on_entity_died)
|
||||
Event.add(de.on_entity_damaged, on_entity_damaged)
|
||||
Event.add(ev.on_wave_created, on_wave_created)
|
||||
Event.add(ev.on_unit_group_created, on_unit_group_created)
|
||||
Event.add(ev.on_entity_created, on_entity_created)
|
||||
Event.add(ev.on_target_aquired, on_target_aquired)
|
||||
Event.add(ev.on_evolution_factor_changed, on_evolution_factor_changed)
|
||||
Event.add(ev.on_game_reset, on_init)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
Event.add(CreatedEvents.events.on_wave_created, on_wave_created)
|
||||
Event.add(CreatedEvents.events.on_unit_group_created, on_unit_group_created)
|
||||
Event.add(CreatedEvents.events.on_entity_created, on_entity_created)
|
||||
Event.add(CreatedEvents.events.on_target_aquired, on_target_aquired)
|
||||
Event.add(CreatedEvents.events.on_evolution_factor_changed, on_evolution_factor_changed)
|
||||
Event.add(CreatedEvents.events.on_game_reset, on_init)
|
||||
Event.on_nth_tick(100, check_states)
|
||||
|
||||
--- This gets values from our table
|
||||
|
||||
@@ -5,6 +5,8 @@ local Difficulty = require 'modules.difficulty_vote_by_amount'
|
||||
local Alert = require 'utils.alert'
|
||||
local Server = require 'utils.server'
|
||||
local Collapse = require 'modules.collapse'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
Collapse.read_tables_only = true
|
||||
|
||||
local random = math.random
|
||||
@@ -381,7 +383,7 @@ local function set_main_target()
|
||||
end
|
||||
|
||||
Public.set('target', sec_target)
|
||||
raise(Public.events.on_target_aquired, { target = target })
|
||||
raise(CreatedEvents.events.on_target_aquired, { target = target })
|
||||
Public.debug_print('set_main_target -- New main target ' .. sec_target.name .. ' at position x' .. sec_target.position.x .. ' y' .. sec_target.position.y .. ' selected.')
|
||||
end
|
||||
|
||||
@@ -432,7 +434,7 @@ local function set_enemy_evolution()
|
||||
|
||||
enemy.set_evolution_factor(evolution_factor, surface_index)
|
||||
|
||||
raise(Public.events.on_evolution_factor_changed, { evolution_factor = evolution_factor })
|
||||
raise(CreatedEvents.events.on_evolution_factor_changed, { evolution_factor = evolution_factor })
|
||||
end
|
||||
|
||||
local function can_units_spawn()
|
||||
@@ -767,7 +769,7 @@ local function set_multi_command()
|
||||
|
||||
local target = Public.get('target')
|
||||
if not valid(target) then
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -874,7 +876,7 @@ local function set_next_wave()
|
||||
Public.set('next_wave', game.tick + wave_interval)
|
||||
end
|
||||
|
||||
raise(Public.events.on_wave_created, event_data)
|
||||
raise(CreatedEvents.events.on_wave_created, event_data)
|
||||
end
|
||||
|
||||
local function reform_group(group)
|
||||
@@ -974,7 +976,7 @@ local function get_main_command(group)
|
||||
|
||||
local target = Public.get('target')
|
||||
if not valid(target) then
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1146,7 +1148,7 @@ local function give_side_commands_to_group()
|
||||
|
||||
local target = Public.get('target')
|
||||
if not valid(target) then
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1165,12 +1167,12 @@ end
|
||||
local function give_main_command_to_group()
|
||||
local target = Public.get('target')
|
||||
if not valid(target) then
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
return
|
||||
end
|
||||
|
||||
-- This is called even if the target is valid
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
|
||||
local generated_units = Public.get('generated_units')
|
||||
for _, group in pairs(generated_units.unit_groups) do
|
||||
@@ -1198,7 +1200,7 @@ local function spawn_unit_group(fs, only_bosses)
|
||||
local target = Public.get('target')
|
||||
if not valid(target) then
|
||||
Public.debug_print('spawn_unit_group - Target was not valid?')
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1292,7 +1294,7 @@ local function spawn_unit_group(fs, only_bosses)
|
||||
end
|
||||
unit_group.add_member(biter)
|
||||
|
||||
raise(Public.events.on_entity_created, { entity = biter, boss_unit = false })
|
||||
raise(CreatedEvents.events.on_entity_created, { entity = biter, boss_unit = false })
|
||||
-- command_to_side_target(unit_group)
|
||||
end
|
||||
end
|
||||
@@ -1322,7 +1324,7 @@ local function spawn_unit_group(fs, only_bosses)
|
||||
break
|
||||
end
|
||||
unit_group.add_member(biter)
|
||||
raise(Public.events.on_entity_created, { entity = biter, boss_unit = true })
|
||||
raise(CreatedEvents.events.on_entity_created, { entity = biter, boss_unit = true })
|
||||
end
|
||||
Public.set('boss_wave', false)
|
||||
end
|
||||
@@ -1343,7 +1345,7 @@ local function spawn_unit_group(fs, only_bosses)
|
||||
break
|
||||
end
|
||||
unit_group.add_member(biter)
|
||||
raise(Public.events.on_entity_created, { entity = biter, boss_unit = true })
|
||||
raise(CreatedEvents.events.on_entity_created, { entity = biter, boss_unit = true })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1354,7 +1356,7 @@ local function spawn_unit_group(fs, only_bosses)
|
||||
Public.set('random_group', unit_group)
|
||||
end
|
||||
Public.set('spot', 'nil')
|
||||
raise(Public.events.on_unit_group_created, event_data)
|
||||
raise(CreatedEvents.events.on_unit_group_created, event_data)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -1362,7 +1364,7 @@ local function spawn_unit_group_simple(fs)
|
||||
local target = Public.get('target')
|
||||
if not valid(target) then
|
||||
Public.debug_print('spawn_unit_group_simple - Target was not valid?')
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1409,7 +1411,7 @@ local function spawn_unit_group_simple(fs)
|
||||
if biter then
|
||||
s = s + 1
|
||||
unit_group.add_member(biter)
|
||||
raise(Public.events.on_entity_created, { entity = biter, boss_unit = is_boss })
|
||||
raise(CreatedEvents.events.on_entity_created, { entity = biter, boss_unit = is_boss })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1436,7 +1438,7 @@ local function check_group_positions()
|
||||
local generated_units = Public.get('generated_units')
|
||||
local target = Public.get('target')
|
||||
if not valid(target) then
|
||||
Event.raise(Public.events.on_primary_target_missing)
|
||||
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1584,7 +1586,7 @@ Event.on_nth_tick(30,
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Public.events.on_biters_evolved,
|
||||
CreatedEvents.events.on_biters_evolved,
|
||||
function (event)
|
||||
if not event then
|
||||
event = { force = game.forces.enemy }
|
||||
@@ -1598,8 +1600,8 @@ Event.add(
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(Public.events.on_spawn_unit_group, spawn_unit_group)
|
||||
Event.add(Public.events.on_spawn_unit_group_simple, spawn_unit_group_simple)
|
||||
Event.add(CreatedEvents.events.on_spawn_unit_group, spawn_unit_group)
|
||||
Event.add(CreatedEvents.events.on_spawn_unit_group_simple, spawn_unit_group_simple)
|
||||
|
||||
Event.on_nth_tick(
|
||||
100,
|
||||
|
||||
@@ -4,23 +4,12 @@ local Gui = require 'utils.gui'
|
||||
local Event = require 'utils.event'
|
||||
local Server = require 'utils.server'
|
||||
|
||||
local this = {
|
||||
local this =
|
||||
{
|
||||
pause_waves_custom_callback = nil,
|
||||
threat_event_custom_callback = nil
|
||||
}
|
||||
local Public = {}
|
||||
Public.events = {
|
||||
on_wave_created = Event.generate_event_name('on_wave_created'),
|
||||
on_unit_group_created = Event.generate_event_name('on_unit_group_created'),
|
||||
on_evolution_factor_changed = Event.generate_event_name('on_evolution_factor_changed'),
|
||||
on_game_reset = Event.generate_event_name('on_game_reset'),
|
||||
on_target_aquired = Event.generate_event_name('on_target_aquired'),
|
||||
on_primary_target_missing = Event.generate_event_name('on_primary_target_missing'),
|
||||
on_entity_created = Event.generate_event_name('on_entity_created'),
|
||||
on_biters_evolved = Event.generate_event_name('on_biters_evolved'),
|
||||
on_spawn_unit_group = Event.generate_event_name('on_spawn_unit_group'),
|
||||
on_spawn_unit_group_simple = Event.generate_event_name('on_spawn_unit_group_simple')
|
||||
}
|
||||
local insert = table.insert
|
||||
|
||||
Global.register(
|
||||
@@ -31,7 +20,8 @@ Global.register(
|
||||
)
|
||||
|
||||
Public.group_size_modifier_raffle = {}
|
||||
local group_size_chances = {
|
||||
local group_size_chances =
|
||||
{
|
||||
{ 4, 0.4 },
|
||||
{ 5, 0.5 },
|
||||
{ 6, 0.6 },
|
||||
@@ -87,7 +77,8 @@ function Public.reset_wave_defense()
|
||||
this.max_biter_age = 3600 * 60
|
||||
this.nest_building_density = 48
|
||||
this.next_wave = game.tick + 3600 * 20
|
||||
this.enable_grace_time = {
|
||||
this.enable_grace_time =
|
||||
{
|
||||
enabled = true,
|
||||
set = nil
|
||||
}
|
||||
@@ -116,7 +107,8 @@ function Public.reset_wave_defense()
|
||||
this.worm_raffle = {}
|
||||
this.alert_boss_wave = false
|
||||
this.remove_entities = false
|
||||
this.pause_waves = {
|
||||
this.pause_waves =
|
||||
{
|
||||
index = 0
|
||||
}
|
||||
this.enable_random_spawn_positions = false
|
||||
@@ -131,27 +123,32 @@ function Public.reset_wave_defense()
|
||||
this.increase_max_active_unit_groups = false
|
||||
this.increase_health_per_wave = false
|
||||
this.fill_tiles_so_biter_can_path = true
|
||||
this.modified_unit_health = {
|
||||
this.modified_unit_health =
|
||||
{
|
||||
current_value = 1.2,
|
||||
limit_value = 150,
|
||||
health_increase_per_boss_wave = 0.5 -- wave % 25 == 0 at wave 2k boost is at 41.2
|
||||
}
|
||||
this.modified_boss_unit_health = {
|
||||
this.modified_boss_unit_health =
|
||||
{
|
||||
current_value = 2,
|
||||
limit_value = 500,
|
||||
health_increase_per_boss_wave = 4 -- wave % 25 == 0 at wave 2k boost is at 322
|
||||
}
|
||||
this.generated_units = {
|
||||
this.generated_units =
|
||||
{
|
||||
active_biters = {},
|
||||
unit_groups = {},
|
||||
unit_group_last_command = {},
|
||||
unit_group_pos = {
|
||||
unit_group_pos =
|
||||
{
|
||||
index = 0,
|
||||
positions = {}
|
||||
},
|
||||
nests = {}
|
||||
}
|
||||
this.threat_values = {
|
||||
this.threat_values =
|
||||
{
|
||||
['biter-spawner'] = 128,
|
||||
['spitter-spawner'] = 128,
|
||||
['behemoth-biter'] = 64,
|
||||
@@ -167,8 +164,10 @@ function Public.reset_wave_defense()
|
||||
['big-worm-turret'] = 64,
|
||||
['behemoth-worm-turret'] = 128
|
||||
}
|
||||
this.unit_settings = {
|
||||
scale_units_by_health = {
|
||||
this.unit_settings =
|
||||
{
|
||||
scale_units_by_health =
|
||||
{
|
||||
['small-biter'] = 1,
|
||||
['medium-biter'] = 0.75,
|
||||
['big-biter'] = 0.5,
|
||||
@@ -178,7 +177,8 @@ function Public.reset_wave_defense()
|
||||
['big-spitter'] = 0.5,
|
||||
['behemoth-spitter'] = 0.25
|
||||
},
|
||||
scale_worms_by_health = {
|
||||
scale_worms_by_health =
|
||||
{
|
||||
['land-mine'] = 0.5, -- not active as of now
|
||||
['gun-turret'] = 0.5, -- not active as of now
|
||||
['flamethrower-turret'] = 0.4, -- not active as of now
|
||||
@@ -189,7 +189,8 @@ function Public.reset_wave_defense()
|
||||
['behemoth-worm-turret'] = 0.3
|
||||
}
|
||||
}
|
||||
this.valid_enemy_forces = {
|
||||
this.valid_enemy_forces =
|
||||
{
|
||||
['enemy'] = true,
|
||||
['aggressors'] = true,
|
||||
['aggressors_frenzy'] = true
|
||||
|
||||
@@ -4,6 +4,7 @@ local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
||||
local Token = require 'utils.token'
|
||||
local Task = require 'utils.task_token'
|
||||
local Misc = require 'utils.commands.misc'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local raise = Event.raise
|
||||
local round = math.round
|
||||
@@ -371,7 +372,8 @@ local function shred_simple_entities(entity)
|
||||
entity.surface.find_entities_filtered(
|
||||
{
|
||||
type = 'simple-entity',
|
||||
area = {
|
||||
area =
|
||||
{
|
||||
{ entity.position.x - 3, entity.position.y - 3 },
|
||||
{ entity.position.x + 3, entity.position.y + 3 }
|
||||
}
|
||||
@@ -443,7 +445,7 @@ local function spawn_unit_spawner_inhabitants(entity)
|
||||
)
|
||||
end
|
||||
if biter and biter.valid then
|
||||
raise(Public.events.on_entity_created, { entity = biter, boss_unit = false })
|
||||
raise(CreatedEvents.events.on_entity_created, { entity = biter, boss_unit = false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,8 +2,7 @@ local Event = require 'utils.event'
|
||||
local Server = require 'utils.server'
|
||||
local Discord = require 'utils.discord_handler'
|
||||
|
||||
local commands =
|
||||
{
|
||||
local commands = {
|
||||
['editor'] = true,
|
||||
['open'] = true,
|
||||
['cheat'] = true,
|
||||
@@ -16,21 +15,19 @@ local commands =
|
||||
['debug'] = true
|
||||
}
|
||||
|
||||
local title_to_command =
|
||||
{
|
||||
['editor'] = "Editor",
|
||||
['open'] = "Open",
|
||||
['cheat'] = "Cheat",
|
||||
['permissions'] = "Permissions",
|
||||
['banlist'] = "Banlist",
|
||||
['config'] = "Config",
|
||||
['command'] = "Command",
|
||||
['silent-command'] = "Silent Command",
|
||||
['sc'] = "Silent Command",
|
||||
['debug'] = "Debug"
|
||||
local title_to_command = {
|
||||
['editor'] = 'Editor',
|
||||
['open'] = 'Open',
|
||||
['cheat'] = 'Cheat',
|
||||
['permissions'] = 'Permissions',
|
||||
['banlist'] = 'Banlist',
|
||||
['config'] = 'Config',
|
||||
['command'] = 'Command',
|
||||
['silent-command'] = 'Silent Command',
|
||||
['sc'] = 'Silent Command',
|
||||
['debug'] = 'Debug'
|
||||
}
|
||||
|
||||
|
||||
local function on_console_command(event)
|
||||
local cmd = event.command
|
||||
if not commands[cmd] then
|
||||
@@ -46,61 +43,61 @@ local function on_console_command(event)
|
||||
end
|
||||
executor = player.name
|
||||
else
|
||||
executor = "Server"
|
||||
executor = 'Server'
|
||||
end
|
||||
|
||||
local param = (event.parameters and event.parameters ~= "" and event.parameters) or "No parameters"
|
||||
local server_name = Server.get_server_name() or "CommandHandler"
|
||||
local param = (event.parameters and event.parameters ~= '' and event.parameters) or 'No parameters'
|
||||
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||
|
||||
Discord.send_notification(
|
||||
{
|
||||
title = title_to_command[cmd],
|
||||
description = "/" .. cmd .. " was used",
|
||||
color = "warning",
|
||||
fields =
|
||||
description = '/' .. cmd .. ' was used',
|
||||
color = 'warning',
|
||||
fields = {
|
||||
{
|
||||
{
|
||||
title = "Server",
|
||||
title = 'Server',
|
||||
description = server_name,
|
||||
inline = "false"
|
||||
inline = 'false'
|
||||
},
|
||||
{
|
||||
title = "By",
|
||||
title = 'By',
|
||||
description = executor,
|
||||
inline = "true"
|
||||
inline = 'true'
|
||||
},
|
||||
{
|
||||
title = "Details",
|
||||
title = 'Details',
|
||||
description = param,
|
||||
inline = "true"
|
||||
inline = 'true'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_console_command, on_console_command)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_promoted,
|
||||
function (event)
|
||||
function(event)
|
||||
local admins = Server.get_admins_data()
|
||||
local player = game.get_player(event.player_index)
|
||||
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||
|
||||
Discord.send_notification(
|
||||
{
|
||||
title = "Admin promotion",
|
||||
description = player.name .. " was promoted.",
|
||||
color = "success",
|
||||
fields =
|
||||
title = 'Admin promotion',
|
||||
description = player.name .. ' was promoted.',
|
||||
color = 'success',
|
||||
fields = {
|
||||
{
|
||||
{
|
||||
title = "Server",
|
||||
title = 'Server',
|
||||
description = server_name,
|
||||
inline = "false"
|
||||
inline = 'false'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
if not game.is_multiplayer() then
|
||||
return
|
||||
@@ -114,46 +111,46 @@ Event.add(
|
||||
)
|
||||
Event.add(
|
||||
defines.events.on_player_demoted,
|
||||
function (event)
|
||||
function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||
|
||||
Discord.send_notification(
|
||||
{
|
||||
title = "Admin demotion",
|
||||
description = player.name .. " was demoted.",
|
||||
color = "warning",
|
||||
fields =
|
||||
title = 'Admin demotion',
|
||||
description = player.name .. ' was demoted.',
|
||||
color = 'warning',
|
||||
fields = {
|
||||
{
|
||||
{
|
||||
title = "Server",
|
||||
title = 'Server',
|
||||
description = server_name,
|
||||
inline = "false"
|
||||
inline = 'false'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_kicked,
|
||||
function (event)
|
||||
function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||
|
||||
Discord.send_notification(
|
||||
{
|
||||
title = "Player kicked",
|
||||
description = player.name .. " was kicked.",
|
||||
color = "danger",
|
||||
fields =
|
||||
title = 'Player kicked',
|
||||
description = player.name .. ' was kicked.',
|
||||
color = 'danger',
|
||||
fields = {
|
||||
{
|
||||
{
|
||||
title = "Server",
|
||||
title = 'Server',
|
||||
description = server_name,
|
||||
inline = "false"
|
||||
inline = 'false'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
end
|
||||
)
|
||||
@@ -13,6 +13,7 @@ local FancyTime = require 'utils.tools.fancy_time'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Discord = require 'utils.discord_handler'
|
||||
local Config = require 'utils.gui.config'
|
||||
|
||||
local Public = {}
|
||||
local match = string.match
|
||||
@@ -112,6 +113,49 @@ Global.register(
|
||||
end
|
||||
)
|
||||
|
||||
local function trust_connected_players()
|
||||
local trust = Session.get_trusted_table()
|
||||
local players = game.connected_players
|
||||
if not this.enabled then
|
||||
for _, p in pairs(players) do
|
||||
trust[p.name] = true
|
||||
end
|
||||
else
|
||||
for _, p in pairs(players) do
|
||||
trust[p.name] = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Config.register_scenario_module(
|
||||
{
|
||||
id = "antigrief",
|
||||
admin_only = true,
|
||||
gui_rows = Config.register_token(
|
||||
function (_, frame)
|
||||
local switch_state = 'right'
|
||||
if this.enabled then
|
||||
switch_state = 'left'
|
||||
end
|
||||
Config.add_switch(frame, switch_state, 'disable_antigrief', 'Antigrief', 'Toggle antigrief function.')
|
||||
frame.add({ type = 'line' })
|
||||
end),
|
||||
handlers =
|
||||
{
|
||||
['disable_antigrief'] = Config.register_token(
|
||||
function (_, event)
|
||||
if event.element.switch_state == 'left' then
|
||||
this.enabled = true
|
||||
Config.get_actor(event, '[Antigrief]', 'has enabled the antigrief function.', true)
|
||||
else
|
||||
this.enabled = false
|
||||
Config.get_actor(event, '[Antigrief]', 'has disabled the antigrief function.', true)
|
||||
end
|
||||
trust_connected_players()
|
||||
end)
|
||||
}
|
||||
})
|
||||
|
||||
local function increment(t, v)
|
||||
t[#t + 1] = (v or 1)
|
||||
end
|
||||
@@ -289,11 +333,12 @@ local function on_marked_for_deconstruction(event)
|
||||
|
||||
local playtime = player.online_time
|
||||
local success = false
|
||||
local is_trusted = Session.get_trusted_player(player)
|
||||
if Session.get_session_player(player) then
|
||||
playtime = player.online_time + Session.get_session_player(player)
|
||||
success = true
|
||||
end
|
||||
if playtime < this.required_playtime then
|
||||
if playtime < this.required_playtime and not is_trusted then
|
||||
event.entity.cancel_deconstruction(player.force.name, player.index)
|
||||
player.print('You are not accustomed to deconstructing yet.', { r = 0.22, g = 0.99, b = 0.99 })
|
||||
return
|
||||
|
||||
@@ -12,8 +12,10 @@ local Discord = require 'utils.discord_handler'
|
||||
local Commands = require 'utils.commands'
|
||||
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
|
||||
local Task = require 'utils.task_token'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local this = {
|
||||
local this =
|
||||
{
|
||||
enabled = true,
|
||||
players = {},
|
||||
bottom_button = false
|
||||
@@ -121,7 +123,8 @@ Commands.new('remove_chunks', 'Iterates over a surface and removes chunks that a
|
||||
|
||||
for chunk in chunks do
|
||||
if surface.is_chunk_generated(chunk) then
|
||||
local area = {
|
||||
local area =
|
||||
{
|
||||
left_top = { chunk.area.left_top.x - 64, chunk.area.left_top.y - 64 },
|
||||
right_bottom = { chunk.area.right_bottom.x + 64, chunk.area.right_bottom.y + 64 }
|
||||
}
|
||||
@@ -287,8 +290,10 @@ Commands.new('generate_map', 'Pregenerates map.')
|
||||
end
|
||||
)
|
||||
|
||||
Commands.new('repair', 'Revives all ghost entities.')
|
||||
Commands.new('repair', 'Revives all ghost entities and inserts all missing modules into the entities.')
|
||||
:require_admin()
|
||||
:add_alias('fix')
|
||||
:add_alias('revive')
|
||||
:require_validation()
|
||||
:add_parameter('1-50', true, 'number')
|
||||
:callback(
|
||||
@@ -306,19 +311,38 @@ Commands.new('repair', 'Revives all ghost entities.')
|
||||
local radius = { { x = (player.position.x + -args), y = (player.position.y + -args) }, { x = (player.position.x + args), y = (player.position.y + args) } }
|
||||
|
||||
local c = 0
|
||||
local modules = 0
|
||||
for _, v in pairs(player.surface.find_entities_filtered { type = 'entity-ghost', area = radius }) do
|
||||
if v and v.valid then
|
||||
c = c + 1
|
||||
v.silent_revive()
|
||||
local _, entity, item_proxy = v.silent_revive()
|
||||
if entity and entity.valid then
|
||||
if item_proxy and item_proxy.valid then
|
||||
for _, plan in pairs(item_proxy.insert_plan) do
|
||||
if entity.get_module_inventory().index == plan.items.in_inventory[1].inventory then
|
||||
item_proxy.proxy_target.get_module_inventory().insert { name = plan.id.name, quality = plan.id.quality, count = 999 }
|
||||
modules = modules + 1
|
||||
end
|
||||
end
|
||||
item_proxy.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
if c == 0 then
|
||||
player.print('No entities to repair were found!')
|
||||
return false
|
||||
end
|
||||
|
||||
Discord.send_notification_raw(nil, player.name .. ' repaired ' .. c .. ' entities!')
|
||||
if modules > 0 then
|
||||
Discord.send_notification_raw(nil, player.name .. ' repaired ' .. c .. ' entities and inserted all missing modules into the entities.')
|
||||
return 'Repaired ' .. c .. ' entities and inserted all missing modules into the entities.'
|
||||
end
|
||||
|
||||
Discord.send_notification_raw(nil, player.name .. ' repaired ' .. c .. ' entities.')
|
||||
return 'Repaired ' .. c .. ' entities!'
|
||||
end
|
||||
)
|
||||
@@ -331,7 +355,8 @@ Commands.new('dump_layout', 'Dump the current map-layout.')
|
||||
local surface = player.surface
|
||||
game.write_file('layout.lua', '', false)
|
||||
|
||||
local area = {
|
||||
local area =
|
||||
{
|
||||
left_top = { x = 0, y = 0 },
|
||||
right_bottom = { x = 32, y = 32 }
|
||||
}
|
||||
@@ -707,7 +732,7 @@ Gui.on_click(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
BottomFrame.events.bottom_quickbar_location_changed,
|
||||
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||
function (event)
|
||||
if not this.enabled then
|
||||
return
|
||||
|
||||
50
utils/created_events.lua
Normal file
50
utils/created_events.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
-- This module is used to create events that can be used throughout the game.
|
||||
-- Without the need of requiring other modules.
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Public =
|
||||
{
|
||||
events =
|
||||
{
|
||||
on_entity_mined = Event.generate_event_name('on_entity_mined'),
|
||||
custom_on_entity_died = Event.generate_event_name('custom_on_entity_died'),
|
||||
remove_surface = Event.generate_event_name('remove_surface'),
|
||||
reset_game = Event.generate_event_name('reset_game'),
|
||||
init_surfaces = Event.generate_event_name('init_surfaces'),
|
||||
on_spell_cast_success = Event.generate_event_name('on_spell_cast_success'),
|
||||
on_spell_cast_failure = Event.generate_event_name('on_spell_cast_failure'),
|
||||
on_wave_created = Event.generate_event_name('on_wave_created'),
|
||||
on_unit_group_created = Event.generate_event_name('on_unit_group_created'),
|
||||
on_evolution_factor_changed = Event.generate_event_name('on_evolution_factor_changed'),
|
||||
on_game_reset = Event.generate_event_name('on_game_reset'),
|
||||
on_target_aquired = Event.generate_event_name('on_target_aquired'),
|
||||
on_primary_target_missing = Event.generate_event_name('on_primary_target_missing'),
|
||||
on_entity_created = Event.generate_event_name('on_entity_created'),
|
||||
on_biters_evolved = Event.generate_event_name('on_biters_evolved'),
|
||||
on_spawn_unit_group = Event.generate_event_name('on_spawn_unit_group'),
|
||||
on_spawn_unit_group_simple = Event.generate_event_name('on_spawn_unit_group_simple'),
|
||||
on_gui_removal = Event.generate_event_name('on_gui_removal'),
|
||||
on_gui_closed_main_frame = Event.generate_event_name('on_gui_closed_main_frame'),
|
||||
on_player_removed = Event.generate_event_name('on_player_removed'),
|
||||
|
||||
-- config events
|
||||
on_config_changed = Event.generate_event_name('on_config_changed'),
|
||||
|
||||
-- server events
|
||||
on_server_started = Event.generate_event_name('on_server_started'),
|
||||
on_changes_detected = Event.generate_event_name('on_changes_detected'),
|
||||
on_player_banned = Event.generate_event_name('on_player_banned'),
|
||||
on_player_jailed = Event.generate_event_name('on_player_jailed'),
|
||||
on_player_unjailed = Event.generate_event_name('on_player_unjailed'),
|
||||
|
||||
-- bottom frame events
|
||||
bottom_quickbar_respawn_raise = Event.generate_event_name('bottom_quickbar_respawn_raise'),
|
||||
bottom_quickbar_location_changed = Event.generate_event_name('bottom_quickbar_location_changed'),
|
||||
|
||||
-- poll events
|
||||
on_poll_complete = Event.generate_event_name('on_poll_complete'),
|
||||
on_poll_created = Event.generate_event_name('on_poll_created')
|
||||
}
|
||||
}
|
||||
|
||||
return Public
|
||||
@@ -9,13 +9,14 @@ local ban_by_join_enabled = false
|
||||
|
||||
local try_get_ban = Server.try_get_ban
|
||||
|
||||
local valid_commands = {
|
||||
local valid_commands =
|
||||
{
|
||||
['ban'] = true
|
||||
}
|
||||
|
||||
local try_get_is_banned_token =
|
||||
Token.register(
|
||||
function(data)
|
||||
function (data)
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
@@ -31,11 +32,11 @@ local try_get_is_banned_token =
|
||||
game.ban_player(data.username, data.reason)
|
||||
end
|
||||
end
|
||||
)
|
||||
)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
function (event)
|
||||
if not ban_by_join_enabled then
|
||||
return
|
||||
end
|
||||
@@ -56,7 +57,7 @@ Event.add(
|
||||
|
||||
Event.add(
|
||||
defines.events.on_console_command,
|
||||
function(event)
|
||||
function (event)
|
||||
if valid_commands[event.command] then
|
||||
Server.ban_handler(event)
|
||||
end
|
||||
|
||||
@@ -11,6 +11,8 @@ local table = require 'utils.table'
|
||||
local Gui = require 'utils.gui'
|
||||
local StatData = require 'utils.datastore.statistics'
|
||||
local Commands = require 'utils.commands'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
local UndoActions = require 'utils.undo_actions'
|
||||
|
||||
StatData.add_normalize('jailed', 'Jailed')
|
||||
|
||||
@@ -24,6 +26,7 @@ local terms_tbl = {}
|
||||
local votejail = {}
|
||||
local votefree = {}
|
||||
local revoked_permissions = {}
|
||||
local undo_polls = {}
|
||||
local settings =
|
||||
{
|
||||
playtime_for_vote = 77760000, -- 15 days
|
||||
@@ -65,7 +68,8 @@ Global.register(
|
||||
settings = settings,
|
||||
player_data = player_data,
|
||||
terms_tbl = terms_tbl,
|
||||
revoked_permissions = revoked_permissions
|
||||
revoked_permissions = revoked_permissions,
|
||||
undo_polls = undo_polls
|
||||
},
|
||||
function (t)
|
||||
jailed = t.jailed
|
||||
@@ -75,17 +79,11 @@ Global.register(
|
||||
player_data = t.player_data
|
||||
terms_tbl = t.terms_tbl
|
||||
revoked_permissions = t.revoked_permissions
|
||||
undo_polls = t.undo_polls
|
||||
end
|
||||
)
|
||||
|
||||
local Public =
|
||||
{
|
||||
events =
|
||||
{
|
||||
on_player_jailed = Event.generate_event_name('on_player_jailed'),
|
||||
on_player_unjailed = Event.generate_event_name('on_player_unjailed')
|
||||
}
|
||||
}
|
||||
local Public = {}
|
||||
|
||||
local function validate_entity(entity)
|
||||
if not (entity and entity.valid) then
|
||||
@@ -663,7 +661,7 @@ local function jail(player, offender, msg, raised, mute)
|
||||
set_data(jailed_data_set, offender, { jailed = true, actor = player, reason = msg, date = date })
|
||||
end
|
||||
|
||||
Event.raise(Public.events.on_player_jailed, { player_index = offender.index })
|
||||
Event.raise(CreatedEvents.events.on_player_jailed, { player_index = offender.index })
|
||||
|
||||
StatData.get_data(to_jail_player.index):increase('jailed')
|
||||
|
||||
@@ -734,7 +732,7 @@ local function jail_temporary(player, offender, msg, mute)
|
||||
|
||||
set_data(jailed_data_set, offender.name, { jailed = true, temporary = true, actor = player.name, reason = msg, date = date })
|
||||
|
||||
Event.raise(Public.events.on_player_jailed, { player_index = offender.index })
|
||||
Event.raise(CreatedEvents.events.on_player_jailed, { player_index = offender.index })
|
||||
|
||||
StatData.get_data(offender.index):increase('jailed')
|
||||
|
||||
@@ -763,7 +761,7 @@ local function free(player, offender)
|
||||
|
||||
set_data(jailed_data_set, offender, nil)
|
||||
|
||||
Event.raise(Public.events.on_player_unjailed, { player_index = offender.index })
|
||||
Event.raise(CreatedEvents.events.on_player_unjailed, { player_index = offender.index })
|
||||
|
||||
Utils.print_to(nil, message)
|
||||
local data = Server.build_embed_data()
|
||||
@@ -1198,7 +1196,7 @@ Event.on_init(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
CreatedEvents.events.on_server_started,
|
||||
function ()
|
||||
Public.sync_revoked_permissions()
|
||||
end
|
||||
@@ -1282,10 +1280,12 @@ Event.add(
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if player.admin then
|
||||
if cmd == 'jail' then
|
||||
Utils.warning(player, 'Logging your actions.')
|
||||
message = message .. ' executed by ' .. player.name
|
||||
UndoActions.do_action_poll(offender)
|
||||
Public.try_ul_data(offender, true, player.name, message)
|
||||
return
|
||||
elseif cmd == 'free' then
|
||||
@@ -1352,6 +1352,7 @@ Event.add(
|
||||
print(module_name .. 'Logging your actions.')
|
||||
message = message .. ' executed by script'
|
||||
Public.try_ul_data(offender, true, 'script', message)
|
||||
UndoActions.do_action_poll(offender)
|
||||
return
|
||||
elseif cmd == 'free' then
|
||||
Public.try_ul_data(offender, false, 'script')
|
||||
|
||||
@@ -8,13 +8,16 @@ local Event = require 'utils.event'
|
||||
local table = require 'utils.table'
|
||||
local RPG = require 'modules.rpg.table'
|
||||
local Color = require 'utils.color_presets'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||
|
||||
local this = {
|
||||
settings = {
|
||||
local this =
|
||||
{
|
||||
settings =
|
||||
{
|
||||
enabled = false,
|
||||
reset_after = 7, -- 7 days
|
||||
required_level_to_progress = 99, -- higher than 99 to be able to save
|
||||
@@ -347,7 +350,7 @@ function Public.toggle_module(state)
|
||||
end
|
||||
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
CreatedEvents.events.on_server_started,
|
||||
function ()
|
||||
Public.try_dl_resets()
|
||||
end
|
||||
|
||||
@@ -8,6 +8,7 @@ local Task = require 'utils.task'
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local table = require 'utils.table'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||
|
||||
@@ -41,9 +42,6 @@ Global.register(
|
||||
)
|
||||
|
||||
local Public = {
|
||||
events = {
|
||||
on_player_removed = Event.generate_event_name('on_player_removed')
|
||||
}
|
||||
}
|
||||
|
||||
local try_download_data_token =
|
||||
@@ -348,7 +346,7 @@ end
|
||||
--- It's vital that we reset the online_track so we
|
||||
--- don't calculate the values wrong.
|
||||
Event.add(
|
||||
Public.events.on_player_removed,
|
||||
CreatedEvents.events.on_player_removed,
|
||||
function ()
|
||||
for name, _ in pairs(online_track) do
|
||||
local player = game.get_player(name)
|
||||
|
||||
@@ -4,6 +4,7 @@ local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||
local statistics_dataset = 'statistics'
|
||||
@@ -13,7 +14,8 @@ local try_get_data = Server.try_get_data
|
||||
local e = defines.events
|
||||
local floor = math.floor
|
||||
|
||||
local events = {
|
||||
local events =
|
||||
{
|
||||
map_tags_made = e.on_chart_tag_added,
|
||||
chat_messages = e.on_console_chat,
|
||||
commands_used = e.on_console_command,
|
||||
@@ -29,19 +31,19 @@ local events = {
|
||||
deconstructer_planner_used = e.on_player_deconstructed_area
|
||||
}
|
||||
|
||||
local settings = {
|
||||
local settings =
|
||||
{
|
||||
required_only_time_to_save_time = 10 * 3600,
|
||||
afk_time = 5 * 3600,
|
||||
nth_tick = 5 * 3600
|
||||
}
|
||||
|
||||
local Public = {
|
||||
events = {
|
||||
on_player_removed = Event.generate_event_name('on_player_removed')
|
||||
}
|
||||
local Public =
|
||||
{
|
||||
}
|
||||
|
||||
local normalized_names = {
|
||||
local normalized_names =
|
||||
{
|
||||
['map_tags_made'] = { name = 'Map-tags created', tooltip = "Tags that you've created in minimap." },
|
||||
['chat_messages'] = { name = 'Messages', tooltip = 'Messages sent in chat.' },
|
||||
['commands_used'] = { name = 'Commands', tooltip = 'Commands used in console.' },
|
||||
@@ -125,7 +127,8 @@ local function get_data(player)
|
||||
if not data then
|
||||
local p = game.get_player(player_index)
|
||||
local name = p and p.valid and p.name or nil
|
||||
local player_data = {
|
||||
local player_data =
|
||||
{
|
||||
name = name,
|
||||
tick = 0
|
||||
}
|
||||
@@ -307,7 +310,7 @@ Event.add(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Public.events.on_player_removed,
|
||||
CreatedEvents.events.on_player_removed,
|
||||
function (event)
|
||||
local player_index = event.player_index
|
||||
statistics[player_index] = nil
|
||||
|
||||
@@ -4,18 +4,20 @@ local Global = require 'utils.global'
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local table = require 'utils.table'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local supporters_dataset = 'supporters'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local this = {
|
||||
local this =
|
||||
{
|
||||
supporters = {}
|
||||
}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(tbl)
|
||||
function (tbl)
|
||||
this = tbl
|
||||
end
|
||||
)
|
||||
@@ -30,7 +32,7 @@ end
|
||||
--- Writes the data called back from the server into the supporter table, clearing any previous entries
|
||||
local sync_supporters_callback =
|
||||
Token.register(
|
||||
function(data)
|
||||
function (data)
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
@@ -42,7 +44,7 @@ local sync_supporters_callback =
|
||||
this.supporters[k] = v
|
||||
end
|
||||
end
|
||||
)
|
||||
)
|
||||
|
||||
--- Signals the server to retrieve the supporters dataset
|
||||
function Public.sync_supporters()
|
||||
@@ -51,14 +53,14 @@ end
|
||||
|
||||
Server.on_data_set_changed(
|
||||
supporters_dataset,
|
||||
function(data)
|
||||
function (data)
|
||||
this.supporters[data.key] = data.value
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Server.events.on_server_started,
|
||||
function()
|
||||
CreatedEvents.events.on_server_started,
|
||||
function ()
|
||||
Public.sync_supporters()
|
||||
end
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ local format = string.format
|
||||
local match = string.match
|
||||
local gsub = string.gsub
|
||||
local serialize = serpent.line
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
local debug_getupvalue = debug.getupvalue
|
||||
|
||||
-- this
|
||||
@@ -133,14 +134,6 @@ function Debug.print_position(position, message)
|
||||
Debug.print(format('%s %s', serialize(position), message))
|
||||
end
|
||||
|
||||
---Executes the given callback if cheating is enabled.
|
||||
---@param callback function
|
||||
function Debug.cheat(callback)
|
||||
if _CHEATS then
|
||||
callback()
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns true if the function is a closure, false otherwise.
|
||||
-- A closure is a function that contains 'upvalues' or in other words
|
||||
-- has a reference to a local variable defined outside the function's scope.
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
local Gui = require 'utils.gui'
|
||||
local table = require 'utils.table'
|
||||
local api = require 'utils.debug.runtime-api-stable'
|
||||
|
||||
local gui_names = Gui.names
|
||||
local type = type
|
||||
local concat = table.concat
|
||||
local inspect = table.inspect
|
||||
local pcall = pcall
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
local loadstring = loadstring
|
||||
local classes = api.classes
|
||||
|
||||
local Public = {}
|
||||
|
||||
local luaObject = { '{', nil, ", name = '", nil, "'}" }
|
||||
local luaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, '}' }
|
||||
local luaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, '}' }
|
||||
local luaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
|
||||
local luaObject = {'{', nil, ", name = '", nil, "'}"}
|
||||
local luaPlayer = {"{LuaPlayer, name = '", nil, "', index = ", nil, '}'}
|
||||
local luaEntity = {"{LuaEntity, name = '", nil, "', unit_number = ", nil, '}'}
|
||||
local luaGuiElement = {"{LuaGuiElement, name = '", nil, "'}"}
|
||||
|
||||
local function get(obj, prop)
|
||||
return obj[prop]
|
||||
@@ -29,26 +32,45 @@ local function get_name_safe(obj)
|
||||
end
|
||||
|
||||
local function get_lua_object_type_safe(obj)
|
||||
local s, r = pcall(get, obj, 'help')
|
||||
local s, r = pcall(get, obj, 'object_name')
|
||||
|
||||
if not s then
|
||||
return
|
||||
return type(obj)
|
||||
end
|
||||
|
||||
return r():match('Lua%a+')
|
||||
return r
|
||||
end
|
||||
|
||||
local function inspect_process(item)
|
||||
local object_name = get_lua_object_type_safe(item)
|
||||
if object_name and classes[object_name] then
|
||||
local class = classes[object_name]
|
||||
local attrs = class.attributes
|
||||
local info = {__type = object_name}
|
||||
local shown = 0
|
||||
for key in pairs(attrs) do
|
||||
local ok, val =
|
||||
pcall(
|
||||
function()
|
||||
return item[key]
|
||||
end
|
||||
)
|
||||
if ok and (type(val) ~= 'table' and type(val) ~= 'userdata') then
|
||||
info[key] = val
|
||||
shown = shown + 1
|
||||
end
|
||||
end
|
||||
return serpent.line(info, {comment = false, numformat = '%g'})
|
||||
end
|
||||
|
||||
if type(item) ~= 'table' or type(item.__self) ~= 'userdata' then
|
||||
return item
|
||||
end
|
||||
|
||||
local suc, valid = pcall(get, item, 'valid')
|
||||
if not suc then
|
||||
-- no 'valid' property
|
||||
return get_lua_object_type_safe(item) or '{NoHelp LuaObject}'
|
||||
end
|
||||
|
||||
if not valid then
|
||||
return '{Invalid LuaObject}'
|
||||
end
|
||||
@@ -61,27 +83,23 @@ local function inspect_process(item)
|
||||
if obj_type == 'LuaPlayer' then
|
||||
luaPlayer[2] = item.name or 'nil'
|
||||
luaPlayer[4] = item.index or 'nil'
|
||||
|
||||
return concat(luaPlayer)
|
||||
elseif obj_type == 'LuaEntity' then
|
||||
luaEntity[2] = item.name or 'nil'
|
||||
luaEntity[4] = item.unit_number or 'nil'
|
||||
|
||||
return concat(luaEntity)
|
||||
elseif obj_type == 'LuaGuiElement' then
|
||||
local name = item.name
|
||||
luaGuiElement[2] = gui_names and gui_names[name] or name or 'nil'
|
||||
|
||||
return concat(luaGuiElement)
|
||||
else
|
||||
luaObject[2] = obj_type
|
||||
luaObject[4] = get_name_safe(item)
|
||||
|
||||
return concat(luaObject)
|
||||
end
|
||||
end
|
||||
|
||||
local inspect_options = { process = inspect_process }
|
||||
local inspect_options = {process = inspect_process}
|
||||
function Public.dump(data)
|
||||
return inspect(data, inspect_options)
|
||||
end
|
||||
@@ -97,14 +115,14 @@ function Public.dump_ignore_builder(ignore)
|
||||
return inspect_process(item)
|
||||
end
|
||||
|
||||
local options = { process = process }
|
||||
return function (data)
|
||||
local options = {process = process}
|
||||
return function(data)
|
||||
return inspect(data, options)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.dump_function(func)
|
||||
local res = { 'upvalues:\n' }
|
||||
local res = {'upvalues:\n'}
|
||||
|
||||
if debug.getupvalue == nil then
|
||||
return concat(res)
|
||||
|
||||
5697
utils/debug/runtime-api-stable.lua
Normal file
5697
utils/debug/runtime-api-stable.lua
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,4 @@
|
||||
---@diagnostic disable: undefined-global
|
||||
--luacheck: ignore function_table
|
||||
--luacheck: ignore function_nth_tick_table
|
||||
--luacheck: globals script
|
||||
|
||||
@@ -3,6 +3,7 @@ local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Server = require 'utils.server'
|
||||
local SpamProtection = require 'utils.spam_protection'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local insert = table.insert
|
||||
local tostring = tostring
|
||||
@@ -10,10 +11,15 @@ local next = next
|
||||
local gui_prefix = 'comfy_'
|
||||
|
||||
local Public = {}
|
||||
Public.events =
|
||||
|
||||
local ordered_tab_names =
|
||||
{
|
||||
on_gui_removal = Event.generate_event_name('on_gui_removal'),
|
||||
on_gui_closed_main_frame = Event.generate_event_name('on_gui_closed_main_frame')
|
||||
"Players",
|
||||
"Admin",
|
||||
"Groups",
|
||||
"Scoreboard",
|
||||
"Statistics",
|
||||
"Config",
|
||||
}
|
||||
|
||||
-- local to this file
|
||||
@@ -663,7 +669,7 @@ function Public.clear_all_screen_frames(player)
|
||||
end
|
||||
|
||||
function Public.clear_all_active_frames(player)
|
||||
Event.raise(Public.events.on_gui_closed_main_frame, { player_index = player.index })
|
||||
Event.raise(CreatedEvents.events.on_gui_closed_main_frame, { player_index = player.index })
|
||||
for _, child in pairs(player.gui.left.children) do
|
||||
if child.name:find(gui_prefix) then
|
||||
remove_data_recursively(child)
|
||||
@@ -825,17 +831,50 @@ local function draw_main_frame(player)
|
||||
|
||||
Public.clear_all_active_frames(player)
|
||||
|
||||
if Public.get_main_frame(player) then
|
||||
remove_data_recursively(Public.get_main_frame(player))
|
||||
Public.get_main_frame(player).destroy()
|
||||
local existing_frame = Public.get_main_frame(player)
|
||||
if existing_frame then
|
||||
remove_data_recursively(existing_frame)
|
||||
existing_frame.destroy()
|
||||
end
|
||||
|
||||
local admins = Server.get_admins_data()
|
||||
local frame, inside_frame = Public.add_main_frame_with_toolbar(
|
||||
player,
|
||||
'left',
|
||||
main_frame_name,
|
||||
nil,
|
||||
close_button_name,
|
||||
'Comfy Factorio'
|
||||
)
|
||||
|
||||
local frame, inside_frame = Public.add_main_frame_with_toolbar(player, 'left', main_frame_name, nil,
|
||||
close_button_name, 'Comfy Factorio')
|
||||
local tabbed_pane = inside_frame.add({ type = 'tabbed-pane', name = 'tabbed_pane' })
|
||||
for name, callback in pairs(tabs) do
|
||||
|
||||
local ordered_tabs = {}
|
||||
|
||||
for _, name in ipairs(ordered_tab_names) do
|
||||
if tabs[name] then
|
||||
table.insert(ordered_tabs, { name = name, data = tabs[name] })
|
||||
end
|
||||
end
|
||||
|
||||
for name, tab_data in pairs(tabs) do
|
||||
local found = false
|
||||
for _, ordered_name in ipairs(ordered_tab_names) do
|
||||
if name == ordered_name then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not found then
|
||||
table.insert(ordered_tabs, { name = name, data = tab_data })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for _, entry in ipairs(ordered_tabs) do
|
||||
local name = entry.name
|
||||
local callback = entry.data
|
||||
|
||||
if not settings.disabled_tabs[name] then
|
||||
local show = false
|
||||
local secs = Server.get_current_time()
|
||||
@@ -851,8 +890,20 @@ local function draw_main_frame(player)
|
||||
end
|
||||
|
||||
if show then
|
||||
local tab = tabbed_pane.add({ type = 'tab', caption = name, name = callback.name, style = 'slightly_smaller_tab' })
|
||||
local name_frame = tabbed_pane.add({ type = 'frame', name = name, direction = 'vertical', style = 'mod_gui_inside_deep_frame' })
|
||||
local tab = tabbed_pane.add(
|
||||
{
|
||||
type = 'tab',
|
||||
caption = name,
|
||||
name = callback.name,
|
||||
style = 'slightly_smaller_tab'
|
||||
})
|
||||
local name_frame = tabbed_pane.add(
|
||||
{
|
||||
type = 'frame',
|
||||
name = name,
|
||||
direction = 'vertical',
|
||||
style = 'mod_gui_inside_deep_frame'
|
||||
})
|
||||
name_frame.style.padding = 8
|
||||
tabbed_pane.add_tab(tab, name_frame)
|
||||
end
|
||||
@@ -866,11 +917,12 @@ local function draw_main_frame(player)
|
||||
end
|
||||
|
||||
player.opened = frame
|
||||
|
||||
Public.reload_active_tab(player, true)
|
||||
|
||||
return frame, inside_frame
|
||||
end
|
||||
|
||||
|
||||
function Public.get_content(player)
|
||||
local left_frame = Public.get_main_frame(player)
|
||||
if not left_frame then
|
||||
@@ -890,7 +942,7 @@ function Public.refresh(player)
|
||||
for _, tab in pairs(tabbed_pane.tabs) do
|
||||
if tab.content.name ~= frame.name then
|
||||
tab.content.clear()
|
||||
Event.raise(Public.events.on_gui_removal, { player_index = player.index })
|
||||
Event.raise(CreatedEvents.events.on_gui_removal, { player_index = player.index })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -974,9 +1026,9 @@ Public.on_click(
|
||||
if frame then
|
||||
remove_data_recursively(frame)
|
||||
frame.destroy()
|
||||
Event.raise(Public.events.on_gui_removal, { player_index = player.index })
|
||||
Event.raise(CreatedEvents.events.on_gui_removal, { player_index = player.index })
|
||||
local active_frame = Public.get_player_active_frame(player)
|
||||
Event.raise(Public.events.on_gui_closed_main_frame,
|
||||
Event.raise(CreatedEvents.events.on_gui_closed_main_frame,
|
||||
{ player_index = player.index, element = active_frame or nil })
|
||||
else
|
||||
draw_main_frame(player)
|
||||
@@ -990,7 +1042,7 @@ Public.on_click(
|
||||
local player = event.player
|
||||
local frame = Public.get_parent_frame(player)
|
||||
local active_frame = Public.get_player_active_frame(player)
|
||||
Event.raise(Public.events.on_gui_closed_main_frame, { player_index = player.index, element = active_frame or nil })
|
||||
Event.raise(CreatedEvents.events.on_gui_closed_main_frame, { player_index = player.index, element = active_frame or nil })
|
||||
if frame then
|
||||
remove_data_recursively(frame)
|
||||
frame.destroy()
|
||||
@@ -1003,7 +1055,7 @@ Public.on_custom_close(
|
||||
function (event)
|
||||
local player = event.player
|
||||
local active_frame = Public.get_player_active_frame(player)
|
||||
Event.raise(Public.events.on_gui_closed_main_frame, { player_index = player.index, element = active_frame or nil })
|
||||
Event.raise(CreatedEvents.events.on_gui_closed_main_frame, { player_index = player.index, element = active_frame or nil })
|
||||
local frame = Public.get_parent_frame(player)
|
||||
if frame then
|
||||
remove_data_recursively(frame)
|
||||
|
||||
@@ -11,6 +11,7 @@ local Task = require 'utils.task_token'
|
||||
local Token = require 'utils.token'
|
||||
local Global = require 'utils.global'
|
||||
local Discord = require 'utils.discord_handler'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local Public = {}
|
||||
|
||||
@@ -1504,6 +1505,6 @@ Gui.on_checked_state_changed(
|
||||
Event.add(defines.events.on_gui_text_changed, text_changed)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(defines.events.on_gui_selection_state_changed, on_gui_selection_state_changed)
|
||||
Event.add(Gui.events.on_gui_closed_main_frame, on_gui_closed)
|
||||
Event.add(CreatedEvents.events.on_gui_closed_main_frame, on_gui_closed)
|
||||
|
||||
return Public
|
||||
|
||||
@@ -3,6 +3,8 @@ local Global = require 'utils.global'
|
||||
local Gui = require 'utils.gui'
|
||||
local Task = require 'utils.task_token'
|
||||
local Config = require 'utils.gui.config'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local this =
|
||||
{
|
||||
players = {},
|
||||
@@ -22,14 +24,7 @@ Global.register(
|
||||
-- @table events
|
||||
-- @field bottom_quickbar_respawn_raise The event triggered when the bottom quickbar is respawned or raised.
|
||||
-- @field bottom_quickbar_location_changed The event triggered when the location of the bottom quickbar is changed.
|
||||
local Public =
|
||||
{
|
||||
events =
|
||||
{
|
||||
bottom_quickbar_respawn_raise = Event.generate_event_name('bottom_quickbar_respawn_raise'),
|
||||
bottom_quickbar_location_changed = Event.generate_event_name('bottom_quickbar_location_changed')
|
||||
}
|
||||
}
|
||||
local Public = {}
|
||||
|
||||
local set_location
|
||||
local destroy_frame
|
||||
@@ -469,7 +464,7 @@ set_location = function (player, state)
|
||||
}
|
||||
end
|
||||
|
||||
Event.raise(Public.events.bottom_quickbar_location_changed, { player_index = player.index, data = data })
|
||||
Event.raise(CreatedEvents.events.bottom_quickbar_location_changed, { player_index = player.index, data = data })
|
||||
|
||||
data.state = state
|
||||
create_frame(player, alignment, location, data)
|
||||
@@ -670,7 +665,7 @@ Event.add(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Public.events.bottom_quickbar_respawn_raise,
|
||||
CreatedEvents.events.bottom_quickbar_respawn_raise,
|
||||
function (event)
|
||||
if not event or not event.player_index then
|
||||
return
|
||||
@@ -685,7 +680,7 @@ Event.add(
|
||||
)
|
||||
|
||||
Event.add(
|
||||
Public.events.bottom_quickbar_location_changed,
|
||||
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||
function (event)
|
||||
if not event or not event.player_index then
|
||||
return
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
local Antigrief = require 'utils.antigrief'
|
||||
local Event = require 'utils.event'
|
||||
local Color = require 'utils.color_presets'
|
||||
local SessionData = require 'utils.datastore.session_data'
|
||||
local Utils = require 'utils.core'
|
||||
local SpamProtection = require 'utils.spam_protection'
|
||||
local Token = require 'utils.token'
|
||||
@@ -125,21 +123,6 @@ local function spaghett()
|
||||
end
|
||||
end
|
||||
|
||||
local function trust_connected_players()
|
||||
local trust = SessionData.get_trusted_table()
|
||||
local AG = Antigrief.get()
|
||||
local players = game.connected_players
|
||||
if not AG.enabled then
|
||||
for _, p in pairs(players) do
|
||||
trust[p.name] = true
|
||||
end
|
||||
else
|
||||
for _, p in pairs(players) do
|
||||
trust[p.name] = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local functions =
|
||||
{
|
||||
['spectator_switch'] = function (event)
|
||||
@@ -179,21 +162,6 @@ local functions =
|
||||
end
|
||||
}
|
||||
|
||||
local antigrief_functions =
|
||||
{
|
||||
['disable_antigrief'] = function (event)
|
||||
local AG = Antigrief.get()
|
||||
if event.element.switch_state == 'left' then
|
||||
AG.enabled = true
|
||||
get_actor(event, '[Antigrief]', 'has enabled the antigrief function.', true)
|
||||
else
|
||||
AG.enabled = false
|
||||
get_actor(event, '[Antigrief]', 'has disabled the antigrief function.', true)
|
||||
end
|
||||
trust_connected_players()
|
||||
end
|
||||
}
|
||||
|
||||
local pirates_functions =
|
||||
{
|
||||
['toggle_disband'] = function (event)
|
||||
@@ -257,7 +225,6 @@ local function build_config_gui(data)
|
||||
if not player then return end
|
||||
local frame = data.frame
|
||||
|
||||
local AG = Antigrief.get()
|
||||
local switch_state
|
||||
local label
|
||||
|
||||
@@ -351,13 +318,6 @@ local function build_config_gui(data)
|
||||
|
||||
scroll_pane.add({ type = 'line' })
|
||||
|
||||
switch_state = 'right'
|
||||
if AG.enabled then
|
||||
switch_state = 'left'
|
||||
end
|
||||
add_switch(scroll_pane, switch_state, 'disable_antigrief', 'Antigrief', 'Toggle antigrief function.')
|
||||
scroll_pane.add({ type = 'line' })
|
||||
|
||||
if storage.tokens.maps_pirates_memory then
|
||||
label = scroll_pane.add({ type = 'label', caption = 'Pirates Settings' })
|
||||
label.style.font = 'default-bold'
|
||||
@@ -407,13 +367,6 @@ local function on_gui_switch_state_changed(event)
|
||||
end
|
||||
functions[event.element.name](event)
|
||||
return
|
||||
elseif antigrief_functions[event.element.name] then
|
||||
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config AntiGrief Elem')
|
||||
if is_spamming then
|
||||
return
|
||||
end
|
||||
antigrief_functions[event.element.name](event)
|
||||
return
|
||||
elseif pirates_functions[event.element.name] then
|
||||
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Pirates Elem')
|
||||
if is_spamming then
|
||||
|
||||
@@ -9,6 +9,8 @@ local SpamProtection = require 'utils.spam_protection'
|
||||
local Math = require 'utils.math.math'
|
||||
local Discord = require 'utils.discord_handler'
|
||||
local Color = require 'utils.color_presets'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local insert = table.insert
|
||||
@@ -952,6 +954,10 @@ local function tick()
|
||||
table.remove(running_polls, i)
|
||||
send_poll_result_to_discord(poll, true)
|
||||
|
||||
local poll_result, winning_answer = Public.poll_result(poll.id)
|
||||
|
||||
Event.raise(CreatedEvents.events.on_poll_complete, { player_index = poll.player_index, poll_id = poll.id, custom_data = poll.custom_data, poll_result = poll_result, winning_answer = winning_answer })
|
||||
|
||||
local message = table.concat { 'Poll finished: Poll #', poll.id, ': ', poll.question }
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if not no_notify_players[p.index] then
|
||||
@@ -962,6 +968,10 @@ local function tick()
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(CreatedEvents.events.on_poll_created, function (event)
|
||||
Public.poll(event)
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_joined_game, player_joined)
|
||||
Event.add(defines.events.on_player_created, player_joined)
|
||||
Event.on_nth_tick(60, tick)
|
||||
@@ -1512,6 +1522,7 @@ function Public.poll(data)
|
||||
local poll_data =
|
||||
{
|
||||
id = id,
|
||||
custom_data = data.custom_data or nil,
|
||||
question = data.question,
|
||||
answers = answers,
|
||||
voters = {},
|
||||
@@ -1543,17 +1554,21 @@ function Public.poll_result(id)
|
||||
local result = { 'Question: ', poll_data.question, ' Answers: ' }
|
||||
local answers = poll_data.answers
|
||||
local answers_count = #answers
|
||||
local winning_answer = nil
|
||||
local highest_vote = 0
|
||||
local winners = {}
|
||||
|
||||
for i, a in pairs(answers) do
|
||||
for i, a in ipairs(answers) do
|
||||
insert(result, '( [')
|
||||
insert(result, a.voted_count)
|
||||
insert(result, '] - ')
|
||||
insert(result, a.text)
|
||||
insert(result, ' )')
|
||||
|
||||
if not winning_answer or a.voted_count > winning_answer.voted_count then
|
||||
winning_answer = a
|
||||
if a.voted_count > highest_vote then
|
||||
highest_vote = a.voted_count
|
||||
winners = { a }
|
||||
elseif a.voted_count == highest_vote then
|
||||
insert(winners, a)
|
||||
end
|
||||
|
||||
if i ~= answers_count then
|
||||
@@ -1561,6 +1576,13 @@ function Public.poll_result(id)
|
||||
end
|
||||
end
|
||||
|
||||
local winning_answer
|
||||
if #winners == 1 then
|
||||
winning_answer = winners[1]
|
||||
else
|
||||
winning_answer = { text = 'Tie', voted_count = highest_vote }
|
||||
end
|
||||
|
||||
return table.concat(result), winning_answer
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local inspect = {
|
||||
local inspect =
|
||||
{
|
||||
_VERSION = 'inspect.lua 3.1.0',
|
||||
_URL = 'http://github.com/kikito/inspect.lua',
|
||||
_DESCRIPTION = 'human-readable representations of tables',
|
||||
@@ -34,21 +35,20 @@ inspect.KEY =
|
||||
setmetatable(
|
||||
{},
|
||||
{
|
||||
__tostring = function()
|
||||
__tostring = function ()
|
||||
return 'inspect.KEY'
|
||||
end
|
||||
}
|
||||
)
|
||||
)
|
||||
inspect.METATABLE =
|
||||
setmetatable(
|
||||
{},
|
||||
{
|
||||
__tostring = function()
|
||||
__tostring = function ()
|
||||
return 'inspect.METATABLE'
|
||||
end
|
||||
}
|
||||
)
|
||||
|
||||
)
|
||||
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
||||
-- Otherwise, it returns a regular quoted string
|
||||
local function smartQuote(str)
|
||||
@@ -59,7 +59,8 @@ local function smartQuote(str)
|
||||
end
|
||||
|
||||
-- \a => '\\a', \0 => '\\0', 31 => '\31'
|
||||
local shortControlCharEscapes = {
|
||||
local shortControlCharEscapes =
|
||||
{
|
||||
['\a'] = '\\a',
|
||||
['\b'] = '\\b',
|
||||
['\f'] = '\\f',
|
||||
@@ -89,7 +90,8 @@ local function isSequenceKey(k, sequenceLength)
|
||||
return type(k) == 'number' and 1 <= k and k <= sequenceLength and math.floor(k) == k
|
||||
end
|
||||
|
||||
local defaultTypeOrders = {
|
||||
local defaultTypeOrders =
|
||||
{
|
||||
['number'] = 1,
|
||||
['boolean'] = 2,
|
||||
['string'] = 3,
|
||||
@@ -176,7 +178,7 @@ local function countTableAppearances(t, tableAppearances)
|
||||
return tableAppearances
|
||||
end
|
||||
|
||||
local copySequence = function(s)
|
||||
local copySequence = function (s)
|
||||
local copy, len = {}, #s
|
||||
for i = 1, len do
|
||||
copy[i] = s[i]
|
||||
@@ -185,7 +187,7 @@ local copySequence = function(s)
|
||||
end
|
||||
|
||||
local function makePath(path, ...)
|
||||
local keys = {...}
|
||||
local keys = { ... }
|
||||
local newPath, len = copySequence(path)
|
||||
for i = 1, #keys do
|
||||
newPath[len + i] = keys[i]
|
||||
@@ -224,10 +226,10 @@ end
|
||||
-------------------------------------------------------------------
|
||||
|
||||
local Inspector = {}
|
||||
local Inspector_mt = {__index = Inspector}
|
||||
local Inspector_mt = { __index = Inspector }
|
||||
|
||||
function Inspector:puts(...)
|
||||
local args = {...}
|
||||
local args = { ... }
|
||||
local buffer = self.buffer
|
||||
local len = #buffer
|
||||
for i = 1, #args do
|
||||
@@ -288,7 +290,7 @@ function Inspector:putTable(t)
|
||||
|
||||
self:puts('{')
|
||||
self:down(
|
||||
function()
|
||||
function ()
|
||||
if toStringResult then
|
||||
self:puts(' -- ', escape(toStringResult))
|
||||
if sequenceLength >= 1 then
|
||||
@@ -389,7 +391,7 @@ end
|
||||
setmetatable(
|
||||
inspect,
|
||||
{
|
||||
__call = function(_, ...)
|
||||
__call = function (_, ...)
|
||||
return inspect.inspect(...)
|
||||
end
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
local Public = {}
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Jailed = require 'utils.datastore.jail_data'
|
||||
local Supporters = require 'utils.datastore.supporters'
|
||||
local Gui = require 'utils.gui'
|
||||
|
||||
@@ -334,8 +332,8 @@ Public.gui_data = function (data)
|
||||
local rpg_enabled = data.rpg_enabled
|
||||
local poke_player_frame_name = data.poke_player_frame_name
|
||||
|
||||
local play_table = Session.get_trusted_table()
|
||||
local jailed = Jailed.get_jailed_table()
|
||||
local play_table = storage.tokens.utils_datastore_session_data.trusted
|
||||
local jailed = storage.tokens.utils_datastore_jail_data.jailed
|
||||
|
||||
local connected_players = #game.connected_players
|
||||
local players = game.players
|
||||
|
||||
@@ -3,6 +3,7 @@ local Task = require 'utils.task'
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
local Print = require('utils.print_override')
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
-- local constants
|
||||
local floor = math.floor
|
||||
@@ -184,15 +185,15 @@ end
|
||||
-- local Server = require 'utils.server'
|
||||
-- local Event = require 'utils.event'
|
||||
--
|
||||
-- Event.add(Server.events.on_server_started,
|
||||
-- Event.add(CreatedEvents.events.on_server_started,
|
||||
-- function()
|
||||
-- Server.try_get_all_data('regulars', callback)
|
||||
-- end)
|
||||
-- Event.add(Server.events.on_changes_detected,
|
||||
-- Event.add(CreatedEvents.events.on_changes_detected,
|
||||
-- function()
|
||||
-- Trigger some sort of automated restart whenever the game ends.
|
||||
-- end)
|
||||
Public.events = { on_server_started = Event.generate_event_name('on_server_started'), on_changes_detected = Event.generate_event_name('on_changes_detected') }
|
||||
-- Defined in CreatedEvents.lua
|
||||
|
||||
-- Starts a new game with the given scenario. Note that this will stop the current game and reset it.
|
||||
---@param scenario_data string|table
|
||||
@@ -1594,6 +1595,7 @@ function Public.ban_handler(event)
|
||||
|
||||
if cmd == 'ban' then
|
||||
Public.set_data(jailed_data_set, target, nil) -- this is added here since we don't want to clutter the jail dataset.
|
||||
Event.raise(CreatedEvents.events.on_player_banned, { player_name = target })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
---@diagnostic disable: lowercase-global
|
||||
local Poll =
|
||||
{
|
||||
send_poll_result_to_discord = function ()
|
||||
@@ -5,6 +6,7 @@ local Poll =
|
||||
}
|
||||
local Token = require 'utils.token'
|
||||
local Server = require 'utils.server'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
|
||||
--- This module is for the web server to call functions and raise events.
|
||||
-- Not intended to be called by scripts.
|
||||
@@ -26,11 +28,11 @@ ServerCommands.raise_scenario_changed = Server.raise_scenario_changed
|
||||
ServerCommands.get_tracked_scenario = Server.get_tracked_scenario
|
||||
|
||||
function ServerCommands.server_started()
|
||||
script.raise_event(Server.events.on_server_started, {})
|
||||
script.raise_event(CreatedEvents.events.on_server_started, {})
|
||||
end
|
||||
|
||||
function ServerCommands.changes_detected()
|
||||
script.raise_event(Server.events.on_changes_detected, {})
|
||||
script.raise_event(CreatedEvents.events.on_changes_detected, {})
|
||||
end
|
||||
|
||||
ServerCommands.set_time = Server.set_time
|
||||
|
||||
295
utils/undo_actions.lua
Normal file
295
utils/undo_actions.lua
Normal file
@@ -0,0 +1,295 @@
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local CreatedEvents = require 'utils.created_events'
|
||||
local Global = require 'utils.global'
|
||||
local Commands = require 'utils.commands'
|
||||
local Task = require 'utils.task_token'
|
||||
|
||||
local module_name = '[Undo actions] '
|
||||
local undo_polls = {}
|
||||
local Public = {}
|
||||
|
||||
Global.register(
|
||||
{
|
||||
undo_polls = undo_polls
|
||||
},
|
||||
function (tbl)
|
||||
undo_polls = tbl.undo_polls
|
||||
end
|
||||
)
|
||||
|
||||
local make_entity_destructible_token =
|
||||
Task.register(
|
||||
function (event)
|
||||
local entity = event.entity
|
||||
if not entity or not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
entity.destructible = true
|
||||
end
|
||||
)
|
||||
|
||||
local function check_undo_queue(player)
|
||||
if not type(player) == 'userdata' then
|
||||
error('Player is not userdata.')
|
||||
end
|
||||
|
||||
local undo_redo_stack = player.undo_redo_stack
|
||||
if undo_redo_stack and undo_redo_stack.get_undo_item_count() > 0 then
|
||||
return undo_redo_stack.get_undo_item_count()
|
||||
end
|
||||
end
|
||||
|
||||
local function do_action_poll(player)
|
||||
if player and type(player) ~= 'userdata' then
|
||||
Server.output_script_data(module_name .. 'Player is not userdata. Getting player from name ' .. player)
|
||||
player = game.get_player(player)
|
||||
end
|
||||
|
||||
if not player or not player.valid then
|
||||
Server.output_script_data(module_name .. 'Player is not valid. Not doing action poll.')
|
||||
return
|
||||
end
|
||||
|
||||
local undo_count = check_undo_queue(player)
|
||||
if not undo_count or undo_count <= 0 then
|
||||
Server.output_script_data(module_name .. 'No undo count found for ' .. player.name .. '. Not doing action poll.')
|
||||
return
|
||||
end
|
||||
Server.output_script_data(module_name .. 'Doing action poll for ' .. player.name .. ' with undo count ' .. undo_count)
|
||||
if undo_count > 0 then
|
||||
game.print(module_name .. player.name .. ' has ' .. undo_count .. ' entities in the undo queue. Creating poll before restoring them.')
|
||||
local unique_id = player.name .. '_' .. 'undo_poll'
|
||||
|
||||
Event.raise(CreatedEvents.events.on_poll_created,
|
||||
{
|
||||
question = player.name .. ' removed ' .. undo_count .. ' entities before getting dealt with. Proceed with restoration?',
|
||||
answers = { 'Yes, restore the entities!', 'No, do not restore the entities!' },
|
||||
duration = 30,
|
||||
custom_data =
|
||||
{
|
||||
unique_id = unique_id,
|
||||
player_name = player.name,
|
||||
surface_index = player.surface.index
|
||||
}
|
||||
})
|
||||
|
||||
Server.output_script_data(module_name .. 'Poll created for ' .. player.name .. ' with id ' .. unique_id)
|
||||
|
||||
undo_polls[#undo_polls + 1] =
|
||||
{
|
||||
unique_id = unique_id,
|
||||
player_index = player.index,
|
||||
player_name = player.name,
|
||||
surface_index = player.surface.index
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local converted_entities =
|
||||
{
|
||||
['straight-rail'] = 'rail',
|
||||
['curved-rail'] = 'rail',
|
||||
}
|
||||
|
||||
local function check_undo_redo_stack(player)
|
||||
if not type(player) == 'userdata' then
|
||||
error('Player is not userdata.')
|
||||
end
|
||||
|
||||
local valid_undos = {}
|
||||
local restored_entities = 0
|
||||
local to_remove_items = 0
|
||||
|
||||
local undo_redo_stack = player.undo_redo_stack
|
||||
if undo_redo_stack and undo_redo_stack.get_undo_item_count() > 0 then
|
||||
for i = 1, undo_redo_stack.get_undo_item_count() do
|
||||
local actions = undo_redo_stack.get_undo_item(i)
|
||||
|
||||
if actions and #actions > 0 then
|
||||
valid_undos[#valid_undos + 1] = actions
|
||||
|
||||
for _, action in pairs(actions) do
|
||||
if not action.surface_index then
|
||||
Server.output_script_data(module_name .. 'Action has no surface index. Not restoring entity.')
|
||||
goto continue_action
|
||||
end
|
||||
|
||||
local surface = game.get_surface(action.surface_index)
|
||||
if not (surface and surface.valid) then
|
||||
Server.output_script_data(module_name .. 'Invalid surface for action.')
|
||||
goto continue_action
|
||||
end
|
||||
|
||||
local target = action.target
|
||||
if not (target and target.name and target.position) then
|
||||
Server.output_script_data(module_name .. 'Invalid target data.')
|
||||
goto continue_action
|
||||
end
|
||||
|
||||
target.force = player.force
|
||||
local entity = surface.create_entity(target)
|
||||
if entity and entity.valid then
|
||||
restored_entities = restored_entities + 1
|
||||
|
||||
local name = converted_entities[target.name]
|
||||
or (string.find(target.name, 'curved') and 'rail')
|
||||
or target.name
|
||||
|
||||
player.remove_item
|
||||
{
|
||||
name = name,
|
||||
quality = target.quality,
|
||||
count = 999
|
||||
}
|
||||
|
||||
if action.insert_plan and next(action.insert_plan) then
|
||||
for _, plan in pairs(action.insert_plan) do
|
||||
for _, items in pairs(plan.items.in_inventory) do
|
||||
if entity.get_module_inventory().index == items.inventory then
|
||||
to_remove_items = to_remove_items + 1
|
||||
entity.get_module_inventory().insert
|
||||
{
|
||||
name = plan.id.name,
|
||||
quality = plan.id.quality,
|
||||
count = 1
|
||||
}
|
||||
end
|
||||
end
|
||||
if to_remove_items > 0 then
|
||||
player.remove_item
|
||||
{
|
||||
name = plan.id.name,
|
||||
quality = plan.id.quality,
|
||||
count = to_remove_items
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
::continue_action::
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Server.output_script_data(module_name .. 'Restored ' .. restored_entities .. ' entities for ' .. player.name)
|
||||
|
||||
if #valid_undos > 0 then
|
||||
while player.undo_redo_stack.get_undo_item_count() > 0 do
|
||||
player.undo_redo_stack.remove_undo_item(player.undo_redo_stack.get_undo_item_count())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(CreatedEvents.events.on_poll_complete, function (event)
|
||||
if not event.winning_answer or not event.winning_answer.text then
|
||||
return
|
||||
end
|
||||
|
||||
local custom_data = event.custom_data
|
||||
if not custom_data then
|
||||
Server.output_script_data(module_name .. 'Custom data is not set. Not checking undo redo stack.')
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = custom_data.player_name
|
||||
if not player_name then
|
||||
return
|
||||
end
|
||||
|
||||
Server.output_script_data(module_name .. 'Poll complete for ' .. player_name .. ' with winning answer ' .. event.winning_answer.text)
|
||||
|
||||
|
||||
if not undo_polls or not next(undo_polls) then
|
||||
Server.output_script_data(module_name .. 'No undo polls found. Not checking undo redo stack.')
|
||||
return
|
||||
end
|
||||
|
||||
for i = 1, #undo_polls do
|
||||
local poll_action = undo_polls[i]
|
||||
if poll_action and poll_action.unique_id == custom_data.unique_id then
|
||||
local surface = game.get_surface(poll_action.surface_index)
|
||||
if not surface or not surface.valid then
|
||||
Server.output_script_data(module_name .. 'Surface is not valid. Not checking undo redo stack.')
|
||||
return
|
||||
end
|
||||
local player = game.get_player(player_name)
|
||||
if not player or not player.valid then
|
||||
Server.output_script_data(module_name .. 'Player is not valid. Not checking undo redo stack.')
|
||||
return
|
||||
end
|
||||
if string.find(event.winning_answer.text, 'Yes') then
|
||||
check_undo_redo_stack(player)
|
||||
Server.output_script_data(module_name .. 'Undo redo stack checked for ' .. player_name)
|
||||
else
|
||||
Server.output_script_data(module_name .. 'Not restore entities. Adding all items to a chest near spawn.')
|
||||
local spawn_position = game.forces.player.get_spawn_position(surface)
|
||||
local non_collidin_position = surface.find_non_colliding_position('blue-chest', spawn_position, 10, 5)
|
||||
local e = surface.create_entity({ name = 'blue-chest', position = non_collidin_position or spawn_position, force = 'player' })
|
||||
if e and e.valid then
|
||||
Task.set_timeout_in_ticks(1000, make_entity_destructible_token, { entity = e })
|
||||
e.set_inventory_size_override(defines.inventory.chest, 1000)
|
||||
game.print(module_name .. 'Adding all items have been transferred to a chest near spawn.')
|
||||
game.print('Located here: [gps=' .. e.position.x .. ',' .. e.position.y .. ',' .. e.surface.name .. ']')
|
||||
local main_inventory = player.get_main_inventory()
|
||||
if main_inventory and main_inventory.valid then
|
||||
for _, item in pairs(main_inventory.get_contents()) do
|
||||
e.insert({ name = item.name, count = item.count })
|
||||
end
|
||||
end
|
||||
player.clear_items_inside()
|
||||
end
|
||||
end
|
||||
Server.output_script_data(module_name .. 'Poll removed from undo polls for ' .. player_name)
|
||||
undo_polls[i] = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(CreatedEvents.events.on_player_banned, function (event)
|
||||
if not event.player_name then
|
||||
return
|
||||
end
|
||||
local player = game.get_player(event.player_name)
|
||||
if not player or not player.valid then
|
||||
Server.output_script_data(module_name .. 'Player is not valid. Not checking undo redo stack.')
|
||||
return
|
||||
end
|
||||
|
||||
Server.output_script_data(module_name .. 'Player event received for ' .. player.name)
|
||||
local undo_count = check_undo_queue(player)
|
||||
if not undo_count or undo_count <= 0 then
|
||||
Server.output_script_data(module_name .. 'No undo count found for ' .. player.name .. '. Not checking undo redo stack.')
|
||||
return
|
||||
end
|
||||
|
||||
check_undo_redo_stack(player)
|
||||
Server.output_script_data(module_name .. 'Undo redo stack checked for ' .. player.name)
|
||||
end)
|
||||
|
||||
Commands.new('undo_player_actions', 'Undoes the actions of a player.')
|
||||
:add_parameter('player', false, 'player')
|
||||
:require_validation('Only utilize this command if the player is jailed and has entities in the undo queue.')
|
||||
:require_admin()
|
||||
:callback(function (player, target_player)
|
||||
if not target_player or not target_player.valid then
|
||||
return player.print('Player is not valid.')
|
||||
end
|
||||
|
||||
local undo_count = check_undo_queue(target_player)
|
||||
if not undo_count or undo_count <= 0 then
|
||||
return player.print('No undo count found for ' .. target_player.name .. '.')
|
||||
end
|
||||
|
||||
check_undo_redo_stack(target_player)
|
||||
player.print('Undone ' .. undo_count .. ' actions for ' .. target_player.name .. '.')
|
||||
end)
|
||||
|
||||
Public.check_undo_redo_stack = check_undo_redo_stack
|
||||
Public.do_action_poll = do_action_poll
|
||||
|
||||
return Public
|
||||
Reference in New Issue
Block a user