Exemplo n.º 1
0
    public bool MoveTo(HexCell destination, int distance = 0)
    {
        if (isMoving)
        {
            Debug.LogError("当前正在移动,不可以发出新的移动指令");
            return(false);
        }

        List <HexCell> path = null;

        if (distance == 0)
        {
            HexRoom.HexCellPaths allPath = LevelManager.room.hexRoom.GetAvailableDestinations(entity.centerCell, m_PropertyComponent.movePoint);
            path = LevelManager.room.hexRoom.FindPath(allPath, entity.centerCell, destination);
            HexRoom.SortPathByDistance(path, destination);
        }
        else
        {
            //和目标保持一定的距离
            int targetDistance = entity.centerCell.GetDistance(destination);
            int moveDistance   = targetDistance - distance;
            moveDistance = moveDistance < 0 ? 0 : moveDistance;
            if (m_PropertyComponent.movePoint < moveDistance)
            {
                Debug.LogError("移动力不足 " + moveDistance);
                return(false);
            }

            HexRoom.HexCellPaths allPath = LevelManager.room.hexRoom.GetAvailableDestinations(entity.centerCell, targetDistance);
            path = LevelManager.room.hexRoom.FindPath(allPath, entity.centerCell, destination);
            HexRoom.SortPathByDistance(path, destination);
            for (int i = 0; i < distance; i++)
            {
                path.RemoveAt(path.Count - 1);
            }
        }

        m_MovingData = new MovingData(path, path[path.Count - 1], entity, m_PropertyComponent);
        if (m_MovingData.BeginMove())
        {
            onBeginMove.Invoke(destination);
            InvokeRepeating("OnMoving", 0f, Config.system.baseTimeDelta);
            return(true);
        }
        else
        {
            m_MovingData = null;
            return(false);
        }
    }
Exemplo n.º 2
0
 public List <HexCell> GetAttackRange()
 {
     HexRoom.HexCellPaths path = LevelManager.room.hexRoom.GetAvailableDestinations(entity.centerCell, (int)m_PropertyComponent.attackRange + (int)m_PropertyComponent.movePoint);
     return(path.GetDestinations());
 }