Esempio n. 1
0
 protected void SpawnEffect(DamageDescriptor d, Vector3 origin)
 {
     if (ImpactFX != null && d.component == null)
     {
         MF_AutoPool.Spawn(ImpactFX, d.point, Quaternion.LookRotation(d.normal));
     }
 }
Esempio n. 2
0
    protected override DamageDescriptor FireRaycast(Vector3 pos, Vector3 dir, float range, LayerMask mask, float rayThickness = 3f)
    {
        DamageDescriptor d = base.FireRaycast(pos, dir, range, mask);

        if (Vector3.Distance(d.point, pos) > 3)
        {
            /*if(!d.Initialised())
             *  SpawnTrace(pos + (dir * range));
             * else
             * {
             *  SpawnTrace(d.point);
             * }*/
            SpawnTrace(d.point);
        }


        return(d);
    }
 public override void Affect(DamageDescriptor damage)
 {
     damage.DamageAmount = 0;
 }
Esempio n. 4
0
    //Useful methods
    protected virtual DamageDescriptor FireRaycast(Vector3 pos, Vector3 dir, float range, LayerMask mask, float rayThickness = 0.25f)
    {
        /*RaycastHit hit;
         * DamageDescriptor d = new DamageDescriptor();
         * if (Physics.Raycast(pos, dir, out hit, range, mask))
         * {
         *  if (damagableTags.Contains(hit.collider.tag))
         *  {
         *      //find a damagable component
         *      IDamagable hitComponenet = hit.collider.GetComponent<IDamagable>();
         *      if (hitComponenet != null)
         *      {
         *          Damage damageInstance = damage;
         *          damageInstance.pushForce = dir * damage.pushForce.magnitude;
         *          hitComponenet.TakeDamage(damageInstance);
         *          if (!d.Initialised())
         *          {
         *              d = new DamageDescriptor(hit, dir, hitComponenet, damageInstance);
         *              if (OnHit != null)
         *                  OnHit(d, pos);
         *
         *              return d;
         *          }
         *
         *      }
         *  }
         *  d = new DamageDescriptor(hit, dir, null, damage);
         *  if (OnHit != null)
         *      OnHit(d, pos);
         *
         *  return d;
         * }
         *
         * return new DamageDescriptor();*/

        DamageDescriptor d = new DamageDescriptor();


        float      r       = range;
        Vector3    ogPoint = new Vector3();
        RaycastHit h;

        if (Physics.Raycast(pos, dir, out h, r, mask))
        {
            r = h.distance;
        }

        ogPoint = h.point;

        RaycastHit[] hits = Physics.SphereCastAll(pos, rayThickness, dir, r, damagableMask);
        System.Array.Sort(hits, (x, y) => x.distance.CompareTo(y.distance));

        foreach (RaycastHit hit in hits)
        {
            if (damagableTags.Contains(hit.collider.tag))
            {
                //find a damagable component
                IDamagable hitComponenet = hit.collider.GetComponent <IDamagable>();
                if (hitComponenet != null)
                {
                    Damage damageInstance = damage;
                    damageInstance.pushForce = dir * damage.pushForce.magnitude;
                    hitComponenet.TakeDamage(damageInstance);
                    if (!d.Initialised())
                    {
                        d = new DamageDescriptor(hit, dir, hitComponenet, damage);
                        if (OnHit != null)
                        {
                            OnHit(d, pos);
                        }

                        return(d);
                    }
                }

                return(d);
            }
        }

        if (h.collider != null)
        {
            d = new DamageDescriptor(h, dir, null, damage);
            if (OnHit != null)
            {
                OnHit(d, pos);
            }
        }
        else
        {
            d.point = pos + dir;
        }

        return(d);
    }
Esempio n. 5
0
    protected override DamageDescriptor FireRaycast(Vector3 pos, Vector3 dir, float range, LayerMask mask, float rayThickness = 0.3f)
    {
        DamageDescriptor d = new DamageDescriptor();

        SpawnTrace();

        float      r = rangeDistance.y;
        RaycastHit h;

        if (Physics.Raycast(pos, dir, out h, r, mask))
        {
            r = h.distance;
        }

        RaycastHit[] hits        = Physics.SphereCastAll(pos, thickness, dir, r, mask);
        int          chosenIndex = -1;
        float        closest     = r;
        int          i           = 0;

        foreach (RaycastHit hit in hits)
        {
            if (hit.distance < closest)
            {
                chosenIndex = i;
            }
            ++i;
        }

        if (chosenIndex != -1)
        {
            RaycastHit hit = hits[chosenIndex];

            if (damagableTags.Contains(hit.collider.tag))
            {
                //find a damagable component
                IDamagable hitComponenet = hit.collider.GetComponent <IDamagable>();
                if (hitComponenet != null)
                {
                    Damage dmg = damage;
                    dmg.pushForce = dir * damage.pushForce.x + Vector3.up * damage.pushForce.y;
                    if (hit.distance > rangeDistance.x)
                    {
                        float x          = (hit.distance - rangeDistance.x) / (rangeDistance.y - rangeDistance.x);
                        float multiplier = 1 - x;
                        dmg.amount = Mathf.Max(damage.amount * multiplier, 0);
                    }

                    //Debug.Log("DAMAGE: " + hit.collider.name + " - " + dmg.amount);

                    hitComponenet.TakeDamage(dmg);
                    if (!d.Initialised())
                    {
                        d = new DamageDescriptor(hit, dir, hitComponenet, damage);
                        if (OnHit != null)
                        {
                            OnHit(d, pos);
                        }

                        return(d);
                    }
                }

                return(d);
            }
        }


        return(new DamageDescriptor());
    }
Esempio n. 6
0
 public override void Affect(DamageDescriptor damage)
 {
     damage.DamageAmount -= this.DamageReduction;
 }