Exemple #1
0
    public void EnterAttackState()
    {
        Log($"---------- {MethodBase.GetCurrentMethod().Name} ----------");
        if (_selected)
        {
            OnUnitInterupt?.Invoke();
        }

        LookAt(_attackPos);
        _prevState = _unitState;
        _unitState = Enums.UnitState.Attacking;
        Log("----------------------------------------");
    }
Exemple #2
0
    public void ReceiveDamage(int damage, bool playClip = false)
    {
        if (isUntouchable || isDead)
        {
            return;
        }
        if (healthPoints >= DamagedThreshold * MaxHealth && healthPoints - damage < DamagedThreshold * MaxHealth)
        {
            audioSource.PlayOneShot(deacticatedClip, 1.0f);
        }
        healthPoints = Mathf.Clamp(healthPoints - damage, 0, MaxHealth);
        if (playClip)
        {
            audioSource.PlayOneShot(damageClip, 0.3f);
        }
        UpdateHealthBar();

        if (healthPoints <= 0)
        {
            gameOverEffect.SetActive(true);
            isDead = true;
            OnDeath.Invoke();
            audioSource.Play();
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        Element element = other.GetComponent <Element>();

        if (element)
        {
            _actualEnergy += element.EnergyGain;
            float ratio = _actualEnergy;
            Debug.Log("ratio1 " + _actualEnergy);
            UiManager.Instance.UpdateEnergy(_actualEnergy);

            if (element.EnergyGain < 0)
            {
                if (_actualEnergy < 0)
                {
                    OnDeath.Invoke();
                }
            }
            else
            {
                if (_actualEnergy >= MaxEnergy)
                {
                    NextLevel.Invoke();
                }
            }
            Debug.Log("ratio2 " + ratio);
            Camera.main.fieldOfView = Mathf.Lerp(MinFov, MaxFov, _actualEnergy);
            _actualForwardSpeed     = Mathf.Lerp(MinForwardSpeed, MaxForwardSpeed, _actualEnergy);
            OnSpeedUp.Invoke(_actualEnergy);
        }
    }
Exemple #4
0
    protected virtual void FixedUpdate()
    {
        if (isDead)
        {
            return;
        }

        Vector3 targetPos = spawnpos;

        if (!isGoingBack && target)
        {
            targetPos = target.position;
        }

        Vector3 dir = targetPos - transform.position;

        dir.y = transform.position.y;
        dir   = Vector3.ClampMagnitude(dir, 1);

        Animator.SetFloat("Horizontal", dir.x);
        Animator.SetFloat("Vertical", dir.z);
        RB.velocity = Vector3.zero;
        RB.MovePosition(transform.position + dir * movementSpeed * Time.deltaTime);

        if (isGoingBack && Vector3.Distance(transform.position, spawnpos) < 0.1f)
        {
            PlayerHealth.Instance.TakeDamage();
            OnDeath?.Invoke(this);
            Destroy(gameObject);
        }
    }
Exemple #5
0
        public void Update(uint tick, float gameSpeed)
        {
            List <Entity> toDestroy = new List <Entity>();

            for (int i = 0; i < Compatible.Count; i++)
            {
                var entity = Compatible[i];
                var health = entity.GetComponent <HealthComponent>();

                // If heath is below 0 then kill it
                if (health.Health <= 0 || health.Suicude > 0)
                {
                    toDestroy.Add(entity);
                    // Check if we would be killing an entity with energy
                    if (entity.TryGetComponent <EnergyComponent>(out EnergyComponent deadEnergy))
                    {
                        deadEnergy.HandleDeath(_energyManager, Pool, _simulation.JsonSettings, entity.GetComponent <TransformComponent>().WorldPosition);
                    }
                    var loc = entity.GetComponent <TransformComponent>().WorldPosition;
                    OnDeath?.Invoke(new DeathEventInfo(loc, tick * gameSpeed, entity.Id, entity.Tag, new HealthDeathCause()));
                }
            }
            foreach (var e in toDestroy)
            {
                Pool.DestroyEntity(e);
            }
        }
        public override void FireEvents(IDamageInfo dmgInf)
        {
            if (isSilent)
            {
                return;
            }
            IDamageInfo overrideSaveDmg = (IDamageInfo)dmgInf.Clone();

            if (currentHealth <= 0)
            {
                if (OnDeath != null && !deathTriggered)
                {
                    deathTriggered = true;
                    OnDeath.Invoke(this, overrideSaveDmg);
                }
            }
            else
            {
                deathTriggered = false;
            }
            if (OnHealthChanged != null && lastHealth != currentHealth)
            {
                lastHealth = currentHealth;
                OnHealthChanged(this, overrideSaveDmg);
            }
        }
    public void Modify(int amount)
    {
        m_currentHealth += amount;

        Mathf.Clamp(m_currentHealth, 0, m_maxHealth);

        if (amount < 0)
        {
            if (OnTakeDamage != null)
            {
                OnTakeDamage.Invoke();
            }
        }
        else if (amount > 0)
        {
            if (OnHeal != null)
            {
                OnHeal.Invoke();
            }
        }
        else
        {
            Debug.Log("Modify called with 0");
        }

        if (OnValueChange != null)
        {
            OnValueChange.Invoke(PercentHealth);
        }

        if (m_currentHealth <= 0 && OnDeath != null)
        {
            OnDeath.Invoke();
        }
    }
Exemple #8
0
    /**
     * <summary>
     * Decrements the health value and if is dead returns the given experience, 0 otherwise
     * </summary>
     */
    public float OnDamageReceived(float damage)
    {
        OnHit?.Invoke();
        if (IsAlive())
        {
            audioManager.Play("BodyHit");
        }
        var finalDamage = absorption >= damage ? 0 : damage - absorption;

        health -= finalDamage;
        if (IsAlive())
        {
            if (IsSkeleton())
            {
                randomAudio.Play();
            }
            return(0);
        }
        if (!isDead)
        {
            OnDeath?.Invoke();
            if (IsSkeleton())
            {
                audioManager.Play("SkeletonDeath");
            }
            isDead = true;
            return(experience);
        }
        return(0);
    }
Exemple #9
0
        public void Update(uint tick, float _gameSpeed)
        {
            List <Entity> toDestroy = new List <Entity>();

            for (int i = 0; i < Compatible.Count; i++)
            {
                var entity       = Compatible[i];
                var ageComponent = entity.GetComponent <OldAgeComponent>();
                ageComponent.CurrentAge += _gameSpeed * _oldAgeMultiplier;

                if (ageComponent.CurrentAge >= ageComponent.MaxAge && _oldAgeEnabled)
                {
                    toDestroy.Add(entity);
                    // Check if we would be killing an entity with energy


                    if (entity.TryGetComponent <EnergyComponent>(out EnergyComponent deadEnergy))
                    {
                        deadEnergy.HandleDeath(_energyManager, Pool, _simulation.JsonSettings, entity.GetComponent <TransformComponent>().WorldPosition);
                    }
                    var transform = entity.GetComponent <TransformComponent>();

                    OnDeath?.Invoke(new DeathEventInfo(transform.WorldPosition, tick * _gameSpeed, entity.Id, entity.Tag, new OldAgeDeathCause()));
                }
            }
            foreach (var e in toDestroy)
            {
                Pool.DestroyEntity(e);
            }
        }
Exemple #10
0
 public void Die(GameObject source)
 {
     if (onDeath != null)
     {
         onDeath.Invoke(new OnDeathArgs(source));
     }
 }
Exemple #11
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Obstacle"))
        {
            if (!isDeath)
            {
                // Calculate point of impact
                deathImpactDirection = transform.position - other.transform.position;
                deathImpactDirection.Normalize();

                audioSource.clip = deathAudio;
                audioSource.Play();

                isDeath = true;
                OnDeath?.Invoke();
            }
        }

        if (other.gameObject.CompareTag("Goal"))
        {
            if (!isDeath)
            {
                OnGoalTouched?.Invoke();
            }
        }
    }
        public virtual void Die()
        {
            OnDeath?.Invoke(this);

            StatisticsManager.Instance.AddIntValue($"Entity.Killed.{stats.name}", 1);
            Destroy(gameObject);
        }
