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
|
_DUMP_ENV = false
|
||||||
_PROFILE = false
|
_PROFILE = false
|
||||||
|
|
||||||
|
require 'utils.created_events'
|
||||||
require 'utils.server'
|
require 'utils.server'
|
||||||
require 'utils.server_commands'
|
require 'utils.server_commands'
|
||||||
require 'utils.gui.init'
|
require 'utils.gui.init'
|
||||||
require 'utils.command_handler'
|
require 'utils.admin_handler'
|
||||||
require 'utils.utils'
|
require 'utils.utils'
|
||||||
require 'utils.math.math'
|
require 'utils.math.math'
|
||||||
require 'utils.pause_game'
|
require 'utils.pause_game'
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ local SpamProtection = require 'utils.spam_protection'
|
|||||||
local BottomFrame = require 'utils.gui.bottom_frame'
|
local BottomFrame = require 'utils.gui.bottom_frame'
|
||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local Color = require 'utils.color_presets'
|
local Color = require 'utils.color_presets'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
local module_name = '[color=blue][Charging station][/color] '
|
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(defines.events.on_player_joined_game, on_player_joined_game)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
BottomFrame.events.bottom_quickbar_location_changed,
|
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||||
function (event)
|
function (event)
|
||||||
local player_index = event.player_index
|
local player_index = event.player_index
|
||||||
if not player_index then
|
if not player_index then
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ local math2d = require 'math2d'
|
|||||||
local Misc = require 'utils.commands.misc'
|
local Misc = require 'utils.commands.misc'
|
||||||
local Core = require 'utils.core'
|
local Core = require 'utils.core'
|
||||||
local Beams = require 'modules.render_beam'
|
local Beams = require 'modules.render_beam'
|
||||||
local BottomFrame = require 'utils.gui.bottom_frame'
|
|
||||||
local Modifiers = require 'utils.player_modifiers'
|
local Modifiers = require 'utils.player_modifiers'
|
||||||
local Session = require 'utils.datastore.session_data'
|
local Session = require 'utils.datastore.session_data'
|
||||||
local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap'
|
local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap'
|
||||||
local Score = require 'utils.gui.score'
|
local Score = require 'utils.gui.score'
|
||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local FunctionColor = { r = 0.98, g = 0.66, b = 0.22 }
|
local FunctionColor = { r = 0.98, g = 0.66, b = 0.22 }
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local zone_settings = Public.zone_settings
|
local zone_settings = Public.zone_settings
|
||||||
local remove_boost_movement_speed_on_respawn
|
local remove_boost_movement_speed_on_respawn
|
||||||
@@ -3583,7 +3583,7 @@ function Public.set_player_to_god(player)
|
|||||||
|
|
||||||
|
|
||||||
Event.raise(
|
Event.raise(
|
||||||
BottomFrame.events.bottom_quickbar_respawn_raise,
|
CreatedEvents.events.bottom_quickbar_respawn_raise,
|
||||||
{
|
{
|
||||||
player_index = player.index
|
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(35, do_replace_tiles_slowly)
|
||||||
Event.on_nth_tick(200, do_custom_surface_funcs)
|
Event.on_nth_tick(200, do_custom_surface_funcs)
|
||||||
Event.on_nth_tick(60, set_difficulty)
|
Event.on_nth_tick(60, set_difficulty)
|
||||||
Event.add(WD.events.on_wave_created, on_wave_created)
|
Event.add(CreatedEvents.events.on_wave_created, on_wave_created)
|
||||||
Event.add(WD.events.on_primary_target_missing, on_primary_target_missing)
|
Event.add(CreatedEvents.events.on_primary_target_missing, on_primary_target_missing)
|
||||||
|
|
||||||
return Public
|
return Public
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ local Score = require 'utils.gui.score'
|
|||||||
local WD = require 'modules.wave_defense.table'
|
local WD = require 'modules.wave_defense.table'
|
||||||
local Core = require 'utils.core'
|
local Core = require 'utils.core'
|
||||||
local SpamProtection = require 'utils.spam_protection'
|
local SpamProtection = require 'utils.spam_protection'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local module_name = Gui.uid_name()
|
local module_name = Gui.uid_name()
|
||||||
local score_dataset = 'highscores'
|
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_left_game, on_player_left_game)
|
||||||
Event.add(defines.events.on_player_joined_game, on_player_joined_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(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
|
return Public
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ local Core = require 'utils.core'
|
|||||||
local JailData = require 'utils.datastore.jail_data'
|
local JailData = require 'utils.datastore.jail_data'
|
||||||
local IC = require 'maps.mountain_fortress_v3.ic.table'
|
local IC = require 'maps.mountain_fortress_v3.ic.table'
|
||||||
local WPT = require 'maps.mountain_fortress_v3.table'
|
local WPT = require 'maps.mountain_fortress_v3.table'
|
||||||
local OfflinePlayers = require 'modules.clear_vacant_players'
|
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
local main_tile_name = 'black-refined-concrete'
|
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
|
Public.kick_non_trusted_players_from_surface = kick_non_trusted_players_from_surface
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
OfflinePlayers.events.remove_surface,
|
CreatedEvents.events.remove_surface,
|
||||||
function (event)
|
function (event)
|
||||||
local target = event.target
|
local target = event.target
|
||||||
if not target then
|
if not target then
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ local OfflinePlayers = require 'modules.clear_vacant_players'
|
|||||||
local Beam = require 'modules.render_beam'
|
local Beam = require 'modules.render_beam'
|
||||||
local Commands = require 'utils.commands'
|
local Commands = require 'utils.commands'
|
||||||
local RobotLimits = require 'modules.robot_limits'
|
local RobotLimits = require 'modules.robot_limits'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local send_ping_to_channel = Discord.channel_names.mtn_channel
|
local send_ping_to_channel = Discord.channel_names.mtn_channel
|
||||||
local role_to_mention = Discord.role_mentions.mtn_fortress
|
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
|
-- 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.set_difficulty()
|
||||||
Public.disable_creative()
|
Public.disable_creative()
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
local Public = require 'maps.mountain_fortress_v3.table'
|
local Public = require 'maps.mountain_fortress_v3.table'
|
||||||
local RPG = require 'modules.rpg.main'
|
local RPG = require 'modules.rpg.main'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Ai = require 'modules.ai'
|
|
||||||
local Misc = require 'utils.commands.misc'
|
local Misc = require 'utils.commands.misc'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
require 'modules.check_fullness'
|
require 'modules.check_fullness'
|
||||||
|
|
||||||
local random = math.random
|
local random = math.random
|
||||||
@@ -502,7 +502,7 @@ Event.add(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Ai.events.on_entity_mined,
|
CreatedEvents.events.on_entity_mined,
|
||||||
function (event)
|
function (event)
|
||||||
if not event then
|
if not event then
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ local Server = require 'utils.server'
|
|||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local Task = require 'utils.task_token'
|
local Task = require 'utils.task_token'
|
||||||
local SpamProtection = require 'utils.spam_protection'
|
local SpamProtection = require 'utils.spam_protection'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local module_name = Gui.uid_name()
|
local module_name = Gui.uid_name()
|
||||||
local score_dataset = 'seasons'
|
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_left_game, on_player_left_game)
|
||||||
Event.add(defines.events.on_player_joined_game, on_player_joined_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(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
|
return Public
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ local Public = require 'maps.mountain_fortress_v3.stateful.table'
|
|||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local WD = require 'modules.wave_defense.table'
|
local WD = require 'modules.wave_defense.table'
|
||||||
local Beam = require 'modules.render_beam'
|
local Beam = require 'modules.render_beam'
|
||||||
local RPG = require 'modules.rpg.main'
|
local CreatedEvents = require 'utils.created_events'
|
||||||
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
|
||||||
|
|
||||||
Public.stateful_gui = require 'maps.mountain_fortress_v3.stateful.gui'
|
Public.stateful_gui = require 'maps.mountain_fortress_v3.stateful.gui'
|
||||||
Public.stateful_blueprints = require 'maps.mountain_fortress_v3.stateful.blueprints'
|
Public.stateful_blueprints = require 'maps.mountain_fortress_v3.stateful.blueprints'
|
||||||
|
|
||||||
local random = math.random
|
local random = math.random
|
||||||
|
|
||||||
local valid_types = {
|
local valid_types =
|
||||||
|
{
|
||||||
['unit'] = true,
|
['unit'] = true,
|
||||||
['turret'] = true
|
['turret'] = true
|
||||||
}
|
}
|
||||||
@@ -97,22 +97,22 @@ Event.on_nth_tick(
|
|||||||
Public.set_stateful(
|
Public.set_stateful(
|
||||||
'stateful_spawn_points',
|
'stateful_spawn_points',
|
||||||
{
|
{
|
||||||
{ { x = -205, y = -37 }, { x = 195, y = 37 } },
|
{ { x = -205, y = -37 }, { x = 195, y = 37 } },
|
||||||
{ { x = -205, y = -112 }, { x = 195, y = 112 } },
|
{ { x = -205, y = -112 }, { x = 195, y = 112 } },
|
||||||
{ { x = -205, y = -146 }, { x = 195, y = 146 } },
|
{ { x = -205, y = -146 }, { x = 195, y = 146 } },
|
||||||
{ { x = -205, y = -112 }, { x = 195, y = 112 } },
|
{ { x = -205, y = -112 }, { x = 195, y = 112 } },
|
||||||
{ { x = -205, y = -72 }, { x = 195, y = 72 } },
|
{ { x = -205, y = -72 }, { x = 195, y = 72 } },
|
||||||
{ { x = -205, y = -146 }, { x = 195, y = 146 } },
|
{ { x = -205, y = -146 }, { x = 195, y = 146 } },
|
||||||
{ { x = -205, y = -37 }, { x = 195, y = 37 } },
|
{ { x = -205, y = -37 }, { x = 195, y = 37 } },
|
||||||
{ { x = -205, y = -5 }, { x = 195, y = 5 } },
|
{ { x = -205, y = -5 }, { x = 195, y = 5 } },
|
||||||
{ { x = -205, y = -23 }, { x = 195, y = 23 } },
|
{ { x = -205, y = -23 }, { x = 195, y = 23 } },
|
||||||
{ { x = -205, y = -5 }, { x = 195, y = 5 } },
|
{ { x = -205, y = -5 }, { x = 195, y = 5 } },
|
||||||
{ { x = -205, y = -72 }, { x = 195, y = 72 } },
|
{ { x = -205, y = -72 }, { x = 195, y = 72 } },
|
||||||
{ { x = -205, y = -23 }, { x = 195, y = 23 } },
|
{ { x = -205, y = -23 }, { x = 195, y = 23 } },
|
||||||
{ { x = -205, y = -54 }, { x = 195, y = 54 } },
|
{ { x = -205, y = -54 }, { x = 195, y = 54 } },
|
||||||
{ { x = -205, y = -80 }, { x = 195, y = 80 } },
|
{ { x = -205, y = -80 }, { x = 195, y = 80 } },
|
||||||
{ { x = -205, y = -54 }, { x = 195, y = 54 } },
|
{ { x = -205, y = -54 }, { x = 195, y = 54 } },
|
||||||
{ { x = -205, y = -80 }, { x = 195, y = 80 } },
|
{ { x = -205, y = -80 }, { x = 195, y = 80 } },
|
||||||
{ { x = -205, y = -103 }, { x = 195, y = 103 } },
|
{ { x = -205, y = -103 }, { x = 195, y = 103 } },
|
||||||
{ { x = -205, y = -150 }, { x = 195, y = 150 } },
|
{ { x = -205, y = -150 }, { x = 195, y = 150 } },
|
||||||
{ { x = -205, y = -103 }, { x = 195, y = 103 } },
|
{ { x = -205, y = -103 }, { x = 195, y = 103 } },
|
||||||
@@ -144,7 +144,7 @@ Event.on_nth_tick(
|
|||||||
WD.set_main_target()
|
WD.set_main_target()
|
||||||
WD.build_worm_custom()
|
WD.build_worm_custom()
|
||||||
-- WD.place_custom_nest(locomotive.surface, area[1], 'aggressors_frenzy')
|
-- 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()
|
Public.set_multi_command_final_battle()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -208,7 +208,7 @@ Event.add(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
RPG.events.on_spell_cast_success,
|
CreatedEvents.events.on_spell_cast_success,
|
||||||
function (event)
|
function (event)
|
||||||
local player = game.get_player(event.player_index)
|
local player = game.get_player(event.player_index)
|
||||||
if not player or not player.valid then
|
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(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(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)
|
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||||
|
|
||||||
return Public
|
return Public
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ local RPG = require 'modules.rpg.table'
|
|||||||
local Beam = require 'modules.render_beam'
|
local Beam = require 'modules.render_beam'
|
||||||
local Discord = require 'utils.discord'
|
local Discord = require 'utils.discord'
|
||||||
local Difficulty = require 'modules.difficulty_vote_by_amount'
|
local Difficulty = require 'modules.difficulty_vote_by_amount'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local this =
|
local this =
|
||||||
{
|
{
|
||||||
@@ -2410,14 +2411,14 @@ function Public.increase_enemy_damage_and_health()
|
|||||||
this.enemies_boosted = true
|
this.enemies_boosted = true
|
||||||
|
|
||||||
if this.rounds_survived == 1 then
|
if this.rounds_survived == 1 then
|
||||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
||||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.aggressors })
|
Event.raise(CreatedEvents.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.aggressors_frenzy })
|
||||||
else
|
else
|
||||||
for _ = 1, this.rounds_survived do
|
for _ = 1, this.rounds_survived do
|
||||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
Event.raise(CreatedEvents.events.on_biters_evolved, { force = game.forces.enemy, health_increase = true })
|
||||||
Event.raise(WD.events.on_biters_evolved, { force = game.forces.aggressors })
|
Event.raise(CreatedEvents.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.aggressors_frenzy })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2483,7 +2484,7 @@ function Public.stateful_on_server_started()
|
|||||||
end
|
end
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Server.events.on_server_started,
|
CreatedEvents.events.on_server_started,
|
||||||
function ()
|
function ()
|
||||||
if this.settings_applied then
|
if this.settings_applied then
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ local Task = require 'utils.task_token'
|
|||||||
local Config = require 'utils.gui.config'
|
local Config = require 'utils.gui.config'
|
||||||
local Fullness = require 'modules.check_fullness'
|
local Fullness = require 'modules.check_fullness'
|
||||||
local Color = require 'utils.color_presets'
|
local Color = require 'utils.color_presets'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local stateful_settings =
|
local stateful_settings =
|
||||||
{
|
{
|
||||||
@@ -845,7 +846,7 @@ local apply_settings_token =
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Server.events.on_server_started,
|
CreatedEvents.events.on_server_started,
|
||||||
function ()
|
function ()
|
||||||
local start_data = Server.get_start_data()
|
local start_data = Server.get_start_data()
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ local Classes = require('maps.pirates.roles.classes')
|
|||||||
local Token = require('utils.token')
|
local Token = require('utils.token')
|
||||||
local Task = require('utils.task')
|
local Task = require('utils.task')
|
||||||
local SurfacesCommon = require('maps.pirates.surfaces.common')
|
local SurfacesCommon = require('maps.pirates.surfaces.common')
|
||||||
local BottomFrame = require('utils.gui.bottom_frame')
|
local CreatedEvents = require('utils.created_events')
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
local enum = {
|
local enum = {
|
||||||
@@ -437,7 +437,7 @@ function Public.leave_crew(player, to_lobby, quiet)
|
|||||||
)
|
)
|
||||||
player.force = Common.lobby_force_name
|
player.force = Common.lobby_force_name
|
||||||
player.create_character()
|
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
|
end
|
||||||
|
|
||||||
memory.crewplayerindices = Utils.ordered_table_with_values_removed(memory.crewplayerindices, player.index)
|
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 Utils = require('maps.pirates.utils_local')
|
||||||
local CoreData = require('maps.pirates.coredata')
|
local CoreData = require('maps.pirates.coredata')
|
||||||
local Common = require('maps.pirates.common')
|
local Common = require('maps.pirates.common')
|
||||||
|
local CreatedEvents = require('utils.created_events')
|
||||||
|
|
||||||
local module_name = Gui.uid_name()
|
local module_name = Gui.uid_name()
|
||||||
-- local module_name = 'Highscore'
|
-- 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_left_game, on_player_left_game)
|
||||||
Event.add(defines.events.on_player_joined_game, on_player_joined_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(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
|
return Public
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ local Server = require 'utils.server'
|
|||||||
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
|
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
|
||||||
local SoftReset = require 'utils.functions.soft_reset'
|
local SoftReset = require 'utils.functions.soft_reset'
|
||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local math_random = math.random
|
local math_random = math.random
|
||||||
local table_shuffle = table.shuffle_table
|
local table_shuffle = table.shuffle_table
|
||||||
@@ -285,7 +286,7 @@ end
|
|||||||
Event.add(defines.events.on_tick, on_tick)
|
Event.add(defines.events.on_tick, on_tick)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Server.events.on_server_started,
|
CreatedEvents.events.on_server_started,
|
||||||
function ()
|
function ()
|
||||||
local this = ScenarioTable.get_table()
|
local this = ScenarioTable.get_table()
|
||||||
if this.settings_applied then
|
if this.settings_applied then
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ local Utils = require 'utils.common'
|
|||||||
local Global = require 'utils.global'
|
local Global = require 'utils.global'
|
||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
local Task = require 'utils.task'
|
local Task = require 'utils.task'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local this = {
|
local this =
|
||||||
|
{
|
||||||
timers = {},
|
timers = {},
|
||||||
characters = {},
|
characters = {},
|
||||||
characters_unit_numbers = {},
|
characters_unit_numbers = {},
|
||||||
@@ -20,14 +22,15 @@ Global.register(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
local Public = { events = { on_entity_mined = Event.generate_event_name('on_entity_mined') } }
|
local Public = {}
|
||||||
|
|
||||||
local max_keepalive = 54000 -- 15 minutes
|
local max_keepalive = 54000 -- 15 minutes
|
||||||
local remove = table.remove
|
local remove = table.remove
|
||||||
local round = math.round
|
local round = math.round
|
||||||
local default_radius = 5
|
local default_radius = 5
|
||||||
|
|
||||||
local armor_names = {
|
local armor_names =
|
||||||
|
{
|
||||||
'power-armor-mk2',
|
'power-armor-mk2',
|
||||||
'power-armor',
|
'power-armor',
|
||||||
'modular-armor',
|
'modular-armor',
|
||||||
@@ -35,7 +38,8 @@ local armor_names = {
|
|||||||
'light-armor'
|
'light-armor'
|
||||||
}
|
}
|
||||||
|
|
||||||
local weapon_names = {
|
local weapon_names =
|
||||||
|
{
|
||||||
['rocket-launcher'] = 'rocket',
|
['rocket-launcher'] = 'rocket',
|
||||||
['submachine-gun'] = { 'uranium-rounds-magazine', 'piercing-rounds-magazine', 'firearm-magazine' },
|
['submachine-gun'] = { 'uranium-rounds-magazine', 'piercing-rounds-magazine', 'firearm-magazine' },
|
||||||
['shotgun'] = { 'piercing-shotgun-shell', 'shotgun-shell' },
|
['shotgun'] = { 'piercing-shotgun-shell', 'shotgun-shell' },
|
||||||
@@ -43,7 +47,8 @@ local weapon_names = {
|
|||||||
}
|
}
|
||||||
local remove_character
|
local remove_character
|
||||||
|
|
||||||
Public.command = {
|
Public.command =
|
||||||
|
{
|
||||||
noop = 0,
|
noop = 0,
|
||||||
seek_and_destroy_cmd = 1,
|
seek_and_destroy_cmd = 1,
|
||||||
seek_and_mine_cmd = 2
|
seek_and_mine_cmd = 2
|
||||||
@@ -54,7 +59,8 @@ local clear_corpse_token =
|
|||||||
function (event)
|
function (event)
|
||||||
local position = event.position
|
local position = event.position
|
||||||
local surface = game.get_surface(event.surface_index)
|
local surface = game.get_surface(event.surface_index)
|
||||||
local search_info = {
|
local search_info =
|
||||||
|
{
|
||||||
type = 'character-corpse',
|
type = 'character-corpse',
|
||||||
position = position,
|
position = position,
|
||||||
radius = 1
|
radius = 1
|
||||||
@@ -125,7 +131,8 @@ end
|
|||||||
local function add_character(player_index, entity, render_id, data)
|
local function add_character(player_index, entity, render_id, data)
|
||||||
local index = #this.characters + 1
|
local index = #this.characters + 1
|
||||||
if not this.characters[index] then
|
if not this.characters[index] then
|
||||||
this.characters[index] = {
|
this.characters[index] =
|
||||||
|
{
|
||||||
player_index = player_index,
|
player_index = player_index,
|
||||||
index = index,
|
index = index,
|
||||||
unit_number = entity.unit_number,
|
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_x = Utils.get_axis(dest, 'x')
|
||||||
local dest_y = Utils.get_axis(dest, 'y')
|
local dest_y = Utils.get_axis(dest, 'y')
|
||||||
|
|
||||||
local step = {
|
local step =
|
||||||
|
{
|
||||||
x = nil,
|
x = nil,
|
||||||
y = nil
|
y = nil
|
||||||
}
|
}
|
||||||
@@ -211,7 +219,8 @@ local function get_dir(src, dest)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function move_to(entity, target, min_distance)
|
local function move_to(entity, target, min_distance)
|
||||||
local state = {
|
local state =
|
||||||
|
{
|
||||||
walking = false
|
walking = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +228,8 @@ local function move_to(entity, target, min_distance)
|
|||||||
if min_distance < distance then
|
if min_distance < distance then
|
||||||
local dir = get_dir(entity.position, target.position)
|
local dir = get_dir(entity.position, target.position)
|
||||||
if dir then
|
if dir then
|
||||||
state = {
|
state =
|
||||||
|
{
|
||||||
walking = true,
|
walking = true,
|
||||||
direction = dir
|
direction = dir
|
||||||
}
|
}
|
||||||
@@ -269,7 +279,8 @@ end
|
|||||||
|
|
||||||
local function shoot_at(entity, target)
|
local function shoot_at(entity, target)
|
||||||
entity.selected = target
|
entity.selected = target
|
||||||
entity.shooting_state = {
|
entity.shooting_state =
|
||||||
|
{
|
||||||
state = defines.shooting.shooting_enemies,
|
state = defines.shooting.shooting_enemies,
|
||||||
position = target.position
|
position = target.position
|
||||||
}
|
}
|
||||||
@@ -280,7 +291,7 @@ local function check_progress_and_raise_event(data)
|
|||||||
if not data.raised_event then
|
if not data.raised_event then
|
||||||
data.raised_event = true
|
data.raised_event = true
|
||||||
Event.raise(
|
Event.raise(
|
||||||
Public.events.on_entity_mined,
|
CreatedEvents.events.on_entity_mined,
|
||||||
{
|
{
|
||||||
player_index = data.player_index,
|
player_index = data.player_index,
|
||||||
entity = data.entity.selected,
|
entity = data.entity.selected,
|
||||||
@@ -298,7 +309,8 @@ local function mine_entity(data, target)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function shoot_stop(entity)
|
local function shoot_stop(entity)
|
||||||
entity.shooting_state = {
|
entity.shooting_state =
|
||||||
|
{
|
||||||
state = defines.shooting.not_shooting,
|
state = defines.shooting.not_shooting,
|
||||||
position = { 0, 0 }
|
position = { 0, 0 }
|
||||||
}
|
}
|
||||||
@@ -395,15 +407,18 @@ local function seek_and_mine(data)
|
|||||||
position = player.position
|
position = player.position
|
||||||
end
|
end
|
||||||
|
|
||||||
local search_info = {
|
local search_info =
|
||||||
|
{
|
||||||
position = position,
|
position = position,
|
||||||
radius = data.radius,
|
radius = data.radius,
|
||||||
type = {
|
type =
|
||||||
|
{
|
||||||
'simple-entity-with-owner',
|
'simple-entity-with-owner',
|
||||||
'simple-entity',
|
'simple-entity',
|
||||||
'tree'
|
'tree'
|
||||||
},
|
},
|
||||||
force = {
|
force =
|
||||||
|
{
|
||||||
'neutral'
|
'neutral'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -463,7 +478,8 @@ local function seek_enemy_and_destroy(data)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local search_info = {
|
local search_info =
|
||||||
|
{
|
||||||
type = { 'unit', 'unit-spawner', 'turret' },
|
type = { 'unit', 'unit-spawner', 'turret' },
|
||||||
position = entity.position,
|
position = entity.position,
|
||||||
radius = data.radius,
|
radius = data.radius,
|
||||||
@@ -552,10 +568,12 @@ function Public.create_char(data)
|
|||||||
local index = #this.characters + 1
|
local index = #this.characters + 1
|
||||||
|
|
||||||
local render_id =
|
local render_id =
|
||||||
rendering.draw_text {
|
rendering.draw_text
|
||||||
|
{
|
||||||
text = player.name .. "'s drone #" .. index,
|
text = player.name .. "'s drone #" .. index,
|
||||||
surface = player.surface,
|
surface = player.surface,
|
||||||
target = {
|
target =
|
||||||
|
{
|
||||||
entity = entity,
|
entity = entity,
|
||||||
offset = { 0, -2.25 },
|
offset = { 0, -2.25 },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ local Event = require 'utils.event'
|
|||||||
local BottomFrame = require 'utils.gui.bottom_frame'
|
local BottomFrame = require 'utils.gui.bottom_frame'
|
||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local Task = require 'utils.task_token'
|
local Task = require 'utils.task_token'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local auto_stash_button_name = Gui.uid_name()
|
local auto_stash_button_name = Gui.uid_name()
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
@@ -51,11 +52,11 @@ local on_init_token =
|
|||||||
if this.insert_into_furnace and this.insert_into_wagon then
|
if this.insert_into_furnace and this.insert_into_wagon then
|
||||||
tooltip = { "modules_auto_stash.furnace_and_wagon_tooltip" }
|
tooltip = { "modules_auto_stash.furnace_and_wagon_tooltip" }
|
||||||
elseif this.insert_into_furnace then
|
elseif this.insert_into_furnace then
|
||||||
tooltip = { "modules_auto_stash.furnace_tooltip" }
|
tooltip = { "modules_auto_stash.furnace_tooltip" }
|
||||||
elseif this.insert_into_wagon then
|
elseif this.insert_into_wagon then
|
||||||
tooltip = { "modules_auto_stash.wagon_tooltip" }
|
tooltip = { "modules_auto_stash.wagon_tooltip" }
|
||||||
else
|
else
|
||||||
tooltip = { "modules_auto_stash.other_tooltip" }
|
tooltip = { "modules_auto_stash.other_tooltip" }
|
||||||
end
|
end
|
||||||
|
|
||||||
this.tooltip = tooltip
|
this.tooltip = tooltip
|
||||||
@@ -230,7 +231,7 @@ local function get_nearby_chests(player, a, furnace, wagon)
|
|||||||
|
|
||||||
if furnace then
|
if furnace then
|
||||||
container_type = { 'furnace' }
|
container_type = { 'furnace' }
|
||||||
inventory_type = defines.inventory.furnace_source
|
inventory_type = defines.inventory.crafter_input
|
||||||
end
|
end
|
||||||
if wagon then
|
if wagon then
|
||||||
container_type = { 'cargo-wagon', 'logistic-container' }
|
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(defines.events.on_player_joined_game, on_player_joined_game)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
BottomFrame.events.bottom_quickbar_location_changed,
|
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||||
function (event)
|
function (event)
|
||||||
if not this.enabled then
|
if not this.enabled then
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ local Global = require 'utils.global'
|
|||||||
local Task = require 'utils.task'
|
local Task = require 'utils.task'
|
||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
local insert = table.insert
|
local insert = table.insert
|
||||||
@@ -19,11 +20,6 @@ local sqrt = math.sqrt
|
|||||||
local round = math.round
|
local round = math.round
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
Public.events =
|
|
||||||
{
|
|
||||||
custom_on_entity_died = Event.generate_event_name('custom_on_entity_died')
|
|
||||||
}
|
|
||||||
|
|
||||||
local this =
|
local this =
|
||||||
{
|
{
|
||||||
enabled = true,
|
enabled = true,
|
||||||
@@ -369,13 +365,13 @@ local function on_entity_damaged(event)
|
|||||||
|
|
||||||
if cause then
|
if cause then
|
||||||
if cause.valid 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)
|
biter.die(cause.force, cause)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Event.raise(Public.events.custom_on_entity_died, event)
|
Event.raise(CreatedEvents.events.custom_on_entity_died, event)
|
||||||
biter.die(biter.force)
|
biter.die(biter.force)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ local Alert = require 'utils.alert'
|
|||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Task = require 'utils.task_token'
|
local Task = require 'utils.task_token'
|
||||||
local Config = require 'utils.gui.config'
|
local Config = require 'utils.gui.config'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local this =
|
local this =
|
||||||
{
|
{
|
||||||
@@ -26,7 +27,7 @@ Global.register(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
local Public = { events = { remove_surface = Event.generate_event_name('remove_surface') } }
|
local Public = {}
|
||||||
local remove = table.remove
|
local remove = table.remove
|
||||||
local insert = table.insert
|
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[4] = target.get_inventory(defines.inventory.character_ammo)
|
||||||
player_inv[5] = target.get_inventory(defines.inventory.character_trash)
|
player_inv[5] = target.get_inventory(defines.inventory.character_trash)
|
||||||
if this.offline_players_surface_removal then
|
if this.offline_players_surface_removal then
|
||||||
Event.raise(this.events.remove_surface, { target = target })
|
Event.raise(CreatedEvents.events.remove_surface, { target = target })
|
||||||
end
|
end
|
||||||
|
|
||||||
local found_items = false
|
local found_items = false
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
--luacheck: ignore
|
--luacheck: ignore
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local HDT = require 'modules.hidden_dimension.table'
|
local HDT = require 'modules.hidden_dimension.table'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local Public = {}
|
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.
|
--- If true then surface will be picked to nauvis.
|
||||||
Public.enable_auto_init = true
|
Public.enable_auto_init = true
|
||||||
@@ -30,7 +27,7 @@ end
|
|||||||
local function teleport(entity, pos, surface)
|
local function teleport(entity, pos, surface)
|
||||||
local sane_pos = surface.find_non_colliding_position(entity.name, pos, 0, 1, 1)
|
local sane_pos = surface.find_non_colliding_position(entity.name, pos, 0, 1, 1)
|
||||||
if entity.type == 'character' then
|
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
|
if v.character == entity then
|
||||||
v.teleport(sane_pos, surface)
|
v.teleport(sane_pos, surface)
|
||||||
end
|
end
|
||||||
@@ -44,7 +41,7 @@ local function clear_surroundings(surface, pos)
|
|||||||
if entity[i].type ~= 'character' then
|
if entity[i].type ~= 'character' then
|
||||||
entity[i].destroy()
|
entity[i].destroy()
|
||||||
else
|
else
|
||||||
teleport(entity[i], {0, 0}, entity[i].surface)
|
teleport(entity[i], { 0, 0 }, entity[i].surface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -69,13 +66,13 @@ local function transport_resources(container1, container2, transport_type)
|
|||||||
local temperature = 0
|
local temperature = 0
|
||||||
|
|
||||||
local function test_for(temp)
|
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
|
if count ~= 0 then
|
||||||
temperature = temp
|
temperature = temp
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
container.insert_fluid({name = 'steam', amount = count, temperature = temp})
|
container.insert_fluid({ name = 'steam', amount = count, temperature = temp })
|
||||||
end
|
end
|
||||||
|
|
||||||
test_for(15)
|
test_for(15)
|
||||||
@@ -114,13 +111,13 @@ local function transport_resources(container1, container2, transport_type)
|
|||||||
temp = math_max(at, bt)
|
temp = math_max(at, bt)
|
||||||
container1.clear_fluid_inside()
|
container1.clear_fluid_inside()
|
||||||
container2.clear_fluid_inside()
|
container2.clear_fluid_inside()
|
||||||
container1.insert_fluid({name = name1, amount = v, temperature = temp})
|
container1.insert_fluid({ name = name1, amount = v, temperature = temp })
|
||||||
container2.insert_fluid({name = name2, amount = v, temperature = temp})
|
container2.insert_fluid({ name = name2, amount = v, temperature = temp })
|
||||||
else
|
else
|
||||||
container1.clear_fluid_inside()
|
container1.clear_fluid_inside()
|
||||||
container2.clear_fluid_inside()
|
container2.clear_fluid_inside()
|
||||||
container1.insert_fluid({name = name1, amount = v})
|
container1.insert_fluid({ name = name1, amount = v })
|
||||||
container2.insert_fluid({name = name2, amount = v})
|
container2.insert_fluid({ name = name2, amount = v })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -128,10 +125,10 @@ local function transport_resources(container1, container2, transport_type)
|
|||||||
local chest1 = container1.get_inventory(defines.inventory.chest)
|
local chest1 = container1.get_inventory(defines.inventory.chest)
|
||||||
local chest2 = container2.get_inventory(defines.inventory.chest)
|
local chest2 = container2.get_inventory(defines.inventory.chest)
|
||||||
for k, v in pairs(chest1.get_contents()) do
|
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)
|
local c = chest2.insert(t)
|
||||||
if (c > 0) then
|
if (c > 0) then
|
||||||
chest1.remove({name = k, count = c})
|
chest1.remove({ name = k, count = c })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -168,21 +165,21 @@ local function create_underground_floor(surface, size, going_down)
|
|||||||
local tiles = {}
|
local tiles = {}
|
||||||
for i = 0, area.x - 1 do
|
for i = 0, area.x - 1 do
|
||||||
for j = 0, area.y - 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
|
||||||
end
|
end
|
||||||
|
|
||||||
surface.set_tiles(tiles)
|
surface.set_tiles(tiles)
|
||||||
end
|
end
|
||||||
tile_generation('tutorial-grid', {x = 0, y = 0}, {x = -size / 2, y = -size / 2}, {x = size - 1, y = size})
|
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('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('hazard-concrete-left', { x = 0, y = 0 }, { x = -3, y = -7 }, { x = 6, y = 3 })
|
||||||
|
|
||||||
if going_down then
|
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 = -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 = -2, y = -2 }, { x = 4, y = 3 })
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -203,30 +200,32 @@ local function create_main_surface(rebuild)
|
|||||||
|
|
||||||
if rebuild then
|
if rebuild then
|
||||||
hidden_dimension.main_surface.reference =
|
hidden_dimension.main_surface.reference =
|
||||||
surface.create_entity {
|
surface.create_entity
|
||||||
name = 'car',
|
{
|
||||||
position = position,
|
name = 'car',
|
||||||
force = game.forces.enemy,
|
position = position,
|
||||||
create_build_effect_smoke = false
|
force = game.forces.enemy,
|
||||||
}
|
create_build_effect_smoke = false
|
||||||
|
}
|
||||||
hidden_dimension.main_surface.reference.minable = false
|
hidden_dimension.main_surface.reference.minable = false
|
||||||
hidden_dimension.main_surface.reference.destructible = false
|
hidden_dimension.main_surface.reference.destructible = false
|
||||||
hidden_dimension.main_surface.reference.operable = 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
|
return
|
||||||
end
|
end
|
||||||
if not hidden_dimension.main_surface.reference or not hidden_dimension.main_surface.reference.valid then
|
if not hidden_dimension.main_surface.reference or not hidden_dimension.main_surface.reference.valid then
|
||||||
hidden_dimension.main_surface.reference =
|
hidden_dimension.main_surface.reference =
|
||||||
surface.create_entity {
|
surface.create_entity
|
||||||
name = 'car',
|
{
|
||||||
position = {position.x, position.y - 23},
|
name = 'car',
|
||||||
force = game.forces.enemy,
|
position = { position.x, position.y - 23 },
|
||||||
create_build_effect_smoke = false
|
force = game.forces.enemy,
|
||||||
}
|
create_build_effect_smoke = false
|
||||||
|
}
|
||||||
hidden_dimension.main_surface.reference.minable = false
|
hidden_dimension.main_surface.reference.minable = false
|
||||||
hidden_dimension.main_surface.reference.destructible = false
|
hidden_dimension.main_surface.reference.destructible = false
|
||||||
hidden_dimension.main_surface.reference.operable = 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
|
if hidden_dimension.logistic_research_level == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -237,10 +236,10 @@ end
|
|||||||
local function create_underground_surfaces()
|
local function create_underground_surfaces()
|
||||||
local function create_underground(floor_table, name, going_down)
|
local function create_underground(floor_table, name, going_down)
|
||||||
--local underground_level
|
--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.always_day = true
|
||||||
floor_table.surface.daytime = 0.5
|
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()
|
floor_table.surface.force_generate_chunk_requests()
|
||||||
local clear_ent = floor_table.surface.find_entities()
|
local clear_ent = floor_table.surface.find_entities()
|
||||||
for i, _ in ipairs(clear_ent) do
|
for i, _ in ipairs(clear_ent) do
|
||||||
@@ -249,17 +248,18 @@ local function create_underground_surfaces()
|
|||||||
floor_table.name = name
|
floor_table.name = name
|
||||||
floor_table.size = 16
|
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)
|
create_underground_floor(floor_table.surface, floor_table.size, going_down)
|
||||||
|
|
||||||
floor_table.going_up.reference =
|
floor_table.going_up.reference =
|
||||||
floor_table.surface.create_entity {
|
floor_table.surface.create_entity
|
||||||
name = 'car',
|
{
|
||||||
position = {0, -6},
|
name = 'car',
|
||||||
force = game.forces.enemy,
|
position = { 0, -6 },
|
||||||
create_build_effect_smoke = false
|
force = game.forces.enemy,
|
||||||
}
|
create_build_effect_smoke = false
|
||||||
|
}
|
||||||
rendering.draw_light(
|
rendering.draw_light(
|
||||||
{
|
{
|
||||||
sprite = 'utility/light_medium',
|
sprite = 'utility/light_medium',
|
||||||
@@ -267,7 +267,7 @@ local function create_underground_surfaces()
|
|||||||
intensity = 1,
|
intensity = 1,
|
||||||
minimum_darkness = 0,
|
minimum_darkness = 0,
|
||||||
oriented = true,
|
oriented = true,
|
||||||
color = {255, 255, 255},
|
color = { 255, 255, 255 },
|
||||||
target = floor_table.going_up.reference,
|
target = floor_table.going_up.reference,
|
||||||
surface = floor_table.surface,
|
surface = floor_table.surface,
|
||||||
visible = true,
|
visible = true,
|
||||||
@@ -277,20 +277,21 @@ local function create_underground_surfaces()
|
|||||||
floor_table.going_up.reference.minable = false
|
floor_table.going_up.reference.minable = false
|
||||||
floor_table.going_up.reference.destructible = false
|
floor_table.going_up.reference.destructible = false
|
||||||
floor_table.going_up.reference.operable = 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
|
if going_down then
|
||||||
floor_table.going_down.reference =
|
floor_table.going_down.reference =
|
||||||
floor_table.surface.create_entity {
|
floor_table.surface.create_entity
|
||||||
name = 'car',
|
{
|
||||||
position = {0, 4},
|
name = 'car',
|
||||||
force = game.forces.enemy,
|
position = { 0, 4 },
|
||||||
create_build_effect_smoke = false
|
force = game.forces.enemy,
|
||||||
}
|
create_build_effect_smoke = false
|
||||||
|
}
|
||||||
floor_table.going_down.reference.minable = false
|
floor_table.going_down.reference.minable = false
|
||||||
floor_table.going_down.reference.destructible = false
|
floor_table.going_down.reference.destructible = false
|
||||||
floor_table.going_down.reference.operable = 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(
|
rendering.draw_light(
|
||||||
{
|
{
|
||||||
@@ -299,7 +300,7 @@ local function create_underground_surfaces()
|
|||||||
intensity = 1,
|
intensity = 1,
|
||||||
minimum_darkness = 0,
|
minimum_darkness = 0,
|
||||||
oriented = true,
|
oriented = true,
|
||||||
color = {255, 255, 255},
|
color = { 255, 255, 255 },
|
||||||
target = floor_table.going_down.reference,
|
target = floor_table.going_down.reference,
|
||||||
surface = floor_table.surface,
|
surface = floor_table.surface,
|
||||||
visible = true,
|
visible = true,
|
||||||
@@ -350,13 +351,13 @@ local function logistic_update()
|
|||||||
local function energy_update(t)
|
local function energy_update(t)
|
||||||
local g = 0
|
local g = 0
|
||||||
local c = 0
|
local c = 0
|
||||||
for k, v in pairs(t) do
|
for _, v in pairs(t) do
|
||||||
if (v.valid) then
|
if (v.valid) then
|
||||||
g = g + v.energy
|
g = g + v.energy
|
||||||
c = c + v.electric_buffer_size
|
c = c + v.electric_buffer_size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for k, v in pairs(t) do
|
for _, v in pairs(t) do
|
||||||
if (v.valid) then
|
if (v.valid) then
|
||||||
local r = (v.electric_buffer_size / c)
|
local r = (v.electric_buffer_size / c)
|
||||||
v.energy = g * r
|
v.energy = g * r
|
||||||
@@ -424,7 +425,7 @@ local function on_research_finished(event)
|
|||||||
hidden_dimension.logistic_research_level = 3
|
hidden_dimension.logistic_research_level = 3
|
||||||
Public.upgrade_transport_buildings(3)
|
Public.upgrade_transport_buildings(3)
|
||||||
elseif event.research.name == 'electric-energy-accumulators' then
|
elseif event.research.name == 'electric-energy-accumulators' then
|
||||||
-- fix power
|
-- fix power
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -439,24 +440,26 @@ local function through_teleporter_update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function surface_play_sound(sound_path, surface, pos)
|
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
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local to_teleport_out_entity_list =
|
local to_teleport_out_entity_list =
|
||||||
source.surface.find_entities_filtered {
|
source.surface.find_entities_filtered
|
||||||
area = {
|
{
|
||||||
{source.position.x - 1.1, source.position.y - 1.1},
|
area =
|
||||||
{source.position.x + 1.1, source.position.y + 1.1}
|
{
|
||||||
},
|
{ source.position.x - 1.1, source.position.y - 1.1 },
|
||||||
type = 'character'
|
{ source.position.x + 1.1, source.position.y + 1.1 }
|
||||||
}
|
},
|
||||||
for i, v in ipairs(to_teleport_out_entity_list) do
|
type = 'character'
|
||||||
|
}
|
||||||
|
for _, v in ipairs(to_teleport_out_entity_list) do
|
||||||
if v.type == 'character' then
|
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
|
if v.position.y < source.position.y then
|
||||||
pos.y = pos.y + 2
|
pos.y = pos.y + 2
|
||||||
else
|
else
|
||||||
@@ -487,7 +490,7 @@ end
|
|||||||
|
|
||||||
local function on_entity_cloned(event)
|
local function on_entity_cloned(event)
|
||||||
local hidden_dimension = HDT.get('hidden_dimension')
|
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
|
if event.source == v then
|
||||||
event.destination.destroy()
|
event.destination.destroy()
|
||||||
end
|
end
|
||||||
@@ -527,11 +530,11 @@ end
|
|||||||
function Public.init(args)
|
function Public.init(args)
|
||||||
local hidden_dimension = HDT.get('hidden_dimension')
|
local hidden_dimension = HDT.get('hidden_dimension')
|
||||||
if args then
|
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'
|
hidden_dimension.hd_surface = args.hd_surface or 'nauvis'
|
||||||
else
|
else
|
||||||
hidden_dimension.hd_surface = 'nauvis'
|
hidden_dimension.hd_surface = 'nauvis'
|
||||||
hidden_dimension.position = {x = 0, y = 3}
|
hidden_dimension.position = { x = 0, y = 3 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -576,30 +579,31 @@ function Public.create_chests(surface, level, build_type)
|
|||||||
|
|
||||||
local function add_container(name, pos, direction, type)
|
local function add_container(name, pos, direction, type)
|
||||||
local container_entity
|
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
|
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
|
if name == 'loader' or name == 'fast-loader' or name == 'express-loader' then
|
||||||
container_entity =
|
container_entity =
|
||||||
logistic_building.surface.create_entity {
|
logistic_building.surface.create_entity
|
||||||
name = name,
|
{
|
||||||
position = pos2,
|
name = name,
|
||||||
force = game.forces.player,
|
position = pos2,
|
||||||
type = type
|
force = game.forces.player,
|
||||||
}
|
type = type
|
||||||
|
}
|
||||||
container_entity.direction = direction
|
container_entity.direction = direction
|
||||||
elseif name == 'pipe-to-ground' then
|
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
|
container_entity.direction = direction
|
||||||
elseif name == energy then
|
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.minable = false
|
||||||
container_entity.destructible = false
|
container_entity.destructible = false
|
||||||
container_entity.operable = false
|
container_entity.operable = false
|
||||||
container_entity.power_production = 0
|
container_entity.power_production = 0
|
||||||
container_entity.electric_buffer_size = 10000000
|
container_entity.electric_buffer_size = 10000000
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
container_entity.minable = false
|
container_entity.minable = false
|
||||||
@@ -607,20 +611,20 @@ function Public.create_chests(surface, level, build_type)
|
|||||||
return container_entity
|
return container_entity
|
||||||
end
|
end
|
||||||
|
|
||||||
surface.entities.loader_1 = add_container(loader, {x = -2, y = 0}, direction1, rotation1)
|
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.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_1 = add_container(chest, { x = -2, y = 1 })
|
||||||
surface.entities.chest_2 = add_container(chest, {x = 1, 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_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.pipe_2 = add_container('pipe-to-ground', { x = 2, y = 1 }, defines.direction.east)
|
||||||
if level > 1 then
|
if level > 1 then
|
||||||
surface.entities.pipe_3 = add_container('pipe-to-ground', {x = -3, y = 0}, defines.direction.west)
|
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_4 = add_container('pipe-to-ground', { x = 2, y = 0 }, defines.direction.east)
|
||||||
if level > 2 then
|
if level > 2 then
|
||||||
local hidden_dimension = HDT.get('hidden_dimension')
|
local hidden_dimension = HDT.get('hidden_dimension')
|
||||||
hidden_dimension.energy[#hidden_dimension.energy + 1] = add_container(energy, {x = 0, y = 0})
|
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_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)
|
surface.entities.pipe_6 = add_container('pipe-to-ground', { x = 2, y = -1 }, defines.direction.east)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -629,7 +633,7 @@ function Public.upgrade_transport_buildings(level)
|
|||||||
local function upgrade(transport, building_type)
|
local function upgrade(transport, building_type)
|
||||||
local function copy_chest_content(content, chest)
|
local function copy_chest_content(content, chest)
|
||||||
for k, v in pairs(content) do
|
for k, v in pairs(content) do
|
||||||
chest.insert({name = k, count = v})
|
chest.insert({ name = k, count = v })
|
||||||
end
|
end
|
||||||
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 chest_2_inventory = transport.entities.chest_2.get_inventory(defines.inventory.chest).get_contents()
|
||||||
|
|
||||||
local pos = transport.reference.position
|
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
|
local surface = transport.reference.surface
|
||||||
|
|
||||||
clear_surroundings(transport.reference.surface, logistic_bb)
|
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.minable = false
|
||||||
transport.reference.destructible = false
|
transport.reference.destructible = false
|
||||||
transport.reference.operable = 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)
|
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_tick, on_tick)
|
||||||
Event.add(defines.events.on_research_finished, on_research_finished)
|
Event.add(defines.events.on_research_finished, on_research_finished)
|
||||||
Event.add(defines.events.on_entity_cloned, on_entity_cloned)
|
Event.add(defines.events.on_entity_cloned, on_entity_cloned)
|
||||||
Event.add(Public.events.reset_game, reset_surface)
|
Event.add(CreatedEvents.events.reset_game, reset_surface)
|
||||||
Event.add(Public.events.init_surfaces, create_underground_surfaces)
|
Event.add(CreatedEvents.events.init_surfaces, create_underground_surfaces)
|
||||||
|
|
||||||
return Public
|
return Public
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ local StatData = require 'utils.datastore.statistics'
|
|||||||
local WD = require 'modules.wave_defense.table'
|
local WD = require 'modules.wave_defense.table'
|
||||||
local Math2D = require 'math2d'
|
local Math2D = require 'math2d'
|
||||||
local Color = require 'utils.color_presets'
|
local Color = require 'utils.color_presets'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
StatData.add_normalize('spells', 'Spells casted')
|
StatData.add_normalize('spells', 'Spells casted')
|
||||||
|
|
||||||
@@ -1043,7 +1044,7 @@ local function on_player_used_capsule_custom(event)
|
|||||||
rpg_t.amount = 1
|
rpg_t.amount = 1
|
||||||
end
|
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')
|
StatData.get_data(player):increase('spells')
|
||||||
|
|
||||||
@@ -1223,7 +1224,7 @@ local function on_player_used_capsule(event)
|
|||||||
rpg_t.amount = 1
|
rpg_t.amount = 1
|
||||||
end
|
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')
|
StatData.get_data(player):increase('spells')
|
||||||
|
|
||||||
|
|||||||
@@ -37,11 +37,6 @@ Global.register(
|
|||||||
)
|
)
|
||||||
|
|
||||||
local Public = {}
|
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
|
Public.points_per_level = 5
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local Public = require 'modules.wave_defense.table'
|
|||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Global = require 'utils.global'
|
local Global = require 'utils.global'
|
||||||
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local this = {}
|
local this = {}
|
||||||
|
|
||||||
@@ -23,7 +24,8 @@ for a = 48, 1, -1 do
|
|||||||
spawn_amount_rolls[#spawn_amount_rolls + 1] = floor(a ^ 5)
|
spawn_amount_rolls[#spawn_amount_rolls + 1] = floor(a ^ 5)
|
||||||
end
|
end
|
||||||
|
|
||||||
local random_particles = {
|
local random_particles =
|
||||||
|
{
|
||||||
'dirt-2-stone-particle-medium',
|
'dirt-2-stone-particle-medium',
|
||||||
'dirt-4-dust-particle',
|
'dirt-4-dust-particle',
|
||||||
'coal-particle'
|
'coal-particle'
|
||||||
@@ -99,7 +101,7 @@ local function spawn_biters(data)
|
|||||||
BiterHealthBooster.add_unit(unit, final_health)
|
BiterHealthBooster.add_unit(unit, final_health)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
local function spawn_worms(data)
|
local function spawn_worms(data)
|
||||||
@@ -155,7 +157,8 @@ function Public.buried_biter(surface, position, max, entity_name, force)
|
|||||||
this[game.tick + t] = {}
|
this[game.tick + t] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
this[game.tick + t][#this[game.tick + t] + 1] =
|
||||||
|
{
|
||||||
callback = 'create_particles',
|
callback = 'create_particles',
|
||||||
data = { surface = surface, position = { x = position.x, y = position.y }, amount = 4 }
|
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 > 90 then
|
||||||
if t % 30 == 29 then
|
if t % 30 == 29 then
|
||||||
a = a + 1
|
a = a + 1
|
||||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
this[game.tick + t][#this[game.tick + t] + 1] =
|
||||||
|
{
|
||||||
callback = 'spawn_biters',
|
callback = 'spawn_biters',
|
||||||
data = { surface = surface, position = { x = position.x, y = position.y }, entity_name = entity_name, force = force or 'enemy' }
|
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] = {}
|
this[game.tick + t] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
this[game.tick + t][#this[game.tick + t] + 1] = {
|
this[game.tick + t][#this[game.tick + t] + 1] =
|
||||||
|
{
|
||||||
callback = 'create_particles',
|
callback = 'create_particles',
|
||||||
data = { surface = surface, position = { x = position.x, y = position.y }, amount = 4 }
|
data = { surface = surface, position = { x = position.x, y = position.y }, amount = 4 }
|
||||||
}
|
}
|
||||||
|
|
||||||
if not a then
|
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',
|
callback = 'spawn_worms',
|
||||||
data = { surface = surface, position = { x = position.x, y = position.y } }
|
data = { surface = surface, position = { x = position.x, y = position.y } }
|
||||||
}
|
}
|
||||||
@@ -217,7 +223,8 @@ function Public.buried_worm(surface, position)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local callbacks = {
|
local callbacks =
|
||||||
|
{
|
||||||
['create_particles'] = create_particles,
|
['create_particles'] = create_particles,
|
||||||
['spawn_biters'] = spawn_biters,
|
['spawn_biters'] = spawn_biters,
|
||||||
['spawn_worms'] = spawn_worms
|
['spawn_worms'] = spawn_worms
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ local Public = require 'modules.wave_defense.table'
|
|||||||
local Difficulty = require 'modules.difficulty_vote_by_amount'
|
local Difficulty = require 'modules.difficulty_vote_by_amount'
|
||||||
local Beams = require 'modules.render_beam'
|
local Beams = require 'modules.render_beam'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local de = defines.events
|
|
||||||
local ev = Public.events
|
|
||||||
local random = math.random
|
local random = math.random
|
||||||
local abs = math.abs
|
local abs = math.abs
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
@@ -1163,7 +1162,7 @@ function Public._esp:work(tick)
|
|||||||
self.last_command = tick + 500
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1215,14 +1214,14 @@ function Public._esp:work(tick)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Event.on_init(on_init)
|
Event.on_init(on_init)
|
||||||
Event.add(de.on_entity_died, on_entity_died)
|
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||||
Event.add(de.on_entity_damaged, on_entity_damaged)
|
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||||
Event.add(ev.on_wave_created, on_wave_created)
|
Event.add(CreatedEvents.events.on_wave_created, on_wave_created)
|
||||||
Event.add(ev.on_unit_group_created, on_unit_group_created)
|
Event.add(CreatedEvents.events.on_unit_group_created, on_unit_group_created)
|
||||||
Event.add(ev.on_entity_created, on_entity_created)
|
Event.add(CreatedEvents.events.on_entity_created, on_entity_created)
|
||||||
Event.add(ev.on_target_aquired, on_target_aquired)
|
Event.add(CreatedEvents.events.on_target_aquired, on_target_aquired)
|
||||||
Event.add(ev.on_evolution_factor_changed, on_evolution_factor_changed)
|
Event.add(CreatedEvents.events.on_evolution_factor_changed, on_evolution_factor_changed)
|
||||||
Event.add(ev.on_game_reset, on_init)
|
Event.add(CreatedEvents.events.on_game_reset, on_init)
|
||||||
Event.on_nth_tick(100, check_states)
|
Event.on_nth_tick(100, check_states)
|
||||||
|
|
||||||
--- This gets values from our table
|
--- This gets values from our table
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ local Difficulty = require 'modules.difficulty_vote_by_amount'
|
|||||||
local Alert = require 'utils.alert'
|
local Alert = require 'utils.alert'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
local Collapse = require 'modules.collapse'
|
local Collapse = require 'modules.collapse'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
Collapse.read_tables_only = true
|
Collapse.read_tables_only = true
|
||||||
|
|
||||||
local random = math.random
|
local random = math.random
|
||||||
@@ -381,7 +383,7 @@ local function set_main_target()
|
|||||||
end
|
end
|
||||||
|
|
||||||
Public.set('target', sec_target)
|
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.')
|
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
|
end
|
||||||
|
|
||||||
@@ -432,7 +434,7 @@ local function set_enemy_evolution()
|
|||||||
|
|
||||||
enemy.set_evolution_factor(evolution_factor, surface_index)
|
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
|
end
|
||||||
|
|
||||||
local function can_units_spawn()
|
local function can_units_spawn()
|
||||||
@@ -767,7 +769,7 @@ local function set_multi_command()
|
|||||||
|
|
||||||
local target = Public.get('target')
|
local target = Public.get('target')
|
||||||
if not valid(target) then
|
if not valid(target) then
|
||||||
Event.raise(Public.events.on_primary_target_missing)
|
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -874,7 +876,7 @@ local function set_next_wave()
|
|||||||
Public.set('next_wave', game.tick + wave_interval)
|
Public.set('next_wave', game.tick + wave_interval)
|
||||||
end
|
end
|
||||||
|
|
||||||
raise(Public.events.on_wave_created, event_data)
|
raise(CreatedEvents.events.on_wave_created, event_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reform_group(group)
|
local function reform_group(group)
|
||||||
@@ -974,7 +976,7 @@ local function get_main_command(group)
|
|||||||
|
|
||||||
local target = Public.get('target')
|
local target = Public.get('target')
|
||||||
if not valid(target) then
|
if not valid(target) then
|
||||||
Event.raise(Public.events.on_primary_target_missing)
|
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1146,7 +1148,7 @@ local function give_side_commands_to_group()
|
|||||||
|
|
||||||
local target = Public.get('target')
|
local target = Public.get('target')
|
||||||
if not valid(target) then
|
if not valid(target) then
|
||||||
Event.raise(Public.events.on_primary_target_missing)
|
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1165,12 +1167,12 @@ end
|
|||||||
local function give_main_command_to_group()
|
local function give_main_command_to_group()
|
||||||
local target = Public.get('target')
|
local target = Public.get('target')
|
||||||
if not valid(target) then
|
if not valid(target) then
|
||||||
Event.raise(Public.events.on_primary_target_missing)
|
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This is called even if the target is valid
|
-- 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')
|
local generated_units = Public.get('generated_units')
|
||||||
for _, group in pairs(generated_units.unit_groups) do
|
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')
|
local target = Public.get('target')
|
||||||
if not valid(target) then
|
if not valid(target) then
|
||||||
Public.debug_print('spawn_unit_group - Target was not valid?')
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1292,7 +1294,7 @@ local function spawn_unit_group(fs, only_bosses)
|
|||||||
end
|
end
|
||||||
unit_group.add_member(biter)
|
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)
|
-- command_to_side_target(unit_group)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1322,7 +1324,7 @@ local function spawn_unit_group(fs, only_bosses)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
unit_group.add_member(biter)
|
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
|
||||||
Public.set('boss_wave', false)
|
Public.set('boss_wave', false)
|
||||||
end
|
end
|
||||||
@@ -1343,7 +1345,7 @@ local function spawn_unit_group(fs, only_bosses)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
unit_group.add_member(biter)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1354,7 +1356,7 @@ local function spawn_unit_group(fs, only_bosses)
|
|||||||
Public.set('random_group', unit_group)
|
Public.set('random_group', unit_group)
|
||||||
end
|
end
|
||||||
Public.set('spot', 'nil')
|
Public.set('spot', 'nil')
|
||||||
raise(Public.events.on_unit_group_created, event_data)
|
raise(CreatedEvents.events.on_unit_group_created, event_data)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1362,7 +1364,7 @@ local function spawn_unit_group_simple(fs)
|
|||||||
local target = Public.get('target')
|
local target = Public.get('target')
|
||||||
if not valid(target) then
|
if not valid(target) then
|
||||||
Public.debug_print('spawn_unit_group_simple - Target was not valid?')
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1409,7 +1411,7 @@ local function spawn_unit_group_simple(fs)
|
|||||||
if biter then
|
if biter then
|
||||||
s = s + 1
|
s = s + 1
|
||||||
unit_group.add_member(biter)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1436,7 +1438,7 @@ local function check_group_positions()
|
|||||||
local generated_units = Public.get('generated_units')
|
local generated_units = Public.get('generated_units')
|
||||||
local target = Public.get('target')
|
local target = Public.get('target')
|
||||||
if not valid(target) then
|
if not valid(target) then
|
||||||
Event.raise(Public.events.on_primary_target_missing)
|
Event.raise(CreatedEvents.events.on_primary_target_missing)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1584,7 +1586,7 @@ Event.on_nth_tick(30,
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Public.events.on_biters_evolved,
|
CreatedEvents.events.on_biters_evolved,
|
||||||
function (event)
|
function (event)
|
||||||
if not event then
|
if not event then
|
||||||
event = { force = game.forces.enemy }
|
event = { force = game.forces.enemy }
|
||||||
@@ -1598,8 +1600,8 @@ Event.add(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
Event.add(Public.events.on_spawn_unit_group, spawn_unit_group)
|
Event.add(CreatedEvents.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_simple, spawn_unit_group_simple)
|
||||||
|
|
||||||
Event.on_nth_tick(
|
Event.on_nth_tick(
|
||||||
100,
|
100,
|
||||||
|
|||||||
@@ -4,23 +4,12 @@ local Gui = require 'utils.gui'
|
|||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
|
|
||||||
local this = {
|
local this =
|
||||||
|
{
|
||||||
pause_waves_custom_callback = nil,
|
pause_waves_custom_callback = nil,
|
||||||
threat_event_custom_callback = nil
|
threat_event_custom_callback = nil
|
||||||
}
|
}
|
||||||
local Public = {}
|
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
|
local insert = table.insert
|
||||||
|
|
||||||
Global.register(
|
Global.register(
|
||||||
@@ -31,22 +20,23 @@ Global.register(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Public.group_size_modifier_raffle = {}
|
Public.group_size_modifier_raffle = {}
|
||||||
local group_size_chances = {
|
local group_size_chances =
|
||||||
{ 4, 0.4 },
|
{
|
||||||
{ 5, 0.5 },
|
{ 4, 0.4 },
|
||||||
{ 6, 0.6 },
|
{ 5, 0.5 },
|
||||||
{ 7, 0.7 },
|
{ 6, 0.6 },
|
||||||
{ 8, 0.8 },
|
{ 7, 0.7 },
|
||||||
{ 9, 0.9 },
|
{ 8, 0.8 },
|
||||||
|
{ 9, 0.9 },
|
||||||
{ 10, 1 },
|
{ 10, 1 },
|
||||||
{ 9, 1.1 },
|
{ 9, 1.1 },
|
||||||
{ 8, 1.2 },
|
{ 8, 1.2 },
|
||||||
{ 7, 1.3 },
|
{ 7, 1.3 },
|
||||||
{ 6, 1.4 },
|
{ 6, 1.4 },
|
||||||
{ 5, 1.5 },
|
{ 5, 1.5 },
|
||||||
{ 4, 1.6 },
|
{ 4, 1.6 },
|
||||||
{ 3, 1.7 },
|
{ 3, 1.7 },
|
||||||
{ 2, 1.8 }
|
{ 2, 1.8 }
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v in pairs(group_size_chances) do
|
for _, v in pairs(group_size_chances) do
|
||||||
@@ -75,7 +65,7 @@ function Public.reset_wave_defense()
|
|||||||
this.log_wave_to_discord = true
|
this.log_wave_to_discord = true
|
||||||
this.paused = false
|
this.paused = false
|
||||||
this.pause_without_votes = true
|
this.pause_without_votes = true
|
||||||
this.pause_wave_in_ticks = 18000 -- 5 minutes
|
this.pause_wave_in_ticks = 18000 -- 5 minutes
|
||||||
this.next_pause_interval = game.tick + 216000 -- 1 hour
|
this.next_pause_interval = game.tick + 216000 -- 1 hour
|
||||||
this.game_lost = false
|
this.game_lost = false
|
||||||
this.get_random_close_spawner_attempts = 5
|
this.get_random_close_spawner_attempts = 5
|
||||||
@@ -87,7 +77,8 @@ function Public.reset_wave_defense()
|
|||||||
this.max_biter_age = 3600 * 60
|
this.max_biter_age = 3600 * 60
|
||||||
this.nest_building_density = 48
|
this.nest_building_density = 48
|
||||||
this.next_wave = game.tick + 3600 * 20
|
this.next_wave = game.tick + 3600 * 20
|
||||||
this.enable_grace_time = {
|
this.enable_grace_time =
|
||||||
|
{
|
||||||
enabled = true,
|
enabled = true,
|
||||||
set = nil
|
set = nil
|
||||||
}
|
}
|
||||||
@@ -116,7 +107,8 @@ function Public.reset_wave_defense()
|
|||||||
this.worm_raffle = {}
|
this.worm_raffle = {}
|
||||||
this.alert_boss_wave = false
|
this.alert_boss_wave = false
|
||||||
this.remove_entities = false
|
this.remove_entities = false
|
||||||
this.pause_waves = {
|
this.pause_waves =
|
||||||
|
{
|
||||||
index = 0
|
index = 0
|
||||||
}
|
}
|
||||||
this.enable_random_spawn_positions = false
|
this.enable_random_spawn_positions = false
|
||||||
@@ -131,27 +123,32 @@ function Public.reset_wave_defense()
|
|||||||
this.increase_max_active_unit_groups = false
|
this.increase_max_active_unit_groups = false
|
||||||
this.increase_health_per_wave = false
|
this.increase_health_per_wave = false
|
||||||
this.fill_tiles_so_biter_can_path = true
|
this.fill_tiles_so_biter_can_path = true
|
||||||
this.modified_unit_health = {
|
this.modified_unit_health =
|
||||||
|
{
|
||||||
current_value = 1.2,
|
current_value = 1.2,
|
||||||
limit_value = 150,
|
limit_value = 150,
|
||||||
health_increase_per_boss_wave = 0.5 -- wave % 25 == 0 at wave 2k boost is at 41.2
|
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,
|
current_value = 2,
|
||||||
limit_value = 500,
|
limit_value = 500,
|
||||||
health_increase_per_boss_wave = 4 -- wave % 25 == 0 at wave 2k boost is at 322
|
health_increase_per_boss_wave = 4 -- wave % 25 == 0 at wave 2k boost is at 322
|
||||||
}
|
}
|
||||||
this.generated_units = {
|
this.generated_units =
|
||||||
|
{
|
||||||
active_biters = {},
|
active_biters = {},
|
||||||
unit_groups = {},
|
unit_groups = {},
|
||||||
unit_group_last_command = {},
|
unit_group_last_command = {},
|
||||||
unit_group_pos = {
|
unit_group_pos =
|
||||||
|
{
|
||||||
index = 0,
|
index = 0,
|
||||||
positions = {}
|
positions = {}
|
||||||
},
|
},
|
||||||
nests = {}
|
nests = {}
|
||||||
}
|
}
|
||||||
this.threat_values = {
|
this.threat_values =
|
||||||
|
{
|
||||||
['biter-spawner'] = 128,
|
['biter-spawner'] = 128,
|
||||||
['spitter-spawner'] = 128,
|
['spitter-spawner'] = 128,
|
||||||
['behemoth-biter'] = 64,
|
['behemoth-biter'] = 64,
|
||||||
@@ -167,8 +164,10 @@ function Public.reset_wave_defense()
|
|||||||
['big-worm-turret'] = 64,
|
['big-worm-turret'] = 64,
|
||||||
['behemoth-worm-turret'] = 128
|
['behemoth-worm-turret'] = 128
|
||||||
}
|
}
|
||||||
this.unit_settings = {
|
this.unit_settings =
|
||||||
scale_units_by_health = {
|
{
|
||||||
|
scale_units_by_health =
|
||||||
|
{
|
||||||
['small-biter'] = 1,
|
['small-biter'] = 1,
|
||||||
['medium-biter'] = 0.75,
|
['medium-biter'] = 0.75,
|
||||||
['big-biter'] = 0.5,
|
['big-biter'] = 0.5,
|
||||||
@@ -178,18 +177,20 @@ function Public.reset_wave_defense()
|
|||||||
['big-spitter'] = 0.5,
|
['big-spitter'] = 0.5,
|
||||||
['behemoth-spitter'] = 0.25
|
['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
|
['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
|
['flamethrower-turret'] = 0.4, -- not active as of now
|
||||||
['artillery-turret'] = 0.25, -- not active as of now
|
['artillery-turret'] = 0.25, -- not active as of now
|
||||||
['small-worm-turret'] = 0.8,
|
['small-worm-turret'] = 0.8,
|
||||||
['medium-worm-turret'] = 0.6,
|
['medium-worm-turret'] = 0.6,
|
||||||
['big-worm-turret'] = 0.3,
|
['big-worm-turret'] = 0.3,
|
||||||
['behemoth-worm-turret'] = 0.3
|
['behemoth-worm-turret'] = 0.3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.valid_enemy_forces = {
|
this.valid_enemy_forces =
|
||||||
|
{
|
||||||
['enemy'] = true,
|
['enemy'] = true,
|
||||||
['aggressors'] = true,
|
['aggressors'] = true,
|
||||||
['aggressors_frenzy'] = true
|
['aggressors_frenzy'] = true
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ local BiterHealthBooster = require 'modules.biter_health_booster_v2'
|
|||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
local Task = require 'utils.task_token'
|
local Task = require 'utils.task_token'
|
||||||
local Misc = require 'utils.commands.misc'
|
local Misc = require 'utils.commands.misc'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local raise = Event.raise
|
local raise = Event.raise
|
||||||
local round = math.round
|
local round = math.round
|
||||||
@@ -371,7 +372,8 @@ local function shred_simple_entities(entity)
|
|||||||
entity.surface.find_entities_filtered(
|
entity.surface.find_entities_filtered(
|
||||||
{
|
{
|
||||||
type = 'simple-entity',
|
type = 'simple-entity',
|
||||||
area = {
|
area =
|
||||||
|
{
|
||||||
{ entity.position.x - 3, entity.position.y - 3 },
|
{ entity.position.x - 3, entity.position.y - 3 },
|
||||||
{ 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
|
end
|
||||||
if biter and biter.valid then
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ local Event = require 'utils.event'
|
|||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
local Discord = require 'utils.discord_handler'
|
local Discord = require 'utils.discord_handler'
|
||||||
|
|
||||||
local commands =
|
local commands = {
|
||||||
{
|
|
||||||
['editor'] = true,
|
['editor'] = true,
|
||||||
['open'] = true,
|
['open'] = true,
|
||||||
['cheat'] = true,
|
['cheat'] = true,
|
||||||
@@ -16,21 +15,19 @@ local commands =
|
|||||||
['debug'] = true
|
['debug'] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
local title_to_command =
|
local title_to_command = {
|
||||||
{
|
['editor'] = 'Editor',
|
||||||
['editor'] = "Editor",
|
['open'] = 'Open',
|
||||||
['open'] = "Open",
|
['cheat'] = 'Cheat',
|
||||||
['cheat'] = "Cheat",
|
['permissions'] = 'Permissions',
|
||||||
['permissions'] = "Permissions",
|
['banlist'] = 'Banlist',
|
||||||
['banlist'] = "Banlist",
|
['config'] = 'Config',
|
||||||
['config'] = "Config",
|
['command'] = 'Command',
|
||||||
['command'] = "Command",
|
['silent-command'] = 'Silent Command',
|
||||||
['silent-command'] = "Silent Command",
|
['sc'] = 'Silent Command',
|
||||||
['sc'] = "Silent Command",
|
['debug'] = 'Debug'
|
||||||
['debug'] = "Debug"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local function on_console_command(event)
|
local function on_console_command(event)
|
||||||
local cmd = event.command
|
local cmd = event.command
|
||||||
if not commands[cmd] then
|
if not commands[cmd] then
|
||||||
@@ -46,61 +43,61 @@ local function on_console_command(event)
|
|||||||
end
|
end
|
||||||
executor = player.name
|
executor = player.name
|
||||||
else
|
else
|
||||||
executor = "Server"
|
executor = 'Server'
|
||||||
end
|
end
|
||||||
|
|
||||||
local param = (event.parameters and event.parameters ~= "" and event.parameters) or "No parameters"
|
local param = (event.parameters and event.parameters ~= '' and event.parameters) or 'No parameters'
|
||||||
local server_name = Server.get_server_name() or "CommandHandler"
|
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||||
|
|
||||||
Discord.send_notification(
|
Discord.send_notification(
|
||||||
{
|
{
|
||||||
title = title_to_command[cmd],
|
title = title_to_command[cmd],
|
||||||
description = "/" .. cmd .. " was used",
|
description = '/' .. cmd .. ' was used',
|
||||||
color = "warning",
|
color = 'warning',
|
||||||
fields =
|
fields = {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
title = "Server",
|
title = 'Server',
|
||||||
description = server_name,
|
description = server_name,
|
||||||
inline = "false"
|
inline = 'false'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "By",
|
title = 'By',
|
||||||
description = executor,
|
description = executor,
|
||||||
inline = "true"
|
inline = 'true'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title = "Details",
|
title = 'Details',
|
||||||
description = param,
|
description = param,
|
||||||
inline = "true"
|
inline = 'true'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
Event.add(defines.events.on_console_command, on_console_command)
|
Event.add(defines.events.on_console_command, on_console_command)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_promoted,
|
defines.events.on_player_promoted,
|
||||||
function (event)
|
function(event)
|
||||||
local admins = Server.get_admins_data()
|
local admins = Server.get_admins_data()
|
||||||
local player = game.get_player(event.player_index)
|
local player = game.get_player(event.player_index)
|
||||||
local server_name = Server.get_server_name() or 'CommandHandler'
|
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||||
|
|
||||||
Discord.send_notification(
|
Discord.send_notification(
|
||||||
{
|
{
|
||||||
title = "Admin promotion",
|
title = 'Admin promotion',
|
||||||
description = player.name .. " was promoted.",
|
description = player.name .. ' was promoted.',
|
||||||
color = "success",
|
color = 'success',
|
||||||
fields =
|
fields = {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
title = "Server",
|
title = 'Server',
|
||||||
description = server_name,
|
description = server_name,
|
||||||
inline = "false"
|
inline = 'false'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if not game.is_multiplayer() then
|
if not game.is_multiplayer() then
|
||||||
return
|
return
|
||||||
@@ -114,46 +111,46 @@ Event.add(
|
|||||||
)
|
)
|
||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_demoted,
|
defines.events.on_player_demoted,
|
||||||
function (event)
|
function(event)
|
||||||
local player = game.get_player(event.player_index)
|
local player = game.get_player(event.player_index)
|
||||||
local server_name = Server.get_server_name() or 'CommandHandler'
|
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||||
|
|
||||||
Discord.send_notification(
|
Discord.send_notification(
|
||||||
{
|
{
|
||||||
title = "Admin demotion",
|
title = 'Admin demotion',
|
||||||
description = player.name .. " was demoted.",
|
description = player.name .. ' was demoted.',
|
||||||
color = "warning",
|
color = 'warning',
|
||||||
fields =
|
fields = {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
title = "Server",
|
title = 'Server',
|
||||||
description = server_name,
|
description = server_name,
|
||||||
inline = "false"
|
inline = 'false'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_kicked,
|
defines.events.on_player_kicked,
|
||||||
function (event)
|
function(event)
|
||||||
local player = game.get_player(event.player_index)
|
local player = game.get_player(event.player_index)
|
||||||
local server_name = Server.get_server_name() or 'CommandHandler'
|
local server_name = Server.get_server_name() or 'CommandHandler'
|
||||||
|
|
||||||
Discord.send_notification(
|
Discord.send_notification(
|
||||||
{
|
{
|
||||||
title = "Player kicked",
|
title = 'Player kicked',
|
||||||
description = player.name .. " was kicked.",
|
description = player.name .. ' was kicked.',
|
||||||
color = "danger",
|
color = 'danger',
|
||||||
fields =
|
fields = {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
title = "Server",
|
title = 'Server',
|
||||||
description = server_name,
|
description = server_name,
|
||||||
inline = "false"
|
inline = 'false'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@@ -13,6 +13,7 @@ local FancyTime = require 'utils.tools.fancy_time'
|
|||||||
local Task = require 'utils.task'
|
local Task = require 'utils.task'
|
||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
local Discord = require 'utils.discord_handler'
|
local Discord = require 'utils.discord_handler'
|
||||||
|
local Config = require 'utils.gui.config'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
local match = string.match
|
local match = string.match
|
||||||
@@ -112,6 +113,49 @@ Global.register(
|
|||||||
end
|
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)
|
local function increment(t, v)
|
||||||
t[#t + 1] = (v or 1)
|
t[#t + 1] = (v or 1)
|
||||||
end
|
end
|
||||||
@@ -289,11 +333,12 @@ local function on_marked_for_deconstruction(event)
|
|||||||
|
|
||||||
local playtime = player.online_time
|
local playtime = player.online_time
|
||||||
local success = false
|
local success = false
|
||||||
|
local is_trusted = Session.get_trusted_player(player)
|
||||||
if Session.get_session_player(player) then
|
if Session.get_session_player(player) then
|
||||||
playtime = player.online_time + Session.get_session_player(player)
|
playtime = player.online_time + Session.get_session_player(player)
|
||||||
success = true
|
success = true
|
||||||
end
|
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)
|
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 })
|
player.print('You are not accustomed to deconstructing yet.', { r = 0.22, g = 0.99, b = 0.99 })
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -12,8 +12,10 @@ local Discord = require 'utils.discord_handler'
|
|||||||
local Commands = require 'utils.commands'
|
local Commands = require 'utils.commands'
|
||||||
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
|
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
|
||||||
local Task = require 'utils.task_token'
|
local Task = require 'utils.task_token'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local this = {
|
local this =
|
||||||
|
{
|
||||||
enabled = true,
|
enabled = true,
|
||||||
players = {},
|
players = {},
|
||||||
bottom_button = false
|
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
|
for chunk in chunks do
|
||||||
if surface.is_chunk_generated(chunk) then
|
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 },
|
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 }
|
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
|
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()
|
:require_admin()
|
||||||
|
:add_alias('fix')
|
||||||
|
:add_alias('revive')
|
||||||
:require_validation()
|
:require_validation()
|
||||||
:add_parameter('1-50', true, 'number')
|
:add_parameter('1-50', true, 'number')
|
||||||
:callback(
|
: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 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 c = 0
|
||||||
|
local modules = 0
|
||||||
for _, v in pairs(player.surface.find_entities_filtered { type = 'entity-ghost', area = radius }) do
|
for _, v in pairs(player.surface.find_entities_filtered { type = 'entity-ghost', area = radius }) do
|
||||||
if v and v.valid then
|
if v and v.valid then
|
||||||
c = c + 1
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if c == 0 then
|
if c == 0 then
|
||||||
player.print('No entities to repair were found!')
|
player.print('No entities to repair were found!')
|
||||||
return false
|
return false
|
||||||
end
|
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!'
|
return 'Repaired ' .. c .. ' entities!'
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@@ -331,7 +355,8 @@ Commands.new('dump_layout', 'Dump the current map-layout.')
|
|||||||
local surface = player.surface
|
local surface = player.surface
|
||||||
game.write_file('layout.lua', '', false)
|
game.write_file('layout.lua', '', false)
|
||||||
|
|
||||||
local area = {
|
local area =
|
||||||
|
{
|
||||||
left_top = { x = 0, y = 0 },
|
left_top = { x = 0, y = 0 },
|
||||||
right_bottom = { x = 32, y = 32 }
|
right_bottom = { x = 32, y = 32 }
|
||||||
}
|
}
|
||||||
@@ -707,7 +732,7 @@ Gui.on_click(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
BottomFrame.events.bottom_quickbar_location_changed,
|
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||||
function (event)
|
function (event)
|
||||||
if not this.enabled then
|
if not this.enabled then
|
||||||
return
|
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,33 +9,34 @@ local ban_by_join_enabled = false
|
|||||||
|
|
||||||
local try_get_ban = Server.try_get_ban
|
local try_get_ban = Server.try_get_ban
|
||||||
|
|
||||||
local valid_commands = {
|
local valid_commands =
|
||||||
|
{
|
||||||
['ban'] = true
|
['ban'] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
local try_get_is_banned_token =
|
local try_get_is_banned_token =
|
||||||
Token.register(
|
Token.register(
|
||||||
function(data)
|
function (data)
|
||||||
if not data then
|
if not data then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local username = data.username
|
local username = data.username
|
||||||
if not username then
|
if not username then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local state = data.state
|
local state = data.state
|
||||||
|
|
||||||
if state == true then
|
if state == true then
|
||||||
game.ban_player(data.username, data.reason)
|
game.ban_player(data.username, data.reason)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
)
|
||||||
)
|
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_joined_game,
|
defines.events.on_player_joined_game,
|
||||||
function(event)
|
function (event)
|
||||||
if not ban_by_join_enabled then
|
if not ban_by_join_enabled then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -56,7 +57,7 @@ Event.add(
|
|||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_console_command,
|
defines.events.on_console_command,
|
||||||
function(event)
|
function (event)
|
||||||
if valid_commands[event.command] then
|
if valid_commands[event.command] then
|
||||||
Server.ban_handler(event)
|
Server.ban_handler(event)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ local table = require 'utils.table'
|
|||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local StatData = require 'utils.datastore.statistics'
|
local StatData = require 'utils.datastore.statistics'
|
||||||
local Commands = require 'utils.commands'
|
local Commands = require 'utils.commands'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
local UndoActions = require 'utils.undo_actions'
|
||||||
|
|
||||||
StatData.add_normalize('jailed', 'Jailed')
|
StatData.add_normalize('jailed', 'Jailed')
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ local terms_tbl = {}
|
|||||||
local votejail = {}
|
local votejail = {}
|
||||||
local votefree = {}
|
local votefree = {}
|
||||||
local revoked_permissions = {}
|
local revoked_permissions = {}
|
||||||
|
local undo_polls = {}
|
||||||
local settings =
|
local settings =
|
||||||
{
|
{
|
||||||
playtime_for_vote = 77760000, -- 15 days
|
playtime_for_vote = 77760000, -- 15 days
|
||||||
@@ -65,7 +68,8 @@ Global.register(
|
|||||||
settings = settings,
|
settings = settings,
|
||||||
player_data = player_data,
|
player_data = player_data,
|
||||||
terms_tbl = terms_tbl,
|
terms_tbl = terms_tbl,
|
||||||
revoked_permissions = revoked_permissions
|
revoked_permissions = revoked_permissions,
|
||||||
|
undo_polls = undo_polls
|
||||||
},
|
},
|
||||||
function (t)
|
function (t)
|
||||||
jailed = t.jailed
|
jailed = t.jailed
|
||||||
@@ -75,17 +79,11 @@ Global.register(
|
|||||||
player_data = t.player_data
|
player_data = t.player_data
|
||||||
terms_tbl = t.terms_tbl
|
terms_tbl = t.terms_tbl
|
||||||
revoked_permissions = t.revoked_permissions
|
revoked_permissions = t.revoked_permissions
|
||||||
|
undo_polls = t.undo_polls
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
local Public =
|
local Public = {}
|
||||||
{
|
|
||||||
events =
|
|
||||||
{
|
|
||||||
on_player_jailed = Event.generate_event_name('on_player_jailed'),
|
|
||||||
on_player_unjailed = Event.generate_event_name('on_player_unjailed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local function validate_entity(entity)
|
local function validate_entity(entity)
|
||||||
if not (entity and entity.valid) then
|
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 })
|
set_data(jailed_data_set, offender, { jailed = true, actor = player, reason = msg, date = date })
|
||||||
end
|
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')
|
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 })
|
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')
|
StatData.get_data(offender.index):increase('jailed')
|
||||||
|
|
||||||
@@ -763,7 +761,7 @@ local function free(player, offender)
|
|||||||
|
|
||||||
set_data(jailed_data_set, offender, nil)
|
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)
|
Utils.print_to(nil, message)
|
||||||
local data = Server.build_embed_data()
|
local data = Server.build_embed_data()
|
||||||
@@ -1198,7 +1196,7 @@ Event.on_init(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Server.events.on_server_started,
|
CreatedEvents.events.on_server_started,
|
||||||
function ()
|
function ()
|
||||||
Public.sync_revoked_permissions()
|
Public.sync_revoked_permissions()
|
||||||
end
|
end
|
||||||
@@ -1282,10 +1280,12 @@ Event.add(
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if player.admin then
|
if player.admin then
|
||||||
if cmd == 'jail' then
|
if cmd == 'jail' then
|
||||||
Utils.warning(player, 'Logging your actions.')
|
Utils.warning(player, 'Logging your actions.')
|
||||||
message = message .. ' executed by ' .. player.name
|
message = message .. ' executed by ' .. player.name
|
||||||
|
UndoActions.do_action_poll(offender)
|
||||||
Public.try_ul_data(offender, true, player.name, message)
|
Public.try_ul_data(offender, true, player.name, message)
|
||||||
return
|
return
|
||||||
elseif cmd == 'free' then
|
elseif cmd == 'free' then
|
||||||
@@ -1352,6 +1352,7 @@ Event.add(
|
|||||||
print(module_name .. 'Logging your actions.')
|
print(module_name .. 'Logging your actions.')
|
||||||
message = message .. ' executed by script'
|
message = message .. ' executed by script'
|
||||||
Public.try_ul_data(offender, true, 'script', message)
|
Public.try_ul_data(offender, true, 'script', message)
|
||||||
|
UndoActions.do_action_poll(offender)
|
||||||
return
|
return
|
||||||
elseif cmd == 'free' then
|
elseif cmd == 'free' then
|
||||||
Public.try_ul_data(offender, false, 'script')
|
Public.try_ul_data(offender, false, 'script')
|
||||||
|
|||||||
@@ -8,17 +8,20 @@ local Event = require 'utils.event'
|
|||||||
local table = require 'utils.table'
|
local table = require 'utils.table'
|
||||||
local RPG = require 'modules.rpg.table'
|
local RPG = require 'modules.rpg.table'
|
||||||
local Color = require 'utils.color_presets'
|
local Color = require 'utils.color_presets'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||||
|
|
||||||
local this = {
|
local this =
|
||||||
settings = {
|
{
|
||||||
|
settings =
|
||||||
|
{
|
||||||
enabled = false,
|
enabled = false,
|
||||||
reset_after = 7, -- 7 days
|
reset_after = 7, -- 7 days
|
||||||
required_level_to_progress = 99, -- higher than 99 to be able to save
|
required_level_to_progress = 99, -- higher than 99 to be able to save
|
||||||
limit = 39600, -- level 100
|
limit = 39600, -- level 100
|
||||||
dataset = 'rpg_v2_dataset',
|
dataset = 'rpg_v2_dataset',
|
||||||
reset_key = 'reset_by_this_date'
|
reset_key = 'reset_by_this_date'
|
||||||
},
|
},
|
||||||
@@ -347,7 +350,7 @@ function Public.toggle_module(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Server.events.on_server_started,
|
CreatedEvents.events.on_server_started,
|
||||||
function ()
|
function ()
|
||||||
Public.try_dl_resets()
|
Public.try_dl_resets()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ local Task = require 'utils.task'
|
|||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local table = require 'utils.table'
|
local table = require 'utils.table'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||||
|
|
||||||
@@ -41,9 +42,6 @@ Global.register(
|
|||||||
)
|
)
|
||||||
|
|
||||||
local Public = {
|
local Public = {
|
||||||
events = {
|
|
||||||
on_player_removed = Event.generate_event_name('on_player_removed')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local try_download_data_token =
|
local try_download_data_token =
|
||||||
@@ -348,7 +346,7 @@ end
|
|||||||
--- It's vital that we reset the online_track so we
|
--- It's vital that we reset the online_track so we
|
||||||
--- don't calculate the values wrong.
|
--- don't calculate the values wrong.
|
||||||
Event.add(
|
Event.add(
|
||||||
Public.events.on_player_removed,
|
CreatedEvents.events.on_player_removed,
|
||||||
function ()
|
function ()
|
||||||
for name, _ in pairs(online_track) do
|
for name, _ in pairs(online_track) do
|
||||||
local player = game.get_player(name)
|
local player = game.get_player(name)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ local Token = require 'utils.token'
|
|||||||
local Task = require 'utils.task'
|
local Task = require 'utils.task'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||||
local statistics_dataset = 'statistics'
|
local statistics_dataset = 'statistics'
|
||||||
@@ -13,7 +14,8 @@ local try_get_data = Server.try_get_data
|
|||||||
local e = defines.events
|
local e = defines.events
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
|
|
||||||
local events = {
|
local events =
|
||||||
|
{
|
||||||
map_tags_made = e.on_chart_tag_added,
|
map_tags_made = e.on_chart_tag_added,
|
||||||
chat_messages = e.on_console_chat,
|
chat_messages = e.on_console_chat,
|
||||||
commands_used = e.on_console_command,
|
commands_used = e.on_console_command,
|
||||||
@@ -29,19 +31,19 @@ local events = {
|
|||||||
deconstructer_planner_used = e.on_player_deconstructed_area
|
deconstructer_planner_used = e.on_player_deconstructed_area
|
||||||
}
|
}
|
||||||
|
|
||||||
local settings = {
|
local settings =
|
||||||
|
{
|
||||||
required_only_time_to_save_time = 10 * 3600,
|
required_only_time_to_save_time = 10 * 3600,
|
||||||
afk_time = 5 * 3600,
|
afk_time = 5 * 3600,
|
||||||
nth_tick = 5 * 3600
|
nth_tick = 5 * 3600
|
||||||
}
|
}
|
||||||
|
|
||||||
local Public = {
|
local Public =
|
||||||
events = {
|
{
|
||||||
on_player_removed = Event.generate_event_name('on_player_removed')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local normalized_names = {
|
local normalized_names =
|
||||||
|
{
|
||||||
['map_tags_made'] = { name = 'Map-tags created', tooltip = "Tags that you've created in minimap." },
|
['map_tags_made'] = { name = 'Map-tags created', tooltip = "Tags that you've created in minimap." },
|
||||||
['chat_messages'] = { name = 'Messages', tooltip = 'Messages sent in chat.' },
|
['chat_messages'] = { name = 'Messages', tooltip = 'Messages sent in chat.' },
|
||||||
['commands_used'] = { name = 'Commands', tooltip = 'Commands used in console.' },
|
['commands_used'] = { name = 'Commands', tooltip = 'Commands used in console.' },
|
||||||
@@ -125,7 +127,8 @@ local function get_data(player)
|
|||||||
if not data then
|
if not data then
|
||||||
local p = game.get_player(player_index)
|
local p = game.get_player(player_index)
|
||||||
local name = p and p.valid and p.name or nil
|
local name = p and p.valid and p.name or nil
|
||||||
local player_data = {
|
local player_data =
|
||||||
|
{
|
||||||
name = name,
|
name = name,
|
||||||
tick = 0
|
tick = 0
|
||||||
}
|
}
|
||||||
@@ -307,7 +310,7 @@ Event.add(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Public.events.on_player_removed,
|
CreatedEvents.events.on_player_removed,
|
||||||
function (event)
|
function (event)
|
||||||
local player_index = event.player_index
|
local player_index = event.player_index
|
||||||
statistics[player_index] = nil
|
statistics[player_index] = nil
|
||||||
|
|||||||
@@ -4,18 +4,20 @@ local Global = require 'utils.global'
|
|||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local table = require 'utils.table'
|
local table = require 'utils.table'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local supporters_dataset = 'supporters'
|
local supporters_dataset = 'supporters'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
local this = {
|
local this =
|
||||||
|
{
|
||||||
supporters = {}
|
supporters = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Global.register(
|
Global.register(
|
||||||
this,
|
this,
|
||||||
function(tbl)
|
function (tbl)
|
||||||
this = tbl
|
this = tbl
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@@ -30,19 +32,19 @@ end
|
|||||||
--- Writes the data called back from the server into the supporter table, clearing any previous entries
|
--- Writes the data called back from the server into the supporter table, clearing any previous entries
|
||||||
local sync_supporters_callback =
|
local sync_supporters_callback =
|
||||||
Token.register(
|
Token.register(
|
||||||
function(data)
|
function (data)
|
||||||
if not data then
|
if not data then
|
||||||
return
|
return
|
||||||
|
end
|
||||||
|
if not data.entries then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
table.clear_table(this.supporters)
|
||||||
|
for k, v in pairs(data.entries) do
|
||||||
|
this.supporters[k] = v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not data.entries then
|
)
|
||||||
return
|
|
||||||
end
|
|
||||||
table.clear_table(this.supporters)
|
|
||||||
for k, v in pairs(data.entries) do
|
|
||||||
this.supporters[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
--- Signals the server to retrieve the supporters dataset
|
--- Signals the server to retrieve the supporters dataset
|
||||||
function Public.sync_supporters()
|
function Public.sync_supporters()
|
||||||
@@ -51,14 +53,14 @@ end
|
|||||||
|
|
||||||
Server.on_data_set_changed(
|
Server.on_data_set_changed(
|
||||||
supporters_dataset,
|
supporters_dataset,
|
||||||
function(data)
|
function (data)
|
||||||
this.supporters[data.key] = data.value
|
this.supporters[data.key] = data.value
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Server.events.on_server_started,
|
CreatedEvents.events.on_server_started,
|
||||||
function()
|
function ()
|
||||||
Public.sync_supporters()
|
Public.sync_supporters()
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ local format = string.format
|
|||||||
local match = string.match
|
local match = string.match
|
||||||
local gsub = string.gsub
|
local gsub = string.gsub
|
||||||
local serialize = serpent.line
|
local serialize = serpent.line
|
||||||
|
---@diagnostic disable-next-line: deprecated
|
||||||
local debug_getupvalue = debug.getupvalue
|
local debug_getupvalue = debug.getupvalue
|
||||||
|
|
||||||
-- this
|
-- this
|
||||||
@@ -133,14 +134,6 @@ function Debug.print_position(position, message)
|
|||||||
Debug.print(format('%s %s', serialize(position), message))
|
Debug.print(format('%s %s', serialize(position), message))
|
||||||
end
|
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.
|
--- Returns true if the function is a closure, false otherwise.
|
||||||
-- A closure is a function that contains 'upvalues' or in other words
|
-- 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.
|
-- has a reference to a local variable defined outside the function's scope.
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local table = require 'utils.table'
|
local table = require 'utils.table'
|
||||||
|
local api = require 'utils.debug.runtime-api-stable'
|
||||||
|
|
||||||
local gui_names = Gui.names
|
local gui_names = Gui.names
|
||||||
local type = type
|
local type = type
|
||||||
local concat = table.concat
|
local concat = table.concat
|
||||||
local inspect = table.inspect
|
local inspect = table.inspect
|
||||||
local pcall = pcall
|
local pcall = pcall
|
||||||
|
---@diagnostic disable-next-line: deprecated
|
||||||
local loadstring = loadstring
|
local loadstring = loadstring
|
||||||
|
local classes = api.classes
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
local luaObject = { '{', nil, ", name = '", nil, "'}" }
|
local luaObject = {'{', nil, ", name = '", nil, "'}"}
|
||||||
local luaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, '}' }
|
local luaPlayer = {"{LuaPlayer, name = '", nil, "', index = ", nil, '}'}
|
||||||
local luaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, '}' }
|
local luaEntity = {"{LuaEntity, name = '", nil, "', unit_number = ", nil, '}'}
|
||||||
local luaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
|
local luaGuiElement = {"{LuaGuiElement, name = '", nil, "'}"}
|
||||||
|
|
||||||
local function get(obj, prop)
|
local function get(obj, prop)
|
||||||
return obj[prop]
|
return obj[prop]
|
||||||
@@ -29,26 +32,45 @@ local function get_name_safe(obj)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_lua_object_type_safe(obj)
|
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
|
if not s then
|
||||||
return
|
return type(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
return r():match('Lua%a+')
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
local function inspect_process(item)
|
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
|
if type(item) ~= 'table' or type(item.__self) ~= 'userdata' then
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
local suc, valid = pcall(get, item, 'valid')
|
local suc, valid = pcall(get, item, 'valid')
|
||||||
if not suc then
|
if not suc then
|
||||||
-- no 'valid' property
|
|
||||||
return get_lua_object_type_safe(item) or '{NoHelp LuaObject}'
|
return get_lua_object_type_safe(item) or '{NoHelp LuaObject}'
|
||||||
end
|
end
|
||||||
|
|
||||||
if not valid then
|
if not valid then
|
||||||
return '{Invalid LuaObject}'
|
return '{Invalid LuaObject}'
|
||||||
end
|
end
|
||||||
@@ -61,27 +83,23 @@ local function inspect_process(item)
|
|||||||
if obj_type == 'LuaPlayer' then
|
if obj_type == 'LuaPlayer' then
|
||||||
luaPlayer[2] = item.name or 'nil'
|
luaPlayer[2] = item.name or 'nil'
|
||||||
luaPlayer[4] = item.index or 'nil'
|
luaPlayer[4] = item.index or 'nil'
|
||||||
|
|
||||||
return concat(luaPlayer)
|
return concat(luaPlayer)
|
||||||
elseif obj_type == 'LuaEntity' then
|
elseif obj_type == 'LuaEntity' then
|
||||||
luaEntity[2] = item.name or 'nil'
|
luaEntity[2] = item.name or 'nil'
|
||||||
luaEntity[4] = item.unit_number or 'nil'
|
luaEntity[4] = item.unit_number or 'nil'
|
||||||
|
|
||||||
return concat(luaEntity)
|
return concat(luaEntity)
|
||||||
elseif obj_type == 'LuaGuiElement' then
|
elseif obj_type == 'LuaGuiElement' then
|
||||||
local name = item.name
|
local name = item.name
|
||||||
luaGuiElement[2] = gui_names and gui_names[name] or name or 'nil'
|
luaGuiElement[2] = gui_names and gui_names[name] or name or 'nil'
|
||||||
|
|
||||||
return concat(luaGuiElement)
|
return concat(luaGuiElement)
|
||||||
else
|
else
|
||||||
luaObject[2] = obj_type
|
luaObject[2] = obj_type
|
||||||
luaObject[4] = get_name_safe(item)
|
luaObject[4] = get_name_safe(item)
|
||||||
|
|
||||||
return concat(luaObject)
|
return concat(luaObject)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local inspect_options = { process = inspect_process }
|
local inspect_options = {process = inspect_process}
|
||||||
function Public.dump(data)
|
function Public.dump(data)
|
||||||
return inspect(data, inspect_options)
|
return inspect(data, inspect_options)
|
||||||
end
|
end
|
||||||
@@ -97,14 +115,14 @@ function Public.dump_ignore_builder(ignore)
|
|||||||
return inspect_process(item)
|
return inspect_process(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
local options = { process = process }
|
local options = {process = process}
|
||||||
return function (data)
|
return function(data)
|
||||||
return inspect(data, options)
|
return inspect(data, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Public.dump_function(func)
|
function Public.dump_function(func)
|
||||||
local res = { 'upvalues:\n' }
|
local res = {'upvalues:\n'}
|
||||||
|
|
||||||
if debug.getupvalue == nil then
|
if debug.getupvalue == nil then
|
||||||
return concat(res)
|
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_table
|
||||||
--luacheck: ignore function_nth_tick_table
|
--luacheck: ignore function_nth_tick_table
|
||||||
--luacheck: globals script
|
--luacheck: globals script
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ local Event = require 'utils.event'
|
|||||||
local Global = require 'utils.global'
|
local Global = require 'utils.global'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
local SpamProtection = require 'utils.spam_protection'
|
local SpamProtection = require 'utils.spam_protection'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local insert = table.insert
|
local insert = table.insert
|
||||||
local tostring = tostring
|
local tostring = tostring
|
||||||
@@ -10,10 +11,15 @@ local next = next
|
|||||||
local gui_prefix = 'comfy_'
|
local gui_prefix = 'comfy_'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
Public.events =
|
|
||||||
|
local ordered_tab_names =
|
||||||
{
|
{
|
||||||
on_gui_removal = Event.generate_event_name('on_gui_removal'),
|
"Players",
|
||||||
on_gui_closed_main_frame = Event.generate_event_name('on_gui_closed_main_frame')
|
"Admin",
|
||||||
|
"Groups",
|
||||||
|
"Scoreboard",
|
||||||
|
"Statistics",
|
||||||
|
"Config",
|
||||||
}
|
}
|
||||||
|
|
||||||
-- local to this file
|
-- local to this file
|
||||||
@@ -663,7 +669,7 @@ function Public.clear_all_screen_frames(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Public.clear_all_active_frames(player)
|
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
|
for _, child in pairs(player.gui.left.children) do
|
||||||
if child.name:find(gui_prefix) then
|
if child.name:find(gui_prefix) then
|
||||||
remove_data_recursively(child)
|
remove_data_recursively(child)
|
||||||
@@ -825,17 +831,50 @@ local function draw_main_frame(player)
|
|||||||
|
|
||||||
Public.clear_all_active_frames(player)
|
Public.clear_all_active_frames(player)
|
||||||
|
|
||||||
if Public.get_main_frame(player) then
|
local existing_frame = Public.get_main_frame(player)
|
||||||
remove_data_recursively(Public.get_main_frame(player))
|
if existing_frame then
|
||||||
Public.get_main_frame(player).destroy()
|
remove_data_recursively(existing_frame)
|
||||||
|
existing_frame.destroy()
|
||||||
end
|
end
|
||||||
|
|
||||||
local admins = Server.get_admins_data()
|
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' })
|
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
|
if not settings.disabled_tabs[name] then
|
||||||
local show = false
|
local show = false
|
||||||
local secs = Server.get_current_time()
|
local secs = Server.get_current_time()
|
||||||
@@ -851,8 +890,20 @@ local function draw_main_frame(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if show then
|
if show then
|
||||||
local tab = tabbed_pane.add({ type = 'tab', caption = name, name = callback.name, style = 'slightly_smaller_tab' })
|
local tab = tabbed_pane.add(
|
||||||
local name_frame = tabbed_pane.add({ type = 'frame', name = name, direction = 'vertical', style = 'mod_gui_inside_deep_frame' })
|
{
|
||||||
|
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
|
name_frame.style.padding = 8
|
||||||
tabbed_pane.add_tab(tab, name_frame)
|
tabbed_pane.add_tab(tab, name_frame)
|
||||||
end
|
end
|
||||||
@@ -866,11 +917,12 @@ local function draw_main_frame(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
player.opened = frame
|
player.opened = frame
|
||||||
|
|
||||||
Public.reload_active_tab(player, true)
|
Public.reload_active_tab(player, true)
|
||||||
|
|
||||||
return frame, inside_frame
|
return frame, inside_frame
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Public.get_content(player)
|
function Public.get_content(player)
|
||||||
local left_frame = Public.get_main_frame(player)
|
local left_frame = Public.get_main_frame(player)
|
||||||
if not left_frame then
|
if not left_frame then
|
||||||
@@ -890,7 +942,7 @@ function Public.refresh(player)
|
|||||||
for _, tab in pairs(tabbed_pane.tabs) do
|
for _, tab in pairs(tabbed_pane.tabs) do
|
||||||
if tab.content.name ~= frame.name then
|
if tab.content.name ~= frame.name then
|
||||||
tab.content.clear()
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -974,9 +1026,9 @@ Public.on_click(
|
|||||||
if frame then
|
if frame then
|
||||||
remove_data_recursively(frame)
|
remove_data_recursively(frame)
|
||||||
frame.destroy()
|
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)
|
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 })
|
{ player_index = player.index, element = active_frame or nil })
|
||||||
else
|
else
|
||||||
draw_main_frame(player)
|
draw_main_frame(player)
|
||||||
@@ -990,7 +1042,7 @@ Public.on_click(
|
|||||||
local player = event.player
|
local player = event.player
|
||||||
local frame = Public.get_parent_frame(player)
|
local frame = Public.get_parent_frame(player)
|
||||||
local active_frame = Public.get_player_active_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
|
if frame then
|
||||||
remove_data_recursively(frame)
|
remove_data_recursively(frame)
|
||||||
frame.destroy()
|
frame.destroy()
|
||||||
@@ -1003,7 +1055,7 @@ Public.on_custom_close(
|
|||||||
function (event)
|
function (event)
|
||||||
local player = event.player
|
local player = event.player
|
||||||
local active_frame = Public.get_player_active_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 })
|
||||||
local frame = Public.get_parent_frame(player)
|
local frame = Public.get_parent_frame(player)
|
||||||
if frame then
|
if frame then
|
||||||
remove_data_recursively(frame)
|
remove_data_recursively(frame)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ local Task = require 'utils.task_token'
|
|||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
local Global = require 'utils.global'
|
local Global = require 'utils.global'
|
||||||
local Discord = require 'utils.discord_handler'
|
local Discord = require 'utils.discord_handler'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local Public = {}
|
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_text_changed, text_changed)
|
||||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
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(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
|
return Public
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ local Global = require 'utils.global'
|
|||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
local Task = require 'utils.task_token'
|
local Task = require 'utils.task_token'
|
||||||
local Config = require 'utils.gui.config'
|
local Config = require 'utils.gui.config'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local this =
|
local this =
|
||||||
{
|
{
|
||||||
players = {},
|
players = {},
|
||||||
@@ -22,14 +24,7 @@ Global.register(
|
|||||||
-- @table events
|
-- @table events
|
||||||
-- @field bottom_quickbar_respawn_raise The event triggered when the bottom quickbar is respawned or raised.
|
-- @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.
|
-- @field bottom_quickbar_location_changed The event triggered when the location of the bottom quickbar is changed.
|
||||||
local Public =
|
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 set_location
|
local set_location
|
||||||
local destroy_frame
|
local destroy_frame
|
||||||
@@ -469,7 +464,7 @@ set_location = function (player, state)
|
|||||||
}
|
}
|
||||||
end
|
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
|
data.state = state
|
||||||
create_frame(player, alignment, location, data)
|
create_frame(player, alignment, location, data)
|
||||||
@@ -670,7 +665,7 @@ Event.add(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Public.events.bottom_quickbar_respawn_raise,
|
CreatedEvents.events.bottom_quickbar_respawn_raise,
|
||||||
function (event)
|
function (event)
|
||||||
if not event or not event.player_index then
|
if not event or not event.player_index then
|
||||||
return
|
return
|
||||||
@@ -685,7 +680,7 @@ Event.add(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Event.add(
|
Event.add(
|
||||||
Public.events.bottom_quickbar_location_changed,
|
CreatedEvents.events.bottom_quickbar_location_changed,
|
||||||
function (event)
|
function (event)
|
||||||
if not event or not event.player_index then
|
if not event or not event.player_index then
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
local Antigrief = require 'utils.antigrief'
|
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Color = require 'utils.color_presets'
|
local Color = require 'utils.color_presets'
|
||||||
local SessionData = require 'utils.datastore.session_data'
|
|
||||||
local Utils = require 'utils.core'
|
local Utils = require 'utils.core'
|
||||||
local SpamProtection = require 'utils.spam_protection'
|
local SpamProtection = require 'utils.spam_protection'
|
||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
@@ -125,21 +123,6 @@ local function spaghett()
|
|||||||
end
|
end
|
||||||
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 =
|
local functions =
|
||||||
{
|
{
|
||||||
['spectator_switch'] = function (event)
|
['spectator_switch'] = function (event)
|
||||||
@@ -179,21 +162,6 @@ local functions =
|
|||||||
end
|
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 =
|
local pirates_functions =
|
||||||
{
|
{
|
||||||
['toggle_disband'] = function (event)
|
['toggle_disband'] = function (event)
|
||||||
@@ -257,7 +225,6 @@ local function build_config_gui(data)
|
|||||||
if not player then return end
|
if not player then return end
|
||||||
local frame = data.frame
|
local frame = data.frame
|
||||||
|
|
||||||
local AG = Antigrief.get()
|
|
||||||
local switch_state
|
local switch_state
|
||||||
local label
|
local label
|
||||||
|
|
||||||
@@ -351,13 +318,6 @@ local function build_config_gui(data)
|
|||||||
|
|
||||||
scroll_pane.add({ type = 'line' })
|
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
|
if storage.tokens.maps_pirates_memory then
|
||||||
label = scroll_pane.add({ type = 'label', caption = 'Pirates Settings' })
|
label = scroll_pane.add({ type = 'label', caption = 'Pirates Settings' })
|
||||||
label.style.font = 'default-bold'
|
label.style.font = 'default-bold'
|
||||||
@@ -407,13 +367,6 @@ local function on_gui_switch_state_changed(event)
|
|||||||
end
|
end
|
||||||
functions[event.element.name](event)
|
functions[event.element.name](event)
|
||||||
return
|
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
|
elseif pirates_functions[event.element.name] then
|
||||||
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Pirates Elem')
|
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Pirates Elem')
|
||||||
if is_spamming then
|
if is_spamming then
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ local SpamProtection = require 'utils.spam_protection'
|
|||||||
local Math = require 'utils.math.math'
|
local Math = require 'utils.math.math'
|
||||||
local Discord = require 'utils.discord_handler'
|
local Discord = require 'utils.discord_handler'
|
||||||
local Color = require 'utils.color_presets'
|
local Color = require 'utils.color_presets'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
local Public = {}
|
local Public = {}
|
||||||
|
|
||||||
local insert = table.insert
|
local insert = table.insert
|
||||||
@@ -952,6 +954,10 @@ local function tick()
|
|||||||
table.remove(running_polls, i)
|
table.remove(running_polls, i)
|
||||||
send_poll_result_to_discord(poll, true)
|
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 }
|
local message = table.concat { 'Poll finished: Poll #', poll.id, ': ', poll.question }
|
||||||
for _, p in pairs(game.connected_players) do
|
for _, p in pairs(game.connected_players) do
|
||||||
if not no_notify_players[p.index] then
|
if not no_notify_players[p.index] then
|
||||||
@@ -962,6 +968,10 @@ local function tick()
|
|||||||
end
|
end
|
||||||
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_joined_game, player_joined)
|
||||||
Event.add(defines.events.on_player_created, player_joined)
|
Event.add(defines.events.on_player_created, player_joined)
|
||||||
Event.on_nth_tick(60, tick)
|
Event.on_nth_tick(60, tick)
|
||||||
@@ -1512,6 +1522,7 @@ function Public.poll(data)
|
|||||||
local poll_data =
|
local poll_data =
|
||||||
{
|
{
|
||||||
id = id,
|
id = id,
|
||||||
|
custom_data = data.custom_data or nil,
|
||||||
question = data.question,
|
question = data.question,
|
||||||
answers = answers,
|
answers = answers,
|
||||||
voters = {},
|
voters = {},
|
||||||
@@ -1543,17 +1554,21 @@ function Public.poll_result(id)
|
|||||||
local result = { 'Question: ', poll_data.question, ' Answers: ' }
|
local result = { 'Question: ', poll_data.question, ' Answers: ' }
|
||||||
local answers = poll_data.answers
|
local answers = poll_data.answers
|
||||||
local answers_count = #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, '( [')
|
||||||
insert(result, a.voted_count)
|
insert(result, a.voted_count)
|
||||||
insert(result, '] - ')
|
insert(result, '] - ')
|
||||||
insert(result, a.text)
|
insert(result, a.text)
|
||||||
insert(result, ' )')
|
insert(result, ' )')
|
||||||
|
|
||||||
if not winning_answer or a.voted_count > winning_answer.voted_count then
|
if a.voted_count > highest_vote then
|
||||||
winning_answer = a
|
highest_vote = a.voted_count
|
||||||
|
winners = { a }
|
||||||
|
elseif a.voted_count == highest_vote then
|
||||||
|
insert(winners, a)
|
||||||
end
|
end
|
||||||
|
|
||||||
if i ~= answers_count then
|
if i ~= answers_count then
|
||||||
@@ -1561,6 +1576,13 @@ function Public.poll_result(id)
|
|||||||
end
|
end
|
||||||
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
|
return table.concat(result), winning_answer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local inspect = {
|
local inspect =
|
||||||
|
{
|
||||||
_VERSION = 'inspect.lua 3.1.0',
|
_VERSION = 'inspect.lua 3.1.0',
|
||||||
_URL = 'http://github.com/kikito/inspect.lua',
|
_URL = 'http://github.com/kikito/inspect.lua',
|
||||||
_DESCRIPTION = 'human-readable representations of tables',
|
_DESCRIPTION = 'human-readable representations of tables',
|
||||||
@@ -32,23 +33,22 @@ local tostring = tostring
|
|||||||
|
|
||||||
inspect.KEY =
|
inspect.KEY =
|
||||||
setmetatable(
|
setmetatable(
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
__tostring = function()
|
__tostring = function ()
|
||||||
return 'inspect.KEY'
|
return 'inspect.KEY'
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
inspect.METATABLE =
|
inspect.METATABLE =
|
||||||
setmetatable(
|
setmetatable(
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
__tostring = function()
|
__tostring = function ()
|
||||||
return 'inspect.METATABLE'
|
return 'inspect.METATABLE'
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
||||||
-- Otherwise, it returns a regular quoted string
|
-- Otherwise, it returns a regular quoted string
|
||||||
local function smartQuote(str)
|
local function smartQuote(str)
|
||||||
@@ -59,7 +59,8 @@ local function smartQuote(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- \a => '\\a', \0 => '\\0', 31 => '\31'
|
-- \a => '\\a', \0 => '\\0', 31 => '\31'
|
||||||
local shortControlCharEscapes = {
|
local shortControlCharEscapes =
|
||||||
|
{
|
||||||
['\a'] = '\\a',
|
['\a'] = '\\a',
|
||||||
['\b'] = '\\b',
|
['\b'] = '\\b',
|
||||||
['\f'] = '\\f',
|
['\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
|
return type(k) == 'number' and 1 <= k and k <= sequenceLength and math.floor(k) == k
|
||||||
end
|
end
|
||||||
|
|
||||||
local defaultTypeOrders = {
|
local defaultTypeOrders =
|
||||||
|
{
|
||||||
['number'] = 1,
|
['number'] = 1,
|
||||||
['boolean'] = 2,
|
['boolean'] = 2,
|
||||||
['string'] = 3,
|
['string'] = 3,
|
||||||
@@ -176,7 +178,7 @@ local function countTableAppearances(t, tableAppearances)
|
|||||||
return tableAppearances
|
return tableAppearances
|
||||||
end
|
end
|
||||||
|
|
||||||
local copySequence = function(s)
|
local copySequence = function (s)
|
||||||
local copy, len = {}, #s
|
local copy, len = {}, #s
|
||||||
for i = 1, len do
|
for i = 1, len do
|
||||||
copy[i] = s[i]
|
copy[i] = s[i]
|
||||||
@@ -185,7 +187,7 @@ local copySequence = function(s)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function makePath(path, ...)
|
local function makePath(path, ...)
|
||||||
local keys = {...}
|
local keys = { ... }
|
||||||
local newPath, len = copySequence(path)
|
local newPath, len = copySequence(path)
|
||||||
for i = 1, #keys do
|
for i = 1, #keys do
|
||||||
newPath[len + i] = keys[i]
|
newPath[len + i] = keys[i]
|
||||||
@@ -224,10 +226,10 @@ end
|
|||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
local Inspector = {}
|
local Inspector = {}
|
||||||
local Inspector_mt = {__index = Inspector}
|
local Inspector_mt = { __index = Inspector }
|
||||||
|
|
||||||
function Inspector:puts(...)
|
function Inspector:puts(...)
|
||||||
local args = {...}
|
local args = { ... }
|
||||||
local buffer = self.buffer
|
local buffer = self.buffer
|
||||||
local len = #buffer
|
local len = #buffer
|
||||||
for i = 1, #args do
|
for i = 1, #args do
|
||||||
@@ -288,7 +290,7 @@ function Inspector:putTable(t)
|
|||||||
|
|
||||||
self:puts('{')
|
self:puts('{')
|
||||||
self:down(
|
self:down(
|
||||||
function()
|
function ()
|
||||||
if toStringResult then
|
if toStringResult then
|
||||||
self:puts(' -- ', escape(toStringResult))
|
self:puts(' -- ', escape(toStringResult))
|
||||||
if sequenceLength >= 1 then
|
if sequenceLength >= 1 then
|
||||||
@@ -368,18 +370,18 @@ function inspect.inspect(root, options)
|
|||||||
|
|
||||||
local inspector =
|
local inspector =
|
||||||
setmetatable(
|
setmetatable(
|
||||||
{
|
{
|
||||||
depth = depth,
|
depth = depth,
|
||||||
level = 0,
|
level = 0,
|
||||||
buffer = {},
|
buffer = {},
|
||||||
ids = {},
|
ids = {},
|
||||||
maxIds = {},
|
maxIds = {},
|
||||||
newline = newline,
|
newline = newline,
|
||||||
indent = indent,
|
indent = indent,
|
||||||
tableAppearances = countTableAppearances(root)
|
tableAppearances = countTableAppearances(root)
|
||||||
},
|
},
|
||||||
Inspector_mt
|
Inspector_mt
|
||||||
)
|
)
|
||||||
|
|
||||||
inspector:putValue(root)
|
inspector:putValue(root)
|
||||||
|
|
||||||
@@ -389,7 +391,7 @@ end
|
|||||||
setmetatable(
|
setmetatable(
|
||||||
inspect,
|
inspect,
|
||||||
{
|
{
|
||||||
__call = function(_, ...)
|
__call = function (_, ...)
|
||||||
return inspect.inspect(...)
|
return inspect.inspect(...)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
local Public = {}
|
local Public = {}
|
||||||
local Session = require 'utils.datastore.session_data'
|
|
||||||
local Jailed = require 'utils.datastore.jail_data'
|
|
||||||
local Supporters = require 'utils.datastore.supporters'
|
local Supporters = require 'utils.datastore.supporters'
|
||||||
local Gui = require 'utils.gui'
|
local Gui = require 'utils.gui'
|
||||||
|
|
||||||
@@ -334,8 +332,8 @@ Public.gui_data = function (data)
|
|||||||
local rpg_enabled = data.rpg_enabled
|
local rpg_enabled = data.rpg_enabled
|
||||||
local poke_player_frame_name = data.poke_player_frame_name
|
local poke_player_frame_name = data.poke_player_frame_name
|
||||||
|
|
||||||
local play_table = Session.get_trusted_table()
|
local play_table = storage.tokens.utils_datastore_session_data.trusted
|
||||||
local jailed = Jailed.get_jailed_table()
|
local jailed = storage.tokens.utils_datastore_jail_data.jailed
|
||||||
|
|
||||||
local connected_players = #game.connected_players
|
local connected_players = #game.connected_players
|
||||||
local players = game.players
|
local players = game.players
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ local Task = require 'utils.task'
|
|||||||
local Global = require 'utils.global'
|
local Global = require 'utils.global'
|
||||||
local Event = require 'utils.event'
|
local Event = require 'utils.event'
|
||||||
local Print = require('utils.print_override')
|
local Print = require('utils.print_override')
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
-- local constants
|
-- local constants
|
||||||
local floor = math.floor
|
local floor = math.floor
|
||||||
@@ -184,15 +185,15 @@ end
|
|||||||
-- local Server = require 'utils.server'
|
-- local Server = require 'utils.server'
|
||||||
-- local Event = require 'utils.event'
|
-- local Event = require 'utils.event'
|
||||||
--
|
--
|
||||||
-- Event.add(Server.events.on_server_started,
|
-- Event.add(CreatedEvents.events.on_server_started,
|
||||||
-- function()
|
-- function()
|
||||||
-- Server.try_get_all_data('regulars', callback)
|
-- Server.try_get_all_data('regulars', callback)
|
||||||
-- end)
|
-- end)
|
||||||
-- Event.add(Server.events.on_changes_detected,
|
-- Event.add(CreatedEvents.events.on_changes_detected,
|
||||||
-- function()
|
-- function()
|
||||||
-- Trigger some sort of automated restart whenever the game ends.
|
-- Trigger some sort of automated restart whenever the game ends.
|
||||||
-- end)
|
-- 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.
|
-- Starts a new game with the given scenario. Note that this will stop the current game and reset it.
|
||||||
---@param scenario_data string|table
|
---@param scenario_data string|table
|
||||||
@@ -1594,6 +1595,7 @@ function Public.ban_handler(event)
|
|||||||
|
|
||||||
if cmd == 'ban' then
|
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.
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
---@diagnostic disable: lowercase-global
|
||||||
local Poll =
|
local Poll =
|
||||||
{
|
{
|
||||||
send_poll_result_to_discord = function ()
|
send_poll_result_to_discord = function ()
|
||||||
@@ -5,6 +6,7 @@ local Poll =
|
|||||||
}
|
}
|
||||||
local Token = require 'utils.token'
|
local Token = require 'utils.token'
|
||||||
local Server = require 'utils.server'
|
local Server = require 'utils.server'
|
||||||
|
local CreatedEvents = require 'utils.created_events'
|
||||||
|
|
||||||
--- This module is for the web server to call functions and raise events.
|
--- This module is for the web server to call functions and raise events.
|
||||||
-- Not intended to be called by scripts.
|
-- 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
|
ServerCommands.get_tracked_scenario = Server.get_tracked_scenario
|
||||||
|
|
||||||
function ServerCommands.server_started()
|
function ServerCommands.server_started()
|
||||||
script.raise_event(Server.events.on_server_started, {})
|
script.raise_event(CreatedEvents.events.on_server_started, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
function ServerCommands.changes_detected()
|
function ServerCommands.changes_detected()
|
||||||
script.raise_event(Server.events.on_changes_detected, {})
|
script.raise_event(CreatedEvents.events.on_changes_detected, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
ServerCommands.set_time = Server.set_time
|
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