1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-06 00:23:49 +02:00

Merge pull request #53 from M3wM3w/master

update from main
This commit is contained in:
hanakocz 2021-03-03 21:09:24 +01:00 committed by GitHub
commit 8b65939e2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 176 additions and 70 deletions

View File

@ -1,36 +1,36 @@
local Server = require 'utils.server'
local Modifers = require 'player_modifiers'
local Modifiers = require 'player_modifiers'
local Global = require 'utils.global'
local Event = require 'utils.event'
local Public = {}
local resettable = {}
local this = {}
---------------------------global table-----------------------------------------
Global.register(
resettable,
this,
function(tbl)
resettable = tbl
this = tbl
end
)
function Public.reset_table()
for k, _ in pairs(resettable) do
resettable[k] = nil
for k, _ in pairs(this) do
this[k] = nil
end
resettable.soft_reset_counter = 0
resettable.original_surface_name = nil
resettable.schedule_step = 0
resettable.schedule_max_step = 0
resettable.schedule = {}
resettable.initial_tick = 0
this.soft_reset_counter = 0
this.original_surface_name = nil
this.schedule_step = 0
this.schedule_max_step = 0
this.schedule = {}
this.initial_tick = 0
end
function Public.get_table()
return resettable
return this
end
local on_init = function ()
local on_init = function()
Public.reset_table()
end
@ -38,15 +38,17 @@ Event.on_init(on_init)
-------------------------scheduled deletion-------------------------------------
local function add_step()
if resettable.schedule_step ~= resettable.schedule_max_step then
resettable.schedule_step = resettable.schedule_step + 1
if this.schedule_step ~= this.schedule_max_step then
this.schedule_step = this.schedule_step + 1
end
end
local function scheduled_surface_clearing()
if resettable.initial_tick > game.tick then return end
local step = resettable.schedule_step
local schedule = resettable.schedule
if this.initial_tick > game.tick then
return
end
local step = this.schedule_step
local schedule = this.schedule
if schedule[step] then
local surface = schedule[step].surface
if not surface.valid then
@ -54,32 +56,38 @@ local function scheduled_surface_clearing()
add_step()
return
end
if schedule[step].operation == "biter_clearing" then
local biters = surface.find_entities_filtered{type = "unit", limit = 10000}
for _,biter in pairs(biters) do
if biter.valid then biter.destroy() end
if schedule[step].operation == 'biter_clearing' then
local biters = surface.find_entities_filtered {type = 'unit', limit = 10000}
for _, biter in pairs(biters) do
if biter.valid then
biter.destroy()
end
end
schedule[step] = nil
add_step()
elseif schedule[step].operation == "nest_clearing" then
local nests = surface.find_entities_filtered{type = "unit-spawner"}
elseif schedule[step].operation == 'nest_clearing' then
local nests = surface.find_entities_filtered {type = 'unit-spawner'}
for _, nest in pairs(nests) do
if nest.valid then nest.destroy() end
if nest.valid then
nest.destroy()
end
end
schedule[step] = nil
add_step()
elseif schedule[step].operation == "scrap_clearing" then
local scrap = surface.find_entities_filtered{force = "neutral", limit = 5000}
elseif schedule[step].operation == 'scrap_clearing' then
local scrap = surface.find_entities_filtered {force = 'neutral', limit = 5000}
for _, e in pairs(scrap) do
if e.valid then e.destroy() end
if e.valid then
e.destroy()
end
end
schedule[step] = nil
add_step()
elseif schedule[step].operation == "clear" then
elseif schedule[step].operation == 'clear' then
surface.clear()
schedule[step] = nil
add_step()
elseif schedule[step].operation == "delete" then
elseif schedule[step].operation == 'delete' then
game.delete_surface(surface)
schedule[step] = nil
add_step()
@ -88,45 +96,45 @@ local function scheduled_surface_clearing()
end
function Public.add_schedule_to_delete_surface(surface)
local step = resettable.schedule_max_step
local step = this.schedule_max_step
local add = 1
resettable.schedule[step + add] = {operation = "nest_clearing", surface = surface}
this.schedule[step + add] = {operation = 'nest_clearing', surface = surface}
add = add + 1
local count_biters = surface.count_entities_filtered{type = "unit"}
local count_biters = surface.count_entities_filtered {type = 'unit'}
for i = 1, count_biters, 10000 do
resettable.schedule[step + add] = {operation = "biter_clearing", surface = surface}
this.schedule[step + add] = {operation = 'biter_clearing', surface = surface}
add = add + 1
end
local count_scrap = surface.count_entities_filtered{force = "neutral"}
local count_scrap = surface.count_entities_filtered {force = 'neutral'}
for i = 1, count_scrap, 5000 do
resettable.schedule[step + add] = {operation = "scrap_clearing", surface = surface}
this.schedule[step + add] = {operation = 'scrap_clearing', surface = surface}
add = add + 1
end
resettable.schedule[step + add] = {operation = "clear", surface = surface}
this.schedule[step + add] = {operation = 'clear', surface = surface}
add = add + 1
resettable.schedule[step + add] = {operation = "delete", surface = surface}
resettable.schedule_max_step = resettable.schedule_max_step + add
if resettable.schedule_step == step then
resettable.schedule_step = resettable.schedule_step + 1
this.schedule[step + add] = {operation = 'delete', surface = surface}
this.schedule_max_step = this.schedule_max_step + add
if this.schedule_step == step then
this.schedule_step = this.schedule_step + 1
end
if resettable.initial_tick <= game.tick then
if this.initial_tick <= game.tick then
--add offset for starting of deletion, so new map can generate peacefully for a minute and tiny bit
resettable.initial_tick = game.tick + 4000
this.initial_tick = game.tick + 4000
end
end
function Public.change_entities_to_neutral(surface, force, delete_pollution)
local entities = surface.find_entities_filtered{force = force or "player"}
local entities = surface.find_entities_filtered {force = force or 'player'}
for _, entity in pairs(entities) do
if entity.valid then
entity.force = "neutral"
entity.force = 'neutral'
entity.active = false
end
end
if delete_pollution then
local pollution = surface.get_total_pollution()
surface.clear_pollution()
game.pollution_statistics.on_flow("power-switch", -pollution)
game.pollution_statistics.on_flow('power-switch', -pollution)
end
end
@ -175,44 +183,79 @@ local function equip_players(player_starting_items)
for item, amount in pairs(player_starting_items) do
player.insert({name = item, count = amount})
end
Modifers.update_player_modifiers(player)
Modifiers.update_player_modifiers(player)
end
end
local function clear_robots(new_surface)
local radius = 512
local area = {{x = -radius, y = -radius}, {x = radius, y = radius}}
for _, entity in pairs(new_surface.find_entities_filtered {area = area, type = 'logistic-robot'}) do
entity.destroy()
end
for _, entity in pairs(new_surface.find_entities_filtered {area = area, type = 'construction-robot'}) do
entity.destroy()
end
end
function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_items)
if not resettable.original_surface_name then
resettable.original_surface_name = old_surface.name
if not this.original_surface_name then
this.original_surface_name = old_surface.name
end
resettable.soft_reset_counter = resettable.soft_reset_counter + 1
this.soft_reset_counter = this.soft_reset_counter + 1
local new_surface =
game.create_surface(
resettable.original_surface_name .. '_' .. tostring(resettable.soft_reset_counter),
map_gen_settings
)
local new_surface = game.create_surface(this.original_surface_name .. '_' .. tostring(this.soft_reset_counter), map_gen_settings)
new_surface.request_to_generate_chunks({0, 0}, 1)
new_surface.force_generate_chunk_requests()
reset_forces(new_surface, old_surface)
teleport_players(new_surface)
equip_players(player_starting_items)
clear_robots(new_surface)
Public.change_entities_to_neutral(old_surface)
Public.add_schedule_to_delete_surface(old_surface)
local message = {'modules.soft_reset_welcome', resettable.original_surface_name}
if resettable.soft_reset_counter > 1 then
message =
{
'modules.soft_reset_reshape',
resettable.original_surface_name,
tostring(resettable.soft_reset_counter),
}
local to_discord = {'modules.soft_reset_welcome', this.original_surface_name}
local restarting_to_discord = {'modules.soft_reset_reshape', this.original_surface_name, tostring(this.soft_reset_counter)}
local message
if this.enable_mapkeeper then
message = {'modules.soft_reset_welcome_mapkeeper', this.original_surface_name}
else
message = to_discord
end
if this.soft_reset_counter > 1 then
if this.enable_mapkeeper then
message = {
'modules.soft_reset_reshape_mapkeeper',
this.original_surface_name,
tostring(this.soft_reset_counter)
}
else
message = restarting_to_discord
end
end
game.print(message, {r = 0.98, g = 0.66, b = 0.22})
Server.to_discord_embed(message, true)
return new_surface
end
--- Returns the amount of times the server has soft restarted.
function Public.get_reset_counter()
return this.soft_reset_counter
end
--- Customizes the message with the mapkeeper param.
---@param boolean <true/false>
function Public.enable_mapkeeper(boolean)
if boolean and type(boolean) == 'boolean' then
this.enable_mapkeeper = boolean or false
end
end
return Public

