Ejemplo n.º 1
0
		public string GetFileName(Galaxy galaxy)
		{
			var faction1 = galaxy.GetPlanet(PlanetIDs[0]).FactionName;
			var faction2 = galaxy.GetPlanet(PlanetIDs[1]).FactionName;
			var offensiveFaction = galaxy.OffensiveFaction.Name;
			return GetFileName(galaxy, faction1, faction2, offensiveFaction);
		}
 public LinkImageGenerator(Size mapSize, Galaxy galaxy, string path, ImageFormat imageFormat)
 {
     MapSize = mapSize;
     Galaxy = galaxy;
     ImagePath = path;
     Directory.CreateDirectory(ImagePath);
     ImageFormat = imageFormat;
     Padding = 10;
 }
Ejemplo n.º 3
0
		public void SetUp()
		{
			galaxy = new Galaxy();
			galaxy.Planets.Add(new Planet(0, 0, 0, "barack", "Arm"));
			galaxy.Planets.Add(new Planet(1, 0, 0, "john", "Core"));
			galaxy.Planets.Add(new Planet(2, 0, 0));
			galaxy.Planets.Add(new Planet(3, 0, 0));
			galaxy.Factions.Add(new Faction("Arm", Color.Blue));
		}
Ejemplo n.º 4
0
		public string GetFileName(Galaxy galaxy, string faction1, string faction2, string offensiveFaction)
		{
			return String.Format("{0}_{1}_{2}_{3}_{4}.png",
				PlanetIDs[0],
				PlanetIDs[1],
				faction1??"neutral",
				faction2??"neutral",
				faction1 != faction2 && faction1 != null && faction2 != null 
					? offensiveFaction
					: String.Empty);
		}
 public LinkImageGenerator(Size mapSize, Galaxy galaxy, string path) : this(mapSize, galaxy, path, ImageFormat.Png) {}
		/// <summary>
		/// Loads galaxy from server
		/// </summary>
		/// <param name="all">should get all maps</param>
		/// <param name="worker">should report to background worker</param>
		/// <param name="loadedGalaxy">use this galaxy state</param>
		public static void LoadGalaxy(bool all, BackgroundWorker worker, Galaxy loadedGalaxy)
		{
			if (all && worker == null) {
				throw new ApplicationException("All needs worker");
			}
			Directory.CreateDirectory(Program.CachePath);
			Directory.CreateDirectory(Program.MapInfoCache);
			Directory.CreateDirectory(Program.MetalmapCache);
			Directory.CreateDirectory(Program.HeightmapCache);
			Directory.CreateDirectory(Program.MinimapCache);
			GalaxyMap.Instance = null;
			if (worker != null) {
				worker.ReportProgress(0, new[] {"Connecting"});
			}
			bool done = Program.AuthInfo != null;
			do {
				if (!done) {
					var loginForm = new LoginForm();
					if (DialogResult.OK != loginForm.ShowDialog()) {
						Application.Exit();
					}
					Program.AuthInfo = loginForm.AuthInfo;
				}
				Program.LastUpdate = DateTime.Now;

				GalaxyMap.Instance.Galaxy = loadedGalaxy ?? Program.Server.GetGalaxyMap(Program.AuthInfo);
				// either use loadedgalaxy or get new one
				done = GalaxyMap.Instance.Galaxy != null;
				if (!done) {
					MessageBox.Show("Invalid username or password.");
				}
			} while (!done);
			var galaxyMap = GalaxyMap.Instance;
			var galaxy = galaxyMap.Galaxy;
			galaxy.Planets.ForEach(p => galaxyMap.PlanetDrawings.Add(new PlanetDrawing(p)));

			var q = (from f in galaxy.Factions
			         from p in galaxy.GetAttackOptions(f)
			         select new {p.ID, f});
			galaxyMap.AttackablePlanetIDs = q.ToDictionary(t => t.ID, t => t.f);

			galaxyMap.ClaimablePlanetIDs = galaxy.GetClaimablePlanets().Select(p => p.ID).ToArray();	

			var neededMaps = all
			                 	? galaxy.MapNames.Except(galaxyMap.Maps.Select(m => m.Name))
			                 	: galaxy.Planets.Select(p => p.MapName).Where(n => n != null);
			var mapsToDownload = neededMaps.Where(n => !File.Exists(Program.MapInfoCache.Combine(n + ".dat"))).ToArray();

			int maxProgress = mapsToDownload.Length*4;
			WebClient Client = new WebClient();
			int progress = 0;

			if (worker != null) {
				Action<string, string> MapReport =
					(message, mapName) =>
					worker.ReportProgress(progress++*100/maxProgress, new[] {message + Map.GetHumanName(mapName), mapName});
#if false 
				foreach (var mapName in mapsToDownload) {
					MapReport("Downloading Map Info", mapName);
					Client.DownloadFile(Program.MapInfoUrl + "/" + mapName + ".dat", Program.MapInfoCache.Combine(mapName + ".dat"));


					MapReport("Downloading Minimap", mapName);
					Client.DownloadFile(Program.MinimapUrl + "/" + mapName + ".jpg", Program.MinimapCache.Combine(mapName + ".jpg"));
					MapReport("Downloading Heightmap", mapName);
					Client.DownloadFile(
						Program.HeightmapUrl + "/" + mapName + ".jpg", Program.HeightmapCache.Combine(mapName + ".jpg"));
					MapReport("Downloading Metalmap", mapName);
					Client.DownloadFile(Program.MetalmapUrl + "/" + mapName + ".png", Program.MetalmapCache.Combine(mapName + ".png"));
					worker.ReportProgress(progress*100/maxProgress, mapName);

				}
#endif
			}
		}
		public ICollection<UpgradeDef> GetAvailableUpgrades(Galaxy galaxy, string playerName)
		{
			return s.GetAvailableUpgrades(galaxy, playerName);
		}
Ejemplo n.º 8
0
		public ICollection<UpgradeDef> GetAvailableUpgrades(Galaxy galaxy, string playerName)
		{
			var player = Galaxy.GetPlayer(playerName);
			var availableUpgrades = new List<UpgradeDef>();
			var allUpgrades = new Upgrades().UpgradeDefs;
			foreach (var upgradeDef in allUpgrades) {
				if (upgradeDef.Cost <= player.MetalAvail && upgradeDef.FactionName == player.FactionName) {
					List<UpgradeDef> upgrades;
					if (!UpgradeData.TryGetValue(playerName, out upgrades)) {
						upgrades = new List<UpgradeDef>();
					}

					var lesserUpgrade =
						allUpgrades.Where(
							x =>
							x.FactionName == upgradeDef.FactionName && x.Branch == upgradeDef.Branch && x.Division == upgradeDef.Division &&
							x.Level == upgradeDef.Level - 1).SingleOrDefault();

					var hasLesserUpgrade = lesserUpgrade == null || upgrades.Where(x => x.ID == lesserUpgrade.ID).Any();

					if (hasLesserUpgrade) {
						availableUpgrades.Add(upgradeDef);
					}
				}
			}
			return availableUpgrades;
		}
Ejemplo n.º 9
0
		public Server(Galaxy galaxy)
		{
			Galaxy = galaxy;
		}