Example #1
0
 public void CheckCollision(ITakeDamage _currentView, int damageValue)
 {
     if (_currentView.GetName() == "EnemyView")
     {
         GameApplication.Instance.GetService <IEnemyService>().SetDamagingPlayerID(GetID());
         _currentView.TakeDamage(damageValue);
     }
     else if (_currentView.GetName() == "PlayerView" && isFriendlyFire)
     {
         _currentView.TakeDamage(damageValue);
     }
 }
Example #2
0
        private void DoingDamageLogic()
        {
            if (_targetEnemy == null)
            {
                return;
            }

            _attackTimer -= GameTime.DeltaTime;
            if (_attackTimer > 0)
            {
                return;                   //keep waiting...
            }
            //ready to attack...
            _attackTimer = AttackSpeed;

            //deal ranged or melee damage if close enough & clear to attack...
            if (DistanceSquaredFromNearestEnemyUnit < Reach * Reach /*&& GetLineOfSightClear(TargetEnemy)*/)
            {
                //SetUpWeapon(true, UnitWeapon.WeaponClasses.Ranged);
                _targetEnemy.TakeDamage(Damage);
                WeaponMgr.Lightning.FireBeamAmmo(transform, Vector3.up * HeightFromPivotToTop, _targetEnemy.transform,
                                                 _targetEnemy.GetCenterOfMassOffset());
                //CurrentWeapon.GetComponent<WeaponMeleeMotion>()?.StartStabMotion();

                //DEBUG
                if (LINE_DEBUG_ENABLED)
                {
                    Debug.DrawLine(transform.position + Vector3.up * HeightFromPivotToTop,
                                   _targetEnemy.transform.position + _targetEnemy.GetCenterOfMassOffset(), Color.red, 0.02f);
                }
            }
        }
Example #3
0
    public void Shoot()
    {
        ShotEffectPlay();

        for (int i = 0; i < gunPattern.BulletsCount; i++)
        {
            Vector3 shotInacurracyVector = new Vector3(Random.Range(-gunPattern.ShotInacurracy, gunPattern.ShotInacurracy),
                                                       Random.Range(-gunPattern.ShotInacurracy, gunPattern.ShotInacurracy),
                                                       Random.Range(-gunPattern.ShotInacurracy, gunPattern.ShotInacurracy));

            Vector3 direction = raycastFrom.forward * gunPattern.Range + shotInacurracyVector;

            if (Physics.Raycast(raycastFrom.position, direction, out RaycastHit hitInfo, gunPattern.Range))
            {
                if (hitInfo.rigidbody != null)
                {
                    hitInfo.rigidbody.AddForce(-hitInfo.normal * gunPattern.ImpactForce / gunPattern.BulletsCount);
                }

                SpawnImpactEffect(hitInfo);

                ITakeDamage hittedObject = hitInfo.transform.GetComponent <ITakeDamage> ();
                if (hittedObject != null && !hitInfo.transform.CompareTag("Player"))
                {
                    hittedObject.TakeDamage(gunPattern.Damage / gunPattern.BulletsCount);
                }
            }
        }
    }
Example #4
0
    protected virtual void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage)
    {
        //Debug.Log("TAKE DAMAGE");

        takeDamage.TakeDamage(damage, gameObject);
        DestroyBall();
    }
    private void DealDamage()
    {
        ITakeDamage _takeDamage = collision.GetComponent <ITakeDamage>();

        // I don't think there was any point casting.
        _takeDamage.TakeDamage(Damage);
    }
Example #6
0
    protected virtual void OnTriggerStay2D(Collider2D collision)
    {
        //if (collision.gameObject.tag != "Player")
        //{
        //    Destroy(this.gameObject);
        //}
        if (collision.gameObject.layer != LayerMask.NameToLayer("TriggerArea") && collision.gameObject.name != fireingCharacterName && collision.name != "ProjectilePrefab(Clone)")
        {
            if (active)
            {
                Debug.Log(name + " OnTriggerStay collided with " + collision.name);

                //GameObject newImpactFX = Instantiate(impactParticlesPrefab, this.transform);
                //newImpactFX.transform.SetParent(null);
                //Destroy(newImpactFX, 1f);
                ObjectPoolManager.Instance.SpawnFromPool("Sparkles", transform.position);

                ITakeDamage takeDamageInterface = collision.gameObject.GetComponent <ITakeDamage>();
                if (takeDamageInterface != null)
                {
                    takeDamageInterface.TakeDamage(projectileDamage + weaponDamage);
                }
                //Destroy(this.gameObject);
                ObjectPoolManager.Instance.ReturnObjectHome(this.gameObject);
            }
        }
    }