Exemple #13
0
    public override void Die()
    {
        if (dead)
        {
            return;
        }

        dead      = true;
        activated = false;

        // Animation and Sound of death
        AudioManager.instance.PlaySound("DieSound");
        dieParticles.Play();

        // If enemy didn't drop power up we may drop some ammo
        if (!GeneratePowerUP())
        {
            GenerateAmmoBox();
        }

        // Call OnDeath event
        OnDeath?.Invoke();

        if (animator != null)
        {
            ChangeAnimationState("Die");
        }
    }
 private void CheckForDeath()
 {
     if (combatStats.Health <= 0)
     {
         OnDeath?.Invoke();
     }
 }
 public void Die()
 {
     _spriteRenderer.color = deathTint;
     IsAlive = false;
     Lock();
     OnDeath?.Invoke();
 }
Exemple #16
0
    // When life is 0 this is called by TakeDamage or Update
    void HandleDeath()
    {
        if (gameObject.tag == "Player")
        {
            currentLife   = MaxLife;
            currentShield = MaxShield;
        }

        // Invoke the On Death Event
        if (onDeath != null)
        {
            onDeath.Invoke();
        }

        if (DestroyOnDeath == true)
        {
            // Destroy the gameobject
            Destroy(gameObject);
        }
        else if (!KeepOnDeath)
        {
            // Respawn the gameobject?
            gameObject.SetActive(false);
        }

        if (explosionPrefab)
        {
            destroyedObject = Instantiate(explosionPrefab);
            destroyedObject.transform.position   = transform.position;
            destroyedObject.transform.rotation   = transform.rotation;
            destroyedObject.transform.localScale = new Vector3(explosionScale, explosionScale, explosionScale);

            AreaManager.Instance.OnObjectAdd(destroyedObject);
        }
    }
