コード例 #1
0
        /// <summary>
        /// 重新生成移动消耗
        /// </summary>
        public void RecreateMoveConsumption()
        {
            // TODO 在构造函数内部用的Random初始化,
            // 有了数据后,这个地方将进行修改
            m_MoveConsumption = new MoveConsumption(ClassType.Knight1);

            Debug.LogFormat("{0}={1}, {2}={3}",
                            TerrainType.Plain.ToString(),
                            m_MoveConsumption[TerrainType.Plain].ToString(),
                            TerrainType.Road.ToString(),
                            m_MoveConsumption[TerrainType.Road].ToString());
        }
コード例 #2
0
ファイル: MapGraph.cs プロジェクト: wschinasl/book_srpg_dev
        /// <summary>
        /// 搜寻路径
        /// </summary>
        /// <param name="startCell"></param>
        /// <param name="endCell"></param>
        /// <param name="consumption"></param>
        /// <returns></returns>
        public List <CellData> SearchPath(CellData startCell, CellData endCell, MoveConsumption consumption)
        {
            if (findPathDirect == null)
            {
                Debug.LogError("Error: Find path is null.");
                return(null);
            }

            if (!m_SearchPath.SearchPath(findPathDirect, startCell, endCell, consumption))
            {
                Debug.LogError("Error: Search Path Error. Maybe some cells are out of range.");
                return(null);
            }

            return(m_SearchPath.result);
        }
コード例 #3
0
        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            m_Reachable.Clear();
            m_Explored.Clear();
            m_Result.Clear();

            m_Range           = Vector2.zero;
            m_StartCell       = null;
            m_EndCell         = null;
            m_CurrentCell     = null;
            m_Finished        = false;
            m_HowToFind       = null;
            m_MoveConsumption = null;

            m_SearchCount = 0;
        }
コード例 #4
0
ファイル: MapGraph.cs プロジェクト: wschinasl/book_srpg_dev
        /// <summary>
        /// 搜寻移动范围
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="movePoint"></param>
        /// <param name="consumption"></param>
        /// <returns></returns>
        public List <CellData> SearchMoveRange(CellData cell, float movePoint, MoveConsumption consumption)
        {
            if (findMoveRange == null)
            {
                Debug.LogError("Error: Find move range is null.");
                return(null);
            }

            if (!m_SearchPath.SearchMoveRange(findMoveRange, cell, movePoint, consumption))
            {
                Debug.LogErrorFormat("Error: Move Range({0}) is Not Found.", 5f);
                return(null);
            }

            return(m_SearchPath.result);
        }
コード例 #5
0
ファイル: PathFinding.cs プロジェクト: QAQrzj/FireEmblem
        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            reachable.Clear();
            explored.Clear();
            result.Clear();

            range           = Vector2.zero;
            startCell       = null;
            endCell         = null;
            currentCell     = null;
            finished        = false;
            howToFind       = null;
            moveConsumption = null;

            searchCount = 0;
        }
コード例 #6
0
        /// <summary>
        /// 寻找移动范围
        /// </summary>
        /// <param name="howToFind"></param>
        /// <param name="start"></param>
        /// <param name="movePoint"></param>
        /// <param name="consumption"></param>
        /// <returns></returns>
        public bool SearchMoveRange(IHowToFind howToFind, CellData start, float movePoint, MoveConsumption consumption)
        {
            if (howToFind == null || start == null || movePoint < 0)
            {
                return(false);
            }

            Reset();

            m_HowToFind       = howToFind;
            m_MoveConsumption = consumption;

            m_StartCell = start;
            m_StartCell.ResetAStar();
            m_Range.y = movePoint;

            m_Reachable.Add(m_StartCell);

            return(SearchRangeInternal());
        }
コード例 #7
0
ファイル: PathFinding.cs プロジェクト: QAQrzj/FireEmblem
        public bool SearchPath(IHowToFind howToFind, CellData start, CellData end, MoveConsumption consumption)
        {
            if (howToFind == null || start == null || end == null)
            {
                return(false);
            }

            Reset();

            this.howToFind  = howToFind;
            moveConsumption = consumption;
            startCell       = start;
            startCell.ResetAStar();
            endCell = end;
            endCell.ResetAStar();

            reachable.Add(startCell);

            startCell.H = this.howToFind.CalcH(this, startCell);

            return(SearchRangeInternal());
        }
コード例 #8
0
        /// <summary>
        /// 搜寻路径
        /// </summary>
        /// <param name="howToFind"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="consumption"></param>
        /// <returns></returns>
        public bool SearchPath(IHowToFind howToFind, CellData start, CellData end, MoveConsumption consumption = null)
        {
            if (howToFind == null || start == null || end == null)
            {
                return(false);
            }

            Reset();

            m_HowToFind       = howToFind;
            m_MoveConsumption = consumption;

            m_StartCell = start;
            m_StartCell.ResetAStar();
            m_EndCell = end;
            m_EndCell.ResetAStar();

            m_Reachable.Add(m_StartCell);

            m_StartCell.h = m_HowToFind.CalcH(this, m_StartCell);

            return(SearchRangeInternal());
        }