Example #7
0
    void OnCollisionEnter(Collision other)
    {
        if (other.collider.CompareTag("Projectile") == false && other.collider.CompareTag("Player") == false)
        {
            GameObject Splash;
            Splash = Instantiate(splashEffect);
            Splash.transform.position = this.transform.position;
            Destroy(this.gameObject);
            Destroy(Splash, 0.05f);



            ITakeDamage damagable = other.collider.GetComponent <ITakeDamage>();
            if (damagable != null)
            {
                damagable.TakeDamage(damage);
                GameObject Effect;
                //Effect = Instantiate(effect, other.transform.position, Quaternion.identity,
                //  other.transform);

                // Effect.transform.position = other.transform.position;
                //Effect.transform.parent = other.transform;
            }
        }
    }
Example #8
0
    void OnTriggerEnter(Collider other)
    {
        if (targetList == (targetList | (1 << other.gameObject.layer)))
        {
            soundPlayer.StopSoundEvent("Fireball");
            ITakeDamage hittedObject = other.GetComponent <ITakeDamage> ();
            if (hittedObject != null)
            {
                hittedObject.TakeDamage(damage);
            }

            foreach (RaycastHit hit in Physics.SphereCastAll(transform.position, 10f, transform.forward))
            {
                Rigidbody rb = hit.collider.gameObject.GetComponent <Rigidbody> ();
                if (rb != null)
                {
                    rb.AddExplosionForce(explosionForce, transform.position, 5f);
                }
            }

            GameObject explosion = Instantiate(explosionVFX, transform.position, transform.rotation);
            explosion.GetComponent <VisualEffect> ().Play();

            StartCoroutine(LateExplosionSound(explosion.GetComponent <SoundPlayer> ()));
            Destroy(explosion, 3f);
            Destroy(gameObject, .1f);
        }
    }
Example #9
0
 public void AttackAble(bool isbool)
 {
     if (isbool)
     { // player attack
         _take.TakeDamage(_enemy.statusbug, _player.statusplayer);
         if (_enemy.statusbug.hp <= 0)
         {
             ExpTalet();
             NewEnemy();
         }
     }
     else
     { //Bug attack
         _take.TakeDamage(_player.statusplayer, _enemy.statusbug);
     }
 }
Example #10
0
    protected virtual void OnCollisionEnter2D(Collision2D collision)
    {
        ITakeDamage takeDamage = collision.gameObject.GetComponent <ITakeDamage>();

        if (takeDamage != null)
        {
            takeDamage.TakeDamage(damage);
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        ITakeDamage damagable = collision.gameObject.GetComponent <ITakeDamage>();

        if (damagable != null)
        {
            damagable.TakeDamage(damageAmount);
        }
    }
Example #12
0
    private void OnTriggerEnter(Collider other)
    {
        ITakeDamage damagable = other.GetComponent <ITakeDamage>();

        if (damagable != null)
        {
            damagable.TakeDamage(1);
        }
    }
Example #13
0
    protected virtual void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage)
    {
        //Debug.Log("TAKE DAMAGE");

        takeDamage.TakeDamage(damage, gameObject);
        DestroyZombie();

        //Debug.Log(other.gameObject.name + "Poop ");
    }
Example #14
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ITakeDamage damagableObj = collision.GetComponent <ITakeDamage>();

        if (damagableObj != null)
        {
            damagableObj.TakeDamage(_damage);
            hit?.Invoke();
        }
    }
Example #15
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ITakeDamage takeDamage = collision.gameObject.GetComponent <ITakeDamage>();

        if (takeDamage != null)
        {
            takeDamage.TakeDamage(explosionDamage);
            Destroy(gameObject);
        }
    }
