/// <summary> /// Applies the elemental effects of a players skill to the target. /// </summary> /// <param name="target">The target.</param> /// <param name="player">The player.</param> /// <param name="skillEntry">The skill entry.</param> public static void ApplyElementalEffects(this IAttackable target, Player player, SkillEntry skillEntry) { var modifier = skillEntry.Skill.ElementalModifierTarget; if (modifier == null) { return; } var resistance = target.Attributes[modifier]; if (resistance >= 1.0f) { return; } if (Rand.NextRandomBool(1.0f - resistance)) { // power-up is the wrong term here... it's more like a power-down ;-) if (skillEntry.Skill.MagicEffectDef != null) { target.ApplyMagicEffect(player, skillEntry); } if (modifier == Stats.LightningResistance) { target.MoveRandomly(); } } }
/// <summary> /// Applies the elemental effects of a players skill to the target. /// </summary> /// <param name="target">The target.</param> /// <param name="player">The player.</param> /// <param name="skillEntry">The skill entry.</param> /// <returns>The success of the appliance.</returns> public static bool TryApplyElementalEffects(this IAttackable target, Player player, SkillEntry skillEntry) { skillEntry.ThrowNotInitializedProperty(skillEntry.Skill is null, nameof(skillEntry.Skill)); var modifier = skillEntry.Skill.ElementalModifierTarget; if (modifier is null) { return(false); } var resistance = target.Attributes[modifier]; if (resistance >= 1.0f || !Rand.NextRandomBool(1.0f - resistance)) { return(false); } var applied = false; if (skillEntry.Skill.MagicEffectDef is { } effectDefinition && !target.MagicEffectList.ActiveEffects.ContainsKey(effectDefinition.Number)) { // power-up is the wrong term here... it's more like a power-down ;-) target.ApplyMagicEffect(player, skillEntry); applied = true; } if (modifier == Stats.LightningResistance) { target.MoveRandomly(); applied = true; } return(applied); }