Beispiel #1
0
 //
 private void OnCollisionEnter2D(Collision2D collision)
 {
     //Debug.Log(collision.collider.transform.gameObject.name);
     if (collision.collider.CompareTag("Plant"))
     {
         // touch a plant --> eat food mode
         plantToEat = collision.collider.transform.gameObject.GetComponent <PlantBehavior>();
         mode       = 2;
     }
     else if (collision.collider.CompareTag("Ant"))
     {
         // ant has food
         friend = collision.collider.transform.gameObject.GetComponent <Ant>();
         if (mode == 3 && friend != lastFriend && (friend.mode == 0 || friend.mode == 4) && friendsToHelp > 0)
         {
             // friend do not has food, friend is searching for food, friend is not last friend met
             // we pass ONCE to friend our last visited plant's position
             friend.lastDetectedPlant = lastDetectedPlant;
             friend.mode = 61;
             friendsToHelp--;
             prevMode = mode;
             mode     = 6;
         }
     }
 }
Beispiel #2
0
    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.tag == "Plant")
        {
            GameObject    plant          = collider.gameObject;
            PlantBehavior plantVariable  = plant.GetComponent <PlantBehavior>();
            GameObject    player         = GameObject.Find("Player");
            PlayerPocket  playerVariable = player.GetComponent <PlayerPocket>();

            playerVariable.money += plantVariable.valuePlant;
            score += plantVariable.valuePlant;

            if (objectiveChecker)
            {
                GameObject plantState = plant.transform.GetChild(0).gameObject;
                if (objectiveGiver.objective.type == ObjectiveType.Collecting)
                {
                    objectiveGiver.objective.goal.CollectingCompleted(plantState.tag);
                }
                else
                {
                    objectiveGiver.objective.goal.TimeLimitCompleted(plantState.tag);
                }
            }
            GameObject    coinObject    = Instantiate(coin, new Vector3(collider.transform.position.x, collider.transform.position.y, collider.transform.position.z), Quaternion.Euler(90, 0, 90));
            MoneyBehavior moneyVariable = coinObject.GetComponent <MoneyBehavior>();
            moneyVariable.money = plantVariable.valuePlant;

            Destroy(collider.gameObject);
        }
    }
Beispiel #3
0
    void EatFood() // MODE 2
    {
        stopTimer += Time.deltaTime;
        // stop sometimes to re-orient randomly
        if (plantToEat.foodQuantity > 0)
        {
            if (stopTimer > eatDur)
            {
                vel     = vel * 0; // we stp
                stopDur = clock * Random.Range(0.2f, 0.5f);

                plantToEat.Eat(1);
                // go to "ReturnWithFood" mode avec collecting food !
                prevMode = 3;
                mode     = 5;
                // reset timer
                stopTimer = 0;
            }
        }
        else
        {
            plantToEat = null;
            prevMode   = 2;
            mode       = 0;
        }
    }
Beispiel #4
0
    public void cmdPlantInteraction(PlantBehavior plant)   // Does NOT cover new plant
    {
        int toolNr = interacUI.currentlySelected;

        switch (toolNr)
        {
        case -1:     // No tool selected
            return;

        case 0:     //SHOVEL
            if (currentGarden.netId != ownGarden.netId)
            {
                Debug.LogWarning("Tried to use shovel on foreign soil!");
            }
            else
            {
                SoundManager sm = SoundManager.self;
                sm.playRandomAudio(0, 3);     // Harke 1 - 4
                Destroy(plant.gameObject);
            }
            break;

        case 1:        //WATERING
            //if (currentGarden.netId == ownGarden.netId) {
            if (false) // Showcase/Debug
            {
                Debug.LogWarning("Tried to wet their plants!");
            }
            else
            {
                SoundManager sm = SoundManager.self;
                sm.playRandomAudio(8, 11);     // Wasser 1 -4

                PerformCooldownAction(plant, wateringCooldowns, 0, CmdWaterPlant, ref wateringCounter);
                UpdateInteracUI();
            }

            break;

        case 2:     //MANURE
            PerformCooldownAction(plant, wateringCooldowns, 0, CmdFertilizePlant, ref wateringCounter);
            UpdateInteracUI();
            break;

        case 3:     //SEED 1
        case 4:     //SEED 2
        case 5:     //SEED 3
        case 6:     //SEED 4
            Debug.LogWarning("Cannot plant here - there is already another plant.");
            break;

        default:
            Debug.Log("An Error has occured - currentlySelected int from InteractionUI is wrong");
            break;
        }
    }
Beispiel #5
0
    private void OnTriggerEnter(Collider other)
    {
        GameObject plant = other.gameObject;

        if (plant.tag == "Plant")
        {
            PlantBehavior plantVariable = plant.GetComponent <PlantBehavior>();
            plantVariable.valuePlant += plantVariable.valuePlant * 10 / 100;
        }
    }
Beispiel #6
0
    public void CmdWaterPlant(PlantBehavior plant)
    {
        var result = PerformCooldownAction(plant, wateringCooldowns, plant.GetWateringCooldown(), p => p.CareFor(), ref wateringCounter);

        if (result)
        {
            wateringCounter++;
            if (wateringCounter >= wateringsForSeedAward)
            {
                AwardSeeds();
                wateringCounter = 0;
            }
        }
    }
