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,209 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
using asap.core;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EventOfferJourneyLvlTriggerData : AEventOfferJourneyData
|
||||
{
|
||||
private int _progress, _ticketCount, _roundCount;
|
||||
private EventOfferJourneyLvlTriggerTableContext _ctx = new EventOfferJourneyLvlTriggerTableContext();
|
||||
public override int EventId => _ctx.TriggerPackId;
|
||||
public override int Progress => _progress;
|
||||
public override int TicketCount => _ticketCount;
|
||||
public override float InflationRate => 0;
|
||||
|
||||
public override ShopBuyType BuyType => ShopBuyType.TriggerPack;
|
||||
public bool IsActive => _ctx.IsEventActive && _roundCount < _ctx.MaxRoundCount;
|
||||
// private int VipLvlOnTrigger => _ctx.VipLvlOnTrigger;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_progress = 0;
|
||||
_ticketCount = 0;
|
||||
_roundCount = 0;
|
||||
}
|
||||
|
||||
public override bool AddTicket(int n)
|
||||
{
|
||||
_ticketCount += n;
|
||||
if (_ticketCount < 0)
|
||||
{
|
||||
_ticketCount -= n;
|
||||
return false;
|
||||
}
|
||||
SaveData();
|
||||
// GContext.container.Resolve<FishingEventData>().SaveTransitionData(_eventId, _ticketCount);
|
||||
GContext.Publish(new EventTicketUpdate());
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnBuySuccess()
|
||||
{
|
||||
if (_progress >= _ctx.GetRewardList().Count)
|
||||
{
|
||||
Debug.LogError($"[EventOfferJourney]Trying to buy pack no.{_progress} but there are only {_ctx.GetRewardList().Count} rewards.");
|
||||
return;
|
||||
}
|
||||
_progress++;
|
||||
SaveData();
|
||||
}
|
||||
|
||||
public override void ProgressUp()
|
||||
{
|
||||
_progress++;
|
||||
if (_progress >= _ctx.GetRewardList().Count)
|
||||
{
|
||||
_progress = 0;
|
||||
_roundCount++;
|
||||
}
|
||||
SaveData();
|
||||
}
|
||||
|
||||
public override void SaveData()
|
||||
{
|
||||
ToPlayfabData().Save();
|
||||
}
|
||||
|
||||
public override bool LoadDataFromPlayfab()
|
||||
{
|
||||
var pfData = EventOfferJourneyLvlTriggerPlayfabData.Load();
|
||||
if (pfData == null)
|
||||
return false;
|
||||
_progress = pfData.Progress;
|
||||
_ticketCount = pfData.TicketCount;
|
||||
_roundCount = pfData.RoundCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
private EventOfferJourneyLvlTriggerPlayfabData ToPlayfabData()
|
||||
{
|
||||
return new EventOfferJourneyLvlTriggerPlayfabData(_progress, _ticketCount, _roundCount);
|
||||
}
|
||||
|
||||
public override EventOfferJourneyEntranceData ToEntranceData()
|
||||
{
|
||||
if (!IsActive)
|
||||
{
|
||||
return new EventOfferJourneyEntranceData(false, TimeSpan.Zero, "", false);
|
||||
}
|
||||
TimeSpan remainingTime = _ctx.GetEventStartTimeAndEndTime().Item2 - ZZTimeHelper.UtcNow();
|
||||
// Debug.Log($"[EventOfferJourney] Remaining time: {remainingTime.TotalSeconds}s.");
|
||||
var isActive = IsActive && remainingTime.TotalSeconds > 0;
|
||||
// Debug.Log($"[EventOfferJourney] First Is active: {IsActive}.");
|
||||
// Debug.Log($"[EventOfferJourney] Total Is active: {isActive}.");
|
||||
var iconUrl = _ctx.EntranceIconUrl;
|
||||
// Debug.Log($"[EventOfferJourney] Icon URL: {iconUrl}.");
|
||||
var cost = _ctx.GetTicketCostByProgress(_progress);
|
||||
// Debug.Log($"[EventOfferJourney] Cost: {cost}.");
|
||||
var doNeedRedPoint = cost > 0 && cost <= _ticketCount;
|
||||
// Debug.Log($"[EventOfferJourney] Do need red point: {doNeedRedPoint}.");
|
||||
var res = new EventOfferJourneyEntranceData(isActive, remainingTime, iconUrl, doNeedRedPoint);
|
||||
return res;
|
||||
}
|
||||
|
||||
public override List<EventOfferJourneyBlockData> GetRewardList()
|
||||
{
|
||||
return _ctx.GetRewardList();
|
||||
}
|
||||
|
||||
public override ITimerContext ToTimerData(Action OnExpire)
|
||||
{
|
||||
var res = new TimerContext
|
||||
{
|
||||
StartTime = _ctx.GetEventStartTimeAndEndTime().Item1,
|
||||
ExpiryTime = _ctx.GetEventStartTimeAndEndTime().Item2,
|
||||
OnExpire = OnExpire
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
public override EventOfferJourneyUiData GetUiData()
|
||||
{
|
||||
return _ctx.GetUiData();
|
||||
}
|
||||
public override int[] GetTicketRewardArray()
|
||||
{
|
||||
return _ctx.GetTicketRewardArray();
|
||||
}
|
||||
|
||||
public override string GetTicketName()
|
||||
{
|
||||
return _ctx.GetTicketName();
|
||||
}
|
||||
|
||||
public override void OnRaid(int multiplier = 1)
|
||||
{
|
||||
int rewardCount = _ctx.GetTicketRewardArray()[0] * multiplier;
|
||||
GContext.Publish(new game.TargetAddData(_ctx.GetTicketId(), TicketCount, rewardCount));
|
||||
AddTicket(rewardCount);
|
||||
}
|
||||
|
||||
public override void OnBomb(int multiplier = 1)
|
||||
{
|
||||
int rewardCount = _ctx.GetTicketRewardArray()[1] * multiplier;
|
||||
GContext.Publish(new game.TargetAddData(_ctx.GetTicketId(), TicketCount, rewardCount));
|
||||
AddTicket(rewardCount);
|
||||
}
|
||||
|
||||
public override int GetStartPosParam()
|
||||
{
|
||||
return _ctx.GetStartPosParam();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class EventOfferJourneyLvlTriggerPlayfabData
|
||||
{
|
||||
readonly game.PlayerDataStorage.IPlayerSaveStore saveStore = GContext.container.Resolve<game.PlayerDataStorage.IPlayerSaveStore>();
|
||||
|
||||
public int Progress, TicketCount, RoundCount;
|
||||
private const string Key = "EventOfferJourneyLvlTriggerData";
|
||||
private const int TokenCount = 3;
|
||||
private const char Splitter = '|', Comma = ',';
|
||||
|
||||
public EventOfferJourneyLvlTriggerPlayfabData(int progress, int ticketCount, int roundCount)
|
||||
{
|
||||
Progress = progress;
|
||||
TicketCount = ticketCount;
|
||||
RoundCount = roundCount;
|
||||
}
|
||||
|
||||
private string Serialize()
|
||||
{
|
||||
var res = new StringBuilder();
|
||||
res.Append(Progress).Append(Splitter)
|
||||
.Append(TicketCount).Append(Splitter)
|
||||
.Append(RoundCount).Append(Splitter);
|
||||
return res.ToString();
|
||||
}
|
||||
|
||||
private static EventOfferJourneyLvlTriggerPlayfabData Deserialize(string s)
|
||||
{
|
||||
if (s == null || s == "")
|
||||
return null;
|
||||
var tokens = s.Trim(Splitter).Split(Splitter);
|
||||
if (tokens.Length != TokenCount)
|
||||
{
|
||||
Debug.LogError($"[EventOfferJourney]Wrong amount of parameters. Expect {TokenCount}, but got {tokens.Length} in \"{s}\".");
|
||||
return null;
|
||||
}
|
||||
var progress = int.Parse(tokens[0]);
|
||||
var ticketCount = int.Parse(tokens[1]);
|
||||
var roundCount = int.Parse(tokens[2]);
|
||||
return new EventOfferJourneyLvlTriggerPlayfabData(progress, ticketCount, roundCount);
|
||||
}
|
||||
|
||||
public static EventOfferJourneyLvlTriggerPlayfabData Load()
|
||||
{
|
||||
var s = GContext.container.Resolve<game.PlayerDataStorage.IPlayerSaveStore>().Read(Key).ValueOrThrow();
|
||||
return Deserialize(s);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
var s = Serialize();
|
||||
saveStore.Write(Key, s).RequireAccepted();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user