public void ApplyEffect(StatusEffect effect, float duration)
    {
        StatusEffect toRemove = null;

        foreach (StatusEffect currentEffect in effects)
        {
            if (currentEffect.GetType() == effect.GetType())
            {
                currentEffect.Deactivate();
                toRemove = currentEffect;
                break;
            }
        }
        effects.Remove(toRemove);
        effect.Activate(duration);
        effects.Add(effect);
    }
Ejemplo n.º 2
0
 public void AddStatusEffect(StatusEffect newEffect, GameCharacter source)
 {
     statusEffects.Add(newEffect);
     newEffect.Activate(this, source);
 }
    public virtual void DoDamage(GameObject attacker, float damage, GameObject statusEffect)
    {
        if (!isImmortal)
        {
            OnHealthChangedArgs args = new OnHealthChangedArgs(attacker, damage);
            if (OnReceiveDamage != null)
            {
                OnReceiveDamage(this, args);
            }

            if (!args.Cancel && args.ChangeValue != 0)
            {
                if (statusEffect != null && gameObject != null)
                {
                    GameObject tempStatusEffect = Instantiate(statusEffect, transform);
                    if (tempStatusEffect != null)
                    {
                        StatusEffect statusScript = tempStatusEffect.GetComponent <StatusEffect>();
                        if (statusScript != null)
                        {
                            StatusEffectArgs statusArgs = new StatusEffectArgs(statusScript, tempStatusEffect);
                            if (OnNewStatusEffect != null)
                            {
                                OnNewStatusEffect(this, statusArgs);
                            }

                            if (!statusArgs.Cancel)
                            {
                                statusScript.Activate(gameObject);
                            }
                        }
                    }
                }

                List <GameObject> AvailablePlayer = new List <GameObject>(GameObject.FindGameObjectsWithTag("Player"));

                if (gameObject.tag == "Enemy")
                {
                    health -= args.ChangeValue * (float)Math.Pow(groupDamage, (double)AvailablePlayer.Count);   //TODO: Abhängig von Spieleranzahl
                }
                else
                {
                    health -= args.ChangeValue;
                }

                if (health <= 0)
                {
                    health = 0;
                    if (OnDeath != null)
                    {
                        OnDeath(this, EventArgs.Empty);
                    }

                    if (audioSource != null && DeathSound != null)
                    {
                        audioSource.clip = DeathSound;
                        audioSource.Play();
                    }
                }
                else
                {
                    if (audioSource != null && DamageSound != null && !audioSource.isPlaying)
                    {
                        audioSource.clip = DamageSound;
                        audioSource.Play();
                    }
                }
            }
        }
    }