using System;
using System.Collections.Generic;
using CriWare;
using Cute;
using Wizard;

public class Se
{
	public enum TYPE
	{
		NONE,
		MAX,
		BREAKCARD,
		SYS_CARD_SCROLL,
		SYS_COMMON_BUTTON,
		SYS_COMMON_CANCEL,
		SYS_COMMON_DECIDE,
		SYS_TITLE_START,
		SYS_BTN_DECIDE,
		SYS_BTN_DECIDE_TRANS,
		SYS_BTN_CANCEL,
		SYS_BTN_CANCEL_TRANS,
		SYS_SWITCH_MENU,
		SYS_MENU_CARD,
		SYS_SWITCH_MENU_CARD,
		SYS_TOGGLE_ON,
		SYS_TOGGLE_OFF,
		SYS_SLIDE_BTN,
		SYS_CARD_INFO,
		SYS_MYPAGE_EVOLVE,
		SYS_DRAG_CARD,
		SYS_DECK_CARD_MOVE_IN,
		SYS_DECK_CARD_MOVE_OUT,
		SYS_USE_RED_ETHER,
		SYS_GET_RED_ETHER,
		SYS_CARDLIST_REVERSE,
		SYS_DECK_IN,
		SYS_DECK_OUT,
		SYS_GIFT_ALL,
		SYS_DIALOG_OPEN,
		SYS_DL_CARD_APPEAR,
		SYS_CARD_INFO_SMALL,
		SYS_CARD_INFO_CANCEL,
		SYS_FEED_TEXT,
		SYS_SCROLL,
		SYS_BAR_SLIDE,
		SYS_CARD_TOUCH,
		SYS_CARD_MOVE_SINGLE_1,
		SYS_CARD_MOVE_SINGLE_2,
		SYS_CARD_MOVE_SINGLE_3,
		SYS_2PICK_SELECT,
		SYS_2PICK_BOX_OPEN,
		SYS_WINDOW_MOVE,
		SYS_ROOM_IN,
		SYS_ROOM_OUT,
		SYS_LOTTERY_BOX_TOUCH,
		SYS_BOX_OPEN_SP,
		SE_BATTLE_MIN,
		BATTLE_START_VS,
		BATTLE_START_VS_ST2,
		DRAW,
		DRAW_CARD_OPEN_LG,
		DRAW_CARD_OPEN,
		MULLIGAN_SELECT_REPLACE_CARD,
		MULLIGAN_CANCEL_REPLACE_CARD,
		MULLIGAN_DECIDE,
		MULLIGAN_CARD_RETURN,
		SET_CARD_TO_HAND,
		SYS_BREAK_CHARACTER,
		SYS_TURN_END,
		SYS_TURN_END_CONFIRM,
		SYS_BATTLE_EVOLVE,
		SYS_BATTLE_EVOLVE_DRAG,
		SYS_BATTLE_EVOLVE_CUTIN,
		SYS_BATTLE_EVOLVE_SKILL,
		SYS_SPELL_CAST,
		SYS_SUMMON_FALL,
		SYS_SUMMON_CARD_DROP,
		SYS_CAMERA_ZOOM_OUT,
		SYS_ACTUVATE_TURNEND_BUTTON,
		SYS_YOURTURN,
		SYS_SUMMON_LANDING,
		SYS_ENEMY_CARD_OPEN,
		SYS_ENEMY_SET_CARD_TO_HAND,
		SYS_ARROW_DRAG,
		SYS_ARROW_SELECT,
		SYS_DRAG_SLIDE,
		SYS_RESULT_GAUGEUP,
		SYS_RESULT_LEVELUP,
		SYS_RESULT_RANKUP,
		SYS_RESULT_WINDOW_APPER,
		SYS_RESULT_YOUWIN,
		SYS_RESULT_YOULOSE,
		SYS_RESULT_PUZZLE_RESET,
		SYS_RANK_UP_MACH_BEGIN,
		SYS_RANK_UP_MACH_WINDOW_MOVE,
		SYS_RANK_UP_MACH_WIN,
		SYS_RANK_UP_MACH_SUCCESS,
		SYS_RANK_UP_MACH_LOSE,
		SYS_RANK_UP_MACH_FAILED,
		SYS_RANK_UP_MACH_RANK_DOWN,
		SYS_RANK_UP_MACH_SUCCES_2,
		SYS_BOSS_RUSH_RESULT_APPEAR,
		SYS_BOSS_RUSH_RESULT_CLEAR,
		SYS_BOSS_RUSH_RESULT_MOVE,
		SYS_OPEN_SEQUENCE_CARD,
		SYS_CMN_CARD_DRAW_4,
		SYS_CMN_CARD_SELECT_3,
		SYS_CMN_CARD_RETURN_1,
		SYS_ATTACK_ICON_1,
		SYS_ATTACK_ICON_2,
		SYS_ATTACK_ICON_3,
		SYS_HAND_MOVE_CENTER,
		SYS_HAND_MOVE_RIGHT,
		SYS_BREAK_LEADER,
		SYS_BREAK_LEADER_ST1,
		SYS_BREAK_LEADER_ST2,
		SYS_APPEAR_MANA,
		SYS_APPEAR_LEADER,
		SYS_CMN_CLASS_DECKOUT_1,
		SYS_REPLAY_TURN_SKIPPING,
		SE_SYS_WIN_REWARD_BOX_SMALL,
		SE_SYS_WIN_REWARD_BOX_BIG,
		SYS_CMN_UI_EP_6,
		SYS_HBP_BUTTON,
		SYS_HBP_UP,
		SE_SYS_UPGRADE_TREASURE_BOX_01,
		SE_SYS_UPGRADE_TREASURE_BOX_02,
		SE_SYS_UPGRADE_TREASURE_BOX_03,
		SE_SYS_UPGRADE_TREASURE_BOX_04,
		SE_BATTLE_MAX,
		SE_BATTLE_JINGLE_MIN,
		SYS_JINGLE_WIN,
		SYS_JINGLE_LOSE,
		SE_BATTLE_JINGLE_MAX,
		SE_GACHA_MIN,
		SYS_GACHA_LEGEND,
		SYS_GACHA_EPIC,
		SYS_GACHA_RARE,
		SYS_GACHA_COMMON,
		SYS_GACHA_OPEN,
		SYS_GACHA_APPEAR,
		SYS_GACHA_MOVE,
		SYS_GACHA_CHOICE,
		SYS_GACHA_BACK,
		SYS_GACHA_RARE_LOOP,
		SYS_GACHA_EPIC_LOOP,
		SYS_GACHA_LEGEND_LOOP,
		SYS_GACHA_CARD_OUT,
		SYS_GACHA_CARD_IN,
		SE_GACHA_MAX,
		SE_PROLOGUE_MIN,
		SYS_PROLOGUE_CHAR_APPEAR,
		SYS_PROLOGUE_CHAR_APPEAR_EFFECT,
		SYS_PROLOGUE_CHAR_LEAVE,
		SE_PROLOGUE_MAX,
		SE_MAP_MIN,
		SYS_MAP_CLEAR,
		SYS_MAP_CAMERA_MOVE,
		SYS_MAP_NEW_AREA_RELEASE,
		SYS_MAP_CUTIN_TEXT,
		SE_MAP_TREE_EFFECT,
		SE_MAP_SECTION9_CHAPTER1,
		SE_MAP_SECTION9_CHAPTER2,
		SE_MAP_SECTION9_CHANGE_CHAPTER,
		SE_MAP_BACKGROUND_CHANGE_FIRST_CLEAR_604,
		SE_MAP_BACKGROUND_CHANGE_604,
		SE_MAP_BACKGROUND_CHANGE_FIRST_CLEAR_614,
		SE_MAP_CHAPTER_SELECT_FOCUS_CHANGE,
		SE_MAP_CHAPTER_SELECT_CLEAR,
		SE_MAP_CHAPTER_SELECT_CHAPTER_RELEASE,
		SE_MAP_CHAPTER_SELECT_LOCKED_CHAPTER_RELEASE,
		SE_MAP_CHAPTER_SELECT_UNLOCK,
		SE_MAP_SECTION20_CHANGE_CHAPTER1,
		SE_MAP_MAX,
		SE_LOGIN_BONUS_MIN,
		LOGIN_BONUS_STAMP_1,
		LOGIN_BONUS_STAMP_2,
		LOGIN_BONUS_STAMP_NEXT,
		SE_LOGIN_BONUS_MAX
	}

