Example #1
0
    private static IEnumerator Quake(Gun gun, BulletScript script)
    {
        script.coroutines_running++;
        while (!script.has_collided && !script.Target)//Wait for collision and check target validity
        {
            yield return(new WaitForEndOfFrame());
        }
        string layer = "";

        if (gun.client_user)
        {
            layer = LayerMask.LayerToName(
                gun.client_user.gameObject.layer);
        }
        else
        {
            layer = LayerMask.LayerToName(
                gun.GetComponentInParent <HealthDefence>()
                .gameObject.layer);
        }
        Collider[] target_colliders = Physics.OverlapSphere(script.gameObject.transform.position, 7,
                                                            LayerMask.GetMask(layer), QueryTriggerInteraction.Collide);
        foreach (Collider col in target_colliders)
        {
            HealthDefence HP = col.GetComponent <HealthDefence>();
            if (HP && script.Target.netId != HP.netId)
            {
                int d = rand.Next(script.lower_bound_damage, script.upper_bound_damage) / 2;
                HP.RpcDisplayHPChange(Color.red, d);
                HP.HP -= d;
            }
        }
        script.coroutines_running--;
    }
Example #2
0
    IEnumerator Damage(Collision hit, Collider col = null)
    {
        if (col == null)
        {
            Target = hit.gameObject.GetComponent <HealthDefence>();
        }
        else
        {
            Target = col.gameObject.GetComponent <HealthDefence>();
        }

        /*If the target still exist and doesn't even have this script,
         * Don't bother executing the rest of the code.As for the exception,it is there
         * in the event the object "dies" midway execution,presumably from another bullet.*/
        /*If a spawn point is hit by enemy,just run on client.*/

        /*If an enemy is hit(for enemy guns have no client user set),test whether the code is
         * running on the same client as the one who shot the bullet(for number UI to show up)
         * If a player is hit,run the code only on whoever got hit*/
        if (Target != null)
        {
            if (can_pierce)
            {
                if (hit != null)
                {
                    StartCoroutine(Pierce(hit));
                }
                else
                {
                    StartCoroutine(Pierce(col));
                }
            }
            legit_target = true;
            has_collided = true;
            //Wait until all coroutines operating on the bullet finish
            while (coroutines_running > 0)
            {
                yield return(new WaitForFixedUpdate());
            }
            int  damage = rand.Next(lower_bound_damage, upper_bound_damage);
            int  d      = (damage - Target.defence);
            bool crit   = false;
            if ((crit_chance - Target.crit_resistance) >= rand.NextDouble() + .001)//bullets with a crit chance of 0 shouldn't be able to land a crit
            {
                crit = true;
                d   *= 3;
            }
            Target.StartCoroutine(Target.DetermineChill(chill_strength));
            Target.StartCoroutine(Target.DetermineBurn(burn_strength, d));
            if (crit)
            {
                Target.RpcDisplayHPChange(new Color(114, 0, 198), d);//Violet
            }
            else
            {
                Target.RpcDisplayHPChange(Color.red, d);
            }


            if (Target.has_exp)
            {
                gun_reference.experience += d * Target.exp_rate;
            }
            if (Target.Controller)
            {
                Target.GetComponent <Rigidbody>().velocity = Vector3.zero;
            }
            AIController AI = Target.Controller as AIController;
            if (AI != null)
            {
                AI.UpdateAggro(d, gun_reference.client_user.netId);
            }
            Target.HP -= d;
            if (!can_pierce)
            {
                NetworkServer.Destroy(gameObject);
            }
        }
        /*If target is null or hit enemy detetion*/
        else if ((col && !col.isTrigger) || (hit != null && !hit.gameObject.GetComponent <Collider>().isTrigger))
        {
            /* Before destruction,Stop all coroutines(the gun_abilities operating on this instance)
             * to prevent exceptions from those coroutines*/

            StopAllCoroutines();
            NetworkServer.Destroy(gameObject);
        }
    }
Example #3
0
    IEnumerator Damage(Collision hit, Collider col = null)
    {
        if (!damaging)
        {
            damaging = true;
            if (col == null)
            {
                Target = hit.gameObject.GetComponent <HealthDefence>();
            }
            else
            {
                Target = col.gameObject.GetComponent <HealthDefence>();
            }

            /*If the target still exist and doesn't even have this script,
             * Don't bother executing the rest of the code.As for the exception,it is there
             * in the event the object "dies" midway execution,presumably from another bullet.*/
            /*If a spawn point is hit by enemy,just run on client.*/

            /*If an enemy is hit(for enemy guns have no client user set),test whether the code is
             * running on the same client as the one who shot the bullet(for number UI to show up)
             * If a player is hit,run the code only on whoever got hit*/
            if (Target != null)
            {
                legit_target = true;
                has_collided = true;
                //Wait until all coroutines operating on the bullet finish
                while (coroutines_running > 0)
                {
                    yield return(new WaitForFixedUpdate());
                }
                if (can_pierce)
                {
                    if (hit != null)
                    {
                        StartCoroutine(Pierce(hit));
                    }
                    else
                    {
                        StartCoroutine(Pierce(col));
                    }
                }
                ValueGroup <bool, int> v = GetDamage(Target);
                bool crit   = v.index;
                int  damage = v.value;
                if (damage > 0)
                {
                    double[] powers = { burn_strength, sunder_strength, chill_strength, mezmerize_strength };
                    Target.DetermineStatusEffects(powers, damage);
                    if (crit)
                    {
                        Target.RpcDisplayHPChange(new Color(114, 0, 198), damage);//Violet
                    }
                    else
                    {
                        Target.RpcDisplayHPChange(Color.red, damage);
                    }
                    ApplyExperience(damage, Target as UnitHealthDefence);
                    ApplyAggro(damage, Target as UnitHealthDefence);
                    ApplySpawnCounterDamage(damage, Target as SpawnPointHealthDefence);
                    Target.HP -= damage;
                }
            }
            if (!can_pierce && !can_bounce)
            {
                GetComponent <Collider>().enabled = false;
                ClearHazardCoords();
                NetworkServer.Destroy(gameObject);
            }
            damaging = false;
        }
    }