public void SetResetDictionary() { spawners = GameObject.FindGameObjectsWithTag("spawner"); for (int i = 0; i < spawners.Length; i++) { SpawnerResetTime newTime = new SpawnerResetTime(); newTime.numberOfDaysLeft = 0; spawnerReset.Add(spawners[i].name, newTime); spawners[i].GetComponent <Gathering>().SpawnPlants(); } }
public void Populate(Gathering gatherer) { SpawnerResetTime sRT; //Debug.Log(spawnerReset.Count); if (spawnerReset.Count == 0) { SetResetDictionary(); } if (spawnerReset.TryGetValue(gatherer.gameObject.name, out sRT)) { if (gatherer.special && !GameObject.FindObjectOfType <ShrineManager>().endNature) { return; } if (sRT.numberOfDaysLeft > 0) { return; } else { SpawnerResetTime newTime = new SpawnerResetTime(); SpawnerData newData = new SpawnerData(); string newPlant = ""; /*do { * int ran = Random.Range(0, rl.ingredients.Count); * newPlant = plants[ran]; * } while (!rl.ingredients[newPlant].imagePath.StartsWith("Plants"));*/ float ran; int dom; if (gatherer.name.Contains("Forest")) { ran = Random.Range(0f, 1f); if (ran < 0.4f) { dom = Random.Range(0, LowForestList.Count); newPlant = LowForestList[dom]; } else if (ran < 0.7f && ran > 0.3f) { dom = Random.Range(0, MidForestList.Count); newPlant = MidForestList[dom]; } else { dom = Random.Range(0, HighForestList.Count); newPlant = HighForestList[dom]; } //newPlant = ForestList[ran]; } else if (gatherer.name.Contains("Meadow")) { ran = Random.Range(0f, 1f); if (ran > 0.6f) { dom = Random.Range(0, HighMeadowList.Count); newPlant = HighMeadowList[dom]; } else //if (ran < 0.7 && ran > 0.3) { dom = Random.Range(0, MidMeadowList.Count); newPlant = MidMeadowList[dom]; } /*else * { * dom = Random.Range(0, LowMeadowList.Count); * newPlant = LowMeadowList[dom]; * } */ //newPlant = MeadowList[ran]; } else if (gatherer.name.Contains("Mountain")) { ran = Random.Range(0f, 1f); if (ran > 0.4f) { dom = Random.Range(0, HighMountainList.Count); newPlant = HighMountainList[dom]; } else if (ran < 0.7f && ran > 0.3f) { dom = Random.Range(0, MidMountainList.Count); newPlant = MidMountainList[dom]; } else { dom = Random.Range(0, LowMountainList.Count); newPlant = LowMountainList[dom]; } //newPlant = MountainList[ran]; } newData.spawnedItem = rl.ingredients[newPlant]; newData.hasSpawnedItem = true; spawnerData.Add(gatherer.gameObject.name, newData); spawnerReset.TryGetValue(gatherer.gameObject.name, out newTime); newTime.numberOfDaysLeft = defaultResetTime; spawnerReset[gatherer.gameObject.name] = newTime; Sprite[] plantSprites = Resources.LoadAll <Sprite>("Plants/" + newData.spawnedItem.name); gatherer.GetComponent <SpriteRenderer>().sprite = plantSprites[plantSprites.Length - 1]; } } else { StartCoroutine(Spawn()); } }