using LitJson;

namespace Wizard.Scripts.Network.Data.TaskData.ItemPurchase;

public class ItemPurchaseInfoTask : BaseTask
{
	public ItemPurchaseInfoTask()
	{
		base.type = ApiType.Type.ItemPurchaseInfo;
	}

	protected override int Parse()
	{
		int num = base.Parse();
		if (num != 1)
		{
			return num;
		}
		Wizard.Data.ItemPurchaseInfo.itemPurchaseList.Clear();
		JsonData jsonData = base.ResponseData["data"]["item_purchase_info"];
		for (int i = 0; i < jsonData.Count; i++)
		{
			ItemPurchaseData itemData = new ItemPurchaseData();
			itemData.purchase_id = jsonData[i]["purchase_id"].ToInt();
			itemData.purchase_item_type = (UserGoods.Type)jsonData[i]["purchase_item_type"].ToInt();
			itemData.PurchaseUserGoodsId = jsonData[i]["purchase_item_id"].ToLong();
			itemData.purchase_item_num = jsonData[i]["purchase_item_num"].ToInt();
			itemData.purchase_name = jsonData[i]["purchase_name"].ToString();
			if (string.IsNullOrEmpty(itemData.purchase_name))
			{
				string userGoodsName = UserGoods.getUserGoodsName(itemData.purchase_item_type, itemData.PurchaseUserGoodsId);
				itemData.purchase_name = Wizard.Data.SystemText.Get("Shop_0132", userGoodsName.ToString(), itemData.purchase_item_num.ToString());
			}
			itemData.require_item_type = (UserGoods.Type)jsonData[i]["require_item_type"].ToInt();
			itemData.RequireUserGoodsId = jsonData[i]["require_item_id"].ToLong();
			itemData.require_item_num = jsonData[i]["require_item_num"].ToInt();
			itemData.isMonthryReset = ((jsonData[i]["is_monthly_reset"].ToInt() != 0) ? true : false);
			itemData.rest = jsonData[i]["rest"].ToInt();
			if (itemData.purchase_item_type == UserGoods.Type.Item)
			{
				itemData.textureName = Wizard.Data.Master.ItemList.Find((Item data) => data.UserGoodsId == itemData.PurchaseUserGoodsId).thumbnail;
			}
			else
			{
				itemData.textureName = UserGoods.GetUserGoodsImageName(itemData.purchase_item_type, itemData.PurchaseUserGoodsId);
			}
			Wizard.Data.ItemPurchaseInfo.itemPurchaseList.Add(itemData);
		}
		JsonData jsonData2 = base.ResponseData["data"]["user_card_pack_ticket_list"];
		for (int num2 = 0; num2 < jsonData2.Count; num2++)
		{
			PlayerStaticData.UpdateItemNum(jsonData2[num2]["item_id"].ToInt(), jsonData2[num2]["number"].ToInt());
		}
		return num;
	}
}
