public static bool AnyVisible(this Shroud shroud, OccupiedCells cells) { foreach (var cell in cells) if (shroud.IsVisible(cell.First)) return true; return false; }
public static bool AnyVisible(this Shroud shroud, OccupiedCells cells) { foreach (var cell in cells) { if (shroud.IsVisible(cell.First)) { return(true); } } return(false); }
public static bool AnyExplored(this Shroud shroud, OccupiedCells cells) { // PERF: Avoid LINQ. foreach (var cell in cells) { if (shroud.IsExplored(cell.First)) { return(true); } } return(false); }
// Start is called before the first frame update void Start() { myStats = GetComponent <CharacterStats>(); blockedCells = levelTilemap.GetComponent <OccupiedCells>(); MoveToCell(startCell); originalTileColor = levelTilemap.GetColor(new Vector3Int(0, 0, 0)); rangeOfAction = new List <Vector3Int>(); currentAction = ""; storyTriggers = GameObject.Find("Narrative Director").GetComponent <NarrativeTriggers>(); }
// Start is called before the first frame update void Start() { levelTilemap = GameObject.Find("Level Tilemap").GetComponent <Tilemap>(); myStats = GetComponent <CharacterStats>(); blockedCells = levelTilemap.GetComponent <OccupiedCells>(); Vector3Int myPosition = levelTilemap.WorldToCell(transform.position); blockedCells.AddOccupiedCell(myPosition); playerCharactersInBattle = new List <CharacterStats>(); FindAllCharactersInBattle(); }
void SummonMonsters(int quantity, Vector3Int summonerCellPosition) { List <Vector3Int> potentialCells = new List <Vector3Int>(); potentialCells.Add(summonerCellPosition + new Vector3Int(1, 0, 0)); potentialCells.Add(summonerCellPosition + new Vector3Int(-1, 0, 0)); potentialCells.Add(summonerCellPosition + new Vector3Int(0, 1, 0)); potentialCells.Add(summonerCellPosition + new Vector3Int(0, -1, 0)); potentialCells.Add(summonerCellPosition + new Vector3Int(1, 1, 0)); potentialCells.Add(summonerCellPosition + new Vector3Int(-1, 1, 0)); potentialCells.Add(summonerCellPosition + new Vector3Int(1, -1, 0)); potentialCells.Add(summonerCellPosition + new Vector3Int(-1, -1, 0)); List <GameObject> monstersToSummon = new List <GameObject>(); monstersToSummon.Add(Instantiate(elementalCharacterPrefab)); monstersToSummon.Add(Instantiate(elementalCharacterPrefab)); foreach (Vector3Int position in potentialCells) { OccupiedCells blockedCells = levelTilemap.GetComponent <OccupiedCells>(); if (!blockedCells.IsCellOccupied(position)) { CharacterStats monsterStats = monstersToSummon[0].GetComponent <CharacterStats>(); monstersToSummon[0].transform.position = levelTilemap.GetCellCenterWorld(position); monsterStats.charName = monsterStats.charName + Random.Range(0, 1000); monstersToSummon[0].SetActive(true); monstersToSummon.RemoveAt(0); } if (monstersToSummon.Count <= 0) { break; } } monstersToSummon.Clear(); FindAllCharactersInScene(); }
List <Vector3Int> CalcOccupiedCells(RBTUnit unit) { var boundsCorners = unit.Bounds.Corners; // var cellIndices = new HashSet<Vector3Int>(); var occupiedCells = new OccupiedCells(); for (int i = 0; i < 4; i++) { var startCorner = boundsCorners[i % 4]; var endCorner = boundsCorners[(i + 1) % 4]; var startCell = GetCellIndex(startCorner); var endCell = GetCellIndex(endCorner); occupiedCells.Add(startCell); if (startCell == endCell) { continue; } occupiedCells.Add(endCell); var rayDir = (endCorner - startCorner).normalized; var step_dzdx = Mathf.Abs(rayDir.z / (rayDir.x + 0.0001f)); var step_dxdz = Mathf.Abs(rayDir.x / (rayDir.z + 0.0001f)); var rayStepX = Mathf.Sqrt(1 + Mathf.Pow(step_dzdx, 2)); var rayStepZ = Mathf.Sqrt(1 + Mathf.Pow(step_dxdz, 2)); int stepX, stepZ; float initialAdjustmentX, initialAdjustmentZ; if (rayDir.x < 0) { stepX = -1; initialAdjustmentX = startCorner.x - startCell.x; } else { stepX = 1; initialAdjustmentX = (startCell.x + 1) - startCorner.x; } if (rayDir.z < 0) { stepZ = -1; initialAdjustmentZ = startCorner.z - startCell.z; } else { stepZ = 1; initialAdjustmentZ = (startCell.z + 1) - startCorner.z; } step_dxdz *= stepX; step_dzdx *= stepZ; var rayLengthX = initialAdjustmentX * rayStepX; var rayLengthZ = initialAdjustmentZ * rayStepZ; float zAlongX = startCorner.z + step_dzdx * initialAdjustmentX; float xAlongZ = startCorner.x + step_dxdz * initialAdjustmentZ; var maxRayLength = (endCorner - startCorner).magnitude; var currentCellX = GetCellIndex(new Vector3(startCorner.x + stepX * initialAdjustmentX, startCorner.y, zAlongX)); if (rayLengthX < maxRayLength) { occupiedCells.Add(currentCellX); } var currentCellZ = GetCellIndex(new Vector3(xAlongZ, startCorner.y, startCorner.z + stepZ * initialAdjustmentZ)); if (rayLengthZ < maxRayLength) { occupiedCells.Add(currentCellZ); } bool endCellReached = false; while (!endCellReached) { bool commonAdjacentCell = currentCellZ.z - currentCellX.z == 1 && currentCellX.x - currentCellZ.x == 1; if (commonAdjacentCell) { occupiedCells.Add(new Vector3Int(currentCellZ.x, startCell.y, currentCellX.z)); } if (rayLengthX < rayLengthZ) { rayLengthX += rayStepX; if (rayLengthX < maxRayLength) { zAlongX += step_dzdx; currentCellX.x += stepX; currentCellX.z = Mathf.FloorToInt(zAlongX); occupiedCells.Add(currentCellX); } } else { rayLengthZ += rayStepZ; if (rayLengthZ < maxRayLength) { xAlongZ += step_dxdz; currentCellZ.z += stepZ; currentCellZ.x = Mathf.FloorToInt(xAlongZ); occupiedCells.Add(currentCellZ); } } endCellReached = rayLengthX >= maxRayLength && rayLengthZ >= maxRayLength; } } foreach (var entry in occupiedCells.rowEdgeValues) { var valuePair = entry.Value; var smallestX = valuePair.Item1; var biggestX = valuePair.Item2; var z = entry.Key; var y = Mathf.FloorToInt(boundsCorners[0].y); for (int x = smallestX + 1; x < biggestX; x++) { occupiedCells.Add(new Vector3Int(x, y, z)); } } int topCount = occupiedCells.Count; var allCells = new List <Vector3Int>(); allCells.Capacity = topCount; foreach (var row in occupiedCells.rowToCells.Values) { foreach (var cell in row) { allCells.Add(cell); } } var diffY = GetCellIndex(boundsCorners[0]).y - GetCellIndex(boundsCorners[4]).y; for (int y = 1; y <= diffY; y++) { for (int i = 0; i < topCount; i++) { allCells.Add(new Vector3Int(allCells[i].x, allCells[i].y - y, allCells[i].z)); } } return(allCells); }