/// <summary> /// Returns whether the spell can be casted (true) or if immunity of the target prevents it (false) /// </summary> public static bool CheckImmune(Unit target, Spell spell, bool hostile) { if (spell.Mechanic != SpellMechanic.None && hostile == spell.Mechanic.IsNegative() && ((spell.Mechanic == SpellMechanic.Invulnerable_2 || spell.Mechanic == SpellMechanic.Invulnerable) && !spell.Attributes.HasFlag(SpellAttributes.UnaffectedByInvulnerability) && (target.IsImmune(SpellMechanic.Invulnerable_2) || target.IsImmune(SpellMechanic.Invulnerable))) || (target.IsImmune(spell.Mechanic) || target.IsImmune(spell.DispelType))) { return false; } return true; }
/// <summary> /// Returns whether the given target is immune to the given spell /// </summary> public static bool IsImmune(Unit target, Spell spell, bool hostile) { if ( hostile && spell.Mechanic.IsNegative() && !spell.Attributes.HasFlag(SpellAttributes.UnaffectedByInvulnerability) && (spell.Mechanic == SpellMechanic.Invulnerable_2 || spell.Mechanic == SpellMechanic.Invulnerable) && ( // immune against spell target.IsInvulnerable || target.IsImmune(SpellMechanic.Invulnerable_2) || target.IsImmune(SpellMechanic.Invulnerable) || target.IsImmune(spell.Mechanic) || target.IsImmune(spell.DispelType) ) ) { return true; } return false; }
/// <summary> /// Indicates whether a spell hit a target or not /// </summary> public CastMissReason CheckCastHit(Unit target, Spell spell) { if (Caster.MayAttack(target)) { if (target.IsEvading) { return CastMissReason.Evade; } if (!spell.Attributes.Has(SpellAttributes.UnaffectedByInvulnerability) || (target is Character && ((Character)target).Role.IsStaff)) { if (target.IsInvulnerable) { return CastMissReason.Immune_2; } var immune = true; for (var i = 0; i < spell.Schools.Length; i++) { var school = spell.Schools[i]; if (!target.IsImmune(school)) { immune = false; break; } } if (immune) { return CastMissReason.Immune; } } if (target.CheckResist(CasterUnit, target.GetLeastResistant(spell), spell.Mechanic) && !spell.AttributesExB.Has(SpellAttributesExB.CannotBeResisted)) { return CastMissReason.Resist; } } return CastMissReason.None; }