Пример #1
0
        public void TestVictoryPoint(byte level, decimal occupiedDays, decimal bonusDays, decimal serverDays, decimal expectedValue)
        {
            var serverDate = SystemClock.Now.Subtract(TimeSpan.FromDays((double)serverDays));

            var systemVariableManager = Substitute.For <ISystemVariableManager>();

            systemVariableManager["Server.date"].Returns(new SystemVariable("Server.date", serverDate));

            var fixture = FixtureHelper.Create();

            fixture.Register(() => systemVariableManager);
            fixture.Customize <Formula>(c => c.FromFactory(new MethodInvoker(new GreedyConstructorQuery())));

            var stronghold = Substitute.For <IStronghold>();

            stronghold.StrongholdState.Returns(StrongholdState.Occupied);
            stronghold.Lvl.Returns(level);
            stronghold.BonusDays.Returns(bonusDays);
            var occupiedDate = SystemClock.Now.Subtract(TimeSpan.FromDays((double)occupiedDays));

            stronghold.DateOccupied.Returns(occupiedDate);

            var formula = fixture.Create <Formula>();

            formula.StrongholdVictoryPoint(stronghold).Should().Be(expectedValue);
        }
Пример #2
0
        public void TestLaborMoveWithOvertime(int labor, IEnumerable <Effect> effects, int expected)
        {
            var formula   = FixtureHelper.Create().Create <Formula>();
            var structure = Substitute.For <IStructure>();

            structure.City.GetTotalLaborers().Returns(160);
            structure.City.Technologies.GetEffects(EffectCode.LaborMoveTimeMod).Returns(effects);

            formula.LaborMoveTime(structure, (ushort)labor, true).Should().Be(expected);
        }
Пример #3
0
        public void TestNonOccupiedVictoryPoint()
        {
            var formula = FixtureHelper.Create().Create <Formula>();

            var stronghold = Substitute.For <IStronghold>();

            stronghold.StrongholdState.Returns(StrongholdState.Neutral);
            stronghold.Lvl.Returns((byte)5);
            stronghold.BonusDays.Returns(10);
            stronghold.DateOccupied.Returns(SystemClock.Now.Subtract(TimeSpan.FromDays(10)));

            formula.StrongholdVictoryPoint(stronghold).Should().Be(0);
        }
Пример #4
0
        public void GetNumberOfHits_WhenObjectIsNotSplashEvery200(ICombatObject attacker, ICombatList defenderCombatList)
        {
            var objectTypeFactory = Substitute.For <IObjectTypeFactory>();
            var fixture           = FixtureHelper.Create();

            fixture.Register(() => objectTypeFactory);
            var battleFormulas = fixture.Create <BattleFormulas>();

            objectTypeFactory.IsObjectType(string.Empty, 0).ReturnsForAnyArgs(false);
            attacker.Stats.Splash.Returns((byte)2);
            defenderCombatList.UpkeepExcludingWaitingToJoinBattle.Returns(800);
            battleFormulas.GetNumberOfHits(attacker, defenderCombatList).Should().Be(2);
        }
Пример #5
0
        public void StrongholdMainBattleMeter_WhenNegativeTime(ISystemVariableManager systemVariableManager)
        {
            systemVariableManager["Server.date"].Returns(new SystemVariable("Server.date", DateTime.MaxValue));

            var fixture = FixtureHelper.Create();

            fixture.Register(() => systemVariableManager);
            fixture.Customize <Formula>(c => c.FromFactory(new MethodInvoker(new GreedyConstructorQuery())));

            var formula = fixture.Create <Formula>();

            SystemClock.SetClock(DateTime.MaxValue.Subtract(new TimeSpan(30, 0, 0, 0)));
            formula.StrongholdMainBattleMeter(1).Should().Be(250);
        }
Пример #6
0
        public void StrongholdMainBattleMeter_WhenLessThanOrEqualTo30Days999Hours(ISystemVariableManager systemVariableManager)
        {
            systemVariableManager["Server.date"].Returns(new SystemVariable("Server.date", DateTime.MinValue));

            var fixture = FixtureHelper.Create();

            fixture.Register(() => systemVariableManager);
            fixture.Customize <Formula>(c => c.FromFactory(new MethodInvoker(new GreedyConstructorQuery())));

            var formula = fixture.Create <Formula>();

            SystemClock.SetClock(DateTime.MinValue.Add(new TimeSpan(30, 999, 0, 0)));
            formula.StrongholdMainBattleMeter(1).Should().Be(1996);
        }
Пример #7
0
        public void StrongholdGateLimit_WhenMoreThan30Days1000Hours(ISystemVariableManager systemVariableManager)
        {
            systemVariableManager["Server.date"].Returns(new SystemVariable("Server.date", DateTime.MinValue));

            var fixture = FixtureHelper.Create();

            fixture.Register(() => systemVariableManager);
            fixture.Customize <Formula>(c => c.FromFactory(new MethodInvoker(new GreedyConstructorQuery())));

            var formula = fixture.Create <Formula>();

            SystemClock.SetClock(DateTime.MinValue.Add(new TimeSpan(30, 2000, 0, 0)));
            formula.StrongholdGateLimit(1).Should().Be(20000);
        }
