Example #1
0
    public void CreateBaby(Creature father)
    {
        babyParams = new Params();
        bool oneChange = true;

        for (int j = 0; j < babyParams.paramsList.Count; j++)
        {
            AParam p = babyParams.paramsList[j];
            ImitationColor(father, p, j);
            float rnd = Random.value;
            if (rnd <= 0.5f)
            {
                p.IsActive = father.Params.paramsList[j].IsActive;
            }
            else
            {
                p.IsActive = Own.Params.paramsList[j].IsActive;
            }
            if (oneChange && rnd < 0.1f)            //Mutation
            {
                p.IsActive = !p.IsActive;
                oneChange  = false;
            }
            if (!p.IsActive)
            {
                continue;
            }
            for (int i = 0; i < p.paramsList.Count; i++)
            {
                AParamValue param = babyParams.paramsList[j].paramsList[i];
                rnd = Random.value;
                if (rnd <= 0.5f)
                {
                    param.Level = (father.Params.paramsList[j].paramsList[i]).Level;
                }
                else
                {
                    param.Level = (Own.Params.paramsList[j].paramsList[i]).Level;
                }
                rnd = Random.value;
                if (rnd <= 0.1024f)
                {
                    param.Increase();
                }
                else if (rnd <= 0.2048f)
                {
                    param.Decrease();
                }
            }
        }

        IsPregnant      = true;
        Baby            = GameObject.Instantiate(Own.Map.prefabCreature);
        Baby.Generation = Own.Generation > father.Generation ? Own.Generation : father.Generation;
        Baby.Generation++;
        Baby.Tr.SetParent(Own.Map.Transform);
        Baby.Tr.position = new Vector3(0, -200, 0);
        babyParams.SetOwn(Baby);
        Baby.Init(babyParams);
        Baby.IsAlive = false;
        //Baby.Rb.useGravity = false;
    }