//find a target unit and get the position target public static List <Cell> findTarget(Board board, Cell currentCell, string targetTag) { int targetDistance = infVal; //Unit targetUnit = null; List <Cell> path = null; //get the list of possible targets, i.e. units the opposing team GameObject[] targetList = GameObject.FindGameObjectsWithTag(targetTag); //if there is at least one opponent alive if (targetList.Length > 0) { //check every possible target in the list foreach (GameObject possibleTarget in targetList) { Cell possibleTargetCell = possibleTarget.GetComponent <Unit>().getCell(); List <Cell> pathProv = PathfindingTool.createPath(board, currentCell, possibleTargetCell); if (pathProv != null) { int possibleTargetDistance = pathProv.Count; //if there is an opponent closer than the current target if (possibleTargetDistance < targetDistance) { //change the target position with the new opponents's position path = pathProv; targetDistance = path.Count; } } } } return(path); }
override public void castAbility() { base.castAbility(); basicRange = unit.Range; unit.Range = castRange; List <Cell> listCells = PathfindingTool.cellsInRadius(unit.currentCell, castRange); int maxTargetTouch = 0; Cell bestTargetCell = null; List <Unit> listUnitsTouch = new List <Unit>(); foreach (Cell cell in listCells) { List <Unit> listUnitsTouchProv = PathfindingTool.unitsInRadius(cell, areaOfEffect, unit.getTargetTag()); int maxTargetTouchProv = listUnitsTouchProv.Count; if (maxTargetTouchProv > maxTargetTouch) { bestTargetCell = cell; maxTargetTouch = maxTargetTouchProv; listUnitsTouch = listUnitsTouchProv; } } if (bestTargetCell != null) { List <Cell> listCellsTouched = PathfindingTool.cellsInRadius(bestTargetCell, areaOfEffect); StartCoroutine(ProjectileAnimation(bestTargetCell, listCellsTouched)); unit.Range = basicRange; } }
override public void castAbility() { base.castAbility(); playSound(); List <Unit> listUnitsHitProv = PathfindingTool.unitsInRadius(unit.currentCell, areaOfEffect, unit.getTargetTag()); Instantiate(animationGameObject, transform.position, Quaternion.identity, transform); foreach (Unit unit in listUnitsHitProv) { unit.takeDamage(currentPower); } }
public override void castAbility() { base.castAbility(); List <Unit> targets = PathfindingTool.unitsInRadius(unit.currentCell, castRange, unit.getTargetTag()); if (targets.Count > 0) { float damageTakenPourcentage = 1 - (unit.CurrentLife / unit.MaxLife); currentPower += currentPower * damageTakenPourcentage; playSound(); targets[0].takeDamage(currentPower); Instantiate(animationGameObject, transform.position, Quaternion.identity, transform); } }
override public void castAbility() { base.castAbility(); List <Unit> listUnitsHealProv = PathfindingTool.unitsInRadius(unit.currentCell, areaOfEffect, unit.tag); playSound(); Instantiate(animationGameObject, transform.position, Quaternion.identity, transform); foreach (Unit unit in listUnitsHealProv) { if (unit.classStat.clas != Class.Healer) { unit.heal(currentPower); } } }
IEnumerator ProjectileAnimation(Cell targetCell, List <Cell> listCells) { Vector3 startPosition = transform.position; GameObject projectile = Instantiate(projectileGameObject, startPosition, Quaternion.identity, transform); //set the speed of the animation (distance at each iteration of while loop) float speed = 0.06f; //set the maximum number of refresh of the projectile animation float maxRefresh = 1 / speed; //time to wait between every movement float refreshRate = 0.01f; int numberOfRefresh = 0; //get the distance between start position and target position Vector3 distance = targetCell.WorldPosition - projectile.transform.position; //set the correct angle float angle = Mathf.Atan2(distance.y, distance.x) * Mathf.Rad2Deg; projectile.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); //while there is still a target, the projectile is not arrived at the target position and the max number of refresh is not reached while (targetCell != null && projectile.transform.position != targetCell.WorldPosition && numberOfRefresh <= maxRefresh) { projectile.transform.position += distance * speed; numberOfRefresh++; yield return(new WaitForSeconds(refreshRate)); } Destroy(projectile); playSound(); List <Unit> listUnitsTouch = PathfindingTool.unitsInRadius(targetCell, areaOfEffect, unit.getTargetTag()); foreach (Unit unit in listUnitsTouch) { unit.takeDamage(currentPower); } //color all hit tiles in red for a short duration, then set the color back to normal GameObject.Find("Board").GetComponent <Board>().StartSetColorForSeconds(listCells); }
private void DesactivateArea(Cell center) { if (center != null) { List <Cell> affectedCells = PathfindingTool.cellsInRadius(center, range); foreach (Cell cell in affectedCells) { if (cell != null) { cell.SetColor(Color.white); if (cell.GetCurrentUnit() != null) { cell.GetCurrentUnit().desactivateOutline(); } } } } }
private void ActivateSpell() { List <Unit> affectedAllyUnit = new List <Unit>(); List <Unit> affectedEnemyUnit = new List <Unit>(); if (race != Race.Ratman) { affectedAllyUnit = PathfindingTool.unitsInRadius(currentCell, range, "UnitAlly"); affectedEnemyUnit = PathfindingTool.unitsInRadius(currentCell, range, "UnitEnemy"); } else { affectedAllyUnit = GameManager.instance.getUnit(); } bool launched = false; switch (race) { case (Race.Orc): foreach (Unit unit in affectedAllyUnit) { if (unit != null) { if (unit.getRace() == Race.Orc) { unit.activateOrcSpell(10, 5); launched = true; } } } if (launched == true) { onCooldown = true; cooldownImage.fillAmount = 1; activated = false; } break; case (Race.Skeleton): foreach (Unit unit in affectedEnemyUnit) { if (unit != null) { unit.activateSkeletonSpell(0.25f, 5); launched = true; } } if (launched == true) { onCooldown = true; cooldownImage.fillAmount = 1; activated = false; } break; case (Race.Octopus): foreach (Unit unit in affectedEnemyUnit) { if (unit != null) { unit.activateStun(2); launched = true; } } if (launched == true) { onCooldown = true; cooldownImage.fillAmount = 1; activated = false; } break; case (Race.Elemental): foreach (Unit unit in affectedEnemyUnit) { if (unit != null) { unit.activateElementalSpell(elemental.getNumber() * 10); launched = true; } } if (launched == true) { onCooldown = true; cooldownImage.fillAmount = 1; activated = false; } break; case (Race.Giant): foreach (Unit unit in affectedAllyUnit) { if (unit != null) { if (unit.getRace() == Race.Giant) { unit.activateGiantSpell(); launched = true; } } } if (launched == true) { onCooldown = true; cooldownImage.fillAmount = 1; activated = false; } break; case (Race.Ratman): foreach (Unit unit in affectedAllyUnit) { if (unit != null) { if (unit.CompareTag("UnitAlly") && unit.getRace() == Race.Ratman) { unit.activateRatmanSpell(); launched = true; } } } if (launched == true) { onCooldown = true; cooldownImage.fillAmount = 1; activated = false; } break; case (Race.Demon): if (currentCell.GetIsOccupied() == false && currentCell.GetIsObstacle() == false) { demonKing = Instantiate(demonKing); HealthbarHandler.ShowBars(); launched = true; } if (launched == true) { onCooldown = true; cooldownImage.fillAmount = 1; activated = false; } break; } }
private void ActivateArea(Cell center) { if (center != null) { List <Cell> affectedCells = PathfindingTool.cellsInRadius(center, range); foreach (Cell cell in affectedCells) { if (cell != null) { cell.SetColor(Color.red); //new Color(Color.red.r, Color.red.g, Color.red.b,0.9f) if (cell.GetCurrentUnit() != null) { switch (race) { case (Race.Orc): if (cell.GetCurrentUnit().getRace() == Race.Orc) { cell.GetCurrentUnit().activateOutline(); outlinedUnit.Add(cell.GetCurrentUnit()); } break; case (Race.Skeleton): if (cell.GetCurrentUnit().getRace() == Race.Human) { cell.GetCurrentUnit().activateOutline(); outlinedUnit.Add(cell.GetCurrentUnit()); } break; case (Race.Octopus): if (cell.GetCurrentUnit().getRace() == Race.Human) { cell.GetCurrentUnit().activateOutline(); outlinedUnit.Add(cell.GetCurrentUnit()); } break; case (Race.Elemental): if (cell.GetCurrentUnit().getRace() == Race.Human) { cell.GetCurrentUnit().activateOutline(); outlinedUnit.Add(cell.GetCurrentUnit()); } break; case (Race.Giant): if (cell.GetCurrentUnit().getRace() == Race.Giant) { cell.GetCurrentUnit().activateOutline(); outlinedUnit.Add(cell.GetCurrentUnit()); } break; case (Race.Ratman): break; case (Race.Demon): break; } } } } } }