public List <MapObject> GetStars() { var db = DataContextFactory.GetAndromedaDataContext(); return(db.Stars.ToList().Select(i => new MapObject() { Name = i.Name, Color = "#999999", X = (int)i.X.Value / 2, Y = (int)i.Y.Value / 2 }) .ToList()); }
private List <LeaderboardItem> GetLeaderboardInternal(int count) { var db = DataContextFactory.GetAndromedaDataContext(); return(db.Players .Where(i => i.IsRunLocationEmulator == false) .Select(i => new LeaderboardItem() { PlayerName = i.PlayerName, NetWorth = i.PlayerMoney.Value + (i.Spaceships.Where(j => j.Deleted == false) .Sum(j => j.CommodityInHolds.Sum(k => k.NetWorth) ?? 0)) }) .OrderByDescending(i => i.NetWorth) .Take(count).ToList()); }
/// <summary> /// This method is called via AJAX. Returns ships to display on map. /// </summary> /// <returns></returns> public List <MapObject> GetShips(string playerGuid) { var db = DataContextFactory.GetAndromedaDataContext(); //Check if the user has a ship //Did we get a valid GUID? Guid?guid; Guid tempGuid; if (Guid.TryParse(playerGuid, out tempGuid)) { guid = tempGuid; } else { guid = null; } //Is there a ship with this GUID? if (guid != null) { if (!db.Spaceships.Any(i => i.PlayerGuid == guid)) { guid = null; } } //Return ships var ships = db.Spaceships.Where(i => i.Deleted == false).ToList(); List <MapObject> mapObjects = new List <MapObject>(); foreach (var i in ships) { var coordinates = i.Coordinates; mapObjects.Add( new MapObject() { Name = Localization.Map_Spaceship + i.Player.PlayerName, Color = (guid != null && i.Player.FirstShipGuid == guid) ? "lightgreen" : "red", //If the Guid is filled (the user has a ship) and this is the player's ship, mark it green, otherwise it's red SensorRange = (guid != null && i.Player.FirstShipGuid == guid) ? i.SensorRangeInLightYears : 0d, CannonRange = (guid != null && i.Player.FirstShipGuid == guid) ? (i.CannonCount ?? 0) * 20d : 0d, X = (int)coordinates.Item1 / 2, Y = (int)coordinates.Item2 / 2 } ); } return(mapObjects); }
public List <MapObject> GetShips() { var db = DataContextFactory.GetAndromedaDataContext(); var ships = db.Spaceships.Where(i => i.Deleted == false).ToList(); List <MapObject> mapObjects = new List <MapObject>(); foreach (var i in ships) { var coordinates = i.Coordinates; mapObjects.Add( new MapObject() { Name = Localization.Map_Spaceship + i.Player.PlayerName, Color = "red", X = (int)coordinates.Item1 / 2, Y = (int)coordinates.Item2 / 2 } ); } return(mapObjects); }
/// <summary> /// Generates ticker string for the specified user and with the specified count. /// If the guid is empty, ticker for all users is returned. /// </summary> /// <returns></returns> private string GetTicker(Guid userGuid, int count) { var db = DataContextFactory.GetAndromedaDataContext(); var lastEvents = db.EventLogEntries.OrderByDescending(i => i.Timestamp) .Where(i => i.Error == "" && (i.EventType == "Launch" || i.EventType == "ShipModification" || i.EventType == "Trade" || i.EventType == "ShipUpgrade" || i.EventType == "PirateRaid" || i.EventType == "ShipPurchase")); if (userGuid != Guid.Empty) { string username = db.Players.Single(i => i.FirstShipGuid == userGuid).PlayerName; lastEvents = lastEvents.Where(i => i.Player == username); } lastEvents = lastEvents.Take(count); string ticker = ""; bool shouldSeparatorBePlaced = lastEvents.Any(i => i.Timestamp > DateTime.Now - TimeSpan.FromSeconds(5)); bool separatorPlacedYet = false; foreach (var evt in lastEvents) { if (shouldSeparatorBePlaced && !separatorPlacedYet && evt.Timestamp <= (DateTime.Now - TimeSpan.FromSeconds(5))) { ticker += "<hr />"; separatorPlacedYet = true; } ticker += string.Format("<b>{0}:{1}:{2}:</b> ", evt.Timestamp.Hour, evt.Timestamp.Minute.ToString().PadLeft(2, '0'), evt.Timestamp.Second.ToString().PadLeft(2, '0')) + ConvertLogToDetailString(evt) + "<br />"; } return(ticker); }
/// <summary> /// If enough time has elapsed since the last increase, increases the stock count for all commodities. /// </summary> public static void IncreaseCommodityQuantities() { #region Log update bool shouldBeLogged = false; bool alreadyLogged = false; StockIncrease logEntry = new StockIncrease() { Guid = Guid.Empty, Player = string.Empty, Timestamp = TimeGetter.GetLocalTime() }; #endregion int exceptionCount = 0; try { if (IncreaseCommodityQuantities_LastRunTime + IncreaseCommodityQuantities_MinimumInterval <= TimeGetter.GetLocalTime()) { #region Log update shouldBeLogged = true; #endregion IncreaseCommodityQuantities_LastRunTime = TimeGetter.GetLocalTime(); var commodityAtStarsIds = db.CommodityAtStars.ToList().Select(i => new { i.Id }); //Increase all commodities //All done in separate data contexts to help successfully continue after an optimistic concurrency exception foreach (var commodityAtStarId in commodityAtStarsIds) { try { using (var db2 = DataContextFactory.GetAndromedaDataContext()) { var commodityAtStar = db2.CommodityAtStars.Single(i => i.Id == commodityAtStarId.Id); if (commodityAtStar.Stock.Value + commodityAtStar.ProductionRate.Value > commodityAtStar.MaxCapacity) { commodityAtStar.Stock = commodityAtStar.MaxCapacity; } else { commodityAtStar.Stock += commodityAtStar.ProductionRate.Value; } db2.SubmitChanges(); } } catch { exceptionCount++; } } } } catch (Exception ex) { #region Log update if (shouldBeLogged) { logEntry.Error = ex.ToString(); Logger.Log(logEntry); alreadyLogged = true; } throw ex; #endregion } finally { #region Log update if (shouldBeLogged && !alreadyLogged) { logEntry.Error = exceptionCount.ToString() + " exceptions"; Logger.Log(logEntry); } #endregion } }
/// <summary> /// Generates pilot status string. /// </summary> /// <returns></returns> private string GetPilotStatus(string playerGuid) { var db = DataContextFactory.GetAndromedaDataContext(); //Check if the user has a ship //Did we get a valid GUID? Guid?guid; Guid tempGuid; if (Guid.TryParse(playerGuid, out tempGuid)) { guid = tempGuid; } else { guid = null; } //Is there a ship with this GUID? if (guid != null) { if (!db.Spaceships.Any(i => i.PlayerGuid == guid)) { guid = null; } } //Return if the guid was invalid or if there was no ship found if (guid == null) { return(""); } //Generate value string result = ""; var player = db.Players.Single(i => i.FirstShipGuid == guid); NumberFormatInfo nfi = new NumberFormatInfo() { NumberDecimalDigits = 0, NumberGroupSeparator = "." }; result += string.Format(Localization.FleetInfo_ShipsAndCredits, player.PlayerMoney.Value.ToString("N", nfi), player.Spaceships.Count); result += "<br />"; int shipIndex = 0; foreach (var spaceship in player.Spaceships) { shipIndex++; result += string.Format(Localization.FleetInfo_ShipN, shipIndex); spaceship.UpdateTravelStatus(); string travelStatus; if (spaceship.IsInTransit) { var currentStar = db.Stars.Single(i => i.Id == spaceship.CurrentStarId.Value); var targetStar = db.Stars.Single(i => i.Id == spaceship.TargetStarId.Value); var coordinates = spaceship.Coordinates; travelStatus = string.Format(Localization.FleetInfo_ShipEnRoute, currentStar.Name, targetStar.Name, DistanceCalculator.GetDistance(currentStar.X.Value, currentStar.Y.Value, targetStar.X.Value, targetStar.Y.Value).ToString("0.0"), DistanceCalculator.GetDistance(targetStar.X.Value, targetStar.Y.Value, coordinates.Item1, coordinates.Item2).ToString("0.0")); } else { travelStatus = string.Format(Localization.FleetInfo_ShipInPort, db.Stars.Single(i => i.Id == spaceship.CurrentStarId.Value).Name); } string hardwareStatus = string.Format(Localization.FleetInfo_Hardware, spaceship.FreeCapacity, spaceship.TotalCapacity, spaceship.SpeedInLightYearsPerMinute, spaceship.SensorRangeInLightYears, spaceship.DriveCount, spaceship.SensorCount, spaceship.CannonCount, spaceship.ShieldCount); if (spaceship.SensorCount > 0 || spaceship.DriveCount > 0 || spaceship.CannonCount > 0 || spaceship.ShieldCount > 0) { hardwareStatus += string.Format(Localization.FleetInfo_SpaceOccupiedByComponents, spaceship.DriveCount * Constants.DriveCostInCapacity + spaceship.SensorCount * Constants.SensorCostInCapacity + spaceship.CannonCount * Constants.CannonCostInCapacity + spaceship.ShieldCount * Constants.ShieldCostInCapacity); } string cargoStatus; if (spaceship.CommodityInHolds.Count == 0) { cargoStatus = string.Format(Localization.FleetInfo_NoCargo); } else { string cargoInHold = ""; foreach (var cargo in spaceship.CommodityInHolds) { cargoInHold += string.Format(Localization.FleetInfo_CargoItem, cargo.Commodity.Name, cargo.Count); } cargoStatus = string.Format(Localization.FleetInfo_CargoHeader, cargoInHold); } //This string does not need localization result += string.Format("{0}<br /><br />{1}<br /><br />{2}", travelStatus, hardwareStatus, cargoStatus); } return(result); }