Example #16
0
    public void OnTriggerEnter(Collider other)
    {
        ITakeDamage damagable = other.GetComponent <ITakeDamage>();

        if (damagable != null)
        {
            damagable.TakeDamage(damage);
        }
        Destroy(gameObject);
    }
Example #17
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ITakeDamage damagable = collision.GetComponent <ITakeDamage>();

        if (damagable != null)
        {
            damagable.TakeDamage(attackPower);
            pool.ReturnToPool(this.gameObject);
        }
    }
Example #18
0
 protected override void OnCollideOwner(Collider2D other, ITakeDamage takeDamage)
 {
     if (IsDeflected)
     {
         //Destroy(Owner);
         //Owner.transform.position = new Vector3(44,5,5);
         takeDamage.TakeDamage(Damage, gameObject);
         //GameManager.Instance.AddPoints(1);
         DestroyProjectile();
     }
 }
Example #19
0
    public void OnCollisionEnter(Collision collision)
    {
        ITakeDamage damageable = collision.gameObject.GetComponentInParent <ITakeDamage>();

        if (damageable != null)
        {
            damageable.TakeDamage(damage, this.gameObject);
        }

        Destroy(this.gameObject);
    }
Example #20
0
 private void OnTriggerEnter2D(Collider2D target)
 {
     if (target.tag == "Bullet")
     {
         meteorDamage.TakeDamage(meteorDamage.damage);
         target.GetComponentInParent <IPoolable>().SetOff();
     }
     else if (target.tag == "Player")
     {
         playerDamage.TakeDamage(playerDamage.damage);
     }
 }
Example #21
0
    protected override void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage)
    {
        takeDamage.TakeDamage(Damage, gameObject);

        var controller = other.gameObject.GetComponent<CharacterController2D>();
        if (controller != null)
        {
            HandleKnockback(controller);
        }

        DestroyProjectile();
    }
    private void OnTriggerEnter2D(Collider2D collider)
    {
        if (((1 << collider.gameObject.layer) & targetLayerMask) == 0)
        {
            return;
        }

        ITakeDamage obj = collider.GetComponent <ITakeDamage>();

        if (obj != null)
        {
            obj.TakeDamage();
        }
    }
    public virtual void AttackTarget(Collider col)
    {
        float randomX = UnityEngine.Random.Range(0f, 0.5f);
        float randomY = UnityEngine.Random.Range(0f, 0.5f);

        if (hittingEffect != null)
        {
            Instantiate(hittingEffect, col.transform.position + new Vector3(randomX, 0f, randomY),
                        Quaternion.Euler(90f, 0f, 0f),
                        col.transform);
        }
        ITakeDamage target = col.GetComponent <ITakeDamage>();

        target?.TakeDamage(Damage);
        Destroy(gameObject);
    }
 public void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         GameObject Splash;
         Splash = Instantiate(splashEffect);
         Splash.transform.position = this.transform.position;
         ITakeDamage damagable = other.GetComponent <ITakeDamage>();
         if (damagable != null)
         {
             damagable.TakeDamage(damage);
         }
         Destroy(this.gameObject);
         Destroy(Splash, 0.05f);
     }
 }
Example #25
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("Hit");

        if (collision.CompareTag(enemyTag))
        {
            ITakeDamage _takeDamage = collision.GetComponent <ITakeDamage>();

            if (_takeDamage is ITakeDamage)
            {
                _takeDamage.TakeDamage(Damage);
            }

            Die();
        }
    }
Example #26
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.name.Contains("Bottom"))
        {
            //to code health reduce
            Destroy(this.gameObject);
        }

        if (damageable != null && other.gameObject.name.Contains("Bullet"))
        {
            //to code health reduce
            Destroy(other.gameObject);
            damageable.TakeDamage(1);
            //Debug.Log("Score: " + GameData.Score);
        }
    }
Example #27
0
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    ITakeDamage damageable = hit.collider.GetComponent <ITakeDamage>();

                    if (damageable != null)
                    {
                        damageable.TakeDamage(1);
                    }
                }
            }
        }
