void RenderFleet(SpaceFleet f, int x, int y, StringBuilder web, StringBuilder js) { fleetId++; string img = string.Format( "img/fleets/{0}{1}.png", Globals.Galaxy.GetPlayer(f.OwnerName).FactionName, Globals.Galaxy.Turn >= f.Arrives ? "_orbit" : ""); web.AppendFormat( "<img id='f{0}' src='{3}' style='position:absolute;z-index:4;left:{1}px;top:{2}px;'>", fleetId, x, y, img); js.AppendFormat( "PW.AddTooltip('f{0}', '<div class=\"popup\">{1}</div>', null);\n", fleetId, f.GetHumanReadableEta(Globals.Galaxy).Replace("\n", "<br/>")); if (f.Arrives > Globals.Galaxy.Turn) { PointF curPos; f.GetCurrentPosition(out curPos, Globals.Galaxy.Turn); js.AppendFormat( "PW.graphics.DrawLine({0},{1},{2},{3}, 1);\n", ToScreenX(curPos.X), ToScreenY(curPos.Y), ToScreenX(f.Destination.X), ToScreenY(f.Destination.Y)); } }
void RenderFleet(SpaceFleet f, int x, int y, StringBuilder web, StringBuilder js) { fleetId++; string img = string.Format( "img/fleets/{0}{1}.png", Globals.Galaxy.GetPlayer(f.OwnerName).FactionName, Globals.Galaxy.Turn >= f.Arrives ? "_orbit" : ""); web.AppendFormat( "<img id='f{0}' src='{3}' style='position:absolute;z-index:4;left:{1}px;top:{2}px;'>", fleetId, x, y, img); js.AppendFormat( "PW.AddTooltip('f{0}', '<div class=\"popup\">{1}</div>', null);\n", fleetId, f.GetHumanReadableEta(Globals.Galaxy).Replace("\n", "<br/>")); if (f.Arrives > Globals.Galaxy.Turn) { PointF curPos; f.GetCurrentPosition(out curPos, Globals.Galaxy.Turn); js.AppendFormat( "PW.graphics.DrawLine({0},{1},{2},{3}, 1);\n", ToScreenX(curPos.X), ToScreenY(curPos.Y), ToScreenX(f.Destination.X), ToScreenY(f.Destination.Y)); } }
public void BuyUpgrade(AuthInfo login, int upgradeDefID, string choice) { if (!ValidateLogin(login)) { throw new Exception("Login failed"); } var udef = new Upgrades().UpgradeDefs.Where(x => x.ID == upgradeDefID).SingleOrDefault(); if (udef == null || !udef.UnitDefs.Where(x => x.Name == choice).Any()) { throw new Exception("No such upgrade definition found"); } // remove upgrade of same level or id if it already exists List<UpgradeDef> existing; if (UpgradeData.TryGetValue(login.Login, out existing)) { var todel = existing.Where( x => x.ID == upgradeDefID || x.Level == udef.Level && x.Branch == udef.Branch && x.Division == udef.Division). ToList(); foreach (var x in todel) { existing.Remove(x); } } var copy = udef.BuyCopy(); copy.UnitChoice = choice; var player = Galaxy.GetPlayer(login.Login); if (copy.IsSpaceShip) { var planet = Galaxy.GetPlanet(player.Name); Planet targetPlanet = null; if (planet != null && planet.FactionName == player.FactionName) { targetPlanet = planet; } else { targetPlanet = Galaxy.Planets.Where(x => x.FactionName == player.FactionName).OrderBy( x => Galaxy.GetPlayer(x.OwnerName).RankOrder).FirstOrDefault(); } if (targetPlanet == null) { throw new Exception("Cannot find suitable planet for the fleet"); } var fleet = new SpaceFleet {TargetPlanetID = targetPlanet.ID, Destination = targetPlanet.Position, OwnerName = player.Name}; Galaxy.Fleets.Add(fleet); copy.Purchased++; } if (existing == null) { existing = new List<UpgradeDef>(); } existing.Add(copy); player.PurchaseHistory.Add(new PurchaseData(upgradeDefID, choice)); UpgradeData[login.Login] = existing; Galaxy.GetPlayer(login.Login).MetalSpent += copy.Cost; SaveState(); }