/// <summary> /// Loads the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns>The collection of spawn sources.</returns> private IEnumerable <SpawnSource> Load(string fileName) { XDocument document = XDocument.Load(fileName); if (!(document.Element("spawns") is XElement spawnsElement)) { throw new ArgumentNullException(nameof(spawnsElement)); } foreach (XElement element in spawnsElement.Elements("spawn")) { SpawnSource spawnSource = new SpawnSource(); spawnSource.CenterPosition = ParseCenterPosition(element); spawnSource.Radius = ParseRadius(element); foreach (XElement monsterElement in element.Elements("monster")) { IMonster monster = _monsterService.GetMonsterByUniqueName(ParseName(monsterElement)); MonsterSpawnSettings monsterSpawnSettings = new MonsterSpawnSettings(); monsterSpawnSettings.Monster = monster; monsterSpawnSettings.AbsolutePosition = ParseAbsolutePosition(spawnSource.CenterPosition, monsterElement); monsterSpawnSettings.SpawnSource = spawnSource; spawnSource.Spawns.Add(monsterSpawnSettings); } foreach (XElement npcElement in element.Elements("npc")) { foreach (INpc npc in _npcService.GetNpcsByName(ParseName(npcElement))) { NpcSpawnSettings npcSpawnSettings = new NpcSpawnSettings(); npcSpawnSettings.Npc = npc; npcSpawnSettings.AbsolutePosition = ParseAbsolutePosition(spawnSource.CenterPosition, npcElement); npcSpawnSettings.SpawnSource = spawnSource; spawnSource.Spawns.Add(npcSpawnSettings); } } yield return(spawnSource); } }