Esempio n. 1
0
 public void GetXForYTotal_WhenNoEffect_ShouldReturnPaidFor(Formula formula, ITechnologyManager technologyManager)
 {
     technologyManager.GetEffects(EffectCode.XFor1, EffectInheritance.Invisible).Returns(new List <Effect>());
     formula.GetXForYTotal(technologyManager, 0).Should().Be(0);
     formula.GetXForYTotal(technologyManager, 1).Should().Be(1);
     formula.GetXForYTotal(technologyManager, 99).Should().Be(99);
 }
Esempio n. 2
0
        public void TrainTime_WhenNoDiscount_ShouldNotLowerTime(int baseTime,
                                                                int expected,
                                                                ITechnologyManager techManager,
                                                                IBaseUnitStats baseUnitStats,
                                                                ICity city,
                                                                Formula formula)
        {
            city.Troops.Upkeep.Returns(15);
            baseUnitStats.BuildTime.Returns(100);

            // Act
            formula.TrainTime(1, 1, baseUnitStats).Should().Be(100);
        }
Esempio n. 3
0
        public void TrainTime_WhenHasDiscount_ShouldLowerTime(int baseTime,
                                                              int structureLevel,
                                                              int expected,
                                                              ITechnologyManager techManager,
                                                              ICity city,
                                                              IBaseUnitStats baseUnitStats,
                                                              Formula formula)
        {
            techManager.GetEffects(0).ReturnsForAnyArgs(new List <Effect>());
            baseUnitStats.BuildTime.Returns(baseTime);

            formula.TrainTime(structureLevel, 2, baseUnitStats).Should().Be(expected * 2);
        }
Esempio n. 4
0
        /// <summary>
        ///     Returns the total unit for the price of paidFor
        /// </summary>
        /// <param name="tech"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public virtual int GetXForYPaidFor(ITechnologyManager tech, int total)
        {
            var effects = tech.GetEffects(EffectCode.XFor1, EffectInheritance.Invisible);

            if (effects.Count == 0)
            {
                return(total);
            }

            var effect = effects.OrderByDescending(x => (decimal)(int)x.Value[0] / (int)x.Value[1]).First();

            return((int)Math.Ceiling((decimal)total / (int)effect.Value[0] * (int)effect.Value[1]));
        }
Esempio n. 5
0
 public Structure(uint structureId,
                  IStructureStats stats,
                  uint x,
                  uint y,
                  string theme,
                  ITechnologyManager technologyManager,
                  StructureProperties structureProperties,
                  IDbManager dbManager) : base(structureId, x, y)
 {
     Theme          = theme;
     this.stats     = stats;
     this.dbManager = dbManager;
     techmanager    = technologyManager;
     properties     = structureProperties;
 }
Esempio n. 6
0
 private void OnTechnologyCleared(ITechnologyManager manager)
 {
     TechnologyCleared(this, new TechnologyEventArgs {
         TechnologyManager = manager
     });
 }
Esempio n. 7
0
        public City(uint id,
                    IPlayer owner,
                    string name,
                    Position position,
                    ILazyResource resource,
                    byte radius,
                    decimal ap,
                    string defaultTheme,
                    string roadTheme,
                    string troopTheme,
                    string wallTheme,
                    IActionWorker worker,
                    CityNotificationManager notifications,
                    IReferenceManager references,
                    ITechnologyManager technologies,
                    ITroopManager troops,
                    IUnitTemplate template,
                    ITroopStubFactory troopStubFactory,
                    IDbManager dbManager,
                    IGameObjectFactory gameObjectFactory,
                    IActionFactory actionFactory,
                    BattleProcedure battleProcedure)
        {
            Id                     = id;
            Owner                  = owner;
            this.name              = name;
            this.radius            = radius;
            this.troopStubFactory  = troopStubFactory;
            this.dbManager         = dbManager;
            this.gameObjectFactory = gameObjectFactory;
            this.actionFactory     = actionFactory;
            this.battleProcedure   = battleProcedure;

            PrimaryPosition = position;
            AlignmentPoint  = ap;
            DefaultTheme    = defaultTheme;
            RoadTheme       = roadTheme;
            WallTheme       = wallTheme;
            TroopTheme      = troopTheme;
            Resource        = resource;

            Worker        = worker;
            Notifications = notifications;
            References    = references;
            Technologies  = technologies;
            Troops        = troops;
            Template      = template;

            #region Event Proxies

            Template.UnitUpdated += evtTemplate =>
            {
                if (Global.Current.FireEvents && DbPersisted)
                {
                    dbManager.Save(evtTemplate);
                }

                UnitTemplateUpdated(this, new EventArgs());
            };

            Troops.TroopAdded += stub => TroopAdded(this, new TroopStubEventArgs {
                Stub = stub
            });
            Troops.TroopRemoved += stub => TroopRemoved(this, new TroopStubEventArgs {
                Stub = stub
            });
            Troops.TroopUpdated += stub => TroopUpdated(this, new TroopStubEventArgs {
                Stub = stub
            });
            Troops.TroopUnitUpdated += stub => TroopUnitUpdated(this, new TroopStubEventArgs {
                Stub = stub
            });

            Worker.ActionRemoved += (stub, state) => ActionRemoved(this, new ActionWorkerEventArgs {
                State = state, Stub = stub
            });
            Worker.ActionStarted += (stub, state) => ActionStarted(this, new ActionWorkerEventArgs {
                State = state, Stub = stub
            });
            Worker.ActionRescheduled += (stub, state) => ActionRescheduled(this, new ActionWorkerEventArgs {
                State = state, Stub = stub
            });

            Resource.ResourcesUpdate += () =>
            {
                CheckUpdateMode();
                ResourcesUpdated(this, new EventArgs());
            };

            Technologies.TechnologyCleared  += OnTechnologyCleared;
            Technologies.TechnologyAdded    += OnTechnologyAdded;
            Technologies.TechnologyRemoved  += OnTechnologyRemoved;
            Technologies.TechnologyUpgraded += OnTechnologyUpgraded;

            References.ReferenceAdded   += (sender, args) => ReferenceAdded(this, args);
            References.ReferenceRemoved += (sender, args) => ReferenceRemoved(this, args);

            #endregion
        }
