而這列幀在主角的動作合成圖中所處的位置為第20列,這樣,我們為每個精靈控件添加一個名為EffectiveFrame(起效幀)的屬性,當精靈動作播放到此幀時,即會啟動相應的處理:
private void Timer_Tick(object sender, EventArgs e) {
……
//如果觸動起效幀
if (FrameCounter == EffectiveFrame[(int)Action]) {
Super.DoInjure(this);
}
}
這裡的處理調用DoInjure方法進行傷害計算、輸出及值更新:
/// <summary>
/// 精靈攻擊並產生傷害及輸出
/// </summary>
/// <param name="spirit">發起攻擊精靈</param>
public static void DoInjure(QXSpirit spirit) {
//捕獲敵人精靈
QXSpirit Enemy = (spirit.Parent as Canvas).FindName(spirit.LockObject) as QXSpirit;
//產生隨機數
Random random = new Random();
//首先進行閃避判斷
if (random.Next(100) >= (spirit.VHit - Enemy.VDodge)) {
Super.ShowText(Enemy, true, true, "Avoid", "Miss", 34, Colors.SkyBlue, 2);
} else {
int Injure = 0;
if (spirit.Action == Actions.Attack) {
Injure = Convert.ToInt32(spirit.VAttackMin + random.Next((int)(spirit.VAttackMax - spirit.VAttackMin)) - Enemy.VDefense);
} else if (spirit.Action == Actions.Magic) {
Injure = Convert.ToInt32(spirit.VMagicMin + random.Next((int)(spirit.VMagicMax - spirit.VMagicMin)) - Enemy.VMagicDefense);
}
//判斷是否暴擊
if (random.Next(100) <= (spirit.VBurst - Enemy.VBlock)) {
Injure *= 2;
Super.ShowText(Enemy, true, true, "Avoid", string.Format("Burst!{0}", Injure >= 0 ? Injure.ToString() : "0"), 30, Colors.Red, 2);
} else {
Super.ShowText(Enemy, true, false, "Avoid", Injure >= 0 ? Injure.ToString() : "0", 30, Colors.Yellow, 0.5);
}
//實際產生去血效果
Enemy.VLife = Enemy.VLife < Injure ? 0 : Enemy.VLife - Injure;
}
}