View File

@ -11,6 +11,8 @@ difficulty_vote_vote=Vote difficulty:
soft_reset_welcome=>> Welcome to __1__!
soft_reset_reshape=>> The world has been reshaped, welcome to __1__ number __2__!
soft_reset_welcome_mapkeeper=[color=blue]Mapkeeper:[/color] Welcome to __1__!
soft_reset_reshape_mapkeeper=[color=blue]Mapkeeper:[/color] The world has been reshaped, welcome to __1__ number __2__!
[modules_towny]
map_info=__1__\n\n__2__\n\n__3__\n\n__4__\n\n__5__

View File

@ -48,6 +48,17 @@ end
local biter_count_limit = 1024 --maximum biters on the east side of the map, next wave will be delayed if the maximum has been reached
local function check_timer()
local wave_grace_period = FDT.get('wave_grace_period')
if not wave_grace_period then
return
end
if wave_grace_period < game.tick then
FDT.set('wave_grace_period', 72000)
end
end
local function create_wave_gui(player)
if player.gui.top['fish_defense_waves'] then
player.gui.top['fish_defense_waves'].destroy()
@ -86,6 +97,8 @@ local function create_wave_gui(player)
if time_remaining <= 0 then
FDT.set('wave_grace_period', nil)
return
else
check_timer()
end
local label = frame.add({type = 'label', caption = 'Waves will start in ' .. time_remaining .. ' minutes.'})
@ -496,7 +509,7 @@ local function spawn_boss_units(surface)
health_factor = health_factor * 2
end
local biter_health_boost = FDT.get('biter_health_boost')
local biter_health_boost = Unit_health_booster.get('biter_health_boost')
local boss_biters = FDT.get('boss_biters')
local position = {x = 216, y = 0}
@ -612,9 +625,19 @@ local function biter_attack_wave()
if Diff.difficulty_vote_index then
m = m * FDT.get_current_difficulty_strength_modifier()
end
game.forces.enemy.set_ammo_damage_modifier('melee', wave_count * m)
game.forces.enemy.set_ammo_damage_modifier('biological', wave_count * m)
FDT.set('biter_health_boost', 1 + (wave_count * (m * 2)))
local biter_health_boost_forced = Unit_health_booster.get('biter_health_boost_forced')
if not biter_health_boost_forced then
Unit_health_booster.set('biter_health_boost', 1 + (wave_count * (m * 2)))
end
local make_normal_unit_mini_bosses = Unit_health_booster.get('make_normal_unit_mini_bosses')
if wave_count > 500 and not make_normal_unit_mini_bosses then
Unit_health_booster.enable_make_normal_unit_mini_bosses(true)
end
m = 4
if Diff.difficulty_vote_index then
@ -1336,6 +1359,9 @@ function Public.reset_game()
end
Unit_health_booster.set_active_surface(surface.name)
Unit_health_booster.check_on_entity_died(true)
Unit_health_booster.acid_nova(true)
Unit_health_booster.boss_spawns_projectiles(true)
Unit_health_booster.set('biter_health_boost', 4)
surface.peaceful_mode = false

