/// <summary> /// Reads the sectors of this map. /// </summary> /// <param name="mapDirectory">The main map directory.</param> /// <param name="sectors">If set, only the given sectors will be loaded.</param> private void ReadSectors(string mapDirectory, string[] sectors = null) { var baseFiles = Directory.GetFiles(mapDirectory, "*.base"); // create itemless instances for all the sectors first; // this is so we have references to the sectors // before we read them to deal with sectors containing // nodes from other sectors foreach (var baseFile in baseFiles) { if (!SectorShouldBeLoaded(baseFile)) { continue; } var sector = new Sector(baseFile, this); Sectors.Add((sector.X, sector.Z), sector); } var sectorList = Sectors.ToList(); foreach (var sectorKvp in sectorList) { Trace.WriteLine($"Reading sector {sectorKvp.Value.ToString()}"); sectorKvp.Value.Read(); } bool SectorShouldBeLoaded(string baseFile) => sectors == null || sectors.Contains(Path.GetFileName(baseFile)); }
public Tower ActivateRandom(string activator = "XANA") { Random random = new Random(); var possibleSectors = Sectors.Where(sector => sector.Towers.Any()) .Where(sector => sector.Towers.Any(tower => !tower.Activated)).ToList(); if (!possibleSectors.Any()) { return(null); } int number = random.Next(possibleSectors.Count); var chosenSector = Sectors.ToList()[number]; return(chosenSector.ActivateRandom(activator)); }