Ejemplo n.º 1
0
        private void ConfigureMapTiles(MapModel mapModel, MapSerializationModel serializationModel)
        {
            foreach (var tileModel in serializationModel.TileList)
            {
                var mapTile = mapModel.GetTileModel(tileModel.Coords);

                foreach (var indicatorName in tileModel.IndicatorNames)
                {
                    var indicator = _indicatorProvider.GetIndicator(indicatorName, mapTile);
                    indicator.Position = mapTile.Position;
                    mapTile.Indicators.Add(indicator);
                }

                if (!string.IsNullOrWhiteSpace(tileModel.TowerName))
                {
                    var agentArgs = new CreateAgentArgs()
                    {
                        Tile = mapTile,
                        Team = tileModel.Team
                    };

                    var agent = _simulationManager.CreateAgent(tileModel.TowerName, agentArgs);
                    _simulationManager.Register(agent);
                    _simulationManager.Site(agent);
                }
            }
        }
Ejemplo n.º 2
0
        public IExtendedAgent CreateAgent(string name, CreateAgentArgs args)
        {
            if (!_agentModels.TryGetValue(name, out var agentModel))
            {
                throw new ArgumentException($"The agent {name} is not defined");
            }

            /*
             * assemble agent
             */

            // Create a child container for specific, agent-scoped dependencies to be used
            // during the construction of this single agent
            // We make a new scope each time incase one of the components keeps a reference
            var agentContainer = _providerScope.CreateChildContainer();

            agentContainer.RegisterInstance <IUnityContainer>(agentContainer);

            // create agent
            var agent = new AgentBase(name, agentContainer.Resolve <IIndicatorProvider>());

            agentContainer.RegisterInstance <IAgent>(agent);
            agentContainer.RegisterInstance <IExtendedAgent>(agent);

            if (args.Path != null)
            {
                agentContainer.RegisterInstance <IMapPath>(args.Path);
            }

            agent.Tile = args.Tile;
            agent.ExtendedStats.Team = args.Team;

            foreach (var indicatorName in agentModel.IndicatorNames)
            {
                agent.Indicators.Add(GetComponent <IIndicator>(indicatorName, agentContainer));
            }

            foreach (var modifierName in agentModel.ModifierNames)
            {
                agent.AddModifier(GetComponent <IModifier>(modifierName, agentContainer));
            }

            foreach (var commandName in agentModel.CommandNames)
            {
                agent.CommandCollection.Add(GetComponent <IAgentCommand>(commandName, agentContainer));
            }

            // add behaviours
            agent.BehaviourComponent = GetComponent <IUpdatable>(agentModel.PrimaryBehaviourName, agentContainer);

            if (agent.BehaviourComponent is IModifier modifier)
            {
                agent.AddModifier(modifier);
            }

            return(agent);
        }
Ejemplo n.º 3
0
        public void Execute(IExecuteEventArgs args)
        {
            var tile = _agent.Tile;

            // remove current tower
            args.Manager.Remove(_agent);

            // create new tower
            var towerArgs = new CreateAgentArgs()
            {
                Tile = tile
            };

            var tower = args.Manager.CreateAgent(GunTowerBehaviour.AgentTypeName, towerArgs);

            args.Manager.Register(tower);
            args.Manager.Site(tower);
        }
Ejemplo n.º 4
0
        private void InitializeEmitScript(MapModel mapModel, MapSerializationModel serializationModel)
        {
            foreach (var emitScriptEntry in serializationModel.EmitScript)
            {
                for (var i = 0; i < emitScriptEntry.Count; ++i)
                {
                    var agentArgs = new CreateAgentArgs()
                    {
                        Path = mapModel.GetPath(emitScriptEntry.PathName),
                        Tile = mapModel.OffMapTileModel,
                        Team = emitScriptEntry.Team
                    };

                    var offset = emitScriptEntry.BeginTime + (i * emitScriptEntry.DelayTime);
                    var task   = new SpawnAgentTask(offset, emitScriptEntry.AgentTypeName, agentArgs);

                    _simulationManager.Register(task);
                }
            }
        }
Ejemplo n.º 5
0
 public IExtendedAgent CreateAgent(string agentName, CreateAgentArgs createArgs)
 {
     return(_agentProvider.CreateAgent(agentName, createArgs));
 }
Ejemplo n.º 6
0
 public SpawnAgentTask(float offsetTicks, string agentName, CreateAgentArgs createArgs) : base(offsetTicks)
 {
     _agentName  = agentName;
     _createArgs = createArgs;
 }