using System.Collections.Generic;
using System.Linq;
using Continentis.MainGame.Card;
using Continentis.MainGame.Character;
using Continentis.MainGame.Combat;
using Continentis.MainGame.Commands;
using SLSUtilities.General;
using UnityEngine;
namespace Continentis.Mods.Basic.Cards
{
///
/// 预判:获得闪避值。
/// 若本回合内没有任何敌人在使用者之前行动,则额外获得 Bonus_Dodge 的闪避值。
///
public class Anticipation : CardLogicBase
{
private const string BONUS_DODGE = "Bonus_Dodge";
public override void SetUpLogicComponents()
{
AddLogicComponent();
}
public override CommandGroup PlayEffect(List targetList)
{
base.PlayEffect(targetList);
int baseDodge = GetAttribute("Dodge");
int finalDodge = IsBeforeAnyEnemy()
? Mathf.RoundToInt(baseDodge + GetAttribute(BONUS_DODGE))
: baseDodge;
return Cmd.Parallel(
new Cmd_PlayAnimation(user.characterView, "Skill"),
Cmd.Do(() => user.AddDodge(finalDodge))
);
}
public override void ApplyAttributeChangesByCard()
{
LogicComponent().SetDodge();
}
///
/// 判断本回合内是否没有任何敌方角色在使用者之前行动过。
///
private bool IsBeforeAnyEnemy()
{
int currentRound = CombatMainManager.Instance.currentRound;
int userActionIndex = user.recordSubmodule.currentAction;
return !CombatMainManager.Instance.characterController.characters
.Any(c => c.fraction == Fraction.Enemy
&& c.recordSubmodule.currentRound == currentRound
&& c.recordSubmodule.currentAction < userActionIndex);
}
}
}