public static PlanetDetail AddResearchQueue(BuildingQue buildingQue) { PlanetDetail pl = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID); AllbuildQues BuildingsQueLeft = PlanetBLL.GetBuildingQueue(buildingQue.PlanetID, buildingQue.UserID); DateTime UTC = DateTime.UtcNow; BuildingQue bq = new BuildingQue(); bq.BuildingID = buildingQue.BuildingID; bq.PlanetID = buildingQue.PlanetID; bq.Seconds = buildingQue.Seconds; bq.UserID = buildingQue.UserID; bq.MaterialCost = 0; bq.Type = 2; DateTime?maxCompletetionDate = BuildingsQueLeft.researchQue.FindAll(x => x.Type == 2).Max(x => x.CompletetionDate); if (maxCompletetionDate.HasValue) { bq.CompletetionDate = maxCompletetionDate.Value.AddSeconds(buildingQue.Seconds.Value); } else { bq.CompletetionDate = UTC.AddSeconds(buildingQue.Seconds.Value); } PlanetDAL.AddBuildingQue(bq); return(pl); }
private ContainerPlanetFormViewModel(Planet planet, PlanetDetail planetDetail, FileManager fileManager, IEnumerable<ClimateZoneViewModel> climates, IEnumerable<SurfaceMorphologyViewModel> terrains) { PlanetFormViewModel = new PlanetFormViewModel(planet); PlanetDetailFormViewModel = new PlanetDetailFormViewModel(planetDetail); PlanetAssets = new PlanetAssetsFormViewModel(planet, fileManager); Climates = climates; Terrains = terrains; }
public static List <PlanetDetail> GetPlanetList(int?UserID) { if (!UserID.HasValue) { throw new ArgumentNullException("UserID", $"UserID cannot be null."); } List <PlanetDetail> planets = new List <PlanetDetail>(); using (SqlConnection sqlConn = DatabaseHelper.GetConnection()) using (SqlCommand DBCmd = new SqlCommand("dbo.GetPlanetList", sqlConn)) { SqlDataReader sqlReader = default(SqlDataReader); DBCmd.CommandType = CommandType.StoredProcedure; DBCmd.Parameters.AddWithValue("@UserID", (int)UserID); sqlConn.Open(); sqlReader = DBCmd.ExecuteReader(CommandBehavior.CloseConnection); while (sqlReader.Read()) { PlanetDetail planet = new PlanetDetail(); planet.PlanetID = sqlReader.GetInt32Nullable("PlanetID"); planet.PlanetName = sqlReader.GetStringNullable("PlanetName"); planet.PlanetType = sqlReader.GetInt32Nullable("PlanetType"); planet.Galaxy = sqlReader.GetInt32Nullable("Galaxy"); planet.Sector = sqlReader.GetStringNullable("Sector"); planet.System = sqlReader.GetInt32Nullable("System"); planet.XSysPosition = sqlReader.GetInt32Nullable("XSysPosition"); planet.YSysPosition = sqlReader.GetInt32Nullable("YSysPosition"); planet.Moon = sqlReader.GetBooleanNullable("Moon"); planet.Owner = sqlReader.GetInt32Nullable("Owner"); planet.Materials = sqlReader.GetDoubleNullable("Materials"); planet.Population = sqlReader.GetInt32Nullable("Population"); planet.Military = sqlReader.GetInt32Nullable("Military"); planet.InfrastructurePop = sqlReader.GetInt32Nullable("InfrastructurePop"); planet.InfrastructurePopMetal = sqlReader.GetInt32Nullable("InfrastructurePopMetal"); planet.EnergyPop = sqlReader.GetInt32Nullable("EnergyPop"); planet.MetalsPop = sqlReader.GetInt32Nullable("MetalsPop"); planet.ResearchPop = sqlReader.GetInt32Nullable("ResearchPop"); planet.FoodPop = sqlReader.GetInt32Nullable("FoodPop"); planet.Barren = sqlReader.GetBooleanNullable("Barren"); planet.ptEnergy = sqlReader.GetDoubleNullable("ptEnergy"); planet.ptFood = sqlReader.GetDoubleNullable("ptFood"); planet.ptInfrastructure = sqlReader.GetDoubleNullable("ptInfrastructure"); planet.ptMining = sqlReader.GetDoubleNullable("ptMining"); planet.ptResearch = sqlReader.GetDoubleNullable("ptResearch"); planet.TypeName = sqlReader.GetStringNullable("TypeName"); planet.LastHarvest = sqlReader.GetDateTimeNullable("LastHarvest"); planet.LastPopChange = sqlReader.GetDateTimeNullable("LastPopChange"); planets.Add(planet); } return(planets); } }
public IHttpActionResult UpdatePlanetPop([FromBody] PlanetDetail planetDetail) { try { return(Ok(PlanetDAL.UpdatePlanetPop(planetDetail))); } catch (Exception e) { return(InternalServerError(e)); } }
public IHttpActionResult ColonizePlanet([FromBody] PlanetDetail planetDetail) { try { return(Ok(PlanetDAL.ColonizePlanet(planetDetail))); } catch (Exception e) { return(InternalServerError(e)); } }
public PlanetDetailFormViewModel(PlanetDetail details) { if (details == null) { return; } PlanetDetailFormViewModelId = details.PlanetID; RotationPeriod = details.RotationPeriod; OrbitalPeriod = details.OrbitalPeriod; Diameter = details.Diameter; Population = details.Population; }
void RespawnGalleries(PlanetDetail data) { GM.DespawnAllChildren(galleryParent); for (int i = 0; i < data.points.Length; i++) { var p = data.points[i]; for (int j = 0; j < p.images.Length; j++) { var m = p.images[j]; var gal = GM.Spawn <GalleryButton>(galleryPrefab, galleryParent); gal.Init(m.path, p.head, p.body, m.caption, galleryGroup); } } }
public ActionResult Save(PlanetFormViewModel planetViewModel, PlanetDetailFormViewModel detailsViewModel, PlanetAssetsFormViewModel planetAssetsFormViewModel, List <ClimateZoneViewModel> climateZonesViewModel, List <SurfaceMorphologyViewModel> surfaceMorphologiesViewModel) { var fileManager = new FileManager(Server); if (!ModelState.IsValid) { Planet planetWithAssets = planetRepository.GetPlanetRawWithAssets(planetViewModel.PlanetFormViewModelId); planetViewModel.AssignUploadedAvatar(fileManager); if (planetWithAssets != null) { planetAssetsFormViewModel = new PlanetAssetsFormViewModel(planetWithAssets, fileManager); } var viewModel = ContainerPlanetFormViewModel.CreateFromViewModels(planetViewModel, detailsViewModel, planetAssetsFormViewModel, climateZonesViewModel, surfaceMorphologiesViewModel); return(View("PlanetForm", viewModel)); } Planet planetToDB; if (planetViewModel.PlanetFormViewModelId == 0) { planetToDB = Planet.CreateFromFormViewModel(planetViewModel, fileManager); var planetDetails = PlanetDetail.CreateFromFormViewModel(detailsViewModel, planetViewModel); planetToDB.UpdateSecondaryData(planetDetails, climateZonesViewModel, surfaceMorphologiesViewModel); planetToDB.InitializeAssets(fileManager, planetAssetsFormViewModel); planetRepository.Add(planetToDB); } else { planetToDB = planetRepository.GetFullDataPlanet(planetViewModel.PlanetFormViewModelId); if (planetToDB == null) { return(HttpNotFound()); } planetToDB.UpdateFromFormViewModel(planetViewModel, fileManager); var planetDetails = PlanetDetail.Create(detailsViewModel.RotationPeriod, detailsViewModel.OrbitalPeriod, detailsViewModel.Diameter, detailsViewModel.Population, planetToDB); planetToDB.UpdateSecondaryData(planetDetails, climateZonesViewModel, surfaceMorphologiesViewModel); planetToDB.UpdateAssets(fileManager, planetAssetsFormViewModel); filePathRepository.RemoveFilepaths(planetToDB.FilePathsToDelete); } unitOfWork.Complete(); planetToDB.SaveAssets(fileManager, planetAssetsFormViewModel); return(RedirectToAction("Index", "Planet")); }
public static PlanetDetail UpdatePlanetHarvest(PlanetDetail planet) { PlanetDetail pl = PlanetDAL.GetPlanet(planet.PlanetID, planet.Owner); if (pl.LastHarvest.HasValue && pl.LastHarvest.Value <= DateTime.UtcNow) { pl.LastHarvest = PlanetDAL.UpdatePlanetHarvest(planet); pl.Materials += planet.Materials; pl.Population += planet.Population; pl.Military += planet.Military; } else { throw new Exception("Not time to harvest."); } return(pl); }
public static PlanetDetail AddShipQueue(BuildingQue buildingQue) { PlanetDetail pl = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID); UserDesigns ship = ShipDAL.GetShipDesignbyUser(buildingQue.UserID).Find(x => x.ShipDesignID == buildingQue.BuildingID); if (pl.Materials < ship.MaterialCost || pl.Military < ship.MilitaryCost) { throw new Exception("Not enough resources"); } else { PlanetDAL.UpdatePopAndMats(buildingQue.PlanetID, pl.Materials - buildingQue.MaterialCost, pl.Population, pl.Military - (int)ship.MilitaryCost.Value); pl.Materials -= buildingQue.MaterialCost; pl.Military -= (int)ship.MilitaryCost.Value; } AllbuildQues BuildingsQueLeft = PlanetBLL.GetBuildingQueue(buildingQue.PlanetID, buildingQue.UserID); DateTime UTC = DateTime.UtcNow; BuildingQue bq = new BuildingQue(); bq.BuildingID = buildingQue.BuildingID; bq.PlanetID = buildingQue.PlanetID; bq.Seconds = buildingQue.Seconds; bq.UserID = buildingQue.UserID; bq.MaterialCost = buildingQue.MaterialCost; bq.Movement = buildingQue.Movement; bq.Type = 3; DateTime?maxCompletetionDate = BuildingsQueLeft.shipQue.FindAll(x => x.Type == 3).Max(x => x.CompletetionDate); if (maxCompletetionDate.HasValue) { bq.CompletetionDate = maxCompletetionDate.Value.AddSeconds(buildingQue.Seconds.Value); } else { bq.CompletetionDate = UTC.AddSeconds(buildingQue.Seconds.Value); } PlanetDAL.AddBuildingQue(bq); return(pl); }
public void Fill(AtomDetail dt, PlanetDetail p, ref int plugged, ref int added, ref int possible) { var path = Application.dataPath + "/Resources/" + p.id; if (!Directory.Exists(path)) { return; } var s = Directory.GetFiles(path); var sL = new List <string> (s); for (int i = sL.Count - 1; i >= 0; i--) { if (sL [i].Contains(".meta")) { sL.RemoveAt(i); } } s = sL.ToArray(); added += s.Length; foreach (var c in dt.images) { if (!string.IsNullOrEmpty(c.path)) { plugged++; continue; } if (string.IsNullOrEmpty(c.wikiLink)) { Debug.LogWarning("NOT VALID: " + p.name + "/" + dt.head); continue; } possible++; string sp; if (LocateImage(c.wikiLink, p.id, s, out sp)) { c.path = sp; plugged++; } } }
public static PlanetDetail AddBuildingQueue(BuildingQue buildingQue) { List <PlanetBuildings> buildings = PlanetDAL.GetBuildingTypes(buildingQue.PlanetID); PlanetBuildings pb = buildings.Find(x => x.BuildingID == buildingQue.BuildingID); PlanetDetail pl = PlanetDAL.GetPlanet(buildingQue.PlanetID, buildingQue.UserID); if (pl.Materials < buildingQue.MaterialCost || pl.Population < pb.PopulationCost) { throw new Exception("Not enough resources"); } else { PlanetDAL.UpdatePopAndMats(buildingQue.PlanetID, pl.Materials - buildingQue.MaterialCost, pl.Population - (int)pb.PopulationCost.Value, pl.Military); pl.Materials -= buildingQue.MaterialCost; pl.Population -= (int)pb.PopulationCost.Value; } AllbuildQues BuildingsQueLeft = GetBuildingQueue(buildingQue.PlanetID, buildingQue.UserID); DateTime UTC = DateTime.UtcNow; BuildingQue bq = new BuildingQue(); bq.BuildingID = buildingQue.BuildingID; bq.PlanetID = buildingQue.PlanetID; bq.Seconds = buildingQue.Seconds; bq.UserID = buildingQue.UserID; bq.MaterialCost = buildingQue.MaterialCost; bq.Type = 1; DateTime?maxCompletetionDate = BuildingsQueLeft.buildingQue.FindAll(x => x.Type == 1).Max(x => x.CompletetionDate); if (maxCompletetionDate.HasValue) { bq.CompletetionDate = maxCompletetionDate.Value.AddSeconds(buildingQue.Seconds.Value); } else { bq.CompletetionDate = UTC.AddSeconds(buildingQue.Seconds.Value); } PlanetDAL.AddBuildingQue(bq); return(pl); }
public void SwitchTo(SolarOrbit now) { enabled = true; //PaintStats (stat.GetPlanet (now.id)); RespawnGalleries(currentPlanet = detail.GetPlanet(now.id)); }
public static ContainerPlanetFormViewModel CreateFromModels(Planet planet, PlanetDetail details, FileManager fileManager, IEnumerable<ClimateZoneViewModel> climates, IEnumerable<SurfaceMorphologyViewModel> terrains) { return new ContainerPlanetFormViewModel(planet, details, fileManager, climates, terrains); }