public bool CanUseOnCell(int index, GridCell target) { if (target.cellType != GridCell.eCellType.DEFAULT) { return(false); } AbilityInfo info = abilityInfo [index]; if (info.ability.requiresFreeCell && target.currentUnit == null && target.CanTarget(info.ability.requiresFreeCell)) { return(true); } if (!info.ability.requiresFreeCell && target.CanTarget(info.ability.requiresFreeCell)) { if (target.currentUnit != null) { if (info.ability.castsPerTargetPerLvl [info.level - 1] != 0) { if (info.hitThisTurn.ContainsKey(target.currentUnit)) { if (info.hitThisTurn[target.currentUnit] <= info.ability.castsPerTargetPerLvl[info.level - 1]) { return(true); } } else { return(true); } } else { return(true); } } else { return(true); } } return(false); }
//Ability range public static HashSet <GridCell> GetAbilityRange(GridCell location, int minRange, int maxRange, bool los, bool linear, bool freeCell, bool ai = false) { GetGridCells(); HashSet <GridCell> inRange = new HashSet <GridCell> (); HashSet <GridCell> canSee = new HashSet <GridCell> (); HashSet <GridCell> retVal = new HashSet <GridCell> (); //non linear if (!linear) { foreach (GridCell c in cells.Values) { if (location.CalcDistance(c) <= maxRange && location.CalcDistance(c) >= minRange) { if (!inRange.Contains(c)) { if (c.CanTarget(freeCell)) { inRange.Add(c); } } } } } else { //linear for (int x = -maxRange; x <= maxRange; x++) { GridPos pos = new GridPos(location.gridPos.x - x, location.gridPos.y); if (cells.ContainsKey(pos)) { GridCell c = cells [pos]; if (c.CalcDistance(location) <= maxRange && c.CalcDistance(location) >= minRange) { if (c.CanTarget(freeCell)) { inRange.Add(c); } } } } for (int y = -maxRange; y <= maxRange; y++) { GridPos pos = new GridPos(location.gridPos.x, location.gridPos.y - y); if (cells.ContainsKey(pos)) { GridCell c = cells [pos]; if (c.CalcDistance(location) <= maxRange && c.CalcDistance(location) >= minRange) { if (c.CanTarget(freeCell)) { inRange.Add(c); } } } } } //Highlight // if (!ai) { // GameObject.FindGameObjectWithTag ("Battle Controller").GetComponent<GridHighlighter> ().HighlightNonVisibleCell (inRange); // } //Check LoS if (los) { foreach (GridCell c in inRange) { GridCell hit = CheckLoS(location.gridPos.x, location.gridPos.y, c.gridPos.x, c.gridPos.y); if (hit.CanTarget(freeCell)) { if (!canSee.Contains(hit)) { canSee.Add(hit); } } } } else { return(inRange); } //Filter out range errors foreach (GridCell c in canSee) { if (location.CalcDistance(c) >= minRange) { retVal.Add(c); } } return(retVal); }