备份CatanBuilding瘦身独立工程
This commit is contained in:
3
Assets/Scripts/SandDig/model/Data.meta
Normal file
3
Assets/Scripts/SandDig/model/Data.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2edda2340cb3420e83671f9efaaaf3c3
|
||||
timeCreated: 1723805251
|
||||
11
Assets/Scripts/SandDig/model/Data/BroadData.cs
Normal file
11
Assets/Scripts/SandDig/model/Data/BroadData.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script.RuntimeScript.model.Data
|
||||
{
|
||||
public class BroadData
|
||||
{
|
||||
public int ID = 201;
|
||||
public Vector3 LocalPos = Vector3.zero;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/SandDig/model/Data/BroadData.cs.meta
Normal file
3
Assets/Scripts/SandDig/model/Data/BroadData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75757a48f91646249ebf60d91fe6b665
|
||||
timeCreated: 1723866522
|
||||
104
Assets/Scripts/SandDig/model/Data/DinggingSceneData.cs
Normal file
104
Assets/Scripts/SandDig/model/Data/DinggingSceneData.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using Random = System.Random;
|
||||
|
||||
namespace Script.RuntimeScript.model.Data
|
||||
{
|
||||
public class DinggingSceneData
|
||||
{
|
||||
public string BoxPositionJson;
|
||||
public string AllBroadJson;
|
||||
public string AllPropJson;
|
||||
public string AllCubeJson;
|
||||
public string AllTempJson;
|
||||
|
||||
private BroadData[] _allBroadData;
|
||||
private GridData[] _allGridData;
|
||||
private PropData[] _allPropData;
|
||||
private List<List<PropTempData>> _allPropTempData;
|
||||
//任务目标宝箱位置
|
||||
private Vector3 _taskBoxPositon = Vector3.zero;
|
||||
|
||||
|
||||
public void AnalysisData(List<ServerGridData> serverGrid)
|
||||
{
|
||||
_taskBoxPositon = JsonConvert.DeserializeObject<Vector3>(BoxPositionJson);
|
||||
_allBroadData = JsonConvert.DeserializeObject<BroadData[]>(AllBroadJson);
|
||||
_allGridData = JsonConvert.DeserializeObject<GridData[]>(AllCubeJson);
|
||||
_allPropData = JsonConvert.DeserializeObject<PropData[]>(AllPropJson);
|
||||
_allPropTempData = JsonConvert.DeserializeObject<List<List<PropTempData>>>(AllTempJson);
|
||||
|
||||
GridData gData;
|
||||
for (int i = 0; i < _allGridData.Length; i++)
|
||||
{
|
||||
gData = _allGridData[i];
|
||||
gData.Init();
|
||||
for (int j = 0; j < serverGrid.Count; j++)
|
||||
{
|
||||
if (serverGrid[j].Row == gData.Row && serverGrid[j].Col == gData.Col)
|
||||
{
|
||||
gData.IsOpen = serverGrid[j].IsOpen == 1;
|
||||
gData.hasClickCount = serverGrid[j].hasClickCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
_allGridData = new GridData[0];
|
||||
_allPropData = new PropData[0];
|
||||
}
|
||||
public GridData GetGridData(int row, int col)
|
||||
{
|
||||
GridData gData;
|
||||
for (int i = 0; i < _allGridData.Length; i++)
|
||||
{
|
||||
gData = _allGridData[i];
|
||||
if (gData.Row == row && gData.Col == col)
|
||||
{
|
||||
return gData;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vector3 GetTaskPosPositon()
|
||||
{
|
||||
return _taskBoxPositon;
|
||||
}
|
||||
|
||||
public BroadData[] GetAllBroadData()
|
||||
{
|
||||
return _allBroadData;
|
||||
}
|
||||
public GridData[] GetAllGridData()
|
||||
{
|
||||
return _allGridData;
|
||||
}
|
||||
|
||||
public PropData[] GetAllPropData()
|
||||
{
|
||||
return _allPropData;
|
||||
}
|
||||
|
||||
public List<PropTempData> GetAllPropTempData(int index)
|
||||
{
|
||||
if (_allPropTempData == null || _allPropTempData.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (index >= _allPropTempData.Count)
|
||||
{
|
||||
index = GetOnePropTempDataIndex();
|
||||
}
|
||||
return _allPropTempData[index];
|
||||
}
|
||||
public int GetOnePropTempDataIndex()
|
||||
{
|
||||
return UnityEngine.Random.Range(0, _allPropTempData.Count);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8aa6471ba052426b8ac286d5b4b07e84
|
||||
timeCreated: 1723806234
|
||||
39
Assets/Scripts/SandDig/model/Data/GridData.cs
Normal file
39
Assets/Scripts/SandDig/model/Data/GridData.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script.RuntimeScript.model.Data
|
||||
{
|
||||
public class GridData
|
||||
{
|
||||
public int PropId = 0;
|
||||
public bool IsBorder = false;
|
||||
public bool DoubleClick = false;
|
||||
public Vector3 LocalPos = Vector3.zero;
|
||||
public int ID = 1;
|
||||
public int Row = 0;
|
||||
public int Col = 0;
|
||||
public GridPropData ConfigData;
|
||||
|
||||
public bool IsOpen { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 已经点击的个数
|
||||
/// </summary>
|
||||
public int hasClickCount = 0;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
Row = (int)LocalPos.x;
|
||||
Col = (int)LocalPos.y;
|
||||
}
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
ServerGridData data = new ServerGridData();
|
||||
data.Row = Row;
|
||||
data.Col = Col;
|
||||
data.IsOpen = IsOpen ? 1 : 0;
|
||||
data.hasClickCount = hasClickCount;
|
||||
return data.ToJson();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/SandDig/model/Data/GridData.cs.meta
Normal file
3
Assets/Scripts/SandDig/model/Data/GridData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fb9576d851440798d5655c115edabdd
|
||||
timeCreated: 1723805269
|
||||
111
Assets/Scripts/SandDig/model/Data/GridPropData.cs
Normal file
111
Assets/Scripts/SandDig/model/Data/GridPropData.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System.Collections.Generic;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using Script.RuntimeScript.ExplosionEffect;
|
||||
using Script.RuntimeScript.GameLogic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script.RuntimeScript.model.Data
|
||||
{
|
||||
public class GridPropData
|
||||
{
|
||||
public int PropId = 0;
|
||||
public int PropDirection = 0;
|
||||
public int PropRows = 2; // 行数
|
||||
public int PropColumns = 2; // 列数
|
||||
public int[] PropArr;
|
||||
public int[,] TempArr;
|
||||
|
||||
/// <summary>
|
||||
/// 道具配置
|
||||
/// </summary>
|
||||
public DiggingItemList Config = null;
|
||||
|
||||
/// <summary>
|
||||
/// 父Grid
|
||||
/// </summary>
|
||||
public GridData ParentGird { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 需要开启的Grid
|
||||
/// </summary>
|
||||
private List<GridData> _needOpenGrids = new List<GridData>();
|
||||
|
||||
/// <summary>
|
||||
/// 目标
|
||||
/// </summary>
|
||||
private PropItem _targetPropItem;
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经被开启
|
||||
/// </summary>
|
||||
public bool AlreadyOpen { get; set; } = false;
|
||||
|
||||
#region 动态赋值数据
|
||||
private int Row = 0;
|
||||
private int Col = 0;
|
||||
#endregion
|
||||
|
||||
public PropItem TargetPropItem
|
||||
{
|
||||
get { return _targetPropItem; }
|
||||
}
|
||||
|
||||
public void Init(int propid,int row,int col)
|
||||
{
|
||||
PropId = propid;
|
||||
Row = row;
|
||||
Col = col;
|
||||
Config = GContext.container.Resolve<DiggingGameManager>().TableData.TbDiggingItemList.Get(PropId);
|
||||
TempArr = GetArray();
|
||||
}
|
||||
|
||||
public void AddGrid(GridData grid)
|
||||
{
|
||||
if (_needOpenGrids.IndexOf(grid) >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DiggingGameManager.LogWarning("AddGridX::" + grid.Row + " AddGridY::" + grid.Col);
|
||||
_needOpenGrids.Add(grid);
|
||||
}
|
||||
|
||||
public void SetTargetPropItem(PropItem propItem)
|
||||
{
|
||||
_targetPropItem = propItem;
|
||||
}
|
||||
|
||||
|
||||
public bool IsCanOpen()
|
||||
{
|
||||
bool canOpen = true;
|
||||
for (int i = 0; i < _needOpenGrids.Count; i++)
|
||||
{
|
||||
if (!_needOpenGrids[i].IsOpen)
|
||||
{
|
||||
canOpen = false;
|
||||
AlreadyOpen = canOpen;
|
||||
return canOpen;
|
||||
}
|
||||
}
|
||||
|
||||
AlreadyOpen = canOpen;
|
||||
return canOpen;
|
||||
}
|
||||
|
||||
private int[,] GetArray()
|
||||
{
|
||||
var arr = new int[PropRows, PropColumns];
|
||||
for (int i = 0; i < PropRows; i++)
|
||||
{
|
||||
for (int j = 0; j < PropColumns; j++)
|
||||
{
|
||||
arr[i, j] = PropArr[i * PropColumns + j];
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/SandDig/model/Data/GridPropData.cs.meta
Normal file
3
Assets/Scripts/SandDig/model/Data/GridPropData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a89fdc76de8c4de8ab60308ee52bcfda
|
||||
timeCreated: 1724209029
|
||||
14
Assets/Scripts/SandDig/model/Data/PropData.cs
Normal file
14
Assets/Scripts/SandDig/model/Data/PropData.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using Script.RuntimeScript.GameLogic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script.RuntimeScript.model.Data
|
||||
{
|
||||
public class PropData
|
||||
{
|
||||
public int PropId = 0;
|
||||
public Vector3 LocalPos = Vector3.zero;
|
||||
public bool IsOk = false;
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/SandDig/model/Data/PropData.cs.meta
Normal file
3
Assets/Scripts/SandDig/model/Data/PropData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db73383b55f74e61b1f3a02f6fb15191
|
||||
timeCreated: 1723805279
|
||||
11
Assets/Scripts/SandDig/model/Data/PropTempData.cs
Normal file
11
Assets/Scripts/SandDig/model/Data/PropTempData.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Script.RuntimeScript.model.Data
|
||||
{
|
||||
public class PropTempData
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
public int PropId;
|
||||
public GridPropData ConfigData;
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/SandDig/model/Data/PropTempData.cs.meta
Normal file
3
Assets/Scripts/SandDig/model/Data/PropTempData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c58dfc94ed294c468bfdc8e65e0c9952
|
||||
timeCreated: 1724226589
|
||||
72
Assets/Scripts/SandDig/model/Data/SandDigServerData.cs
Normal file
72
Assets/Scripts/SandDig/model/Data/SandDigServerData.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Script.RuntimeScript.model.Data
|
||||
{
|
||||
[System.Serializable]
|
||||
public class SandDigServerData
|
||||
{
|
||||
public int ClampId = 0;
|
||||
public int ClickCount = 0;
|
||||
/// <summary>
|
||||
/// 已经获得的目标道具
|
||||
/// </summary>
|
||||
public List<int> PassPropIds = new List<int>();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
PassPropIds.Clear();
|
||||
}
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ServerGridData
|
||||
{
|
||||
public int Row = 0;
|
||||
public int Col = 0;
|
||||
public int IsOpen = 0;
|
||||
public int hasClickCount = 0;
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SaveDataJson
|
||||
{
|
||||
public int ActivityId = 0;
|
||||
public string SandDigServerData;
|
||||
public string AllGridJson;
|
||||
public int TempIndex = -1;
|
||||
|
||||
//public string AllGridPropsJson;
|
||||
|
||||
public SandDigServerData GetSerializableData()
|
||||
{
|
||||
return JsonConvert.DeserializeObject<SandDigServerData>(SandDigServerData);
|
||||
}
|
||||
|
||||
public ServerGridData[] GetSerializableGridData()
|
||||
{
|
||||
if (string.IsNullOrEmpty(AllGridJson))
|
||||
return new ServerGridData[0];
|
||||
return JsonConvert.DeserializeObject<ServerGridData[]>(AllGridJson);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SaveDigCountJson
|
||||
{
|
||||
public int ActivityId = 0;
|
||||
public int DigCount = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c63d6ecedfd442f83e59df31144fb65
|
||||
timeCreated: 1724898766
|
||||
501
Assets/Scripts/SandDig/model/DiggingGameModel.cs
Normal file
501
Assets/Scripts/SandDig/model/DiggingGameModel.cs
Normal file
@@ -0,0 +1,501 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using Newtonsoft.Json;
|
||||
using Script.RuntimeScript;
|
||||
using Script.RuntimeScript.model.Data;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
|
||||
public class DiggingGameModel
|
||||
{
|
||||
#region 协议Const区域
|
||||
|
||||
//工具个数
|
||||
private const string DigCountKey = "DigCount";
|
||||
//棋盘管卡数据
|
||||
private const string DigGridDataKey = "DigGridData";
|
||||
|
||||
#endregion
|
||||
|
||||
#region 管卡json中原始数据
|
||||
private DinggingSceneData _dinggingSceneData;
|
||||
#endregion
|
||||
|
||||
#region 服务器数据
|
||||
/// <summary>
|
||||
/// 沙滩寻宝基本数据
|
||||
/// </summary>
|
||||
private SandDigServerData _serverData = null;
|
||||
/// <summary>
|
||||
/// 沙滩寻宝棋盘网格数据
|
||||
/// </summary>
|
||||
private List<ServerGridData> _allServerGridData = new List<ServerGridData>();
|
||||
public int TempIndex = -1;
|
||||
private int _serverDigCount = 0;
|
||||
int redDot = 10;
|
||||
//最新获取 道具个数 *** 已经废弃
|
||||
public int NewAddDigCount = 0;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 本期活动开放的所有管卡
|
||||
/// </summary>
|
||||
private List<int> _allClamps = new List<int>();
|
||||
public List<int> AllClamps => _allClamps;
|
||||
|
||||
private int _curActivityId = 0;
|
||||
public int CurActivityId
|
||||
{
|
||||
get => _curActivityId;
|
||||
}
|
||||
public DiggingActivityInit digActivityConfig;
|
||||
public string ResourceTopic => digActivityConfig.ResourceTopic;
|
||||
#region 数据初始化
|
||||
|
||||
/// <summary>
|
||||
/// 在线时候 活动开启
|
||||
/// </summary>
|
||||
public void ActivityOpen(cfg.FishingEvent t)
|
||||
{
|
||||
if (_curActivityId == t.ID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_curActivityId = t.ID;
|
||||
if (_curActivityId > 0)
|
||||
{
|
||||
digActivityConfig = GContext.container.Resolve<Tables>().TbDiggingActivityInit.Get(t.RedirectID);
|
||||
redDot = GContext.container.Resolve<FishingEventData>().GetRedDot(_curActivityId);
|
||||
}
|
||||
DiggingGameManager.LogError("沙滩寻宝开启");
|
||||
string countJson = PlayFabMgr.Instance.GetLocalData(DigCountKey);
|
||||
string digGridDataJson = PlayFabMgr.Instance.GetLocalData(DigGridDataKey);
|
||||
if (string.IsNullOrEmpty(countJson))
|
||||
{
|
||||
SaveNull();
|
||||
}
|
||||
DoServerData(countJson, digGridDataJson);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进入游戏初始化数据
|
||||
/// </summary>
|
||||
/// <param name="userDatas"></param>
|
||||
public async System.Threading.Tasks.Task InitServerData()
|
||||
{
|
||||
_curActivityId = GContext.container.Resolve<DiggingGameManager>().GetActivityId();
|
||||
DiggingGameManager.LogError("沙滩寻宝数据初始化");
|
||||
if (_curActivityId > 0)
|
||||
{
|
||||
FishingEvent fishingEvent = GContext.container.Resolve<Tables>().TbFishingEvent.GetOrDefault(_curActivityId);
|
||||
digActivityConfig = GContext.container.Resolve<Tables>().TbDiggingActivityInit.Get(fishingEvent.RedirectID);
|
||||
}
|
||||
|
||||
string countJson = PlayFabMgr.Instance.GetLocalData(DigCountKey);
|
||||
string digGridDataJson = PlayFabMgr.Instance.GetLocalData(DigGridDataKey);
|
||||
DoServerData(countJson, digGridDataJson);
|
||||
await InitClientData(ClientDataHandleEnum.Init);
|
||||
}
|
||||
private void DoServerData(string countJson, string digGridDataJson)
|
||||
{
|
||||
if (_curActivityId <= 0)
|
||||
{
|
||||
SaveNull();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
redDot = GContext.container.Resolve<FishingEventData>().GetRedDot(_curActivityId);
|
||||
FishingEvent acInfo = GContext.container.Resolve<DiggingGameManager>().GetActivityConfig(_curActivityId);
|
||||
int redirectID = acInfo.RedirectID;
|
||||
|
||||
DiggingActivityInit digActivityConfig = GContext.container.Resolve<Tables>().TbDiggingActivityInit.Get(redirectID);
|
||||
if (digActivityConfig == null)
|
||||
{
|
||||
SaveNull();
|
||||
return;
|
||||
}
|
||||
_allClamps = digActivityConfig.StageList;
|
||||
|
||||
if (!string.IsNullOrEmpty(countJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
SaveDigCountJson data = Newtonsoft.Json.JsonConvert.DeserializeObject<SaveDigCountJson>(countJson);
|
||||
if (data.ActivityId == _curActivityId)
|
||||
{
|
||||
_serverDigCount = data.DigCount;
|
||||
DiggingGameManager.LogError("玩家铲子个数 :::" + _serverDigCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveNull();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SaveNull();
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
_serverData = null;
|
||||
_allServerGridData.Clear();
|
||||
if (!string.IsNullOrEmpty(digGridDataJson))
|
||||
{
|
||||
SaveDataJson data = Newtonsoft.Json.JsonConvert.DeserializeObject<SaveDataJson>(digGridDataJson);
|
||||
if (data.ActivityId == _curActivityId)
|
||||
{
|
||||
_serverData = data.GetSerializableData();
|
||||
_allServerGridData = data.GetSerializableGridData().ToList();
|
||||
TempIndex = data.TempIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveNull();
|
||||
}
|
||||
}
|
||||
if (_serverData == null || (!_allClamps.Contains(_serverData.ClampId) && _serverData.ClampId > 0))
|
||||
{
|
||||
_serverData = new SandDigServerData();
|
||||
_serverData.ClampId = _allClamps[0];
|
||||
_allServerGridData.Clear();
|
||||
}
|
||||
SetRedPoint();
|
||||
//#if UNITY_EDITOR
|
||||
// //测试
|
||||
// _allServerGridData = new List<ServerGridData>();
|
||||
// _allServerGridPropsData = new List<ServerGridPropsData>();
|
||||
// _serverData = new SandDigServerData();
|
||||
// _serverData.ClampId = _allClamps[1];
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
public void GMSetClamp(int index)
|
||||
{
|
||||
if (_curActivityId <= 0 || _serverData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (index >= _allClamps.Count)
|
||||
{
|
||||
index = _allClamps.Count - 1;
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
_serverData.ClampId = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_serverData.ClampId = _allClamps[index];
|
||||
}
|
||||
NewData();
|
||||
}
|
||||
public async Task<bool> InitClientData(ClientDataHandleEnum handleType)
|
||||
{
|
||||
if (_serverData == null || _serverData.ClampId <= 0)
|
||||
return false;
|
||||
DiggingGameManager.LogError("初始化客户端管卡数据");
|
||||
string JsonPath = $"Clamp{_serverData.ClampId}";// $"Assets/ABPackage/SandDig/ClampJson/Clamp{_serverData.ClampId}";
|
||||
|
||||
GContext.container.Resolve<DiggingGameManager>().GameState = SandDigGameState.LoadJson;
|
||||
AsyncOperationHandle<TextAsset> handle = Addressables.LoadAssetAsync<TextAsset>(JsonPath);
|
||||
TaskCompletionSource<bool> taskCompletion = new TaskCompletionSource<bool>();
|
||||
handle.Completed += (AsyncOperationHandle<TextAsset> obj) =>
|
||||
{
|
||||
if (obj.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
DiggingGameManager.LogError("新管卡数据加载完毕");
|
||||
_dinggingSceneData = JsonConvert.DeserializeObject<DinggingSceneData>(obj.Result.ToString());
|
||||
_dinggingSceneData.AnalysisData(_allServerGridData);
|
||||
// 释放资源
|
||||
Addressables.Release(handle);
|
||||
if (handleType == ClientDataHandleEnum.PassClamp)
|
||||
{
|
||||
//可以切换了
|
||||
GContext.container.Resolve<DiggingGameManager>().GameState = SandDigGameState.WaitPassLoading;
|
||||
}
|
||||
else if (handleType == ClientDataHandleEnum.EnterGame)
|
||||
{
|
||||
GContext.container.Resolve<DiggingGameManager>().GameState = SandDigGameState.LoadJsonOver;
|
||||
}
|
||||
else if (handleType == ClientDataHandleEnum.Init)
|
||||
{
|
||||
InitCheckClampPass();
|
||||
}
|
||||
taskCompletion.SetResult(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
taskCompletion.SetResult(false);
|
||||
DiggingGameManager.LogError("Failed to load asset: " + JsonPath);
|
||||
}
|
||||
};
|
||||
return await taskCompletion.Task;
|
||||
}
|
||||
public void InitCheckClampPass()
|
||||
{
|
||||
List<int> allHaveProps = new List<int>(GetAllPassIds());
|
||||
PropData[] allData = GetAllPropData();
|
||||
bool allFinded = true;
|
||||
|
||||
for (int i = 0; i < allData.Length; i++)
|
||||
{
|
||||
var propData = allData[i];
|
||||
if (!allHaveProps.Contains(propData.PropId))
|
||||
{
|
||||
allFinded = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
allHaveProps.Remove(propData.PropId);
|
||||
}
|
||||
}
|
||||
if (!allFinded)
|
||||
{
|
||||
allFinded = true;
|
||||
GridData[] gridDatas = GetAllGridData();
|
||||
for (int i = 0; i < gridDatas.Length; i++)
|
||||
{
|
||||
GridData gridData = gridDatas[i];
|
||||
if (gridData.IsBorder || gridData.IsOpen)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
allFinded = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allFinded)
|
||||
{
|
||||
DiggingStageReward config = GContext.container.Resolve<Tables>().TbDiggingStageReward.Get(_serverData.ClampId);
|
||||
_serverData.ClampId = config.NextTarget;
|
||||
NewData();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过当前管卡发奖
|
||||
/// </summary>
|
||||
public void PassClamp()
|
||||
{
|
||||
GContext.container.Resolve<DiggingGameManager>().ClampIsPass = true;
|
||||
DiggingStageReward config = GContext.container.Resolve<Tables>().TbDiggingStageReward.Get(_serverData.ClampId);
|
||||
|
||||
var playerData = GContext.container.Resolve<PlayerItemData>();
|
||||
|
||||
DiggingGameManager.LogError("获得的Drop奖励 :::" + config.DropID);
|
||||
GContext.container.Resolve<DiggingGameManager>().itemDatas = playerData.AddItemByDrop(config.DropID, true);
|
||||
|
||||
_serverData.ClampId = config.NextTarget;
|
||||
NewData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在线进入新关卡,数据初始化
|
||||
/// </summary>
|
||||
public void NewData()
|
||||
{
|
||||
TempIndex = -1;
|
||||
_serverData.ClickCount = 0;
|
||||
_serverData.Reset();
|
||||
_allServerGridData.Clear();
|
||||
_dinggingSceneData?.Reset();
|
||||
SaveAll();
|
||||
}
|
||||
public void NewClampInit()
|
||||
{
|
||||
GContext.Publish(new EventSandDigNewClamp(_serverData.ClampId));
|
||||
if (_serverData.ClampId <= 0)
|
||||
{
|
||||
//通关所有关卡
|
||||
DiggingGameManager.LogError("通关所有关卡!!!!!!!");
|
||||
}
|
||||
else
|
||||
{
|
||||
InitClientData(ClientDataHandleEnum.PassClamp);
|
||||
}
|
||||
}
|
||||
|
||||
#region 数据接口
|
||||
|
||||
/// <summary>
|
||||
/// 使用道具
|
||||
/// </summary>
|
||||
public void UseDig()
|
||||
{
|
||||
_serverDigCount--;
|
||||
_serverData.ClickCount++;
|
||||
SaveDigCount();
|
||||
|
||||
GContext.Publish(new EventSandDigPropUpdate());
|
||||
}
|
||||
/// <summary>
|
||||
/// 增加道具
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public void AddDigCount(int count)
|
||||
{
|
||||
_serverDigCount += count;
|
||||
|
||||
SaveDigCount();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获得目标道具
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public void AddProp(int id)
|
||||
{
|
||||
_serverData.PassPropIds.Add(id);
|
||||
}
|
||||
|
||||
public List<int> GetAllPassIds()
|
||||
{
|
||||
return _serverData.PassPropIds;
|
||||
}
|
||||
|
||||
public DinggingSceneData GetBroadData()
|
||||
{
|
||||
return _dinggingSceneData;
|
||||
}
|
||||
|
||||
public BroadData[] GetAllBroadData()
|
||||
{
|
||||
return _dinggingSceneData.GetAllBroadData();
|
||||
}
|
||||
|
||||
public GridData[] GetAllGridData()
|
||||
{
|
||||
return _dinggingSceneData.GetAllGridData();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取一个格子数据
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
/// <param name="col"></param>
|
||||
/// <returns></returns>
|
||||
public GridData GetGridData(int row, int col)
|
||||
{
|
||||
return _dinggingSceneData.GetGridData(row, col);
|
||||
}
|
||||
|
||||
public PropData[] GetAllPropData()
|
||||
{
|
||||
return _dinggingSceneData.GetAllPropData();
|
||||
}
|
||||
|
||||
public List<PropTempData> GetOnePropTempData()
|
||||
{
|
||||
if (TempIndex < 0)
|
||||
{
|
||||
TempIndex = _dinggingSceneData.GetOnePropTempDataIndex();
|
||||
}
|
||||
return _dinggingSceneData.GetAllPropTempData(TempIndex);
|
||||
}
|
||||
public Vector3 GetTaskPosPositon()
|
||||
{
|
||||
return _dinggingSceneData.GetTaskPosPositon();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取道具个数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetDigCount()
|
||||
{
|
||||
return _serverDigCount;
|
||||
}
|
||||
|
||||
|
||||
public SandDigServerData GetServerData()
|
||||
{
|
||||
return _serverData;
|
||||
}
|
||||
|
||||
public int GetCurClampId()
|
||||
{
|
||||
return _serverData.ClampId;
|
||||
}
|
||||
public int GetClickCount()
|
||||
{
|
||||
return _serverData.ClickCount;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region 数据存储
|
||||
|
||||
public void SaveDigCount()
|
||||
{
|
||||
SetRedPoint();
|
||||
SaveDigCountJson dataJson = new SaveDigCountJson();
|
||||
dataJson.ActivityId = _curActivityId;
|
||||
dataJson.DigCount = _serverDigCount;
|
||||
string json = JsonConvert.SerializeObject(dataJson);
|
||||
PlayFabMgr.Instance.UpdateUserDataValue(DigCountKey, json);
|
||||
GContext.container.Resolve<FishingEventData>().SaveTransitionData(dataJson.ActivityId, dataJson.DigCount);
|
||||
}
|
||||
void SetRedPoint()
|
||||
{
|
||||
RedPointManager.Instance.SetRedPointState("Home.Digging", _serverData != null && _serverData.ClampId > 0 && _serverDigCount >= redDot);
|
||||
}
|
||||
public void SaveData()
|
||||
{
|
||||
//通用数据 + 任务目标数据
|
||||
SaveDataJson dataJson = new SaveDataJson();
|
||||
dataJson.ActivityId = _curActivityId;
|
||||
dataJson.SandDigServerData = _serverData.ToJson();
|
||||
dataJson.TempIndex = TempIndex;
|
||||
//网格数据
|
||||
GridData[] allGridData = _dinggingSceneData?.GetAllGridData() ?? new GridData[0];
|
||||
string allGridStr = allGridData.Length > 0 ? "[" : string.Empty;
|
||||
|
||||
for (int i = 0; i < allGridData.Length; i++)
|
||||
{
|
||||
if (i == allGridData.Length - 1)
|
||||
{
|
||||
allGridStr += allGridData[i].ToJson() + "]";
|
||||
}
|
||||
else
|
||||
{
|
||||
allGridStr += allGridData[i].ToJson() + ",";
|
||||
}
|
||||
}
|
||||
dataJson.AllGridJson = allGridStr;
|
||||
|
||||
string json = JsonConvert.SerializeObject(dataJson);
|
||||
//DiggingGameManager.LogError(json);
|
||||
PlayFabMgr.Instance.UpdateUserDataValue(DigGridDataKey, json);
|
||||
}
|
||||
|
||||
public void SaveAll()
|
||||
{
|
||||
this.SaveDigCount();
|
||||
this.SaveData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空上一期活动数据
|
||||
/// </summary>
|
||||
private void SaveNull()
|
||||
{
|
||||
_serverDigCount = GContext.container.Resolve<FishingEventData>().GetInitWelcomeGift(_curActivityId);
|
||||
SaveDigCount();
|
||||
PlayFabMgr.Instance.UpdateUserDataValue(DigGridDataKey, string.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
3
Assets/Scripts/SandDig/model/DiggingGameModel.cs.meta
Normal file
3
Assets/Scripts/SandDig/model/DiggingGameModel.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6b18e78d9f547e3aa1eef0a1f10b7dd
|
||||
timeCreated: 1723804889
|
||||
Reference in New Issue
Block a user