Пример #1
0
    public void Decision()
    {
        if (ai.currentState != Case.AVAILABLE)
        {
            return;
        }

        cases = ai.caseDatas.OrderByDescending(x => (int)x.priority).ToList();

        for (var i = 0; i < cases.Count; i++)
        {
            if (cases[i].value > cases[i].criticalTreshold)
            {
                ai.HandleSpeed(SpeedPhase.SPRINT);
                MakeDecision(i);
                return;
            }
        }

        for (var i = 0; i < cases.Count; i++)
        {
            if (cases[i].value > cases[i].valueTreshold)
            {
                ai.HandleSpeed(SpeedPhase.RUN);
                MakeDecision(i);
                return;
            }
        }

        cases.Clear();
        ai.HandleSpeed(SpeedPhase.WALK);
        ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.WANDER));
    }
Пример #2
0
    private AnimalAI FindPartner()
    {
        Transform partnerTransform = ai.FindClosestThing(transform.position, targetMask, vision);

        if (partnerTransform == null || partnerTransform.gameObject == null)
        {
            return(null);
        }

        if (AnimalManager.Instance.animals.ContainsKey(partnerTransform.gameObject.GetInstanceID()))
        {
            AnimalAI partner  = AnimalManager.Instance.animals[partnerTransform.gameObject.GetInstanceID()];
            Identity identity = partner.Identity;
            if (identity.Sex != sex && identity.canReproduce && partner.currentState != Case.HUNGER && partner.currentState != Case.THIRST)
            {
                partner.OnCaseChanged(new CaseChangedEventArgs(new ReproductionCaseData(ai), Case.REPRODUCTION));
                return(partner);
            }
            else
            {
                return(null);
            }
        }

        return(null);
    }
Пример #3
0
 private void OnCaseChanged(object sender, CaseChangedEventArgs e)
 {
     if (e.state == Case.DEATH)
     {
         ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.RESET));
         Death();
     }
 }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (!canReproduce)
        {
            return;
        }

        reproductionUrge += Time.deltaTime;
        if (isRunning && target != null)
        {
            if (!isVFXUsed)
            {
                isVFXUsed = true;
                vfx       = VFXManager.Instance.GetStateVFX(transform.position, ai, VFXType.LOVE);
            }
            _animationManager.SetState(AnimationType.Walk);
            ai.Move(target.transform.position);
            if (Vector3.Distance(target.transform.position, transform.position) < targetRange)
            {
                reproductionUrge = 0;
                isRunning        = false;
                alerted          = false;

                // ÖNEMLİ NOT : DİREK HAMİLELİĞE GEÇİLDİĞİNDEN HAMİLELİĞİ BİRAZDA IDLE SÜRESİ EKLENMELİ!
                if (sex == Sex.FEMALE)
                {
                    ai.OnCaseChanged(new CaseChangedEventArgs(new PregnancyCaseData(target.Identity.GeneticCode), Case.PREGNANCY));
                }
                else
                {
                    ai.OnCaseChanged(new CaseChangedEventArgs(new IdleCaseData(10f), Case.IDLE));
                }

                target    = null;
                isVFXUsed = false;
                VFXManager.Instance.Push(vfx, VFXType.LOVE);
            }
        }

        if (!alerted && reproductionUrge > reproductionTreshold)
        {
            alerted = true;
            ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.AVAILABLE));
        }
    }
Пример #5
0
 private void Update()
 {
     if (isRunning)
     {
         wander += Time.deltaTime;
         if (wanderTime < wander)
         {
             wander    = 0;
             isRunning = false;
             ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.AVAILABLE));
         }
     }
 }
