Exemple #1
0
    protected override void OnTriggerEnter(Collider other)
    {
        BaseBall otherBall = other.GetComponentInParent <BaseBall>();

        if (otherBall.useHealth && otherBall.infected)
        {
            base.OnTriggerEnter(other);
            return;
        }

        if (otherBall.isMedic)
        {
            return;
        }

        if (otherBall.infected || otherBall.isScaling)
        {
            float healChance = m_cachedVirusLevel / (m_cachedVirusLevel + otherBall.m_cachedVirusLevel);

            if (Random.value < healChance)
            {
                otherBall.SetHealed();
            }
            else
            {
                Debug.Log("KILL");
                OnDeath();
            }
        }
    }
    protected virtual void OnTriggerStay(Collider other)
    {
        BaseBall otherBall = other.GetComponentInParent <BaseBall>();

        if (otherBall == null || !otherBall.useHealth)
        {
            return;
        }



        if (infected)
        {
            if (!otherBall.objectAffectingBall && !otherBall.infected)
            {
                otherBall.objectAffectingBall = gameObject;
            }

            float infectChance = m_cachedVirusLevel / (m_cachedVirusLevel + otherBall.m_cachedVirusLevel);
            float dmg          = infectChance;


            if (!otherBall.infected)
            {
                otherBall.ChangeHealth(-dmg, gameObject);
                //otherBall.currentHealth -= dmg;

                if (otherBall.currentHealth < 0)
                {
                    //Debug.Log("Current Health "+currentHealth);
                    otherBall.SetInfected();
                }
            }
            else
            {
                if (otherBall.currentHealth > -otherBall.startHealth * 0.5f)
                {
                    otherBall.ChangeHealth(-dmg, gameObject);
                    //otherBall.currentHealth -= dmg;
                }
            }
        }
        else if (isMedic)
        {
            if (otherBall.isSuperinfected)
            {
                return;
            }

            if (!otherBall.objectAffectingBall && otherBall.infected)
            {
                otherBall.objectAffectingBall = gameObject;
            }

            float infectChance = m_cachedVirusLevel / (m_cachedVirusLevel + otherBall.m_cachedVirusLevel);
            float heal         = 0.5f;

            if (otherBall.infected)
            {
                otherBall.ChangeHealth(heal, gameObject);
                currentHealth -= heal * 2f; //Damage medics when healing other balls
                //otherBall.currentHealth += heal;

                if (otherBall.currentHealth > otherBall.startHealth * 0.5f)
                {
                    otherBall.SetHealed();
                    //Debug.Log("Current Health Healed "+otherBall.currentHealth);
                }
            }
            else
            {
                if (otherBall.currentHealth < otherBall.startHealth)
                {
                    otherBall.ChangeHealth(heal, gameObject);
                    //Debug.Log("Healing OtherBall");
                    //otherBall.currentHealth += heal;
                }
            }

            if (currentHealth < 0)
            {
                OnDeath();
            }
        }

        if (objectAffectingBall && otherBall.gameObject == objectAffectingBall)
        {
            resetObjectTimer = 1;
        }
    }