usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassAbilityRange : MonoBehaviour{List<ExWhyCell> cellsInRange;List<GameObject> rangeVisuals;List<BattleCharacterObject> charactersInRange;int range;ExWhyCell epicentre;ExWhy grid;//The prefab used to show rangeGameObject visual;List<ExWhyCell> visited;//Finds all cells in range. //It just uses a two dimensional for loop adding a cell to each quandrant. publicList<ExWhyCell>findCellsInRange(){intepiX=epicentre.xPosition;intepiY=epicentre.yPosition;for (intx=0;x<=range;++x){for (inty=0;y<=range;++y){ExWhyCellpossibleCell;if (x+y<=range) {if (!(epiX+x>=grid.xMax|| (epiY+y>=grid.yMax))) {possibleCell=grid.gridCells[epiX+x,epiY+y];if (!cellsInRange.Contains(possibleCell)){cellsInRange.Add(grid.gridCells[epiX+x,epiY+y]);}}if (!(epiX-x<0|| (epiY-y<0))){possibleCell=grid.gridCells[epiX-x,epiY-y];if (!cellsInRange.Contains(possibleCell)){cellsInRange.Add(grid.gridCells[epiX-x,epiY-y]);}}if (!((epiX-x<0)|| (epiY+y>=grid.yMax))){possibleCell=grid.gridCells[epiX-x,epiY+y];if (!cellsInRange.Contains(possibleCell)){cellsInRange.Add(grid.gridCells[epiX-x,epiY+y]);}}if (!((epiX+x>=grid.xMax) || (epiY-y<0))){possibleCell=grid.gridCells[epiX+x,epiY-y];if (!cellsInRange.Contains(possibleCell)){cellsInRange.Add(grid.gridCells[epiX+x,epiY-y]);}}}}}returncellsInRange;}//This "Jumper Range" is a bredth-First search for finding the walkable range of an ability. //Basically, a path finding algorithm//Todo : Add "visted" code to make more efficientpublicvoidjumperRange(ExWhyCellcurrentCell,intjumpsLeft){// visited = new List<ExWhyCell>();cellsInRange.Add(currentCell);if (jumpsLeft==0||!currentCell.walkable){return;}//Upif (currentCell.yPosition!=grid.yMax){if (grid.gridCells[currentCell.xPosition,currentCell.yPosition+1].walkable) {jumperRange(grid.gridCells[currentCell.xPosition,currentCell.yPosition],jumpsLeft-1);}}//Downif (currentCell.yPosition!=0){if (grid.gridCells[currentCell.xPosition,currentCell.yPosition-1].walkable){jumperRange(grid.gridCells[currentCell.xPosition,currentCell.yPosition],jumpsLeft-1);}}//Leftif (currentCell.xPosition!=0){if (grid.gridCells[currentCell.xPosition-1,currentCell.yPosition].walkable){jumperRange(grid.gridCells[currentCell.xPosition,currentCell.yPosition],jumpsLeft-1);}}//Rightif (currentCell.xPosition!=grid.xMax){if (grid.gridCells[currentCell.xPosition+1,currentCell.yPosition].walkable){jumperRange(grid.gridCells[currentCell.xPosition,currentCell.yPosition],jumpsLeft-1);}}}publicvoidinitalize(intrnge,ExWhyCellepcntr,ExWhygrd){range=rnge;epicentre=epcntr;visual=Resources.Load<GameObject>("RangeVisual");grid=grd;cellsInRange=newList<ExWhyCell>();rangeVisuals=newList<GameObject>();}publicvoiddestroyVisual(){foreach (GameObjectgoinrangeVisuals){Destroy(go);}}//Spawns a blue visial effect for the range of abilities/ publicvoidspawnVisuals(){foreach(ExWhyCellcellincellsInRange){rangeVisuals.Add(Instantiate(visual,cell.cellGO.transform));}}//Finds the characters in already foudn cells. publicList<BattleCharacterObject>findCharactersInRange(){List<BattleCharacterObject>output=newList<BattleCharacterObject>();foreach (ExWhyCellcellincellsInRange){if (cell.occupier){output.Add(cell.occupier);}charactersInRange=output;}returnoutput;}}