601 lines
18 KiB
C#
601 lines
18 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using LitJson;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class CampDataMM
|
|
{
|
|
private cfg.Tables _tables;
|
|
MMTService _MMService;
|
|
public CampDataMM(cfg.Tables tables, MMTService mmService)
|
|
{
|
|
this._tables = tables;
|
|
_MMService = mmService;
|
|
}
|
|
|
|
#region SERVER_DATA
|
|
int _id = 101;
|
|
public int PreID;
|
|
public int Id
|
|
{
|
|
set { _id = value; }
|
|
get
|
|
{
|
|
return _id;
|
|
}
|
|
}
|
|
public int AreaIndex { get; private set; } = 0;
|
|
public int AreaStep { get; private set; } = 0;
|
|
Dictionary<string, int> CampDataDic = new Dictionary<string, int>();
|
|
#endregion
|
|
|
|
public SwitchBuildingData SwitchBuildingData;
|
|
|
|
public int AreaId { get; private set; } = 0;
|
|
public int AreaStepCount { get; private set; }
|
|
public int TimelineId { get; private set; }
|
|
public string Name { get { return _tables.TbConstruction.DataMap[Id].Name_l10n_key; } }
|
|
|
|
public string AreaIcon { get; private set; }
|
|
public string BasePrefab => _tables.TbConstruction.DataMap[Id].Prefab;
|
|
public List<string> AllPrefabs
|
|
{
|
|
get
|
|
{
|
|
List<int> AreaList;
|
|
if (_MMService.mmBuilding)
|
|
{
|
|
AreaList = _tables.TbConstruction.DataMap[Id].MmtAreaList;
|
|
}
|
|
else
|
|
{
|
|
AreaList = _tables.TbConstruction.DataMap[Id].AreaList;
|
|
}
|
|
return AreaList.Select(stepid => _tables.TBArea.DataMap[stepid].BuildingPrefeb).Distinct().ToList();
|
|
}
|
|
}
|
|
|
|
|
|
public string CurrentPrefab
|
|
{
|
|
get
|
|
{
|
|
int index = AreaIndex;
|
|
if (index >= AreaList.Count)
|
|
index = AreaList.Count - 1;
|
|
|
|
return _tables.TBArea.DataMap[AreaList[index]].BuildingPrefeb;
|
|
}
|
|
}
|
|
|
|
|
|
public AreaMM GetAreaByIndex(int index)
|
|
{
|
|
if (index >= AreaList.Count)
|
|
index = AreaList.Count - 1;
|
|
return _tables.TBArea.DataMap[AreaList[index]];
|
|
}
|
|
|
|
|
|
public string BGM { get { return _tables.TbConstruction.DataMap[Id].BGM; } }
|
|
public int NextMapID { get { return _tables.TbConstruction.DataMap[Id].NextID; } }
|
|
public AreaMM constructionArea { get; private set; }
|
|
public StepMM StepInfo { get; private set; }
|
|
public List<int> AreaList
|
|
{
|
|
get
|
|
{
|
|
if (_MMService.mmBuilding)
|
|
return _tables.TbConstruction.DataMap[Id].MmtAreaList;
|
|
else
|
|
return _tables.TbConstruction.DataMap[Id].AreaList;
|
|
}
|
|
}
|
|
|
|
public List<int> AreaStepList { get; private set; }
|
|
|
|
public bool IsUpdataArea = false;
|
|
string _isOpenSkyscraper = "0";
|
|
public bool IsOpenSkyscraper => _isOpenSkyscraper == "1" || IsCanSkyscraper;
|
|
public bool IsCanSkyscraper
|
|
{
|
|
get
|
|
{
|
|
var dataMap = _tables.TbMapData.DataList[^1];
|
|
return GContext.container.Resolve<PlayerData>().lv >= dataMap.LevelRequired;
|
|
}
|
|
}
|
|
//public int curQRewardCount = 0;
|
|
//是否需要修复
|
|
public bool IsFix => _isFix && AreaIndex < AreaList.Count;
|
|
bool _isFix;
|
|
public void InitData(Dictionary<string, string> userData)
|
|
{
|
|
string value;
|
|
|
|
if (userData.TryGetValue("IsFix", out value))
|
|
{
|
|
SetIsFix(bool.Parse(value), false);
|
|
}
|
|
if (userData.TryGetValue("IsOpenSkyscraper", out value))
|
|
{
|
|
_isOpenSkyscraper = value;
|
|
}
|
|
|
|
if (userData.TryGetValue("CampDataDic", out value))
|
|
{
|
|
CampDataDic = JsonMapper.ToObject<Dictionary<string, int>>(value);
|
|
}
|
|
}
|
|
public void SetIsFix(bool isFix, bool isSave = true)
|
|
{
|
|
_isFix = isFix;
|
|
if (isSave)
|
|
{
|
|
PlayFabMgr.Instance.UpdateUserDataValue("IsFix", _isFix.ToString());
|
|
}
|
|
}
|
|
|
|
public void SetCampAreaIndex(string id_string)
|
|
{
|
|
AreaIndex = GlobalUtils.TryParseInt(id_string);
|
|
}
|
|
|
|
public void SetCampAreaStep(string step_string)
|
|
{
|
|
AreaStep = GlobalUtils.TryParseInt(step_string);
|
|
}
|
|
void SetCampByLevel()
|
|
{
|
|
List<Construction> _dataList = _tables.TbConstruction.DataList;
|
|
if (!_tables.TbConstruction.DataMap.ContainsKey(Id))
|
|
{
|
|
Debug.LogError($"[CampData]UpdateCurrentData: Not found data of id({Id})!");
|
|
Id = _dataList[^1].ID;
|
|
}
|
|
int level = GContext.container.Resolve<PlayerData>().lv;
|
|
int id = _dataList[0].ID;
|
|
for (int i = _dataList.Count - 1; i >= 0; i--)
|
|
{
|
|
if (_dataList[i].InitialLevel <= level)
|
|
{
|
|
id = _dataList[i].ID;
|
|
level -= _dataList[i].InitialLevel;
|
|
break;
|
|
}
|
|
}
|
|
|
|
AreaIndex = AreaList.Count;
|
|
var _area = _tables.TBArea.DataMap[AreaList[^1]];
|
|
int StepCount = _area.StepCount;
|
|
AreaStep = StepCount;
|
|
if (id % 1000 <= Id % 1000)
|
|
{
|
|
Id = id;
|
|
AreaIndex = AreaList.Count;
|
|
for (int i = 0; i < AreaList.Count; i++)
|
|
{
|
|
_area = _tables.TBArea.DataMap[AreaList[i]];
|
|
StepCount = _area.StepCount;
|
|
if (StepCount > level)
|
|
{
|
|
AreaIndex = i;
|
|
AreaStep = level;
|
|
break;
|
|
}
|
|
level -= StepCount;
|
|
}
|
|
}
|
|
}
|
|
public void Init()
|
|
{
|
|
if (CampDataDic.Count > 0)
|
|
{
|
|
Id = CampDataDic["CampId"];
|
|
}
|
|
SetCampByLevel();
|
|
PreID = Id;
|
|
if (_tables.TbConstruction.DataMap.ContainsKey(Id))
|
|
{
|
|
if (AreaIndex >= AreaList.Count)
|
|
{
|
|
CompleteInit();
|
|
}
|
|
else
|
|
{
|
|
UpdateCurrentData();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"[CampData]UpdateCurrentData: Not found data of id({Id})!");
|
|
}
|
|
}
|
|
|
|
public void ChangeNextCampID()
|
|
{
|
|
OnChangeCamp(NextMapID);
|
|
}
|
|
public void ChangeCampId(int id)
|
|
{
|
|
OnChangeCamp(id);
|
|
}
|
|
|
|
void OnChangeCamp(int id)
|
|
{
|
|
PreID = Id;
|
|
if (_tables.TbConstruction.DataMap.TryGetValue(id, out var camp_data))
|
|
{
|
|
constructionArea = null;
|
|
Id = id;
|
|
SetCampByLevel();
|
|
if (AreaIndex >= AreaList.Count)
|
|
{
|
|
CompleteInit();
|
|
}
|
|
else
|
|
{
|
|
UpdateCurrentData();
|
|
}
|
|
CampDataDic["CampId"] = Id;
|
|
PlayFabMgr.Instance.UpdateUserDataValue("CampDataDic", JsonMapper.ToJson(CampDataDic)); ;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"[CampData]UpdateCurrentData: Not found data of id({id})!");
|
|
}
|
|
}
|
|
public void SaveChangeCamp()
|
|
{
|
|
SetCampID();
|
|
}
|
|
|
|
|
|
async void SetCampID()
|
|
{
|
|
IUserService userService = GContext.container.Resolve<IUserService>();
|
|
SetCampIDRequest setCampIDRequest = new SetCampIDRequest()
|
|
{
|
|
playerID = userService.UserId,
|
|
campID = Id
|
|
};
|
|
var customServerMgr = GContext.container.Resolve<ICustomServerMgr>();
|
|
string json = await customServerMgr.BombRequest("SetCampID", setCampIDRequest);
|
|
if (!string.IsNullOrEmpty(json) && json != "[]")
|
|
{
|
|
SetCampIDResponse setCampIDResp = Newtonsoft.Json.JsonConvert.DeserializeObject<SetCampIDResponse>(json);
|
|
}
|
|
}
|
|
public void ShowReward()
|
|
{
|
|
int lv = GContext.container.Resolve<PlayerData>().lv;
|
|
if (_tables.TbGlobalConfig.AutoClaimUnlock > 0 && lv > _tables.TbGlobalConfig.AutoClaimUnlock)
|
|
GContext.Publish(new ShowData(RewardType.AutoOpen));
|
|
else
|
|
GContext.Publish(new ShowData());
|
|
|
|
}
|
|
|
|
|
|
public void UpdateCurrentData()
|
|
{
|
|
if (AreaList != null)
|
|
{
|
|
if (AreaIndex < 0 || AreaIndex >= AreaList.Count)
|
|
{
|
|
if (NextMapID == -1 || !_tables.TbConstruction.DataMap.ContainsKey(NextMapID))
|
|
{
|
|
_isOpenSkyscraper = "1";
|
|
PlayFabMgr.Instance.UpdateUserDataValue("IsOpenSkyscraper", _isOpenSkyscraper);
|
|
return;
|
|
}
|
|
Debug.LogError(
|
|
$"[CampData]UpdateCurrentData: AreaIndex({AreaIndex}) is out of range[0-{AreaList.Count}]! Will reset to 0");
|
|
AreaIndex = 0;
|
|
}
|
|
|
|
IsUpdataArea = AreaId != AreaList[AreaIndex];
|
|
if (IsUpdataArea)
|
|
{
|
|
AreaId = AreaList[AreaIndex];
|
|
SetArea();
|
|
}
|
|
|
|
if (AreaStepList != null)
|
|
{
|
|
if (AreaStep < 0 || AreaStep >= AreaStepList.Count)
|
|
{
|
|
AreaStep = 0;
|
|
Debug.LogError(
|
|
$"[CampData]UpdateCurrentData: AreaStep({AreaStep}) is out of range[0-{AreaStepList.Count}]! Reset it to 0.");
|
|
}
|
|
|
|
var step_id = AreaStepList[AreaStep];
|
|
SetAreaStep(step_id);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"[CampData]UpdateCurrentData: AreaStepList is empty!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"[CampData]UpdateCurrentData: AreaList is empty!");
|
|
}
|
|
}
|
|
|
|
void SetArea()
|
|
{
|
|
if (_tables.TBArea.DataMap.TryGetValue(AreaId, out var area_data))
|
|
{
|
|
constructionArea = area_data;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"[CampData]UpdateCurrentData: Not found data of area id({AreaId})!");
|
|
}
|
|
AreaIcon = constructionArea.Icon;
|
|
TimelineId = constructionArea.TimelineID;
|
|
|
|
AreaStepCount = constructionArea.StepCount;
|
|
AreaStepList = constructionArea.StepList;
|
|
}
|
|
void SetAreaStep(int step_id)
|
|
{
|
|
if (_tables.TBStep.DataMap.TryGetValue(step_id, out var step_data))
|
|
{
|
|
StepInfo = step_data;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"[CampData]UpdateCurrentData: Not found step data of id({step_id})!");
|
|
}
|
|
}
|
|
void CompleteInit()
|
|
{
|
|
if (AreaList != null)
|
|
{
|
|
int curAreaIndex = AreaList.Count - 1;
|
|
AreaId = AreaList[curAreaIndex];
|
|
|
|
SetArea();
|
|
|
|
if (AreaStepList != null)
|
|
{
|
|
var step_id = AreaStepList[^1];
|
|
SetAreaStep(step_id);
|
|
}
|
|
if (NextMapID == -1 || !_tables.TbConstruction.DataMap.ContainsKey(NextMapID))
|
|
{
|
|
_isOpenSkyscraper = "1";
|
|
PlayFabMgr.Instance.UpdateUserDataValue("IsOpenSkyscraper", _isOpenSkyscraper);
|
|
}
|
|
}
|
|
}
|
|
void SetHome_Skyscraper()
|
|
{
|
|
if (IsOpenSkyscraper)
|
|
{
|
|
if (IsCanSkyscraper)
|
|
{
|
|
ulong curGold = GContext.container.Resolve<PlayerData>().gold;
|
|
ulong basePrice =
|
|
(ulong)GContext.container.Resolve<Tables>().TbMapData.DataList[^1].ConstrutionCost;
|
|
var multiplierTable = GContext.container.Resolve<Tables>().TbConstructionInfiniteConfig.CashMagList;
|
|
var ibData = new InfiniteBuildingData();
|
|
ibData.Deserialize(GContext.container.Resolve<PlayerData>().InfiniteBuildingData);
|
|
int step = ibData.Step;
|
|
ulong price = (ulong)(basePrice * multiplierTable[step]);
|
|
int count = 0;
|
|
while (curGold >= price)
|
|
{
|
|
curGold -= price;
|
|
step++;
|
|
step %= multiplierTable.Count;
|
|
price = (ulong)(basePrice * multiplierTable[step]);
|
|
count++;
|
|
if (count >= 99)
|
|
break;
|
|
}
|
|
|
|
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Skyscraper, count > 0, (int)count);
|
|
}
|
|
else
|
|
{
|
|
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Skyscraper, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool GoBuilding()
|
|
{
|
|
if (AreaStep >= AreaStepList.Count)
|
|
{
|
|
return false;
|
|
}
|
|
long gold = (long)(ulong)GContext.container.Resolve<PlayerData>().gold;
|
|
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<ConstructionCost>();
|
|
bool isConstructionCost = buffTimeData != null;
|
|
long _upgradeCost;
|
|
var step_id = AreaStepList[AreaStep];
|
|
var camp_data = _tables.TbConstruction.DataMap[Id];
|
|
List<int> _areaStepList = AreaStepList;
|
|
int start;
|
|
int endIndex;
|
|
List<int> _areaList;
|
|
if (_MMService.mmBuilding)
|
|
{
|
|
_areaList = camp_data.MmtAreaList;
|
|
|
|
}
|
|
else
|
|
{
|
|
_areaList = camp_data.AreaList;
|
|
}
|
|
start = _tables.TBStep.DataList.IndexOf(_tables.TBStep.DataMap[step_id]);
|
|
if (_tables.TBArea.DataMap.TryGetValue(_areaList[^1], out var area_data))
|
|
{
|
|
_areaStepList = area_data.StepList;
|
|
}
|
|
endIndex = _tables.TBStep.DataList.IndexOf(_tables.TBStep.DataMap[_areaStepList[^1]]);
|
|
List<StepMM> DataList = _tables.TBStep.DataList;
|
|
for (int i = start; i <= endIndex; i++)
|
|
{
|
|
if (isConstructionCost)
|
|
{
|
|
_upgradeCost = (long)(DataList[i].BuildRequired * (1 - buffTimeData.Param));
|
|
}
|
|
else
|
|
{
|
|
_upgradeCost = DataList[i].BuildRequired;
|
|
}
|
|
gold -= _upgradeCost;
|
|
if (gold < 0)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
public bool GoBuilding02(int endId)
|
|
{
|
|
var step_id = AreaStepList[AreaStep];
|
|
if (step_id < 101003 || step_id >= endId)
|
|
{
|
|
return false;
|
|
}
|
|
long gold = (long)(ulong)GContext.container.Resolve<PlayerData>().gold;
|
|
long _upgradeCost;
|
|
|
|
int start = _tables.TBStep.DataList.IndexOf(_tables.TBStep.DataMap[step_id]);
|
|
int endIndex = _tables.TBStep.DataList.IndexOf(_tables.TBStep.DataMap[endId]);
|
|
List<StepMM> DataList = _tables.TBStep.DataList;
|
|
for (int i = start; i < endIndex; i++)
|
|
{
|
|
_upgradeCost = DataList[i].BuildRequired;
|
|
gold -= _upgradeCost;
|
|
if (gold < 0)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void SetRedPoint()
|
|
{
|
|
SetHome_Skyscraper();
|
|
int count = 0;
|
|
bool redPoint = false;
|
|
|
|
if (GContext.container.Resolve<GuideDataCenter>().GetIsFinish(_tables.TbGlobalConfig.BuildRedPointUnlock) && GContext.container.Resolve<PlayerData>().gold >= (ulong)StepInfo.BuildRequired)
|
|
{
|
|
if (AreaStep >= AreaStepList.Count)
|
|
{
|
|
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Build, redPoint, count);
|
|
return;
|
|
}
|
|
var step_id = AreaStepList[AreaStep];
|
|
int nextId = NextMapID;
|
|
var camp_data = _tables.TbConstruction.DataMap[Id];
|
|
while (_tables.TbConstruction.DataMap.TryGetValue(nextId, out var _camp_data))
|
|
{
|
|
camp_data = _camp_data;
|
|
nextId = camp_data.NextID;
|
|
}
|
|
List<int> _areaStepList = AreaStepList;
|
|
long gold = (long)(ulong)GContext.container.Resolve<PlayerData>().gold;
|
|
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<ConstructionCost>();
|
|
bool isConstructionCost = buffTimeData != null;
|
|
long _upgradeCost;
|
|
List<int> BuildRequired = new List<int>();
|
|
List<int> _areaList;
|
|
if (_MMService.mmBuilding)
|
|
{
|
|
_areaList = camp_data.MmtAreaList;
|
|
//TBArea
|
|
}
|
|
else
|
|
{
|
|
_areaList = camp_data.AreaList;
|
|
}
|
|
|
|
int start = _tables.TBStep.DataList.IndexOf(_tables.TBStep.DataMap[step_id]);
|
|
if (_tables.TBArea.DataMap.TryGetValue(_areaList[^1], out var area_data))
|
|
{
|
|
_areaStepList = area_data.StepList;
|
|
}
|
|
int endIndex = _tables.TBStep.DataList.IndexOf(_tables.TBStep.DataMap[_areaStepList[^1]]);
|
|
|
|
int length = start + 100;
|
|
length = Math.Min(length, endIndex + 1);
|
|
|
|
List<StepMM> DataList = _tables.TBStep.DataList;
|
|
for (int i = start; i < length; i++)
|
|
{
|
|
BuildRequired.Add(DataList[i].BuildRequired);
|
|
}
|
|
|
|
for (int i = 0; i < BuildRequired.Count; i++)
|
|
{
|
|
if (isConstructionCost)
|
|
{
|
|
_upgradeCost = (long)(BuildRequired[i] * (1 - buffTimeData.Param));
|
|
}
|
|
else
|
|
{
|
|
_upgradeCost = BuildRequired[i];
|
|
}
|
|
gold -= _upgradeCost;
|
|
if (gold < 0)
|
|
{
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
redPoint = true;
|
|
}
|
|
RedPointManager.Instance.SetRedPointState(RedPointName.Home_Build, redPoint, count);
|
|
}
|
|
|
|
public void NextStep()
|
|
{
|
|
if (AreaStepList != null)
|
|
{
|
|
AreaStep++;
|
|
|
|
if (AreaStep < AreaStepList.Count)
|
|
{
|
|
UpdateCurrentData();
|
|
}
|
|
else
|
|
{
|
|
AreaIndex++;
|
|
if (AreaIndex < AreaList.Count)
|
|
{
|
|
AreaStep = 0;
|
|
UpdateCurrentData();
|
|
}
|
|
else
|
|
{
|
|
AreaIndex = AreaList.Count;
|
|
AreaStep = AreaStepList.Count;
|
|
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GameDebug.LogError($"[CampData]NextStep: AreaStepList is empty!");
|
|
}
|
|
}
|
|
}
|