// placing food is more complicated due to grid public void placeFood(Vector3Int mouseGridPosition, FoodSourceSpecies species, int buildProgress = 0) { Vector3 FoodLocation = gridSystem.CellToWorld(mouseGridPosition); //equivalent since cell and world is 1:1, but in Vector3 FoodLocation += new Vector3((float)species.Size.x / 2, (float)species.Size.y / 2, 0); GameObject Food = foodSourceManager.CreateFoodSource(species.SpeciesName, FoodLocation); FoodSource foodSource = Food.GetComponent <FoodSource>(); gridSystem.AddFoodReferenceToTile(mouseGridPosition, species.Size, Food); if (buildProgress < this.GetStoreItem(species).buildTime) //If the food source has yet to fully construct, add a build buffer { foodSource.isUnderConstruction = true; GameManager.Instance.m_tileDataController.ConstructionFinishedCallback(() => { foodSource.isUnderConstruction = false; }); gridSystem.CreateRectangleBuffer(new Vector2Int(mouseGridPosition.x, mouseGridPosition.y), this.GetStoreItem(species).buildTime, species.Size, species.SpeciesName.Equals("Gold Space Maple") || species.SpeciesName.Equals("Space Maple") ? TileDataController.ConstructionCluster.ConstructionType.TREE : TileDataController.ConstructionCluster.ConstructionType.ONEFOOD, buildProgress); } else //Otherwise, make sure its needs are up to date { GameManager.Instance.UpdateAllNeedSystems(); foodSource.CalculateTerrainNeed(); foodSource.CalculateWaterNeed(); GameManager.Instance.m_inspector.UpdateCurrentDisplay(); } }
// Set up UI for move and delete private void SetMoveUI() { Vector3 screenPos = Camera.main.WorldToScreenPoint(objectToMove.transform.position); MoveButton.SetActive(true); DeleteButton.SetActive(true); MoveButton.transform.position = screenPos + new Vector3(-50, 100, 0); DeleteButton.transform.position = screenPos + new Vector3(50, 100, 0); switch (movingItemType) { case ItemType.ANIMAL: int price = itemByID[objectToMove.GetComponent <Animal>().PopulationInfo.species.SpeciesName].Price; moveCost = Mathf.RoundToInt(MoveCost * price); sellBackCost = Mathf.RoundToInt(SellBackRefund * price); break; case ItemType.FOOD: FoodSourceSpecies species = objectToMove.GetComponent <FoodSource>().Species; price = itemByID[species.SpeciesName].Price; moveCost = Mathf.RoundToInt(MoveCost * price); sellBackCost = Mathf.RoundToInt(SellBackRefund * price); break; case ItemType.TILE: LevelData.ItemData tileItemData = GameManager.Instance.LevelData.itemQuantities.Find(x => x.itemObject.ID.ToLower().Equals(objectToMove.name)); sellBackCost = Mathf.RoundToInt(SellBackRefund * tileItemData.itemObject.Price); break; default: break; } MoveButton.GetComponentInChildren <Text>().text = $"${moveCost}"; DeleteButton.GetComponentInChildren <Text>().text = $"${sellBackCost}"; }
public void placeFood(Vector3Int mouseGridPosition, FoodSourceSpecies species, int ttb = -1) { Vector3 FoodLocation = m_gridSystemReference.CellToWorld(mouseGridPosition); FoodLocation.x += (float)species.Size.x / 2; FoodLocation.y += (float)species.Size.y / 2; CreateFoodSource(species, FoodLocation, ttb); }
public void InitializeFoodSource(FoodSourceSpecies species, Vector2 position) { this.species = species; this.Position = position; this.GetComponent <SpriteRenderer>().sprite = species.FoodSourceItem.Icon; this.InitializeNeedValues(); this.accessibleTerrian = GameManager.Instance.m_tileDataController.CountOfTilesInRange(Vector3Int.FloorToInt(this.Position), this.Species.RootRadius); }
private Item GetStoreItem(FoodSourceSpecies foodSourceSpecies) { string itemID = ""; foreach (KeyValuePair <string, FoodSourceSpecies> nameToFoodSpecies in GameManager.Instance.FoodSources) { if (nameToFoodSpecies.Value == foodSourceSpecies) { itemID = nameToFoodSpecies.Key; } } return(this.FoodSourceStoreSection.GetItemByID(itemID)); }
public string GetSpeciesID(FoodSourceSpecies species) { if (GameManager.Instance.FoodSources.ContainsValue(species)) { for (var pair = GameManager.Instance.FoodSources.GetEnumerator(); pair.MoveNext() != false;) { if (pair.Current.Value.Equals(species)) { return(pair.Current.Key); } } } return(null); }
public GameObject CreateFoodSource(FoodSourceSpecies species, Vector2 position, int ttb = -1) { GameObject newFoodSourceGameObject = Instantiate(foodSourcePrefab, position, Quaternion.identity, this.transform); newFoodSourceGameObject.name = species.SpeciesName; FoodSource foodSource = newFoodSourceGameObject.GetComponent <FoodSource>(); foodSource.InitializeFoodSource(species, position); foodSources.Add(foodSource); Vector2 pos = position; pos.x -= species.Size.x / 2; pos.y -= species.Size.y / 2; m_gridSystemReference.AddFoodReferenceToTile(m_gridSystemReference.WorldToCell(pos), species.Size, newFoodSourceGameObject); if (ttb > 0) { m_gridSystemReference.CreateRectangleBuffer(new Vector2Int((int)pos.x, (int)pos.y), ttb, species.Size, species.SpeciesName.Equals("Gold Space Maple") || species.SpeciesName.Equals("Space Maple") ? TileDataController.ConstructionCluster.ConstructionType.TREE : TileDataController.ConstructionCluster.ConstructionType.ONEFOOD); foodSource.isUnderConstruction = true; m_gridSystemReference.ConstructionFinishedCallback(() => { foodSource.isUnderConstruction = false; }); } if (!foodSourcesBySpecies.ContainsKey(foodSource.Species)) { foodSourcesBySpecies.Add(foodSource.Species, new List <FoodSource>()); foodSourcesBySpecies[foodSource.Species].Add(foodSource); } else { foodSourcesBySpecies[foodSource.Species].Add(foodSource); } //Debug.Log("Food source being added: " + foodSource.Species.SpeciesName); ((FoodSourceNeedSystem)GameManager.Instance.NeedSystems[NeedType.FoodSource]).AddFoodSource(foodSource); // Register with NeedSystemManager GameManager.Instance.RegisterWithNeedSystems(foodSource); EventManager.Instance.InvokeEvent(EventType.NewFoodSource, newFoodSourceGameObject.GetComponent <FoodSource>()); return(newFoodSourceGameObject); }
/// <summary> /// Get a list of Food Source with the given species name. /// </summary> /// <param name="speciesName">Same as FoodSourceSpecies.SpeciesName</param> /// <returns>An list of Food Source with the given species name</returns> public List <FoodSource> GetFoodSourcesWithSpecies(string speciesName) { // Given species doesn't exist in the level if (!GameManager.Instance.FoodSources.ContainsKey(speciesName)) { Debug.Log("Food source not in level data"); return(null); } FoodSourceSpecies species = GameManager.Instance.FoodSources[speciesName]; // No food source of given species exist if (!foodSourcesBySpecies.ContainsKey(species)) { return(null); } else { return(foodSourcesBySpecies[species]); } }
private void TryPlaceFood(Vector3 worldPos, GameObject toMove) { FoodSource foodSource = toMove.GetComponent <FoodSource>(); FoodSourceSpecies species = foodSource.Species; Vector3Int pos = this.gridSystem.WorldToCell(worldPos); Vector3Int sizeOffset = new Vector3Int(foodSource.Species.Size.x / 2, foodSource.Species.Size.y / 2, 0); Vector3Int initialGridPos = gridSystem.WorldToCell(initialPos) - sizeOffset; //If the player clicks on the food source's original position, don't bother with the mess below if (pos == initialGridPos) { toMove.transform.position = initialPos; return; } //Check if the food source is under construction and if so, grab its build progress TileDataController.ConstructionCluster cluster = this.gridSystem.GetConstructionClusterAtPosition(initialGridPos); int buildProgress = this.GetStoreItem(species).buildTime; if (cluster != null) { buildProgress = cluster.currentDays; } //Remove the food so it doesn't interfere with its own placement removeOriginalFood(foodSource); float cost = moveCost; bool valid = gridSystem.IsFoodPlacementValid(worldPos, null, species) && GameManager.Instance.Balance >= cost; if (valid) //If valid, place the food at the mouse destination { placeFood(pos, species); GameManager.Instance.SubtractFromBalance(cost); } else //Otherwise, place it back at the original position with the correct build progress { placeFood(initialGridPos, species, buildProgress); toMove.transform.position = initialPos; } }
public TerrainNeed(TerrainNeedConstructData needConstructData, FoodSourceSpecies species) : base(needConstructData) { foodSourceSpecies = species; }