1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00

Merge pull request #281 from ComfyFactory/decon_fix

Mtn v3 - allow deconstruct
This commit is contained in:
Gerkiz 2022-07-04 00:29:27 +02:00 committed by GitHub
commit dc2d77e7e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 182 additions and 14 deletions

View File

@ -14,10 +14,15 @@ function Public.add_player_to_permission_group(player, group, forced)
local session = Session.get_session_table()
local AG = Antigrief.get()
local allow_decon = WPT.get('allow_decon')
local allow_decon_main_surface = WPT.get('allow_decon_main_surface')
local default_group = game.permissions.get_group('Default')
default_group.set_allows_action(defines.input_action.deconstruct, false)
default_group.set_allows_action(defines.input_action.activate_cut, false)
if allow_decon_main_surface then
default_group.set_allows_action(defines.input_action.deconstruct, true)
else
default_group.set_allows_action(defines.input_action.deconstruct, false)
end
if not game.permissions.get_group('limited') then
local limited_group = game.permissions.create_group('limited')
@ -35,13 +40,21 @@ function Public.add_player_to_permission_group(player, group, forced)
local near_locomotive_group = game.permissions.create_group('near_locomotive')
near_locomotive_group.set_allows_action(defines.input_action.cancel_craft, false)
near_locomotive_group.set_allows_action(defines.input_action.drop_item, false)
near_locomotive_group.set_allows_action(defines.input_action.deconstruct, false)
if allow_decon_main_surface then
near_locomotive_group.set_allows_action(defines.input_action.deconstruct, true)
else
near_locomotive_group.set_allows_action(defines.input_action.deconstruct, false)
end
near_locomotive_group.set_allows_action(defines.input_action.activate_cut, false)
end
if not game.permissions.get_group('main_surface') then
local main_surface_group = game.permissions.create_group('main_surface')
main_surface_group.set_allows_action(defines.input_action.deconstruct, false)
if allow_decon_main_surface then
main_surface_group.set_allows_action(defines.input_action.deconstruct, true)
else
main_surface_group.set_allows_action(defines.input_action.deconstruct, false)
end
main_surface_group.set_allows_action(defines.input_action.activate_cut, false)
end

View File

@ -230,6 +230,7 @@ function Public.reset_map()
AntiGrief.enable_jail(true)
AntiGrief.damage_entity_threshold(20)
AntiGrief.explosive_threshold(32)
AntiGrief.decon_surface_blacklist(surface.name)
PL.show_roles_in_list(true)
PL.rpg_enabled(true)

View File

@ -112,6 +112,7 @@ function Public.reset_table()
}
this.force_chunk = false
this.allow_decon = true
this.allow_decon_main_surface = true
this.train_upgrades = 0
this.flamethrower_damage = {}
this.mined_scrap = 0

View File

