// Moves unit to the target tile following the specified movement path. public void MoveUnit(GroundTileController targetTileController, Stack <Vector3> movementPath) { UpdateOccupyingTileController(targetTileController); moved = true; StartCoroutine(MoveCoroutine(movementPath)); }
public void setAllGroundSprites() { List <GameObject> tiles = getAllGroundTiles(); for (int i = 0; i < tiles.Count; i++) { GroundTileController controller = tiles[i].GetComponent <GroundTileController>(); if (!controller.dontChange) { if (controller.currentGroundType == GroundType.Dirt) { if (controller.plant.watered) { tiles[i].GetComponent <WateredTileChanger>().setWateredSprite(); } else { tiles[i].GetComponent <TilledGroundArtSetter>().detectAndSetSprite(); } } else { tiles[i].GetComponent <DirtArtSetter>().detectAndSetSprite(); } } } }
/* * ------------------------------------------------------------------------- * MARK: PERSISTENT DATA FUNCTIONS * ------------------------------------------------------------------------- */ // Load enemy unit's saved data. public void LoadSavedData(UnitInfo enemyInfo) { GroundTileController targetTileController = enemyController.UnitController.BattleController .TerrainController.GroundController .FindGroundTileControllerByXZ(enemyInfo.location.x, enemyInfo.location.z); UpdateOccupyingTileController(targetTileController); UpdatePositionFixed(Utils.XZProjVec(enemyInfo.location)); UpdateStats(enemyInfo.stats); }
/* * Handle party member movement after move menu selection. * Moves selected party member to target position and updates GUI state. */ public void MoveUnit(GroundTileController targetTileController) { EntityController memberController = guiController.BattleController.ActiveSelection; Assert.IsTrue(memberController.EntityType == Utils.EntityType.PartyMember); GroundController groundController = guiController.BattleController.TerrainController.GroundController; Stack <Vector3> movementPath = groundController.groundGraph.GetMoveMapPath(targetTileController.transform.position); groundController.groundGraph.ResetMoveMap(); groundController.ResetAllTileColors(); guiController.GuiState = Utils.GUIState.PartyTurnDefault; memberController.MoveUnit(targetTileController, movementPath); }
public Node(GroundTileController tileController) { this.tileController = tileController; northNode = Node.Empty; eastNode = Node.Empty; southNode = Node.Empty; westNode = Node.Empty; moveDepth = 0; moveVisited = false; moveColor = Utils.TileColor.None; prevMoveNode = Node.Empty; attackDepth = 0; attackVisited = false; attackColor = Utils.TileColor.None; prevAttackNode = Node.Empty; }
// Handles construction of graph. Performed once on initialization of terrain. public void ConstructGraph() { for (int x = 0; x < controller.GridSizeX; x++) { for (int z = 0; z < controller.GridSizeZ; z++) { GroundTileController tileController = controller.FindGroundTileControllerByXZ(x, z); Node node = new Node(tileController); nodeList[x * controller.GridSizeZ + z] = node; if (z > 0) { node.southNode = nodeList[x * controller.GridSizeZ + z - 1]; nodeList[x * controller.GridSizeZ + z - 1].northNode = node; } if (x > 0) { node.westNode = nodeList[(x - 1) * controller.GridSizeZ + z]; nodeList[(x - 1) * controller.GridSizeZ + z].eastNode = node; } } } }
// Private Functions private void setTilledBooleans() { Vector3 position = gameObject.transform.position; GroundTileController leftTile = groundTileManager.getTileByPosition(position + Vector3.left); GroundTileController rightTile = groundTileManager.getTileByPosition(position + Vector3.right); GroundTileController topTile = groundTileManager.getTileByPosition(position + Vector3.up); GroundTileController bottomTile = groundTileManager.getTileByPosition(position + Vector3.down); GroundTileController diagTopLeft = groundTileManager.getTileByPosition(position + Vector3.up + Vector3.left); GroundTileController diagTopRight = groundTileManager.getTileByPosition(position + Vector3.up + Vector3.right); GroundTileController diagBottomRight = groundTileManager.getTileByPosition(position + Vector3.down + Vector3.right); GroundTileController diagBottomLeft = groundTileManager.getTileByPosition(position + Vector3.down + Vector3.left); if (leftTile != null) { leftTilled = leftTile.currentGroundType == GroundType.Dirt; } else { leftTilled = false; } if (rightTile != null) { rightTilled = rightTile.currentGroundType == GroundType.Dirt; } else { rightTilled = false; } if (topTile != null) { topTilled = topTile.currentGroundType == GroundType.Dirt; } else { topTilled = false; } if (bottomTile != null) { bottomTilled = bottomTile.currentGroundType == GroundType.Dirt; } else { bottomTilled = false; } if (diagTopLeft != null) { topLeftTilled = diagTopLeft.currentGroundType == GroundType.Dirt; } else { topLeftTilled = false; } if (diagTopRight != null) { topRightTilled = diagTopRight.currentGroundType == GroundType.Dirt; } else { topRightTilled = false; } if (diagBottomLeft != null) { bottomLeftTilled = diagBottomLeft.currentGroundType == GroundType.Dirt; } else { bottomLeftTilled = false; } if (diagBottomRight != null) { bottomRightTilled = diagBottomRight.currentGroundType == GroundType.Dirt; } else { bottomRightTilled = false; } }
public void detectAndSetSprite() { Vector3 position = gameObject.transform.position; GroundTileController leftTile = groundTileManager.getTileByPosition(position + Vector3.left); GroundTileController rightTile = groundTileManager.getTileByPosition(position + Vector3.right); GroundTileController topTile = groundTileManager.getTileByPosition(position + Vector3.up); GroundTileController bottomTile = groundTileManager.getTileByPosition(position + Vector3.down); bool leftTilled; bool rightTilled; bool topTilled; bool bottomTilled; if (leftTile != null) { leftTilled = leftTile.currentGroundType == GroundType.Dirt; } else { leftTilled = false; } if (rightTile != null) { rightTilled = rightTile.currentGroundType == GroundType.Dirt; } else { rightTilled = false; } if (topTile != null) { topTilled = topTile.currentGroundType == GroundType.Dirt; } else { topTilled = false; } if (bottomTile != null) { bottomTilled = bottomTile.currentGroundType == GroundType.Dirt; } else { bottomTilled = false; } if (bottomTilled && topTilled && leftTilled && rightTilled) { spriteRenderer.sprite = allClosed; } else if (!bottomTilled && !topTilled && !leftTilled && !rightTilled) { spriteRenderer.sprite = allOpen; } else if (bottomTilled && !topTilled && !leftTilled && !rightTilled) { spriteRenderer.sprite = topOpen; } else if (topTilled && !bottomTilled && !leftTilled && !rightTilled) { spriteRenderer.sprite = bottomOpen; } else if (leftTilled && !rightTilled && !topTilled && !bottomTilled) { spriteRenderer.sprite = rightOpen; } else if (rightTilled && !leftTilled && !topTilled && !bottomTilled) { spriteRenderer.sprite = leftOpen; } else if (rightTilled && topTilled && !bottomTilled && !leftTilled) { spriteRenderer.sprite = bottomLeftOpen; } else if (leftTilled && topTilled && !bottomTilled && !rightTilled) { spriteRenderer.sprite = bottomRightOpen; } else if (rightTilled && bottomTilled && !topTilled && !leftTilled) { spriteRenderer.sprite = topLeftOpen; } else if (leftTilled && bottomTilled && !topTilled && !rightTilled) { spriteRenderer.sprite = topRightOpen; } else { spriteRenderer.sprite = allClosed; } }
/* * ------------------------------------------------------------------------- * MARK: UNIT MOVEMENT FUNCTIONS * ------------------------------------------------------------------------- */ // Updates unit's occupying tile. public void UpdateOccupyingTileController(GroundTileController targetTileController) { OccupyingTileController.occupyingEntity = EntityController.Empty; targetTileController.occupyingEntity = this; OccupyingTileController = targetTileController; }
public void useEquippedItem() { ItemType item = playerInventory.heldItem; GroundTileController controller = groundTileManager.getTileByPosition(selectedTileController.selectedTilePosition); if (selectedTileController.selectedTilePosition == groundTileManager.ovenPosition) { if (!foodManager.isCooking) { foodManager.toggleRecipePanel(); } } else if (selectedTileController.selectedTilePosition == groundTileManager.vendingMachinePosition) { // Open shop menu. shopManager.toggleShopPanel(); } else if (selectedTileController.selectedTilePosition != groundTileManager.belowVendingMachinePosition) { switch (item) { case ItemType.WaterCan: if (controller.currentGroundType == GroundType.Dirt) { controller.plant.waterGround(); sfxPlayer.playWaterSound(); } break; case ItemType.Hoe: if (selectedTileController.selectedTilePosition != groundTileManager.cratePosition) { controller.groundHitWithHoe(); sfxPlayer.playHitGround(); } break; case ItemType.CarrotSeed: case ItemType.PotatoeSeed: case ItemType.GarlicSeed: case ItemType.PepperSeed: case ItemType.ChickpeaSeed: if (controller.currentGroundType == GroundType.Dirt && !controller.plant.seedPresent) { controller.plantSeed(item); playerInventory.deleteInventoryItem(); } break; case ItemType.Carrot: case ItemType.Potatoe: case ItemType.Pepper: case ItemType.Chickpea: case ItemType.Garlic: if (selectedTileController.selectedTilePosition == groundTileManager.cratePosition) { // store it foodManager.addItemToStorage(item); playerInventory.deleteInventoryItem(); } else { // eat it playerInventory.deleteInventoryItem(); ageManager.eatFood(foodManager.getAgeFromItemType(item)); sfxPlayer.playEatFoodSound(); } break; case ItemType.RecipeOne: case ItemType.RecipeTwo: case ItemType.RecipeThree: case ItemType.RecipeFour: case ItemType.RecipeFive: playerInventory.deleteInventoryItem(); ageManager.eatFood(foodManager.getAgeFromItemType(item)); sfxPlayer.playEatFoodSound(); break; case ItemType.None: if (controller.plant.canBePicked) { playerInventory.setNewInventoryItem(plantManager.getItemTypeFromPlantType(controller.plant.plantType)); controller.plant.pickPlant(); sfxPlayer.playPickupPlantSound(); } break; default: Debug.Log("Unhandled ItemType in UseItem"); break; } } }
private void Awake() { spriteRenderer = gameObject.transform.GetChild(0).GetComponent <SpriteRenderer>(); groundTileController = gameObject.GetComponent <GroundTileController>(); }