Пример #6
0
    private void Update()
    {
        thirst += Time.deltaTime;

        if (isRunning)
        {
            if (!isVFXUsed)
            {
                isVFXUsed = true;
                vfx       = VFXManager.Instance.GetStateVFX(transform.position, ai, VFXType.THIRST);
            }

            if (target != null && Vector3.Distance(target.position, thisTransform.position) < targetRange)
            {
                thirst    = 0;
                isRunning = false;
                alerted   = false;
                target    = null;

                isVFXUsed = false;
                VFXManager.Instance.Push(vfx, VFXType.THIRST);

                ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.IDLE));
            }
        }

        if (!alerted && thirst > thirstTreshold)
        {
            alerted = true;
            ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.AVAILABLE));
        }

        if (thirst > deathTreshold)
        {
            // vfx = VFXManager.Instance.GetDeadVFX(transform.position, ai, VFXType.THIRSTDEAD);
            // VFXManager.Instance.WaitPush(vfx, VFXType.THIRSTDEAD);
            ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.DEATH));
        }
    }
Пример #7
0
 private void Update()
 {
     if (isRunning)
     {
         _animationManager.SetState(AnimationType.Idle);
         idle += Time.deltaTime;
         if (idle > tempTime)
         {
             idle      = 0;
             isRunning = false;
             ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.AVAILABLE));
         }
     }
 }
Пример #8
0
    private void Update()
    {
        hunger += Time.deltaTime;

        if (isRunning)
        {
            if (!isVFXUsed)
            {
                isVFXUsed = true;
                vfx       = VFXManager.Instance.GetStateVFX(transform.position, ai, VFXType.HUNGER);
            }

            if (target != null)
            {
                _animationManager.SetState(AnimationType.Walk);
                ai.Move(target.position);
                if (Vector3.Distance(target.position, transform.position) < targetRange)
                {
                    if (target.tag == "Chicken")
                    {
                        AnimalAI targetAi = target.GetComponent <AnimalAI>();
                        // vfx = VFXManager.Instance.GetDeadVFX(transform.position, targetAi, VFXType.EATDEAD);
                        // VFXManager.Instance.WaitPush(vfx, VFXType.EATDEAD);
                        target.GetComponent <AnimalAI>().OnCaseChanged(new CaseChangedEventArgs(null, Case.DEATH));
                    }

                    hunger    = 0;
                    isRunning = false;
                    alerted   = false;
                    target    = null;

                    isVFXUsed = false;
                    VFXManager.Instance.Push(vfx, VFXType.HUNGER);

                    ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.IDLE));
                }
            }
            else
            {
                isRunning = false;
                ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.IDLE));
            }
        }

        if (!alerted && hunger > hungerTreshold)
        {
            alerted = true;
            ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.AVAILABLE));
        }

        if (hunger > deathTreshold)
        {
            // vfx = VFXManager.Instance.GetDeadVFX(transform.position, ai, VFXType.HUNGERDEAD);
            // VFXManager.Instance.WaitPush(vfx, VFXType.HUNGERDEAD);
            ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.DEATH));
        }
    }
Пример #9
0
 private void Update()
 {
     if (!flee)
     {
         searchTime += Time.deltaTime;
         if (searchTime >= timeBetweenSearches)
         {
             searchTime = 0;
             target     = Search();
             if (target != null)
             {
                 flee            = true;
                 ai.currentState = Case.FLEE;
                 ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.FLEE));
             }
         }
     }
     else
     {
         if (target != null)
         {
             float distance = Vector3.Distance(transform.position, target.position);
             if (distance < enemyDistanceRun)
             {
                 RunAway();
             }
             else
             {
                 Stop();
             }
         }
         else
         {
             Stop();
         }
     }
 }
Пример #10
0
    private IEnumerator Growth()
    {
        ai.Identity.canReproduce = false;
        while (phase > 0)
        {
            growth += Time.deltaTime;
            if (growth > growthTime)
            {
                growth = 0;
                GrowUp();
                phase--;
            }
            yield return(new WaitForFixedUpdate());
        }

        ai.Identity.canReproduce = true;
        this.enabled             = false;
        ai.OnCaseChanged(new CaseChangedEventArgs(null, Case.IDENTITY_UPDATE));
    }