Ejemplo n.º 1
0
    public UnitGridCombat CheckAlliesHealth(UnitGridCombat thisUnit)
    {
        bool willBeHealing = false;

        alliesCount = gridCombatSystem.GetComponent <GridCombatSystem>().enemiesTeamList.Count;
        Vector3 myPosition = thisUnit.GetPosition();
        float   minHealth  = 9999;

        for (int i = 0; i < alliesCount; i++)
        {
            if ((gridCombatSystem.GetComponent <GridCombatSystem>().enemiesTeamList[i].curHealth <= gridCombatSystem.GetComponent <GridCombatSystem>().enemiesTeamList[i].maxHealth / 2) && (gridCombatSystem.GetComponent <GridCombatSystem>().enemiesTeamList[i].curHealth < minHealth))
            {
                willBeHealing = true;
                minHealth     = gridCombatSystem.GetComponent <GridCombatSystem>().enemiesTeamList[i].curHealth;
                needHealing   = gridCombatSystem.GetComponent <GridCombatSystem>().enemiesTeamList[i];
            }
        }

        if (willBeHealing)
        {
            return(needHealing);
        }
        else
        {
            return(null);
        }
    }
Ejemplo n.º 2
0
    //Atacas a alguien a melee
    public UnitGridCombat lookForEnemies(UnitGridCombat thisUnit) // lookForEnemies a una casilla
    {
        enemiesCount = gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList.Count;
        Vector3 myPosition = thisUnit.GetPosition();
        float   distance;

        for (int i = 0; i <= enemiesCount; i++) // para comparar mi posición con la posición de todos los personajes del equipo del jugador
        {
            //El primer Player a rango, lo atacas
            distance = Vector3.Distance(myPosition, gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList[i].GetPosition());
            if (distance <= 11 && (thisUnit.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MELEE || thisUnit.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.TANK))
            {
                return(gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList[i]);
            }
            else if (distance <= 31 && (thisUnit.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MAGE || thisUnit.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.HEALER))
            {
                return(gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList[i]);
            }
            else if (distance <= 41 && (thisUnit.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.RANGED))
            {
                return(gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList[i]);
            }
        }
        return(null);
    }
Ejemplo n.º 3
0
    //Me muevo a la posicion dentro del rango de movimiento
    private void WalkToEnemyInRange(UnitGridCombat thisUnit)
    {
        Grid <GridCombatSystem.GridObject> grid = GameHandler_GridCombatSystem.Instance.GetGrid();
        GridPathfinding gridPathfinding         = GameHandler_GridCombatSystem.Instance.gridPathfinding;

        if (CheckCollisionsTargetIntermedio() && gridObject.GetUnitGridCombat() == null)
        {
            if (thisUnit.GetComponent <CHARACTER_PREFS>().tipo != CHARACTER_PREFS.Tipo.DUMMY)
            {
                grid.GetGridObject(thisUnit.GetPosition()).ClearUnitGridCombat();
                thisUnit.MoveTo(target, () =>
                {
                    gridObject.SetUnitGridCombat(thisUnit);
                    if (gridCombatSystem.GetComponent <GridCombatSystem>().SeekEnemiesIA(thisUnit) == true)
                    {
                        thisUnit.AttackUnit(lookForEnemies(thisUnit));
                    }
                });
            }
        }
        else
        {
            Debug.Log("Aqui no deberia entrar nunca");
        }
    }
Ejemplo n.º 4
0
    private void ShootUnit(UnitGridCombat unitGridCombat, Action onShootComplete)
    {
        GetComponent <IMoveVelocity>().Disable();
        Vector3 attackDir = (unitGridCombat.GetPosition() - transform.position).normalized;

        //UtilsClass.ShakeCamera(.6f, .1f);
        GameHandler_GridCombatSystem.Instance.ScreenShake();

        characterBase.PlayShootAnimation(attackDir, (Vector3 vec) => {
            Shoot_Flash.AddFlash(vec);
            WeaponTracer.Create(vec, unitGridCombat.GetPosition() + GetRandomDir() * UnityEngine.Random.Range(-2f, 4f));
            unitGridCombat.Damage(this, UnityEngine.Random.Range(4, 12));
        }, () => {
            characterBase.PlayIdleAnim();
            GetComponent <IMoveVelocity>().Enable();

            onShootComplete();
        });
    }
