private bool CreateStars(IDbConnection connection) { var starTypeName = MapTypes.Star.ToString(); var gTypes = _gameTypeService.GetGGameTypes(connection, starTypeName); var gTIds = gTypes.Select(i => i.Id).ToList(); var typeUsed = new List <byte>(); var systemNames = _getSystemNames(connection); var textureTypes = _gameTypeService.GetTextures(connection, starTypeName); var stars = new List <GGeometryStarDataModel>(); var parentIds = _systemService.GetAllSystemIds(connection); stars.AddRange(from t in parentIds let typeId = GameTypeHalper.GetRandomTypeFromUsedTyps(gTIds, ref typeUsed) select new GGeometryStarDataModel { Id = t, TypeId = typeId, TextureTypeId = textureTypes.First(i => i.GameTypeId == typeId).Id, Radius = (double)Rand.Next(500, 1000) * Scale / (1000 * 20) }); stars = (List <GGeometryStarDataModel>)_systemService.AddOrUpdateGeometryStars(connection, stars); var systemDetails = stars.Select(star => CreateSystemDetail(connection, star.Id, star.TypeId, systemNames[star.Id])).ToList(); var suc = _systemService.AddOrUpdateDetailSystems(connection, systemDetails).Any(); return(true); }
private bool CreateGalaxies(IDbConnection connection) { var galaxyNativeName = MapTypes.Galaxy.ToString(); var spiraleNativeName = GalaxySubTypes.Spirale.ToString(); var gTypes = _gameTypeService.GetGGameTypes(connection, galaxyNativeName, spiraleNativeName); var typeIds = gTypes.Select(i => i.Id).ToList(); var typeUsed = new List <byte>(); var translate = new L10N(); translate.InitializeField(); var galaxyIds = new List <byte> { 1 }; const string baseName = "galaxy"; var galaxies = new List <GGalaxyDataModel>(); foreach (var galaxyId in galaxyIds) { translate.En.Name = "Galaxy " + galaxyId; translate.Es.Name = "Galaxia " + galaxyId; translate.Ru.Name = "Галактика " + galaxyId; var typeId = GameTypeHalper.GetRandomTypeFromUsedTyps(typeIds, ref typeUsed); var type = gTypes.Single(i => i.Id == typeId); var typeTranslate = type.Description; translate.En.Description = "Unique Description En " + translate.En.Name + " TypeDescription: " + typeTranslate.En.Description; translate.Es.Description = "Unique Description Es " + translate.Es.Name + " TypeDescription: " + typeTranslate.Es.Description; translate.Ru.Description = "Unique Description Ru " + translate.Ru.Name + " TypeDescription: " + typeTranslate.Ru.Description; var textures = _gameTypeService.GetTextures(connection, typeId); galaxies.Add(new GGalaxyDataModel { Id = galaxyId, Translate = translate, NativeName = baseName + galaxyId, Opened = true, TypeId = type.Id, Position = CreateGalaxyPosition(galaxyId), TextureTypeId = _gameTypeService.GetRandTextureId(textures, Rand) }); } foreach (var i in galaxies) { _gGalaxyService.AddOrUpdate(connection, i); } return(true); }
public bool CreateMoons(IDbConnection connection) { var moonType = PlanetoidSubTypes.Moon.ToString(); var moonTextureTypes = _gameTypeService.GetTextures(connection, MapTypes.Satellite.ToString(), moonType); var moonTextIds = moonTextureTypes.Select(i => i.Id).ToList(); var moonTextUsedIds = new List <short>(); var planetGeomety = _getPlanetCollection(connection); var planetsDetail = _getPlanetDetailCollection(connection); var parentId = 0; double firstPlanetRadius = 0; var mincoef = 4; var planetCount = planetGeomety.Count; for (var i = 0; i < planetCount; i++) { var planet = planetGeomety[i]; var detailPlanet = planetsDetail[i]; if (parentId != planet.Parent) { parentId = planet.Parent; firstPlanetRadius = planet.Radius; } var parentRadius = planet.Radius; var minMoonRadius = firstPlanetRadius / mincoef; var minMoonOrbit = parentRadius + (1.5 * minMoonRadius); if (detailPlanet.MoonCount == 0) { continue; } for (var moonIndex = 0; moonIndex < detailPlanet.MoonCount; moonIndex++) { var ki = Math.Pow(Factor, moonIndex + 1); //"DT-CA-1-3" var moonName = planet.NativeName + "-" + (moonIndex + 1); var maxRadius = parentRadius / 4; var moonRadius = RandNum.NextDouble(minMoonRadius, maxRadius); //13.72 var moonCurrOrbit = minMoonOrbit * ki; var moonTextureId = GameTypeHalper.GetRandomTypeFromUsedTyps(moonTextIds, ref moonTextUsedIds); var geometryMoon = _moonService.AddOrUpdateGeometryMoon(connection, new GGeometryMoonDataModel { GalaxyId = planet.GalaxyId, SectorId = planet.SectorId, SystemId = planet.SystemId, PlanetId = planet.Id, Radius = Math.Round(moonRadius, 4), Orbit = Math.Round(moonCurrOrbit, 4), OrbitPosition = (byte)Rand.Next(0, Tes), TypeId = (byte)PlanetoidSubTypes.Moon, AxisAngle = _getRandomAngle(FactorAngle), OrbitAngle = _getRandomAngle(FactorAngle), TextureTypeId = moonTextureId, }); var detailMoon = _createMoonDetail(connection, geometryMoon.Id, moonName); var dm = _moonService.AddOrUpdateDetailMoon(connection, detailMoon); if (dm == null || dm.Id == 0) { throw new NotImplementedException("moon didn't created"); } } } return(true); }
private bool CreatePlanets(IDbConnection connection) { var stars = _getStarCollection(connection); var pl = new PlanetGeometry(); // const double FactorAngle = Math.PI/16; //================================================== var planetTypeName = MapTypes.Planet.ToString(); var gasGameTypes = new List <byte> { (byte)PlanetoidSubTypes.Gas, (byte)PlanetoidSubTypes.IceGas }; var usedGasGameTypes = new List <byte>(); var planetTextureTypes = _gameTypeService.GetTextures(connection, planetTypeName); var earthTextureTypes = planetTextureTypes.Where(i => i.GameTypeId == (byte)PlanetoidSubTypes.Earth).Select(i => i.Id) .ToList(); var gasTextureTypes = planetTextureTypes.Where(i => i.GameTypeId == (byte)PlanetoidSubTypes.Gas).Select(i => i.Id).ToList(); var iceGasTypes = planetTextureTypes.Where(i => i.GameTypeId == (byte)PlanetoidSubTypes.IceGas) .Select(i => i.Id) .ToList(); var earthTextureUsed = new List <short>(); var gasTextureUsed = new List <short>(); var iceGasTextureUsed = new List <short>(); //================================================== var planets = new List <GGeometryPlanetDataModel>(); foreach (var star in stars) { var planetCount = Rand.Next(6, 10); var starRadius = star.Radius; var basicPlanetOrbit = 1.2 * starRadius; var secondRingCoef = 1; for (var i = 0; i < planetCount; i++) { pl.Atmosphere = true; pl.Rings = null; var currOrbit = basicPlanetOrbit * Math.Pow(Factor, i) / 4; var q = currOrbit / 2; currOrbit *= Scale; currOrbit = Math.Round(currOrbit, 4); var planetCurrRadius = Math.Round(q - (q * 0.1 * i), 4); byte typeId; short textureType; if (i <= 4) { typeId = (byte)PlanetoidSubTypes.Earth; textureType = GameTypeHalper.GetRandomTypeFromUsedTyps(earthTextureTypes, ref earthTextureUsed); } else { typeId = GameTypeHalper.GetRandomTypeFromUsedTyps(gasGameTypes, ref usedGasGameTypes); textureType = (typeId == (byte)PlanetoidSubTypes.Gas) ? GameTypeHalper.GetRandomTypeFromUsedTyps(gasTextureTypes, ref gasTextureUsed) : GameTypeHalper.GetRandomTypeFromUsedTyps(iceGasTypes, ref iceGasTextureUsed); var hasRing = HasRings(i, ref secondRingCoef); if (hasRing) { pl.Rings = _createRings(connection); } } var orbitPosition = (byte)Rand.Next(0, Tes); var orbitAngle = _getRandomAngle(FactorAngle); planets.Add(new GGeometryPlanetDataModel { GalaxyId = star.GalaxyId, SectorId = star.SectorId, SystemId = star.Id, TypeId = typeId, Orbit = currOrbit, AxisAngle = _getRandomAngle(FactorAngle), OrbitAngle = orbitAngle, RingTypeId = pl.Rings, SystemPosition = (byte)(i + 1), Radius = planetCurrRadius, Color = PlanetColor3Generator.CreateColorByType(typeId), TextureTypeId = textureType, OrbitPosition = orbitPosition }); } } var suc = _gGeometryPlanetService.AddOrUpdateGeometryPlanets(planets, connection).Any(); return(suc); }