private static void ParseSpawnerList(Mobile from, List <DynamicJson> spawners, JsonSerializerOptions options) { var watch = Stopwatch.StartNew(); var failures = new List <string>(); var count = 0; for (var i = 0; i < spawners.Count; i++) { var json = spawners[i]; var type = AssemblyHandler.FindTypeByName(json.Type); if (type == null || !typeof(BaseSpawner).IsAssignableFrom(type)) { var failure = $"GenerateSpawners: Invalid spawner type {json.Type ?? "(-null-)"} ({i})"; if (!failures.Contains(failure)) { failures.Add(failure); from.SendMessage(failure); } continue; } json.GetProperty("location", options, out Point3D location); json.GetProperty("map", options, out Map map); var eable = map.GetItemsInRange <BaseSpawner>(location, 0); if (eable.Any(sp => sp.GetType() == type)) { eable.Free(); continue; } eable.Free(); try { var spawner = type.CreateInstance <ISpawner>(json, options); spawner !.MoveToWorld(location, map); spawner !.Respawn(); } catch (Exception) { var failure = $"GenerateSpawners: Spawner {type} failed to construct"; if (!failures.Contains(failure)) { failures.Add(failure); from.SendMessage(failure); } continue; } count++; } watch.Stop(); from.SendMessage( "GenerateSpawners: Generated {0} spawners ({1:F2} seconds, {2} failures)", count, watch.Elapsed.TotalSeconds, failures.Count ); }
public static Type GetType(string name) => AssemblyHandler.FindTypeByName(name);