using System.Collections.Generic;
using System.Linq;
using Continentis.MainGame;
using Continentis.MainGame.Card;
using Continentis.MainGame.Character;
using Continentis.MainGame.Combat;
using Continentis.MainGame.Commands;
using SLSFramework.General;
using UnityEngine;
namespace Continentis.Mods.Basic.Cards
{
///
/// 命令术:对目标执行一次感知检定:
/// 对敌人:若感知低于{PerceptionThreshold_Remove},随机移除一个意图;若低于{PerceptionThreshold_Change},随机改变一个意图
/// 对玩家英雄:若感知检定未通过,将一张"扼制"卡牌放入目标的抽牌堆
///
public class Command : CardLogicBase
{
private static readonly Color HintGreen = new Color(0.2f, 0.85f, 0.3f);
private static readonly Color HintRed = new Color(0.9f, 0.2f, 0.2f);
public override void Initialize(CardInstance cardInstance)
{
base.Initialize(cardInstance);
// 战场角色变化时刷新 hintShadow,托管机制自动取消订阅
CombatEventCollection events = CombatMainManager.Instance.eventCollection;
SubscribeCombatEvent(events.onCharacterDeath, new PrioritizedAction(_ => InvalidateHint()));
SubscribeCombatEvent(events.onCharacterJoin, new PrioritizedAction(_ => InvalidateHint()));
}
/// 抽到此牌时刷新 hintShadow。
protected override void OnDraw() => InvalidateHint();
public override CommandGroup PlayEffect(List targetList)
{
return ForEachTarget(targetList, target => Cmd.Parallel(
new Cmd_PlayAnimation(user.characterView, "Action"),
Cmd.Do(() =>
{
if (target is PlayerHero)
PlayEffectOnPlayer(target);
else
PlayEffectOnEnemy(target);
})
));
}
///
/// 检查场上是否存在感知低于阈值的可用目标。
/// 有可用目标时返回绿色,无可用目标时返回红色。
///
public override Color? GetHintColor()
{
if (user == null || card.handCardView == null) return null;
card.DetectTargetsValidity(out List valid, out _, out _);
if (valid.Count == 0) return HintRed;
int changeThreshold = GetAttribute("Perception_Threshold_High");
bool hasEffectiveTarget = valid.Any(t =>
t.GetAttribute(CharacterAttributes.Perception) < changeThreshold);
return hasEffectiveTarget ? HintGreen : HintRed;
}
/// 对敌方目标:根据感知检定移除或改变意图。
private void PlayEffectOnEnemy(CharacterBase target)
{
int removeThreshold = GetAttribute("Perception_Threshold_Low");
int changeThreshold = GetAttribute("Perception_Threshold_High");
int perception = target.GetAttribute(CharacterAttributes.Perception);
if (perception < removeThreshold)
target.intentionSubmodule.RemoveRandomIntendedCard();
else if (perception < changeThreshold)
target.intentionSubmodule.ChangeRandomIntendedCard();
}
/// 对玩家英雄:感知检定未通过时,向目标抽牌堆塞入一张"扼制"卡牌。
private void PlayEffectOnPlayer(CharacterBase target)
{
int stifleThreshold = GetAttribute("Perception_Threshold_Low");
int disruptionThreshold = GetAttribute("Perception_Threshold_High");
int perception = target.GetAttribute(CharacterAttributes.Perception);
if (perception < stifleThreshold)
CardInstance.GenerateCardInstance(GetDerivativeCardData(0), target, Piles.Draw);
else if (perception < disruptionThreshold)
CardInstance.GenerateCardInstance(GetDerivativeCardData(1), target, Piles.Draw);
}
}
}