Esempio n. 8
0
 public virtual byte GetTroopRadius(ITroopStub stub, ITechnologyManager em)
 {
     // The radius is based on the sum of levels of the structures in the city, from 0 to 4
     return((byte)Math.Min(stub.City.Value / 40, 4));
 }
Esempio n. 9
0
        public virtual int BuildTime(int baseValue, ICity city, ITechnologyManager em)
        {
            IStructure university = city.FirstOrDefault(structure => ObjectTypeFactory.IsStructureType("University", structure));

            return((int)(baseValue * (100 - (university == null ? 0 : university.Stats.Labor) * 0.25) / 100));
        }
Esempio n. 10
0
        public void GetXForYTotal_WhenMultipleEffects_ShouldUseTheHighestValue(Formula formula, ITechnologyManager technologyManager)
        {
            var effects = new List <Effect>
            {
                new Effect
                {
                    Id        = EffectCode.XFor1,
                    IsPrivate = true,
                    Location  = EffectLocation.Object,
                    Value     = new object[] { 5, 3 }
                },
                new Effect
                {
                    Id        = EffectCode.XFor1,
                    IsPrivate = true,
                    Location  = EffectLocation.Object,
                    Value     = new object[] { 2, 1 }
                },
                new Effect
                {
                    Id        = EffectCode.XFor1,
                    IsPrivate = true,
                    Location  = EffectLocation.Object,
                    Value     = new object[] { 3, 2 }
                }
            };

            technologyManager.GetEffects(EffectCode.XFor1, EffectInheritance.Invisible).Returns(effects);
            formula.GetXForYTotal(technologyManager, 100).Should().Be(200);
        }
Esempio n. 11
0
        public void GetXForYTotal_WhenXForY(int x, int y, int paidForCount, int expectTotalCount, Formula formula, ITechnologyManager technologyManager)
        {
            var effect = new Effect
            {
                Id        = EffectCode.XFor1,
                IsPrivate = true,
                Location  = EffectLocation.Object,
                Value     = new object[] { x, y }
            };

            technologyManager.GetEffects(EffectCode.XFor1, EffectInheritance.Invisible).Returns(new List <Effect> {
                effect
            });
            formula.GetXForYTotal(technologyManager, paidForCount).Should().Be(expectTotalCount);
        }
Esempio n. 12
0
        public void UserCancelled_WhenUserHasDifferentTechnologies_ShouldRefundCorrectAmount(
            UserCancelledTestData testData,
            [FrozenMock] Formula formula,
            [FrozenMock] UnitFactory unitFactory,
            [Frozen] IWorld world,
            ICity city,
            IStructure structure,
            ITechnologyManager technologyManager)
        {
            ushort trainedCount = 0;

            formula.GetInstantTrainCount(structure).ReturnsForAnyArgs(testData.InstantTrainCount);
            formula.GetXForYTotal(technologyManager, testData.TrainCount).Returns(testData.TotalCount);
            formula.GetXForYPaidFor(technologyManager, testData.InstantTrainCount + testData.CompletedTraining).Returns(testData.TotalPaidFor);
            formula.UnitTrainCost(city, 100, 0).Returns(testData.CostPerUnit);
            formula.GetActionCancelResource(DateTime.MinValue, null)
            .ReturnsForAnyArgs(c => c.Arg <Resource>());

            city.DefaultTroop.When(m => m.AddUnit(FormationType.Normal, 100, Arg.Any <ushort>()))
            .Do(args =>
            {
                trainedCount += (ushort)args[2];
            });

            city.Resource.HasEnough(testData.TotalCost).ReturnsForAnyArgs(true);
            city.Id.Returns <uint>(1);

            structure.City.Returns(city);
            structure.Technologies.Returns(technologyManager);

            IStructure outStructure;
            ICity      outCity;

            city.TryGetStructure(10, out outStructure).Returns(args =>
            {
                args[1] = structure;
                return(true);
            });

            world.TryGetObjects(1, 10, out outCity, out outStructure).Returns(args =>
            {
                args[2] = city;
                args[3] = structure;
                return(true);
            });

            var gameObjectLocator = new GameObjectLocatorStub(city);
            var locker            = new LockerStub(gameObjectLocator);

            var action = new UnitTrainActiveAction(1, 10, 100, testData.TrainCount, unitFactory, locker, world, formula);

            action.WorkerObject = Substitute.For <ICanDo>();

            action.Execute();

            action.ActionCount.Should().Be(testData.ExpectedQueuedCount);

            city.Resource.Received(1).Subtract(testData.TotalCost);

            for (var i = 0; i < testData.CompletedTraining; i++)
            {
                action.Callback(null);
            }

            action.UserCancelled();

            city.Resource.Received(1).Add(testData.ExpectedRefundAmount);

            trainedCount.Should().Be(testData.ExpectedCityReceivedCount);
        }