//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); }
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); } }
private void Update() { unitGridCombat = gridCombatSystem.unitGridCombat; SetMaxHealth(unitGridCombat.maxHealth); SetHealth(unitGridCombat.curHealth); UpdateSprite(unitGridCombat); }
//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"); } }
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); } }
public void UpdateSprite(UnitGridCombat unitGridCombat) { if (unitGridCombat.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MELEE) { knightSprite.SetActive(true); archerSprite.SetActive(false); healerSprite.SetActive(false); tankSprite.SetActive(false); mageSprite.SetActive(false); tipoText.SetText("Knight"); atkText.SetText("Atk: 25"); SetLevelText(); } else if (unitGridCombat.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.RANGED) { knightSprite.SetActive(false); archerSprite.SetActive(true); healerSprite.SetActive(false); tankSprite.SetActive(false); mageSprite.SetActive(false); tipoText.SetText("Archer"); atkText.SetText("Atk: 20"); SetLevelText(); } else if (unitGridCombat.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.HEALER) { knightSprite.SetActive(false); archerSprite.SetActive(false); healerSprite.SetActive(true); tankSprite.SetActive(false); mageSprite.SetActive(false); tipoText.SetText("Priest"); atkText.SetText("Atk: 10"); SetLevelText(); } else if (unitGridCombat.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.TANK) { knightSprite.SetActive(false); archerSprite.SetActive(false); healerSprite.SetActive(false); tankSprite.SetActive(true); mageSprite.SetActive(false); tipoText.SetText("Paladin"); atkText.SetText("Atk: 15"); SetLevelText(); } else if (unitGridCombat.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MAGE) { knightSprite.SetActive(false); archerSprite.SetActive(false); healerSprite.SetActive(false); tankSprite.SetActive(false); mageSprite.SetActive(true); tipoText.SetText("Wizard"); atkText.SetText("Atk: 25"); SetLevelText(); } }
public void HealAlly(UnitGridCombat unitGridCombat) { if (sceneCombatSystem.hexOfNature) { unitGridCombat.Heal(60); sceneCombatSystem.hexOfNature = false; sceneCombatSystem.inspiration -= 3; } else { unitGridCombat.Heal(healAmount); } }
private void SelectNextActiveUnit() { if (unitGridCombat == null || unitGridCombat.GetTeam() == UnitGridCombat.Team.Red) { unitGridCombat = GetNextActiveUnit(UnitGridCombat.Team.Blue); } else { unitGridCombat = GetNextActiveUnit(UnitGridCombat.Team.Red); } GameHandler_GridCombatSystem.Instance.SetCameraFollowPosition(unitGridCombat.GetPosition()); canMoveThisTurn = true; canAttackThisTurn = true; }
//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); } }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //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); }
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; } }
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(); }); }
public void AttackUnit(UnitGridCombat unitGridCombat, Action onAttackComplete) { state = State.Attacking; ShootUnit(unitGridCombat, () => { if (!unitGridCombat.IsDead()) { ShootUnit(unitGridCombat, () => { if (!unitGridCombat.IsDead()) { ShootUnit(unitGridCombat, () => { if (!unitGridCombat.IsDead()) { ShootUnit(unitGridCombat, () => { state = State.Normal; onAttackComplete(); }); } else { state = State.Normal; onAttackComplete(); } }); } else { state = State.Normal; onAttackComplete(); } }); } else { state = State.Normal; onAttackComplete(); } }); }
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(); } }
public void Damage(UnitGridCombat Attacker) { if (Attacker.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MELEE) { attackID = 1; attackedByMelee = true; attackedByArcher = false; attackedByHealer = false; attackedByTank = false; attackedByMage = false; if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL1) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 25.0f + ((25.0f / 100.0f) * 55.0f); } else { damageAmount = 25.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL2) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 30.0f + ((30.0f / 100.0f) * 20.0f); } else { damageAmount = 30.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL3) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 35.0f + ((35.0f / 100.0f) * 20.0f); } else { damageAmount = 35.0f; } } } else if (Attacker.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.RANGED) { attackID = 2; attackedByMelee = false; attackedByArcher = true; attackedByHealer = false; attackedByTank = false; attackedByMage = false; if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL1) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 20.0f + ((20.0f / 100.0f) * 20.0f); } else { damageAmount = 20.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL2) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 25.0f + ((25.0f / 100.0f) * 20.0f); } else { damageAmount = 25.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL3) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 30.0f + ((30.0f / 100.0f) * 20.0f); } else { damageAmount = 30.0f; } } } else if (Attacker.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.HEALER) { attackedByMelee = false; attackedByArcher = false; attackedByHealer = true; attackedByTank = false; attackedByMage = false; if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL1) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 10.0f + ((10.0f / 100.0f) * 20.0f); } else { damageAmount = 10.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL2) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 15.0f + ((15.0f / 100.0f) * 20.0f); } else { damageAmount = 15.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL3) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 20.0f + ((20.0f / 100.0f) * 20.0f); } else { damageAmount = 20.0f; } } } else if (Attacker.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.TANK) { attackedByMelee = false; attackedByArcher = false; attackedByHealer = false; attackedByTank = true; attackedByMage = false; if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL1) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 15.0f + ((15.0f / 100.0f) * 20.0f); } else { damageAmount = 15.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL2) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 20.0f + ((20.0f / 100.0f) * 20.0f); } else { damageAmount = 20.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL3) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 25.0f + ((25.0f / 100.0f) * 20.0f); } else { damageAmount = 25.0f; } } } else if (Attacker.GetComponent <CHARACTER_PREFS>().tipo == CHARACTER_PREFS.Tipo.MAGE) { attackID = 3; attackedByMelee = false; attackedByArcher = false; attackedByHealer = false; attackedByTank = false; attackedByMage = true; if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL1) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 25.0f + ((25.0f / 100.0f) * 20.0f); } else { damageAmount = 25.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL2) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 30.0f + ((30.0f / 100.0f) * 20.0f); } else { damageAmount = 30.0f; } } else if (Attacker.GetComponent <CHARACTER_PREFS>().Getlevel() == CHARACTER_PREFS.Level.NIVEL3) { if (sceneCombatSystem.inspiredAttack) { damageAmount = 35.0f + ((35.0f / 100.0f) * 20.0f); } else { damageAmount = 35.0f; } } } float dmg; dmg = RandomDamage(damageAmount); sceneCombatSystem.DamagePopUp(this.GetPosition(), (int)dmg); healthSystem.Damage((int)dmg); if (healthSystem.IsDead()) { if (Attacker.GetTeam() == Team.Blue) { if (characterPrefs.Getlevel() == CHARACTER_PREFS.Level.NIVEL1) { if (attackedByMelee) { characterManager.meleeExp += 5; } if (attackedByArcher) { characterManager.archerExp += 5; } if (attackedByHealer) { characterManager.healerExp += 5; } if (attackedByTank) { characterManager.tankExp += 5; } if (attackedByMage) { characterManager.mageExp += 5; } } if (characterPrefs.Getlevel() == CHARACTER_PREFS.Level.NIVEL3) { if (attackedByMelee) { characterManager.meleeExp += 25; } if (attackedByArcher) { characterManager.archerExp += 25; } if (attackedByHealer) { characterManager.healerExp += 25; } if (attackedByTank) { characterManager.tankExp += 25; } if (attackedByMage) { characterManager.mageExp += 25; } } imDead = true; sceneCombatSystem.CheckIfDead(); for (int i = 0; i < sceneCombatSystem.enemiesTeamList.Count; i++) { if (!sceneCombatSystem.enemiesTeamList[i].imDead) { sceneCombatSystem.newEnemiesTeamList.Add(sceneCombatSystem.enemiesTeamList[i]); } } CleanListIA(); } else if (Attacker.GetTeam() == Team.Red) { imDead = true; sceneCombatSystem.CheckIfDead(); sceneCombatSystem.allydeads += 1; if (characterPrefs.getType() == CHARACTER_PREFS.Tipo.MELEE) { sceneCombatSystem.numberOfMeleeLeft--; } if (characterPrefs.getType() == CHARACTER_PREFS.Tipo.RANGED) { sceneCombatSystem.numberOfRangedLeft--; } if (characterPrefs.getType() == CHARACTER_PREFS.Tipo.HEALER) { sceneCombatSystem.numberOfHealerLeft--; } if (characterPrefs.getType() == CHARACTER_PREFS.Tipo.TANK) { sceneCombatSystem.numberOfTankLeft--; } if (characterPrefs.getType() == CHARACTER_PREFS.Tipo.MAGE) { sceneCombatSystem.numberOfMageLeft--; } for (int i = 0; i < sceneCombatSystem.alliesTeamList.Count; i++) { if (!sceneCombatSystem.alliesTeamList[i].imDead) { sceneCombatSystem.newAlliesTeamList.Add(sceneCombatSystem.alliesTeamList[i]); } } CleanListAlly(); } } StartCoroutine(FeedbackAttack(Attacker)); }
public void AttackUnit(UnitGridCombat unitGridCombat) { GetComponent <IMoveVelocity>().Disable(); unitGridCombat.Damage(this); GetComponent <IMoveVelocity>().Enable(); }
public bool IsEnemy(UnitGridCombat unitGridCombat) { return(unitGridCombat.GetTeam() != team); }
public bool CanAttackUnit(UnitGridCombat unitGridCombat) { return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) < AttackRange); }
public void UpdateHealth(UnitGridCombat unitGridCombat) { SetMaxHealth(unitGridCombat.maxHealth); currHealthText.SetText("hp: " + unitGridCombat.curHealth + " / " + unitGridCombat.maxHealth); SetHealth(unitGridCombat.curHealth); }
//la misma función de antes pero para aliados de la IA public void lookForAlliesDist(UnitGridCombat thisUnit) // lookForAllies de más distancia { CheckRange(needHealing, thisUnit); }
//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)); }
//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)); } }); } } } } }
public bool CanHealUnit(UnitGridCombat unitGridCombat) { return(Vector3.Distance(GetPosition(), unitGridCombat.GetPosition()) <= rangeHeal); }
public void SetUnitGridCombat(UnitGridCombat unitGridCombat) { this.unitGridCombat = unitGridCombat; }