public virtual void FollowPath() { if (((Vector2)gameObject.transform.position - goalPosition).magnitude < 0.03f) { hasFinishedGoingToLastStep = true; if (requestedTargetPositionInGrid != null) { isFollowingPath = false; SetNewPositionOnMapSettingWorldPosition(MapGridded.WorldToMapPosition(gameObject.transform.position)); StartFollowingPath(ASTARPathfinder.Instance.FindPath(positionInGrid, requestedTargetPositionInGrid)); requestedTargetPositionInGrid = null; return; } if (followedPath.Count == 0 || nextNodeToFollow == followedPath[followedPath.Count - 1]) { isFollowingPath = false; } else { ++indexOfFollowedPathNode; nextNodeToFollow = followedPath[indexOfFollowedPathNode]; if (CheckIfCanGoTo(new IntVector2(nextNodeToFollow.X, nextNodeToFollow.Y))) { positionInGridSyncVar = new Vector2(nextNodeToFollow.X, nextNodeToFollow.Y); RpcMoveFromTo(gameObject.transform.position, new Vector2(nextNodeToFollow.X, nextNodeToFollow.Y)); } else { isFollowingPath = false; RequestGoTo(new IntVector2(followedPath[followedPath.Count - 1].X, followedPath[followedPath.Count - 1].Y)); } } } }
public void ShowBuildGrid() { HideBuildGrid(); lastUsedCanBuildGridElements = new List <MapGridElement>(); placeOnMapGrid = MapGridded.WorldToMapPosition(gameObject.transform.position); for (int row = 0; row < height; ++row) { for (int column = 0; column < width; ++column) { if (MapGridded.Instance.IsInMap(new IntVector2(placeOnMapGrid.X + column, placeOnMapGrid.Y + row))) { if (!MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].IsWalkable && (MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].Unit != Builder)) { MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].ShowCannotBuildIndicator(); MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].HideCanBuildIndicator(); } else { MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].ShowCanBuildIndicator(); MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].HideCannotBuildIndicator(); } lastUsedCanBuildGridElements.Add(MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column]); } } } }
void Update() { Vector2 mousePositionInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition); IntVector2 positionInMap = MapGridded.WorldToMapPosition(mousePositionInWorld); if (IsInEditingArea(mousePositionInWorld)) { if (prefabShowingWhereYouArePuttingTile != null && IsInMap(positionInMap)) { prefabShowingWhereYouArePuttingTile.transform.position = MapGridded.MapToWorldPosition(positionInMap); if (Input.GetMouseButton(0)) { SaveTileToMap(positionInMap); } } else if (mineSelectionPrefab != null) { mineSelectionPrefab.transform.position = MapGridded.MapToWorldPosition(positionInMap); if (Input.GetMouseButton(0)) { SaveMineToMap(positionInMap); } } else if (lumberSelectionPrefab != null) { lumberSelectionPrefab.transform.position = MapGridded.MapToWorldPosition(positionInMap); if (Input.GetMouseButton(0)) { SaveLumberToMap(positionInMap); } } else if (player1MarkerSelectionPrefab != null) { player1MarkerSelectionPrefab.transform.position = MapGridded.MapToWorldPosition(positionInMap); if (Input.GetMouseButton(0) && IsInMap(positionInMap) && Map[positionInMap.Y, positionInMap.X].Tile.IsWalkable && Map[positionInMap.Y, positionInMap.X].Mine == null && Map[positionInMap.Y, positionInMap.X].Lumber == null) { player1Position = positionInMap; if (player1MarkerOnMapInstance != null) { Destroy(player1MarkerOnMapInstance); } player1MarkerOnMapInstance = Instantiate(player1MarkerPrefab, MapGridded.MapToWorldPosition(positionInMap), Quaternion.identity); } } else if (player2MarkerSelectionPrefab != null) { player2MarkerSelectionPrefab.transform.position = MapGridded.MapToWorldPosition(positionInMap); if (Input.GetMouseButton(0) && IsInMap(positionInMap) && Map[positionInMap.Y, positionInMap.X].Tile.IsWalkable && Map[positionInMap.Y, positionInMap.X].Mine == null && Map[positionInMap.Y, positionInMap.X].Lumber == null) { player2Position = positionInMap; if (player2MarkerOnMapInstance != null) { Destroy(player2MarkerOnMapInstance); } player2MarkerOnMapInstance = Instantiate(player2MarkerPrefab, MapGridded.MapToWorldPosition(positionInMap), Quaternion.identity); } } } }
public void SetPositionInMapGrid() { placeOnMapGrid = MapGridded.WorldToMapPosition(gameObject.transform.position); for (int row = 0; row < height; ++row) { for (int column = 0; column < width; ++column) { MapEditor.Instance.Map[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].Mine = this; } } }
void RpcPlaceOnMap(Vector2 buildingPositioninWorld) { placeOnMapGrid = MapGridded.WorldToMapPosition(buildingPositioninWorld); for (int row = 0; row < height; ++row) { for (int column = 0; column < width; ++column) { if (MapGridded.Instance.IsInMap(new IntVector2(placeOnMapGrid.X + column, placeOnMapGrid.Y + row)) || MapGridded.Instance.MapGrid[row, column].IsWalkable) { MapGridded.Instance.MapGrid[placeOnMapGrid.Y + row, placeOnMapGrid.X + column].Building = this; } } } }
public void SetBuildingToBuildPositionsInGrid(BuildingType buildingType, Vector2 buildPlaceInWorldSpace) { Building buildingtoBuild = Buildings.Instance.BuildingsList.Find(item => item.BuildingType == buildingType && item.Owner == owner); IntVector2 positionOfBuildingToBuild = MapGridded.WorldToMapPosition(buildPlaceInWorldSpace); buildingToBuildPositionsInGrid = new List <IntVector2>(); for (int row = 0; row < buildingtoBuild.Height; ++row) { for (int column = 0; column < buildingtoBuild.Width; ++column) { buildingToBuildPositionsInGrid.Add(new IntVector2(positionOfBuildingToBuild.X + column, positionOfBuildingToBuild.Y + row)); } } }
public List <MapGridElement> FindPathForBuilding(IntVector2 startNodePosition, Building building) { MapGridElement startNode = MapGridded.Instance.MapGrid[startNodePosition.Y, startNodePosition.X]; List <MapGridElement> closedNodes = new List <MapGridElement>(); List <MapGridElement> openNodes = new List <MapGridElement>(); openNodes.Add(startNode); startNode.PathNode.CostFromStart = 0; startNode.PathNode.HeuristicCostToGoal = (Mathf.Abs(startNode.X - MapGridded.WorldToMapPosition(building.transform.position).X) + Mathf.Abs(startNode.Y - MapGridded.WorldToMapPosition(building.transform.position).Y)) * 10; startNode.PathNode.CostFunctionValue = startNode.PathNode.CostFromStart + startNode.PathNode.HeuristicCostToGoal; while (openNodes.Count > 0) { MapGridElement actualOpenNode = GetPathNodeWithMinimumFunctionValue(openNodes); if (MapGridded.Instance.GetAdjacentGridElements(new IntVector2(actualOpenNode.X, actualOpenNode.Y)).Find(item => item.Building == building) != null) { return(ReconstructPath(startNode, actualOpenNode)); } openNodes.Remove(actualOpenNode); closedNodes.Add(actualOpenNode); foreach (MapGridElement nextNode in GetAdjacentNodesForPath(actualOpenNode, startNodePosition)) { if (closedNodes.Contains(nextNode)) { continue; } int testedCostFromStart = actualOpenNode.PathNode.CostFromStart + nextNode.GetCostToGetHereFrom(actualOpenNode); bool isTestedCostFromStartIsBetter = false; if (!openNodes.Contains(nextNode)) { openNodes.Add(nextNode); nextNode.PathNode.HeuristicCostToGoal = (Mathf.Abs(nextNode.X - MapGridded.WorldToMapPosition(building.transform.position).X) + Mathf.Abs(nextNode.Y - MapGridded.WorldToMapPosition(building.transform.position).Y)) * 10; isTestedCostFromStartIsBetter = true; } else if (testedCostFromStart < nextNode.PathNode.CostFromStart) { isTestedCostFromStartIsBetter = true; } if (isTestedCostFromStartIsBetter) { nextNode.PathNode.parentPathNode = actualOpenNode; nextNode.PathNode.CostFromStart = testedCostFromStart; nextNode.PathNode.CostFunctionValue = nextNode.PathNode.CostFromStart + nextNode.PathNode.HeuristicCostToGoal; } } } return(null); }
public void GoToBuildPlace(BuildingType buildingType, Vector2 buildPlaceInWorldSpace) { buildingToBuildType = buildingType; positionOfBuildingToBuild = MapGridded.WorldToMapPosition(buildPlaceInWorldSpace); SetBuildingToBuildPositionsInGrid(buildingType, buildPlaceInWorldSpace); IsSelectingPlaceForBuilding = false; RequestGoTo(positionOfBuildingToBuild); isGoingToBuildPlace = true; if (CheckIfIsInBuildingArea()) { if (CheckIfCanBuildInBuildingArea()) { isFollowingPath = false; isMoving = false; Build(); } } }
void Update() { if (!hasAuthority || SceneManager.GetActiveScene().name != "Game" || MapGridded.Instance.MapGrid == null) { return; } if (isSelectingBuildingPlace && Selector.CheckIfIsInSelectionArea()) { Vector2 griddedPosition = new Vector2(Selector.GetGridPositionFromMousePosition().X, Selector.GetGridPositionFromMousePosition().Y); buildingToBuild.transform.position = Selector.GetGriddedWorldPositionFromMousePosition(); buildingToBuild.ShowBuildGrid(); if (Input.GetMouseButtonUp(0)) { if (buildingToBuild.CouldBeBuildInPlace(MapGridded.WorldToMapPosition(buildingToBuild.transform.position), player.Selector.SelectedUnits[0])) { isSelectingBuildingPlace = false; buildingToBuild.HideBuildGrid(); CmdOrderUnitToBuild(buildingToBuild.BuildingType, buildingToBuild.transform.position); Destroy(buildingToBuild.gameObject); } } else if (Input.GetMouseButtonUp(1)) { isSelectingBuildingPlace = false; buildingToBuild.HideBuildGrid(); Destroy(buildingToBuild.gameObject); player.ActionButtonsController.ShowButtons(player.Selector.SelectedUnits[0]); } } else { if (Selector.CheckIfIsInSelectionArea()) { if (Input.GetMouseButtonUp(1) && player.Selector.SelectedUnits.Count > 0 && MapGridded.Instance.IsInMap(Selector.GetGridPositionFromMousePosition()) && player.Selector.SelectedUnits[0].Owner == MultiplayerController.Instance.LocalPlayer.PlayerType) { CmdRightClickCommand(Camera.main.ScreenToWorldPoint(Input.mousePosition), MultiplayerController.Instance.LocalPlayer.PlayerType); } } } }
public void LoadMap(string filePath) { List <string> lines = new List <string>(new StreamReader(filePath).ReadToEnd().Split('\n')); foreach (string line in lines) { string[] words = line.Split(' '); switch (words[0]) { case mapSizeFileKey: mapWidth = int.Parse(words[1]); mapHeight = int.Parse(words[2]); Map = new MapEditorGridElement[mapHeight, mapWidth]; break; case player1PositionKey: player1MarkerOnMapInstance = Instantiate(player1MarkerPrefab, MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))), Quaternion.identity); player1Position = MapGridded.WorldToMapPosition(player1MarkerOnMapInstance.transform.position); break; case player2PositionKey: player2MarkerOnMapInstance = Instantiate(player2MarkerPrefab, MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))), Quaternion.identity); player2Position = MapGridded.WorldToMapPosition(player2MarkerOnMapInstance.transform.position); break; case tileKey: SaveTileToMap(new IntVector2(int.Parse(words[1]), int.Parse(words[2])), (TileType)System.Enum.Parse(typeof(TileType), words[3])); break; case goldMineKey: SaveMineToMap(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); break; case lumberKey: SaveLumberToMap(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); break; } } }
public void FinishTraining() { GameObject instantiatedUnit = Instantiate(TrainedUnit.gameObject, MapGridded.MapToWorldPosition(MapGridded.Instance.GetFirstFreePlaceAround(MapGridded.WorldToMapPosition(gameObject.transform.position), width, height)), Quaternion.identity); instantiatedUnit.GetComponent <Unit>().InitializePositionInGrid(); NetworkServer.Spawn(instantiatedUnit); IsTraining = false; RpcFinishTraining(); actualTrainingTime = 0; }
private void PlaceYourselfOnMapGrid() { IntVector2 positionOnMapGrid = MapGridded.WorldToMapPosition(gameObject.transform.position); MapGridded.Instance.MapGrid[positionOnMapGrid.Y, positionOnMapGrid.X].Lumber = this; }
public static bool CheckMap(string mapName) { try { string wholeMapText = new StreamReader(Application.dataPath + "/" + MapEditor.mapsFolderName + "/" + mapName + ".map").ReadToEnd(); List <string> lines = new List <string>(wholeMapText.Split('\n')); int mapSizeX = 0; int mapSizeY = 0; Vector2 player1StartingPosition = -Vector2.one; Vector2 player2StartingPosition = -Vector2.one; MapGridElement[,] mapGrid = null; IntVector2 positionInMap; Vector2 postionToCreate; foreach (string line in lines) { string[] words = line.Split(' '); switch (words[0]) { case MapEditor.mapSizeFileKey: mapSizeX = int.Parse(words[1]); mapSizeY = int.Parse(words[2]); mapGrid = new MapGridElement[mapSizeY, mapSizeX]; break; case MapEditor.tileKey: positionInMap = new IntVector2(int.Parse(words[1]), int.Parse(words[2])); postionToCreate = MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); mapGrid[positionInMap.Y, positionInMap.X] = new MapGridElement(Tiles.Instance.TilesPrefabs.Find(item => item.TileType == (TileType)System.Enum.Parse(typeof(TileType), words[3]))); break; case MapEditor.goldMineKey: positionInMap = new IntVector2(int.Parse(words[1]), int.Parse(words[2])); postionToCreate = MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); foreach (IntVector2 minePositionInMap in Resources.Instance.MinePrefab.GetComponent <Mine>().GetMapPositions(positionInMap)) { mapGrid[minePositionInMap.Y, minePositionInMap.X].Mine = Resources.Instance.MinePrefab.GetComponent <Mine>(); } break; case MapEditor.lumberKey: positionInMap = new IntVector2(int.Parse(words[1]), int.Parse(words[2])); postionToCreate = MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); mapGrid[positionInMap.Y, positionInMap.X].Lumber = Resources.Instance.TreePrefab.GetComponent <LumberInGame>(); break; case MapEditor.player1PositionKey: player1StartingPosition = MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); break; case MapEditor.player2PositionKey: player2StartingPosition = MapGridded.MapToWorldPosition(new IntVector2(int.Parse(words[1]), int.Parse(words[2]))); break; } } if (mapGrid == null) { return(false); } foreach (MapGridElement mapGridElement in mapGrid) { if (mapGridElement == null) { return(false); } } if (mapSizeX <= 0 || mapSizeY <= 0 || mapSizeX > 50 || mapSizeY > 50 || player1StartingPosition == null || player2StartingPosition == null || player1StartingPosition == player2StartingPosition || player1StartingPosition.x < 0 || player1StartingPosition.x > mapSizeX - 1 || player1StartingPosition.y < 0 || player1StartingPosition.y > mapSizeY - 1 || player2StartingPosition.x < 0 || player2StartingPosition.x > mapSizeX - 1 || player2StartingPosition.y < 0 || player2StartingPosition.y > mapSizeY - 1 || !mapGrid[MapGridded.WorldToMapPosition(player1StartingPosition).Y, MapGridded.WorldToMapPosition(player1StartingPosition).X].IsWalkable || !mapGrid[MapGridded.WorldToMapPosition(player2StartingPosition).Y, MapGridded.WorldToMapPosition(player2StartingPosition).X].IsWalkable) { return(false); } } catch (Exception e) { return(false); } return(true); }
public void SetPositionInMapGrid() { placeOnMapGrid = MapGridded.WorldToMapPosition(gameObject.transform.position); MapEditor.Instance.Map[placeOnMapGrid.Y, placeOnMapGrid.X].Lumber = this; }
void CmdRightClickCommand(Vector2 mousePositionInWorld, PlayerType commander) { IntVector2 mousePositionOnMap = MapGridded.WorldToMapPosition(mousePositionInWorld); if (player.Selector.SelectedUnits.Count > 0 && MapGridded.Instance.IsInMap(mousePositionOnMap) && player.Selector.SelectedUnits[0].Owner == commander) { foreach (Unit selectedUnit in player.Selector.SelectedUnits) { if (selectedUnit.GetType() == typeof(Worker)) { if (!((Worker)selectedUnit).IsSelectingPlaceForBuilding) { ((Worker)selectedUnit).CancelBuild(); ((Worker)selectedUnit).CancelGatheringGold(); ((Worker)selectedUnit).CancelGatheringLumber(); RaycastHit2D hitInfo = Physics2D.GetRayIntersection(new Ray((Vector3)mousePositionInWorld - Vector3.forward, Vector3.forward), Mathf.Infinity, 1 << LayerMask.NameToLayer("Select")); if (hitInfo.collider != null && hitInfo.collider.transform.parent.GetComponent <Mine>() && ((Worker)selectedUnit).TakenGoldAmount == 0 && ((Worker)selectedUnit).TakenLumberAmount == 0) { ((Worker)selectedUnit).GoForGold(hitInfo.collider.transform.parent.GetComponent <Mine>()); } else if (hitInfo.collider != null && hitInfo.collider.transform.parent.GetComponent <LumberInGame>() && !hitInfo.collider.transform.parent.GetComponent <LumberInGame>().IsDepleted&& ((Worker)selectedUnit).TakenGoldAmount == 0 && ((Worker)selectedUnit).TakenLumberAmount == 0) { ((Worker)selectedUnit).GoForLumber(); } else if (hitInfo.collider != null && hitInfo.collider.transform.parent.GetComponent <Building>() && hitInfo.collider.transform.parent.GetComponent <Building>().BuildingType == BuildingType.Castle && hitInfo.collider.transform.parent.GetComponent <Building>().Owner == selectedUnit.Owner) { if (((Worker)selectedUnit).TakenGoldAmount > 0) { ((Worker)selectedUnit).ReturnWithGold(); } else if (((Worker)selectedUnit).TakenLumberAmount > 0) { ((Worker)selectedUnit).ReturnWithLumber(); } } else { selectedUnit.RequestGoTo(mousePositionOnMap); } } else { ((Worker)selectedUnit).CancelBuild(); } } else if (selectedUnit.GetType() == typeof(Warrior)) { RaycastHit2D hitInfo = Physics2D.GetRayIntersection(new Ray((Vector3)mousePositionInWorld - Vector3.forward, Vector3.forward), Mathf.Infinity, 1 << LayerMask.NameToLayer("Select")); if (hitInfo.collider != null && hitInfo.collider.transform.parent.GetComponent <Unit>() && hitInfo.collider.transform.parent.GetComponent <Unit>().Owner != selectedUnit.Owner) { ((Warrior)selectedUnit).StartAttack(hitInfo.collider.transform.parent.GetComponent <Unit>()); } else if (hitInfo.collider != null && hitInfo.collider.transform.parent.GetComponent <Building>() && hitInfo.collider.transform.parent.GetComponent <Building>().Owner != selectedUnit.Owner) { ((Warrior)selectedUnit).StartAttack(hitInfo.collider.transform.parent.GetComponent <Building>()); } else { if (((Warrior)selectedUnit).IsAttacking) { ((Warrior)selectedUnit).StopAttack(); } selectedUnit.RequestGoTo(mousePositionOnMap); } } else { selectedUnit.RequestGoTo(mousePositionOnMap); } } } }
public void LeaveMine(Worker visiter) { miners.Remove(visiter); if (miners.Count == 0) { RpcSetNonVisitedMineSprite(); } IntVector2 firstFreePlaceOnMapAroundMine = MapGridded.Instance.GetFirstFreePlaceAround(MapGridded.WorldToMapPosition(gameObject.transform.position), width, height); visiter.SetNewPositionOnMapSettingWorldPosition(firstFreePlaceOnMapAroundMine); visiter.RpcMoveFromTo(visiter.transform.position, visiter.transform.position); visiter.RpcShowYourself(); if (visiter.TakenGoldAmount > 0) { visiter.RpcSetGoldVisibility(true); visiter.ReturnWithGold(); } }
public bool CheckIfIsInBuildingArea() { return(buildingToBuildPositionsInGrid.Find(item => item.X == MapGridded.WorldToMapPosition(gameObject.transform.position).X&& item.Y == MapGridded.WorldToMapPosition(gameObject.transform.position).Y) != null); }
public void FinishBuild() { RpcShowYourself(); RpcSetNewPosition(MapGridded.MapToWorldPosition(MapGridded.Instance.GetFirstFreePlaceAround(MapGridded.WorldToMapPosition(buildingToBuild.transform.position), buildingToBuild.Width, buildingToBuild.Height))); positionInGridSyncVar = MapGridded.MapToWorldPosition(MapGridded.Instance.GetFirstFreePlaceAround(MapGridded.WorldToMapPosition(buildingToBuild.transform.position), buildingToBuild.Width, buildingToBuild.Height)); RpcStop(); }
public bool CheckIfIsNextToMine() { List <MapGridElement> AdjacentGridElements = MapGridded.Instance.GetAdjacentGridElements(MapGridded.WorldToMapPosition(gameObject.transform.position)); foreach (MapGridElement actualMapGridElement in AdjacentGridElements) { if (actualMapGridElement.Mine != null && actualMapGridElement.Mine == mineToGoForGold) { return(true); } } return(false); }
public IEnumerator GivingLumber() { castleToReturnWithGoods.Visiters.Add(this); yield return(new WaitForSeconds(timeOfGivingLumber)); castleToReturnWithGoods.Visiters.Remove(this); MultiplayerController.Instance.Players.Find(item => item.PlayerType == owner).LumberAmount += TakenLumberAmount; MultiplayerController.Instance.Players.Find(item => item.PlayerType == owner).AllGatheredLumber += TakenLumberAmount; TakenLumberAmount = 0; IntVector2 firstFreePlaceOnMapAroundCastle = MapGridded.Instance.GetFirstFreePlaceAround(MapGridded.WorldToMapPosition(castleToReturnWithGoods.transform.position), castleToReturnWithGoods.Width, castleToReturnWithGoods.Height); SetNewPositionOnMapSettingWorldPosition(firstFreePlaceOnMapAroundCastle); RpcMoveFromTo(gameObject.transform.position, gameObject.transform.position); RpcShowYourself(); GoForLumber(); }
public bool CheckIfIsNextToLumber() { List <MapGridElement> AdjacentGridElements = MapGridded.Instance.GetAdjacentGridElements(MapGridded.WorldToMapPosition(gameObject.transform.position)); foreach (MapGridElement actualMapGridElement in AdjacentGridElements) { if (actualMapGridElement.Lumber != null && actualMapGridElement.Lumber == lumberToCut) { return(true); } } return(false); }
public bool CheckIfIsNextToCastleToReturnGoods() { List <MapGridElement> AdjacentGridElements = MapGridded.Instance.GetAdjacentGridElements(MapGridded.WorldToMapPosition(gameObject.transform.position)); foreach (MapGridElement actualMapGridElement in AdjacentGridElements) { if (actualMapGridElement.Building != null && actualMapGridElement.Building == castleToReturnWithGoods) { return(true); } } return(false); }