Beispiel #1
0
            public void WillTestBuildingCapacityWithLargeNumbers()
            {
                var r = new Random();

                var totalNetValue = new NetValue
                {
                    Cash   = r.Next(1, int.MaxValue),
                    Energy = r.Next(1, int.MaxValue),
                    Food   = r.Next(1, int.MaxValue),
                    Iron   = r.Next(1, int.MaxValue),
                    Mana   = r.Next(1, int.MaxValue)
                };
                var buildCosts = new BuildCosts <object>
                {
                    Cash   = 1 * r.NextDouble(),
                    Energy = 1 * r.NextDouble(),
                    Food   = 1 * r.NextDouble(),
                    Iron   = 1 * r.NextDouble(),
                    Mana   = 1 * r.NextDouble()
                };

                var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, r.Next(250));

                Assert.GreaterOrEqual(netValue.EntityCount, 1);
            }
Beispiel #2
0
        /// <summary>
        /// Used to schedule buildings to be built.
        /// </summary>
        /// <param name="player">
        /// The player who is building.
        /// </param>
        /// <param name="planet">
        /// The planet to build on.
        /// </param>
        /// <param name="buildingCosts">
        /// The building costs for a particular building type.
        /// </param>
        /// <param name="costs">
        /// The costs of building.
        /// </param>
        /// <param name="type">
        /// The type of building to build.
        /// </param>
        /// <returns>
        /// True if the build was added to the queue.
        /// </returns>
        public bool BuildBuildings(Player player, Planet planet, BuildCosts <BuildingType> buildingCosts, NetValue costs, BuildingType type)
        {
            if (this.scheduler == null)
            {
                Trace.WriteLine("this.scheduler is null", "SpaceScheduler.SubtractBuildCosts");
                return(false);
            }

            if (buildingCosts == null)
            {
                Trace.WriteLine("buildCosts is null", "SpaceScheduler.SubtractBuildCosts");
                return(false);
            }

            // Needs to subtract the cost here. return false if the player tries to build too many buildings.
            var totalCosts = buildingCosts.CalculateBuildCosts(costs, planet.TotalBuildings, planet.BuildingCapacity);

            player.TotalNetValue.Subtract(totalCosts);

            var jobSetup = new JobSetup <BuildBuildingsJob>(this.scheduler);

            jobSetup.Set(bbj => bbj.PlanetID, planet.ID);
            jobSetup.Set(bbj => bbj.BuildingType, type);
            jobSetup.Set(bbj => bbj.BuildingCount, totalCosts.EntityCount);

            jobSetup.Run(DateTimeOffset.UtcNow.AddMilliseconds(buildingCosts.Time));

            return(true);
        }
Beispiel #3
0
            public void WillReturnZeroBuildItems()
            {
                var totalNetValue = new NetValue();
                var buildCosts    = new BuildCosts <object>();

                var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1);

                Assert.AreEqual(netValue.EntityCount, 0);
            }
Beispiel #4
0
            public void WillReturnOneBuildItem()
            {
                var totalNetValue = new NetValue {
                    Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1
                };
                var buildCosts = new BuildCosts <object> {
                    Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1
                };

                var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1);

                Assert.AreEqual(netValue.EntityCount, 1);
            }
Beispiel #5
0
            public void WillTestUser()
            {
                var totalNetValue = new NetValue {
                    EntityCount = 2, Cash = 3, Energy = 3, Food = 3, Iron = 3, Mana = 3
                };
                var buildCosts = new BuildCosts <object> {
                    Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1
                };

                var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 100);

                Assert.AreEqual(netValue.EntityCount, 2);
            }
Beispiel #6
0
            public void WillTestBuildingCapacityMinimum()
            {
                var totalNetValue = new NetValue {
                    Cash = 2, Energy = 2, Food = 2, Iron = 2, Mana = 2
                };
                var buildCosts = new BuildCosts <object> {
                    Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1
                };

                var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1);

                Assert.AreEqual(netValue.EntityCount, 1);
            }
Beispiel #7
0
            public void WillTestBuildingCapacityMaximum()
            {
                var totalNetValue = new NetValue {
                    Cash = 3, Energy = 3, Food = 3, Iron = 3, Mana = 3
                };
                var buildCosts = new BuildCosts <object> {
                    Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1
                };

                var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1);

                // 2 here because of the building capacity and overbuild cost (x2)
                Assert.AreEqual(netValue.EntityCount, 2);
            }