Files
ft/CodexOutput/upserver/B3BatchMigration/M2/C2d修改前快照/046-InfiniteBuildingData.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

89 lines
3.1 KiB
Plaintext

using asap.core;
using cfg;
using GameCore;
using System.Collections.Generic;
using UnityEngine;
public class InfiniteBuildingData
{
readonly game.PlayerDataStorage.IPlayerSaveStore saveStore = GContext.container.Resolve<game.PlayerDataStorage.IPlayerSaveStore>();
public int Lvl, Step, StepLvl = 1, LastHangingBlock = -1;
public List<BlockRecord> Record = new List<BlockRecord>();
// private readonly TbConstructionUnits BlocksTable = GContext.container.Resolve<Tables>().TbConstructionUnits;
public int ConstructPrice => (int)
(GContext.container.Resolve<Tables>().TbMapData.DataList[^1].ConstrutionCost
* GContext.container.Resolve<Tables>().TbConstructionInfiniteConfig.CashMagList[Step]);
public struct BlockRecord
{
public readonly int ID;
public Vector2 Pos;
public readonly float Height => GContext.container.Resolve<Tables>().TbConstructionUnits[ID].Height;
public readonly string PrefabID => GContext.container.Resolve<Tables>().TbConstructionUnits[ID].Prefab;
public BlockRecord(int id = 0, Vector2 pos = default)
{
this.ID = id;
this.Pos = pos;
}
public BlockRecord(int id = 0, float x = 0, float y = 0)
{
this.ID = id;
Pos = new Vector2(x, y);
}
public readonly override string ToString() => $"{ID},{Pos.x},{Pos.y}";
}
private string Serialize()
{
var sb = new System.Text.StringBuilder();
sb.Append($"{Lvl},{Step},{StepLvl},{LastHangingBlock},");
foreach (BlockRecord node in Record)
sb.Append($"{node.ToString()},");
return sb.ToString().Trim(',');
}
public void Deserialize(string s)
{
string[] tokens = s.Split(',');
if (tokens == null || tokens.Length < 4 || tokens.Length % 3 != 1)
{
Debug.LogWarning($"string \"{s}\" cannot be deserialized.");
return;
}
Lvl = int.Parse(tokens[0]);
Step = int.Parse(tokens[1]);
StepLvl = int.Parse(tokens[2]);
LastHangingBlock = int.Parse(tokens[3]);
Record = new List<BlockRecord>();
for (int i = 4; i < tokens.Length; i+=3)
{
Record.Add(new BlockRecord(int.Parse(tokens[i]),
float.Parse(tokens[i + 1]), float.Parse(tokens[i + 2])));
//Debug.Log($"{int.Parse(tokens[i])}, {float.Parse(tokens[i + 1])}, {float.Parse(tokens[i + 2])}");
}
}
public void UploadData()
{
string s = Serialize();
//Debug.Log("Upload!!!!!!!!!!!!!!");
//Debug.Log(s);
GContext.container.Resolve<PlayerData>().InfiniteBuildingData = s;
saveStore.Write("InfiniteBuildingData", s).RequireAccepted();
}
public void DownloadData(string s)
{
Deserialize(s);
}
#if UNITY_EDITOR
public void PrintSelf()
{
Debug.Log($"Lvl: {Lvl}");
Debug.Log($"Step: {Step}");
Debug.Log($"StepLvl: {StepLvl}");
foreach (BlockRecord node in Record)
{
Debug.Log($"node: {node.PrefabID}, {node.Pos}");
}
}
#endif
}