using System;
using LitJson;

namespace Wizard;

public class RankBattleFinishTask : FinishTaskBase
{
	public class RankBattleFinishParam : BattleFinishParam
	{
	}

	public RankBattleFinishTask()
	{
		if (GameMgr.GetIns().IsAINetwork)
		{
			base.type = ((Data.CurrentFormat == Format.Rotation) ? ApiType.Type.AIRotationRankBattleFinish : ApiType.Type.AIUnlimitedRankBattleFinish);
		}
		else
		{
			switch (Data.CurrentFormat)
			{
			case Format.Rotation:
				base.type = ApiType.Type.RankMatchFinishRotation;
				break;
			case Format.Unlimited:
				base.type = ApiType.Type.RankMatchFinishUnlimited;
				break;
			case Format.Crossover:
				base.type = ApiType.Type.RankMatchFinishCrossover;
				break;
			default:
				Debug.LogError("UnknownFormat:" + Data.CurrentFormat);
				break;
			}
		}
		Data.RankMatchFinish.data = new RankMatchFinishDetail();
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (IsEffectiveErrorCode(num))
		{
			return num;
		}
		Data.RankMatchFinish.data = new RankMatchFinishDetail();
		if (!IsResponseDataExist(base.ResponseData))
		{
			return num;
		}
		RankMatchFinishDetail data = Data.RankMatchFinish.data;
		data.class_chara_experience = 0;
		data.class_chara_level = 0;
		Data.Load.data._userRank[(int)Data.CurrentFormat].user_promotion_match = new UserPromotionMatch();
		new BattleFinishResponsProcessing().Processing(base.ResponseData, Data.RankMatchFinish.data);
		JsonData jsonData = base.ResponseData["data"];
		data.UserRank = jsonData.GetValueOrDefault("rank", 0);
		data.AfterBattlePoint = jsonData.GetValueOrDefault("after_battle_point", 0);
		data.AfterMasterPoint = jsonData.GetValueOrDefault("after_master_point", 0);
		data.BasicBattlePoint_and_SuperiorBonus = jsonData.GetValueOrDefault("battle_point", 0);
		data.BasicMasterPoint_and_SuperiorBonus = jsonData.GetValueOrDefault("master_point", 0);
		data.SuccessiveWinNumber = jsonData.GetValueOrDefault("successive_win_number", 0);
		data.SuccessiveWinBonus = jsonData.GetValueOrDefault("successive_win_bonus", 0);
		if (jsonData.Keys.Contains("upgrade_treasure_box_info"))
		{
			data.TreasureBoxCpResultInfo.Parse(jsonData["upgrade_treasure_box_info"]);
		}
		if (jsonData.TryGetValue("speed_challenge_schedule", out var value) && value.TryGetValue("announce_time", out var value2))
		{
			data.SpeedChallengeAnnounceTime = DateTime.Parse(value2.ToString());
		}
		int num2 = PlayerStaticData.UserRankCurrentFormat();
		if (num2 != data.UserRank)
		{
			PlayerStaticData.ReLoadUserRankTexture(num2.ToString("00"), data.UserRank.ToString("00"), Data.CurrentFormat);
		}
		ClassCharaPrm classPrm = GameMgr.GetIns().GetDataMgr().GetClassPrm(classId);
		classPrm.AddClassCharaBattleCount();
		if (data.battleResult == BattleManagerBase.BATTLE_RESULT_TYPE.WIN)
		{
			classPrm.AddClassCharaWin();
		}
		return num;
	}

	protected override BattleFinishParam CreateBattleFinishParam(int class_id, int total_turn, int evolve_count, int enemy_evolve_count, int battle_result, int is_retire)
	{
		BattleFinishParam battleFinishParam = base.CreateBattleFinishParam(class_id, total_turn, evolve_count, enemy_evolve_count, battle_result, is_retire);
		battleFinishParam.SDTRB = (int)PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.SELF_DISCONNECT_OPEN_STATUS_TO_REPLACE_LOG);
		return battleFinishParam;
	}
}