Exemple #17
0
 private void Die()
 {
     if (OnDeath != null)
     {
         OnDeath.Invoke();
     }
 }
Exemple #18
0
 public virtual void KillTile()
 {
     //does not remove it from map tiles
     Destroy(gameObject);
     OnDeath?.Invoke(this);
     Map.RemoveTile(LayeredGridPosition);
 }
Exemple #19
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         OnDeath?.Invoke();
     }
 }
Exemple #20
0
    public void AlterHealth(int changeInHealth)
    {
        CurrentHealth += changeInHealth;

        if (onHealthAltered != null)
        {
            onHealthAltered.Invoke(this);
        }

        var negative = changeInHealth < 0;

        if (negative)
        {
            hitIndicator.Indicate();
        }

        if (CurrentHealth <= 0)
        {
            currentCell.cellUnit = null;
            if (onDeath != null)
            {
                onDeath.Invoke(this);
            }
            Destroy(this.gameObject);
        }
    }
    private void Death(bool doDestroy)   // no need to handle the non destructive death, since it never happens
    {
        OnDeath?.Invoke();

        anim.SetBool("isDead", true);
        pc.StopControl();
        Debug.Log("stopped control");
        rb.velocity = Vector2.zero; //prevent sliding
        coroutines.WaitThenExecute(1f, () => {
            sf.FadeIn();
        });
        coroutines.WaitThenExecute(2f, () => {
            hs.FullHealth();
            tr.position = respawnPoint;
        });
        coroutines.WaitThenExecute(3f, () => {
            sf.FadeOut();
        });
        coroutines.WaitThenExecute(3.5f, () => {
            anim.SetBool("isDead", false);
        });
        coroutines.WaitThenExecute(3.8f, () => {
            pc.RegainControl();
            Debug.Log("regained control");
        });
        //TODO finesse this
    }
        private void PerformDeath()
        {
            if (deathAnimationFinished)
            {
                return;
            }

            if (!IsDrowning && CurrentActionState != Action.Dying)
            {
                OnDeath?.Invoke(this);
                OnDeath           -= OnDeath;
                CurrentActionState = Action.Dying;
                PlayDeathSound();
            }

            if (SpriteInstanceAnimate && IsOnFinalFrameOfAnimation)
            {
                SpriteInstanceAnimate = false;
            }

            if (Altitude <= 0f && IsOnFinalFrameOfAnimation)
            {
                if (IsDrowning)
                {
                    OnDeath?.Invoke(this);
                    OnDeath -= OnDeath;
                }
                deathAnimationFinished = true;
                this.Call(() =>
                {
                    RemoveArrows();
                    Destroy();
                }).After(2f);
            }
        }
Exemple #23
0
    public virtual bool ModifyHealth(int amount)
    {
        if (amount < 0 && Audio)
        {
            Audio.Play();
        }

        health += amount;
        if (health <= 0)
        {
            Die();
        }
        return(health <= 0);

        void Die()
        {
            OnDeath?.Invoke(this);
            Collider.enabled = false;
            RB.isKinematic   = true;
            isDead           = true;
            target           = null;
            if (Animator.GetFloat("Horizontal") > 0)
            {
                Vector3 curScale = transform.localScale;
                curScale.x          *= -1;
                transform.localScale = curScale;
            }
            Animator.SetTrigger("Die");
        }
    }
