From f39f0ea7675607ce8c5590279383350050b0c1ee Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Thu, 1 Jun 2023 00:53:10 +0200 Subject: [PATCH] WD and Mtn v3 - fix weird bug and adjust aoe punch --- maps/mountain_fortress_v3/functions.lua | 16 ++++- modules/rpg/functions.lua | 42 ++++++------ modules/rpg/main.lua | 13 ++-- modules/wave_defense/commands.lua | 14 ++-- modules/wave_defense/enemy_states.lua | 86 +++++++++++++++++++------ modules/wave_defense/main.lua | 20 +++++- 6 files changed, 134 insertions(+), 57 deletions(-) diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index bee90abe..60d50569 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1394,7 +1394,13 @@ function Public.on_player_joined_game(event) -- end if player.surface.index ~= active_surface_index then - player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5), surface) + local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5) + if pos then + player.teleport(pos, surface) + else + pos = game.forces.player.get_spawn_position(surface) + player.teleport(pos, surface) + end else local p = {x = player.position.x, y = player.position.y} local get_tile = surface.get_tile(p) @@ -1415,7 +1421,13 @@ function Public.on_player_joined_game(event) return end if player.position.y > locomotive.position.y then - player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5), surface) + local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5) + if pos then + player.teleport(pos, surface) + else + pos = game.forces.player.get_spawn_position(surface) + player.teleport(pos, surface) + end end end diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index ef14071f..9999a3ac 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -166,7 +166,7 @@ local function level_up(player) Public.level_up_effects(player) end -local function has_health_boost(entity, damage, final_damage_amount, cause, callback_func) +local function has_health_boost(entity, damage, final_damage_amount, cause) local biter_health_boost = BiterHealthBooster.get('biter_health_boost') local biter_health_boost_units = BiterHealthBooster.get('biter_health_boost_units') @@ -194,9 +194,7 @@ local function has_health_boost(entity, damage, final_damage_amount, cause, call if health_pool[1] <= 0 then local entity_number = entity.unit_number - if not callback_func then - entity.die(entity.force.name, cause) - end + entity.die(entity.force.name, cause) if biter_health_boost_units[entity_number] then biter_health_boost_units[entity_number] = nil @@ -206,9 +204,7 @@ local function has_health_boost(entity, damage, final_damage_amount, cause, call entity.health = entity.health + final_damage_amount entity.health = entity.health - damage if entity.health <= 0 then - if not callback_func then - entity.die(cause.force.name, cause) - end + entity.die(cause.force.name, cause) end end else @@ -216,9 +212,7 @@ local function has_health_boost(entity, damage, final_damage_amount, cause, call entity.health = entity.health + final_damage_amount entity.health = entity.health - damage if entity.health <= 0 then - if not callback_func then - entity.die(cause.force.name, cause) - end + entity.die(cause.force.name, cause) end end @@ -648,18 +642,25 @@ function Public.log_aoe_punch(callback) end --Melee damage modifier -function Public.aoe_punch(entity, target, damage, get_health_pool) - if not (target and target.valid) then +function Public.aoe_punch(cause, entity, damage, final_damage_amount) + if not (entity and entity.valid) then + return + end + if not (cause and cause.valid) then return end - local base_vector = {target.position.x - entity.position.x, target.position.y - entity.position.y} + local ent_position = entity.position + + local get_health_pool = has_health_boost(entity, damage, final_damage_amount, cause) + + local base_vector = {ent_position.x - cause.position.x, ent_position.y - cause.position.y} local vector = {base_vector[1], base_vector[2]} vector[1] = vector[1] * 1000 vector[2] = vector[2] * 1000 - entity.surface.create_entity({name = 'blood-explosion-huge', position = target.position}) + cause.surface.create_entity({name = 'blood-explosion-huge', position = ent_position}) if abs(vector[1]) > abs(vector[2]) then local d = abs(vector[1]) @@ -684,8 +685,8 @@ function Public.aoe_punch(entity, target, damage, get_health_pool) local a = 0.20 - local cs = entity.surface - local cp = entity.position + local cs = cause.surface + local cp = cause.position for i = 1, 16, 1 do for x = i * -1 * a, i * a, 1 do @@ -696,7 +697,7 @@ function Public.aoe_punch(entity, target, damage, get_health_pool) if e.valid then if e.health then if e.destructible and e.minable and e.force.index ~= 3 then - if e.force.index ~= entity.force.index then + if e.force.index ~= cause.force.index then if get_health_pool then local max_unit_health = floor(get_health_pool * 0.00015) if max_unit_health <= 0 then @@ -706,15 +707,12 @@ function Public.aoe_punch(entity, target, damage, get_health_pool) max_unit_health = 10 end local final = floor(damage * max_unit_health) - set_health_boost(e, final, entity) - if e.valid and e.health <= 0 and get_health_pool <= 0 then - e.die(e.force.name, entity) - end + set_health_boost(e, final, cause) else if e.valid then e.health = e.health - damage * 0.05 if e.health <= 0 then - e.die(e.force.name, entity) + e.die(e.force.name, cause) end end end diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 9262ff39..eb0a7686 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -519,7 +519,10 @@ local function on_entity_damaged(event) ) end - local get_health_pool = Public.has_health_boost(entity, damage, final_damage_amount, cause, true) + local is_explosive_bullets_enabled = Public.get_explosive_bullets() + if is_explosive_bullets_enabled then + Public.explosive_bullets(event) + end --Cause a one punch. if enable_aoe_punch then @@ -537,16 +540,14 @@ local function on_entity_damaged(event) end ) if success then - Public.aoe_punch(cause, entity, damage, get_health_pool) -- only kill the biters if their health is below or equal to zero + Public.aoe_punch(cause, entity, damage, final_damage_amount) -- only kill the biters if their health is below or equal to zero return end end end - local is_explosive_bullets_enabled = Public.get_explosive_bullets() - if is_explosive_bullets_enabled then - Public.explosive_bullets(event) - end + --Handle vanilla damage. + Public.has_health_boost(entity, damage, final_damage_amount, cause) end local function on_player_repaired_entity(event) diff --git a/modules/wave_defense/commands.lua b/modules/wave_defense/commands.lua index 4810cde1..ab2ec471 100644 --- a/modules/wave_defense/commands.lua +++ b/modules/wave_defense/commands.lua @@ -34,20 +34,26 @@ commands.add_command( return end - if param == 'spawn_wave' then + if param == 'toggle_es_boss' then + Public.set_track_bosses_only() + p(module_name .. ' ES bosses has been toggled!') + return + end + + if param == 'spawn' then Public.spawn_unit_group(true, true) p(module_name .. ' wave spawned!') return end - if param == 'next_wave' then + if param == 'next' then Public.set_next_wave() Public.spawn_unit_group(true, true) p(module_name .. ' wave spawned!') return end - if param == 'set_next_50' then + if param == 'next_50' then for _ = 1, 50 do Public.set_next_wave() end @@ -56,7 +62,7 @@ commands.add_command( return end - if param == 'set_wave_1500' then + if param == 'next_1500' then for _ = 1, 1500 do Public.set_next_wave() end diff --git a/modules/wave_defense/enemy_states.lua b/modules/wave_defense/enemy_states.lua index 6245aeca..a3377615 100644 --- a/modules/wave_defense/enemy_states.lua +++ b/modules/wave_defense/enemy_states.lua @@ -13,7 +13,6 @@ local random = math.random local abs = math.abs local floor = math.floor local set_timeout_in_ticks = Task.set_timeout_in_ticks -local deepcopy = table.deepcopy local this = { states = {}, @@ -22,7 +21,8 @@ local this = { frenzy_length = 3600, frenzy_burst_length = 160, update_rate = 60, - enabled = false + enabled = true, + track_bosses_only = true }, target_settings = {} } @@ -385,7 +385,7 @@ local function on_init() this.state_count = 0 this.settings.frenzy_length = 3600 this.settings.frenzy_burst_length = 160 - this.settings.update_rate = 60 + this.settings.update_rate = 120 this.target_settings = {} set_forces() @@ -420,6 +420,10 @@ local function on_unit_group_created(event) return end + if not this.settings.enabled_ug then + return + end + local unit_group = event.unit_group if not unit_group or not unit_group.valid then return @@ -483,14 +487,19 @@ local function on_entity_created(event) local data = { entity = entity } - state = Public.new(data) - state:set_burst_frenzy() - if event.boss_unit then - state:set_boss() - end - else - if event.boss_unit then - state:set_boss() + + if this.settings.track_bosses_only then + if event.boss_unit then + state = Public.new(data) + state:set_burst_frenzy() + state:set_boss() + end + else + state = Public.new(data) + state:set_burst_frenzy() + if event.boss_unit then + state:set_boss() + end end end end @@ -507,6 +516,10 @@ local function on_evolution_factor_changed(event) local forces = game.forces + if forces.aggressors.evolution_factor == 1 and evolution_factor == 1 then + return + end + forces.aggressors.evolution_factor = evolution_factor forces.aggressors_frenzy.evolution_factor = evolution_factor end @@ -882,16 +895,13 @@ function Public._esp:attack_target() return end - local compound_commands = deepcopy(this.target_settings.commands) + local compound_commands = this.target_settings.commands if not orders then - self:find_targets() self.moving_to_attack_target = tick + 200 orders = self.moving_to_attack_target if self.commands and next(self.commands) then - for _, entry in pairs(self.commands) do - compound_commands[#compound_commands + 1] = entry - end + compound_commands = self.commands end local command = { type = defines.command.compound, @@ -902,12 +912,9 @@ function Public._esp:attack_target() end if tick > orders then - self:find_targets() self.moving_to_attack_target = tick + 200 if self.commands and next(self.commands) then - for _, entry in pairs(self.commands) do - compound_commands[#compound_commands + 1] = entry - end + compound_commands = self.commands end local command = { @@ -1012,6 +1019,8 @@ function Public._esp:work(tick) self:spew_damage() elseif random(1, 30) == 1 then self:set_burst_frenzy() + elseif random(1, 40) == 1 then + self:find_targets() elseif random(1, 50) == 1 then self:fire_projectile() elseif random(1, 60) == 1 then @@ -1026,7 +1035,9 @@ function Public._esp:work(tick) end end elseif tick < self.ttl then - if random(1, 40) == 1 then + if random(1, 30) == 1 then + self:find_targets() + elseif random(1, 40) == 1 then self:spew_damage() elseif random(1, 50) == 1 then self:set_burst_frenzy() @@ -1043,6 +1054,10 @@ Public.set_module_status = function() this.settings.enabled = not this.settings.enabled end +Public.set_track_bosses_only = function() + this.settings.track_bosses_only = not this.settings.track_bosses_only +end + Event.on_init(on_init) Event.add(de.on_entity_died, on_entity_died) Event.add(de.on_entity_damaged, on_entity_damaged) @@ -1053,4 +1068,33 @@ Event.add(ev.on_target_aquired, on_target_aquired) Event.add(ev.on_evolution_factor_changed, on_evolution_factor_changed) Event.add(ev.on_game_reset, on_init) +--- This gets values from our table +-- @param key +function Public.get_es(key) + if key then + return this[key] + else + return this + end +end + +--- This sets values to our table +-- use with caution. +-- @param key +-- @param value +function Public.set_es(key, value) + if key and (value or value == false or value == 'nil') then + if value == 'nil' then + this[key] = nil + else + this[key] = value + end + return this[key] + elseif key then + return this[key] + else + return this + end +end + return Public diff --git a/modules/wave_defense/main.lua b/modules/wave_defense/main.lua index 244fecc2..3fc82c89 100644 --- a/modules/wave_defense/main.lua +++ b/modules/wave_defense/main.lua @@ -393,6 +393,7 @@ local function set_enemy_evolution() local threat = Public.get('threat') local evolution_factor = wave_number * 0.001 local enemy = game.forces.enemy + local biter_health_boost = 1 if evolution_factor > 1 then @@ -414,6 +415,7 @@ local function set_enemy_evolution() end enemy.evolution_factor = evolution_factor + raise(Public.events.on_evolution_factor_changed, {evolution_factor = evolution_factor}) end @@ -506,7 +508,14 @@ local function spawn_biter(surface, position, forceSpawn, is_boss_biter, unit_se position = old_position end - local biter = surface.create_entity({name = name, position = position, force = 'enemy'}) + local force = 'enemy' + local es_settings = Public.get_es('settings') + + if es_settings.enabled then + force = 'aggressors' + end + + local biter = surface.create_entity({name = name, position = position, force = force}) biter.ai_settings.allow_destroy_when_commands_fail = true biter.ai_settings.allow_try_return_to_spawner = false biter.ai_settings.do_separation = true @@ -1056,8 +1065,15 @@ local function spawn_unit_group(fs, only_bosses) local event_data = {} + local es_settings = Public.get_es('settings') + + local force = 'enemy' + if es_settings.enabled then + force = 'aggressors' + end + local generated_units = Public.get('generated_units') - local unit_group = surface.create_unit_group({position = spawn_position, force = 'enemy'}) + local unit_group = surface.create_unit_group({position = spawn_position, force = force}) event_data.unit_group = unit_group