Exemplo n.º 1
0
 public override void Reset()
 {
     StopMoving();
     m_OnDeath = null;
     m_IsAlive = false;
     transform.localPosition = Vector3.zero;
 }
 void Die()
 {
     OnEnemyDeath?.Invoke(this, new OnEnemyDeathEventArgs {
         enemyMovement = gameObject.GetComponent <EnemyMovement>()
     });
     Destroy(gameObject);
 }
Exemplo n.º 3
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("StompBox"))
     {
         OnEnemyDeath?.Invoke();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Called on death of one of passengers
        /// </summary>
        void PassengerDied(EnemyData passengerData, Transform enemyPosition, GameObject initiator)
        {
            // check for incorrect states;
            // must be 'Active' or 'DeadDriver'
            if (State == EnemyVehicleState.DeadPassengers ||
                (State == EnemyVehicleState.DeadDriver && passengerData.IsDriver) ||
                State == EnemyVehicleState.Nothing)
            {
                Debug.Log("Called from wrong state", this);
                return;
            }

            // decrement
            alivePassengersAmount--;

            // call event
            OnEnemyDeath?.Invoke(passengerData, enemyPosition, initiator);

            // if there are passengers, but driver died
            if (passengerData.IsDriver)
            {
                State = EnemyVehicleState.DeadDriver;

                DoDriverDeath();
            }

            // if there are no alive passengers
            if (alivePassengersAmount <= 0)
            {
                alivePassengersAmount = 0;
                State = EnemyVehicleState.DeadPassengers;

                DoPassengerDeath();
            }
        }
Exemplo n.º 5
0
 public void KillEnemy()
 {
     Destroy(gameObject);
     OnEnemyDeath?.Invoke(this, new OnEnemyDeathEventArgs {
         enemy = enemy
     });
 }
 public void ReachedGoal()
 {
     OnEnemyDeath?.Invoke(this, new OnEnemyDeathEventArgs {
         enemyMovement = gameObject.GetComponent <EnemyMovement>()
     });
     OnEnemyScored?.Invoke(this, EventArgs.Empty);
     Destroy(gameObject);
 }
Exemplo n.º 7
0
    void StartDeath()
    {
        gameObject.GetComponent <DramaticDeath>().StartDeath();
        //CameraShaker.Instance.ShakeOnce(1, 1, 1, 1);
        OnEnemyDeath?.Invoke(10);

        UnSubscribe();
    }
Exemplo n.º 8
0
    /*
     * Destroyes the game object after a few seconds and notifies the
     * subscribers of the `onEnemyDeath` event
     */
    private IEnumerator DestroyAfter(float seconds)
    {
        yield return(new WaitForSeconds(seconds));

        Destroy(gameObject);

        OnEnemyDeath?.Invoke(gameObject);
    }
Exemplo n.º 9
0
 public override void Death()
 {
     isDead = true;
     capsuleCollider.isTrigger = true;
     anim.SetTrigger("Dead");
     enemyAudio.clip = deathClip;
     enemyAudio.Play();
     OnEnemyDeath?.Invoke();
 }
Exemplo n.º 10
0
 protected void EnemyTakeDamage()
 {
     base.TakeDamage();
     if (health <= 0 && !enemyDeathInvoked)
     {
         OnEnemyDeath?.Invoke(transform.position);
         OnEnemyDeathPoints?.Invoke();
         enemyDeathInvoked = true;
     }
 }
Exemplo n.º 11
0
 private void CheckIfEnemyIsDead()
 {
     if (rb.position.y < 0.5f)
     {
         targetTransforms.Clear();
         targetDistances.Clear();
         OnEnemyDeath?.Invoke();
         isAlive = false;
     }
 }
Exemplo n.º 12
0
 public void TakeDamage()
 {
     hitTarget -= 1;
     animator.SetTrigger("TookDamage");
     if (hitTarget <= 0)
     {
         PlayHitSound();
         OnEnemyDeath?.Invoke();
         animator.SetBool("IsDying", true);
     }
 }
Exemplo n.º 13
0
 void Awake()
 {
     try
     {
         EnemySpawnerHandler enemySpawnerHandler = FindObjectOfType <EnemySpawnerHandler>();
         OnEnemyDeath = enemySpawnerHandler.OnEnemyDeath;
     }
     catch (Exception e)
     {
         Debug.Log("controlado");
     }
 }
Exemplo n.º 14
0
 // When an enemy died
 public void EnemyDeath(AbstractEnemy enemy)
 {
     OnEnemyDeath?.Invoke(enemy);
     EnemyKillCount++;
     LevelsScript.Instance.CurrentQuestion.killedEnemies++;
     if (EnemyKillCount >= EnemiesInGame)
     {
         LevelsScript.Instance.EndQuestion();
         //InvokeOnLevelCompleted();
     }
     Debug.Log($"we killed {enemy.Name}, we have now slain {EnemyKillCount} enemies");
     Destroy(enemy.gameObject);
 }
Exemplo n.º 15
0
    public virtual void Die(bool scorePoints = false)
    {
        ObjectPool.Instance.ReturnObject(this.gameObject);

        // Increase combo by 1

        if (scorePoints)
        {
            OnEnemyDeath?.Invoke(1);
            OnEnemyDeathScore?.Invoke(scoreValue);
            AudioManager.PlaySFX(deathSound, true);
        }
    }
Exemplo n.º 16
0
    protected override void HandleDeath(GameObject attacker)
    {
        var dungeon = Dungeon.Singleton;
        var loot    = transform.GetChild(0);

        loot.transform.SetParent(dungeon.GetRoomObject(dungeon.CurrentRoom.RoomID).transform);
        loot.GetComponent <Loot>().Drop(attacker, transform.position);

        attacker.GetComponent <BlackBoard>().RemoveTypePOI(GetType(), gameObject);

        OnEnemyDeath.Invoke();
        base.HandleDeath(attacker);
    }
Exemplo n.º 17
0
 public void UpdateHealth(int changeInHealth)
 {
     _currentHealth = ChangeHealth(changeInHealth);
     if (_currentHealth <= 0)
     {
         OnEnemyDeath?.Invoke(this);
         _animator.SetTrigger("Die");
         _enemy.enabled = false;
         Destroy(gameObject, 5);
     }
     else
     {
         StartCoroutine(DamageCooldown());
     }
 }
    public void KillEntity(IDamageable entity)
    {
        if (entity is Enemy)
        {
            OnEnemyDeath?.Invoke((Enemy)entity);
        }
        else if (entity is Player)
        {
            Debug.Log("Player died");
            OnPlayerDeath?.Invoke((Player)entity);
        }

        RemoveEntity(entity);
        entity.OnDeath();
        //print($"Enemies remaining: {DamageableEntities.Count}");
    }
Exemplo n.º 19
0
    public void ModifyHealth(int value)
    {
        Health = Health + value;
        if (Health <= 0)
        {
            OnEnemyDeath?.Invoke(this, null);
        }
        if (Health > maxHealth)
        {
            maxHealth = Health;
        }
        var damageText     = Instantiate(DamageText, gameObject.transform.position, Quaternion.identity);
        var floatingNumber = damageText.GetComponent <FloatingNumber>();

        floatingNumber.UIText.text = Math.Abs(value).ToString();
        healthFill.sizeDelta       = new Vector2(Math.Min((float)Health / maxHealth, 1f), healthFill.sizeDelta.y);
    }
Exemplo n.º 20
0
    //////////////
    public override void TakeDamage(int damage)
    {
        int calculatedDamage = damage;

        //
        // NOTE: сначала обработка входящего дамага, потом базовое применение
        //

        if (calculatedDamage > 0)
        {
            Health -= calculatedDamage;
        }

        if (Health < 0)
        {
            Health = 0;
        }

        m_EnemyHealthText.text = Health.ToString();

        // после применения урона проверяем, не погиб ли персонаж
        if (Health <= 0)
        {
            Debug.Log(m_EnemyData.Name + " is dead");

            if (m_AbilityCastingProcess != null)
            {
                StopCoroutine(m_AbilityCastingProcess);
                m_AbilityCastingProcess = null;
            }

            // дропаем предмет игроку
            MaterialData droppedItem = m_EnemyData.TryDropItem();

            if (droppedItem != null)
            {
                InventoryContent.Instance.AddMaterial(droppedItem);
                Debug.Log("Dropped item " + droppedItem.Name);
            }

            OnEnemyDeath?.Invoke();

            Destroy(gameObject);
        }
    }
Exemplo n.º 21
0
    /// <summary>
    /// This method destroys the enemy gameobject this script is attached to. Called when the corresponding stats Script calls OnDeath.
    /// </summary>
    protected virtual void Die()
    {
        agent.isStopped = true;
        dead            = true;
        GetComponent <Collider>().enabled = false;
        if (anim != default(Animator))
        {
            anim.SetBool("Dead", true);
        }

        stats.OnDeath -= Die;
        OnEnemyDeath?.Invoke(this); //Tell further listners that it was an enemy that died.

        if (Random.Range(0, 100) <= dropChance && AmmoCrate != null)
        {
            Instantiate(AmmoCrate, new Vector3(transform.position.x, 2, transform.position.z), transform.rotation);
        }
        Destroy(gameObject, deathAnimationLength + 0.1f);
    }
Exemplo n.º 22
0
        public void TakeDamage(float damage)
        {
            CurrentHealth = (CurrentHealth - damage > 0) ?
                            CurrentHealth - damage : 0;

            OnDamageTaken?.Invoke(damage);
            _damageHighlight.HighLight();

            if (CurrentHealth <= 0)
            {
                OnEnemyDeath?.Invoke(this);

                Destroy(gameObject);
                GameObject deathParticles = Instantiate(_deathParticles,
                                                        transform.position + new Vector3(0, 0.5f, 0),
                                                        Quaternion.identity);
                deathParticles.GetComponent <DestroyAfterTime>().StartTimer(0.5f);
            }
        }
Exemplo n.º 23
0
 //responsible for the movemnt of the enemy and makes it move towarads the current pathpoint and if it gets close enough changes target to the next. It also checks if the enemy has reached the last pathpoint and in that case invokes the OnEnemyDeath event.
 protected override void Movment()
 {
     if (i == 0)
     {
         currentPath = pathPoints[0];
         i++;
     }
     else
     {
         if (Distance(new Vector2(this.X, this.Y)) < distanceToChange)
         {
             if (currentPath == pathPoints[pathPoints.Length - 1] && !WaveController.DeadEnemies.Contains(this))
             {
                 OnEnemyDeath.Invoke();
             }
             else if (!WaveController.DeadEnemies.Contains(this))
             {
                 currentPath = pathPoints[i];
                 i++;
             }
         }
     }
     if (!WaveController.DeadEnemies.Contains(this))
     {
         if (this.X > currentPath.X)
         {
             this.X -= movementSpeed;
         }
         else if (this.X < currentPath.X)
         {
             this.X += movementSpeed;
         }
         else if (this.Y > currentPath.Y)
         {
             this.Y -= movementSpeed;
         }
         else if (this.Y < currentPath.Y)
         {
             this.Y += movementSpeed;
         }
     }
 }
    /// <summary>
    /// Actually destroys the object. Should only be called by an animation event.
    /// Also gives xp to the ally who killed this enemy
    /// </summary>
    protected override void Ascend()
    {
        // Give xp to the killer

        EnemyStats myStats = this.GetComponent <EnemyStats>();

        _myKiller.GainExperience(myStats.KillReward());

        //Give reduced xp to other allies
        foreach (AllyStats _helper in _helpers)
        {
            _helper.GainReducedExperience(myStats.SharedKillReward(_helper));
            // Debug.Log(_helper);
        }

        // Call the enemy death event
        OnEnemyDeath?.Invoke();

        // Call the base's version
        // (make sure to do this last, since the object is destroyed by this call)
        base.Ascend();
    }
    private void InitiateEnemy()
    {
        // No need to initiate anything if the object is a dummy,
        //  so simply skip this part and move to the update loop.
        if (isDummy)
        {
            return;
        }

        if (!GameObject.FindGameObjectWithTag("Player"))
        {
            Debug.LogError("Could not find a player, make sure they are tagged and present in the current scene.", gameObject);
        }

        levelManager = LevelManager.instance;
        levelManager.onDayStateChangeCallback += NightBuff;

        onEnemyDeathCallback += DeathEffect;

        _attackDelay = enemyStats.characterAttackDelay.GetValue();
        canAttack    = true;
    }
Exemplo n.º 26
0
 void Awake()
 {
     animator    = GetComponent <Animator> ();
     audioSource = GetComponent <AudioSource>();
     blood       = GetComponent <ParticleSystem>();
     // hitParticles = GetComponent<ParticleSystem>();
     //Declaracion observers
     try {
         //Change make this an option
         if (isStateMachines)
         {
             EnemySpawnerHandler enemySpawnerHandler = FindObjectOfType <EnemySpawnerHandler>();
             OnEnemyDeath = enemySpawnerHandler.OnEnemyDeath;
         }
         else
         {
             BTEnemySpawnerHandler enemySpawnerHandler = FindObjectOfType <BTEnemySpawnerHandler>();
             OnEnemyDeath = enemySpawnerHandler.OnEnemyDeath;
         }
     }
     catch (Exception e) {
     }
 }
Exemplo n.º 27
0
 public static void EnemyDied(int i)
 {
     OnEnemyDeath?.Invoke(i);
 }
Exemplo n.º 28
0
 public static void EnemyDiedShake()
 {
     OnEnemyDeath?.Invoke();
 }
Exemplo n.º 29
0
 public void OnEnemyDeathInvoke()
 {
     OnEnemyDeath?.Invoke();
 }
Exemplo n.º 30
0
 private void OnDestroy()
 {
     OnEnemyDeath?.Invoke();
 }