Esempio n. 1
0
        IEnumerator SpawnTry(RabbitAI mother, RabbitAI father)
        {
            LayerMask         mask        = LayerMask.GetMask(new string[] { "Herbivore", "Carnivore", "Food" });
            Vector3           randomPoint = mother.transform.position + Random.insideUnitSphere.normalized * Random.Range(1.3f, 2.5f);
            NavMeshHit        hit;
            BaseAIPersonality fatherPersonality = father.Personality; // Storing father personality in case father dies;
            int tries = 0;

            while (tries < 500)
            {
                if (!mother)
                {
                    yield break; // mother died before giving birth
                }
                randomPoint = mother.transform.position + Random.insideUnitSphere.normalized * Random.Range(1.3f, 2.5f);
                if (NavMesh.SamplePosition(randomPoint, out hit, 1f, NavMesh.AllAreas))
                {
                    if (Physics.OverlapSphereNonAlloc(hit.position, .3f, null, mask) <= 0)
                    {
                        GameObject child = Instantiate(m_RabbitChildPrefab, mother.transform.parent);
                        child.transform.position = hit.position;
                        child.GetComponent <RabbitAI>().SetParents(mother.Personality, fatherPersonality);
                        yield break;
                    }
                }
                tries++;
                yield return(new WaitForSeconds(0.1f));
            }
        }
Esempio n. 2
0
 public bool Seduce(RabbitAI mate)
 {
     if (!m_DesiredMate || (m_DesiredMate.Apperance <= mate.Apperance && !m_DesiredMate.IsInterestedIn(this)))
     {
         m_DesiredMate = mate;
     }
     return(m_DesiredMate == mate);
 }
Esempio n. 3
0
 public void MakeBaby(RabbitAI with)
 {
     if (m_MatingState == RabbitMatingState.FemaleLooking)
     {
         m_MatingState = RabbitMatingState.FemaleSatisfied;
     }
     if (m_MatingState == RabbitMatingState.MaleLooking)
     {
         m_MatingState = RabbitMatingState.MaleSatisfied;
     }
     m_TimeLastMating = Time.time;
     if (m_MatingState == RabbitMatingState.FemaleSatisfied && with.IsMale)
     {
         AIManager.Instance.SpawnChild(this, with);
     }
 }
Esempio n. 4
0
 public bool IsInterestedIn(RabbitAI mate)
 {
     return(mate == m_DesiredMate);
 }
Esempio n. 5
0
        protected override void Mate()
        {
            if (EvaluateNeeds())
            {
                var exists = m_ActionsInterests.FindIndex(x => (BaseAIOrder.BaseActions)x.Action == BaseAIOrder.BaseActions.Mate);
                if (exists < 0)
                {
                    if (IsMale)
                    {
                        m_MatingState = RabbitMatingState.MaleLooking;
                    }
                    else
                    {
                        m_MatingState = RabbitMatingState.FemaleLooking;
                    }
                    m_ActionsInterests.Add(m_ActionCurrent);
                }
                m_DesiredMate   = null;
                m_CurrentTarget = null;
                m_ActionCurrent = null;
                return;
            }
            if (IsSatisfied)
            {
                m_DesiredMate   = null;
                m_CurrentTarget = null;
                m_ActionCurrent = null;
                return;
            }
            if (m_DesiredMate)
            {
                if (!m_DesiredMate.IsSatisfied)
                {
                    var dist = Vector3.Distance(transform.position, m_DesiredMate.transform.position);
                    if (dist < m_Personality.NeedDetection / 2f)
                    {
                        if (m_DesiredMate.Seduce(this))
                        {
                            if (dist < .5f)
                            {
                                m_DesiredMate.MakeBaby(this);
                                MakeBaby(m_DesiredMate);
                                m_DesiredMate   = null;
                                m_CurrentTarget = null;
                                m_ActionCurrent = null;
                                return;
                            }
                        }
                        else
                        {
                            m_DesiredMate   = null;
                            m_CurrentTarget = null;
                            return;
                        }
                    }
                    else
                    {
                        if (m_CurrentTarget == null)
                        {
                            SetNavmeshTarget(m_DesiredMate.transform);
                        }
                    }
                }
                else
                {
                    m_DesiredMate   = null;
                    m_CurrentTarget = null;
                }
            }
            else if (m_CurrentTarget == null)
            {
                int amount       = Physics.OverlapSphereNonAlloc(transform.position, m_Personality.NeedDetection, m_NonAllocResults, 1 << gameObject.layer);
                var DesiredState = m_MatingState == RabbitMatingState.MaleLooking ? RabbitMatingState.FemaleLooking : RabbitMatingState.MaleLooking;

                int      index         = -1;
                float    max           = 0;
                RabbitAI mateCandidate = null;
                for (int i = 0; i < amount; i++)
                {
                    mateCandidate = m_NonAllocResults[i].GetComponent <RabbitAI>();
                    if (!mateCandidate || mateCandidate.MatingState != DesiredState)
                    {
                        continue;
                    }
                    var matevalue = mateCandidate.Apperance + (mateCandidate.IsInterestedIn(this) ? .4f : 0f) + (mateCandidate.IsAvailable ? .2f : 0f);
                    if (matevalue >= max)
                    {
                        max   = matevalue;
                        index = i;
                    }
                }
                if (index < 0)
                {
                    WanderRandomDirection(m_Personality.NeedDetection);
                    return;
                }
                m_DesiredMate = mateCandidate;
                SetNavmeshTarget(m_NonAllocResults[index].transform);
            }
        }
Esempio n. 6
0
 public void SpawnChild(RabbitAI mother, RabbitAI father)
 {
     StartCoroutine(SpawnTry(mother, father));
 }