void onPlantDestroyed(AGPEvent e) { var plantEvent = (PlantDestroyed)e; OldPlant plant = plantEvent.plant; FMODUnity.RuntimeManager.PlayOneShot(ondestroyEvent, plant.position); }
public void FindNeighbors(OldPlant p1) { foreach (OldPlant p2 in plants) { byte p1Level = (byte)p1.type; byte p2Level = (byte)p2.type; if (p1Level == p2Level || Mathf.Abs(p1Level - p2Level) == 1) { } else { continue; } float distance = Vector3.Distance(p1.position, p2.position); if (distance > Services.GameController.plantInfo[(int)PlantInfo.maxNeighborDistance, p1Level]) { continue; } if (!p1.neighbors.Contains(p2))//add this plant to its neighbor { p1.neighbors.Add(p2); p1.NewPlantUpdate(p2); } if (!p2.neighbors.Contains(p1))//add neighbor to this plant { p2.neighbors.Add(p1); p2.NewPlantUpdate(p1); } } }
public bool HaveBaby() { float level = (int)type + 1; Vector3 newPosition = position + Random.insideUnitSphere * Random.Range(Services.GameController.plantInfo[(int)PlantInfo.minBabyDistance, (int)type], Services.GameController.plantInfo[(int)PlantInfo.maxBabyDistance, (int)type]) * (level); newPosition.y = position.y + 5f; RaycastHit hit; Ray ray = new Ray(newPosition, Vector3.down); if (Physics.Raycast(ray, out hit)) { if (hit.collider.CompareTag("Ground") == false)//you hit something thats not ground? { return(false); } newPosition.y = hit.point.y; } else { //you hit nothing, somehow, you need to at least hit the ground! return(false); } OldPlant baby = Services.PlantManager.CreateNewPlant(type, newPosition); if (ReferenceEquals(baby, null)) { return(false); } else { babies.Add(baby); return(true); } }
public static void Load() { string path = "Assets/Resources/Save" + Services.GameController.saveId + ".json"; string json = System.IO.File.ReadAllText(path); Save save = JsonUtility.FromJson(json, typeof(Save)) as Save; Services.GameController.date = new DateTime(save.year, save.month, 1); foreach (OldPlant plant in Services.PlantManager.plants) { plant.Destroy(); } Services.PlantManager.plants.Clear(); foreach (PlantData data in save.plants) { OldPlant plant = new OldPlant((OldPlantType)data.plantType, data.position); plant.LoadPlant(data); Services.PlantManager.FindNeighbors(plant); Services.PlantManager.plants.Add(plant); } for (int i = 0; i < 3; i++) { if (Services.GameController.player.canAccessPlant[i + 1] == false) { //still trying to unlock this level if (Services.PlantManager.typeCount[i] >= Services.GameController.unlockLevels[i]) { Services.GameController.player.canAccessPlant[i + 1] = true; } } } }
void OnPlantCreated(AGPEvent e) { var plantEvent = (PlantCreated)e; OldPlant plant = plantEvent.plant; //Play creation sound FMODUnity.RuntimeManager.PlayOneShot(oncreateEvent, plant.position); }
void OnPlantGrownUp(AGPEvent e) { //Need To check if all FMOD get components work with decentralized eventsystem. //GetComponent<FMODUnity.StudioEvent.Emitter>().Play(); var plantEvent = (PlantGrown)e; OldPlant plant = plantEvent.plant; FMODUnity.RuntimeManager.PlayOneShot(oncreateEvent, plant.position); }
void OnPlantFed(AGPEvent e) { var plantEvent = (PlantJustFed)e; OldPlant plant = plantEvent.plant; FMODUnity.RuntimeManager.PlayOneShot(ondestroyEvent, plant.position); UnityEngine.Debug.Log("REEEEEE"); UnityEngine.Debug.Log("REEEEEE"); }
void OnPlantGrown(AGPEvent e) { var plantEvent = (PlantGrown)e; OldPlant plant = plantEvent.plant; if (plant.type == OldPlantType.Spread) { grassGrown++; if (check == GrownCheck.grassUnlock) { ActivateCounter("Grass grown: ", grassGrown, Services.GameController.unlockLevels[0]); //these update the counter if (grassGrown >= Services.GameController.unlockLevels[0]) { Debug.Log("FLOWER MSG"); DeactivateTutorial(); ActivateTutorial(tutorials[6], 20); //HEY YOU UNLOCKED FLOWERS check = GrownCheck.flowerUnlock; hasGivenUnlockTut = 0; } } } if (plant.type == OldPlantType.Grass) { flowersGrown++; if (check == GrownCheck.flowerUnlock) { ActivateCounter("Flowers grown: ", flowersGrown, Services.GameController.unlockLevels[1]); if (flowersGrown >= Services.GameController.unlockLevels[1]) { DeactivateCounter(); DeactivateTutorial(); ActivateTutorial(tutorials[7], 15); check = GrownCheck.bushUnlock; hasGivenUnlockTut = 0; } } } if (plant.type == OldPlantType.Shrub) { bushesGrown++; if (check == GrownCheck.bushUnlock) { ActivateCounter("Bushes grown: ", bushesGrown, Services.GameController.unlockLevels[2]); if (bushesGrown >= Services.GameController.unlockLevels[2]) { DeactivateCounter(); DeactivateTutorial(); ActivateTutorial(tutorials[8], 15); check = GrownCheck.gotTree; hasGivenUnlockTut = 0; } } } }
//this should only happen if a plant JUST reached a point where it can support others void OnPlantFed(AGPEvent e) { var pjf = (PlantJustFed)e; OldPlant plant = pjf.plant; if (plant.CanGiveEnergy == false) { return; } foreach (OldPlant other in plants) { if (other.CheckNeedThisPlant(plant)) { other.PlantFullUpdate(plant); } } }
void OnPlantDestroyed(AGPEvent e) { //var event = (PlantDestroyed) e; var pd = (PlantDestroyed)e; OldPlant plant = pd.plant; //remove plants from other people's lists foreach (OldPlant other in plants) { if (other.neighbors.Contains(plant)) { other.RemovePlantUpdate(plant); } if (other.babies.Contains(plant)) { other.babies.Remove(plant); } } deadPlants.Add(plant); }
public OldPlant CreateNewPlant(OldPlantType type, Vector3 pos, bool playerPlaced = false) { bool isCloseEnough = CloseToPylon(pos); if (!isCloseEnough) { Debug.Log("Plant is not in pylon radius"); return(null); } if (!playerPlaced) { foreach (OldPlant p in plants) { float distance = Vector3.Distance(pos, p.position); float maxAllowedDistance = 0f; if (p.type != type) { //they're different maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForOthers, (int)type]; } else { maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForSame, (int)type]; } //this is for all the same if (distance < maxAllowedDistance) { if ((int)p.type < (int)type - 1) { //its below it, so just destroy it instead p.Destroy(); } else { Debug.Log("Plant is too close to other plants"); return(null); } } } foreach (OldPlant p in newPlants) { float distance = Vector3.Distance(pos, p.position); float maxAllowedDistance = 0f; if (p.type != type) { //they're different maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForOthers, (int)type]; } else { maxAllowedDistance = Services.GameController.plantInfo[(int)PlantInfo.collideDistanceForSame, (int)type]; } //this is for all the same if (distance < maxAllowedDistance) { if ((int)p.type < (int)type - 1) { //its below it, so just destroy it instead p.Destroy(); } else { Debug.Log("Plant is too close to other plants"); return(null); } } } } OldPlant plant = new OldPlant(type, pos); if (type == OldPlantType.Tree && firstTreePlanted == false) { firstTreePlanted = true; Services.EventManager.Fire(new FirstTreePlanted()); } FindNeighbors(plant); if (playerPlaced) { plants.Add(plant); } else { newPlants.Add(plant); } Services.EventManager.Fire(new PlantCreated(plant)); return(plant); }
public PlantJustUnFed(OldPlant plant) { this.plant = plant; }
public PlantDestroyed(OldPlant plant) { this.plant = plant; }
public PlantGrown(OldPlant plant) { this.plant = plant; }
public PlantCreated(OldPlant plant) { this.plant = plant; }
public bool CheckNeedThisPlant(OldPlant plant) { return(needs.ContainsKey(plant.type) || plant.type == type); }
//this is called when a new plant is added to your neighbors public void NewPlantUpdate(OldPlant newPlant) { //you need it! CheckNeeds(); }
//when a plant you are neighbors with is updated to be able to need fulfilling public void PlantFullUpdate(OldPlant newPlant) { CheckNeeds(); }
//this is called when a plant is removed from your neighbors public void RemovePlantUpdate(OldPlant newPlant) { neighbors.Remove(newPlant); CheckNeeds(); }