Пример #1
0
        private void SubstractResources(PlayerObject pO, int[] resources)
        {
            if (resources.Length < 3)
            {
                throw new ArgumentException();
            }

            pO.Resources.Energy -= resources[0];
            pO.Resources.Crystal -= resources[1];
            pO.Resources.Metal -= resources[2];
        }
Пример #2
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;
        }
Пример #3
0
        private bool CanBuild(PlayerObject pO, int toLevel, IBuilding buildingLogic)
        {
            if (pO.Buildings.CurrentlyBuilding != CurrentlyBuilding.None)
            {
                return false;
            }

            if (toLevel > buildingLogic.MaxLevel)
            {
                return false;
            }

            if (pO.Buildings.HeadQuartersLevel < buildingLogic.Prerequisite)
            {
                return false;
            }

            if (toLevel > pO.Buildings.HeadQuartersLevel && buildingLogic.Name != "Headquarters")
            {
                return false;
            }

            var requiredResources = buildingLogic.GetRequiredResources(toLevel);

            return pO.Resources.Energy > requiredResources[0]
                && pO.Resources.Crystal > requiredResources[1]
                && pO.Resources.Metal > requiredResources[2];
        }
        private bool CanResearch(PlayerObject pO, int toLevel, ITechnology techLogic)
        {
            if (pO.Technologies.CurrentlyResearching != CurrentlyResearching.None)
            {
                return false;
            }

            if (toLevel > techLogic.MaxLevel)
            {
                return false;
            }

            if (pO.Buildings.ResearchCentreLevel < techLogic.Prerequisite)
            {
                return false;
            }

            var requiredResources = techLogic.GetRequiredResources(toLevel);

            return pO.Resources.Energy > requiredResources[0]
                && pO.Resources.Crystal > requiredResources[1]
                && pO.Resources.Metal > requiredResources[2];
        }
Пример #5
0
        private void SubstractResources(PlayerObject pO, int[] resources, int amount, ITechnology techLogic)
        {
            if (resources.Length < 3)
            {
                throw new ArgumentException();
            }

            var cheaperFleetModifier = techLogic.Modifier[pO.Technologies.CheaperFleetLevel];

            var requiredEnergy = (resources[0] - (int)(cheaperFleetModifier * resources[0])) * amount;
            var requiredCrystals = (resources[1] - (int)(cheaperFleetModifier * resources[1])) * amount;
            var requiredMetal = (resources[2] - (int)(cheaperFleetModifier * resources[2])) * amount;

            pO.Resources.Energy -= requiredEnergy;
            pO.Resources.Crystal -= requiredCrystals;
            pO.Resources.Metal -= requiredMetal;
        }
Пример #6
0
        private bool CanRecruit(PlayerObject pO, int amount, IShip shipLogic, ITechnology techLogic)
        {
            if (pO.Units.CurrentlyRecruiting != CurrentlyRecruiting.None)
            {
                return false;
            }

            if (amount <= 0)
            {
                return false;
            }

            if (pO.Buildings.BarracksLevel < shipLogic.Prerequisite)
            {
                return false;
            }

            var requiredResources = shipLogic.RequiredResourcesToBuild;
            var cheaperFleetModifier = techLogic.Modifier[pO.Technologies.CheaperFleetLevel];

            var requiredEnergy = (requiredResources[0] - (int) (cheaperFleetModifier*requiredResources[0]))*amount;
            var requiredCrystals = (requiredResources[1] - (int)(cheaperFleetModifier * requiredResources[1])) * amount;
            var requiredMetal = (requiredResources[2] - (int)(cheaperFleetModifier * requiredResources[2])) * amount;

            return pO.Resources.Energy > requiredEnergy
                   && pO.Resources.Crystal > requiredCrystals
                   && pO.Resources.Metal > requiredMetal;
        }
Пример #7
0
 private bool IsAllowed(PlayerObject player, Shard shard)
 {
     return player.Planet.ShardId == shard.Id;
 }