using System.Collections.Generic;
using UnityEngine;
using Wizard;
using Wizard.Battle.View.Vfx;

public class Skill_special_win : SkillBase
{
	private const int SHAKE_SCREEN_MAX_VALUE = 10;

	private const float SHAKE_CAMERA_VECTOR_VALUE = 0.02f;

	private const float SHAKE_CAMERA_TIME_COEFFICIENT = 0.05f;

	private const float SHAKE_CAMERA_TIME_OFFSET = 0.2f;

	private const string OPTION_WHEN_SPECIAL_LOSE = "when_special_lose";

	public Skill_special_win(SkillParameter skillPrm, string option)
		: base(skillPrm, option)
	{
	}

	public override VfxWithLoading Start(CallParameter parameter)
	{
		if (BattleManagerBase.IsForecast)
		{
			return NullVfxWithLoading.GetInstance();
		}
		SequentialVfxPlayer sequentialVfxPlayer = SequentialVfxPlayer.Create();
		IEnumerable<BattleCardBase> targetCards = parameter.targetCards;
		bool flag = base.OptionValue.GetString(SkillFilterCreator.ContentKeyword.invalid_ability, "_OPT_NULL_") == "when_special_lose";
		foreach (BattleCardBase targetCard in parameter.targetCards)
		{
			BattlePlayerReadOnlyInfoPair playerInfoPair = new BattlePlayerReadOnlyInfoPair(targetCard.OpponentBattlePlayer, targetCard.SelfBattlePlayer);
			SkillProcessor.ProcessInfo processInfo = targetCard.OpponentBattlePlayer.Class.Skills.CreateWhenSpecialLose(parameter.skillProcessor, playerInfoPair);
			if (processInfo != null && !flag)
			{
				parameter.skillProcessor.Register(processInfo);
				if (!BattleManagerBase.GetIns().IsRecovery)
				{
					BattleCardBase targetClass = targetCard.OpponentBattlePlayer.Class;
					sequentialVfxPlayer.Register(SkillBase.CreateSingleVfx(base.SkillPrm.resourceMgr, () => targetClass.BattleCardView.GameObject.transform.position, new List<BattleCardBase> { targetClass }, targetClass.IsPlayer, targetClass.BattleCardView, "btl_nerva_2", EffectMgr.EngineType.SHURIKEN, "se_btl_nerva_2", EffectMgr.MoveType.DIRECT_LEADER, EffectMgr.TargetType.SINGLE, 0f));
				}
			}
			else
			{
				targetCard.OpponentBattlePlayer.Class.FlagCardAsDestroyedBySkill();
				sequentialVfxPlayer.Register(targetCard.SelfBattlePlayer.BattleMgr.PlaySpecialWin(targetCard.SelfBattlePlayer));
			}
		}
		List<BattleCardBase> list = new List<BattleCardBase>();
		foreach (BattleCardBase item in targetCards)
		{
			list.Add(item.OpponentBattlePlayer.Class);
		}
		VfxWithLoading vfxWithLoading = CreateSkillEffect(base.SkillPrm.resourceMgr, list);
		VfxBase vfxBase = SequentialVfxPlayer.Create(WaitVfx.Create(base.SkillPrm.buildInfo._effectTime), InstantVfx.Create(delegate
		{
			ShakeScreen();
		}));
		SetInductionVoiceIndex(isSpecialWin: true);
		ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create(vfxWithLoading.MainVfx, CreateSkillActivationVoiceVfx(), vfxBase);
		VfxBase mainVfx = SequentialVfxPlayer.Create(parallelVfxPlayer, sequentialVfxPlayer);
		return VfxWithLoading.Create(vfxWithLoading.LoadingVfx, mainVfx);
	}

	public static void ShakeScreen(int shakeScreenMinValue = 10)
	{
		BattleManagerBase ins = BattleManagerBase.GetIns();
		float num = Mathf.Min(10, shakeScreenMinValue);
		BattleCamera camera = ins.Camera;
		ins.VfxMgr.RegisterImmediateVfx(SequentialVfxPlayer.Create(camera.ShakeCamera(Vector3.one * (num * 0.02f), num * 0.05f + 0.2f, 0f), WaitVfx.Create(num * 0.05f + 0.2f), camera.ShakeComplete()));
		ins.BackGround.StartFieldShake();
	}
}
