Exemple #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>();
        }
Exemple #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);
        }