Example #28
0
File: Gun.cs Project: vmkomp/testi
    void Shoot()
    {
        RaycastHit hit;

        shootParticle.Play();

        if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, range))
        {
            ITakeDamage damagable = hit.collider.GetComponent <ITakeDamage>();
            if (damagable != null)
            {
                Rigidbody damagablerb = hit.collider.GetComponent <Rigidbody>();
                Vector3   newVector   = hit.point - playerCamera.transform.position;
                damagablerb.AddForce(newVector * 100);
                damagable.TakeDamage(damage);
            }
        }
    }
Example #29
0
    private void OnTriggerEnter(Collider info)
    {
        ITakeDamage damagable = info.GetComponent <ITakeDamage>(); // Damageable is anything with the ITakeDamage interface

        // If hammer is moving fast enough and it hit a mole
        if (speedPerSec > speedWhenRegistered && damagable != null)
        {
            // Play hit particle system
            hitParticle = info.GetComponentInChildren <ParticleSystem>();
            hitParticle.Play();

            // Add damage to the mole that was hit
            damagable.TakeDamage(1.0f);
        }

        if (speedPerSec > speedWhenRegistered && damagable == null)
        {
            // Remove time from timer on miss
            //timerScript.timer -= removeTimeOnMiss;
        }
    }
Example #30
0
 public void DealDamage()
 {
     Collider2D[] hit = Physics2D.OverlapCircleAll(attackPoint.position, swordRange, LayerMask.GetMask("Enemies"));
     foreach (Collider2D e in hit)
     {
         if (hit != null)
         {
             IEnemyCombat enemy = e.GetComponent <IEnemyCombat>();
             if (attacking && !enemy.blocking)
             {
                 ITakeDamage damaging = e.GetComponent <ITakeDamage>();
                 damaging.TakeDamage(attackDamage, gameObject.GetComponent <Character_Controller>().flipSide, push);
             }
             else if (attacking && enemy.blocking)
             {
                 gameObject.GetComponent <Rigidbody2D>().AddForce(Vector2.left * 2.5f * push, ForceMode2D.Impulse);
                 Instantiate(blockFlash, attackPoint.position, Quaternion.identity);
             }
         }
     }
 }
Example #31
0
    /*
     * @param other, the other GameObject
     * @param takeDamage, the amount of damage that the other GameObject receives
     * On collision, the other GameObject takes damage
     */
    protected override void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage)
    {
        // Handles what happens when the enemy is frozen
        if (other.GetComponent <EnemyAI>() != null && CanFreeze == true)
        {
            Enemy.Status            = EnemyAI.EnemyStatus.Frozen;
            Enemy.MovementSpeed     = 0f;
            Enemy.SpriteColor.color = Color.cyan;
            Enemy.StartCoroutine(Enemy.CountdownDebuff());
        }

        // Handles what happens when the enemy is confused
        if (other.GetComponent <EnemyAI>() != null && CanConfuse == true)
        {
            Enemy.Status = EnemyAI.EnemyStatus.Confused;
            Enemy.StartCoroutine(Enemy.CountdownDebuff());
            Enemy.Reverse();
            Enemy.SpriteColor.color = Color.red;
        }

        // Handles what happens when the enemy is disabled
        if (other.GetComponent <EnemyAI>() != null && CanPoison == true)
        {
            Enemy.Status = EnemyAI.EnemyStatus.Poisoned;
            Enemy.StartCoroutine(Enemy.CountdownDebuff());
            Enemy.SpriteColor.color = Color.green;
        }

        // Handles what happens when the enemy is paralyzed
        if (other.GetComponent <EnemyAI>() != null && CanParalyze == true)
        {
            Enemy.Status = EnemyAI.EnemyStatus.Paraylyzed;
            Enemy.StartCoroutine(Enemy.CountdownDebuff());
            Enemy.CanFireProjectiles = false;
            Enemy.SpriteColor.color  = Color.yellow;
        }

        takeDamage.TakeDamage(Damage, gameObject);
        DestroyProjectile(); // destroys the projectile
    }
	protected override void OnCollideTakeDamage (Collider2D other, ITakeDamage takeDamage)
	{
		takeDamage.TakeDamage (Damage, gameObject);
		DestroyProjectile ();
	}