// Shoot management
    protected virtual void Shoot()
    {
        GameObject      shoot       = ShootPool.instance.getObjectOfType(bulletName, Utils.CreateStructFromTransform(transform));
        ShootBaseEntity shootEntity = shoot.GetComponent <ShootBaseEntity>();

        if (shootEntity && !currentShoots.Contains(shoot))
        {
            currentShoots.Add(shoot);
            shootEntity.SetOwnerSpawner(this);
        }
    }
Esempio n. 2
0
    protected virtual void OnTriggerEnter2D(Collider2D other)
    {
        if (currentHealth <= 0)
        {
            return;
        }
        ShootBaseEntity shootEntity  = other.gameObject.GetComponent <ShootBaseEntity>();
        ShooterEntity   otherShooter = other.gameObject.GetComponent <ShooterEntity>();

        if (other.gameObject.tag == "shoot" && shootEntity != null)
        {
            switch (this.type)
            {
            case CharacterType.npc:
            case CharacterType.player:
                if (shootEntity.type == CharacterType.enemy)
                {
                    // NPC BEHAVIOUR
                }

                break;

            case CharacterType.enemy:
                if (shootEntity.type == CharacterType.npc || shootEntity.type == CharacterType.player)
                {
                    // Critical
                    float baseDamage = shootEntity.damage;
                    bool  isCritical = false;
                    if (Utils.GetRand01() < 0.09f)
                    {
                        baseDamage *= 1.8f;
                        isCritical  = true;
                    }
                    // Health reduction
                    currentHealth -= (int)Mathf.Ceil(baseDamage);
                    PlayDamageHit();


                    if (enemyInterface != null)
                    {
                        enemyInterface.OnHit();
                    }
                    if (_bar)
                    {
                        _bar.ReduceHealthBar(currentHealth, totalHealth);
                    }
                }

                break;

            default:
                break;
            }
        }
        else if (otherShooter != null && otherShooter.type == CharacterType.enemy && (this.type == CharacterType.player || this.type == CharacterType.npc))
        {
            if (otherShooter.damageByCollision > 0)
            {
                currentHealth -= otherShooter.damageByCollision;
                PlayDamageHit();
                if (enemyInterface != null)
                {
                    enemyInterface.OnHit();
                }
                if (_bar)
                {
                    _bar.ReduceHealthBar(currentHealth, totalHealth);
                }
            }
        }
        if (currentHealth <= 0 && hitableInterface != null)
        {
            EntityDestroy();
        }
    }