Exemplo n.º 1
0
    public void Attack(BasicEntity entity)
    {
        VoxelBlocks map  = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();
        Vector3     ePos = entity.GetComponent <BlockInfoComponent> ().m_logicPosition;

        Vector3 tPos = target.GetComponent <BlockInfoComponent> ().m_logicPosition;

        if ((Mathf.Abs(ePos.x - tPos.x) <= 1.5f) && (Mathf.Abs(ePos.y - tPos.y) <= 1.5f))
        {
            AiToInput.Attack(entity, tPos);
        }
        else
        {
            target.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.None;
            List <Vector3> path = FindPath.GetPath(ePos, tPos);
            target.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.Player;
            if (path != null)
            {
                path.Remove(tPos);
                tPos = path [path.Count - 1];
                AiToInput.Move(entity, tPos);
            }
            else
            {
                Debug.Log("Fail to Attack");
            }
        }
    }
Exemplo n.º 2
0
    static public Vector3 GetNearestFriend(Vector3 s)
    {
        List <BasicEntity> enemyList = StateStaticComponent.enemyActionList;
        int num = -1;
        int min = -1;

        for (int i = 0; i < enemyList.Count; i++)
        {
            BasicEntity e   = enemyList[i];
            Vector3     pos = e.GetComponent <BlockInfoComponent>().m_logicPosition;
            e.GetComponent <BlockInfoComponent>().m_blockType = BlockType.None;
            List <Vector3> path = FindPath.GetPath(s, pos);
            e.GetComponent <BlockInfoComponent>().m_blockType = BlockType.Enemy;
            if (path != null && path.Count > 0)
            {
                if (i == 0)
                {
                    num = 0;
                    min = path.Count;
                }
                if (min > path.Count)
                {
                    min = path.Count;
                    num = i;
                }
            }
        }
        if (num >= 0)
        {
            return(enemyList[num].GetComponent <BlockInfoComponent>().m_logicPosition);
        }
        return(Vector3.down);
    }
Exemplo n.º 3
0
    public List <Node> GetPath(Vector3 startPosition, Vector3 targetPosition)
    {
        Node startNode  = GetNodeFromPoint((int)startPosition.x, (int)startPosition.z);
        Node targetNode = GetNodeFromPoint((int)targetPosition.x, (int)targetPosition.z);

        if (AStar)
        {
            return(path.GetPath(startNode, targetNode));
        }

        return(_path.GetPath(startNode, targetNode));
    }
Exemplo n.º 4
0
    public int CalculateDistance(BasicEntity entity)
    {
        MonitorComponent monitorComp = (MonitorComponent)entity.GetSpecicalComponent(ComponentType.Monitor);
        BasicEntity      player      = monitorComp.m_enemy [0];

        player.GetComponent <BlockInfoComponent> ().m_blockType = BlockType.None;
        List <Vector3> pathLsit = FindPath.GetPath(entity.GetComponent <BlockInfoComponent> ().m_logicPosition,
                                                   player.GetComponent <BlockInfoComponent> ().m_logicPosition);

        if (pathLsit != null)
        {
            Debug.Log("cant find path!!!!!!!!!!!");
            return(0);
        }
        else
        {
            return(pathLsit.Count);
        }
    }
Exemplo n.º 5
0
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (var entity in entities)
        {
            MoveComponent    move      = entity.gameObject.GetComponent <MoveComponent> ();
            AbilityComponent ab        = entity.GetComponent <AbilityComponent> ();
            InputComponent   input     = entity.GetComponent <InputComponent> ();
            StateComponent   ap        = entity.GetComponent <StateComponent> ();
            BlockType        blockType = entity.GetComponent <BlockInfoComponent>().m_blockType;

            int i = AiToInput.GetAbilityCount(entity, M_LinkedType);
            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                continue;
            }
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple>();

            VoxelBlocks map = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();

            if (move.pathList == null)
            {
                move.pathList = new List <Vector3> ();
                move.pathList.Add(entity.GetComponent <BlockInfoComponent> ().m_logicPosition);
            }
            if (move.path == null)
            {
                move.path = FindPath.FindPathInStep(move.pathList [move.pathList.Count - 1], ap.m_actionPoint * move.SPD - move.pathList.Count + 1);
            }
            List <Vector3> a = move.path;
            if (blockType != BlockType.Enemy)
            {
                ui.ShowUI(a, 3);
            }
            if (input.currentPos != null)
            {
                if (a.Count == 0 && input.leftButtonDown)
                {
                    SetPath(move);
                    move.pathList        = null;
                    move.path            = null;
                    input.leftButtonDown = false;
                    return;
                }
                foreach (var bi in a)
                {
                    //判断鼠标停靠位置是否位于可移动范围之内
                    if (bi == input.currentPos)
                    {
                        List <Vector3> path = new List <Vector3> ();
                        path.AddRange(move.pathList);
                        List <Vector3> newPath = FindPath.GetPath(move.pathList [move.pathList.Count - 1], input.currentPos);
                        if (newPath != null)
                        {
                            path.AddRange(newPath);
                        }
                        //调用UI显示路径
                        if (blockType != BlockType.Enemy)
                        {
                            ui.ShowUI(path, 2);
                        }
                        if (input.midButtonDown)
                        {
                            move.pathList = path;
                            move.path     = null;
                        }

                        if (input.rightButtonDown)
                        {
                            move.pathList.Clear();
                            move.path = null;
                        }

                        if (input.leftButtonDown && ap.m_actionPoint != 0)
                        {
                            move.pathList = path;

                            SetPath(move);
                            move.GetComponent <StateComponent>().AnimationStart();

                            move.pathList        = null;
                            move.path            = null;
                            input.leftButtonDown = false;
                            return;
                        }
                    }
                }
            }
        }
    }