void TryToUseObject(GameObject animal)
    {
        if (ObjectInHand != null)
        {
            AnimalStatistics stats = animal.GetComponent <AnimalStatistics>();
            HeldObject       obj   = ObjectInHand.GetComponent <HeldObject>();

            if (!obj.IsCarryingUnits())
            {
                return;
            }

            float food  = 0;
            float water = 0;
            switch (obj.GetTypeOfObject())
            {
            case TypeOfObject.ResourceCollector:
                stats.RetrieveResourceFromAnimal();
                break;

            case TypeOfObject.Bucket:
                water = (obj.IsCarryingUnits() ? obj.GetNumUnitsHeld() : 0);
                ConsumedPerpetualObject();
                break;

            case TypeOfObject.Hay:
                food = obj.GetNumUnitsHeld();
                ConsumedOneTimeUseObject();
                break;
            }
            stats.GiveFoodAndWater(food, water);
        }
    }
Example #2
0
    void PassInNewGeneralStats(ref AnimalStatistics childStats, AnimalStatistics parent1, AnimalStatistics parent2)
    {
        float  StartWillPer    = (Random.value < 0.5f ? parent1.GetStartingWTB() : parent2.GetStartingWTB());
        float  MaxWillBreed    = (Random.value < 0.5f ? parent1.GetMaxWTB() : parent2.GetMaxWTB());
        float  ReqWillBreed    = (Random.value < 0.5f ? parent1.GetReqWTBPercent() : parent2.GetReqWTBPercent());
        float  WillChangeAm    = (Random.value < 0.5f ? parent1.GetWillChangeAm() : parent2.GetWillChangeAm());
        float  WillChangeTimer = (Random.value < 0.5f ? parent1.GetWillChangeTimer() : parent2.GetWillChangeTimer());
        float  PostBreedPer    = (Random.value < 0.5f ? parent1.GetPostBreedPercent() : parent2.GetPostBreedPercent());
        float  StartHungPer    = (Random.value < 0.5f ? parent1.GetStartHungPer() : parent2.GetStartHungPer());
        float  StartThirstPer  = (Random.value < 0.5f ? parent1.GetStartThirstPer() : parent2.GetStartThirstPer());
        float  MaxFood         = (Random.value < 0.5f ? parent1.GetMaxFood() : parent2.GetMaxFood());
        float  MaxWater        = (Random.value < 0.5f ? parent1.GetMaxWater() : parent2.GetMaxWater());
        float  FoodDec         = (Random.value < 0.5f ? parent1.GetFoodDec() : parent2.GetFoodDec());
        float  WaterDec        = (Random.value < 0.5f ? parent1.GetWaterDec() : parent2.GetWaterDec());
        float  FoodDecTimer    = (Random.value < 0.5f ? parent1.GetFoodDecTimer() : parent2.GetFoodDecTimer());
        float  WaterDecTimer   = (Random.value < 0.5f ? parent1.GetWaterDecTimer() : parent2.GetWaterDecTimer());
        float  ResDecTimer     = (Random.value < 0.5f ? parent1.GetResDecTimer(): parent2.GetResDecTimer());
        float  ResourceInc     = (Random.value < 0.5f ? parent1.GetResourceIncrease() : parent2.GetResourceIncrease());
        float  ResourceValue   = (Random.value < 0.5f ? parent1.GetResourceValue() : parent2.GetResourceValue());
        int    RewardMoney     = Mathf.FloorToInt(((parent1.GetRewardValue() + parent2.GetRewardValue()) / 2f) * Random.Range(0.5f, 2f));
        string NewBreed        = CreateNewBreed(parent1.GetBreed(), parent2.GetBreed());



        childStats.SetAnimalCanvas(AnimalManager.instance.GetCanvasPrefab());

        childStats.IsNewChild(StartWillPer, MaxWillBreed, ReqWillBreed, WillChangeAm, WillChangeTimer, PostBreedPer, StartHungPer, StartThirstPer,
                              MaxFood, MaxWater, FoodDec, WaterDec, FoodDecTimer, WaterDecTimer, ResDecTimer, ResourceInc, ResourceValue, RewardMoney, NewBreed);
    }
Example #3
0
    void CreateChildObject(Material main, Material second, GameObject parent1, GameObject parent2)
    {
        GameObject       Child = new GameObject();
        AnimalStatistics stats = Child.AddComponent <AnimalStatistics>();
        AnimalMovement   move  = Child.AddComponent <AnimalMovement>();
        BoxCollider      coll  = Child.AddComponent <BoxCollider>();



        GameObject[] BodyParts = new GameObject[4];
        for (int i = 0; i < 4; ++i)
        {
            BodyParts[i] = (Random.value < 0.5f ? parent1.transform.GetChild(i).gameObject : parent2.transform.GetChild(i).gameObject);
        }


        GameObject Body = Instantiate(BodyParts[0]);

        Body.transform.parent = Child.transform;

        GameObject   NewPart;
        MeshRenderer TempMeshRend = Body.GetComponent <MeshRenderer>();

        ApplyMaterial(main, second, TempMeshRend);

        for (int i = 1; i < 4; ++i)
        {
            NewPart = Instantiate(BodyParts[i]);
            NewPart.transform.parent   = Child.transform;
            NewPart.transform.position = Body.transform.GetChild(i - 1).position;

            if (i == 2)
            {
                for (int j = 0; j < NewPart.transform.childCount; ++j)
                {
                    TempMeshRend = NewPart.transform.GetChild(j).GetComponent <MeshRenderer>();
                    ApplyMaterial(main, second, TempMeshRend);
                }
            }
            else
            {
                TempMeshRend = NewPart.GetComponent <MeshRenderer>();
                ApplyMaterial(main, second, TempMeshRend);
            }
        }

        PassInNewGeneralStats(ref stats, parent1.GetComponent <AnimalStatistics>(), parent2.GetComponent <AnimalStatistics>());
        PassInNewCollider(ref coll, (Random.value < 0.5f ? parent1.GetComponent <BoxCollider>() : parent2.GetComponent <BoxCollider>()));
        PassInNewMoveVars(ref move, (Random.value < 0.5f ? parent1.GetComponent <AnimalMovement>() : parent2.GetComponent <AnimalMovement>()));

        Child.tag = (Random.value < 0.5f ? parent1.tag : parent2.tag);
        Child.transform.position = (parent1.transform.position + parent2.transform.position) / 2f;
    }
Example #4
0
 private void Start()
 {
     coll         = this.GetComponent <BoxCollider>();
     AnimalStats  = this.GetComponent <AnimalStatistics>();
     CurrentTimer = TimeBetweenMovements;
 }
Example #5
0
 void Awake()
 {
     Instance = this;
 }
Example #6
0
 private void Awake()
 {
     CurrentAnimalStatistics = gameObject.GetComponent <AnimalStatistics>();
     AnimalMovement          = gameObject.GetComponent <AnimalMovement>();
     partner = null;
 }