public uint?ResolveUnitIndex(IUnitData unitData)
        {
            IUnitData[] unitDatas = _unitSpawnSettings.GetUnits(unitData.UnitType);
            for (var i = unitDatas.Length - 1; i >= 0; i--)
            {
                if (unitDatas[i] == unitData)
                {
                    return((uint)i);
                }
            }

            return(null);
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        public void Initialize()
        {
            // If we are loading a replay or edit mode, don't attempt to initially spawn units
            if (_encounterSelectionContext.EncounterType != EncounterType.Combat)
            {
                return;
            }

            if (_mapSectionData.PlayerUnitSpawnPoint == null)
            {
                return;
            }

            // Spawn initial player units
            IUnitData[] playerUnits   = _unitSpawnSettings.GetUnits(UnitType.Player);
            IntVector2  startPosition = _mapSectionData.PlayerUnitSpawnPoint.Value;

            IntVector2[] tilePositions =
                _randomGridPositionProvider.GetRandomUniquePositions(startPosition,
                                                                     _unitSpawnSettings
                                                                     .MaxInitialUnitSpawnDistanceToCenter,
                                                                     playerUnits.Length);
            for (int i = 0; i < tilePositions.Length; i++)
            {
                SpawnUnit(playerUnits[i], tilePositions[i]);
            }
        }
Ejemplo n.º 4
0
        public void Construct(IUnitSpawnSettings unitSpawnSettings,
                              IUnitDataIndexResolver unitDataIndexResolver,
                              IRandomGridPositionProvider randomGridPositionProvider,
                              ICommandQueue commandQueue,
                              IFactory <IUnitData, UnitCommandData> unitCommandDataFactory,
                              ILogger logger)
        {
            _numPlayers = (uint)unitSpawnSettings.GetUnits(UnitType.Player).Length;
            _unitDatas  = unitSpawnSettings.GetUnits(UnitType.Player)
                          .Concat(unitSpawnSettings.GetUnits(UnitType.NonPlayer))
                          .ToArray();

            _unitDataIndexResolver      = unitDataIndexResolver;
            _randomGridPositionProvider = randomGridPositionProvider;
            _commandQueue           = commandQueue;
            _unitCommandDataFactory = unitCommandDataFactory;
            _logger = logger;

            Preconditions.CheckNotNull(_dropdown, _spawnButton, _cancelButton, _unitAmountDropdown);
        }