Example #1
0
        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.isTrigger)
            {
                return;
            }
            if (MG != null)
            {
                //Check for the parent and all its transforms
                if (MG.CH != null)
                {
                    if (MG.CH.transform == collision.transform)
                    {
                        return;
                    }
                    foreach (Transform t in MG.CH.transform)
                    {
                        if (collision.transform == t)
                        {
                            return;
                        }
                    }
                }
            }

            Character.Health h;
            h = collision.GetComponent <Character.Health>();
            if (h != null)
            {
                //Direction should always be away from the weapon
                bool f = false;
                if (transform.lossyScale.x > 0)
                {
                    f = true;
                }
                Vector2 dirup = Menu.UsefulStuff.FromRotationToVector(transform.rotation.eulerAngles.z, f); //only for up vector?

                Vector2 direction = new Vector2(transform.position.x - collision.transform.position.x, dirup.y * 8);
                h.DealDamage(damage, collision.transform.position, -direction, punch);

                if (knockbackowner)
                {
                    if (MG != null && MG.CH != null)
                    {
                        Rigidbody2D pRB = MG.CH.GetComponent <Rigidbody2D>();
                        if (pRB != null)
                        {
                            pRB.AddForce(new Vector2((punch * -1) / 2, 0), ForceMode2D.Impulse);
                        }
                    }
                }
                if (FX != null)
                {
                    FX.DoFX(direction, transform.position, 50, 5, new int[] { 0, 1 }, 2);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Deal damage to the component.
        /// 1-10 minor to no damage.
        /// 10-30 hits hard (think blunt).
        /// 30-60 pierce (bullets and piercing).
        /// >60 gibbing damage (explosions).
        /// </summary>
        /// <param name="dmg">Damage</param>
        /// <param name="location">Where FX to spawn</param>
        /// <param name="direction">Where FX to go</param>
        public bool DealDamage(int dmg, Vector2 location, Vector2 direction, float punch = 0)
        {
            //Really needs a cleanup.
            bool pierce = false;

            dmg -= Random.Range(armor / 2, armor);
            if (Global)
            {
                Debug.Log("Dealing damage to global?! Should not happen! " + gameObject.name); return(false);
            }

            if (dmg < 10)                                // Minor hit, no bleeding, reflect FX (occasional), HP does not fall below 60%. (regenerates full if not bleeding).
            {
                if (HPp > 60 && Random.Range(0, 5) == 0) // 1 in 4 chance
                {
                    pierce = true;
                }
                else
                {
                    dmg = 0;
                }
                if (FX != null && Random.Range(0, 1) == 0)
                {
                    FX.DoFX(direction, location, 50, 3, new int[] { 3, 4 }, Mathf.FloorToInt(1 * fxmult));
                }
            }
            else if (dmg < 30) //Major hit, might start bleeding. Hard to kill.
            {
                if (HPp < 40)
                {
                    if (Random.Range(0, 5) == 0)
                    {
                        dmg = dmg / 2; pierce = true; Bleed(location);
                    }
                    else
                    {
                        dmg = dmg / 5;
                    }
                }
                else if (Random.Range(0, 4) == 0) // 1 in 3 chance
                {
                    pierce = true;
                    Bleed(location);
                }
                else
                {
                    dmg = dmg / 3;
                }

                if (FX != null)
                {
                    FX.DoFX(direction, location, 30, 3, new int[] { 0, 1, 2, 3 }, Mathf.FloorToInt(1 * fxmult));
                }
            }
            else if (dmg < 50) //Mortal hit, will start bleeding to max. Wont die unless critical is hit.
            {
                pierce = true;
                if (HPp < 30)
                {
                    int ndmg = dmg / 2;
                    if (Critical)
                    {
                        if (Random.Range(0, 4) == 0) // 1 in 4 chance
                        {
                            ndmg   = dmg;
                            pierce = false;
                        }
                    }
                    else
                    {
                        if (Random.Range(0, 2) == 0) // 1 in 2 chance
                        {
                            ndmg   = dmg;
                            pierce = false;
                        }
                    }
                    dmg = ndmg;
                }
                Bleed(location);
                if (FX != null)
                {
                    FX.DoFX(direction, location, 70, 5, new int[] { 0, 1, 2 }, Mathf.FloorToInt(2 * fxmult));
                }
            }
            else // Brutal deadly hit, will bleed twice. Twice damage if all bleeding
            {
                pierce = true;
                Bleed(location);
                Bleed(location);
                if (BLEED.Count == maxbleed)
                {
                    dmg += dmg;
                }
                if (FX != null)
                {
                    FX.DoFX(direction, location, 50, 15, new int[] { 0, 1, 2 }, Mathf.FloorToInt(3 * fxmult));
                }
            }

            //Deal damage depending not on percent!
            //dmg = 100 - (int)(((float)(RealHP - dmg) / (float)RealHP) * 100);
            //if (dmg < 0) { dmg = 0; }
            CurrentHP -= dmg;
            CalculatePercent();
            if (punch != 0)
            {
                //float f = 1;
                //if (transform.lossyScale.x < 0) { f = -1; }
                if (RB != null)
                {
                    RB.AddForceAtPosition(direction.normalized * punch, location, ForceMode2D.Impulse);
                }
                if (pRB != null)
                {
                    pRB.AddForceAtPosition(direction.normalized * punch, location, ForceMode2D.Impulse);
                }
            }

            //if (BLEED.Count >= maxbleed) { deathflag = true; }


            //if (HpChanged != null) { HpChanged(this); }
            return(pierce);
        }