using UnityEngine; using UnityEngine.UI; using GameCore; using System; using asap.core; using cfg; using System.Collections.Generic; using System.Linq; public class EventLuckyTriplePackPanel : MonoBehaviour { [SerializeField] private Button btnClose; [SerializeField] private BingoTimer timer; [SerializeField] private EventLuckyTriplePackContentView[] packViewList; private int _eventId; public void Start() { btnClose.onClick.AddListener(OnClickClose); } public void Init(EventLuckyTriplePackData data) { // var packData = EventLuckMagicAct.TableContext.GetTriplePackData(); timer.Init(data.ToTimerContext(OnClickClose)); for (int i = 0; i < packViewList.Length; i++) { var iap = data.PackDataList[i].IAPItemList; var dropId = data.PackDataList[i].DropId; packViewList[i].Init(data.PackDataList[i], () => OnClickBuy(dropId, iap)); } _eventId = data.EventId; } private async void OnClickBuy(int dropId, IAPItemList iap) { try { var shopBuyTypeData = new ShopBuyTypeData { type = ShopBuyType.EventPack, ID = _eventId }; bool res = await GContext.container.Resolve().OnBuy(dropId, shopBuyTypeData, iap, GContext.container.Resolve().GetItemDataByDropId(dropId)); if (res) { Debug.Log("[LuckTriplePack] Purchase Success."); OnClickClose(); } } catch (Exception e) { Debug.Log($"[EventLuckyPack] Purchase Error."); Debug.LogError(e); } } private void OnClickClose() { UIManager.Instance.DestroyUI(gameObject.name); } } public class EventLuckyTriplePackData { public DateTime ExpiryTime { get; set; } public DateTime StartTime { get; set; } public EventLuckyTriplePackContentData[] PackDataList { get; set; } public int EventId { get; set; } public ITimerContext ToTimerContext(Action onExpire) { return new TimerContext { ExpiryTime = ExpiryTime, StartTime = StartTime, OnExpire = onExpire }; } public static EventLuckyTriplePackData Create(int eventId, int packId) { var _tableEvent = GContext.container.Resolve().TbFishingEvent[eventId]; var res = new EventLuckyTriplePackData(); var expireTime = new DateTime(); try { expireTime = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime); } catch (Exception e) { Debug.Log($"[EventLuckMagic] {e.Message}\n{e.StackTrace}"); return null; } res.ExpiryTime = expireTime; var startTime = new DateTime(); try { startTime = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).StartTime); } catch (Exception e) { Debug.Log($"[EventLuckMagic] {e.Message}\n{e.StackTrace}"); return null; } res.ExpiryTime = expireTime; var packDataList = new List(); var playerVipLevel = GContext.container.Resolve().PriceLv; var _packData = GContext.container.Resolve().TbEventPackManager[packId]; var packIdList = playerVipLevel < _packData.VIPPackList.Count ? _packData.VIPPackList[playerVipLevel] : _packData.VIPPackList.Last(); for (int i = 0; i < packIdList.Count; i++) { var p = GContext.container.Resolve().TbPack[packIdList[i]]; var d = new EventLuckyTriplePackContentData(); d.Rewards = GContext.container.Resolve().GetItemDataByDropId(p.DropID).ToArray(); d.Discount = p.Rebate; d.IAPItemList = GContext.container.Resolve().TbIAPItemList.GetOrDefault(p.IAPID); //Debug.Log($"_iap: {_iap}"); var sdde = new SKUDetailDataEvent(d.IAPItemList); GContext.Publish(sdde); d.TextPrice = sdde.price; d.DropId = p.DropID; packDataList.Add(d); } res.PackDataList = packDataList.ToArray(); res.EventId = _tableEvent.ID; return res; } }