Example #1
0
        public void SetupScenario(string name, out SimulationLifecycleManager lifecycleManager, out NodeConfig[] nodeConfigs)
        {
            // Arrange
            var nodeLeft = new NodeConfig
            {
                Name      = "00",
                X         = 0,
                Y         = 0,
                Archetype = SubsystemNode.Archetype,
            };

            var nodeRight = new NodeConfig()
            {
                Name      = "10",
                X         = 1,
                Y         = 0,
                Archetype = SubsystemNode.Archetype,
            };

            nodeConfigs = new []
            {
                nodeLeft,
                nodeRight
            };

            SetupScenario(name, out lifecycleManager, nodeConfigs);
        }
Example #2
0
        private void CreateItem(string itemType, EntityConfig node, SimulationLifecycleManager lifecycleManager, out ComponentEntityTuple <IItemType, CurrentLocation> item, out int itemContainerIndex, out ItemContainer itemContainer)
        {
            // store current match
            var itemLocationMatcher        = lifecycleManager.ECSRoot.ECS.MatcherProvider.CreateMatcherGroup <IItemType, CurrentLocation>();
            var priorMatchignEntitiesTotal = itemLocationMatcher.MatchingEntities.Length;

            // Add Items to swap
            var createItem = new CreateItem(TutorialScanner.Archetype.Name,
                                            node);

            createItem.Execute(lifecycleManager.ECSRoot.ECS,
                               lifecycleManager.ECSRoot.Configuration);

            // Tick so commands get processed
            lifecycleManager.ECSRoot.ECS.Tick();

            item = itemLocationMatcher.MatchingEntities[priorMatchignEntitiesTotal];

            // Get the subsystem the item's current location is set to
            var systemWithStorageMatcher = lifecycleManager.ECSRoot.ECS.MatcherProvider.CreateMatcherGroup <Subsystem, ItemStorage>();

            systemWithStorageMatcher.TryGetMatchingEntity(item.Component2.Value.Value,
                                                          out var subsystemTuple);

            var itemLocal = item;

            itemContainerIndex = Array.FindIndex(subsystemTuple.Component2.Items,
                                                 ic => ic.Item == itemLocal.Entity.Id);

            itemContainer = subsystemTuple.Component2.Items[itemContainerIndex];
        }
Example #3
0
        private SimulationLifecycleManager InitializeSimulationRoot()
        {
            if (string.IsNullOrEmpty(RoomSettings.GameScenario) == false)
            {
                if (_scenarioLoader.TryGetScenario(RoomSettings.GameScenario, out var scenario))
                {
                    // add the database event logger
                    scenario.Configuration.Systems.Add(new SystemConfiguration <DatabaseEventLogger>());
                    scenario.Configuration.GameName            = RoomSettings.GameName;
                    scenario.Configuration.PlayerConfiguration = PlayerManager.Players.Select((p, i) =>
                    {
                        var playerConfig        = scenario.PlayerConfigFactory.GetNextPlayerConfig(i);
                        playerConfig.ExternalId = p.PhotonId;
                        playerConfig.Identifiers.Add(Identifiers.SUGAR, p.Name);
                        if (string.IsNullOrEmpty(p.RageClassId) == false)
                        {
                            playerConfig.Identifiers.Add(Identifiers.RAGE_CLASS, p.RageClassId);
                        }
                        playerConfig.Name   = p.Name;
                        playerConfig.Colour = p.Colour;
                        playerConfig.Glyph  = p.Glyph;
                        return(playerConfig);
                    }).ToList();

                    return(SimulationLifecycleManager.Initialize(scenario));
                }
            }

            throw new SimulationException("Could not load scenario");
        }
