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

namespace Wizard;

public class PracticeFinishTask : BaseTask
{
	public class PracticeFinishTaskParam : BaseParam
	{
		public int deck_no;

		public int is_win;

		public int evolve_count;

		public int total_turn;

		public int enemy_class_id;

		public int difficulty;

		public int deck_format;

		public int class_id;

		public Dictionary<string, int> mission;

		public string recovery_data;

		public string[] prosessing_time_data;
	}

	public PracticeFinishTask()
	{
		base.type = ApiType.Type.PracticeFinish;
	}

	public void SetParameter(int deck_no, int is_win, int evolve_count, int total_turn, int enemy_class_id, int difficulty, Format format, int class_id)
	{
		BattleManagerBase ins = BattleManagerBase.GetIns();
		DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
		PracticeFinishTaskParam practiceFinishTaskParam = new PracticeFinishTaskParam
		{
			deck_no = deck_no,
			is_win = is_win,
			evolve_count = evolve_count,
			total_turn = total_turn,
			enemy_class_id = enemy_class_id,
			difficulty = difficulty,
			deck_format = Data.FormatConvertApi(format),
			class_id = class_id
		};
		if (dataMgr.RecoveryData == null)
		{
			dataMgr.SetRecoveryData(RecoveryOperationInfo.ReadRecoveryFile(OperationRecorderBase.RecordDirectoryPath + "recovery_single.json"));
		}
		practiceFinishTaskParam.recovery_data = dataMgr.RecoveryData.ToJson();
		BattlePlayerPair battlePlayerPair = ins.GetBattlePlayerPair(isPlayer: true);
		BattleCardBase selfClass = ins.GetBattlePlayer(isPlayer: true).Class;
		practiceFinishTaskParam.mission = dataMgr.MissionNecessaryInformation.GetMissionNecessaryInfo(battlePlayerPair, selfClass);
		base.Params = practiceFinishTaskParam;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			DeleteRecoveryFileIfBattleAlreadyEnded(num);
			return num;
		}
		Data.PracticeFinish.data = new PracticeFinishDetail();
		Data.PracticeFinish.data._responseData = base.ResponseData;
		Data.PracticeFinish.data.class_chara_experience = 0;
		Data.PracticeFinish.data.class_chara_level = 0;
		Data.PracticeFinish.data.get_class_chara_experience = base.ResponseData["data"]["get_class_experience"].ToInt();
		Data.PracticeFinish.data.class_chara_experience = base.ResponseData["data"]["class_experience"].ToInt();
		Data.PracticeFinish.data.class_chara_level = base.ResponseData["data"]["class_level"].ToInt();
		JsonData jsonData = base.ResponseData["data"]["achieved_info"];
		if (jsonData.GetJsonType() == JsonType.Object)
		{
			Data.PracticeFinish.data.AchievedInfo.Read(jsonData);
		}
		PlayerStaticData.UpdateHaveUserGoodsNumByJsonData(base.ResponseData["data"]["reward_list"]);
		return num;
	}
}
