Exemple #1
0
        public void Undo()
        {
            // Undo is not supported for player units.
            // We may want to consider splitting this command in two: Spawn initial unit / Spawn unit
            if (_data.unitCommandData.UnitType == UnitType.Player)
            {
                _logger.Log(LoggedFeature.Replays, "Not undoing command since unit type is player.");
                return;
            }

            // Despawn pets first.
            // We need to directly run the command since these are children of the parent spawn unit command,
            // and should never be ran as standalone
            for (var i = 0; i < _data.unitCommandData.pets.Length; i++)
            {
                ICommand petSpawnCommand =
                    _commandFactory.Create(typeof(SpawnUnitCommand),
                                           typeof(SpawnUnitData),
                                           new SpawnUnitData(_data.unitCommandData.pets[i],
                                                             _data.tileCoords,
                                                             _data.isInitialSpawn));
                petSpawnCommand.Undo();
            }

            // Now the unit itself.
            IUnit unit = _unitRegistry.GetUnit(_data.unitCommandData.unitId);

            _unitPool.Despawn(unit.UnitId);
            _gridUnitManager.RemoveUnit(unit);
        }
Exemple #2
0
        public IObservable <UniRx.Unit> Run()
        {
            _unit = _unitRegistry.GetUnit(_data.unitId);
            if (_unit == null)
            {
                string errorMsg = $"Unit not found: {_data.unitId}";
                _logger.LogError(LoggedFeature.Units, errorMsg);
                return(Observable.Throw <UniRx.Unit>(new IndexOutOfRangeException(errorMsg)));
            }

            _tileCoords = _gridUnitManager.GetUnitCoords(_unit);

            // Only despawn the unit. This does not remove pet units.
            _logger.Log(LoggedFeature.Units, "Despawning: {0}", _unit.UnitId);
            _unitPool.Despawn(_unit.UnitId);
            _gridUnitManager.RemoveUnit(_unit);

            return(Observable.ReturnUnit());
        }