public static List <PlanetDto> CreatePlanets(int randomValue, double starTemperature) { var result = new List <PlanetDto>(); var rand = new Random(randomValue * Settings.Seed); var value = rand.Next(); var numberOfPlanets = Settings.PlanetNumberMinimum + value % (Settings.PlanetNumberMaximum - Settings.PlanetNumberMinimum); for (int i = 0; i < numberOfPlanets; i++) { var mass = Settings.PlanetMassMinimum + rand.NextDouble() * (Settings.PlanetMassMaximum - Settings.PlanetMassMinimum); var radius = Settings.PlanetRadiusMinimum + rand.NextDouble() * (Settings.PlanetRadiusMaximum - Settings.PlanetRadiusMinimum); var distanceToStar = Settings.PlanetDistanceToStarMinimum + rand.NextDouble() * (Settings.PlanetDistanceToStarMaximum - Settings.PlanetDistanceToStarMinimum); var planet = new PlanetDto { Mass = mass, Radius = radius, DistanceToStar = distanceToStar, MinTemperature = Calculate.CalculatePlanetTemperatureMinimum(Settings, mass, distanceToStar, starTemperature), MaxTemperature = Calculate.CalculatePlanetTepmeratureMaximum(Settings, distanceToStar, starTemperature), GravitationalAcceleration = Calculate.CalculatePlanetGravitationalAcceleration(mass, radius), Moons = CreateMoons(value), Name = GeneratePlanetName(randomValue, value), Population = 0, Resources = new ResourcesDto(), Buildings = new BuildingsDto() }; planet.Triats = GenerateTriatsForPlanet(planet, value); result.Add(planet); } return(result); }
public static void AddPlanet(PlanetDto planetDto) { using (var ctx = new PlanetHuntersContext()) { try { var planet = new Planet { Name = planetDto.Name, Mass = planetDto.Mass ?? 0 }; if (!Check.IsSystemExisting(planetDto.StarSystem)) { AddStarSystem(planetDto.StarSystem); } planet.HostStarSystemId = DataLoader.GetStarSystemByName(planetDto.StarSystem).Id; ctx.Planets.Add(planet); ctx.SaveChanges(); Printer.PrintSuccess(planet.Name); } catch (Exception) { Printer.PrintError(); } } }
private static TriatsDto GenerateTriatsForPlanet(PlanetDto planet, int value) { var rand = new Random(value * Settings.Seed); var triats = new TriatsDto(); triats.Rocky = true; if (Calculate.CalculateIsPlanetGasGiant(planet.Mass, planet.Radius)) { triats.GasGiant = true; triats.Rocky = false; } else if (Calculate.CalculateIsPlanetHasDenseAtmosphere(Settings, planet.Mass, planet.MaxTemperature)) { triats.DenseAtmosphere = true; } else if (!Calculate.CalculateIsPlanetHasAtmosphere(Settings, planet.Mass, planet.MaxTemperature)) { triats.NoAtmosphere = true; } var number = rand.Next() % _modulo; if (triats.Rocky && !triats.NoAtmosphere && number < Settings.PlanetFriendlyAtmosphereChance) { triats.FriendlyAtmosphere = true; } number = rand.Next() % _modulo; if (triats.Rocky && !triats.NoAtmosphere && number < Settings.PlanetToxicAtmosphereChance) { triats.ToxicAtmosphere = true; } number = rand.Next() % _modulo; if (number < Settings.PlanetStrongRadiationChance) { triats.StrongRadiation = true; } number = rand.Next() % _modulo; if (triats.Rocky && number < Settings.PlanetHightVolcanicActivityChance) { triats.HightVolcanicActivity = true; } if ((planet.MinTemperature + planet.MaxTemperature) / 2 > Settings.PlanetHotTreshold) { triats.Hot = true; } else if ((planet.MinTemperature + planet.MaxTemperature) / 2 < Settings.PlanetColdTreshold) { triats.Cold = true; } return(triats); }
private int GetFleetNeeded(PlanetDto myPlanet, PlanetDto enemy, GameStateDto state) { var output = enemy.NumberOfShips + GetIncomingEnemies(enemy, state) - GetIncomingSupport(enemy, state); if (enemy.OwnerID != 0) { output += TravelTime(myPlanet.Position, enemy.Position) * enemy.GrowthRate; } return(output); }
public IPlanetDto GetPlanetById(int planetId) { Planet planet = this.unitOfWork.PlanetsDbRepository.Find(planetId); IPlanetDto planetDto = new PlanetDto() { Id = planet.Id, Name = planet.Name, SolarSystemId = planet.SollarSystemId, SunId = planet.SunId }; return(planetDto); }
public IHttpActionResult CreatePlanet(PlanetDto planetDto) { if (!ModelState.IsValid) { return(BadRequest()); } var planet = Mapper.Map <PlanetDto, Planet>(planetDto); _context.Planets.Add(planet); _context.SaveChanges(); planetDto.Id = planet.Id; return(Created(new Uri(Request.RequestUri + "/" + planet.Id), planetDto)); }
public IHttpActionResult UpdatePlanet(int id, PlanetDto planetDto) { if (!ModelState.IsValid) { return(BadRequest()); } var planetInDb = _context.Planets.SingleOrDefault(c => c.Id == id); if (planetInDb == null) { return(NotFound()); } Mapper.Map(planetDto, planetInDb); _context.SaveChanges(); return(Ok()); }
private static void ImportPlanetToDatabase(PlanetDto planetDto) { var db = new MassDefectDatabaseContext(); if (planetDto == null) { throw new ArgumentNullException("Planet cannot be null!"); } else if (planetDto.Name == null) { throw new ArgumentNullException("Planet name cannot be null!"); } else if (planetDto.Sun == null) { throw new ArgumentNullException("Planet sun cannot be null!"); } else if (planetDto.SolarSystem == null) { throw new ArgumentNullException("Planet solar system cannot be null!"); } var sun = db.Stars.FirstOrDefault(s => s.Name == planetDto.Sun); var solarSystem = db.SolarSystems.FirstOrDefault(s => s.Name == planetDto.SolarSystem); if (sun == null) { throw new ArgumentNullException("Sun doesn't exist in dbo.Stars"); } else if (solarSystem == null) { throw new ArgumentNullException("Solar system doesn't exist in dbo.SolarSystems"); } var newPlanet = new Planet() { Name = planetDto.Name, Sun = sun, SolarSystem = solarSystem }; db.Planets.Add(newPlanet); db.SaveChanges(); }
public IEnumerable <IPlanetDto> GetPlanetsByName(string name) { IList <Planet> planets = this.unitOfWork.PlanetsDbRepository.GetAll(p => p.Name == name).ToList(); IList <IPlanetDto> planetDtos = new List <IPlanetDto>(planets.Count); foreach (Planet planet in planets) { IPlanetDto planetDto = new PlanetDto() { Id = planet.Id, Name = planet.Name, SolarSystemId = planet.SollarSystemId, SunId = planet.SunId }; planetDtos.Add(planetDto); } return(planetDtos); }
public List <PlanetDto> GetAll() { List <Planet> planets = _planetService.GetAll(); return(PlanetDto.Convert(planets)); }
private int GetIncomingEnemies(PlanetDto planet, GameStateDto state) { return(state.Fleets.Where(x => x.OwnerID != me && x.DestinationPlanetID == planet.ID).Sum(x => x.NumberOfShips)); }