1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-11 14:49:24 +02:00
This commit is contained in:
Gerkiz 2020-09-12 19:16:38 +02:00
parent e56515627d
commit f4c5ea7703
9 changed files with 83 additions and 280 deletions

View File

@ -36,7 +36,6 @@ local this = {
enable_autoban = false,
enable_jail = false,
enable_capsule_warning = false,
enable_damage_warning = false,
enable_capsule_cursor_warning = false,
required_playtime = 2592000,
damage_entity_threshold = 20,
@ -392,136 +391,6 @@ local function on_player_used_capsule(event)
end
end
-- Damage things
local function on_entity_damaged(event)
if not this.enabled then
return
end
local cause = event.cause
if not cause or not cause.valid or cause.force.index ~= 1 then
return
end
local force = event.force
if not force.index == 1 then
return
end
if cause.name ~= 'character' then
return
end
local entity = event.entity
if not entity or not entity.valid then
return
end
if entity.force.index ~= 1 then
return
end
local trusted = session.get_trusted_table()
local tracker = session.get_session_table()
local player = game.get_player(event.cause.player.index)
if player.admin then
return
end
if trusted[player.name] and this.do_not_check_trusted then
return
end
local name = entity.name
local e_type = entity.type
local position = entity.position
local msg
local playtime = player.online_time
if tracker[player.name] then
playtime = player.online_time + tracker[player.name]
end
if playtime > this.required_playtime then
return
end
if not this.damage_history[player.index] then
this.damage_history[player.index] = {}
this.damage_history[player.index].targets = ''
this.damage_history[player.index].count = 0
end
if this.enable_damage_warning then
if name ~= 'entity-ghost' and name ~= 'character' and not blacklisted_types[e_type] then
if chests[e_type] then
local inv = entity.get_inventory(1)
local contents = inv.get_contents()
if next(contents) == nil then
return
else
for n, count in pairs(contents) do
if n == 'explosives' then
if count < this.explosive_threshold then
return
end
end
end
end
end
name = name:gsub('-', ' ')
local index = this.damage_history[player.index].targets:find(name)
if not index then
this.damage_history[player.index].targets = this.damage_history[player.index].targets .. name .. ', '
end
this.damage_history[player.index].count = this.damage_history[player.index].count + 1
end
if this.damage_history[player.index].count <= this.damage_entity_threshold then
return
end
local target_names = this.damage_history[player.index].targets
local prefix = '{Friendly Fire}'
msg =
format(
player.name .. ' damaged: %s counted times: %s',
target_names,
this.damage_history[player.index].count
)
local ban_msg =
format(
'Damaged: %s counted times: %s. This action was performed automatically. Visit getcomfy.eu/discord for forgiveness',
target_names,
this.damage_history[player.index].count
)
do_action(player, prefix, msg, ban_msg, true)
else
msg = player.name .. ' damaged ' .. name
end
this.damage_history[player.index].count = 0
this.damage_history[player.index].targets = ''
if not this.friendly_fire_history then
this.friendly_fire_history = {}
end
if #this.friendly_fire_history > 1000 then
this.friendly_fire_history = {}
end
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. msg
str = str .. ' at X:'
str = str .. math.floor(position.x)
str = str .. ' Y:'
str = str .. math.floor(position.y)
str = str .. ' '
str = str .. 'surface:' .. player.surface.index
increment(this.friendly_fire_history, str)
end
--Friendly Fire History
local function on_entity_died(event)
if not this.enabled then
@ -1035,18 +904,6 @@ function Public.enable_capsule_warning(value)
return this.enable_capsule_warning
end
--- If ANY actions should be performed when a player misbehaves.
---@param value <string>
function Public.enable_damage_warning(value)
if value then
this.enable_damage_warning = value
else
this.enable_damage_warning = false
end
return this.enable_damage_warning
end
--- If ANY actions should be performed when a player misbehaves.
---@param value <string>
function Public.enable_capsule_cursor_warning(value)
@ -1127,7 +984,6 @@ end
Event.on_init(on_init)
Event.add(de.on_player_mined_entity, on_player_mined_entity)
Event.add(de.on_entity_died, on_entity_died)
Event.add(de.on_entity_damaged, on_entity_damaged)
Event.add(de.on_built_entity, on_built_entity)
Event.add(de.on_gui_opened, on_gui_opened)
Event.add(de.on_marked_for_deconstruction, on_marked_for_deconstruction)

View File

@ -517,10 +517,10 @@ local function redraw_market_items(gui, player, search_text)
button.enabled = false
button.tooltip = ({'locomotive.not_trusted'})
end
if item == 'car' then
--[[ if item == 'car' then
button.enabled = false
button.tooltip = ({'locomotive.not_trusted'})
end
end ]]
end
end
@ -1980,14 +1980,14 @@ function Public.get_items()
upgrade = false,
static = true
}
main_market_items['car'] = {
--[[ main_market_items['car'] = {
stack = 1,
value = 'coin',
price = 6000,
tooltip = ({'main_market.car'}),
upgrade = false,
static = true
}
} ]]
main_market_items['tank'] = {
stack = 1,
value = 'coin',

View File

@ -4,7 +4,6 @@ require 'maps.mountain_fortress_v3.breached_wall'
require 'maps.mountain_fortress_v3.ic.main'
require 'modules.rpg.main'
require 'modules.autofill'
require 'modules.dynamic_landfill'
require 'modules.shotgun_buff'
require 'modules.no_deconstruction_of_neutral_entities'
@ -309,7 +308,6 @@ function Public.reset_map()
AntiGrief.log_tree_harvest(true)
AntiGrief.whitelist_types('tree', true)
AntiGrief.enable_capsule_warning(false)
AntiGrief.enable_damage_warning(false)
AntiGrief.enable_capsule_cursor_warning(false)
AntiGrief.enable_jail(true)
AntiGrief.damage_entity_threshold(20)
@ -384,12 +382,11 @@ local on_player_changed_position = function(event)
local position = player.position
local surface = game.surfaces[this.active_surface_index]
if player.connected and not player.character or not player.character.valid then
--[[ if player.connected and not player.character or not player.character.valid then
player.set_controller({type = defines.controllers.god})
player.create_character()
return
end
end ]]
local p = {x = player.position.x, y = player.position.y}
local get_tile = surface.get_tile(p)
local config_tile = WPT.get('void_or_tile')
@ -494,94 +491,6 @@ local on_pre_player_left_game = function(event)
end
end
local remove_offline_players = function()
local this = WPT.get()
if not this.offline_players_enabled then
return
end
local offline_players = WPT.get('offline_players')
local active_surface_index = WPT.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
local player_inv = {}
local items = {}
if #offline_players > 0 then
local later = {}
for i = 1, #offline_players, 1 do
if
offline_players[i] and game.players[offline_players[i].index] and
game.players[offline_players[i].index].connected
then
this.offline_players[i] = nil
else
if offline_players[i] and offline_players[i].tick < game.tick - 34000 then
local name = offline_players[i].name
player_inv[1] =
game.players[offline_players[i].index].get_inventory(defines.inventory.character_main)
player_inv[2] =
game.players[offline_players[i].index].get_inventory(defines.inventory.character_armor)
player_inv[3] =
game.players[offline_players[i].index].get_inventory(defines.inventory.character_guns)
player_inv[4] =
game.players[offline_players[i].index].get_inventory(defines.inventory.character_ammo)
player_inv[5] =
game.players[offline_players[i].index].get_inventory(defines.inventory.character_trash)
local pos = game.forces.player.get_spawn_position(surface)
local e =
surface.create_entity(
{
name = 'character',
position = pos,
force = 'neutral'
}
)
local inv = e.get_inventory(defines.inventory.character_main)
for ii = 1, 5, 1 do
if player_inv[ii].valid then
for iii = 1, #player_inv[ii], 1 do
if player_inv[ii][iii].valid then
items[#items + 1] = player_inv[ii][iii]
end
end
end
end
if #items > 0 then
for item = 1, #items, 1 do
if items[item].valid then
inv.insert(items[item])
end
end
local message = ({'main.cleaner', name})
local data = {
position = pos
}
Alert.alert_all_players_location(data, message)
e.die('neutral')
else
e.destroy()
end
for ii = 1, 5, 1 do
if player_inv[ii].valid then
player_inv[ii].clear()
end
end
this.offline_players[i] = nil
else
later[#later + 1] = offline_players[i]
end
end
end
this.offline_players = {}
if #later > 0 then
for i = 1, #later, 1 do
this.offline_players[#offline_players + 1] = later[i]
end
end
end
end
local on_research_finished = function(event)
disable_tech()
local research = event.research
@ -827,7 +736,6 @@ local on_tick = function()
chunk_load()
if tick % 1200 == 0 then
remove_offline_players()
boost_difficulty()
collapse_after_wave_100()
Entities.set_scores()
@ -916,7 +824,7 @@ local on_init = function()
end
end
Event.on_nth_tick(15, on_tick)
Event.on_nth_tick(20, on_tick)
Event.on_init(on_init)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_left_game, on_player_left_game)

View File

@ -549,6 +549,15 @@ Public.add_chest_to_refill_callback = function(player, entity)
end
end
Public.globally_enabled = function(value)
if value then
this.globally_enabled = value
else
this.globally_enabled = false
end
return this.globally_enabled
end
Event.add(defines.events.on_built_entity, on_entity_built)
Event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)
Event.on_nth_tick(50, on_tick)

View File

@ -652,12 +652,12 @@ Gui.on_click(
P.update_player_modifiers(player)
elseif magic_pickup_gui_input.state then
player_modifiers.disabled_modifier[player.index].character_item_pickup_distance_bonus = false
player_modifiers.disabled_modifier[player.index].character_build_distance_bonus = true
player_modifiers.disabled_modifier[player.index].character_item_drop_distance_bonus = true
player_modifiers.disabled_modifier[player.index].character_reach_distance_bonus = true
player_modifiers.disabled_modifier[player.index].character_loot_pickup_distance_bonus = true
player_modifiers.disabled_modifier[player.index].character_item_pickup_distance_bonus = true
player_modifiers.disabled_modifier[player.index].character_resource_reach_distance_bonus = true
player_modifiers.disabled_modifier[player.index].character_build_distance_bonus = false
player_modifiers.disabled_modifier[player.index].character_item_drop_distance_bonus = false
player_modifiers.disabled_modifier[player.index].character_reach_distance_bonus = false
player_modifiers.disabled_modifier[player.index].character_loot_pickup_distance_bonus = false
player_modifiers.disabled_modifier[player.index].character_item_pickup_distance_bonus = false
player_modifiers.disabled_modifier[player.index].character_resource_reach_distance_bonus = false
P.update_player_modifiers(player)
end
end

View File

@ -20,6 +20,17 @@ local space = {
bottom_padding = 0
}
local function get_player_data(player, remove)
if remove and this.data[player.index] then
this.data[player.index] = nil
return
end
if not this.data[player.index] then
this.data[player.index] = {}
end
return this.data[player.index]
end
local function addStyle(guiIn, styleIn)
for k, v in pairs(styleIn) do
guiIn.style[k] = v
@ -41,7 +52,7 @@ local function validate_object(obj)
end
local function player_opened(player)
local data = this.data[player.index]
local data = get_player_data(player)
if not data then
return false
@ -57,7 +68,7 @@ local function player_opened(player)
end
local function last_tab(player)
local data = this.data[player.index]
local data = get_player_data(player)
if not data then
return false
@ -91,7 +102,7 @@ local function validate_player(player)
end
local function close_player_inventory(player)
local data = this.data[player.index]
local data = get_player_data(player)
if not data then
return
@ -110,7 +121,7 @@ local function close_player_inventory(player)
end
element.destroy()
Public.reset_table(player)
get_player_data(player, true)
end
local function redraw_inventory(gui, source, target, caption, panel_type)
@ -169,7 +180,7 @@ local function redraw_inventory(gui, source, target, caption, panel_type)
end
local function add_inventory(panel, source, target, caption, panel_type)
local data = this.data[source.index]
local data = get_player_data(source)
data.panel_type = data.panel_type or {}
local pane_name = panel.add({type = 'tab', caption = caption, name = caption})
local scroll_pane =
@ -231,8 +242,10 @@ local function open_inventory(source, target)
local panel = frame.add({type = 'tabbed-pane', name = 'tabbed_pane'})
panel.selected_tab_index = 1
this.data[source.index].player_opened = target
this.data[source.index].last_tab = 'Main'
local data = get_player_data(source)
data.player_opened = target
data.last_tab = 'Main'
local main = target.get_main_inventory().get_contents()
local armor = target.get_inventory(defines.inventory.character_armor).get_contents()
@ -278,7 +291,7 @@ local function on_gui_click(event)
return
end
local data = this.data[player.index]
local data = get_player_data(player)
if not data then
return
end
@ -312,7 +325,7 @@ local function gui_closed(event)
local type = event.gui_type
if type == defines.gui_type.custom then
local data = this.data[player.index]
local data = get_player_data(player)
if not data then
return
end
@ -320,14 +333,6 @@ local function gui_closed(event)
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not this.data[player.index] then
this.data[player.index] = {}
end
end
local function on_pre_player_left_game(event)
local player = game.players[event.player_index]
close_player_inventory(player)
@ -419,19 +424,9 @@ function Public.get(key)
end
end
function Public.reset_table(player)
if validate_player(player) then
local data = this.data[player.index]
for k in pairs(data) do
this.data[player.index][k] = nil
end
end
end
Event.add(defines.events.on_player_main_inventory_changed, update_gui)
Event.add(defines.events.on_gui_closed, gui_closed)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)
return Public

View File

@ -718,6 +718,15 @@ end
local function clear_tables()
local this = WD.get()
this.unit_group_last_command = {}
for k, groups in next, this.active_biters do
for _, entity in next, groups do
if type(entity) == 'table' then
if not entity or not entity.valid then
this.active_biters[k] = nil
end
end
end
end
end
local tick_tasks = {

View File

@ -220,10 +220,15 @@ local on_player_changed_surface = function(event)
if not player or not player.valid then
return
end
local p_data = get_player_data(player)
if jailed[player.name] and p_data and p_data.locked then
local surface = game.surfaces['gulag']
if player.surface.index ~= surface.index then
if not jailed[player.name] then
return
end
local surface = game.surfaces['gulag']
if player.surface.index ~= surface.index then
local p_data = get_player_data(player)
if jailed[player.name] and p_data and p_data.locked then
teleport_player_to_gulag(player, 'jail')
end
end

View File

@ -115,6 +115,27 @@ function Gui.clear(element)
element.clear()
end
local function clear_invalid_data()
for _, player in pairs(game.connected_players) do
local player_index = player.index
local values = data[player_index]
if values then
for _, element in next, values do
if type(element) == 'table' then
for key, obj in next, element do
if type(obj) == 'table' and obj.valid ~= nil then
if not obj.valid then
element[key] = nil
end
end
end
end
end
end
end
end
Event.on_nth_tick(300, clear_invalid_data)
local function handler_factory(event_id)
local handlers