Files
ft/CodexOutput/upserver/B3BatchMigration/M2/C2d修改前快照/099-SocialRushArchitecture.cs.txt
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

158 lines
5.1 KiB
Plaintext

using UnityEngine;
using asap.core;
using System.Text;
using cfg;
using System.Linq;
using GameCore;
using game;
namespace Assets.Scripts.UI.SocialRush
{
public class SocialRushArchitecture
{
readonly game.PlayerDataStorage.IPlayerSaveStore saveStore = GContext.container.Resolve<game.PlayerDataStorage.IPlayerSaveStore>();
private Model _model = new Model();
private TableContext _tableContext;
public int EventId => _tableContext.EventId;
public Model Model => _model;
public TableContext TableContext => _tableContext;
#region RedPoint
private bool _isFirstTime = true;
public bool IsFirstTime => _isFirstTime;
private string _redPointKey = "social_rush";
public string RedPointKey => _redPointKey;
#endregion
#region DataStorage
public static void Load(FishingEvent e)
{
var arc = GContext.container.Resolve<SocialRushArchitecture>();
if (arc == null)
{
GContext.container.Register<SocialRushArchitecture>().AsSingleton();
arc = GContext.container.Resolve<SocialRushArchitecture>();
}
var res = arc.LoadPlayfab();
arc.LoadPlayerPreferences();
if (!res || arc.EventId != e.ID)
arc.Init(e.ID);
var urls = arc.TableContext.GetAddressableUrls();
UITypes.SocialRushPanel.SetType(urls[1]);
}
public void InitTest(int eventId)
{
_tableContext = TableContext.CreateTest(eventId);
_model.Reset();
_model.Set(0, 0, GContext.container.Resolve<GameCore.PlayerData>().InflationRate);
}
public void Init(int eventId)
{
_tableContext = new TableContext(eventId);
_model.Reset();
_isFirstTime = true;
SavePlayfab();
SavePlayerPreferences();
}
private const char Pipe = '|';
private const string PfKey = "FeastRush";
private string PpKey => "SocialRush" + GContext.container.Resolve<IUserService>().UserId;
public void SavePlayfab()
{
var sb = new StringBuilder();
sb.Append(_tableContext.EventId).Append(Pipe);
sb.Append(_model.ProgressDisplay).Append(Pipe);
sb.Append(_model.ProgressActual).Append(Pipe);
sb.Append(_model.InflationRate).Append(Pipe);
saveStore.Write(PfKey, sb.ToString()).RequireAccepted();
}
public bool LoadPlayfab()
{
try
{
var dataString = saveStore.Read(PfKey).ValueOrThrow();
var tokens = dataString.Trim(Pipe).Split(Pipe);
var eventId = int.Parse(tokens[0]);
var progressDisplay = int.Parse(tokens[1]);
var progressActual = int.Parse(tokens[2]);
var inflationRate = float.Parse(tokens[3]);
_tableContext = new TableContext(eventId);
_model.Set(progressActual, progressDisplay, inflationRate);
return true;
}
catch (System.Exception e)
{
Debug.LogWarning(e);
return false;
}
}
public void LoadPlayerPreferences()
{
_isFirstTime = PlayerPrefs.GetInt(PpKey, 1) == 1;
}
public void SavePlayerPreferences()
{
PlayerPrefs.SetInt(PpKey, _isFirstTime ? 1 : 0);
}
public void SetFirstTime()
{
_isFirstTime = false;
SavePlayerPreferences();
}
#endregion
#region System
public bool IsActive()
{
return _tableContext.IsActive()
&& _model.ProgressDisplay < _tableContext.GetTaskList().Sum(x => x.TaskParam)
&& _model.ProgressDisplay >= 0;
}
public bool NeedUpdate()
{
return _model.ProgressDisplay < _model.ProgressActual;
}
public bool NeedPopup()
{
var res = TableContext.HasUnclaimedReward(_model.ProgressDisplay, _model.ProgressActual, out var displayTaskIdx, out var actualTaskIdx);
return res;
}
public void AddProgress(int n)
{
if (!IsActive())
return;
_model.AddProgress(n);
SavePlayfab();
}
#endregion
#region leyuan
public void AddFishRaidProgress(int multiplier = 1)
{
var count = _tableContext.GetFishRaidProgress() * multiplier;
GContext.Publish(new game.TargetAddData(TableContext.GetProgressItemId(), Model.ProgressActual, count));
AddProgress(count);
}
public void AddBombProgress(int multiplier = 1)
{
var count = _tableContext.GetBombProgress() * multiplier;
GContext.Publish(new game.TargetAddData(TableContext.GetProgressItemId(), Model.ProgressActual, count));
AddProgress(_tableContext.GetBombProgress() * multiplier);
}
#endregion
}
}