using System; using System.Linq; using asap.core; using cfg; public class BlackFridayCouponData { private readonly Tables _tables = GContext.container.Resolve(); private readonly TbEventCoupon _tableCoupon = GContext.container.Resolve().TbEventCoupon; public DateTime ActivateTime = new DateTime(1996, 11, 28); public int EventId { get; private set; } public int RedirectId { get; private set; } public bool IsBought => _isBought; public bool DoesPop = true; private bool _isBought = false; public TimeSpan RemainingTime { get { var eventLimit = DateTime.Parse((_tables.TbFishingEvent[EventId].TimeDefinition as LimitedTime)?.EndTime); var activeLimit = ActivateTime + TimeSpan.FromSeconds(EventDuration); var limit = eventLimit < activeLimit ? eventLimit : activeLimit; return limit - ZZTimeHelper.UtcNow(); } } public bool IsWithinEventTime { get { var now = ZZTimeHelper.UtcNow(); var fishingEvent = _tables.TbFishingEvent[EventId]; return now >= DateTime.Parse((fishingEvent.TimeDefinition as LimitedTime)?.StartTime) && now < DateTime.Parse((fishingEvent.TimeDefinition as LimitedTime)?.EndTime); } } public const string PlayFabDataKey = "BlackFridayCouponDate"; public bool IsActive => _tables.TbFishingEvent.DataMap.ContainsKey(EventId) && _tableCoupon.DataMap.ContainsKey(RedirectId) && IsWithinEventTime && ZZTimeHelper.UtcNow() <= ActivateTime + TimeSpan.FromSeconds(EventDuration) && !IsBought; public int Multiplier => GContext.container.Resolve().TbEventCoupon[RedirectId].Multiple; public int EventDuration => GContext.container.Resolve().TbEventCoupon[RedirectId].Time; public void LoadData(string s) { int[] tokens = s.Split(',').Select(int.Parse).ToArray(); ActivateTime = new DateTime(tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]); EventId = tokens[6]; if (tokens.Length < 9) { _isBought = false; RedirectId = 0; } else { RedirectId = tokens[7]; _isBought = tokens[8] == 1; } // BlackFridayCouponPopupPanel.DebugWithColor("Debug Activated."); // EventId = 0; } public void UploadData() { string s = $"{ActivateTime.Year},{ActivateTime.Month},{ActivateTime.Day},{ActivateTime.Hour},{ActivateTime.Minute},{ActivateTime.Second},{EventId},{RedirectId},{(IsBought ? 1 : 0)}"; PlayFabMgr.Instance.UpdateUserDataValue(PlayFabDataKey, s); } public void UpdateData(FishingEvent e) { if (e.Type != 3 || e.SubType != 9 || e.ID == EventId) return ; EventId = e.ID; RedirectId = e.RedirectID; ActivateTime = ZZTimeHelper.UtcNow(); _isBought = false; // Debug.Log($"Black Friday Activated @ {ActivateTime}"); UploadData(); } public void SetStateBought() { _isBought = true; UploadData(); } }