Beispiel #1
0
        public void TestComponentActorConstructionSingleStage()
        {
            var building = new Building()
            {
                Name   = "Test",
                Stages =
                {
                    new Building.Stage()
                    {
                        NeededResources = new Dictionary <string, int>
                        {
                            { "Wood", 2 }
                        },
                        Steps = 2,
                    },
                }
            };

            var siteComponent = new Components.ConstructionSite()
            {
                Building = "Test",
            };

            var testEntity = new Entity("Test")
            {
                siteComponent
            };

            // ReSharper disable once SuggestVarOrType_SimpleTypes
            var minTimeBetweenUpdate = TimeSpan.FromSeconds(ConstructionSiteActor.SecondsBetweenUpdate);

            IActorRef componentActor = Sys.ActorOf(ConstructionSiteActor.Props(siteComponent, building), "TestSiteActor");

            siteComponent.CurrentStageProgress = 1.0f;
            componentActor.Tell(new Update(new Xenko.Games.GameTime(minTimeBetweenUpdate, minTimeBetweenUpdate)));
            ExpectMsg <WaitingForResources>();
            Assert.Equal(1, siteComponent.CurrentStage);
            Assert.Equal(0f, siteComponent.CurrentStageProgress);
            Components.Storage storage  = testEntity.Get <Components.Storage>();
            Building.Stage     curStage = building.Stages[siteComponent.CurrentStage - 1];
            foreach (KeyValuePair <string, int> pair in curStage.NeededResources)
            {
                Assert.Equal(pair.Value, storage.RequestedItems[pair.Key]);
                storage.Items[pair.Key] = pair.Value;
            }
            componentActor.Tell(new Update(new Xenko.Games.GameTime(minTimeBetweenUpdate, minTimeBetweenUpdate)));
            ExpectMsg <BuilderNeeded>();
            componentActor.Tell(new AdvanceProgress());
            ExpectNoMsg(100);
            Assert.NotEqual(0f, siteComponent.CurrentStageProgress);
            Assert.True(siteComponent.CurrentStageProgress < 1f);
            foreach (var _ in Enumerable.Range(0, curStage.Steps))
            {
                componentActor.Tell(new AdvanceProgress());
            }
            ExpectNoMsg(100);
            Assert.True(siteComponent.CurrentStageProgress >= 1.0f);
            componentActor.Tell(new Update(new Xenko.Games.GameTime(minTimeBetweenUpdate, minTimeBetweenUpdate)));
            ExpectMsg <ConstructionFinished>();
        }
Beispiel #2
0
        public void TestComponentActorPreparing()
        {
            var building = new Building()
            {
                Name = "Test"
            };

            var siteComponent = new Components.ConstructionSite()
            {
                Building = "Test",
            };

            // ReSharper disable once SuggestVarOrType_SimpleTypes
            var minTimeBetweenUpdate = TimeSpan.FromSeconds(ConstructionSiteActor.SecondsBetweenUpdate);

            IActorRef componentActor = Sys.ActorOf(ConstructionSiteActor.Props(siteComponent, building), "TestSiteActor");

            componentActor.Tell(new Update(new Xenko.Games.GameTime()));
            componentActor.Tell(new Update(new Xenko.Games.GameTime(minTimeBetweenUpdate, minTimeBetweenUpdate)));
            ExpectMsg <BuilderNeeded>();
            componentActor.Tell(new AdvanceProgress());
            ExpectNoMsg(100);
            Assert.Equal(0.25f, siteComponent.CurrentStageProgress);
            componentActor.Tell(new AdvanceProgress());
            componentActor.Tell(new AdvanceProgress());
            componentActor.Tell(new AdvanceProgress());
            ExpectNoMsg(100);
            Assert.Equal(1.0f, siteComponent.CurrentStageProgress);
        }
Beispiel #3
0
        public void TestComplete()
        {
            var mockComponentActorFactory = new Mock <ComponentActorFactory <Components.ConstructionSite> >(Sys);
            var constructionSite          = new Components.ConstructionSite();
            var buildOrder = new Systems.Orders.Build(constructionSite, mockComponentActorFactory.Object);

            Assert.False(buildOrder.IsComplete(null));
            constructionSite.CurrentStageProgress = 1.0f;
            Assert.True(buildOrder.IsComplete(null));
        }
Beispiel #4
0
        public void TestValid()
        {
            var mockComponentActorFactory = new Mock <ComponentActorFactory <Components.ConstructionSite> >(Sys);
            var constructionSite          = new Components.ConstructionSite();
            var buildOrder = new Systems.Orders.Build(constructionSite, mockComponentActorFactory.Object);
            var entity     = new Entity();

            Assert.False(buildOrder.IsValid(entity));
            entity.Add(new Components.Builder());
            Assert.True(buildOrder.IsValid(entity));
        }
Beispiel #5
0
        private void TestUpdate()
        {
            var entity = new Entity();
            var mockComponentActorFactory = new Mock <ComponentActorFactory <Components.ConstructionSite> >(Sys);

            mockComponentActorFactory.Setup(f => f.GetProps(It.IsAny <Components.ConstructionSite>())).Returns(Props.Create(() => new EntityTestActor()));
            var constructionSite = new Components.ConstructionSite();
            var buildOrder       = new Systems.Orders.Build(constructionSite, mockComponentActorFactory.Object);

            buildOrder.Update(entity, new Xenko.Games.GameTime());
            ExpectNoMsg(100);
            entity.Add(new Components.Builder());
            buildOrder.Update(entity, new Xenko.Games.GameTime());
            ExpectMsg <Systems.Construction.Messages.AdvanceProgress>();
            constructionSite.CurrentStageProgress = 1.0f;
            buildOrder.Update(entity, new Xenko.Games.GameTime());
            ExpectNoMsg(1000);
        }