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

namespace Wizard.Battle.Player.Emotion;

public abstract class EmotionBase : IEmotion
{
	public const float DEFAULT_HIDE_TEXT_TIME = 1.5f;

	public const float ICON_HIDE_DURATION_TIME = 0.3f;

	public const float ICON_HIDE_DELAY_TIME = 1.2f;

	protected readonly string _emotionId;

	protected readonly IClassCharacter _classCharacter;

	public Vector3 LeaderPosition
	{
		get
		{
			if (_classCharacter.GameObject == null)
			{
				return Vector3.zero;
			}
			return _classCharacter.GameObject.transform.position;
		}
	}

	public bool Enable { get; set; }

	public event Func<ClassCharaPrm.EmotionType, VfxBase> OnPlay;

	protected EmotionBase(string emotionId, IClassCharacter classCharacter)
	{
		Enable = true;
		_emotionId = emotionId;
		_classCharacter = classCharacter;
	}

	public VfxBase PlayEmotion(ClassCharaPrm.EmotionType emoteType, float hideTextTime)
	{
		if (!Enable)
		{
			return NullVfx.GetInstance();
		}
		Dictionary<ClassCharaPrm.EmotionType, Wizard.Emotion> emotionDataBySkinId = GameMgr.GetIns().GetDataMgr().GetEmotionDataBySkinId(_emotionId);
		if (emotionDataBySkinId.ContainsKey(emoteType))
		{
			BattleManagerBase.GetIns().GetBattlePlayer(this is PlayerEmotion).CallOnEmotion(emoteType);
			return ParallelVfxPlayer.Create(this.OnPlay.GetAllFuncVfxResults(emoteType), PlayEmotion(emotionDataBySkinId[emoteType], hideTextTime));
		}
		return NullVfx.GetInstance();
	}

	public VfxBase PlayEmotion(Wizard.Emotion emotionInfo, float hideTextTime)
	{
		bool flag = false;
		ClassCharaPrm.EmotionType emotion_id = (ClassCharaPrm.EmotionType)emotionInfo.emotion_id;
		if ((uint)(emotion_id - 15) <= 4u || emotion_id == ClassCharaPrm.EmotionType.STORY_LOSE)
		{
			flag = true;
		}
		string voiceId = emotionInfo.GetVoiceId(IsSkinEvolved());
		string text = emotionInfo.GetText(IsSkinEvolved());
		if (flag)
		{
			return PlayEmotion(emotionInfo.motion_id, emotionInfo.face_id, voiceId, text, hideTextTime, flag);
		}
		if (!GameMgr.GetIns().IsWatchBattle || PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.SHOW_OTHER_PLAYER_EMOTE))
		{
			return PlayEmotion(emotionInfo.motion_id, emotionInfo.face_id, voiceId, text, hideTextTime, flag);
		}
		return NullVfx.GetInstance();
	}

	public virtual VfxBase PlayEmotion(ClassCharaPrm.MotionType motionType, ClassCharaPrm.FaceType faceType, string voiceId, string text)
	{
		return PlayEmotion(motionType, faceType, voiceId, text, 1.5f);
	}

	public bool IsSkinEvolved()
	{
		bool isPlayer = this is PlayerEmotion;
		return BattleManagerBase.GetIns().GetBattlePlayer(isPlayer).IsSkinEvolved;
	}

	public virtual VfxBase PlayEmotion(ClassCharaPrm.MotionType motionType, ClassCharaPrm.FaceType faceType, string voiceId, string text, float hideTextTime, bool forcePlay = false)
	{
		if (!Enable)
		{
			return NullVfx.GetInstance();
		}
		if (IsSkinEvolved())
		{
			switch (motionType)
			{
			case ClassCharaPrm.MotionType.extra_2:
				motionType = ClassCharaPrm.MotionType.z_extra_2;
				break;
			case ClassCharaPrm.MotionType.damage:
				motionType = ClassCharaPrm.MotionType.z_damage;
				break;
			case ClassCharaPrm.MotionType.greet:
				motionType = ClassCharaPrm.MotionType.z_greet;
				break;
			case ClassCharaPrm.MotionType.idle:
				motionType = ClassCharaPrm.MotionType.z_idle;
				break;
			case ClassCharaPrm.MotionType.negative:
				motionType = ClassCharaPrm.MotionType.z_negative;
				break;
			case ClassCharaPrm.MotionType.negative_2:
				motionType = ClassCharaPrm.MotionType.z_negative_2;
				break;
			case ClassCharaPrm.MotionType.negative_2_a:
				motionType = ClassCharaPrm.MotionType.z_negative_2_a;
				break;
			case ClassCharaPrm.MotionType.positive:
				motionType = ClassCharaPrm.MotionType.z_positive;
				break;
			case ClassCharaPrm.MotionType.positive_2:
				motionType = ClassCharaPrm.MotionType.z_positive_2;
				break;
			case ClassCharaPrm.MotionType.shock:
				motionType = ClassCharaPrm.MotionType.z_shock;
				break;
			case ClassCharaPrm.MotionType.think:
				motionType = ClassCharaPrm.MotionType.z_think;
				break;
			}
		}
		if (text == "NONE")
		{
			return SequentialVfxPlayer.Create(_classCharacter.CreateLoadVoiceResource(voiceId), InstantVfx.Create(delegate
			{
				_classCharacter.PlayMotion(motionType);
				_classCharacter.ChangeFace(faceType);
			}), _classCharacter.PlayVoice(voiceId, forcePlay), WaitVfx.Create(hideTextTime));
		}
		VfxBase vfxBase = NullVfx.GetInstance();
		VfxBase vfxBase2 = NullVfx.GetInstance();
		if (text != string.Empty)
		{
			vfxBase = _classCharacter.ShowVoiceMessage(text);
			vfxBase2 = _classCharacter.HideVoiceMessage();
		}
		return SequentialVfxPlayer.Create(_classCharacter.CreateLoadVoiceResource(voiceId), InstantVfx.Create(delegate
		{
			_classCharacter.PlayMotion(motionType);
			_classCharacter.ChangeFace(faceType);
		}), _classCharacter.PlayVoice(voiceId, forcePlay), vfxBase, (hideTextTime > 0f) ? ((VfxBase)WaitVfx.Create(hideTextTime)) : ((VfxBase)new OpeningVfx.WaitVoiceEndVfx()), vfxBase2);
	}

	public virtual VfxBase ReceiveOpponentEmotion(ClassCharaPrm.EmotionType emotionType)
	{
		return NullVfx.GetInstance();
	}
}