Beispiel #7
0
    public void CmdFertilizePlant(PlantBehavior plant)
    {
        var time = NetworkTime.time;

        if (time + NetworkTime.timeStandardDeviation >= fertilizingCooldown)
        {
            var result = PerformCooldownAction(plant, fertilizingCooldowns, plant.GetFertilizingCooldown(), p => p.CareFor(2), ref fertilizingCounter);
            if (result)
            {
                fertilizingCounter++;
                CheckSeedSlotUnlocks();
                fertilizingCooldown = time + fertilizingCooldownDuration;
            }
        }
    }
    // When this herbivore collides with its food, the food should get eaten
    private void OnCollisionStay(Collision collision)
    {
        PlantBehavior plant = collision.gameObject.GetComponent <PlantBehavior>();

        if (hunger.isHungry() && foodList.Contains(collision.gameObject.tag) && plant != null)
        {
            // can only eat if the plant is an adult
            if (plant.size == PlantSize.Adult)
            {
                hunger.Eat(); // Increments hunger points by 1
                plant.GetEaten();
                currentFood = null;
            }
        }
    }
Beispiel #9
0
    private bool PerformCooldownAction(PlantBehavior plant, SyncDictionary <NetworkIdentity, double> cooldowns, double cooldownDuration, CooldownActionDelegate action, ref int counter)
    {
        var netid       = plant.gameObject.GetComponent <NetworkIdentity>() as NetworkIdentity;
        var time        = NetworkTime.time;
        var cooldownEnd = time - cooldownDuration; // If we haven't watered this plant yet, pretend the cooldown just elapsed.

        cooldowns.TryGetValue(netid, out cooldownEnd);
        if (time + NetworkTime.timeStandardDeviation >= cooldownEnd) // Give some wiggle room for comparison to account for time variation
        {
            action(plant);
            cooldowns[netid] = time + cooldownDuration;
            counter++;
            return(true);
        }
        return(false);
    }
Beispiel #10
0
    void changeState()
    {
        //Debug.Log("CHANGING...");
        targetTime = 3.0f;
        if (gameObject.transform.parent != null)
        {
            Instantiate(nextObject, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity, transform.parent);
        }
        else
        {
            Instantiate(nextObject, new Vector3(transform.position.x, transform.position.y, transform.position.z), nextObject.transform.rotation);
        }
        PlantBehavior nextVariable = nextObject.GetComponent <PlantBehavior>();

        Destroy(gameObject);
    }
    public override void GetFood()
    {
        // Only get food if the animal is hungry
        if (currentFood == null && hunger.isHungry())
        {
            // check for food in a certain radius
            Collider[] colliders = Physics.OverlapSphere(animalBody.position, searchRadius);
            foreach (Collider c in colliders)
            {
                // if there is viable food in the radius, go for it
                if (foodList.Contains(c.gameObject.tag))
                {
                    // make sure the plant is an adult
                    PlantBehavior plant = c.gameObject.GetComponent <PlantBehavior>();
                    if (plant && plant.size == PlantSize.Adult)
                    {
                        currentFood = c.gameObject;
                        break;
                    }
                }
            }
        }

        if (currentFood != null)
        {
            // check that this plant is still suitable size
            PlantBehavior plant = currentFood.GetComponent <PlantBehavior>();
            if (plant && plant.size != PlantSize.Adult)
            {
                currentFood = null;
            }
            else
            {
                // move toward the food
                // INFO: this fixes minor bug where animal moves into the ground when approaching plant (kind of hacky)
                float   adjustmentHeight = (animalCollider.size.y * animalBody.localScale.y) / 2;
                Vector3 foodLocation     = new Vector3(currentFood.transform.position.x, currentFood.transform.position.y + adjustmentHeight,
                                                       currentFood.transform.position.z);
                animalBody.LookAt(foodLocation);
                animalBody.position = Vector3.MoveTowards(animalBody.position, foodLocation, searchSpeed * Time.fixedDeltaTime);
                // animalBody.position += animalBody.forward * searchSpeed * Time.fixedDeltaTime;
            }
        }
    }
Beispiel #12
0
    public void CmdPlantSeed(int seedSlot, Vector2 location)
    {
        if (seedSlot >= seedInventory.Count)
        {
            Debug.LogWarning($"Atempt to plant a seed from slot {seedSlot}, but the player has only {seedInventory.Count} slots unlocked.");
            return;
        }
        if (seedInventory[seedSlot] == -1)
        {
            Debug.LogWarning($"Atempt to plant a seed from slot {seedSlot}, but that slot is empty.");
            return;
        }
        if (currentGarden.netId != ownGarden.netId)
        {
            Debug.LogWarning($"Atempt to plant a seed in a garden that doesn't belong to the acting player.");
            return;
        }
        PlantBehavior plantPrefab = plantTypeMapping.GetPlantTypePrefab(seedInventory[seedSlot]);
        var           plant       = Instantiate(plantPrefab, location, Quaternion.identity, currentGarden.transform);

        NetworkServer.Spawn(plant.gameObject);
        seedInventory[seedSlot] = -1;
    }