Пример #1
0
 public void ProjectileHitCallback(IRangedWeaponProjectile p, IDamageable target, float damages)
 {
     if (OnHit != null)
     {
         OnHit(this, new OnHitArgs(target, damages));
     }
 }
Пример #2
0
 public void ProjectileOnKillCallback(IRangedWeaponProjectile p, IDamageable target, float damages)
 {
     if (OnKill != null)
     {
         OnKill(this, new OnKillArgs(target));
     }
 }
Пример #3
0
    private IEnumerator FiringBehavior()
    {
        float halfDeviation = projectileDeviation / 2.0f;

        IDamageable dmg     = null;
        Vector3     worldhp = Vector3.zero;

        if (aimGatherer == null)
        {
            Debug.LogError("No aim gatherer present for " + this.name);
        }
        else
        {
            worldhp = aimGatherer.GetAimHitpoint(ref dmg);
        }

        bool isAngleValid = Vector3.Dot(fireMuzzle.forward, (worldhp - fireMuzzle.position).normalized) >= 0.0f;

        for (int i = 0; i < projectilePerShot; i++)
        {
            if (!isAngleValid && dmg == null)
            {
                Debug.Log("Invalid shot, breaking ...");
                break;
            }

            IRangedWeaponProjectile p = Ammo.InstantiateProjectile(fireMuzzle);
            p.Initialize(this);
            p.IgnoreTag = weaponManager.gameObject.tag;

            Ammo.ApplyEffect(p);

            GameObject.Destroy((p as Behaviour).gameObject, projectileLifetime);

            if (!isAngleValid && !(dmg as Behaviour).gameObject.transform.IsChildOf(weaponManager.transform))
            {
                p.Hit(dmg);
                continue;
            }

            p.Direction = (worldhp - (p as Behaviour).transform.position).normalized;
            p.Direction = Quaternion.Euler(UnityEngine.Random.Range(-halfDeviation, halfDeviation),
                                           UnityEngine.Random.Range(-halfDeviation, halfDeviation),
                                           UnityEngine.Random.Range(-halfDeviation, halfDeviation)) * p.Direction;
        }

        yield return(new WaitForSeconds(animationTime));

        if (OnEndPrimary != null)
        {
            OnEndPrimary(this, new EventArgs());
        }

        state = RangedWeaponState.Idle;
    }
Пример #4
0
 public void ApplyEffect(IRangedWeaponProjectile projectile)
 {
     projectile.MinDamages += addedDamages.min;
     projectile.MaxDamages += addedDamages.max;
 }