コード例 #1
0
ファイル: Unit.Combat.cs プロジェクト: WCellFR/WCellFR
		/// <summary>
		/// Does spell-damage to this Unit
		/// </summary>
		public void DoSpellDamage(Unit attacker, SpellEffect effect, int dmg)
		{
			DamageSchool school;
			if (effect != null)
			{
				school = GetLeastResistant(effect.Spell);
				if (effect.Spell.DamageIncreasedByAP)
				{
					int ap;
					if (effect.Spell.IsRangedAbility)
					{
						ap = TotalRangedAP;
					}
					else
					{
						ap = TotalMeleeAP;
					}

					dmg += (ap + 7) / 14;	// round
				}
			}
			else
			{
				school = DamageSchool.Physical;
			}

			if (IsEvading || IsImmune(school) || IsInvulnerable || !IsAlive)
			{
				return;
			}

			var action = attacker != null ? attacker.m_DamageAction : m_DamageAction;
			if (action == null || action.IsInUse)
			{
				// currently in use
				action = new DamageAction(attacker);
			}
			else
			{
				action.Attacker = attacker;
				action.HitFlags = 0;
				action.VictimState = 0;
				action.Weapon = null;
			}

			if (effect != null)
			{
				action.UsedSchool = school;
				action.Schools = effect.Spell.SchoolMask;
				action.IsDot = effect.IsPeriodic;
			}
			else
			{
				action.UsedSchool = DamageSchool.Physical;
				action.Schools = DamageSchoolMask.Physical;
				action.IsDot = false;
			}

			action.Damage = dmg;
			action.ResistPct = GetResistChancePct(this, action.UsedSchool);

			action.Victim = this;

			if (attacker != null)
			{
				attacker.AddDamageMods(action);

				if (effect != null && !action.IsDot && !effect.Spell.AttributesExB.HasFlag(SpellAttributesExB.CannotCrit) &&
					attacker.CalcSpellCritChance(this, action.UsedSchool, action.ResistPct, effect.Spell) > Utility.Random(0f, 100f))
				{
					action.Damage = attacker.CalcCritDamage(action.ActualDamage, this, effect).RoundInt();
					action.IsCritical = true;
				}
				else
				{
					action.IsCritical = false;
				}
			}


			action.Absorbed = Absorb(action.UsedSchool, action.Damage);
			action.Resisted = (int)Math.Round(action.Damage * action.ResistPct / 100);
			action.Blocked = 0; // TODO: Deflect
			action.SpellEffect = effect;

			//TODO: figure this out: However, when spells do only damage, it's not just a full hit or full miss situation. Pure damage spells can be resisted for 0%, 25%, 50%, 75%, or 100% of their regular damage. 

			DoRawDamage(action);
			CombatLogHandler.SendMagicDamage(action);
			action.OnFinished();
			//Your average resistance can still be anywhere betweeen 0% and 75%. If your average resistance is maxed out, then there's a really good chance of having 75% of the spell's damage be resisted. 
			//There's also a fairly good chance of having 100% of the spell's damage be resisted, a slightly lower chance of 50% of its damage being resisted, a small chances of only 25%, or even 0% of the damage being resisted. 
			//It's a weighted average. Visualize it as a bell curve around your average resistance.
		}