Пример #8
0
        public void TestGateBaseValue(int level, int expectedValue)
        {
            var systemVariableManager = Substitute.For <ISystemVariableManager>();

            systemVariableManager["Server.date"].Returns(new SystemVariable("Server.date", DateTime.MinValue));

            var fixture = FixtureHelper.Create();

            fixture.Register(() => systemVariableManager);

            var formula = fixture.Create <Formula>();

            SystemClock.SetClock(DateTime.MinValue);
            formula.StrongholdGateLimit((byte)level).Should().Be(expectedValue);
        }
Пример #9
0
        public void CityValueShouldReturnProperValue(IEnumerable <IStructure> structures, int expected)
        {
            var fixture = FixtureHelper.Create();

            var objectTypeFactory = fixture.Freeze <IObjectTypeFactory>();

            // Structures with id less than 100 count towards Influence, others dont
            objectTypeFactory.IsStructureType("NoInfluencePoint", Arg.Any <IStructure>())
            .Returns(args => ((IStructure)args[1]).Type >= 100);

            var formula = fixture.Create <Formula>();

            var city = Substitute.For <ICity>();

            city.GetEnumerator().Returns(structures.GetEnumerator());

            formula.CalculateCityValue(city).Should().Be((ushort)expected);
        }
Пример #10
0
        public void TestMoveFromBattleToNormal(TroopStub stub)
        {
            Global.Current = Substitute.For <IGlobal>();
            Global.Current.FireEvents.Returns(false);
            stub.AddFormation(FormationType.Normal);
            stub.AddFormation(FormationType.Garrison);
            stub.AddFormation(FormationType.InBattle);
            stub.AddUnit(FormationType.Normal, 101, 10);

            var fixture   = FixtureHelper.Create();
            var procedure = fixture.Create <CityBattleProcedure>();

            procedure.MoveUnitFormation(stub, FormationType.Normal, FormationType.InBattle);
            procedure.MoveUnitFormation(stub, FormationType.InBattle, FormationType.Normal);

            Assert.True(stub[FormationType.Normal].Type == FormationType.Normal);
            Assert.True(stub[FormationType.InBattle].Type == FormationType.InBattle);
        }
Пример #11
0
        public void GetDmgModifier_WhenOver5Rounds(WeaponType weaponType, ArmorType armorType, double dmg)
        {
            var unitModFactory = Substitute.For <UnitModFactory>();

            var fixture = FixtureHelper.Create();

            fixture.Register(() => unitModFactory);
            var battleFormulas = fixture.Create <BattleFormulas>();

            unitModFactory.GetModifier(0, 0).ReturnsForAnyArgs(1);

            var attacker = Substitute.For <ICombatObject>();
            var defender = Substitute.For <ICombatObject>();

            attacker.Stats.Base.Weapon.Returns(WeaponType.Sword);
            defender.Stats.Base.Armor.Returns(ArmorType.Building1);

            battleFormulas.GetDmgModifier(attacker, defender, 5).Should().Be(1);
        }
Пример #12
0
        public void HiddenResourceWithBasementsShouldProtectResources(byte[] basementLevels,
                                                                      decimal ap,
                                                                      bool checkApBonus,
                                                                      Resource cityResourceLimit,
                                                                      Resource expectedOutput)
        {
            var fixture = FixtureHelper.Create();

            var city = Substitute.For <ICity>();

            var basements = new List <IStructure>();

            foreach (byte basementLevel in basementLevels)
            {
                var basement = Substitute.For <IStructure>();
                basement.Lvl.Returns(basementLevel);
                basements.Add(basement);
            }

            city.GetEnumerator().Returns(args => basements.GetEnumerator());
            city.Resource.Crop.Limit.Returns(cityResourceLimit.Crop);
            city.Resource.Gold.Limit.Returns(cityResourceLimit.Gold);
            city.Resource.Wood.Limit.Returns(cityResourceLimit.Wood);
            city.Resource.Iron.Limit.Returns(cityResourceLimit.Iron);
            city.Resource.Labor.Limit.Returns(cityResourceLimit.Labor);
            city.AlignmentPoint.Returns(ap);

            var objectTypeFactory = fixture.Freeze <IObjectTypeFactory>();

            objectTypeFactory.IsStructureType("Basement", Arg.Any <IStructure>()).Returns(true);

            var formula = fixture.Create <Formula>();

            var hiddenResources = formula.HiddenResource(city, checkApBonus);

            hiddenResources.CompareTo(expectedOutput)
            .Should()
            .Be(0,
                "Expected {0} but found {1}",
                expectedOutput.ToNiceString(),
                hiddenResources.ToNiceString());
        }
Пример #13
0
        public void TestUpkeepValue(int level, int expectedLevel, int expectedUpkeep)
        {
            var systemVariableManager = Substitute.For <ISystemVariableManager>();

            systemVariableManager["Server.date"].Returns(new SystemVariable("Server.date", DateTime.MinValue));

            var fixture = FixtureHelper.Create();

            fixture.Register(() => systemVariableManager);

            var formula = fixture.Create <Formula>();

            SystemClock.SetClock(DateTime.MinValue);

            byte unitLevel;
            int  upkeep;

            formula.StrongholdUpkeep((byte)level, out upkeep, out unitLevel);
            unitLevel.Should().Be((byte)expectedLevel);
            upkeep.Should().Be(expectedUpkeep);
        }