Beispiel #1
0
        public IObservable <UniRx.Unit> Run()
        {
            IUnitData[] unitDatas = _unitSpawnSettings.GetUnits(_data.unitCommandData.UnitType);
            if (_data.unitCommandData.UnitIndex >= unitDatas.Length)
            {
                string errorMsg = string.Format("Unit Index not in unit datas range: {0}",
                                                _data.unitCommandData.UnitIndex);
                _logger.LogError(LoggedFeature.Units, errorMsg);
                return(Observable.Throw <UniRx.Unit>(new IndexOutOfRangeException(errorMsg)));
            }

            IUnitData unitData = unitDatas[(int)_data.unitCommandData.UnitIndex];

            // First, spawn the pets recursively.
            // We create commands that we execute directly, because
            // we don't want to treat these as standalone commands (they are only ever children of this command)
            IUnit[] pets = new IUnit[_data.unitCommandData.pets.Length];
            for (var i = 0; i < _data.unitCommandData.pets.Length; i++)
            {
                SpawnUnitData petSpawnUnitData =
                    new SpawnUnitData(_data.unitCommandData.pets[i], _data.tileCoords, _data.isInitialSpawn);
                ICommand petSpawnCommand =
                    _commandFactory.Create(typeof(SpawnUnitCommand), typeof(SpawnUnitData), petSpawnUnitData);
                petSpawnCommand.Run();
                pets[i] = _unitRegistry.GetUnit(_data.unitCommandData.pets[i].unitId);
            }

            // Now, spawn the unit itself.
            IUnit unit = _unitPool.Spawn(_data.unitCommandData.unitId, unitData, pets);

            _gridUnitManager.PlaceUnitAtTile(unit, _data.tileCoords);

            _logger.Log(LoggedFeature.Units, "Spawned: {0}. Id: {1}", unitData.Name, unit.UnitId);
            return(Observable.ReturnUnit());
        }
Beispiel #2
0
 public SpawnUnitCommand(SpawnUnitData data,
                         ICommandFactory commandFactory,
                         IUnitSpawnSettings unitSpawnSettings,
                         IMutableUnitRegistry unitRegistry,
                         IGridUnitManager gridUnitManager,
                         IUnitPool unitPool,
                         ILogger logger)
 {
     _data              = data;
     _commandFactory    = commandFactory;
     _unitSpawnSettings = unitSpawnSettings;
     _unitRegistry      = unitRegistry;
     _gridUnitManager   = gridUnitManager;
     _unitPool          = unitPool;
     _logger            = logger;
 }