using Convention;
using Cute;
using UnityEngine;
using Wizard.RoomMatch;

namespace Wizard;

public static class SoftwareReset
{
	private const float BGM_FADE_OUT_TIME = 1f;

	private static string _bootScene;

	private static void resetAction()
	{
		Data.Clear();
		PaymentImpl.GetInstance().finalize();
		GameObject gameObject = GameObject.Find("_GameMgr");
		if (gameObject != null)
		{
			Object.Destroy(gameObject);
		}
		GameObject gameObject2 = GameObject.Find("_Game");
		if (gameObject2 != null)
		{
			Object.Destroy(gameObject2);
		}
		BGMManager.Dispose();
		Global.GAME_FONT = null;
		Global.IS_LOAD_ALLDONE = false;
	}

	public static void setAction()
	{
		SoftwareResetBase.setSoftwareResetAction(resetAction);
	}

	public static void BgmFadeEndCallBack()
	{
		SoftwareResetBase.SoftwareReset(_bootScene, resetAction);
		_bootScene = null;
	}

	public static void exec(string sceneName = null, bool isFromUserDelete = false)
	{
		UIManager.GetInstance().isBattleRecovery = false;
		_bootScene = sceneName;
		SoundMgr soundMgr = GameMgr.GetIns().GetSoundMgr();
		soundMgr.StopBGM(BgmFadeEndCallBack, 1f);
		soundMgr.StopSeAll(0f);
		soundMgr.PlaySe(Se.TYPE.SYS_BTN_CANCEL_TRANS);
		UIManager.GetInstance().CreatFadeClose();
		VideoHostingUtil.OnSoftwareReset();
		RoomBase.OnSoftwareReset();
		Offline.OnSoftwareReset();
		SealedController.OnSoftwareReset();
		PlayerPrefsCache.OnSoftwareReset();
		if (null != GameMgr.GetIns().GetBattleCtrl())
		{
			GameMgr.GetIns().GetBattleCtrl().BattleRelease();
		}
		if (BattleManagerBase.GetIns() != null)
		{
			BattleManagerBase.GetIns().DisposeBattleGameObj();
		}
	}
}
