using LitJson;

namespace Wizard;

public class BaseRoomBattleEnterRoomTask : BaseTask
{
	public int result_reason;

	public int battlePoint;

	public int degreeId;

	public long emblemId;

	public string countryCode;

	public int rank;

	public string userName;

	public int viewerId;

	public bool isFriend;

	public string node_server_url;

	public int HighFormatRank { get; private set; }

	public bool IsOfficialUser { get; set; }

	public BattleParameter BattleParameterInstance { get; private set; }

	public bool IsEnableInviteGuild { get; private set; }

	public bool IsSameGuildMember { get; private set; }

	public bool IsJoinGuildOpponent { get; private set; }

	public bool IsJoinGuildOwn { get; private set; }

	public bool CanUseNonPossessionCard { get; set; }

	public string BattleID { get; private set; }

	public static void GetGuildResponse(JsonData response, out bool isSameGuild, out bool isOpponentJoinGuild, out bool isOwnJoinGuild)
	{
		int num = response["data"]["guild_id"].ToInt();
		int num2 = response["data"]["oppo_guild_id"].ToInt();
		isSameGuild = num > 0 && num == num2;
		isOpponentJoinGuild = num2 > 0;
		isOwnJoinGuild = num > 0;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		JsonData jsonData = base.ResponseData["data"];
		result_reason = jsonData["result_reason"].ToInt();
		if (result_reason == 0)
		{
			isFriend = jsonData["is_friend"].ToInt() == 1;
			GetGuildResponse(base.ResponseData, out var isSameGuild, out var isOpponentJoinGuild, out var isOwnJoinGuild);
			IsSameGuildMember = isSameGuild;
			IsJoinGuildOpponent = isOpponentJoinGuild;
			IsJoinGuildOwn = isOwnJoinGuild;
			JsonData jsonData2 = jsonData["oppo_info"];
			viewerId = jsonData2["oppoId"].ToInt();
			battlePoint = jsonData2["battlePoint"].ToInt();
			degreeId = jsonData2["degreeId"].ToInt();
			emblemId = jsonData2["emblemId"].ToLong();
			countryCode = jsonData2["country_code"].ToString();
			rank = jsonData2["rank"].ToInt();
			HighFormatRank = jsonData2["max_rank"].ToInt();
			userName = jsonData2["userName"].ToString();
			IsOfficialUser = jsonData2["isOfficial"].ToInt() == 1;
			BattleParameterInstance = BattleParameter.JsonToBattleParameter(jsonData);
			node_server_url = jsonData["node_server_url"].ToString();
			IsEnableInviteGuild = jsonData.GetValueOrDefault("is_invitation_user", defaultValue: false);
			CanUseNonPossessionCard = jsonData.GetValueOrDefault("is_enabled_all_card", defaultValue: false);
		}
		if (jsonData.TryGetValue("battle_id", out var value))
		{
			BattleID = value.ToString();
			Data.LastRoomBattleId = BattleID;
		}
		return num;
	}
}
