private int UpdateScripts(PlayfieldScriptData playfieldData, Func <PlayfieldScriptData, IEntity, int> process, string name) { try { if (playfieldData.Playfield == null) { ModApi.Log($"UpdateScripts no Playfield"); return(0); } if (playfieldData.Playfield.Entities == null) { ModApi.Log($"UpdateScripts no Entities"); return(0); } var timer = new Stopwatch(); timer.Start(); playfieldData.AllEntities = playfieldData.Playfield.Entities.Values.ToArray(); playfieldData.CurrentEntities = playfieldData.AllEntities .Where(E => E.Type == EntityType.BA || E.Type == EntityType.CV || E.Type == EntityType.SV || E.Type == EntityType.HV) .ToArray(); Log($"CurrentEntities: {playfieldData.CurrentEntities.Length}", LogLevel.Debug); playfieldData.EntityCultureInfo.Clear(); int count = 0; playfieldData.CurrentEntities.ForEach(E => count += process(playfieldData, E)); timer.Stop(); if (timer.Elapsed.TotalSeconds > 30) { Log($"UpdateScripts: {name} RUNS {timer.Elapsed} !!!!", LogLevel.Message); } else { Log($"UpdateScripts: {name} take {timer.Elapsed}", LogLevel.Debug); } return(count); } catch (Exception error) { ModApi.LogWarning("Next try because: " + ErrorFilter(error)); return(0); } }