Ejemplo n.º 5
0
 public bool CanAttackUnit(UnitGridCombat unitGridCombat)
 {
     if (gameObject.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MELEE)
     {
         return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= attackRangeMelee);
     }
     else if (gameObject.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.RANGED && sceneCombatSystem.boltOfPrecision)
     {
         return(true);
     }
     else if (gameObject.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.RANGED)
     {
         return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= attackRangeRanged);
     }
     else if (gameObject.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.HEALER)
     {
         return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= attackRangeHealer);
     }
     else if (gameObject.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MAGE)
     {
         return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= attackRangeMage);
     }
     else if (gameObject.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.TANK)
     {
         return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= attackRangeTank);
     }
     else //DUMMY
     {
         return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= 0);
     }
 }
Ejemplo n.º 6
0
 //Comporbamos si el Enemigo mas Cercano esta a Rango de Movimiento o Hay que hacer un Target Intermedio
 private void CheckRange(UnitGridCombat nearestEnemy, UnitGridCombat thisUnit)
 {
     target = CheckTargetRange(nearestEnemy.GetPosition(), thisUnit);
     //Debug.Log(target);
     if (enemyOutOfRange)
     {
         //No Estoy en Rango de Movimiento
         WalkToEnemyOutOfRange(thisUnit);
     }
     else
     {
         //Estoy en Rango de Movimiento
         WalkToEnemyInRange(thisUnit);
     }
 }
Ejemplo n.º 7
0
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //BUCLE DE LA IA
    //Sabemos que no estas a Rango de Ataque y te mueves
    //Buscas el Player mas cercano y lo pasas a WalkToEnemy
    public void lookForEnemiesDist(UnitGridCombat thisUnit) // lookForEnemies de más distancia
    {
        enemiesCount = gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList.Count;
        float          minDist      = 9999.0f; // para encontrar el enemigo más cerca
        Vector3        myPosition   = thisUnit.GetPosition();
        UnitGridCombat nearestEnemy = null;

        for (int i = 0; i < enemiesCount; i++) // para comparar mi posición con la posición de todos los personajes del equipo del jugador
        {
            float distance = Vector3.Distance(myPosition, gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList[i].GetPosition());
            if (distance < minDist)
            {
                minDist      = distance;
                nearestEnemy = gridCombatSystem.GetComponent <GridCombatSystem>().alliesTeamList[i];
            }
        }
        CheckRange(nearestEnemy, thisUnit);
    }
Ejemplo n.º 8
0
    public void Damage(UnitGridCombat attacker, int damageAmount)
    {
        Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized;

        Blood_Handler.SpawnBlood(GetPosition(), bloodDir);

        DamagePopup.Create(GetPosition(), damageAmount, false);
        healthSystem.Damage(damageAmount);
        if (healthSystem.IsDead())
        {
            FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir);
            Destroy(gameObject);
        }
        else
        {
            // Knockback
            //transform.position += bloodDir * 5f;
        }
    }
Ejemplo n.º 9
0
 public bool CanHealUnit(UnitGridCombat unitGridCombat)
 {
     return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= rangeHeal);
 }
