Ejemplo n.º 1
0
        public Change ApplyModifier(
            ModificationParameter parameter,
            float amount,
            CharacterState sourceCharacter,
            ISubSpellHandler subSpell = null,
            bool applyChange          = true)
        {
            // First - calculate an actual change of modifier
            // using all spell amplification things, evasions and other stuff
            var change = CalcChange(parameter, amount, sourceCharacter, subSpell);

#if DEBUG_COMBAT
            _combatLog.Log(
                $"<b>{gameObject.name}</b> received modifier <b>{parameter}</b> with amount <b>{amount}</b>. Actual change: <b>{change.Amount}</b>");
#endif

            if (applyChange)
            {
#if DEBUG
                ModifierApplied?.Invoke(parameter, subSpell, change.Amount);
#endif
                // Apply an actual change
                ApplyChange(change);
            }

            return(change);
        }
Ejemplo n.º 2
0
    private void CharacterStateOnOnModifierApplied(ModificationParameter parameter, ISubSpellHandler spell, float actualChange)
    {
        var spellName = String.Empty;

        if (spell != null)
        {
            spellName = spell.Spell.name;
        }
        _modLog.Push($"{spellName} <color=yellow>{parameter}</color>: {actualChange:0.##}");

        foreach (var line in _modLog.Reverse())
        {
            _stringBuilder2.AppendLine(line);
        }

        Text2.text = _stringBuilder2.ToString();
        _stringBuilder2.Clear();
    }
Ejemplo n.º 3
0
        private Change CalcChange(ModificationParameter parameter,
                                  float amount,
                                  CharacterState sourceCharacter,
                                  ISubSpellHandler subSpell)
        {
            // Zero-change
            if (parameter == ModificationParameter.None || Mathf.Abs(amount) < 1e-6)
            {
                return new Change
                       {
                           Parameter = ModificationParameter.None,
                           Amount    = 0
                       }
            }
            ;

            if (parameter == ModificationParameter.HpFlat || parameter == ModificationParameter.HpMult)
            {
                var targetHp = _hp;

                if (parameter == ModificationParameter.HpFlat)
                {
                    targetHp += amount;
                }
                if (parameter == ModificationParameter.HpMult)
                {
                    targetHp *= amount;
                }
                targetHp = Mathf.Min(targetHp, MaxHealth);
                var delta = targetHp - _hp;
                // If taking damage
                if (delta < 0)
                {
                    // If the damage comes from spell, amplify it buy character source damage multiplier
                    if (subSpell != null && sourceCharacter != null)
                    {
                        // Damage amplification
                        delta *= sourceCharacter.SpellDamageMultiplier;
#if DEBUG_COMBAT
                        _combatLog.Log(
                            $"Receiving in total <b>{-delta}</b> spell multiplied ({100 * sourceCharacter.SpellDamageMultiplier}%) damage from <b>{sourceCharacter.name}</b> " +
                            $"from spell <b>{subSpell.Spell.name}</b>");
#endif

                        // Lifesteal
                        // TODO: Shouldn't we apply lifesteal afterwards?
                        var lifeStealFactor = subSpell.Spell.LifeSteal.GetValue(subSpell.Stacks);
                        var hpStolen        = -delta * lifeStealFactor;
                        if (hpStolen > 0)
                        {
#if DEBUG_COMBAT
                            _combatLog.Log(
                                $"Returning <b>{hpStolen}</b> hp back to <b>{sourceCharacter.name}</b> " +
                                $"because spell <b>{subSpell.Spell.name}</b> has <b>{100 * lifeStealFactor}%</b> lifesteal");
#endif
                            sourceCharacter.ApplyModifier(ModificationParameter.HpFlat,
                                                          hpStolen,
                                                          this,
                                                          subSpell);
                        }
                    }
                }

                // Notice that we are returning HpFlat even if the original modifier was HpMult.
                // Because there was some additional modifer applied to damage (if any)
                return(new Change
                {
                    Parameter = ModificationParameter.HpFlat,
                    Amount = delta
                });
            }

            switch (parameter)
            {
            case ModificationParameter.CritChanceFlat:
            case ModificationParameter.EvasionChanceFlat:
                return(new Change
                {
                    Parameter = parameter,
                    Amount = 1 - amount
                });
            }

            // Default change computation for stats like speed and other relatively simple stats
            return(new Change
            {
                Parameter = parameter,
                Amount = amount
            });
        }