Exemplo n.º 1
0
 public void PlanetOptions()
 {
     "Planet: ".Write();
     PlanetName.Write(PlanetNameCColor);
     " Natural resource available to mine: ".Write();
     PlanetResource.WriteLine(PlanetResourceCColor);
     "[1] Store".WriteLine();
     "[2] Mine".WriteLine();
     "[3] Travel".WriteLine();
     "[4] Save Game".WriteLine();
     "[5] Quit".WriteLine();
 }
Exemplo n.º 2
0
        private void AddResource(ResourceStatistic resourceStatistic, PlanetResource resource)
        {
            if (resource.Value < resourceStatistic.MinValue)
            {
                resourceStatistic.MinValue = resource.Value;
            }
            else if (resource.Value > resourceStatistic.MaxValue)
            {
                resourceStatistic.MaxValue = resource.Value;
            }

            resourceStatistic.AverageValue = (resourceStatistic.Amount * resourceStatistic.AverageValue + resource.Value) / ++resourceStatistic.Amount;
        }
Exemplo n.º 3
0
        public void AddResource(int planetId, int resourceId)
        {
            var            planet   = _planetRepository.GetPlanetDetails(planetId);
            var            resource = _resourceRepository.GetResourceDetails(resourceId);
            PlanetResource link     = new PlanetResource();

            link.PlanetId   = planetId;
            link.ResourceId = resourceId;
            link.Planet     = planet;
            planet.PlanetResource.Add(link);
            resource.PlanetResource.Add(link);
            _planetRepository.UpdatePlanet(planet);
            _resourceRepository.UpdateResource(resource);
        }
Exemplo n.º 4
0
        public void AddResource(int planetId, List <int> resourcesId)
        {
            var planet = _planetRepository.GetPlanetDetails(planetId);

            resourcesId.ForEach(r =>
            {
                var resource        = _resourceRepository.GetResourceDetails(r);
                PlanetResource link = new PlanetResource();
                link.PlanetId       = planetId;
                link.ResourceId     = r;
                link.Planet         = planet;
                planet.PlanetResource.Add(link);
                resource.PlanetResource.Add(link);
                _resourceRepository.UpdateResource(resource);
            });
            _planetRepository.UpdatePlanet(planet);
        }
Exemplo n.º 5
0
        private static async Task SeedPlanetsResourcesAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            var planetsResources = new List <PlanetResource>();

            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths
                                                                                 .PlanetsResourcesCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var planetIdParseSuccess = long.TryParse(lineArgs[0], out var planetId);
                var itemId             = (await dbContext.Items.FirstOrDefaultAsync(i => i.Name.Equals(lineArgs[6])))?.Id ?? 0;
                var richnessId         = (await dbContext.Richnesses.FirstOrDefaultAsync(i => i.Name.Equals(lineArgs[7])))?.Id ?? 0;
                var outputParseSuccess = double.TryParse(lineArgs[8], out var output);

                if (!planetIdParseSuccess ||
                    itemId is 0 ||
                    richnessId is 0 ||
                    !outputParseSuccess)
                {
                    logger.LogWarning($"Can't parse planet resource");
                    logger.LogWarning(line);
                    continue;
                }

                var planetResource = new PlanetResource()
                {
                    PlanetId   = planetId,
                    ItemId     = itemId,
                    RichnessId = richnessId,
                    Output     = output,
                };

                planetsResources.Add(planetResource);
            }

            await dbContext.AddRangeAsync(planetsResources);

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 6
0
    private static PlanetResource GenerateResource(PlanetResource origResource)
    {
        PlanetResource generatedResource = new PlanetResource();

        generatedResource.RangeMin = origResource.RangeMin;
        generatedResource.RangeMax = origResource.RangeMax + origResource.Dispersion;

        float value = UnityEngine.Random.Range(generatedResource.RangeMin, generatedResource.RangeMax);

        if (value < 0)
        {
            value = 0;
        }
        generatedResource.Value = value;

        generatedResource.DispersionRangeMin = value - origResource.Dispersion;
        if (generatedResource.DispersionRangeMin < 0)
        {
            generatedResource.DispersionRangeMin = 0;
        }
        generatedResource.DispersionRangeMax = value + origResource.Dispersion;

        return(generatedResource);
    }
Exemplo n.º 7
0
        private static async Task UpdateOrCreatePlanetResources(List <PlanetInfoCsv> planetInfo)
        {
            var planetGroups = planetInfo.GroupBy(g => g.PlanetId);

            foreach (var resouceList in planetGroups.Select(s => s.ToList()))
            {
                try
                {
                    var planetBase = resouceList.FirstOrDefault(p => !string.IsNullOrEmpty(p.Region) && !string.IsNullOrEmpty(p.Constellation) && !string.IsNullOrEmpty(p.System) && !string.IsNullOrEmpty(p.PlanetName));

                    if (planetBase == null)
                    {
                        continue;
                    }

                    Console.WriteLine($"Adding planet {planetBase.PlanetName}");

                    var region = await _db.Regions.FirstOrDefaultAsync(r =>
                                                                       r.Name == planetBase.Region);

                    if (region == null)
                    {
                        region = new Region()
                        {
                            Name = planetBase.Region
                        };
                        await _db.Regions.AddAsync(region);

                        await _db.SaveChangesAsync();
                    }

                    var constellation = await _db.Constellations.FirstOrDefaultAsync(c =>
                                                                                     c.Name == planetBase.Constellation);

                    if (constellation == null)
                    {
                        constellation = new Constellation()
                        {
                            Name   = planetBase.Constellation,
                            Region = region
                        };
                        await _db.Constellations.AddAsync(constellation);

                        await _db.SaveChangesAsync();
                    }

                    var system = await _db.Systems.FirstOrDefaultAsync(c =>
                                                                       c.Name == planetBase.System);

                    if (system == null)
                    {
                        system = new UniverseSystem()
                        {
                            Name          = planetBase.System,
                            Constellation = constellation
                        };
                        await _db.Systems.AddAsync(system);

                        await _db.SaveChangesAsync();
                    }

                    var planet = await _db.Planets.FirstOrDefaultAsync(p => p.Id == planetBase.PlanetId);

                    Enum.TryParse(planetBase.PlanetType.RemoveWhitespace(), out PlanetTypes planetEnum);


                    if (planet == null)
                    {
                        planet = new Planet()
                        {
                            Name   = planetBase.PlanetName,
                            Id     = planetBase.PlanetId,
                            Type   = planetEnum,
                            System = system,
                        };
                        await _db.Planets.AddAsync(planet);

                        await _db.SaveChangesAsync();
                    }

                    planet.Resources = new List <PlanetResource>();
                    foreach (var resource in resouceList)
                    {
                        Enum.TryParse(resource.Resource.RemoveWhitespace(), out PlanetResourceTypes resourceEnum);

                        Enum.TryParse(resource.Richness.RemoveWhitespace(), out ResourceRichnessTypes richnessEnum);
                        var dbResource = new PlanetResource()
                        {
                            Planet   = planet,
                            Output   = Double.Parse(resource.Output),
                            Type     = resourceEnum,
                            Richness = richnessEnum
                        };

                        await _db.PlanetResources.AddAsync(dbResource);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            await _db.SaveChangesAsync();
        }
Exemplo n.º 8
0
 private static float GetMinValue(float currentValue, PlanetResource resource)
 {
     return(Math.Min(currentValue, resource.RangeMin - resource.Dispersion));
 }