feat(upserver): 保存M2客户端KV迁移至本人统计写检查点
保存独立KV用户服务、固定会话存档与原业务接线,以及C3d资料缓存和C3e本人统计写。 保留原PF/AGG路线、业务公式和时序;榜单读取、好友资料、公告、匹配及首场景闸仍待完成。 验证:ServiceHost两条件各33组646断言;Unity CLI Loop编译0错误269警告。 包含相关方案、评审裁决、测试及状态文档。未操作服务器、正式账号或打包。
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
|
||||
public class BlackFridayCouponData
|
||||
{
|
||||
private game.PlayerDataStorage.IPlayerSaveStore saveStore;
|
||||
internal void BindSaveStore(game.PlayerDataStorage.IPlayerSaveStore store)
|
||||
{
|
||||
if (saveStore != null && !ReferenceEquals(saveStore, store)) throw new System.InvalidOperationException("Archive store cannot change login.");
|
||||
saveStore = store;
|
||||
}
|
||||
|
||||
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;
|
||||
internal void ResetForKVLoad()
|
||||
{ ActivateTime=default; EventId=0; RedirectId=0; _isBought=false; DoesPop=true; }
|
||||
internal void ReplaceFromKVDecoded(game.PlayerDataStorage.PlayerKVCouponState state)
|
||||
{ if(state==null) throw new ArgumentNullException(nameof(state)); ActivateTime=state.ActivateTime; EventId=state.EventId; RedirectId=state.RedirectId; _isBought=state.Bought; }
|
||||
|
||||
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)}";
|
||||
saveStore.Write(PlayFabDataKey, s).RequireAccepted();
|
||||
}
|
||||
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