コード例 #9
0
ファイル: MapGraph.cs プロジェクト: wschinasl/book_srpg_dev
        /// <summary>
        /// 搜寻移动范围与攻击范围
        /// </summary>
        /// <param name="cls"></param>
        /// <param name="nAtk">是否包含攻击范围</param>
        /// <param name="moveCells"></param>
        /// <param name="atkCells"></param>
        /// <returns></returns>
        public bool SearchMoveRange(
            MapClass cls,
            bool nAtk,
            out IEnumerable <CellData> moveCells,
            out IEnumerable <CellData> atkCells)
        {
            moveCells = null;
            atkCells  = null;

            if (cls == null)
            {
                Debug.LogError("MapGraph -> SearchMoveRange: `cls` is null.");
                return(false);
            }

            CellData cell = GetCellData(cls.cellPosition);

            if (cell == null)
            {
                Debug.LogError("MapGraph -> SearchMoveRange: `cls.cellPosition` is out of range.");
                return(false);
            }

            // 搜索移动范围,从MapClass中读取数据
            Role role = cls.role;

            if (role == null)
            {
                Debug.LogErrorFormat(
                    "MapGraph -> SearchMoveRange: `cls.role` is null. Pos: {0}",
                    cell.position.ToString());
                return(false);
            }

            float           movePoint   = role.movePoint;
            MoveConsumption consumption = role.cls.moveConsumption;

            List <CellData> rangeCells = SearchMoveRange(cell, movePoint, consumption);

            if (rangeCells == null)
            {
                return(false);
            }

            HashSet <CellData> moveRangeCells = new HashSet <CellData>(
                rangeCells, cellPositionEqualityComparer);

            moveCells = moveRangeCells;

            if (nAtk && role.equipedWeapon != null /* 是否有武器 */)
            {
                // 搜索攻击范围,从MapClass中读取数据
                Vector2Int atkRange = new Vector2Int(
                    role.equipedWeapon.uniqueInfo.minRange,
                    role.equipedWeapon.uniqueInfo.maxRange);

                HashSet <CellData> atkRangeCells = new HashSet <CellData>(cellPositionEqualityComparer);
                foreach (CellData moveCell in moveRangeCells)
                {
                    rangeCells = SearchAttackRange(moveCell, atkRange.x, atkRange.y, true);

                    if (rangeCells == null)
                    {
                        return(false);
                    }

                    if (rangeCells.Count > 0)
                    {
                        atkRangeCells.UnionWith(rangeCells.Where(c => !moveRangeCells.Contains(c)));
                    }
                }

                atkCells = atkRangeCells;
            }

            return(true);
        }
コード例 #10
0
ファイル: MapGraph.cs プロジェクト: wschinasl/book_srpg_dev
        /// <summary>
        /// 搜寻移动范围与攻击范围
        /// </summary>
        /// <param name="cls"></param>
        /// <param name="nAtk">是否包含攻击范围</param>
        /// <param name="moveCells"></param>
        /// <param name="atkCells"></param>
        /// <returns></returns>
        public bool SearchMoveRange(
            MapClass cls,
            bool nAtk,
            out IEnumerable <CellData> moveCells,
            out IEnumerable <CellData> atkCells)
        {
            moveCells = null;
            atkCells  = null;

            if (cls == null)
            {
                Debug.LogErrorFormat("MapGraph -> SearchMoveRange: `cls` is null.");
                return(false);
            }

            CellData cell = GetCellData(cls.cellPosition);

            if (cell == null)
            {
                Debug.LogErrorFormat("MapGraph -> SearchMoveRange: `cls.cellPosition` is out of range.");
                return(false);
            }

            // TODO 搜索移动范围,从MapClass中读取数据
            float           movePoint   = 0;
            MoveConsumption consumption = null;

            List <CellData> rangeCells = SearchMoveRange(cell, movePoint, consumption);

            if (rangeCells == null)
            {
                return(false);
            }

            moveCells = rangeCells.ToArray();

            if (nAtk /* TODO && 是否有武器 */)
            {
                // TODO 搜索攻击范围,从MapClass中读取数据
                Vector2Int atkRange = Vector2Int.one;

                HashSet <CellData> atkRangeCells = new HashSet <CellData>(cellPositionEqualityComparer);
                foreach (CellData moveCell in moveCells)
                {
                    rangeCells = SearchAttackRange(moveCell, atkRange.x, atkRange.y, true);

                    if (rangeCells == null)
                    {
                        return(false);
                    }

                    if (rangeCells.Count > 0)
                    {
                        atkRangeCells.UnionWith(rangeCells.Where(c => !c.hasCursor));
                    }
                }

                atkCells = atkRangeCells;
            }

            return(true);
        }