mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-06 00:23:49 +02:00
fixes
This commit is contained in:
parent
7da400db14
commit
8bc37712ff
@ -210,12 +210,7 @@ local function on_player_built_tile(event)
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
local surface = event.surface
|
||||
if surface and surface.valid then
|
||||
surface = event.surface.index
|
||||
else
|
||||
surface = 'nil'
|
||||
end
|
||||
local surface = event.surface_index
|
||||
|
||||
--landfill history--
|
||||
|
||||
@ -617,43 +612,34 @@ local function on_player_cursor_stack_changed(event)
|
||||
end
|
||||
|
||||
local function on_player_cancelled_crafting(event)
|
||||
local tracker = session.get_session_table()
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
local playtime = player.online_time
|
||||
if tracker[player.name] then
|
||||
playtime = player.online_time + tracker[player.name]
|
||||
end
|
||||
|
||||
local count = #event.items
|
||||
|
||||
if playtime < 1296000 then
|
||||
if count > 40 then
|
||||
Utils.action_warning(
|
||||
'{Crafting}',
|
||||
player.name ..
|
||||
' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. count .. '.'
|
||||
)
|
||||
if not this.cancel_crafting_history[player.index] then
|
||||
this.cancel_crafting_history[player.index] = {}
|
||||
end
|
||||
if #this.cancel_crafting_history[player.index] > 100 then
|
||||
this.cancel_crafting_history[player.index] = {}
|
||||
end
|
||||
|
||||
local t = math.abs(math.floor((game.tick) / 3600))
|
||||
local str = '[' .. t .. '] '
|
||||
str = str .. player.name .. ' canceled '
|
||||
str = str .. ' item ' .. event.recipe.name
|
||||
str = str .. ' count was a total of: ' .. count
|
||||
str = str .. ' at X:'
|
||||
str = str .. math.floor(player.position.x)
|
||||
str = str .. ' Y:'
|
||||
str = str .. math.floor(player.position.y)
|
||||
str = str .. ' '
|
||||
str = str .. 'surface:' .. player.surface.index
|
||||
increment(this.cancel_crafting_history, player.index, str)
|
||||
if count > 40 then
|
||||
Utils.action_warning(
|
||||
'{Crafting}',
|
||||
player.name .. ' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. count .. '.'
|
||||
)
|
||||
if not this.cancel_crafting_history[player.index] then
|
||||
this.cancel_crafting_history[player.index] = {}
|
||||
end
|
||||
if #this.cancel_crafting_history[player.index] > 100 then
|
||||
this.cancel_crafting_history[player.index] = {}
|
||||
end
|
||||
|
||||
local t = math.abs(math.floor((game.tick) / 3600))
|
||||
local str = '[' .. t .. '] '
|
||||
str = str .. player.name .. ' canceled '
|
||||
str = str .. ' item ' .. event.recipe.name
|
||||
str = str .. ' count was a total of: ' .. count
|
||||
str = str .. ' at X:'
|
||||
str = str .. math.floor(player.position.x)
|
||||
str = str .. ' Y:'
|
||||
str = str .. math.floor(player.position.y)
|
||||
str = str .. ' '
|
||||
str = str .. 'surface:' .. player.surface.index
|
||||
increment(this.cancel_crafting_history, player.index, str)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -12,7 +12,6 @@ require 'modules.custom_death_messages'
|
||||
local Unit_health_booster = require 'modules.biter_health_booster'
|
||||
local Difficulty = require 'modules.difficulty_vote'
|
||||
local Map = require 'modules.map_info'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Event = require 'utils.event'
|
||||
local Reset = require 'functions.soft_reset'
|
||||
local Server = require 'utils.server'
|
||||
@ -37,26 +36,7 @@ local starting_items = {
|
||||
['stone'] = 12
|
||||
}
|
||||
|
||||
local set_difficulty = function()
|
||||
local Diff = Difficulty.get()
|
||||
local wave_defense_table = WD.get_table()
|
||||
local player_count = #game.connected_players
|
||||
if not Diff.difficulty_vote_value then
|
||||
Diff.difficulty_vote_value = 0.1
|
||||
end
|
||||
|
||||
wave_defense_table.max_active_biters = 888 + player_count * (90 * Diff.difficulty_vote_value)
|
||||
|
||||
wave_defense_table.threat_gain_multiplier = 1.2 + player_count * Diff.difficulty_vote_value * 0.1
|
||||
|
||||
wave_defense_table.wave_interval = 3600 - player_count * 60
|
||||
if wave_defense_table.wave_interval < 1800 then
|
||||
wave_defense_table.wave_interval = 1800
|
||||
end
|
||||
end
|
||||
|
||||
function Public.reset_game()
|
||||
local wave_defense_table = WD.get_table()
|
||||
FDT.reset_table()
|
||||
Poll.reset()
|
||||
local this = FDT.get()
|
||||
@ -119,17 +99,6 @@ function Public.reset_game()
|
||||
|
||||
surface.peaceful_mode = false
|
||||
|
||||
WD.reset_wave_defense()
|
||||
wave_defense_table.surface_index = this.active_surface_index
|
||||
wave_defense_table.target = this.locomotive
|
||||
wave_defense_table.nest_building_density = 32
|
||||
wave_defense_table.game_lost = false
|
||||
wave_defense_table.spawn_position = {x = 0, y = 100}
|
||||
WD.alert_boss_wave(true)
|
||||
WD.clear_corpses(false)
|
||||
|
||||
set_difficulty()
|
||||
|
||||
local r = 320
|
||||
local p = {x = -131, y = 5}
|
||||
game.forces.player.chart(
|
||||
@ -1182,17 +1151,12 @@ local on_player_joined_game = function(event)
|
||||
|
||||
create_wave_gui(player)
|
||||
add_fd_stats_button(player)
|
||||
set_difficulty()
|
||||
|
||||
if game.tick > 900 then
|
||||
is_game_lost()
|
||||
end
|
||||
end
|
||||
|
||||
local on_player_left_game = function()
|
||||
set_difficulty()
|
||||
end
|
||||
|
||||
local on_built_entity = function(event)
|
||||
local get_score = Score.get_table().score_table
|
||||
local this = FDT.get()
|
||||
@ -1484,7 +1448,6 @@ Event.add(defines.events.on_built_entity, on_built_entity)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
Event.add(defines.events.on_research_finished, on_research_finished)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
|
@ -41,12 +41,12 @@ function Public.reset_table()
|
||||
this.market_age = nil
|
||||
this.last_reset = game.tick
|
||||
this.wave_interval = 3600
|
||||
this.wave_grace_period = game.tick + 3600 * 20
|
||||
this.wave_grace_period = game.tick + 5500 * 20
|
||||
-- this.wave_grace_period = game.tick + 3600
|
||||
this.boss_biters = {}
|
||||
this.acid_lines_delay = {}
|
||||
this.entity_limits = {
|
||||
['gun-turret'] = {placed = 1, limit = 1, str = 'gun turret', slot_price = 75},
|
||||
['gun-turret'] = {placed = 1, limit = 2, str = 'gun turret', slot_price = 75},
|
||||
['laser-turret'] = {placed = 0, limit = 1, str = 'laser turret', slot_price = 300},
|
||||
['artillery-turret'] = {placed = 0, limit = 1, str = 'artillery turret', slot_price = 500},
|
||||
['flamethrower-turret'] = {placed = 0, limit = 0, str = 'flamethrower turret', slot_price = 50000},
|
||||
@ -62,7 +62,7 @@ function Public.reset_table()
|
||||
[7] = {wave_interval = 2700, amount_modifier = 1.48, strength_modifier = 2.50, boss_modifier = 9.0}
|
||||
}
|
||||
this.boss_waves = {
|
||||
[50] = {{name = 'big-biter', count = 3}},
|
||||
[50] = {{name = 'big-biter', count = 2}},
|
||||
[100] = {{name = 'behemoth-biter', count = 1}},
|
||||
[150] = {{name = 'behemoth-spitter', count = 4}, {name = 'big-spitter', count = 16}},
|
||||
[200] = {
|
||||
@ -77,10 +77,6 @@ function Public.reset_table()
|
||||
},
|
||||
[300] = {{name = 'behemoth-biter', count = 16}, {name = 'behemoth-spitter', count = 8}}
|
||||
}
|
||||
this.comfylatron_habitat = {
|
||||
left_top = {x = -1500, y = -1500},
|
||||
right_bottom = {x = -80, y = 1500}
|
||||
}
|
||||
this.shotgun_shell_damage_modifier_old = {}
|
||||
this.flame_boots = {}
|
||||
end
|
||||
|
162
utils/event.lua
162
utils/event.lua
@ -109,6 +109,8 @@ local stage_load = _STAGE.load
|
||||
local script_on_event = script.on_event
|
||||
local script_on_nth_tick = script.on_nth_tick
|
||||
local generate_event_name = script.generate_event_name
|
||||
local function_table = function_table
|
||||
local function_nth_tick_table = function_nth_tick_table
|
||||
|
||||
local Event = {}
|
||||
|
||||
@ -259,30 +261,47 @@ end
|
||||
-- See documentation at top of file for details on using events.
|
||||
-- @param event_name<number>
|
||||
-- @param func<function>
|
||||
function Event.add_removable_function(event_name, func)
|
||||
-- @param name<string>
|
||||
function Event.add_removable_function(event_name, func, name)
|
||||
if _LIFECYCLE == stage_load then
|
||||
error('cannot call during on_load', 2)
|
||||
end
|
||||
if type(func) ~= 'function' then
|
||||
|
||||
if not event_name or not func or not name then
|
||||
return
|
||||
end
|
||||
|
||||
local f = assert(load('return ' .. func))()
|
||||
|
||||
if type(f) ~= 'function' then
|
||||
error('func must be a function', 2)
|
||||
end
|
||||
|
||||
if Debug.is_closure(func) then
|
||||
if Debug.is_closure(f) then
|
||||
error(
|
||||
'func cannot be a closure as that is a desync risk. Consider using Event.add_removable(event_name, token) instead.',
|
||||
'func cannot be a closure as that is a desync risk. Consider using Event.add_removable(event, token) instead.',
|
||||
2
|
||||
)
|
||||
end
|
||||
|
||||
local funcs = function_handlers[event_name]
|
||||
local funcs = function_handlers[name]
|
||||
if not funcs then
|
||||
function_handlers[event_name] = {func}
|
||||
else
|
||||
funcs[#funcs + 1] = func
|
||||
function_handlers[name] = {}
|
||||
funcs = function_handlers[name]
|
||||
end
|
||||
|
||||
funcs[#funcs + 1] = {event_name = event_name, handler = func}
|
||||
|
||||
local func_table = function_table[name]
|
||||
if not func_table then
|
||||
function_table[name] = {}
|
||||
func_table = function_table[name]
|
||||
end
|
||||
|
||||
func_table[#func_table + 1] = {event_name = event_name, handler = f}
|
||||
|
||||
if handlers_added then
|
||||
core_add(event_name, func)
|
||||
core_add(event_name, f)
|
||||
end
|
||||
end
|
||||
|
||||
@ -290,12 +309,17 @@ end
|
||||
-- Do NOT call this method during on_load.
|
||||
-- See documentation at top of file for details on using events.
|
||||
-- @param event_name<number>
|
||||
-- @param func<function>
|
||||
function Event.remove_removable_function(event_name, func)
|
||||
-- @param name<string>
|
||||
function Event.remove_removable_function(event_name, name)
|
||||
if _LIFECYCLE == stage_load then
|
||||
error('cannot call during on_load', 2)
|
||||
end
|
||||
local funcs = function_handlers[event_name]
|
||||
|
||||
if not event_name or not name then
|
||||
return
|
||||
end
|
||||
|
||||
local funcs = function_handlers[name]
|
||||
|
||||
if not funcs then
|
||||
return
|
||||
@ -303,12 +327,22 @@ function Event.remove_removable_function(event_name, func)
|
||||
|
||||
local handlers = event_handlers[event_name]
|
||||
|
||||
remove(funcs, func)
|
||||
remove(handlers, func)
|
||||
for k, v in pairs(function_table[name]) do
|
||||
local n = v.event_name
|
||||
if n == event_name then
|
||||
local f = v.handler
|
||||
function_handlers[name][k] = nil
|
||||
remove(handlers, f)
|
||||
end
|
||||
end
|
||||
|
||||
if #handlers == 0 then
|
||||
script_on_event(event_name, nil)
|
||||
end
|
||||
|
||||
if #function_handlers[name] == 0 then
|
||||
function_handlers[name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
--- Register a token handler for the nth tick that can be safely added and removed at runtime.
|
||||
@ -369,30 +403,46 @@ end
|
||||
-- See documentation at top of file for details on using events.
|
||||
-- @param tick<number>
|
||||
-- @param func<function>
|
||||
function Event.add_removable_nth_tick_function(tick, func)
|
||||
function Event.add_removable_nth_tick_function(tick, func, name)
|
||||
if _LIFECYCLE == stage_load then
|
||||
error('cannot call during on_load', 2)
|
||||
end
|
||||
if type(func) ~= 'function' then
|
||||
|
||||
if not tick or not func or not name then
|
||||
return
|
||||
end
|
||||
|
||||
local f = assert(load('return ' .. func))()
|
||||
|
||||
if type(f) ~= 'function' then
|
||||
error('func must be a function', 2)
|
||||
end
|
||||
|
||||
if Debug.is_closure(func) then
|
||||
if Debug.is_closure(f) then
|
||||
error(
|
||||
'func cannot be a closure as that is a desync risk. Consider using Event.add_removable_nth_tick(tick, token) instead.',
|
||||
2
|
||||
)
|
||||
end
|
||||
|
||||
local funcs = function_nth_tick_handlers[tick]
|
||||
local funcs = function_nth_tick_handlers[name]
|
||||
if not funcs then
|
||||
function_nth_tick_handlers[tick] = {func}
|
||||
else
|
||||
funcs[#funcs + 1] = func
|
||||
function_nth_tick_handlers[name] = {}
|
||||
funcs = function_nth_tick_handlers[name]
|
||||
end
|
||||
|
||||
funcs[#funcs + 1] = {tick = tick, handler = func}
|
||||
|
||||
local func_table = function_nth_tick_table[name]
|
||||
if not func_table then
|
||||
function_nth_tick_table[name] = {}
|
||||
func_table = function_nth_tick_table[name]
|
||||
end
|
||||
|
||||
func_table[#func_table + 1] = {tick = tick, handler = f}
|
||||
|
||||
if handlers_added then
|
||||
core_on_nth_tick(tick, func)
|
||||
core_on_nth_tick(tick, f)
|
||||
end
|
||||
end
|
||||
|
||||
@ -401,20 +451,43 @@ end
|
||||
-- See documentation at top of file for details on using events.
|
||||
-- @param tick<number>
|
||||
-- @param func<function>
|
||||
function Event.remove_removable_nth_tick_function(tick, func)
|
||||
function Event.remove_removable_nth_tick_function(tick, name)
|
||||
if _LIFECYCLE == stage_load then
|
||||
error('cannot call during on_load', 2)
|
||||
end
|
||||
local funcs = function_nth_tick_handlers[tick]
|
||||
|
||||
if not tick or not name then
|
||||
return
|
||||
end
|
||||
|
||||
local funcs = function_nth_tick_handlers[name]
|
||||
|
||||
if not funcs then
|
||||
return
|
||||
end
|
||||
|
||||
local handlers = on_nth_tick_event_handlers[tick]
|
||||
local f = function_nth_tick_table[name]
|
||||
|
||||
remove(funcs, func)
|
||||
remove(handlers, func)
|
||||
for k, v in pairs(function_nth_tick_table[name]) do
|
||||
local t = v.tick
|
||||
if t == tick then
|
||||
f = v.handler
|
||||
end
|
||||
end
|
||||
|
||||
remove(handlers, f)
|
||||
|
||||
for k, v in pairs(function_nth_tick_handlers[name]) do
|
||||
local t = v.tick
|
||||
if t == tick then
|
||||
function_nth_tick_handlers[name][k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if #function_nth_tick_handlers[name] == 0 then
|
||||
function_nth_tick_handlers[name] = nil
|
||||
end
|
||||
|
||||
if #handlers == 0 then
|
||||
script_on_nth_tick(tick, nil)
|
||||
@ -447,6 +520,13 @@ function Event.add_event_filter(event, filter)
|
||||
end
|
||||
|
||||
local function add_handlers()
|
||||
if not function_table then
|
||||
function_table = {}
|
||||
end
|
||||
if not function_nth_tick_table then
|
||||
function_nth_tick_table = {}
|
||||
end
|
||||
|
||||
for event_name, tokens in pairs(token_handlers) do
|
||||
for i = 1, #tokens do
|
||||
local handler = Token.get(tokens[i])
|
||||
@ -454,10 +534,19 @@ local function add_handlers()
|
||||
end
|
||||
end
|
||||
|
||||
for event_name, funcs in pairs(function_handlers) do
|
||||
for name, funcs in pairs(function_handlers) do
|
||||
for i = 1, #funcs do
|
||||
local handler = funcs[i]
|
||||
core_add(event_name, handler)
|
||||
local e_name = funcs[i].event_name
|
||||
local func = funcs[i].handler
|
||||
local handler = assert(load('return ' .. func))()
|
||||
local func_handler = function_table[name]
|
||||
if not func_handler then
|
||||
function_table[name] = {}
|
||||
func_handler = function_table[name]
|
||||
end
|
||||
|
||||
func_handler[#func_handler + 1] = {event_name = e_name, handler = handler}
|
||||
core_add(e_name, handler)
|
||||
end
|
||||
end
|
||||
|
||||
@ -468,9 +557,18 @@ local function add_handlers()
|
||||
end
|
||||
end
|
||||
|
||||
for tick, funcs in pairs(function_nth_tick_handlers) do
|
||||
for name, funcs in pairs(function_nth_tick_handlers) do
|
||||
for i = 1, #funcs do
|
||||
local handler = funcs[i]
|
||||
local tick = funcs[i].tick
|
||||
local func = funcs[i].handler
|
||||
local handler = assert(load('return ' .. func))()
|
||||
local func_handler = function_nth_tick_table[name]
|
||||
if not func_handler then
|
||||
function_nth_tick_table[name] = {}
|
||||
func_handler = function_nth_tick_table[name]
|
||||
end
|
||||
|
||||
func_handler[#func_handler + 1] = {tick = tick, handler = handler}
|
||||
core_on_nth_tick(tick, handler)
|
||||
end
|
||||
end
|
||||
@ -480,5 +578,7 @@ end
|
||||
|
||||
core_on_init(add_handlers)
|
||||
core_on_load(add_handlers)
|
||||
function_table = {}
|
||||
function_nth_tick_table = {}
|
||||
|
||||
return Event
|
||||
|
Loading…
Reference in New Issue
Block a user