Exemple #24
0
    public void TakeDamage(float proposedDamage, Monster source)
    {
        var actualDamage = (int)(proposedDamage / Defense);

        Health -= actualDamage;
        OnDamage?.Invoke(this, new OnDamageEventArgs()
        {
            DamageAmount = actualDamage, RemainingHealth = Health, DamageSource = source
        });

        if (Health > 0)
        {
            return;
        }

        OnDeath?.Invoke(this, new OnDeathEventArgs()
        {
            DamageSource = source
        });
        if (Health > 0)
        {
            return;             //OnDeath may restore health
        }
        gameObject.SetActive(false);
        Battle.Instance.CalculateTurnOrder();
    }
    public void Damage(float amount, GameObject attacker = null, Vector3?from = null)
    {
        if (Invulnerable)
        {
            return;
        }
        if (Health <= 0)
        {
            return;
        }

        Health -= amount;

        if (DamageRegenDelay > 0)
        {
            regenDelay = DamageRegenDelay;
        }

        OnDamage?.Invoke(amount);

        if (Health < 0 + Mathf.Epsilon)
        {
            if (RagdollOnDeath)
            {
                ActivateRagdoll(true);
            }
            OnDeath?.Invoke();
        }
    }
Exemple #26
0
    /// <summary>
    /// Kills the component with sound and effects.
    /// </summary>
    public void Die()
    {
        if (data.deathAnim != null)
        {
            var       deathAnim = ObjectPool.Instance.Spawn(ObjectPool.Types.explosion, transform.position);
            Explosion exp       = deathAnim.GetComponent <Explosion>();

            exp.data = data.deathAnim;
            exp.Initialize();
        }

        if (data.deathText != null)
        {
            GameManager.Instance.Money += data.killReward;

            var        flyingText = ObjectPool.Instance.Spawn(ObjectPool.Types.flyingText, transform.position);
            FlyingText text       = flyingText.GetComponent <FlyingText>();

            text.data = data.deathText;
            text.Initialize(data.killReward);
        }

        if (data.dropHealth)
        {
            if (Random.Range(0, 100f) < data.dropChance)
            {
                ObjectPool.Instance.Spawn(ObjectPool.Types.healthDrop, transform.position);
            }
        }

        AudioManager.Instance.PlaySound(data.deathAudio);
        OnDeath?.Invoke(gameObject);

        Destroy(gameObject);
    }
Exemple #27
0
        public void SetHealth(int hp, int hpmax)
        {
            if (HP <= 0 && hp > 0)
            {
                OnRevive?.Invoke(this);
            }

            BaseInst.SetHealth(hp, hpmax);
            if (hp <= 0)
            {
                if (IsSpawned && !IsPlayer)
                {
                    World.DespawnList_NPC.AddVob(this);
                }

                if (unconTimer != null && unconTimer.Started)
                {
                    unconTimer.Stop();
                }
            }

            if (hp <= 0)
            {
                _Uncon = Unconsciousness.None;
                OnDeath?.Invoke(this);
                sOnDeath?.Invoke(this);
            }
        }
Exemple #28
0
    public void TakeDamage(bool doInvincibility)
    {
        if (!godMode)
        {
            if (!isInvincible && !(invulnerabilityBoost && doInvincibility))
            {
                //Handle damage taking
                health--;
                if (health >= 0)
                {
                    healthArea.transform.GetChild(health).gameObject.SetActive(false);
                }
                if (health <= 0)
                {
                    soundManager.PlaySFX(sfxCollection.playerDeath);
                    // Handle player death
                    OnDeath?.Invoke();
                    gm.GameOver();
                }

                if (doInvincibility)
                {
                    isInvincible = true;
                }
            }
        }
    }
Exemple #29
0
    /// <summary>
    /// Deals damage and returns damage actually dealt
    /// </summary>
    /// <param name="amount"></param>
    /// <returns></returns>
    public float TakeDamage(float amount)
    {
        var healthAfter = Mathf.Clamp(_health.Health - amount, 0.0f, _health.MaxHealth);
        var dmgDealt    = _health.Health - healthAfter;

        if (_info.IsLocal)
        {
            if (_damageManager.NegateDamage == false)
            {
                _health.Health = healthAfter;
            }
            OnDamageTaken?.Invoke(new DamageTakenArgs(dmgDealt, _health.Health));

            if (_health.Health <= 0.0f)
            {
                DeathParameters deathParameters = new DeathParameters();
                deathParameters.characterInfo = _info;
                OnDeath?.Invoke(deathParameters);
            }
        }
        else
        {
            SendMessage(amount); //we use {amount} instead of {dmgDealt} because HP may not be up to date on the client
        }

        return(dmgDealt);
    }
Exemple #30
0
 private void Kill()
 {
     OnAnyEnemyDeath?.Invoke();
     UnitKillPointReached?.Invoke();
     OnDeath?.Invoke();
     StartCoroutine(KillWithDelay());
 }