@ -10,12 +10,14 @@ local Color = require 'utils.color_presets'
local Server = require 'utils.server'
local Jail = require 'utils.datastore.jail_data'
local FancyTime = require 'tools.fancy_time'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Public = {}
local match = string.match
local capsule_bomb_threshold = 8
local de = defines.events
local sub = string.sub
local format = string.format
local floor = math.floor
local random = math.random
@ -31,6 +33,7 @@ local this = {
corpse_history = {},
message_history = {},
cancel_crafting_history = {},
deconstruct_history = {},
whitelist_types = {},
permission_group_editing = {},
players_warned = {},
@ -45,6 +48,9 @@ local this = {
required_playtime = 2592000,
damage_entity_threshold = 20,
explosive_threshold = 16,
enable_jail_when_decon = true,
decon_surface_blacklist = 'nauvis',
players_warn_when_decon = {},
limit = 2000
}
@ -75,6 +81,17 @@ local chests = {
['logistic-container'] = true
}
-- Clears the player from players_warn_when_decon tbl.
local clear_player_decon_warnings =
Token.register(
function(event)
local player_index = event.player_index
if this.players_warn_when_decon[player_index] then
this.players_warn_when_decon[player_index] = nil
end
end
)
Global.register(
this,
function(t)
@ -762,7 +779,6 @@ local function on_init()
return
end
local branch_version = '0.18.35'
local sub = string.sub
local is_branch_18 = sub(branch_version, 3, 4)
local get_active_version = sub(game.active_mods.base, 3, 4)
local default = game.permissions.get_group('Default')
@ -809,6 +825,74 @@ local function on_permission_group_deleted(event)
end
end
local function on_player_deconstructed_area(event)
local surface = event.surface
local surface_name = this.decon_surface_blacklist
if sub(surface.name, 0, #surface_name) ~= surface_name then
return
end
local player = game.get_player(event.player_index)
local area = event.area
local count = surface.count_entities_filtered({area = area, force = 'neutral'})
if count and count > 0 then
surface.cancel_deconstruct_area {
area = area,
force = player.force
}
if count >= 2000 then
local msg = '[Deconstruct] ' .. player.name .. ' tried to deconstruct: ' .. count .. ' entities!'
Utils.print_to(nil, msg)
Server.to_discord_embed(msg)
if not this.deconstruct_history then
this.deconstruct_history = {}
end
if #this.deconstruct_history > this.limit then
overflow(this.deconstruct_history)
end
local t = abs(floor((game.tick) / 60))
t = FancyTime.short_fancy_time(t)
local str = '[' .. t .. '] '
str = str .. msg
str = str .. ' at lt_x:'
str = str .. floor(area.left_top.x)
str = str .. ' at lt_y:'
str = str .. floor(area.left_top.y)
str = str .. ' at rb_x:'
str = str .. floor(area.right_bottom.x)
str = str .. ' at rb_y:'
str = str .. floor(area.right_bottom.y)
str = str .. ' '
str = str .. 'surface:' .. player.surface.index
increment(this.deconstruct_history, str)
if this.enable_jail_when_decon and not player.admin then
if not this.players_warn_when_decon[player.index] then
this.players_warn_when_decon[player.index] = 1
local r = random(7200, 18000)
Task.set_timeout_in_ticks(r, clear_player_decon_warnings, {player_index = player.index})
end
local warnings = this.players_warn_when_decon[player.index]
if warnings then
if warnings == 1 or warnings == 2 then
Utils.print_to(player, '[Deconstruct] Warning! Do not deconstruct that many entities at once!')
this.players_warn_when_decon[player.index] = this.players_warn_when_decon[player.index] + 1
elseif warnings == 3 then
Utils.print_to(player, '[Deconstruct] Warning! Do not deconstruct that many entities at once! This is your final warning!')
this.players_warn_when_decon[player.index] = this.players_warn_when_decon[player.index] + 1
else
Jail.try_ul_data(player, true, 'script', 'Deconstructed ' .. count .. ' entities. Has been warned 3 times before getting jailed.')
this.players_warn_when_decon[player.index] = nil
end
end
end
end
end
end
local function on_permission_group_edited(event)
if not this.enabled then
return
@ -901,33 +985,47 @@ function Public.whitelist_types(key, value)
end
--- If the event should also check trusted players.
---@param value string
---@param value boolean
function Public.do_not_check_trusted(value)
this.do_not_check_trusted = value or false
return this.do_not_check_trusted
end
--- If ANY actions should be performed when a player misbehaves.
---@param value string
---@param value boolean
function Public.enable_capsule_warning(value)
this.enable_capsule_warning = value or false
return this.enable_capsule_warning
end
--- If ANY actions should be performed when a player misbehaves.
---@param value string
---@param value boolean
function Public.enable_capsule_cursor_warning(value)
this.enable_capsule_cursor_warning = value or false
return this.enable_capsule_cursor_warning
end
--- If the script should jail a person instead of kicking them
---@param value string
---@param value boolean
function Public.enable_jail(value)
this.enable_jail = value or false
return this.enable_jail
end
--- If the script should jail a person whenever they deconstruct multiple times.
---@param value boolean
function Public.enable_jail_when_decon(value)
this.enable_jail_when_decon = value or false
return this.enable_jail_when_decon
end
--- If the script should jail a person whenever they deconstruct multiple times.
---@param value string
function Public.decon_surface_blacklist(value)
this.decon_surface_blacklist = value or 'nauvis'
return this.decon_surface_blacklist
end
--- Defines what the threshold for amount of explosives in chest should be - logged or not.
---@param value string
function Public.explosive_threshold(value)
@ -976,5 +1074,6 @@ Event.add(de.on_permission_group_deleted, on_permission_group_deleted)
Event.add(de.on_permission_group_edited, on_permission_group_edited)
Event.add(de.on_permission_string_imported, on_permission_string_imported)
Event.add(de.on_console_chat, on_console_chat)
Event.add(de.on_player_deconstructed_area, on_player_deconstructed_area)
return Public

View File

@ -478,7 +478,7 @@ local function jail(player, griefer, msg, raised)
end
if not msg then
return
msg = 'Jailed by script'
end
if not game.get_player(griefer) then
@ -589,7 +589,10 @@ function Public.try_dl_data(key)
end
--- Tries to get data from the webpanel and updates the local table with values.
-- @param data_set player token
-- @param key LuaPlayer
-- @param value boolean
-- @param player LuaPlayer or <script>
-- @param message string
function Public.try_ul_data(key, value, player, message)
if type(key) == 'table' then
key = key.name

View File

@ -247,7 +247,8 @@ local function draw_events(data)
['Mining Override History'] = antigrief.whitelist_mining_history,
['Landfill History'] = antigrief.landfill_history,
['Corpse Looting History'] = antigrief.corpse_history,
['Cancel Crafting History'] = antigrief.cancel_crafting_history
['Cancel Crafting History'] = antigrief.cancel_crafting_history,
['Deconstruct History'] = antigrief.deconstruct_history
}
local scroll_pane
@ -358,6 +359,10 @@ local function create_admin_panel(data)
local player = data.player
local frame = data.frame
local antigrief = AntiGrief.get()
if not antigrief then
return
end
frame.clear()
local player_names = {}
@ -508,6 +513,9 @@ local function create_admin_panel(data)
if antigrief.cancel_crafting_history then
table.insert(histories, 'Cancel Crafting History')
end
if antigrief.deconstruct_history then
table.insert(histories, 'Deconstruct History')
end
if #histories == 0 then
return

View File

@ -82,7 +82,7 @@ end
local function spaghett()
local spaghetti = this.gui_config.spaghett
if spaghetti.noop then
return
return
end
if spaghetti.enabled then
for _, f in pairs(game.forces) do
@ -355,6 +355,40 @@ local fortress_functions = {
get_actor(event, '[Decon]', 'has disabled decon on car/tanks/trains.', true)
end
end,
['allow_decon_main_surface'] = function(event)
local WPT = is_loaded('maps.mountain_fortress_v3.table')
if event.element.switch_state == 'left' then
local near_locomotive_group = game.permissions.get_group('near_locomotive')
if near_locomotive_group then
near_locomotive_group.set_allows_action(defines.input_action.deconstruct, true)
end
local default_group = game.permissions.get_group('Default')
if default_group then
default_group.set_allows_action(defines.input_action.deconstruct, true)
end
local main_surface_group = game.permissions.get_group('main_surface')
if main_surface_group then
main_surface_group.set_allows_action(defines.input_action.deconstruct, true)
end
WPT.set('allow_decon_main_surface', true)
get_actor(event, '[Decon]', 'has allowed decon on main surface.', true)
else
local near_locomotive_group = game.permissions.get_group('near_locomotive')
if near_locomotive_group then
near_locomotive_group.set_allows_action(defines.input_action.deconstruct, false)
end
local default_group = game.permissions.get_group('Default')
if default_group then
default_group.set_allows_action(defines.input_action.deconstruct, false)
end
local main_surface_group = game.permissions.get_group('main_surface')
if main_surface_group then
main_surface_group.set_allows_action(defines.input_action.deconstruct, false)
end
WPT.set('allow_decon_main_surface', false)
get_actor(event, '[Decon]', 'has disabled decon on main surface.', true)
end
end,
['christmas_mode'] = function(event)
local WPT = is_loaded('maps.mountain_fortress_v3.table')
if event.element.switch_state == 'left' then
@ -667,8 +701,17 @@ local function build_config_gui(data)
if Module.allow_decon then
switch_state = 'left'
end
add_switch(scroll_pane, switch_state, 'allow_decon', 'Deconstruct', 'On = Allows decon on car/tanks/trains.\nOff = Disables decon on car/tanks/trains.')
add_switch(scroll_pane, switch_state, 'allow_decon', 'Deconstruct IC', 'On = Allows decon on car/tanks/trains.\nOff = Disables decon on car/tanks/trains.')
scroll_pane.add({type = 'line'})
switch_state = 'right'
if Module.allow_decon_main_surface then
switch_state = 'left'
end
add_switch(scroll_pane, switch_state, 'allow_decon_main_surface', 'Deconstruct Surface', 'On = Allows decon on main surface.\nOff = Disables decon on main surface.')
scroll_pane.add({type = 'line'})
switch_state = 'right'
if Module.christmas_mode then
switch_state = 'left'
end