public override bool EvaluateInterests() { if (m_TimeLastMating + 2f < Time.time) { if (m_ActionCurrent == null || (BaseAIOrder.BaseActions)m_ActionCurrent.Action != BaseAIOrder.BaseActions.Mate) { 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(new BaseAIOrder(BaseAIOrder.BaseActions.Mate, 1f)); } } } else { m_ActionsInterests.RemoveAll(x => (BaseAIOrder.BaseActions)x.Action == BaseAIOrder.BaseActions.Mate); } return(base.EvaluateInterests()); }
protected override void Awake() { base.Awake(); if (!m_Animator) { m_Animator.GetComponentInChildren <Animator>(); } m_MatingState = (RabbitMatingState)Random.Range(0, 5); }
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); } }
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); } }