View File

@ -45,7 +45,6 @@ function Public.reset_table()
this.last_reset = game.tick
this.wave_interval = 3600
this.wave_grace_period = game.tick + 72000
this.biter_health_boost = 4
-- this.wave_grace_period = game.tick + 3600
this.boss_biters = {}
this.acid_lines_delay = {}

View File

@ -35,6 +35,7 @@ local BottomFrame = require 'comfy_panel.bottom_frame'
local Misc = require 'commands.misc'
local Modifiers = require 'player_modifiers'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
local Reset = require 'functions.soft_reset'
require 'maps.mountain_fortress_v3.rocks_yield_ore_veins'
@ -104,7 +105,10 @@ function Public.reset_map()
local this = WPT.get()
local wave_defense_table = WD.get_table()
Reset.enable_mapkeeper(true)
this.active_surface_index = CS.create_surface()
this.soft_reset_counter = CS.get_reset_counter()
Autostash.insert_into_furnace(true)
Autostash.insert_into_wagon(true)

View File

@ -1,7 +1,7 @@
local Global = require 'utils.global'
local surface_name = 'mountain_fortress_v3'
local WPT = require 'maps.mountain_fortress_v3.table'
local Reset = require 'maps.mountain_fortress_v3.soft_reset'
local Reset = require 'functions.soft_reset'
local Public = {}
@ -89,6 +89,8 @@ function Public.create_surface()
this.active_surface_index = Reset.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
end
this.soft_reset_counter = Reset.get_reset_counter()
if not this.cleared_nauvis then
local mgs = game.surfaces['nauvis'].map_gen_settings
mgs.width = 16
@ -101,14 +103,21 @@ function Public.create_surface()
return this.active_surface_index
end
--- Returns the surface index.
function Public.get_active_surface()
return this.active_surface
end
--- Returns the surface name.
function Public.get_surface_name()
return this.surface_name
end
--- Returns the amount of times the server has soft restarted.
function Public.get_reset_counter()
return this.soft_reset_counter
end
function Public.get(key)
if key then
return this[key]

