using System.Collections.Generic;
using System.Linq;
using Cute;
using Wizard.Battle.Touch;
using Wizard.Battle.View.Vfx;

public class WatchInPlayAction : InPlayCardReflection
{
	private const float DELAY_BEFORE_START_SKILL_TARGET_SELECT = 0.5f;

	private const float WAIT_TIME_BETWEEN_SELECT_AND_EVOLUTION = 0.25f;

	private const float WAIT_TIME_BETWEEN_CHOICE_AND_EVOLUTION = 0.5f;

	public WatchInPlayAction(BattleManagerBase battleMgr, OperateMgr operateMgr)
		: base(battleMgr, operateMgr)
	{
	}

	protected override VfxBase CreateEvolveVfx(BattleCardBase evolvedCard, List<BattleCardBase> targetCards, bool isPlayer, List<int> choiceId, bool isChoice)
	{
		if (((targetCards != null && targetCards.Any()) || (choiceId != null && choiceId.Any())) && (isPlayer || GameMgr.GetIns().IsAdmin))
		{
			return NullVfx.GetInstance();
		}
		return base.CreateEvolveVfx(evolvedCard, targetCards, isPlayer, choiceId, isChoice);
	}

	public override void StartSelect(int actingCardIndex, bool isPlayer = true)
	{
		SequentialVfxPlayer sequentialVfxPlayer = SequentialVfxPlayer.Create();
		BattleCardBase indexToCardBase = NetworkBattleGenericTool.GetIndexToCardBase(_battleMgr, _battleMgr.GetBattlePlayer(isPlayer), actingCardIndex);
		sequentialVfxPlayer.Register(CreateStartSelectVfx(indexToCardBase, isEvolve: true));
		_battleMgr.VfxMgr.RegisterSequentialVfx(sequentialVfxPlayer);
	}

	public override void StartChoiceSelect(int actingCardIndex, bool isPlayer = true)
	{
		SequentialVfxPlayer sequentialVfxPlayer = SequentialVfxPlayer.Create();
		BattleCardBase indexToCardBase = NetworkBattleGenericTool.GetIndexToCardBase(_battleMgr, _battleMgr.GetBattlePlayer(isPlayer), actingCardIndex);
		SkillBase choiceSkill = GetSelectSkills(indexToCardBase, isEvolve: true).FirstOrDefault();
		sequentialVfxPlayer.Register(new StartEvolutionTargetFocusVfx(indexToCardBase.BattleCardView.GameObject));
		sequentialVfxPlayer.Register(CreateStartChoiceSelectVfx(indexToCardBase, choiceSkill, isEvolve: true, null));
		_battleMgr.VfxMgr.RegisterSequentialVfx(sequentialVfxPlayer);
	}

	public override void StartSelectFusion(int actingCardIndex, bool isPlayer = true)
	{
		SequentialVfxPlayer sequentialVfxPlayer = SequentialVfxPlayer.Create();
		BattleCardBase indexToCardBase = NetworkBattleGenericTool.GetIndexToCardBase(_battleMgr, _battleMgr.GetBattlePlayer(isPlayer), actingCardIndex);
		sequentialVfxPlayer.Register(new StartEvolutionTargetFocusVfx(indexToCardBase.BattleCardView.GameObject));
		sequentialVfxPlayer.Register(CreateStartFusionSelectVfx(indexToCardBase));
		_battleMgr.VfxMgr.RegisterSequentialVfx(sequentialVfxPlayer);
	}

	public override void CancelSelect(bool isPlayer = true)
	{
		if (_actingCard != null)
		{
			base.CancelSelect(isPlayer);
			_battleMgr.VfxMgr.RegisterImmediateVfx(CreateStopEvolutionTargetFocusVfx(_actingCard));
		}
	}

	public override void CancelChoiceSelect(bool isPlayer = true)
	{
		if (_actingChoiceCard != null)
		{
			ChoiceUtility.StopChoiceEffects(_choiceCards);
			ChoiceUtility.PlayCancelEvolveChoiceAnimation(_choiceCards, _battleMgr);
			base.CancelChoiceSelect(isPlayer);
			_battleMgr.VfxMgr.RegisterImmediateVfx(CreateStopEvolutionTargetFocusVfx(_actingChoiceCard));
		}
	}

	protected override VfxBase CreateAfterSelectVfx(BattleCardBase actingCard, List<int> selectedChoiceCardIds, bool isPlayer = true, bool isChoiceBrave = false)
	{
		float waitTime = (selectedChoiceCardIds.IsNotNullOrEmpty() ? 0.5f : 0.25f);
		return SequentialVfxPlayer.Create(WaitVfx.Create(waitTime), ParallelVfxPlayer.Create(_operateMgr.EvolutionCard(actingCard, isPlayer, _selectedCards, selectedChoiceCardIds), CreateStopEvolutionTargetFocusVfx(actingCard)));
	}

	private VfxBase CreateStopEvolutionTargetFocusVfx(BattleCardBase actingCard)
	{
		return new StopEvolutionTargetFocasVfx(actingCard.BattleCardView.GameObject);
	}
}
