Exemplo n.º 1
0
        /// <summary>
        ///     This method generates simplestub.
        /// </summary>
        /// <param name="level">level of object</param>
        /// <param name="upkeep">Total output upkeep</param>
        /// <param name="unitLevel">The unit level to generate</param>
        /// <param name="randomness">A percentage of upkeep being completely random, 1 means it's completely random</param>
        /// <param name="seed">seed for the randomizer</param>
        /// <param name="stub">output</param>
        public virtual void Generate(int level, int upkeep, byte unitLevel, double randomness, int seed, out ISimpleStub stub)
        {
            stub = new SimpleStub();
            for (int i = 0; i < type.Length; ++i)
            {
                stub.AddUnit(FormationType.Normal,
                             type[i],
                             (ushort)(upkeep * (1 - randomness) * ratio[level - 1][i] / unitFactory.GetUnitStats(type[i], unitLevel).Upkeep));
            }

            Random random    = new Random(seed);
            int    remaining = (int)(upkeep * randomness);

            while (remaining > 0)
            {
                var nextUpkeep = random.Next(1, remaining);
                var nextType   = random.Next(0, type.Length);
                var unitUpkeep = unitFactory.GetUnitStats(type[nextType], unitLevel).Upkeep;
                var unitCount  = nextUpkeep / unitUpkeep;
                if (unitCount <= 0)
                {
                    continue;
                }
                stub.AddUnit(FormationType.Normal, type[nextType], (ushort)unitCount);
                remaining -= unitUpkeep * unitCount;
            }
        }
Exemplo n.º 2
0
        public void RemoveFromFormation_WhenSourceHasSameUnitsInDifferentFormationsAndTroopDoesHasEnough_ReturnsTrueAndRemovesUnits(
            IFormation sourceFormation,
            SimpleStub unitsToRemove,
            SimpleStub troopStub)
        {
            troopStub.AddUnit(FormationType.Normal, 100, 310);

            unitsToRemove.AddUnit(FormationType.Attack, 100, 150);
            unitsToRemove.AddUnit(FormationType.Defense, 100, 150);

            troopStub.RemoveFromFormation(FormationType.Normal, unitsToRemove).Should().BeTrue();
            troopStub[FormationType.Normal][100].Should().Be(10);
        }
Exemplo n.º 3
0
        public void RemoveFromFormation_WhenSourceHasSameUnitsInDifferentFormationsAndTroopDoesNotHaveEnough_ReturnsFalseAndDoesNotModifyTroop(
            IFormation sourceFormation,
            SimpleStub unitsToRemove,
            SimpleStub troopStub)
        {
            troopStub.AddUnit(FormationType.Normal, 100, 200);

            unitsToRemove.AddUnit(FormationType.Attack, 100, 150);
            unitsToRemove.AddUnit(FormationType.Defense, 100, 150);

            troopStub.RemoveFromFormation(FormationType.Normal, unitsToRemove).Should().BeFalse();
            troopStub[FormationType.Normal][100].Should().Be(200);
        }
Exemplo n.º 4
0
        public void RemoveFromFormation_WhenHasEnoughUnits_ReturnsTrueAndRemovesUnitsFromCorrectFormation(
            IFormation sourceFormation,
            SimpleStub unitsToRemove,
            SimpleStub troopStub)
        {
            troopStub.AddUnit(FormationType.Normal, 100, 200);
            troopStub.AddUnit(FormationType.Normal, 101, 100);

            unitsToRemove.AddUnit(FormationType.Attack, 100, 10);
            unitsToRemove.AddUnit(FormationType.Defense, 101, 10);

            troopStub.RemoveFromFormation(FormationType.Normal, unitsToRemove).Should().BeTrue();
            troopStub[FormationType.Normal][100].Should().Be(190);
            troopStub[FormationType.Normal][101].Should().Be(90);
        }
Exemplo n.º 5
0
        public void RemoveFromFormation_WhenTroopHasUnitsButNotInSpecifiedFormation_ReturnsFalseAndDoesNotModifyTroop(
            IFormation sourceFormation,
            SimpleStub unitsToRemove,
            SimpleStub troopStub)
        {
            troopStub.AddUnit(FormationType.Defense, 100, 200);

            unitsToRemove.AddUnit(FormationType.Attack, 100, 150);

            troopStub.RemoveFromFormation(FormationType.Normal, unitsToRemove).Should().BeFalse();
            troopStub[FormationType.Defense][100].Should().Be(200);
        }
Exemplo n.º 6
0
        public void RemoveFromFormation_WhenDoesntHaveFormation_ReturnsFailureAndDoesNotModifyTroop(
            IFormation sourceFormation,
            SimpleStub unitsToRemove,
            SimpleStub troopStub)
        {
            troopStub.AddUnit(FormationType.Normal, 100, 200);

            unitsToRemove.AddUnit(FormationType.Attack, 100, 10);

            troopStub.RemoveFromFormation(FormationType.Attack, unitsToRemove).Should().BeFalse();
            troopStub.TotalCount.Should().Be(200);
        }
Exemplo n.º 7
0
        public static ISimpleStub ReadStub(Packet packet, params FormationType[] formations)
        {
            var simpleStub = new SimpleStub();

            for (int i = 0; i < formations.Length; i++)
            {
                FormationType formationType = (FormationType)packet.GetByte();
                if (!formations.Contains(formationType))
                {
                    throw new Exception("Invalid formation sent");
                }

                byte unitCount = packet.GetByte();

                for (int u = 0; u < unitCount; ++u)
                {
                    ushort type  = packet.GetUInt16();
                    ushort count = packet.GetUInt16();
                    simpleStub.AddUnit(formationType, type, count);
                }
            }

            return(simpleStub);
        }