Ejemplo n.º 10
0
    private IEnumerator FeedbackAttack(UnitGridCombat Attacker)
    {
        if (attackedByMelee || attackedByTank)
        {
            animEnded = false;
            slashAnim.SetActive(true);
            SoundManager.PlaySound("Attack");
            yield return(new WaitForSeconds(0.5f));

            slashAnim.SetActive(false);
            playerSprite.color = Color.red;
            yield return(new WaitForSeconds(0.3f));

            playerSprite.color = Color.white;
            animEnded          = true;
            if (imDead)
            {
                Destroy(gameObject);
            }
            sceneCombatSystem.CheckIfGameIsOver();
        }

        else if (attackedByArcher && !sceneCombatSystem.boltOfPrecision)
        {
            animEnded = false;

            //LOGICA
            //Cambiamos los 2 primeros puntos de la curva al centro del arquero y el otro un poco mas arriba
            //Cambiamos los 2 ultimos puntos de la curva al centro del objetivo y el otro un poco mas arriba
            //Instanciamos una flecha en el inicio de la curva
            attackerPosArrow = Attacker.GetPosition();
            myPosArrow       = this.GetPosition();
            //Pos0
            p0   = sceneCombatSystem.arrowRoute.GetChild(0).position;
            p0.x = attackerPosArrow.x;
            p0.y = attackerPosArrow.y;
            sceneCombatSystem.arrowRoute.GetChild(0).position = p0;
            //Pos1
            p1   = sceneCombatSystem.arrowRoute.GetChild(1).position;
            p1.x = attackerPosArrow.x;
            p1.y = attackerPosArrow.y + 3;
            sceneCombatSystem.arrowRoute.GetChild(1).position = p1;
            //Pos2
            p2   = sceneCombatSystem.arrowRoute.GetChild(2).position;
            p2.x = myPosArrow.x;
            p2.y = myPosArrow.y + 3;
            sceneCombatSystem.arrowRoute.GetChild(2).position = p2;
            //Pos3
            p3   = sceneCombatSystem.arrowRoute.GetChild(3).position;
            p3.x = myPosArrow.x;
            p3.y = myPosArrow.y;
            sceneCombatSystem.arrowRoute.GetChild(3).position = p3;

            sceneCombatSystem.arrowPrefab.GetComponent <BezierFollow>().route = sceneCombatSystem.arrowRoute;
            Instantiate(sceneCombatSystem.arrowPrefab, attackerPosArrow, Quaternion.Euler(new Vector3(0, 0, 90)));

            SoundManager.PlaySound("ArrowHit");
            //Seguimos con sonido y feedback
            yield return(new WaitForSeconds(0.1f));

            playerSprite.color = Color.red;
            yield return(new WaitForSeconds(0.3f));

            playerSprite.color = Color.white;
            animEnded          = true;
            if (imDead)
            {
                Destroy(gameObject);
            }
            sceneCombatSystem.CheckIfGameIsOver();
        }

        else if (attackedByArcher && sceneCombatSystem.boltOfPrecision)
        {
            animEnded = false;
            boltAnim.SetActive(true);
            SoundManager.PlaySound("ArrowHit");
            SoundManager.PlaySound("Bolt");
            yield return(new WaitForSeconds(1.2f));

            boltAnim.SetActive(false);
            playerSprite.color = Color.red;
            yield return(new WaitForSeconds(0.3f));

            playerSprite.color = Color.white;
            animEnded          = true;
        }

        else if (attackedByMage)
        {
            animEnded = false;
            lightningAnim.SetActive(true);
            SoundManager.PlaySound("Lightning");
            playerSprite.color = Color.red;
            yield return(new WaitForSeconds(1.2f));

            lightningAnim.SetActive(false);
            yield return(new WaitForSeconds(0.3f));

            playerSprite.color = Color.white;
            animEnded          = true;
            if (imDead)
            {
                Destroy(gameObject);
            }
            sceneCombatSystem.CheckIfGameIsOver();
        }

        else if (attackedByHealer)
        {
            animEnded = false;
            explosionAnim.SetActive(true);
            SoundManager.PlaySound("HealerBasicAttack");
            playerSprite.color = Color.red;
            yield return(new WaitForSeconds(0.9f));

            explosionAnim.SetActive(false);
            yield return(new WaitForSeconds(0.3f));

            playerSprite.color = Color.white;
            animEnded          = true;
            if (imDead)
            {
                Destroy(gameObject);
            }
            sceneCombatSystem.CheckIfGameIsOver();
        }
    }
Ejemplo n.º 11
0
 public bool CanAttackUnit(UnitGridCombat unitGridCombat)
 {
     return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) < AttackRange);
 }
Ejemplo n.º 12
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));
    }
Ejemplo n.º 13
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));
                            }
                        });
                    }
                }
            }
        }
    }