Пример #1
0
    //Busco un target al que moverme cerca de mi posicion
    private Vector3 CheckTargetRange(Vector3 Objective, UnitGridCombat thisUnit)
    {
        Grid <GridCombatSystem.GridObject> grid = GameHandler_GridCombatSystem.Instance.GetGrid();
        Vector3 myPosition  = thisUnit.GetPosition();
        Vector3 targetRight = new Vector3(0, 0, 0);
        Vector3 targetLeft  = new Vector3(0, 0, 0);
        Vector3 targetTop   = new Vector3(0, 0, 0);
        Vector3 targetBot   = new Vector3(0, 0, 0);

        targetRight.x = Objective.x + 10;
        targetRight.y = Objective.y;

        targetLeft.x = Objective.x - 10;
        targetLeft.y = Objective.y;

        targetTop.x = Objective.x;
        targetTop.y = Objective.y + 10;

        targetBot.x = Objective.x;
        targetBot.y = Objective.y - 10;

        gridObject = grid.GetGridObject(targetRight);
        if (CheckMoveRange(targetRight, myPosition) && CheckCollisionsTarget() && gridObject.GetUnitGridCombat() == null)
        {
            Debug.Log("Derecha");
            enemyOutOfRange = false;
            return(targetRight);
        }
        gridObject = grid.GetGridObject(targetLeft);
        if (CheckMoveRange(targetLeft, myPosition) && CheckCollisionsTarget() && gridObject.GetUnitGridCombat() == null)
        {
            Debug.Log("Izquierda");
            enemyOutOfRange = false;
            return(targetLeft);
        }
        gridObject = grid.GetGridObject(targetTop);
        if (CheckMoveRange(targetTop, myPosition) && CheckCollisionsTarget() && gridObject.GetUnitGridCombat() == null)
        {
            Debug.Log("Arriba");
            enemyOutOfRange = false;
            return(targetTop);
        }
        gridObject = grid.GetGridObject(targetBot);
        if (CheckMoveRange(targetBot, myPosition) && CheckCollisionsTarget() && gridObject.GetUnitGridCombat() == null)
        {
            Debug.Log("Abajo");
            enemyOutOfRange = false;
            return(targetBot);
        }


        //Debug.Log(CheckMoveRange(targetRight, myPosition) + " CheckRange");
        //Debug.Log(CheckCollisionsTarget() + " CheckCollision");
        //Debug.Log((gridObject.GetUnitGridCombat() == null) + " UnitGridCombat");

        float distTop   = CheckMoveOutOfRange(targetTop, myPosition);
        float distBot   = CheckMoveOutOfRange(targetBot, myPosition);
        float distRight = CheckMoveOutOfRange(targetRight, myPosition);
        float distLeft  = CheckMoveOutOfRange(targetLeft, myPosition);

        if (distTop < distBot && distTop < distRight && distTop < distLeft)
        {
            Debug.Log("ArribaOut");
            enemyOutOfRange = true;
            return(targetTop);
        }
        if (distBot <= distTop && distBot <= distRight && distBot <= distLeft)
        {
            Debug.Log("AbajoOut");
            enemyOutOfRange = true;
            return(targetBot);
        }
        if (distRight <= distBot && distRight <= distTop && distRight <= distLeft)
        {
            Debug.Log("DerechaOut");
            enemyOutOfRange = true;
            return(targetRight);
        }
        if (distLeft < distBot && distLeft < distRight && distLeft < distTop)
        {
            Debug.Log("IzquierdaOut");
            enemyOutOfRange = true;
            return(targetLeft);
        }

        Debug.Log("Else");
        return(new Vector3(0, 0, 0));
    }
Пример #2
0
    //Moverse hacia un enemigo al target intermedio (Movimiento fuera del Rango de Movimiento)
    private void WalkToEnemyOutOfRange(UnitGridCombat thisUnit)
    {
        Grid <GridCombatSystem.GridObject> grid = GameHandler_GridCombatSystem.Instance.GetGrid();
        GridPathfinding gridPathfinding         = GameHandler_GridCombatSystem.Instance.gridPathfinding;

        SelectNewMovePosition(thisUnit.GetPosition()); //Se calcula el targetIntermedio
        gridObject = grid.GetGridObject(targetIntermedio);
        if (CheckCollisionsTargetIntermedio() && gridObject.GetUnitGridCombat() == null)
        {
            if (thisUnit.GetComponent <CHARACTER_PREFS>().tipo != CHARACTER_PREFS.Tipo.DUMMY)
            {
                grid.GetGridObject(thisUnit.GetPosition()).ClearUnitGridCombat();
                thisUnit.MoveTo(targetIntermedio, () =>
                {
                    gridObject.SetUnitGridCombat(thisUnit);
                    if (gridCombatSystem.GetComponent <GridCombatSystem>().SeekEnemiesIA(thisUnit) == true)
                    {
                        thisUnit.AttackUnit(lookForEnemies(thisUnit));
                    }
                });
            }
        }
        //Buscar nuevo target Intermedio y me muevo
        else
        {
            enemyOutOfRange  = false; //El target intermedio se calcula para que siempre este a rango de movimiento, por lo tanto esto va a ser siempre false en esta parte del codigo
            targetIntermedio = CheckTargetRange(targetIntermedio, thisUnit);
            gridObject       = grid.GetGridObject(targetIntermedio);
            if (CheckCollisionsTargetIntermedio() && gridObject.GetUnitGridCombat() == null && CheckMoveRange(targetIntermedio, thisUnit.GetPosition()))
            {
                if (thisUnit.GetComponent <CHARACTER_PREFS>().tipo != CHARACTER_PREFS.Tipo.DUMMY)
                {
                    grid.GetGridObject(thisUnit.GetPosition()).ClearUnitGridCombat();
                    thisUnit.MoveTo(targetIntermedio, () =>
                    {
                        gridObject.SetUnitGridCombat(thisUnit);
                        if (gridCombatSystem.GetComponent <GridCombatSystem>().SeekEnemiesIA(thisUnit) == true)
                        {
                            thisUnit.AttackUnit(lookForEnemies(thisUnit));
                        }
                    });
                }
            }
            else //Busca un segundo target intermedio y sus adyacentes para moverse a una posicion
            {
                targetIntermedio = CheckTargetRange(targetIntermedio, thisUnit);
                gridObject       = grid.GetGridObject(targetIntermedio);
                if (CheckCollisionsTargetIntermedio() && gridObject.GetUnitGridCombat() == null && CheckMoveRange(targetIntermedio, thisUnit.GetPosition()))
                {
                    if (thisUnit.GetComponent <CHARACTER_PREFS>().tipo != CHARACTER_PREFS.Tipo.DUMMY)
                    {
                        grid.GetGridObject(thisUnit.GetPosition()).ClearUnitGridCombat();
                        thisUnit.MoveTo(targetIntermedio, () =>
                        {
                            gridObject.SetUnitGridCombat(thisUnit);
                            if (gridCombatSystem.GetComponent <GridCombatSystem>().SeekEnemiesIA(thisUnit) == true)
                            {
                                thisUnit.AttackUnit(lookForEnemies(thisUnit));
                            }
                        });
                    }
                }
            }
        }
    }