Exemplo n.º 1
0
    void onPlantDestroyed(AGPEvent e)
    {
        var      plantEvent = (PlantDestroyed)e;
        OldPlant plant      = plantEvent.plant;

        FMODUnity.RuntimeManager.PlayOneShot(ondestroyEvent, plant.position);
    }
Exemplo n.º 2
0
 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);
         }
     }
 }
Exemplo n.º 3
0
    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);
        }
    }
Exemplo n.º 4
0
    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;
                }
            }
        }
    }
Exemplo n.º 5
0
    void OnPlantCreated(AGPEvent e)
    {
        var      plantEvent = (PlantCreated)e;
        OldPlant plant      = plantEvent.plant;

        //Play creation sound
        FMODUnity.RuntimeManager.PlayOneShot(oncreateEvent, plant.position);
    }
Exemplo n.º 6
0
    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);
    }
Exemplo n.º 7
0
    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");
    }
Exemplo n.º 8
0
    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;
                }
            }
        }
    }
Exemplo n.º 9
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);
            }
        }
    }
Exemplo n.º 10
0
    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);
    }
Exemplo n.º 11
0
    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);
    }
Exemplo n.º 12
0
 public PlantJustUnFed(OldPlant plant)
 {
     this.plant = plant;
 }
Exemplo n.º 13
0
 public PlantDestroyed(OldPlant plant)
 {
     this.plant = plant;
 }
Exemplo n.º 14
0
 public PlantGrown(OldPlant plant)
 {
     this.plant = plant;
 }
Exemplo n.º 15
0
 public PlantCreated(OldPlant plant)
 {
     this.plant = plant;
 }
Exemplo n.º 16
0
 public bool CheckNeedThisPlant(OldPlant plant)
 {
     return(needs.ContainsKey(plant.type) || plant.type == type);
 }
Exemplo n.º 17
0
 //this is called when a new plant is added to your neighbors
 public void NewPlantUpdate(OldPlant newPlant)
 {
     //you need it!
     CheckNeeds();
 }
Exemplo n.º 18
0
 //when a plant you are neighbors with is updated to be able to need fulfilling
 public void PlantFullUpdate(OldPlant newPlant)
 {
     CheckNeeds();
 }
Exemplo n.º 19
0
 //this is called when a plant is removed from your neighbors
 public void RemovePlantUpdate(OldPlant newPlant)
 {
     neighbors.Remove(newPlant);
     CheckNeeds();
 }