예제 #1
0
 public void ApplyStatusEffect(DD4EStatusEffect newStatusEffect)
 {
     // Extend the duration of Status Effect with similar effect
     if (StatusEffects.Exists(s => s.IsSameEffect(newStatusEffect)))
     {
         var newDamageEffect = (newStatusEffect as DD4EDamageModifier);
         if (newDamageEffect != null)
         {
             var index = StatusEffects.IndexOf(StatusEffects.Find(s => s.IsSameEffect(newStatusEffect)));
             if (newDamageEffect.DamageAmount > (StatusEffects[index] as DD4EDamageModifier).DamageAmount)
             {
                 StatusEffects[index] = newStatusEffect;
             }
         }
         else
         {
             var index = StatusEffects.IndexOf(StatusEffects.Find(s => s.IsSameEffect(newStatusEffect)));
             StatusEffects[index].Duration = newStatusEffect.Duration;
         }
     }
     else
     {
         StatusEffects.Add(newStatusEffect);
     }
     OnPropertyChanged("StatusEffects");
 }
예제 #2
0
        public void TakeDamage(DD4EDamageType damageType, int damage)
        {
            int incomingDamage = damage;

            // Find Vulnerability Amount
            var vulnerabilityModifier = 0;

            foreach (DD4EStatusEffect status in StatusEffects.FindAll(s => s.Type == DD4EStatusEffectType.Vulnerability))
            {
                var damageStatus = (status as DD4EDamageModifier);
                if (damageStatus != null)
                {
                    if ((damageStatus.DamageType & damageType) != DD4EDamageType.None)
                    {
                        vulnerabilityModifier = Math.Max(vulnerabilityModifier, damageStatus.DamageAmount);
                    }
                }
            }
            incomingDamage += vulnerabilityModifier;

            // Apply Resitances
            // 1) Build List of Resistance
            var            resistanceModifier = Int32.MaxValue;
            DD4EDamageType resistanceList     = DD4EDamageType.None;

            foreach (DD4EStatusEffect status in StatusEffects.FindAll(s => s.Type == DD4EStatusEffectType.Resistance))
            {
                var damageStatus = (status as DD4EDamageModifier);
                if (damageStatus != null)
                {
                    resistanceList |= damageStatus.DamageType;
                }
            }

            // 2) Figure out if they resist everything
            if ((resistanceList & damageType) == damageType)
            {
                // 3) If they resist everything, find lowest resistance value and do so
                foreach (DD4EStatusEffect status in StatusEffects.FindAll(s => s.Type == DD4EStatusEffectType.Resistance))
                {
                    var damageStatus = (status as DD4EDamageModifier);
                    if (damageStatus != null)
                    {
                        if ((damageStatus.DamageType & damageType) != DD4EDamageType.None)
                        {
                            resistanceModifier = Math.Min(resistanceModifier, damageStatus.DamageAmount);
                        }
                    }
                }

                // 4) If they have a resist all use the maximum between all and the current resistance
                if (StatusEffects.Exists(s => s.Type == DD4EStatusEffectType.Resistance && (s as DD4EDamageModifier).DamageType == DD4EDamageType.All))
                {
                    resistanceModifier = Math.Max(resistanceModifier, (StatusEffects.Find(s => s.Type == DD4EStatusEffectType.Resistance && (s as DD4EDamageModifier).DamageType == DD4EDamageType.All) as DD4EDamageModifier).DamageAmount);
                }

                // 5) Apply Resistance
                incomingDamage -= resistanceModifier;
            }

            if (incomingDamage > 0)
            {
                if (TemporaryHP > 0)
                {
                    if (TemporaryHP > incomingDamage)
                    {
                        TemporaryHP   -= incomingDamage;
                        incomingDamage = 0;
                    }
                    else
                    {
                        incomingDamage -= TemporaryHP;
                        TemporaryHP     = 0;
                    }
                }
            }

            if (incomingDamage > 0)
            {
                CurrentHP = Math.Max(0, CurrentHP - incomingDamage);
            }

            if (CurrentHP <= 0)
            {
                // Remove Regeneration and Ongoing Damage
                StatusEffects.RemoveAll(s => (s.Type == DD4EStatusEffectType.OngoingDamage || s.Type == DD4EStatusEffectType.Regeneration));
                OnPropertyChanged("StatusEffects");
            }
        }