View File

@ -15,15 +15,16 @@ local floor = math.floor
local insert = table.insert
local random = math.random
local sqrt = math.sqrt
local ceil = math.ceil
local round = math.round
local Public = {}
local this = {
biter_health_boost = 1,
biter_health_boost_forced = false,
biter_health_boost_forces = {},
biter_health_boost_units = {},
biter_health_boost_count = 0,
make_normal_unit_mini_bosses = false,
active_surface = 'nauvis',
acid_lines_delay = {},
acid_nova = false,
@ -251,7 +252,7 @@ local function on_entity_damaged(event)
return
end
if not health_pool then
if not health_pool and this.make_normal_unit_mini_bosses then
if this.biter_health_boost_forces[biter.force.index] then
Public.add_unit(biter, this.biter_health_boost_forces[biter.force.index])
else
@ -260,6 +261,10 @@ local function on_entity_damaged(event)
health_pool = this.biter_health_boost_units[unit_number]
end
if not health_pool then
return
end
--Process boss unit health bars
local boss = health_pool[3]
if boss then
@ -360,9 +365,11 @@ end
--- Use this function to reset the global table to it's init values.
function Public.reset_table()
this.biter_health_boost = 1
this.biter_health_boost_forces = false
this.biter_health_boost_forces = {}
this.biter_health_boost_units = {}
this.biter_health_boost_count = 0
this.make_normal_unit_mini_bosses = false
this.active_surface = 'nauvis'
this.check_on_entity_died = false
this.acid_lines_delay = {}
@ -444,6 +451,22 @@ function Public.enable_boss_loot(boolean)
return this.enable_boss_loot
end
--- Forces a value of biter_health_boost
---@param boolean
function Public.enable_biter_health_boost_forced(boolean)
this.biter_health_boost_forced = boolean or false
return this.biter_health_boost_forced
end
--- Enables that normal units have boosted health.
---@param boolean
function Public.enable_make_normal_unit_mini_bosses(boolean)
this.make_normal_unit_mini_bosses = boolean or false
return this.make_normal_unit_mini_bosses
end
Event.on_init(
function()
Public.reset_table()