Inheritance: IdentityUser
示例#1
0
        public void AssignPlayerObjectWithShard(ApplicationUser user, int shardId)
        {
            var pO = new PlayerObject();

            pO.Units = new Units();

            pO.Buildings = new Buildings
            {
                HeadQuartersLevel = 1,
                BarracksLevel = 0,
                ResearchCentreLevel = 0,
                SolarCollectorLevel = 1,
                CrystalExtractorLevel = 1,
                MetalScrapperLevel = 1
            };

            // TODO: Extract into logic
            pO.Points = new Points
            {
                PointsCombat = 0,
                PointsNeutral = 0,
                PointsPlanet = (pO.Buildings.HeadQuartersLevel*100)
                               + (pO.Buildings.SolarCollectorLevel*10)
                               + (pO.Buildings.CrystalExtractorLevel*10)
                               + (pO.Buildings.MetalScrapperLevel*10)
            };

            // TODO: Extract into logic
            pO.Resources = new Resources
            {
                Energy = 350,
                Crystal = 350,
                Metal = 350
            };

            pO.Technologies = new Technologies();

            Planet planet;

            var shard = this.shards.All().FirstOrDefault(x => x.Id == shardId);

            if (shard != null)
            {
                planet = shard.Planets.Where(y => !y.IsPopulated)
                    .OrderBy(x => Guid.NewGuid())
                    .FirstOrDefault();
            }
            else
            {
                var randomShard = this.shards.All()
                    .Where(x => x.Planets.Any(p => !p.IsPopulated && !x.IsLocked))
                    .OrderBy(x => Guid.NewGuid())
                    .First();

                planet = randomShard.Planets.Where(y => !y.IsPopulated)
                    .OrderBy(x => Guid.NewGuid())
                    .FirstOrDefault();
            }

            planet.IsPopulated = true;

            planets.Update(planet);
            planets.SaveChanges();

            pO.PlanetId = planet.Id;

            user.PlayerObject = pO;
        }
示例#2
0
 public void AssignPlayerObject(ApplicationUser user)
 {
     this.AssignPlayerObjectWithShard(user, -1);
 }