Beispiel #1
0
        public void OnUpdate()
        {
            if (_mapGrid == null || OnDestroyCallback == null)
            {
                return;
            }

            Vector3 unitPosition = transform.position;

            //Update map information
            TileNode standTile = FindValidStandPosition(unitPosition);

            if (standTile.TilemapMember != null && standTile.GridIndex != _currentTile.GridIndex)
            {
                if (_currentTile.TilemapMember != null)
                {
                    _mapGrid.EditUnitState(_currentTile.GridIndex.x, _currentTile.GridIndex.y, this, false);
                }

                _mapGrid.EditUnitState(standTile.GridIndex.x, standTile.GridIndex.y, this, true);
            }

            //Add self under mapObject
            BlockComponent blockComponent = _mapBlockManager.GetMapComponentByPos(unitPosition);

            if (blockComponent != null && currentBlockComp != blockComponent)
            {
                if (currentBlockComp == null || (!currentBlockComp.isMoving && !blockComponent.isMoving))
                {
                    currentBlockComp = blockComponent;

                    this.transform.SetParent(currentBlockComp.unitHolder);
                }
            }

            UpdateActiveState(currentBlockComp);

            if (currentState == ActiveState.Action)
            {
                //Fallback function
                if (_strategy == null)
                {
                    AgentMove();
                }
                else
                {
                    //_strategy shouldn't put any where but here, all units share the same strategy object
                    _strategy.SetUp(this, _uniqueUnitID, _monsterStats, _mapGrid, _gameDamageManager);

                    _currentStrategy = _strategy.Think(_currentTile, _currentStrategy);

                    _strategy.Execute(_currentTile, _currentStrategy);
                }
            }

            _currentTile = standTile;
        }
Beispiel #2
0
        private async void SelectTowerToBuild(string tower_id)
        {
            if (IsTileNodeValid(currentSelectedNode))
            {
                TowerStats towerStats = _statHolder.FindObject <TowerStats>(tower_id);

                //No money
                if (_levelDesignManager.selfPlayer.capital < towerStats.cost)
                {
                    return;
                }


                var tower = PoolManager.instance.ReuseObject(VariableFlag.Pooling.TowerID);

                if (tower != null)
                {
                    tower.transform.position = currentSelectedNode.WorldSpace;

                    BlockComponent mapBlock  = _mapBlockManager.GetMapComponentByPos(currentSelectedNode.WorldSpace);
                    STPTower       stpTower  = _stpTheme.FindObject <STPTower>(VariableFlag.Pooling.TowerID);
                    TowerUnit      towerUnit = tower.GetComponent <TowerUnit>();

                    if (stpTower != null && towerUnit != null && mapBlock != null && towerStats != null)
                    {
                        tower.transform.SetParent(mapBlock.unitHolder);
                        towerUnit.SetUp(towerStats, stpTower,
                                        _mapGrid, _levelDesignManager.selfPlayer,
                                        (UnitInterface projectile, GameDamageManager.DMGRegistry dmgRistry) =>
                        {
                            _gameUnitManager.AddUnit(projectile);
                            _gameUnitManager.gameDamageManager.AddRequest(dmgRistry);
                        });

                        _gameUnitManager.AddUnit(towerUnit);
                        isTaskDone = true;
                    }
                }
            }
        }