You've already forked ComfyFactorio
							
							
				mirror of
				https://github.com/ComfyFactory/ComfyFactorio.git
				synced 2025-10-30 23:47:41 +02:00 
			
		
		
		
	Fix wrong event handling
This commit is contained in:
		| @@ -51,9 +51,7 @@ std = STD_CONTROL | ||||
| globals = { | ||||
|     'print', | ||||
|     '_DEBUG', | ||||
|     '_DEBUG_HALT_ON_ERR', | ||||
|     '_PROFILE', | ||||
|     '_PROFILE_ON_INIT', | ||||
|     '_CHEATS', | ||||
|     '_DUMP_ENV', | ||||
|     'ServerCommands', | ||||
|   | ||||
| @@ -3,6 +3,7 @@ local Event = require 'utils.event' | ||||
| local WD = require 'modules.wave_defense.table' | ||||
| local Beam = require 'modules.render_beam' | ||||
| local RPG = require 'modules.rpg.main' | ||||
| local BiterHealthBooster = require 'modules.biter_health_booster_v2' | ||||
|  | ||||
| Public.stateful_gui = require 'maps.mountain_fortress_v3.stateful.gui' | ||||
| Public.stateful_blueprints = require 'maps.mountain_fortress_v3.stateful.blueprints' | ||||
| @@ -10,6 +11,42 @@ Public.stateful_blueprints = require 'maps.mountain_fortress_v3.stateful.bluepri | ||||
| local random = math.random | ||||
| local shuffle = table.shuffle_table | ||||
|  | ||||
| local valid_types = { | ||||
|     ['unit'] = true, | ||||
|     ['turret'] = true | ||||
| } | ||||
|  | ||||
| ---@param event EventData.on_entity_died | ||||
| local function on_entity_died(event) | ||||
|     local entity = event.entity | ||||
|     if not entity or not entity.valid then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     if not Public.valid_enemy_forces[entity.force.name] then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     local objectives = Public.get_stateful('objectives') | ||||
|  | ||||
|     local damage_type = event.damage_type | ||||
|     if not damage_type then | ||||
|         return | ||||
|     end | ||||
|     local killed_enemies = objectives.killed_enemies_type | ||||
|     if not killed_enemies then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     if killed_enemies.damage_type ~= damage_type.name then | ||||
|         return | ||||
|     end | ||||
|  | ||||
|     if valid_types[entity.type] then | ||||
|         killed_enemies.actual = killed_enemies.actual + 1 | ||||
|     end | ||||
| end | ||||
|  | ||||
| Event.add( | ||||
|     defines.events.on_research_finished, | ||||
|     function(event) | ||||
| @@ -145,39 +182,6 @@ Event.add( | ||||
|     end | ||||
| ) | ||||
|  | ||||
| Event.add( | ||||
|     defines.events.on_entity_died, | ||||
|     function(event) | ||||
|         local entity = event.entity | ||||
|         if not entity or not entity.valid then | ||||
|             return | ||||
|         end | ||||
|  | ||||
|         if not Public.valid_enemy_forces[entity.force.name] then | ||||
|             return | ||||
|         end | ||||
|  | ||||
|         local objectives = Public.get_stateful('objectives') | ||||
|  | ||||
|         local damage_type = event.damage_type | ||||
|         if not damage_type then | ||||
|             return | ||||
|         end | ||||
|         local killed_enemies = objectives.killed_enemies_type | ||||
|         if not killed_enemies then | ||||
|             return | ||||
|         end | ||||
|  | ||||
|         if killed_enemies.damage_type ~= damage_type.name then | ||||
|             return | ||||
|         end | ||||
|  | ||||
|         if entity.type == 'unit' then | ||||
|             killed_enemies.actual = killed_enemies.actual + 1 | ||||
|         end | ||||
|     end | ||||
| ) | ||||
|  | ||||
| Event.add( | ||||
|     defines.events.on_rocket_launched, | ||||
|     function(event) | ||||
| @@ -262,5 +266,7 @@ Event.on_nth_tick( | ||||
|  | ||||
| Event.add(defines.events.on_pre_player_died, Public.on_pre_player_died) | ||||
| Event.add(Public.events.on_market_item_purchased, Public.on_market_item_purchased) | ||||
| Event.add(BiterHealthBooster.events.custom_on_entity_died, on_entity_died) | ||||
| Event.add(defines.events.on_entity_died, on_entity_died) | ||||
|  | ||||
| return Public | ||||
|   | ||||
| @@ -18,6 +18,10 @@ local sqrt = math.sqrt | ||||
| local round = math.round | ||||
| local Public = {} | ||||
|  | ||||
| Public.events = { | ||||
|     custom_on_entity_died = Event.generate_event_name('custom_on_entity_died') | ||||
| } | ||||
|  | ||||
| local this = { | ||||
|     biter_health_boost = 1, | ||||
|     biter_health_boost_forced = false, | ||||
| @@ -268,6 +272,7 @@ local function extra_projectiles(cause, target) | ||||
|     end | ||||
| end | ||||
|  | ||||
| ---@param event EventData.on_entity_damaged | ||||
| local function on_entity_damaged(event) | ||||
|     local biter = event.entity | ||||
|     if not (biter and biter.valid) then | ||||
| @@ -350,10 +355,13 @@ local function on_entity_damaged(event) | ||||
|  | ||||
|     if cause then | ||||
|         if cause.valid then | ||||
|             Event.raise(Public.events.custom_on_entity_died, event) | ||||
|             event.entity.die(cause.force, cause) | ||||
|             return | ||||
|         end | ||||
|     end | ||||
|  | ||||
|     Event.raise(Public.events.custom_on_entity_died, event) | ||||
|     biter.die(biter.force) | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -25,7 +25,7 @@ end | ||||
|  | ||||
| local function call_handlers(handlers, event) | ||||
|     for i = 1, #handlers do | ||||
|         if _DEBUG_HALT_ON_ERR then | ||||
|         if _DEBUG then | ||||
|             local handler = handlers[i] | ||||
|             handler(event) | ||||
|         else | ||||
|   | ||||
| @@ -252,7 +252,7 @@ if (debug.sethook) then | ||||
|     end | ||||
|     ignored_functions[Public.stop] = true | ||||
|  | ||||
|     if _PROFILE and _PROFILE_ON_INIT then | ||||
|     if _PROFILE then | ||||
|         Event.on_init( | ||||
|             function() | ||||
|                 game.print('[PROFILER] Started!') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user