	public class BtlSmnSEPlayTimeAndSeName
	{
		public DateTime PlayTime { get; private set; }

		public string SeName { get; private set; }

		public BtlSmnSEPlayTimeAndSeName()
		{
			PlayTime = DateTime.Now;
			SeName = "NONE";
		}

		public void SetValue(DateTime playTime, string seName)
		{
			PlayTime = playTime;
			SeName = seName;
		}
	}

	private CriAtomSource m_SeAudioSource;

	private CriAtomSource m_SeAudioSourcLoop;

	private const string CATEGORY_NAME = "SE";

	public const string CUESHEETNAME_LOGINBONUS = "se_login";

	private Dictionary<TYPE, string> m_AudioData;

	private float m_volume;

	private bool m_isMuted;

	private const int BTL_SMN_SE_DUPLICATE_CHECK_MILLISECOND = 180;

	private BtlSmnSEPlayTimeAndSeName _btlSmnSEPlayTimeAndSeName;

	private BtlSmnSEPlayTimeAndSeName _sysSEPlayTimeAndSeName;

	public Se()
	{
		CriAtom.AttachDspBusSetting("DspBusSetting_0");
		m_SeAudioSource = GameMgr.GetIns().GetGameObjMgr().GetGameObj()
			.AddComponent<CriAtomSource>();
		m_SeAudioSource.loop = false;
		m_SeAudioSource.playOnStart = false;
		m_SeAudioSource.use3dPositioning = false;
		m_SeAudioSourcLoop = GameMgr.GetIns().GetGameObjMgr().GetGameObj()
			.AddComponent<CriAtomSource>();
		m_SeAudioSourcLoop.loop = true;
		m_SeAudioSourcLoop.playOnStart = false;
		m_SeAudioSourcLoop.use3dPositioning = false;
		m_SeAudioSourcLoop.player.AttachFader();
		m_SeAudioSourcLoop.player.SetFadeOutTime(150);
		m_AudioData = new Dictionary<TYPE, string>();
		_btlSmnSEPlayTimeAndSeName = new BtlSmnSEPlayTimeAndSeName();
		_sysSEPlayTimeAndSeName = new BtlSmnSEPlayTimeAndSeName();
		SetVolume(PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.SE_VOLUME));
		Mute(PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.SOUND_MUTE));
	}

	public void Load(TYPE SeType, string Path)
	{
		if (!m_AudioData.ContainsKey(SeType))
		{
			m_AudioData.Add(SeType, Path);
		}
	}

	public void UnLoad(TYPE SeType)
	{
		if (m_AudioData.ContainsKey(SeType))
		{
			m_AudioData.Remove(SeType);
		}
	}

	public void SetVolume(float Prm)
	{
		CriAtomExCategory.SetVolume("SE", Prm);
		m_volume = Prm;
	}

	public float GetVolume()
	{
		return m_volume;
	}

	public void Mute(bool isMute)
	{
		CriAtomExCategory.Mute("SE", isMute);
		m_isMuted = isMute;
	}

	public bool IsMuted()
	{
		return m_isMuted;
	}

	public void SetAisac(string cuename, string param, float num)
	{
		Toolbox.AudioManager.SetAisac(cuename, param, num);
	}

	public void SetAisac(TYPE SeType, string param, float num)
	{
		Toolbox.AudioManager.SetAisac(m_AudioData[SeType], param, num);
	}

	private void AddSeCueSheetPlay(TYPE SeType, bool isSeSysSummonLandingDuplicateCheck = false)
	{
		string acbName = "preinstall";
		if (SeType >= TYPE.SE_BATTLE_MIN && SeType <= TYPE.SE_BATTLE_MAX)
		{
			acbName = "se_battle";
		}
		else if (SeType >= TYPE.SE_BATTLE_JINGLE_MIN && SeType <= TYPE.SE_BATTLE_JINGLE_MAX)
		{
			acbName = "bgm_btl_jingle";
		}
		else if (SeType >= TYPE.SE_GACHA_MIN && SeType <= TYPE.SE_GACHA_MAX)
		{
			acbName = "se_gacha";
		}
		else if (SeType >= TYPE.SE_PROLOGUE_MIN && SeType <= TYPE.SE_PROLOGUE_MAX)
		{
			acbName = "se_st_prologue";
		}
		else if (SeType >= TYPE.SE_MAP_MIN && SeType <= TYPE.SE_MAP_MAX)
		{
			acbName = "se_st_map";
		}
		else if (SeType >= TYPE.SE_LOGIN_BONUS_MIN && SeType <= TYPE.SE_LOGIN_BONUS_MAX)
		{
			acbName = "se_login";
		}
		string text = m_AudioData[SeType];
		if (isSeSysSummonLandingDuplicateCheck && SeType == TYPE.SYS_SUMMON_LANDING)
		{
			DateTime now = DateTime.Now;
			if ((now - _sysSEPlayTimeAndSeName.PlayTime).TotalMilliseconds < 180.0 && _sysSEPlayTimeAndSeName.SeName == text)
			{
				return;
			}
			_sysSEPlayTimeAndSeName.SetValue(now, text);
		}
		Toolbox.AudioManager.PlaySeFromName(acbName, text, loop: false, 0f, 0L);
	}

	public void Play(TYPE SeType, bool isSeSysSummonLandingDuplicateCheck)
	{
		if (SeType == TYPE.NONE)
		{
			return;
		}
		try
		{
			AddSeCueSheetPlay(SeType, isSeSysSummonLandingDuplicateCheck);
		}
		catch
		{
			Debug.LogError("SE ERR " + SeType);
		}
	}

	public void PlayByStr(string SeStr, string AcbName, float fadeInTime, long startTime)
	{
		try
		{
			if (SeStr.Contains("btl") || SeStr.Contains("smn"))
			{
				DateTime now = DateTime.Now;
				if ((now - _btlSmnSEPlayTimeAndSeName.PlayTime).TotalMilliseconds < 180.0 && _btlSmnSEPlayTimeAndSeName.SeName == SeStr)
				{
					return;
				}
				_btlSmnSEPlayTimeAndSeName.SetValue(now, SeStr);
			}
			Toolbox.AudioManager.PlaySeFromName(AcbName, SeStr, loop: false, fadeInTime, startTime);
		}
		catch
		{
			Debug.LogError("SE ERR " + SeStr);
		}
	}

	public void PlayLoop(TYPE SeType)
	{
		try
		{
			AddSeCueSheetPlay(SeType);
		}
		catch
		{
			Debug.LogError("SE ERR " + SeType);
		}
	}

	public void PlayLoopByStr(string SeStr, float fadeInTime, long startTime)
	{
		try
		{
			Toolbox.AudioManager.PlaySeFromName(SeStr, SeStr, loop: true, fadeInTime, startTime);
		}
		catch
		{
			Debug.LogError("SE ERR " + SeStr);
		}
	}

	public void AisacChange(float aisacnum)
	{
		if (m_SeAudioSourcLoop.status == CriAtomSource.Status.Playing)
		{
			m_SeAudioSourcLoop.SetAisacControl("Speed", aisacnum);
		}
	}

	public void Stop(string cuename, float fadeOutTime)
	{
		Toolbox.AudioManager.StopSe(cuename, fadeOutTime);
	}

	public void Stop(TYPE setype, float fadetime = 0f)
	{
		Toolbox.AudioManager.StopSe(m_AudioData[setype], fadetime);
	}

	public void StopAll(float fadeOutTime)
	{
		Toolbox.AudioManager.StopSeAll(fadeOutTime);
	}
}
