public void CalculateRanges() { foreach (Tile t in GridManager.grid) { if (t.bEntityConnection.ContainsKey(this)) { t.bEntityConnection.Remove(this); } } Pathfinding.ThisIsCool cool1 = new Pathfinding.ThisIsCool(); Pathfinding.ThisIsCool cool2 = new Pathfinding.ThisIsCool(); Pathfinding.ThisIsCool cool3 = new Pathfinding.ThisIsCool(); Pathfinding.GridInfo gridInfo = new Pathfinding.GridInfo(); gridInfo.cleanse = false; gridInfo.useMovementPenalty = true; gridInfo.useThisIsCool = true; gridInfo.allowEntitiesToBeTargeted = true; tilesInMovementRange = Pathfinding.GetRangeObstacles(tile, movementRange, gridInfo, out cool1); gridInfo.useMovementPenalty = false; tilesInIntimidationRange = Pathfinding.GetRangeObstacles(tile, entity.stats.intimidationRange * BattleManager.distanceCoefficient, gridInfo, out cool2); tilesInMeleeRange = Pathfinding.GetRangeObstacles(tile, entity.stats.meleeRange * BattleManager.distanceCoefficient, gridInfo, out cool3); foreach (Tile t in GridManager.grid) { t.bEntityConnection.Add(this, new Tile.BattleEntityConnection()); if (tilesInMovementRange.Contains(t)) { t.bEntityConnection[this].inEntitiesMovementRange = true; } if (tilesInIntimidationRange.Contains(t)) { t.bEntityConnection[this].inEntitiesIntimidationRange = true; } if (tilesInMeleeRange.Contains(t)) { t.bEntityConnection[this].inEntitiesMeleeRange = true; } if (cool2.outerTiles.Contains(t)) { t.bEntityConnection[this].inEntitiesIntimidationRangeOuter = true; } if (cool3.outerTiles.Contains(t)) { t.bEntityConnection[this].inEntitiesMeleeRangeOuter = true; } } }
void GetInput() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit = new RaycastHit(); bool currentlyHittingATile = false; Tile tileHit = null; string currentTileName = ""; Physics.Raycast(ray, out hit); if (hit.transform != null) { if (hit.transform.parent.GetComponent <Tile>() != null) { currentlyHittingATile = true; tileHit = hit.transform.parent.GetComponent <Tile>(); currentTileName = tileHit.name; } else { currentlyHittingATile = false; tileHit = null; currentTileName = ""; } } else { currentlyHittingATile = false; tileHit = null; currentTileName = ""; } if (lastHit != currentTileName) { lastHit = currentTileName; update = true; } if (inputPhase == InputPhase.NoInput || entityOnTurn.lowerBodyAvailable == false) { return; } if (inputPhase == InputPhase.Move || inputPhase == InputPhase.Battle) { GetMouseInput(tileHit); } if (update == true) { bool isClickable = false; mouseClickAllowed = false; if (currentlyHittingATile) { isClickable = tileHit.isClickableForInput; } if (characterMoving == false) { if (inputPhase == InputPhase.Looking) { if (currentlyHittingATile == true) { if (tileHit.entityPresent != Tile.EntityType.None && tileHit.entityPresent != Tile.EntityType.Rock) { GridManager.instance.DisplayRange(tileHit.entityOnTile, RangeType.Any); DisplayEntityInfoWindow(true, tileHit.entityOnTile); } else { DisplayEntityInfoWindow(false, null); GridManager.instance.ResetGridColor(); } } else { DisplayEntityInfoWindow(false, null); GridManager.instance.ResetGridColor(); } } else if (inputPhase == InputPhase.Battle) { DisplayEntityInfoWindow(true, entityOnTurn); List <BattleEntity> enemiesInMeleeRange = entityOnTurn.GetEntitiesInRange(entityOnTurn, RangeType.Melee, Relationship.Enemy); GridManager.instance.DisplayRange(entityOnTurn, RangeType.Melee); } else if (inputPhase == InputPhase.Move) { DisplayEntityInfoWindow(true, entityOnTurn); if (currentlyHittingATile == true && isClickable == false) { GridManager.instance.DisplayRelativeRangeAndPath(entityOnTurn, RangeType.Any); } else if (currentlyHittingATile == true && isClickable == true) { mouseClickAllowed = true; Pathfinding.GridInfo gridInfo = new Pathfinding.GridInfo(); gridInfo.unreachableTiles = new List <Tile>(); foreach (Tile t in GridManager.grid) { if (!t.isAvailableToPathfinding) { gridInfo.unreachableTiles.Add(t); } } gridInfo.unreachableTiles.Remove(tileHit); entityOnTurn.path = Pathfinding.FindPath(entityOnTurn.tile, tileHit, out cost, gridInfo); GridManager.instance.DisplayRelativeRangeAndPath(entityOnTurn, RangeType.Any); } else { GridManager.instance.DisplayRelativeRangeAndPath(entityOnTurn, RangeType.Any); } } } update = false; } }
public void CalculateReachableAreas() { Pathfinding.GridInfo gridInfo = new Pathfinding.GridInfo(); Pathfinding.ThisIsCool cool1 = new Pathfinding.ThisIsCool(); gridInfo = new Pathfinding.GridInfo(); gridInfo.useLineOfSight = false; gridInfo.useMovementPenalty = true; gridInfo.unreachableTiles = new List <Tile>(); gridInfo.unPathableTiles = new List <Tile>(); // Set everything to be unreachable for this entity. foreach (Tile t in GridManager.grid) { gridInfo.unreachableTiles.Add(t); gridInfo.unPathableTiles.Add(t); } // Cycle through all tiles and set each one that isn't in enemy's intimidation range // and intimidation ring to reachable and solve for pathing. foreach (Tile t in GridManager.grid) { if (t.IsInEnemysIntimidationRange(this) == false) { gridInfo.unreachableTiles.Remove(t); gridInfo.unPathableTiles.Remove(t); } else if (t.IsInEnemysOuterIntimidationRing(this) == true) { gridInfo.unreachableTiles.Remove(t); } } // Cycle through all of this battle entity's battle entities in range. foreach (BattleEntity be in bEntitiesInIntimidationRange) { List <Tile> alliedIntimidationTiles = new List <Tile>(); foreach (BattleEntity ally in be.alliesSharingIntimidationRange) { alliedIntimidationTiles.AddRange(ally.tilesInIntimidationRange); } alliedIntimidationTiles.AddRange(be.tilesInIntimidationRange); foreach (Tile t in alliedIntimidationTiles) { bool flag = false; foreach (BattleEntity other in t.GetEntitiesInRange(be, RangeType.Intimidation, Relationship.Ally)) { if (be != other) { if (!be.alliesSharingIntimidationRange.Contains(other) && !bEntitiesInIntimidationRange.Contains(other)) { flag = true; } } } if (flag == false) { gridInfo.unreachableTiles.Remove(t); gridInfo.unPathableTiles.Remove(t); } } } gridInfo.cleanse = true; gridInfo.bEntity = this; tilesInMovementRange = Pathfinding.GetRangeObstacles(this.tile, movementRange, gridInfo, out cool1); foreach (Tile t in GridManager.grid) { if (gridInfo.unreachableTiles.Contains(t)) { t.isClickableForInput = false; } if (gridInfo.unPathableTiles.Contains(t)) { t.isAvailableToPathfinding = false; } } foreach (Tile t in tilesInMovementRange) { Tile.BattleEntityConnection bec = new Tile.BattleEntityConnection(); bec.inEntitiesMovementRange = true; if (!t.bEntityConnection.ContainsKey(this)) { t.bEntityConnection.Add(this, new Tile.BattleEntityConnection()); } else { t.bEntityConnection[this].inEntitiesMovementRange = true; } } }