Example #4
0
 public InitializingState(SimulationLifecycleManager simulationLifecycleManager,
                          PluginBase photonPlugin,
                          Messenger messenger,
                          ITAlertPlayerManager playerManager,
                          RoomSettings roomSettings,
                          AnalyticsServiceManager analytics)
     : base(photonPlugin, messenger, playerManager, roomSettings, analytics)
 {
     _simulationLifecycleManager = simulationLifecycleManager;
 }
        private void AssignToPlayer(int playerId, int itemId, SimulationLifecycleManager lifecycleManager, out ComponentEntityTuple <ITAlert.Simulation.Components.EntityTypes.Player, ItemStorage, CurrentLocation> playerTuple)
        {
            var swapCommand = new PickupItemCommand
            {
                PlayerId = playerId,
                ItemId   = itemId
            };

            lifecycleManager.ECSRoot.ECS.EnqueueCommand(swapCommand);

            lifecycleManager.ECSRoot.ECS.Tick();

            GetPlayerTuple(playerId, lifecycleManager, out playerTuple);

            Assert.NotNull(playerTuple.Component2.Items[0].Item);
            Assert.AreEqual(playerTuple.Component2.Items[0].Item.Value, itemId);
        }
Example #6
0
        private void CreatePlayer(string name, EntityConfig node, SimulationLifecycleManager lifecycleManager, out ComponentEntityTuple <ITAlert.Simulation.Components.EntityTypes.Player> player)
        {
            var playerMatcher             = lifecycleManager.ECSRoot.ECS.MatcherProvider.CreateMatcherGroup <ITAlert.Simulation.Components.EntityTypes.Player>();
            var priorMatchingEntitesTotal = playerMatcher.MatchingEntities.Length;

            // Create a NPC to initiate the swap action
            var createNpc = new CreatePlayer(Player.Archetype,
                                             node,
                                             name);

            createNpc.Execute(lifecycleManager.ECSRoot.ECS,
                              lifecycleManager.ECSRoot.Configuration);

            // Tick so commands get processed
            lifecycleManager.ECSRoot.ECS.Tick();

            player = playerMatcher.MatchingEntities[priorMatchingEntitesTotal];
        }
Example #7
0
        public void SetupScenario(string name, out SimulationLifecycleManager lifecycleManager, NodeConfig[] nodeConfigs)
        {
            ConfigurationHelper.ProcessNodeConfigs(nodeConfigs);
            var edgeConfigs = ConfigurationHelper.GenerateFullyConnectedConfiguration(nodeConfigs, 1);

            var archetypes = new List <Archetype>
            {
                SubsystemNode.Archetype,
                ConnectionNode.Archetype,
                Player.Archetype,
                TutorialScanner.Archetype,
                AntivirusWorkstation.Archetype,
                AnalyserActivator.Archetype,
                AntivirusTool.Archetype,
            };

            var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs,
                                                                          edgeConfigs,
                                                                          null,
                                                                          archetypes);

            var scenarioInfo = new ScenarioInfo
            {
                Description            = name,
                Key                    = name,
                LocalizationDictionary = null,
                MaxPlayerCount         = 1,
                MinPlayerCount         = 1,
                Name                   = name
            };

            var scenario = new SimulationScenario(scenarioInfo)
            {
                Configuration = configuration,
                Sequence      = new List <SequenceFrame <Simulation, SimulationConfiguration> >(),
            };

            lifecycleManager = SimulationLifecycleManager.Initialize(scenario);
        }
Example #8
0
        private bool GetSubsystemItemStorage(EntityConfig node, SimulationLifecycleManager lifecycleManager, out ComponentEntityTuple <Subsystem, ItemStorage> subsystemTuple)
        {
            var systemWithStorageMatcher = lifecycleManager.ECSRoot.ECS.MatcherProvider.CreateMatcherGroup <Subsystem, ItemStorage>();

            return(systemWithStorageMatcher.TryGetMatchingEntity(node.EntityId, out subsystemTuple));
        }
        private void GetPlayerTuple(int playerId, SimulationLifecycleManager lifecycleManager, out ComponentEntityTuple <ITAlert.Simulation.Components.EntityTypes.Player, ItemStorage, CurrentLocation> playerTuple)
        {
            var itemLocationMatcher = lifecycleManager.ECSRoot.ECS.MatcherProvider.CreateMatcherGroup <ITAlert.Simulation.Components.EntityTypes.Player, ItemStorage, CurrentLocation>();

            itemLocationMatcher.TryGetMatchingEntity(playerId, out playerTuple);
        }