/// <summary>
 /// Adds the parameter to the current health. Clamps the health value between 0 - maxHealth. Will fire events.
 /// </summary>
 public override void ChangeHealth(IDamageInfo dmgInf)
 {
     Debug.Log(name + " recieved " + dmgInf + ", resulting in " + (dmgInf.Damage * resistance.resistances[(int)dmgInf.DmgTyp]) + " damage.");
     currentHealth += dmgInf.Damage * resistance.resistances[(int)dmgInf.DmgTyp];
     currentHealth  = Mathf.Clamp(currentHealth, 0, maxHealth);
     FireEvents(dmgInf);
 }
 public override void TakeDamage(IDamageInfo dmgInf)
 {
     Debug.Assert(actor != null);
     Debug.Log(name + " recieved " + dmgInf + ", resulting in " + (dmgInf.Damage * multiplikator) + " damage.");
     dmgInf.Damage *= multiplikator;
     actor.ChangeHealth(dmgInf);
 }
 /// <summary>
 /// Adds the parameter to the current health. Clamps the health value between 0 - maxHealth. Will fire events.
 /// No resistance is applied.
 /// </summary>
 public override void ChangeHealthRaw(IDamageInfo dmgInf)
 {
     Debug.Log(name + " recieved " + dmgInf + ", resulting in " + dmgInf.Damage + " damage.");
     currentHealth += dmgInf.Damage;
     currentHealth  = Mathf.Clamp(currentHealth, 0, maxHealth);
     FireEvents(dmgInf);
 }
        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);
            }
        }
        private IEnumerator HandleLongTimeDamager(ITimedDamageInfo timedDmgInf, HealthChangeTyp healthChangeTyp)
        {
            IDamageInfo timeLessDmg = (IDamageInfo)timedDmgInf;

            while (timedDmgInf.RunTime > 0)
            {
                ChangeHealth(timeLessDmg);
                float secondsToWait = timedDmgInf.Frequency;
                yield return(new WaitForSeconds(secondsToWait));

                timedDmgInf.RunTime -= secondsToWait;
            }
        }
        public override void OnInspectorGUI()
        {
            DamageFeedbackDefinition myTarget = (DamageFeedbackDefinition)target;

            myTarget.ResizeOrCreateAudioClips();
            EditorGUI.BeginChangeCheck();
            for (int i = 0; i < IDamageInfo.DamageTypCount; i++)
            {
                SerializedProperty tps = serializedObject.FindProperty("audioClips").GetArrayElementAtIndex(i);
                EditorGUILayout.PropertyField(tps, new GUIContent(IDamageInfo.DamageTypToString(i)), true);
            }
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
        public override void TakeDamageIgnoreMultiplier(IDamageInfo dmgInf, IHealth.HealthChangeTyp changeTyp)
        {
            switch (changeTyp)
            {
            case IHealth.HealthChangeTyp.Clamping:
                TakeDamageIgnoreMultiplier(dmgInf);
                break;

            case IHealth.HealthChangeTyp.Raw:
                TakeDamageRaw(dmgInf);
                break;

            case IHealth.HealthChangeTyp.NoClamping:
                TakeDamageDontClampIgnoreMultiplier(dmgInf);
                break;
            }
        }
        public override void TakeDamage(IDamageInfo dmgInf, IHealth.HealthChangeTyp changeTyp)
        {
            switch (changeTyp)
            {
            case IHealth.HealthChangeTyp.Clamping:
                TakeDamage(dmgInf);
                break;

            case IHealth.HealthChangeTyp.Raw:
                TakeDamageIgnoreResistance(dmgInf);
                break;

            case IHealth.HealthChangeTyp.NoClamping:
                TakeDamageDontClamp(dmgInf);
                break;
            }
        }
 /// <summary>
 ///Will apply the damage without any multiplication.
 /// /// <summary>
 public abstract void TakeDamageIgnoreMultiplier(IDamageInfo dmgInf, IHealth.HealthChangeTyp changeTyp);
 /// <summary>
 ///Will apply the damage without any multiplication.
 /// /// <summary>
 public abstract void TakeDamageIgnoreMultiplier(IDamageInfo dmgInf);
 /// <summary>
 ///Will apply the damage without clamp the health to between 0 and max.
 /// /// <summary>
 public abstract void TakeDamageDontClamp(IDamageInfo dmgInf);
Example #12
0
 /// <summary>
 /// Adds the parameter to the current health and clamp it to max health.
 /// </summary>
 public abstract void ChangeHealth(IDamageInfo dmgInf);
 public override void TakeDamageRaw(IDamageInfo dmgInf)
 {
     Debug.Assert(actor != null);
     actor.ChangeHealthRaw(dmgInf);
 }
 public override void TakeDamageIgnoreResistance(IDamageInfo dmgInf)
 {
     Debug.Assert(actor != null);
     dmgInf.Damage *= multiplikator;
     actor.ChangeHealthRaw(dmgInf);
 }
 public override void TakeDamageIgnoreMultiplier(IDamageInfo dmgInf)
 {
     Debug.Assert(actor != null);
     actor.ChangeHealth(dmgInf);
 }
 public override void TakeDamageDontClamp(IDamageInfo dmgInf)
 {
     Debug.Assert(actor != null);
     dmgInf.Damage *= multiplikator;
     actor.ChangeHealth_NoClamping(dmgInf);
 }
 /// <summary>
 /// Will apply the damage.
 /// /// <summary>
 public abstract void TakeDamage(IDamageInfo dmgInf, IHealth.HealthChangeTyp changeTyp);
 /// <summary>
 ///Will apply the damage without any modifications.
 /// /// <summary>
 public abstract void TakeDamageRaw(IDamageInfo dmgInf);
Example #19
0
 /// <summary>
 /// Adds the parameter to the current health, but dont clamp it to max health.
 /// </summary>
 public abstract void ChangeHealth_NoClamping(IDamageInfo dmgInf);
 /// <summary>
 ///Will apply the damage without any resistance applied.
 /// /// <summary>
 public abstract void TakeDamageIgnoreResistance(IDamageInfo dmgInf);
Example #21
0
 /// <summary>
 /// Fires a event to all listeners.
 /// </summary>
 public abstract void FireEvents(IDamageInfo dmgInf);
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);
            position.height = EditorGUIUtility.singleLineHeight;
            label.text     += " multiplicator";
            foldout         = EditorGUI.Foldout(position, foldout, label);
            if (foldout)
            {
                // Don't make child fields be indented
                int indent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = indent + 1;
                position.y           += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                // Draw fields - passs GUIContent.none to each so they are drawn without labels
                SerializedProperty resArray = property.FindPropertyRelative("resistances");
                if (resArray.arraySize < IDamageInfo.DamageTypCount)
                {
                    int oldSize = resArray.arraySize;
                    resArray.arraySize = IDamageInfo.DamageTypCount;
                    do
                    {
                        resArray.InsertArrayElementAtIndex(oldSize++);
                        resArray.GetArrayElementAtIndex(oldSize - 1).floatValue = 1;
                    } while (oldSize != IDamageInfo.DamageTypCount);
                    property.serializedObject.ApplyModifiedProperties();
                }
                else if (resArray.arraySize > IDamageInfo.DamageTypCount)
                {
                    resArray.arraySize = IDamageInfo.DamageTypCount;
                    property.serializedObject.ApplyModifiedProperties();
                }
                position.height = EditorGUIUtility.singleLineHeight;
                for (int i = 0; i < resArray.arraySize; i++)
                {
                    EditorGUI.PropertyField(position, resArray.GetArrayElementAtIndex(i), new GUIContent(IDamageInfo.DamageTypToString(i)));
                    position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                }
                // Set indent back to what it was
                EditorGUI.indentLevel = indent;
            }


            EditorGUI.EndProperty();
        }