备份CatanBuilding瘦身独立工程
This commit is contained in:
87
Assets/Scripts/UI/Shop/BlackFridayCouponData.cs
Normal file
87
Assets/Scripts/UI/Shop/BlackFridayCouponData.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
|
||||
public class BlackFridayCouponData
|
||||
{
|
||||
private readonly Tables _tables = GContext.container.Resolve<Tables>();
|
||||
private readonly TbEventCoupon _tableCoupon = GContext.container.Resolve<Tables>().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<Tables>().TbEventCoupon[RedirectId].Multiple;
|
||||
public int EventDuration => GContext.container.Resolve<Tables>().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($"<color=#23aaf2>Black Friday Activated @ {ActivateTime}</color>");
|
||||
UploadData();
|
||||
}
|
||||
|
||||
public void SetStateBought()
|
||||
{
|
||||
_isBought = true;
|
||||
UploadData();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user