コード例 #1
0
ファイル: SpellCast.cs プロジェクト: MeaNone/WCell
		/// <summary>
		/// Indicates whether a spell hit a target or not
		/// TODO: Actually check whether a spell 'Misses' (CastMissReason.Miss)
		/// </summary>
		public CastMissReason CheckCastHit(Unit target, Spell spell)
		{
			if (CasterObject != null && CasterObject.MayAttack(target))
			{
				var school = target.GetLeastResistantSchool(spell);
				// evasion
				if (target.IsEvading)
				{
					return CastMissReason.Evade;
				}
				// immune & invul
				if (!spell.Attributes.HasFlag(SpellAttributes.UnaffectedByInvulnerability) ||
					(target is Character && ((Character)target).Role.IsStaff))
				{
					if (target.IsInvulnerable)
					{
						return CastMissReason.Immune_2;
					}

					if (spell.Schools.All(target.IsImmune))
					{
						return CastMissReason.Immune;
					}
				}

				//// avoid/miss
				//var avoidance = target.GetSpellAvoidancePct(school);
				//if (avoidance > 0 && Utility.Random(1, 101) < avoidance)
				//{
				//    return CastMissReason.Miss;
				//}


				// resist
				if (target.CheckResist(CasterUnit, school, spell.Mechanic) && !spell.AttributesExB.HasFlag(SpellAttributesExB.CannotBeResisted))
				{
					return CastMissReason.Resist;
				}
			}

			return CastMissReason.None;
		}
コード例 #2
0
ファイル: SpellCast.cs プロジェクト: pallmall/WCell
		/// <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;
		}