using System.Collections.Generic;
using LitJson;
using Wizard.Battle.Recovery;

namespace Wizard;

public class BossRushHiddenBattleFinishTask : BaseTask
{
	public class BossRushHiddenBattleFinishTaskParam : BaseParam
	{
		public bool is_win;

		public int deck_no;

		public int deck_format;

		public int class_id;

		public int enemy_class_id;

		public int total_turn;

		public int turn_state;

		public int evolve_count;

		public Dictionary<string, int> mission;

		public string recovery_data;

		public string[] prosessing_time_data;

		public bool is_prebuild_deck;

		public bool is_trial_deck;

		public int challenge_count_num;
	}

	public BossRushHiddenBattleFinishTask()
	{
		base.type = ApiType.Type.BossRushHiddenBattleFinish;
	}

	public void SetParameter(int quest_stage_id, int deck_no, bool is_win, Format format, bool isPreBuildDeck, bool isTrialDeck, bool isFirst, int totalTurn)
	{
		BattleManagerBase ins = BattleManagerBase.GetIns();
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		BossRushHiddenBattleFinishTaskParam bossRushHiddenBattleFinishTaskParam = new BossRushHiddenBattleFinishTaskParam();
		bossRushHiddenBattleFinishTaskParam.is_win = is_win;
		bossRushHiddenBattleFinishTaskParam.deck_no = deck_no;
		bossRushHiddenBattleFinishTaskParam.deck_format = Data.FormatConvertApi(format);
		bossRushHiddenBattleFinishTaskParam.class_id = dataMgr.GetPlayerClassId();
		bossRushHiddenBattleFinishTaskParam.enemy_class_id = dataMgr.GetEnemyClassId();
		bossRushHiddenBattleFinishTaskParam.total_turn = totalTurn;
		bossRushHiddenBattleFinishTaskParam.turn_state = ((!isFirst) ? 1 : 0);
		bossRushHiddenBattleFinishTaskParam.evolve_count = ins.BattlePlayer._cumulativeEvolutionCount;
		bossRushHiddenBattleFinishTaskParam.is_prebuild_deck = isPreBuildDeck;
		bossRushHiddenBattleFinishTaskParam.is_trial_deck = isTrialDeck;
		bossRushHiddenBattleFinishTaskParam.challenge_count_num = deck_no;
		BattlePlayerPair battlePlayerPair = ins.GetBattlePlayerPair(isPlayer: true);
		BattleCardBase selfClass = ins.GetBattlePlayer(isPlayer: true).Class;
		if (dataMgr.RecoveryData == null)
		{
			dataMgr.SetRecoveryData(RecoveryOperationInfo.ReadRecoveryFile(OperationRecorderBase.RecordDirectoryPath + "recovery_single.json"));
		}
		bossRushHiddenBattleFinishTaskParam.recovery_data = dataMgr.RecoveryData.ToJson();
		bossRushHiddenBattleFinishTaskParam.mission = dataMgr.MissionNecessaryInformation.GetMissionNecessaryInfo(battlePlayerPair, selfClass);
		base.Params = bossRushHiddenBattleFinishTaskParam;
	}

	protected override int Parse()
	{
		GameMgr.GetIns().GetDataMgr().ClearSpecialBattleSettingInfo();
		int num = base.Parse();
		if (num != 1)
		{
			DeleteRecoveryFileIfBattleAlreadyEnded(num);
			return num;
		}
		Data.QuestFinish.data = new QuestFinishDetail();
		Data.QuestFinish.data._responseData = base.ResponseData;
		JsonData jsonData = base.ResponseData["data"];
		Data.QuestFinish.data.get_class_chara_experience = jsonData["get_class_experience"].ToInt();
		Data.QuestFinish.data.class_chara_experience = jsonData["class_experience"].ToInt();
		Data.QuestFinish.data.class_chara_level = jsonData["class_level"].ToInt();
		Data.QuestFinish.data.CurrentPoint = (jsonData.Keys.Contains("current_point") ? jsonData["current_point"].ToInt() : 0);
		Data.QuestFinish.data.AddPoint = (jsonData.Keys.Contains("add_point") ? jsonData["add_point"].ToInt() : 0);
		Data.QuestFinish.data.CommonMissionClearInfoList = new List<QuestFinishDetail.MissionClearInfo>();
		if (jsonData.Keys.Contains("clear_mission_list") && jsonData["clear_mission_list"].Keys.Contains("common_mission"))
		{
			JsonData jsonData2 = jsonData["clear_mission_list"]["common_mission"];
			for (int i = 0; i < jsonData2.Count; i++)
			{
				Data.QuestFinish.data.CommonMissionClearInfoList.Add(new QuestFinishDetail.MissionClearInfo(jsonData2[i]["name"].ToString(), jsonData2[i]["point"].ToInt()));
			}
		}
		Data.QuestFinish.data.CharacterMissionClearInfoList = new List<QuestFinishDetail.MissionClearInfo>();
		if (jsonData.Keys.Contains("clear_mission_list") && jsonData["clear_mission_list"].Keys.Contains("character_mission"))
		{
			JsonData jsonData3 = jsonData["clear_mission_list"]["character_mission"];
			for (int j = 0; j < jsonData3.Count; j++)
			{
				Data.QuestFinish.data.CharacterMissionClearInfoList.Add(new QuestFinishDetail.MissionClearInfo(jsonData3[j]["name"].ToString(), jsonData3[j]["point"].ToInt()));
			}
		}
		Data.QuestFinish.data.AddPoint = Data.QuestFinish.data.AddPoint - Data.QuestFinish.data.GetTotalCommonMissionClearPoint() - Data.QuestFinish.data.GetTotalCharacterMissionClearPoint();
		Data.QuestFinish.data.NecessaryPointList = new List<int>();
		if (jsonData.Keys.Contains("point_reward_list"))
		{
			int num2 = 0;
			for (int k = 0; k < jsonData["point_reward_list"].Count; k++)
			{
				int num3 = jsonData["point_reward_list"][k]["point"].ToInt();
				Data.QuestFinish.data.NecessaryPointList.Add(num3 - num2);
				num2 = num3;
			}
		}
		Data.QuestFinish.data.NecessaryPointList.Add(-1);
		JsonData data = jsonData["achieved_info"];
		Data.QuestFinish.data.AchievedInfo.Read(data);
		Data.QuestFinish.data.HomeDialogData = new MyPageHomeDialogData(jsonData, "battle_dialog_list");
		PlayerStaticData.UpdateHaveUserGoodsNumByJsonData(jsonData["reward_list"]);
		if (jsonData.Keys.Contains("hidden_boss_reward_list"))
		{
			_ = jsonData["hidden_boss_reward_list"];
		}
		return num;
	}
}
