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 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; } }