Files
ft/Client/Assets/Scripts/DataCenter/EventPackData.cs
Liubing\LB 6813da149a feat(upserver): 保存M2客户端KV迁移至本人统计写检查点
保存独立KV用户服务、固定会话存档与原业务接线,以及C3d资料缓存和C3e本人统计写。
保留原PF/AGG路线、业务公式和时序;榜单读取、好友资料、公告、匹配及首场景闸仍待完成。

验证:ServiceHost两条件各33组646断言;Unity CLI Loop编译0错误269警告。
包含相关方案、评审裁决、测试及状态文档。未操作服务器、正式账号或打包。
2026-09-30 19:19:05 +08:00

119 lines
5.0 KiB
C#

using asap.core;
using GameCore;
using cfg;
public class EventPackData
{
[asap.core.Inject] public game.PlayerDataStorage.IPlayerSaveStore playerSaveStore { get; set; }
private Tables _tables = GContext.container.Resolve<Tables>();
private struct Data
{
public int currentEventID;
public int purchaseCount;
public int VIPLvlWhenEventActivate;
public int redirectID;
public Data(int eventID = 0, int p = 0, int v = 0, int rid = 0)
{
currentEventID = eventID;
purchaseCount = p;
VIPLvlWhenEventActivate = v;
redirectID = rid;
}
}
private Data _data;
internal static game.PlayerDataStorage.PlayerKVEventPackState DecodeForKVLoad(System.Collections.Generic.IReadOnlyDictionary<string,string> raw,
game.PlayerDataStorage.PlayerKVSchemaSnapshot snapshot,game.PlayerDataStorage.PlayerKVSchemaDiagnostics errors) =>
game.PlayerDataStorage.PlayerKVSaveSchema.DecodeEventPack(raw,snapshot,errors);
internal void ResetForKVLoad() { _data=default(Data); }
internal void ReplaceFromKVDecoded(game.PlayerDataStorage.PlayerKVEventPackState state)
{
if (state == null) throw new System.ArgumentNullException(nameof(state));
_data=new Data { currentEventID=state.EventId,purchaseCount=state.PurchaseCount,
VIPLvlWhenEventActivate=state.VipLevel,redirectID=state.RedirectId };
}
internal game.PlayerDataStorage.PlayerKVEventPackState SnapshotForKVValidation() =>
new game.PlayerDataStorage.PlayerKVEventPackState(_data.currentEventID,_data.purchaseCount,_data.VIPLvlWhenEventActivate,_data.redirectID);
public int CurrentEventID { get { return _data.currentEventID; } }
public int PurchaseCount { get { return _data.purchaseCount; } }
public int VIPLvlWhenEventActivated { get { return _data.VIPLvlWhenEventActivate; } }
public bool IsActive => _tables.TbFishingEvent.DataMap.ContainsKey(_data.currentEventID) &&
(System.DateTime.Parse(
(_tables.TbFishingEvent[_data.currentEventID].TimeDefinition as LimitedTime)
?.EndTime) -
ZZTimeHelper.UtcNow()).TotalSeconds > 0 &&
PurchaseCount < _tables.TbEventPackManager[_data.redirectID].MaxCount;
public EventPackData()
{
//Debug.Log("<color=red>construct</color>");
_data = new Data();
//PlayFabMgr.Instance.UpdateUserDataValue("EventPackData",
// Newtonsoft.Json.JsonConvert.SerializeObject(_data));
}
public void AddPurchaceCount()
{
_data.purchaseCount++;
SaveEventPackData();
}
/// <summary>
/// Refresh and update EventPackData if current event is not the event given. Will reset current
/// event if the event given is null
/// </summary>
/// <param name="e">New event</param>
public bool UpdateEventData(cfg.FishingEvent e = null)
{
bool isUpdated = false;
if (e == null)
{
_data = new Data();
isUpdated = true;
}
else if (_data.currentEventID != e.ID)
{
_data = new Data(e.ID, 0, GContext.container.Resolve<PlayerData>().PriceLv, e.RedirectID);
isUpdated = true;
}
//else
// do nothing
SaveEventPackData();
return isUpdated;
}
public void LoadEventPackData(string s)
{
//Debug.Log("<color=red>load epd</color>");
_data = Newtonsoft.Json.JsonConvert.DeserializeObject<Data>(s);
//Debug.Log($"load: {_data.currentEventID}");
if (!_tables.TbFishingEvent.DataMap.ContainsKey(_data.currentEventID) ||
(System.DateTime.Parse((_tables.TbFishingEvent[_data.currentEventID].TimeDefinition
as LimitedTime).EndTime) - ZZTimeHelper.UtcNow()).TotalSeconds <= 0 )
{
return;
}
if (_tables.TbEventPackManager[_tables.TbFishingEvent[_data.currentEventID].RedirectID].PackType != 1)
{
_data = new Data();
return;
}
if (_data.redirectID == 0)
_data.redirectID = 4054001;
TriggerEventPack();
}
public void SaveEventPackData()
{
playerSaveStore.Write("EventPackData",
Newtonsoft.Json.JsonConvert.SerializeObject(_data)).RequireAccepted();
}
private void TriggerEventPack()
{
var tables = GContext.container.Resolve<Tables>();
FishingEvent e = tables.TbFishingEvent.DataMap[_data.currentEventID];
int packID = _data.redirectID;
var packData = tables.TbEventPackManager.DataMap[packID];//pack data read from tables
// if (_data.purchaseCount < packData.MaxCount && packData.PackType == 1)
//TODO:change panel according to RedirecctID of current event
// GContext.container.Resolve<IFaceUIService>().
// AddGiftFaceUI(e.ID, UITypes.GiftPopupPanel_9, packData.PackType, true);
}
}