mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-24 03:47:58 +02:00
commit
a47a50ade0
3
locale/en/wave_defense.cfg
Normal file
3
locale/en/wave_defense.cfg
Normal file
@ -0,0 +1,3 @@
|
||||
[wave_defense]
|
||||
pause_waves=[color=blue][Wave Defense][/color] New waves will not spawn for 5 minutes!
|
||||
start_waves=[color=blue][Wave Defense][/color] Waves will spawn normally again.
|
@ -294,6 +294,9 @@ end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
local surface_name = player.surface.name
|
||||
local map_name = 'mtn_v3'
|
||||
|
||||
|
@ -5,6 +5,7 @@ local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local Server = require 'utils.server'
|
||||
local SpamProtection = require 'utils.spam_protection'
|
||||
local Alert = require 'utils.alert'
|
||||
|
||||
local main_frame_name = Gui.uid_name()
|
||||
local save_button_name = Gui.uid_name()
|
||||
@ -112,7 +113,8 @@ end
|
||||
|
||||
local function pause_waves_state(state)
|
||||
if state then
|
||||
game.print('[color=blue][Wave Defense][/color] New waves will not spawn for 5 minutes!', {r = 0.98, g = 0.66, b = 0.22})
|
||||
local message = ({'wave_defense.pause_waves'})
|
||||
Alert.alert_all_players(30, message, nil, 'achievement/tech-maniac', 0.75)
|
||||
Public.set('paused', true)
|
||||
Public.set('last_pause', game.tick)
|
||||
Public.set('paused_waves_for', game.tick + 18000)
|
||||
@ -120,7 +122,8 @@ local function pause_waves_state(state)
|
||||
local next_wave = Public.get('next_wave')
|
||||
Public.set('next_wave', next_wave + 18000)
|
||||
else
|
||||
game.print('[color=blue][Wave Defense][/color] Waves will spawn normally again.', {r = 0.98, g = 0.66, b = 0.22})
|
||||
local message = ({'wave_defense.start_waves'})
|
||||
Alert.alert_all_players(30, message, nil, 'achievement/tech-maniac', 0.75)
|
||||
Public.set('paused', false)
|
||||
Public.set('paused_waves_for', nil)
|
||||
Public.set('last_pause', nil)
|
||||
@ -139,6 +142,17 @@ function Public.toggle_pause_wave()
|
||||
end
|
||||
end
|
||||
|
||||
function Public.toggle_pause_wave_without_votes()
|
||||
local paused = Public.get('paused')
|
||||
if paused then
|
||||
return
|
||||
end
|
||||
|
||||
Public.set('pause_waves', {index = 0})
|
||||
pause_waves_state(true)
|
||||
Task.set_timeout_in_ticks(18000, pause_waves_state_token, false) -- 5 minutes
|
||||
end
|
||||
|
||||
Gui.on_click(
|
||||
save_button_name,
|
||||
function(event)
|
||||
@ -225,7 +239,12 @@ Event.on_nth_tick(
|
||||
return
|
||||
end
|
||||
|
||||
Public.toggle_pause_wave()
|
||||
local pause_without_votes = Public.get('pause_without_votes')
|
||||
if pause_without_votes then
|
||||
Public.toggle_pause_wave_without_votes()
|
||||
else
|
||||
Public.toggle_pause_wave()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
@ -252,4 +271,33 @@ commands.add_command(
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'wave_defense_force_pause_waves',
|
||||
'Usable only for admins - pauses the wave defense waves!',
|
||||
function()
|
||||
local player = game.player
|
||||
|
||||
if player and player.valid then
|
||||
if not player.admin then
|
||||
return
|
||||
end
|
||||
|
||||
local paused = Public.get('paused')
|
||||
if paused then
|
||||
return
|
||||
end
|
||||
|
||||
print('[Wave Defense] ' .. player.name .. ' paused wave defense.')
|
||||
|
||||
Public.toggle_pause_wave_without_votes()
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
--- Toggles if we should show a gui or just pause the waves without votes.
|
||||
---@param state boolean
|
||||
function Public.pause_without_votes(state)
|
||||
Public.set('pause_without_votes', state or true)
|
||||
end
|
||||
|
||||
return Public
|
||||
|
@ -157,6 +157,10 @@ local function update_alert(id, frame, tick)
|
||||
end
|
||||
|
||||
local data = Gui.get_data(frame)
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
|
||||
local end_tick = data.end_tick
|
||||
|
||||
if tick > end_tick then
|
||||
@ -188,9 +192,9 @@ on_tick =
|
||||
---Message a specific player, template is a callable that receives a LuaGuiElement
|
||||
---to add contents to and a player as second argument.
|
||||
---@param player LuaPlayer
|
||||
---@param duration table
|
||||
---@param duration number
|
||||
---@param template function
|
||||
---@param sound string sound to play, nil to not play anything
|
||||
---@param sound string|nil sound to play, nil to not play anything
|
||||
function Public.alert_player_template(player, duration, template, sound, volume)
|
||||
sound = sound or 'utility/new_objective'
|
||||
local container = alert_to(player, duration, sound, volume)
|
||||
@ -218,7 +222,7 @@ end
|
||||
---to add contents to and a player as second argument.
|
||||
---@param duration number
|
||||
---@param template function
|
||||
---@param sound string sound to play, nil to not play anything
|
||||
---@param sound string|nil sound to play, nil to not play anything
|
||||
function Public.alert_all_players_template(duration, template, sound)
|
||||
sound = sound or 'utility/new_objective'
|
||||
local players = game.connected_players
|
||||
@ -230,7 +234,7 @@ end
|
||||
|
||||
---Message all players at a given location
|
||||
---@param player LuaPlayer
|
||||
---@param message string
|
||||
---@param message string|table
|
||||
---@param color string|nil
|
||||
function Public.alert_all_players_location(player, message, color, duration)
|
||||
local length = duration or 15
|
||||
@ -263,7 +267,7 @@ end
|
||||
---Message to a specific player
|
||||
---@param player LuaPlayer
|
||||
---@param duration number
|
||||
---@param message string
|
||||
---@param message string|table
|
||||
---@param color string|nil
|
||||
function Public.alert_player(player, duration, message, color, sprite, volume)
|
||||
Public.alert_player_template(
|
||||
@ -288,7 +292,7 @@ end
|
||||
---@param player LuaPlayer
|
||||
---@param duration number
|
||||
---@param message string
|
||||
---@param color string
|
||||
---@param color string|nil
|
||||
function Public.alert_player_warning(player, duration, message, color)
|
||||
Public.alert_player_template(
|
||||
player,
|
||||
@ -320,7 +324,7 @@ end
|
||||
|
||||
---Message to all players
|
||||
---@param duration number
|
||||
---@param message string
|
||||
---@param message string|table
|
||||
---@param color string|nil
|
||||
function Public.alert_all_players(duration, message, color, sprite, volume)
|
||||
local players = game.connected_players
|
||||
|
@ -223,8 +223,10 @@ local function get_gulag_permission_group()
|
||||
if not gulag then
|
||||
gulag = game.permissions.create_group('gulag')
|
||||
for action_name, _ in pairs(defines.input_action) do
|
||||
---@diagnostic disable-next-line: need-check-nil
|
||||
gulag.set_allows_action(defines.input_action[action_name], false)
|
||||
end
|
||||
---@diagnostic disable-next-line: need-check-nil
|
||||
gulag.set_allows_action(defines.input_action.write_to_console, true)
|
||||
end
|
||||
|
||||
@ -236,6 +238,7 @@ local function get_super_gulag_permission_group()
|
||||
if not gulag then
|
||||
gulag = game.permissions.create_group('super_gulag')
|
||||
for action_name, _ in pairs(defines.input_action) do
|
||||
---@diagnostic disable-next-line: need-check-nil
|
||||
gulag.set_allows_action(defines.input_action[action_name], false)
|
||||
end
|
||||
end
|
||||
@ -351,8 +354,13 @@ local function teleport_player_to_gulag(player, action)
|
||||
|
||||
local p = p_data.position
|
||||
local p_group = game.permissions.get_group(p_data.p_group_id)
|
||||
if not p_group then
|
||||
return
|
||||
end
|
||||
|
||||
p_group.add_player(player)
|
||||
local pos = {x = p.x, y = p.y}
|
||||
---@diagnostic disable-next-line: missing-parameter
|
||||
local get_tile = surface.get_tile(pos)
|
||||
if get_tile.valid and get_tile.name == 'out-of-map' then
|
||||
player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 128, 1), surface.name)
|
||||
@ -587,6 +595,9 @@ local function jail(player, offender, msg, raised, mute)
|
||||
end
|
||||
|
||||
local to_jail_player = game.get_player(offender)
|
||||
if not to_jail_player then
|
||||
return
|
||||
end
|
||||
|
||||
draw_notice_frame(to_jail_player)
|
||||
|
||||
@ -956,8 +967,8 @@ function Public.print_jailed()
|
||||
result[#result + 1] = k
|
||||
end
|
||||
|
||||
result = concat(result, ', ')
|
||||
Game.player_print(result)
|
||||
local final = concat(result, ', ')
|
||||
Game.player_print(final)
|
||||
end
|
||||
|
||||
--- Returns the table of jailed
|
||||
@ -1112,6 +1123,10 @@ commands.add_command(
|
||||
return Utils.print_to(player, 'No player was provided.')
|
||||
end
|
||||
|
||||
if not revoke_player then
|
||||
return
|
||||
end
|
||||
|
||||
if is_revoked(revoke_player.name) then
|
||||
remove_revoked(revoke_player.name)
|
||||
Utils.print_to(player, revoke_player.name .. ' can now utilize jail commands once again!')
|
||||
@ -1164,6 +1179,9 @@ Event.add(
|
||||
|
||||
if event.player_index then
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
local playtime = validate_playtime(player)
|
||||
local trusted = validate_trusted(player)
|
||||
|
||||
@ -1371,7 +1389,7 @@ Gui.on_text_changed(
|
||||
local offender = data.offender
|
||||
|
||||
if textfield and textfield.valid then
|
||||
if string.len(textfield.text) >= 1000 then
|
||||
if string.len(textfield.text) >= 2000 then
|
||||
textfield.text = ''
|
||||
return
|
||||
end
|
||||
@ -1415,6 +1433,12 @@ Gui.on_click(
|
||||
Utils.print_to(player, module_name .. 'Jail data has been submitted!')
|
||||
Utils.print_to(nil, module_name .. offender .. ' was jailed by ' .. player.name .. '.')
|
||||
|
||||
local jail_data = Server.build_embed_data()
|
||||
jail_data.username = offender
|
||||
jail_data.admin = player.name
|
||||
jail_data.reason = jailed[offender].reason
|
||||
Server.to_unjailed_named_embed(jail_data)
|
||||
|
||||
if frame and frame.valid then
|
||||
remove_target_frame(frame)
|
||||
end
|
||||
|
@ -61,6 +61,8 @@ local discord_jailed_tag = '[DISCORD-JAILED]'
|
||||
local discord_jailed_embed_tag = '[DISCORD-JAILED-EMBED]'
|
||||
local discord_unjailed_tag = '[DISCORD-UNJAILED]'
|
||||
local discord_unjailed_embed_tag = '[DISCORD-UNJAILED-EMBED]'
|
||||
local discord_jailed_named_embed_tag = '[DISCORD-JAILED-NAMED-EMBED]'
|
||||
local discord_unjailed_named_embed_tag = '[DISCORD-UNJAILED-NAMED-EMBED]'
|
||||
local discord_admin_raw_tag = '[DISCORD-ADMIN-RAW]'
|
||||
local discord_embed_parsed_tag = '[DISCORD-EMBED-PARSED]'
|
||||
local discord_embed_tag = '[DISCORD-EMBED]'
|
||||
@ -418,6 +420,31 @@ function Public.to_jailed_embed(message, locale)
|
||||
end
|
||||
end
|
||||
|
||||
--- Sends a embed message to the jailed discord channel. The message is sanitized of markdown server side.
|
||||
-- @param message<tbl> the content of the embed.
|
||||
-- @param locale<boolean> if the message should be handled as localized.
|
||||
function Public.to_jailed_named_embed(message, locale)
|
||||
local table_to_json = game.table_to_json
|
||||
if not type(message) == 'table' then
|
||||
return
|
||||
end
|
||||
|
||||
if locale then
|
||||
print(message, discord_jailed_named_embed_tag)
|
||||
else
|
||||
if not message.username then
|
||||
return
|
||||
end
|
||||
if not message.reason then
|
||||
return
|
||||
end
|
||||
if not message.admin then
|
||||
return
|
||||
end
|
||||
raw_print(discord_jailed_named_embed_tag .. table_to_json(message))
|
||||
end
|
||||
end
|
||||
|
||||
--- Sends a embed message to the linked connected discord channel. The message is sanitized of markdown server side.
|
||||
-- @param message<tbl> the content of the embed.
|
||||
-- @param locale<boolean> if the message should be handled as localized.
|
||||
@ -439,6 +466,27 @@ function Public.to_unjailed_embed(message, locale)
|
||||
end
|
||||
end
|
||||
|
||||
--- Sends a embed message to the linked connected discord channel. The message is sanitized of markdown server side.
|
||||
-- @param message<tbl> the content of the embed.
|
||||
-- @param locale<boolean> if the message should be handled as localized.
|
||||
function Public.to_unjailed_named_embed(message, locale)
|
||||
local table_to_json = game.table_to_json
|
||||
if not type(message) == 'table' then
|
||||
return
|
||||
end
|
||||
if locale then
|
||||
print(message, discord_unjailed_named_embed_tag)
|
||||
else
|
||||
if not message.username then
|
||||
return
|
||||
end
|
||||
if not message.admin then
|
||||
return
|
||||
end
|
||||
raw_print(discord_unjailed_named_embed_tag .. table_to_json(message))
|
||||
end
|
||||
end
|
||||
|
||||
--- Sends a embed message to the linked admin discord channel. The message is not sanitized of markdown.
|
||||
-- @param message<string> the content of the embed.
|
||||
-- @param locale<boolean> if the message should be handled as localized.
|
||||
|
Loading…
x
Reference in New Issue
Block a user