1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-05 13:15:03 +02:00

minor changes

This commit is contained in:
Gerkiz 2020-07-10 16:08:50 +02:00
parent 473f75f7a6
commit 4cfe885df6
7 changed files with 187 additions and 17 deletions

View File

@ -6,10 +6,14 @@ local Event = require 'utils.event'
local session = require 'utils.session_data'
local Global = require 'utils.global'
local Utils = require 'utils.core'
local Color = require 'utils.color_presets'
local Server = require 'utils.server'
local Public = {}
local match = string.match
local capsule_bomb_threshold = 8
local format = string.format
local this = {
landfill_history = {},
@ -19,8 +23,12 @@ local this = {
corpse_history = {},
cancel_crafting_history = {},
whitelist_types = {},
players_warned = {},
log_tree_harvest = false,
do_not_check_trusted = true
do_not_check_trusted = true,
protect_entities = false,
enable_autokick = true,
enable_autoban = false
}
local blacklisted_types = {
@ -36,6 +44,7 @@ local blacklisted_types = {
}
local ammo_names = {
['artillery-targeting-remote'] = true,
['poison-capsule'] = true,
['cluster-grenade'] = true,
['grenade'] = true,
@ -44,6 +53,12 @@ local ammo_names = {
['rocket'] = true
}
local not_protected = {
['wall'] = true,
['container'] = true,
['logistic-container'] = true
}
Global.register(
this,
function(t)
@ -55,8 +70,47 @@ local function increment(t, k, v)
t[k][#t[k] + 1] = (v or 1)
end
local function damage_player(player)
local function get_entities(item_name, entities)
local set = {}
for i = 1, #entities do
local e = entities[i]
local name = e.name
if name ~= item_name and name ~= 'entity-ghost' then
local count = set[name]
if count then
set[name] = count + 1
else
set[name] = 1
end
end
end
local list = {}
local i = 1
for k, v in pairs(set) do
list[i] = v
i = i + 1
list[i] = ' '
i = i + 1
list[i] = k
i = i + 1
list[i] = ', '
i = i + 1
end
list[i - 1] = nil
return table.concat(list)
end
local function damage_player(player, kill)
local msg = ' tried to destroy our base, but it backfired!'
if player.character then
if kill then
player.character.die('enemy')
game.print(player.name .. msg, Color.yellow)
return
end
player.character.health = player.character.health - math.random(50, 100)
player.character.surface.create_entity({name = 'water-splash', position = player.position})
local messages = {
@ -64,10 +118,10 @@ local function damage_player(player)
'Just a fleshwound.',
'Better keep those hands to yourself or you might loose them.'
}
player.print(messages[math.random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0})
player.print(messages[math.random(1, #messages)], Color.yellow)
if player.character.health <= 0 then
player.character.die('enemy')
game.print(player.name .. ' should have obeyed the law.', {r = 0.75, g = 0.0, b = 0.0})
game.print(player.name .. msg, Color.yellow)
return
end
end
@ -197,8 +251,6 @@ local function on_player_used_capsule(event)
if trusted[player.name] and this.do_not_check_trusted then
return
end
local position = event.position
local item = event.item
if not item then
@ -207,7 +259,58 @@ local function on_player_used_capsule(event)
local name = item.name
local position = event.position
local x, y = position.x, position.y
local surface = player.surface
if ammo_names[name] then
if
surface.count_entities_filtered({force = 'enemy', area = {{x - 10, y - 10}, {x + 10, y + 10}}, limit = 1}) >
0
then
return
end
local count = 0
local entities =
player.surface.find_entities_filtered {force = player.force, area = {{x - 5, y - 5}, {x + 5, y + 5}}}
for i = 1, #entities do
local e = entities[i]
local entity_name = e.name
if entity_name ~= name and entity_name ~= 'entity-ghost' and not blacklisted_types[e.type] then
count = count + 1
end
end
if count <= capsule_bomb_threshold then
return
end
local msg = format(player.name .. ' damaged: %s with: %s', get_entities(name, entities), name)
if this.players_warned[event.player_index] == 2 then
if this.enable_autoban then
Server.ban_sync(
player.name,
format(
'Damaged: %s with: %s. This action was performed automatically. Visit getcomfy.eu/discord for forgiveness',
get_entities(name, entities),
name
),
'<script>'
)
end
elseif this.players_warned[event.player_index] == 1 then
this.players_warned[event.player_index] = true
if this.enable_autokick then
game.kick_player(player, msg)
end
else
this.players_warned[event.player_index] = 1
damage_player(player, true)
Utils.print_to(nil, msg)
end
if not this.capsule_history[player.index] then
this.capsule_history[player.index] = {}
end
@ -217,7 +320,7 @@ local function on_player_used_capsule(event)
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. player.name .. ' used ' .. name
str = str .. msg
str = str .. ' at X:'
str = str .. math.floor(position.x)
str = str .. ' Y:'
@ -488,6 +591,7 @@ local function on_player_cursor_stack_changed(event)
end
end
end
local function on_player_cancelled_crafting(event)
local tracker = session.get_session_table()
local player = game.players[event.player_index]
@ -529,6 +633,47 @@ local function on_player_cancelled_crafting(event)
end
end
local function protect_entities(event)
local entity = event.entity
local function is_protected(e)
if not_protected[e.type] then
return false
end
return true
end
if is_protected(entity) then
entity.health = entity.health + event.final_damage_amount
end
end
local function on_entity_damaged(event)
local entity = event.entity
if not entity or not entity.valid then
return
end
if entity.force.index ~= 1 then
return
end
if this.protect_entities then
protect_entities(event)
end
end
--- Enabling this will protect all entities except for those in the not_protected table.
---@param boolean true/false
function Public.protect_entities(value)
if value then
this.protect_entities = value
end
end
--- This will reset the table of this
function Public.reset_tables()
this.landfill_history = {}
this.capsule_history = {}
@ -538,12 +683,6 @@ function Public.reset_tables()
this.cancel_crafting_history = {}
end
function Public.cursor_stack(event, pattern)
local player = game.get_player(event.player_index)
local stack = player.cursor_stack
return stack and stack.valid_for_read and stack.name:match(pattern)
end
--- Enable this to log when trees are destroyed
---@param value boolean
function Public.log_tree_harvest(value)
@ -591,5 +730,6 @@ Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
Event.add(defines.events.on_player_cursor_stack_changed, on_player_cursor_stack_changed)
Event.add(defines.events.on_player_cancelled_crafting, on_player_cancelled_crafting)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
return Public

View File

@ -276,6 +276,10 @@ local function draw_events(data)
if game.players[target_player_name] then
local target_player = game.players[target_player_name].index
if #history_index[history] <= 0 then
return
end
for _, value in pairs(history_index[history][target_player]) do
if search_text then
local success = contains_text(value, nil, search_text)

View File

@ -369,6 +369,7 @@ local function player_list_show(player, frame, sort_by)
-- Frame management
frame.clear()
frame.style.padding = 8
local play_table = play_time.get_trusted_table()
-- Header management
local t = frame.add {type = 'table', name = 'player_list_panel_header_table', column_count = 5}
@ -469,12 +470,27 @@ local function player_list_show(player, frame, sort_by)
sprite.style.width = 32
sprite.style.stretch_image_to_widget_size = true
local trusted
local tooltip
if game.players[player_list[i].name].admin then
trusted = '[color=#ff0000][A][/color]'
tooltip = 'This player is an admin of this server.'
elseif play_table[player_list[i].name] then
trusted = '[color=#008000][T][/color]'
tooltip = 'This player trusted.'
else
trusted = '[color=#ffff00][U][/color]'
tooltip = 'This player not trusted.'
end
-- Name
local label =
player_list_panel_table.add {
type = 'label',
name = 'player_list_panel_player_names_' .. i,
caption = player_list[i].name
caption = player_list[i].name .. ' ' .. trusted,
tooltip = tooltip
}
label.style.font = 'default'
label.style.font_color = {

View File

@ -1,5 +1,5 @@
[mountain_fortress_v3]
map_info_main_caption=M O U N T A I N F O R T R E S S V3
map_info_sub_caption= ..diggy diggy choo choo..
map_info_text=The biters have catched the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn additon, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research, will overhaul your mining equipment,\nreinforcing your pickaxe as well as increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nArtillery will try to shoot you down! Dig fast, dig north!\n\nSome explosives may cause parts of the ceiling to crumble, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nYou may find some supply goods, if you enter the wagon.\n\nRandom buildings that generate resources can be found throughout the world.\nPlacing steel-chests near cargo-wagons enables you to quickly move content.\n\nGood luck on your journey!
map_info_sub_caption= ~~ diggy diggy choo choo ~~
map_info_text=The biters have catched the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn additon, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research, will overhaul your mining equipment,\nreinforcing your pickaxe as well as increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nArtillery will try to shoot you down! Dig fast, dig north!\n\nSome explosives may cause parts of the ceiling to crumble, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nEnter the cargo wagon to reveal the wagon surface!\n\nRandom buildings that generate resources can be found throughout the world.\n\nPlacing steel-chests near cargo-wagons enables you to quickly move content.\n\nGood luck on your journey!

View File

@ -31,7 +31,7 @@ commands.add_command(
::continue::
local this = FDT.get()
local reset_map = require 'maps.fish_defender.main'.on_init
local reset_map = require 'maps.fish_defender.main'.reset_game
if not this.reset_are_you_sure then
this.reset_are_you_sure = true

View File

@ -341,6 +341,7 @@ local function on_player_mined_entity(event)
give_coin(player)
if Locomotive.is_around_train(entity) then
entity.destroy()
return
end
@ -617,6 +618,10 @@ local function on_entity_died(event)
}
if entity_type[entity.type] then
if Locomotive.is_around_train(entity) then
entity.destroy()
return
end
if entity.type == 'unit' or entity_type == 'unit-spawner' then
this.biters_killed = this.biters_killed + 1
end
@ -631,6 +636,10 @@ local function on_entity_died(event)
end
if entity.type == 'tree' then
if Locomotive.is_around_train(entity) then
entity.destroy()
return
end
angry_tree(event.entity, event.cause)
return
end

View File

@ -244,6 +244,7 @@ function Public.reset_map()
Entities.set_scores()
AntiGrief.log_tree_harvest(true)
AntiGrief.whitelist_types('tree', true)
AntiGrief.protect_entities(true)
get_score.score_table = {}
Difficulty.reset_difficulty_poll({difficulty_poll_closing_timeout = game.tick + 36000})
Diff.gui_width = 20