1389 lines
54 KiB
C#
1389 lines
54 KiB
C#
using asap.core;
|
||
// using Assets.Scripts.UI.OfferSweep;
|
||
using cfg;
|
||
using game;
|
||
using LitJson;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using UnityEngine;
|
||
|
||
namespace GameCore
|
||
{
|
||
public class PlayerData
|
||
{
|
||
private cfg.Tables _tables;
|
||
public PlayerData(cfg.Tables tables)
|
||
{
|
||
this._tables = tables;
|
||
// _MMService = mmService;
|
||
}
|
||
public const string Gold = "Gold";
|
||
/// <summary>
|
||
/// "Diamond"==>"Pearl"(不改名是因为数据已经通过Diamond键存储到云端了)
|
||
/// </summary>
|
||
public const string Pearl = "Diamond";
|
||
public const string RodLevel = "RodLevel";
|
||
public const string WeightScore = "WeightScore";
|
||
public const string Diamond = "DiamondTrue";
|
||
Dictionary<string, string> NewPlayerDataDic = new Dictionary<string, string>();
|
||
public IReadOnlyDictionary<string, string> PlayerDataDic => NewPlayerDataDic;
|
||
public int lv { get; set; }
|
||
public int vip { get; private set; }
|
||
public int vipAllScore { get; private set; }
|
||
public int vipLastScore { get; private set; }
|
||
Dictionary<int, int> vipScoreDic = new Dictionary<int, int>();
|
||
#region 付费积分
|
||
public int PriceLv { get; private set; }
|
||
|
||
public VipLevel priceLevel;
|
||
#endregion 付费积分
|
||
private int energy;
|
||
int energyRM;
|
||
public ulong gold { get; private set; }
|
||
ulong goldRM;
|
||
public int pearl { get; private set; }
|
||
public int diamond { get; private set; }
|
||
|
||
public int equipRodID = 10001;
|
||
public int magnification;
|
||
public int seasonId = 0;
|
||
public int rewardNewMap = 0;
|
||
bool IsOpenAppraise = false;
|
||
int _currentMapId = 0;
|
||
public string InfiniteBuildingData = "0";
|
||
public string InfiniteBuildingLevel => InfiniteBuildingData.Split(',')[0];
|
||
public int currentMapId
|
||
{
|
||
set { _currentMapId = value; }
|
||
get
|
||
{
|
||
if (_currentMapId == 0 || !_tables.TbMapData.DataMap.ContainsKey(_currentMapId))
|
||
{
|
||
_currentMapId = _tables.TbMapData.DataList[0].ID;
|
||
}
|
||
//if (_TestService.TestMapIDs != null)
|
||
//{
|
||
// var ab = _TestService.TestMapIDs.FirstOrDefault(a => a.OldID == _currentMapId);
|
||
// return ab != null ? ab.NewID : _currentMapId;
|
||
//}
|
||
return _currentMapId;
|
||
}
|
||
}
|
||
//膨胀系数
|
||
public float InflationRate { get; private set; }
|
||
|
||
int _lastMapId = 0;
|
||
public int lastMapId
|
||
{
|
||
set { _lastMapId = value; }
|
||
get
|
||
{
|
||
if (_lastMapId == 0)
|
||
{
|
||
_lastMapId = _tables.TbMapData.DataList[0].ID;
|
||
}
|
||
//if (_TestService.TestMapIDs != null)
|
||
//{
|
||
// var ab = _TestService.TestMapIDs.FirstOrDefault(a => a.OldID == _lastMapId);
|
||
// return ab != null ? ab.NewID : _lastMapId;
|
||
//}
|
||
return _lastMapId;
|
||
}
|
||
}
|
||
public int _fishingFrequency = 0;
|
||
public int _allFishingFrequency = 0;
|
||
public List<int> newRodList = new List<int>();
|
||
|
||
public List<int> showNewRodList = new List<int>();
|
||
|
||
bool addShowNewRod = true;
|
||
|
||
public float benefitsCashMag { get; private set; }
|
||
public float benefitsCashMagLimited { get; private set; }
|
||
public int benefitsEnergyLimit { get; private set; }
|
||
public int benefitsEnergyRecover { get; private set; }
|
||
public float benefitsEventFishCashMag { get; private set; }
|
||
public float benefitsEventFishDamage { get; private set; }
|
||
public int benefitsAquariumLimit { get; private set; }
|
||
public float benefitsAquariumCashMag { get; private set; }
|
||
public List<int> benefitsLevel;
|
||
public int OpenGradeID = 0;
|
||
public bool OpenGrade = false;
|
||
public int MagnificationCount
|
||
{
|
||
get
|
||
{
|
||
List<EnergyDef> DataList = _tables.TbEnergyDef.DataList;
|
||
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<SuperEnergyMag>();
|
||
bool isSuperEnergy = buffTimeData != null;
|
||
for (int i = 0; i < DataList.Count; i++)
|
||
{
|
||
int demandEnergy = DataList[i].Energy;
|
||
if (isSuperEnergy)
|
||
{
|
||
demandEnergy = DataList[i].FishBuffEnergy;
|
||
}
|
||
if (demandEnergy < 0 || Energy < demandEnergy)
|
||
{
|
||
return i;
|
||
}
|
||
}
|
||
return DataList.Count;
|
||
}
|
||
}
|
||
public Account nextAccountData;
|
||
public bool IsOpenMagnification = false;
|
||
public int GetCurMaxMagnification()
|
||
{
|
||
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<SuperEnergyMag>();
|
||
bool isSuperEnergy = buffTimeData != null;
|
||
List<EnergyDef> DataList = _tables.TbEnergyDef.DataList;
|
||
for (int i = DataList.Count - 1; i >= 0; i--)
|
||
{
|
||
int demandEnergy = DataList[i].Energy;
|
||
if (isSuperEnergy)
|
||
{
|
||
demandEnergy = DataList[i].FishBuffEnergy;
|
||
}
|
||
if (demandEnergy >= 0)
|
||
{
|
||
if (Energy >= demandEnergy)
|
||
{
|
||
return i;
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
public void SaveFishingFrequency()
|
||
{
|
||
_fishingFrequency++;
|
||
GContext.Publish(new ExchangeFishCount(_fishingFrequency));
|
||
_allFishingFrequency += GContext.container.Resolve<PlayerData>().GetMagnification();
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.GetFishCount, 1));
|
||
SavePlayerData();
|
||
}
|
||
/// <summary>
|
||
/// buff 过期
|
||
/// </summary>
|
||
public void CheckSuperEnergyBuff()
|
||
{
|
||
List<EnergyDef> DataList = _tables.TbEnergyDef.DataList;
|
||
for (int i = DataList.Count - 1; i >= 0; i--)
|
||
{
|
||
if (DataList[i].Energy >= 0)
|
||
{
|
||
if (i < magnification)
|
||
{
|
||
magnification = i;
|
||
SetMagnification();
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
public int Energy
|
||
{
|
||
get => energy;
|
||
private set { SetEnergy(value); }
|
||
}
|
||
int RecoverNotificationID = 1002;
|
||
public int MaxEnergy => benefitsEnergyLimit;
|
||
|
||
public int EnergyRecover => benefitsEnergyRecover;
|
||
|
||
DateTime _lastEnergyRecoveryTime = ZZTimeHelper.UtcNow();
|
||
|
||
public void SetEnergy(int count, bool remote = true)
|
||
{
|
||
if (count < 0)
|
||
{
|
||
count = 0;
|
||
}
|
||
if (count < energy)
|
||
{
|
||
energyRM += energy - count;
|
||
}
|
||
energy = count;
|
||
if (energy >= MaxEnergy)
|
||
{
|
||
GContext.container.Resolve<ILocalNotificationService>().ClearNotification(RecoverNotificationID);
|
||
}
|
||
SavePlayerData(remote);
|
||
}
|
||
public int GetEnergyRM()
|
||
{
|
||
return energyRM;
|
||
}
|
||
public void AddGold(ulong count)
|
||
{
|
||
SetGold(gold + count);
|
||
}
|
||
public void SetGold(ulong count)
|
||
{
|
||
if (count < gold)
|
||
{
|
||
goldRM += gold - count;
|
||
}
|
||
gold = count;
|
||
SavePlayerData();
|
||
}
|
||
|
||
public void SetPearl(int count)
|
||
{
|
||
if (count < 0)
|
||
{
|
||
count = 0;
|
||
}
|
||
pearl = count;
|
||
SavePlayerData();
|
||
GContext.container.Resolve<PlayerFishData>().CheckAllRodUpLevel();
|
||
}
|
||
public void AddDiamond(int count)
|
||
{
|
||
var newCount = diamond + count;
|
||
if (newCount < 0)
|
||
{
|
||
newCount = 0;
|
||
}
|
||
diamond = newCount;
|
||
if (count < 0)
|
||
{
|
||
GContext.Publish(new ConditionTypeEvent { type = ConditionType.ConsumeDiamondCount, count = -count });
|
||
GContext.Publish(new ResAddEvent(1005));
|
||
}
|
||
SavePlayerData();
|
||
}
|
||
|
||
|
||
public void SetEquipRodID(int ID)
|
||
{
|
||
equipRodID = ID;
|
||
GContext.container.Resolve<PlayerFishData>().SetRedPoint();
|
||
SavePlayerData();
|
||
}
|
||
|
||
public void SetMagnification()
|
||
{
|
||
SavePlayerData();
|
||
}
|
||
|
||
public void AddNewMap(int index)
|
||
{
|
||
rewardNewMap |= 1 << index;
|
||
}
|
||
|
||
public void RewardNewMap(int index)
|
||
{
|
||
int newMap = 1 << index;
|
||
rewardNewMap &= ~newMap;
|
||
SavePlayerData();
|
||
}
|
||
|
||
public bool IsNewMap(int index)
|
||
{
|
||
int newMap = 1 << index;
|
||
return (rewardNewMap & newMap) == newMap;
|
||
}
|
||
|
||
|
||
public void AddNewRod(int id)
|
||
{
|
||
if (!newRodList.Contains(id))
|
||
{
|
||
newRodList.Add(id);
|
||
PlayFabMgr.Instance.UpdateUserDataValue("NewRodList", JsonMapper.ToJson(newRodList));
|
||
if (addShowNewRod)
|
||
{
|
||
showNewRodList.Add(id);
|
||
}
|
||
}
|
||
}
|
||
|
||
public void StartAddNewRod()
|
||
{
|
||
addShowNewRod = true;
|
||
}
|
||
|
||
public void ShowNewRod()
|
||
{
|
||
//addShowNewRod = false;
|
||
if (showNewRodList.Count > 0)
|
||
{
|
||
List<ItemData> itemDatas = new List<ItemData>();
|
||
for (int i = 0; i < showNewRodList.Count; i++)
|
||
{
|
||
itemDatas.Add(new ItemData { id = showNewRodList[i], count = 1 });
|
||
}
|
||
GContext.Publish(new ShowData(itemDatas, RewardType.NewRod));
|
||
showNewRodList.Clear();
|
||
}
|
||
}
|
||
|
||
public void RewardNewRod(int id)
|
||
{
|
||
newRodList.Remove(id);
|
||
PlayFabMgr.Instance.UpdateUserDataValue("NewRodList", JsonMapper.ToJson(newRodList));
|
||
GContext.container.Resolve<PlayerFishData>().SetRedPoint();
|
||
}
|
||
|
||
public bool IsNewRod(int id)
|
||
{
|
||
return newRodList.Contains(id);
|
||
}
|
||
|
||
public void SetLv(int count)
|
||
{
|
||
int addLevel = count - lv;
|
||
|
||
lv = count;
|
||
|
||
#if AGG
|
||
GEvent.SetProp("building_times", count);
|
||
GEvent.SetUserProp("building_times", count);
|
||
#endif
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.AccountLevel, addLevel));
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.ConstructionCount, addLevel));
|
||
OnLvChange();
|
||
SavePlayerData();
|
||
GContext.container.Resolve<LeadboardData>().AwaitSetLvData();
|
||
}
|
||
//等级改变的时候
|
||
|
||
public void OnLvChange()
|
||
{
|
||
var account = _tables.TbAccount.DataList;
|
||
nextAccountData = account[^1];
|
||
|
||
Account curAccountData = null;
|
||
for (int i = 0; i < account.Count; i++)
|
||
{
|
||
if (lv < account[i].ID)
|
||
{
|
||
nextAccountData = account[i];
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
curAccountData = account[i];
|
||
}
|
||
}
|
||
SetBenefits(curAccountData);
|
||
//解锁地图
|
||
int unLockIndex = 0;
|
||
var dataList = _tables.TbMapData.DataList;
|
||
var mapData = dataList[^1];
|
||
int count = dataList.Count;
|
||
InflationRate = 0;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
if (lv < dataList[i].LevelRequired)
|
||
{
|
||
unLockIndex = i;
|
||
mapData = dataList[i];
|
||
break;
|
||
}
|
||
//计算膨胀系数
|
||
InflationRate = dataList[i].LureScalePercent / 100;
|
||
}
|
||
int newMapId = mapData.ID;
|
||
|
||
if (lastMapId != newMapId)
|
||
{
|
||
lastMapId = newMapId;
|
||
LoadNewMap();
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("open_new"))
|
||
{
|
||
e.AddContent("open_type", 1)
|
||
.AddContent("map_id", lastMapId);
|
||
|
||
}
|
||
#endif
|
||
if (unLockIndex > 0)
|
||
{
|
||
AddNewMap(unLockIndex);
|
||
}
|
||
}
|
||
GContext.Publish(new OnLvChangeEvent() { lvl = lv });
|
||
if (lv >= _tables.TbGlobalConfig.NotPopUpUnlockLevel
|
||
&& GContext.container.Resolve<ISettingService>().CheckRequestPermission())
|
||
{
|
||
GContext.container.Resolve<IFaceUIService>().AddFaceCustomUIData(new UIType("SettingNotificationsGradePopupPanel"));
|
||
}
|
||
}
|
||
void SetBenefits(Account curAccountData)
|
||
{
|
||
int levelCashMag = 0;
|
||
int levelCashMagLimited = 0;
|
||
int levelEnergyLimit = 0;
|
||
int levelEnergyRecover = 0;
|
||
int levelEventFishCashMag = 0;
|
||
int levelEventFishDamage = 0;
|
||
int levelAquariumLimit = 0;
|
||
int levelAquariumCashMag = 0;
|
||
if (curAccountData != null)
|
||
{
|
||
levelCashMag = curAccountData.CashMag;
|
||
levelCashMagLimited = curAccountData.CashMagLimited;
|
||
levelEnergyLimit = curAccountData.EnergyLimit;
|
||
levelEnergyRecover = curAccountData.EnergyRecover;
|
||
levelEventFishCashMag = curAccountData.EventFishCashMag;
|
||
levelEventFishDamage = curAccountData.EventFishDamage;
|
||
levelAquariumLimit = curAccountData.AquariumLimit;
|
||
levelAquariumCashMag = curAccountData.AquariumCashMag;
|
||
}
|
||
benefitsLevel = new List<int>
|
||
{
|
||
levelCashMag,
|
||
levelCashMagLimited,
|
||
levelEnergyLimit,
|
||
levelEnergyRecover,
|
||
levelEventFishCashMag,
|
||
levelEventFishDamage,
|
||
levelAquariumLimit,
|
||
levelAquariumCashMag,
|
||
};
|
||
var TbBenefits = _tables.TbBenefits;
|
||
benefitsCashMag = TbBenefits.GetOrDefault(1).BenefitsValue[levelCashMag];
|
||
benefitsCashMagLimited = TbBenefits.GetOrDefault(2).BenefitsValue[levelCashMagLimited];
|
||
benefitsEnergyLimit = Mathf.RoundToInt(TbBenefits.GetOrDefault(3).BenefitsValue[levelEnergyLimit]);
|
||
benefitsEnergyRecover = Mathf.RoundToInt(TbBenefits.GetOrDefault(4).BenefitsValue[levelEnergyRecover]);
|
||
benefitsEventFishCashMag = TbBenefits.GetOrDefault(5).BenefitsValue[levelEventFishCashMag];
|
||
benefitsEventFishDamage = TbBenefits.GetOrDefault(6).BenefitsValue[levelEventFishDamage];
|
||
benefitsAquariumLimit = Mathf.RoundToInt(TbBenefits.GetOrDefault(7).BenefitsValue[levelAquariumLimit]);
|
||
benefitsAquariumCashMag = TbBenefits.GetOrDefault(8).BenefitsValue[levelAquariumCashMag];
|
||
}
|
||
public void LoadNewMap()
|
||
{
|
||
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||
var mapData = _tables.TbMapData.GetOrDefault(lastMapId);
|
||
if (mapData != null && mapData.DownloadPkg != null && mapData.DownloadPkg.Count > 0)
|
||
{
|
||
var fishList = _tables.TbAquariumConfig.AquariumSpFishList;
|
||
List<string> strings = new List<string>();
|
||
foreach (var fish in fishList)
|
||
{
|
||
var item = _tables.TbItem.GetOrDefault(fish);
|
||
var fishData = _tables.TbFishData.GetOrDefault(item.RedirectID);
|
||
if (item != null && !string.IsNullOrEmpty(fishData.Fbx))
|
||
{
|
||
strings.Add(fishData.Fbx);
|
||
}
|
||
}
|
||
strings.AddRange(mapData.DownloadPkg);
|
||
strings.Add("entermap");
|
||
loadResourceService.EnqueueBundleSilently(strings);
|
||
}
|
||
}
|
||
public MapData GetCurrentMapData()
|
||
{
|
||
return _tables.TbMapData.GetOrDefault(currentMapId);
|
||
}
|
||
public bool MapIsUnlock(List<string> Param)
|
||
{
|
||
return Param.Contains(lastMapId.ToString());
|
||
}
|
||
public void SetCurrentMapId(int id)
|
||
{
|
||
currentMapId = id;
|
||
SavePlayerData();
|
||
}
|
||
|
||
public void AddVIPScore(int count, bool isBuy = false)
|
||
{
|
||
UpdateVIPScoreDic();
|
||
|
||
vipAllScore += count;
|
||
if (vipScoreDic.ContainsKey(0))
|
||
{
|
||
vipScoreDic[0] += count;
|
||
}
|
||
else
|
||
{
|
||
vipScoreDic[0] = count;
|
||
}
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("getpoint_vip"))
|
||
{
|
||
e.AddContent("add_count", count).AddContent("all_count", vipAllScore);
|
||
}
|
||
#endif
|
||
VipChange();
|
||
SavePlayerData();
|
||
}
|
||
void VipChange()
|
||
{
|
||
vipLastScore = vipScoreDic.Where(_ => _.Key >= 0 && _.Key < 10).Select(_ => _.Value).Sum();
|
||
SetVIP();
|
||
}
|
||
public void SetPriceLevel(int level)
|
||
{
|
||
priceLevel = _tables.TbVipLevel.GetOrDefault(level);
|
||
var dynamicVipParam = _tables.TbGlobalConfig.DynamicVipParam;
|
||
vipAllScore = 0;
|
||
vipScoreDic.Clear();
|
||
vipScoreDic[0] = level == 0 ? 0 : (int)(priceLevel.LevelScore / dynamicVipParam[1]) + 1;
|
||
VipChange();
|
||
}
|
||
void SetVIP()
|
||
{
|
||
int LevelScore = 0;
|
||
//设置vip等级
|
||
var vipData = _tables.TbVipLevel.DataList;
|
||
PriceLv = vip = vipData.Count - 1;
|
||
//付费等级=f1(vip积分,地区积分)+f2(活跃积分)
|
||
var dynamicVipParam = _tables.TbGlobalConfig.DynamicVipParam;
|
||
|
||
int allPackPoints = (int)(vipAllScore * dynamicVipParam[0] + vipLastScore * dynamicVipParam[1]);
|
||
for (int i = 0; i < vipData.Count; i++)
|
||
{
|
||
LevelScore += vipData[i].LevelScore;
|
||
if (i < vip && vipAllScore < LevelScore)
|
||
{
|
||
vip = i;
|
||
}
|
||
if (i < PriceLv && allPackPoints < LevelScore)
|
||
{
|
||
PriceLv = i;
|
||
}
|
||
}
|
||
int dynamicVipLifeTime = _tables.TbGlobalConfig.DynamicVipLifeTime;
|
||
var userService = GContext.container.Resolve<IUserService>();
|
||
//注册时间
|
||
var register_days = (ZZTimeHelper.UtcNow() - userService.CreateTime).TotalSeconds;
|
||
if (register_days < dynamicVipLifeTime)
|
||
{
|
||
PriceLv = vip;
|
||
}
|
||
|
||
priceLevel = vipData[PriceLv];
|
||
#if AGG
|
||
GEvent.SetProp("Dynamic_Vip_Level", PriceLv);
|
||
GEvent.SetUserProp("Dynamic_Vip_Level", PriceLv);
|
||
|
||
GEvent.SetProp("vip_level", vip);
|
||
GEvent.SetUserProp("vip_level", vip);
|
||
#endif
|
||
}
|
||
public void LoadPlayerData(Dictionary<string, string> userDatas)
|
||
{
|
||
lv = 1;
|
||
gold = (ulong)_tables.TbGlobalConfig.InitCash;
|
||
vipAllScore = 0;
|
||
vipLastScore = 0;
|
||
energy = _tables.TbGlobalConfig.InitEnergy;
|
||
pearl = _tables.TbGlobalConfig.InitResin;
|
||
magnification = 0;
|
||
equipRodID = _tables.TbGlobalConfig.InitRodID;
|
||
_lastEnergyRecoveryTime = ZZTimeHelper.UtcNow();
|
||
rewardNewMap = 0b1;
|
||
GContext.container.Resolve<PlayerShopData>().InitData(userDatas);
|
||
if (userDatas == null || userDatas.Count < 1)
|
||
{
|
||
GameDebug.Log(
|
||
"[PlayerData]LoadPlayerData: No player data in User Data, initializing with default values");
|
||
}
|
||
else
|
||
{
|
||
GameDebug.Log("[PlayerData]LoadPlayerData: Load Player data from User Data");
|
||
GContext.container.Resolve<PlayerFishData>().InitData(userDatas);
|
||
GContext.container.Resolve<FishingEventData>().InitData(userDatas);
|
||
|
||
GContext.container.Resolve<BuffDataCenter>().InitData(userDatas);
|
||
|
||
GContext.container.Resolve<CampDataMM>().InitData(userDatas);
|
||
|
||
var etor = userDatas.GetEnumerator();
|
||
|
||
while (etor.MoveNext())
|
||
{
|
||
var data_key = etor.Current.Key;
|
||
var data_value = etor.Current.Value;
|
||
|
||
switch (data_key)
|
||
{
|
||
|
||
#region 旧数据兼容
|
||
case "Lv":
|
||
lv = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
case "Energy":
|
||
energy = GlobalUtils.TryParseInt(data_value, _tables.TbGlobalConfig.InitEnergy);
|
||
if (energy < 0)
|
||
{
|
||
energy = 0;
|
||
}
|
||
break;
|
||
case "EnergyRM":
|
||
energyRM = GlobalUtils.TryParseInt(data_value, 0);
|
||
break;
|
||
case "Gold":
|
||
gold = GlobalUtils.TryParseUlong(data_value, (ulong)_tables.TbGlobalConfig.InitCash);
|
||
break;
|
||
case "GoldRM":
|
||
goldRM = GlobalUtils.TryParseUlong(data_value, 0);
|
||
break;
|
||
case Pearl:
|
||
pearl = GlobalUtils.TryParseInt(data_value, 0);
|
||
break;
|
||
case Diamond:
|
||
diamond = GlobalUtils.TryParseInt(data_value, 0);
|
||
break;
|
||
case "Magnification":
|
||
magnification = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
case "EquipRodID":
|
||
equipRodID = GlobalUtils.TryParseInt(data_value);
|
||
if (!_tables.TbRodData.DataMap.ContainsKey(equipRodID))
|
||
{
|
||
equipRodID = _tables.TbGlobalConfig.InitRodID;
|
||
}
|
||
break;
|
||
case "LastEnergyRecoveryTime":
|
||
_lastEnergyRecoveryTime = GlobalUtils.TryParseDateTime(data_value, ZZTimeHelper.UtcNow());
|
||
break;
|
||
|
||
case "RewardNewMap":
|
||
rewardNewMap = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
|
||
case "vipAllScore":
|
||
vipAllScore = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
|
||
case "CurrentMapId":
|
||
currentMapId = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
case "LastMapId":
|
||
lastMapId = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
case "FishingFrequency":
|
||
_fishingFrequency = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
case "AllFishingFrequency":
|
||
_allFishingFrequency = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
case "HeistGameCount":
|
||
GContext.container.Resolve<SmallGameData>().SetHeistGameCount(GlobalUtils.TryParseInt(data_value));
|
||
break;
|
||
case "BombGameCount":
|
||
GContext.container.Resolve<SmallGameData>().SetBombGameCount(GlobalUtils.TryParseInt(data_value));
|
||
break;
|
||
case "FishHuntGameCount":
|
||
GContext.container.Resolve<SmallGameData>().SetFishHuntGameCount(GlobalUtils.TryParseInt(data_value));
|
||
break;
|
||
|
||
case "LuckDataDic":
|
||
GContext.container.Resolve<PlayerFishData>().LuckDataDic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, float>>(data_value);
|
||
break;
|
||
|
||
case "AchievementData":
|
||
GContext.container.Resolve<AchievementDataManager>().LoadAchievementData(data_value);
|
||
break;
|
||
case "FishingBoxData":
|
||
GContext.container.Resolve<FishingBoxData>().InitData(data_value);
|
||
break;
|
||
|
||
case "GuideSaveData":
|
||
try
|
||
{
|
||
var guideSaveData = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, GuideSaveData>>(data_value);
|
||
if (guideSaveData != null)
|
||
{
|
||
GContext.container.Resolve<GuideDataCenter>().GuideSaveDataDic = guideSaveData;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
GameDebug.LogWarning($"[PlayerData]LoadPlayerData: Fail to parse GuideSaveData {data_value}!");
|
||
}
|
||
break;
|
||
#endregion 旧数据兼容
|
||
|
||
case "NewRodList":
|
||
newRodList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>(data_value);
|
||
break;
|
||
case "SeasonId":
|
||
GContext.container.Resolve<PlayerData>().seasonId = GlobalUtils.TryParseInt(data_value);
|
||
break;
|
||
|
||
case "MonthlySignEvent":
|
||
GContext.container.Resolve<SigninData>().monthlySignEvent = Newtonsoft.Json.JsonConvert.DeserializeObject<MonthlySignEvent>(data_value);
|
||
break;
|
||
|
||
case "TriggerPackDataList":
|
||
GContext.container.Resolve<TriggerPackData>().triggerPackList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TriggerPackBuyData>>(data_value);
|
||
break;
|
||
case "GiftVIPDData":
|
||
var giftVIPDData = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, GiftVIPDData>>(data_value);
|
||
GContext.container.Resolve<TriggerPackData>().giftVIPDData = giftVIPDData;
|
||
break;
|
||
case "FixedTimeShopDic":
|
||
var FixedTimeshopDic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<int, FixedTimeEvent>>(data_value);
|
||
GContext.container.Resolve<TriggerPackData>().SetFixedTimeShopDic(FixedTimeshopDic);
|
||
break;
|
||
|
||
case "ClubSignin":
|
||
break;
|
||
case "LureDonateData":
|
||
break;
|
||
|
||
case "IsOpenAppraise":
|
||
IsOpenAppraise = true;
|
||
break;
|
||
|
||
//case "MonthCardData":
|
||
// GContext.container.Resolve<MonthCardDataConter>().InitMonthCardData(data_value);
|
||
// break;
|
||
// case "ChallengeData":
|
||
// break;
|
||
// case "FishingChallengeData":
|
||
// break;
|
||
// break;
|
||
// break;
|
||
|
||
// break;
|
||
// break;
|
||
|
||
//case "TargetEventPackData":
|
||
// GContext.container.Resolve<PlayerShopData>().InitTargetEventData(data_value);
|
||
// break;
|
||
|
||
|
||
case "IsOpenClubRed":
|
||
break;
|
||
//case "PokerScoreData":
|
||
// GContext.container.Resolve<PokerScoreData>().InitPockerScore(data_value);
|
||
// break;
|
||
|
||
case "EventPackData":
|
||
GContext.container.Resolve<EventPackData>().LoadEventPackData(data_value);
|
||
break;
|
||
|
||
|
||
case "PiggyBankPackData":
|
||
break;
|
||
case "GeneralEventPackData":
|
||
var tempData = JsonConvert.DeserializeObject<GeneralEventPackData>(data_value);
|
||
int packType = _tables.TbEventPackManager[tempData.redirectID].PackType;
|
||
switch (packType)
|
||
{
|
||
case 3:
|
||
GContext.container.Resolve<BargainPackData>().LoadData(tempData);
|
||
break;
|
||
}
|
||
break;
|
||
case "InfiniteBuildingData":
|
||
InfiniteBuildingData = data_value;
|
||
break;
|
||
/* case "EventPartnerData":
|
||
GContext.container.Resolve<EventPartnerData>().LoadPlayfabData(data_value);
|
||
break; */
|
||
|
||
case "FootPrint":
|
||
GContext.container.Resolve<IFootPrintService>().LoadData(data_value);
|
||
break;
|
||
// if (data == null)
|
||
// {
|
||
// }
|
||
// data.LoadData(data_value);
|
||
// break;
|
||
// break;
|
||
// break;
|
||
// break;
|
||
// break;
|
||
// break;
|
||
// break;
|
||
// break;
|
||
// case nameof(EventPinataPackData):
|
||
// break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
LoadPlayerDataNew(userDatas);
|
||
}
|
||
// 新版玩家数据加载
|
||
public void LoadPlayerDataNew(Dictionary<string, string> userDatas)
|
||
{
|
||
if (userDatas.TryGetValue("NewPlayerDataDic", out string newPlayerDataDic))
|
||
{
|
||
NewPlayerDataDic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(newPlayerDataDic);
|
||
SetPlayerData();
|
||
}
|
||
GContext.container.Resolve<BattlePassData>().InitData(userDatas);
|
||
if (userDatas.TryGetValue("GuideSaveDataNew", out string data_value))
|
||
{
|
||
try
|
||
{
|
||
GContext.container.Resolve<GuideDataCenter>().SetData(data_value);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
GameDebug.LogWarning($"[PlayerData]LoadPlayerData: Fail to parse GuideSaveData {data_value}!");
|
||
}
|
||
}
|
||
}
|
||
void SetPlayerDataOld()
|
||
{
|
||
string data_value;
|
||
//========================兼容=========================
|
||
if (NewPlayerDataDic.TryGetValue("lv", out data_value))
|
||
{
|
||
lv = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("lv");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("gold", out data_value))
|
||
{
|
||
gold = GlobalUtils.TryParseUlong(data_value, (ulong)_tables.TbGlobalConfig.InitCash);
|
||
NewPlayerDataDic.Remove("gold");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("vipS", out data_value))
|
||
{
|
||
vipAllScore = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("vipS");
|
||
}
|
||
|
||
if (NewPlayerDataDic.TryGetValue("energy", out data_value))
|
||
{
|
||
energy = GlobalUtils.TryParseInt(data_value);
|
||
if (energy < 0)
|
||
{
|
||
energy = 0;
|
||
}
|
||
NewPlayerDataDic.Remove("energy");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("pearl", out data_value))
|
||
{
|
||
pearl = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("pearl");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("mag", out data_value))
|
||
{
|
||
magnification = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("mag");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("rodID", out data_value))
|
||
{
|
||
equipRodID = GlobalUtils.TryParseInt(data_value);
|
||
if (!_tables.TbRodData.DataMap.ContainsKey(equipRodID))
|
||
{
|
||
equipRodID = _tables.TbGlobalConfig.InitRodID;
|
||
}
|
||
NewPlayerDataDic.Remove("rodID");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("EnergyTime", out data_value))
|
||
{
|
||
_lastEnergyRecoveryTime = GlobalUtils.TryParseDateTime(data_value, ZZTimeHelper.UtcNow());
|
||
|
||
NewPlayerDataDic.Remove("EnergyTime");
|
||
}
|
||
|
||
if (NewPlayerDataDic.TryGetValue("rewardNewMap", out data_value))
|
||
{
|
||
rewardNewMap = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("rewardNewMap");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("energyRM", out data_value))
|
||
{
|
||
energyRM = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("energyRM");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("goldRM", out data_value))
|
||
{
|
||
goldRM = GlobalUtils.TryParseUlong(data_value);
|
||
NewPlayerDataDic.Remove("goldRM");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("diamond", out data_value))
|
||
{
|
||
diamond = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("diamond");
|
||
}
|
||
|
||
if (NewPlayerDataDic.TryGetValue("cMapID", out data_value))
|
||
{
|
||
currentMapId = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("cMapID");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("lMapID", out data_value))
|
||
{
|
||
lastMapId = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("lMapID");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("FF", out data_value))
|
||
{
|
||
_fishingFrequency = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("FF");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("AFF", out data_value))
|
||
{
|
||
_allFishingFrequency = GlobalUtils.TryParseInt(data_value);
|
||
NewPlayerDataDic.Remove("AFF");
|
||
}
|
||
SmallGameData smallGameData = GContext.container.Resolve<SmallGameData>();
|
||
if (NewPlayerDataDic.TryGetValue("HGC", out data_value))
|
||
{
|
||
smallGameData.SetHeistGameCount(GlobalUtils.TryParseInt(data_value));
|
||
NewPlayerDataDic.Remove("HGC");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("BGC", out data_value))
|
||
{
|
||
smallGameData.SetBombGameCount(GlobalUtils.TryParseInt(data_value));
|
||
NewPlayerDataDic.Remove("BGC");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("FHGC", out data_value))
|
||
{
|
||
smallGameData.SetFishHuntGameCount(GlobalUtils.TryParseInt(data_value));
|
||
NewPlayerDataDic.Remove("FHGC");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("LDD", out data_value))
|
||
{
|
||
GContext.container.Resolve<PlayerFishData>().LuckDataDic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, float>>(data_value);
|
||
NewPlayerDataDic.Remove("LDD");
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("AD", out data_value))
|
||
{
|
||
GContext.container.Resolve<AchievementDataManager>().LoadAchievementDataToObject(data_value);
|
||
NewPlayerDataDic.Remove("AD");
|
||
}
|
||
//========================兼容=========================
|
||
}
|
||
void SetPlayerData()
|
||
{
|
||
SetPlayerDataOld();
|
||
string data_value;
|
||
|
||
if (NewPlayerDataDic.TryGetValue("newData", out data_value))
|
||
{
|
||
string[] strings = data_value.Split(',');
|
||
if (strings.Length > 18)
|
||
{
|
||
lv = GlobalUtils.TryParseInt(strings[0]);
|
||
gold = GlobalUtils.TryParseUlong(strings[1], (ulong)_tables.TbGlobalConfig.InitCash);
|
||
vipAllScore = GlobalUtils.TryParseInt(strings[2]);
|
||
energy = GlobalUtils.TryParseInt(strings[3]);
|
||
if (energy < 0)
|
||
{
|
||
energy = 0;
|
||
}
|
||
pearl = GlobalUtils.TryParseInt(strings[4]);
|
||
magnification = GlobalUtils.TryParseInt(strings[5]);
|
||
equipRodID = GlobalUtils.TryParseInt(strings[6]);
|
||
if (!_tables.TbRodData.DataMap.ContainsKey(equipRodID))
|
||
{
|
||
equipRodID = _tables.TbGlobalConfig.InitRodID;
|
||
}
|
||
_lastEnergyRecoveryTime = GlobalUtils.TryParseDateTime(strings[7], ZZTimeHelper.UtcNow());
|
||
rewardNewMap = GlobalUtils.TryParseInt(strings[8]);
|
||
energyRM = GlobalUtils.TryParseInt(strings[9]);
|
||
goldRM = GlobalUtils.TryParseUlong(strings[10]);
|
||
diamond = GlobalUtils.TryParseInt(strings[11]);
|
||
currentMapId = GlobalUtils.TryParseInt(strings[12]);
|
||
lastMapId = GlobalUtils.TryParseInt(strings[13]);
|
||
_fishingFrequency = GlobalUtils.TryParseInt(strings[14]);
|
||
_allFishingFrequency = GlobalUtils.TryParseInt(strings[15]);
|
||
SmallGameData smallGameData = GContext.container.Resolve<SmallGameData>();
|
||
smallGameData.SetHeistGameCount(GlobalUtils.TryParseInt(strings[16]));
|
||
smallGameData.SetBombGameCount(GlobalUtils.TryParseInt(strings[17]));
|
||
smallGameData.SetFishHuntGameCount(GlobalUtils.TryParseInt(strings[18]));
|
||
}
|
||
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("vipL", out data_value))
|
||
{
|
||
vipScoreDic = data_value.Split('|').Select(part => part.Split(','))
|
||
.ToDictionary(arr => int.Parse(arr[0]), arr => int.Parse(arr[1]));
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("ld", out data_value))
|
||
{
|
||
string[] luckDataDic = data_value.Split('|');
|
||
var LuckDataDic = new Dictionary<string, float>();
|
||
if (luckDataDic.Length == 3)
|
||
{
|
||
LuckDataDic["InitFishLuck"] = float.Parse(luckDataDic[0]);
|
||
LuckDataDic["InitBotLuck"] = float.Parse(luckDataDic[1]);
|
||
LuckDataDic["BotCount"] = float.Parse(luckDataDic[2]);
|
||
}
|
||
GContext.container.Resolve<PlayerFishData>().LuckDataDic = LuckDataDic;
|
||
}
|
||
|
||
if (NewPlayerDataDic.TryGetValue("ad", out data_value))
|
||
{
|
||
GContext.container.Resolve<AchievementDataManager>().LoadAchievementDataToObjectNew(data_value);
|
||
}
|
||
|
||
if (NewPlayerDataDic.TryGetValue("bd", out data_value))
|
||
{
|
||
GContext.container.Resolve<FishingBoxData>().InitDataNew(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("ct", out data_value))
|
||
{
|
||
GContext.container.Resolve<FishingEventData>().CTDeserialize(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("rt", out data_value))
|
||
{
|
||
GContext.container.Resolve<FishingEventData>().RTDeserialize(data_value);
|
||
}
|
||
}
|
||
public void UpdateVIPScoreDic()
|
||
{
|
||
int currentDayOfYear = (int)(ZZTimeHelper.UtcNow() - new DateTime(2025, 10, 20)).TotalDays;
|
||
if (!vipScoreDic.ContainsKey(-1))
|
||
{
|
||
vipScoreDic[-1] = currentDayOfYear;
|
||
}
|
||
if (currentDayOfYear > vipScoreDic[-1])
|
||
{
|
||
int offsetDays = currentDayOfYear - vipScoreDic[-1];
|
||
var scoreDic = new Dictionary<int, int>();
|
||
foreach (var kvp in vipScoreDic)
|
||
{
|
||
if (kvp.Key >= 0 && kvp.Key < 14 - offsetDays)
|
||
{
|
||
scoreDic[kvp.Key + offsetDays] = kvp.Value;
|
||
}
|
||
}
|
||
scoreDic[-1] = currentDayOfYear;
|
||
scoreDic[0] = 0;
|
||
vipScoreDic = scoreDic;
|
||
}
|
||
else if (currentDayOfYear < vipScoreDic[-1])
|
||
{
|
||
vipScoreDic[-1] = currentDayOfYear;
|
||
}
|
||
}
|
||
public void SavePlayerData(bool remote = true)
|
||
{
|
||
GContext.Publish<PlayerData>(this);
|
||
StringBuilder sb = new StringBuilder();
|
||
sb.Append(lv).Append(",");
|
||
sb.Append(gold).Append(",");
|
||
sb.Append(vipAllScore).Append(",");
|
||
sb.Append(energy).Append(",");
|
||
sb.Append(pearl).Append(",");
|
||
sb.Append(magnification).Append(",");
|
||
sb.Append(equipRodID).Append(",");
|
||
sb.Append(_lastEnergyRecoveryTime.ToString()).Append(",");
|
||
sb.Append(rewardNewMap).Append(",");
|
||
sb.Append(energyRM).Append(",");
|
||
sb.Append(goldRM).Append(",");
|
||
sb.Append(diamond).Append(",");
|
||
sb.Append(currentMapId).Append(",");
|
||
sb.Append(lastMapId).Append(",");
|
||
sb.Append(_fishingFrequency).Append(",");
|
||
sb.Append(_allFishingFrequency).Append(",");
|
||
SmallGameData smallGameData = GContext.container.Resolve<SmallGameData>();
|
||
sb.Append(smallGameData.HeistGameCount).Append(",");
|
||
sb.Append(smallGameData.BombGameCount).Append(",");
|
||
sb.Append(smallGameData.FishHuntGameCount);
|
||
NewPlayerDataDic["newData"] = sb.ToString();
|
||
|
||
string vipl = vipScoreDic.Select(kvp => $"{kvp.Key},{kvp.Value}").Aggregate((a, b) => $"{a}|{b}");
|
||
//GameDebug.Log($"[PlayerData]SavePlayerData: vipScoreDic string = {vipl}");
|
||
NewPlayerDataDic["vipL"] = vipl;
|
||
string luckDataDic = "";
|
||
var LuckDataDic = GContext.container.Resolve<PlayerFishData>().LuckDataDic;
|
||
luckDataDic += LuckDataDic.GetValueOrDefault("InitFishLuck") + "|";
|
||
luckDataDic += LuckDataDic.GetValueOrDefault("InitBotLuck") + "|";
|
||
luckDataDic += LuckDataDic.GetValueOrDefault("BotCount");
|
||
|
||
NewPlayerDataDic["ld"] = luckDataDic;
|
||
|
||
NewPlayerDataDic["ad"] = GContext.container.Resolve<AchievementDataManager>().AchievementDataToJson();
|
||
|
||
NewPlayerDataDic["bd"] = GContext.container.Resolve<FishingBoxData>().GetString();
|
||
|
||
NewPlayerDataDic["ct"] = GContext.container.Resolve<FishingEventData>().CTSerialize();
|
||
NewPlayerDataDic["rt"] = GContext.container.Resolve<FishingEventData>().RTSerialize(); ;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("NewPlayerDataDic", Newtonsoft.Json.JsonConvert.SerializeObject(NewPlayerDataDic), remote);
|
||
}
|
||
public void Init()
|
||
{
|
||
OnLvChange();
|
||
UpdateVIPScoreDic();
|
||
VipChange();
|
||
RecoveryEnergy();
|
||
}
|
||
void InitEnergy()
|
||
{
|
||
List<EnergyDef> DataList = _tables.TbEnergyDef.DataList;
|
||
if (magnification >= DataList.Count)
|
||
{
|
||
magnification = 0;
|
||
}
|
||
EnergyDef energyDef = DataList[magnification];
|
||
if (energyDef.Energy >= 0)
|
||
{
|
||
return;
|
||
}
|
||
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<SuperEnergyMag>();
|
||
bool isSuperEnergy = buffTimeData != null;
|
||
if (isSuperEnergy)
|
||
{
|
||
return;
|
||
}
|
||
for (int i = DataList.Count - 1; i >= 0; i--)
|
||
{
|
||
if (DataList[i].Energy >= 0)
|
||
{
|
||
if (i < magnification)
|
||
{
|
||
magnification = i;
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
public bool ContainsOrGreaterRatio(int ratio)
|
||
{
|
||
List<EnergyDef> DataList = _tables.TbEnergyDef.DataList;
|
||
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<SuperEnergyMag>();
|
||
bool isSuperEnergy = buffTimeData != null;
|
||
for (int i = 0; i < DataList.Count; i++)
|
||
{
|
||
int demandEnergy = DataList[i].Energy;
|
||
if (isSuperEnergy)
|
||
{
|
||
demandEnergy = DataList[i].FishBuffEnergy;
|
||
}
|
||
if (demandEnergy >= 0 && Energy > demandEnergy)
|
||
{
|
||
if (ratio <= DataList[i].Mag)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
public int GetMagnification()
|
||
{
|
||
if (magnification >= _tables.TbEnergyDef.DataList.Count)
|
||
{
|
||
magnification = _tables.TbEnergyDef.DataList.Count - 1;
|
||
}
|
||
return _tables.TbEnergyDef.DataList[magnification].Mag;
|
||
}
|
||
public string GetMagnificationIcon()
|
||
{
|
||
if (magnification >= _tables.TbEnergyDef.DataList.Count)
|
||
{
|
||
magnification = _tables.TbEnergyDef.DataList.Count - 1;
|
||
}
|
||
return _tables.TbEnergyDef.DataList[magnification].Icon;
|
||
}
|
||
public int SetLittleMagnification()
|
||
{
|
||
List<EnergyDef> DataList = _tables.TbEnergyDef.DataList;
|
||
for (int i = 3; i >= 0; i--)
|
||
{
|
||
int demandEnergy = DataList[i].Mag;
|
||
|
||
if (demandEnergy >= 0)
|
||
{
|
||
if (Energy >= demandEnergy)
|
||
{
|
||
return i;
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
public float GetLuckMultipier()
|
||
{
|
||
if (magnification >= _tables.TbEnergyDef.DataList.Count)
|
||
{
|
||
magnification = _tables.TbEnergyDef.DataList.Count - 1;
|
||
}
|
||
return _tables.TbEnergyDef.DataList[magnification].LuckMultipier;
|
||
}
|
||
public bool GetCanMagnification()
|
||
{
|
||
return GetMagnification() <= Energy;
|
||
}
|
||
public bool GetCanRetryCost()
|
||
{
|
||
if (magnification >= _tables.TbEnergyDef.DataList.Count)
|
||
{
|
||
magnification = _tables.TbEnergyDef.DataList.Count - 1;
|
||
}
|
||
return _tables.TbEnergyDef.DataList[magnification].RetryCost <= Energy;
|
||
}
|
||
public bool IsShowEffectBeilvLoop()
|
||
{
|
||
return _tables.TbEnergyDef.DataList[magnification + 1].Mag <= Energy;
|
||
}
|
||
public bool IsMaxMagnification()
|
||
{
|
||
return magnification >= MagnificationCount - 1;
|
||
}
|
||
|
||
bool _isRecoveryEnergy;
|
||
public void RecoveryEnergy(int time)
|
||
{
|
||
_lastEnergyRecoveryTime = ZZTimeHelper.UtcNow();
|
||
SavePlayerData();
|
||
if (!_isRecoveryEnergy)
|
||
{
|
||
CoRecoveryEnergy(time);
|
||
if (Energy < MaxEnergy)
|
||
{
|
||
SetRecoverNotification();
|
||
}
|
||
}
|
||
}
|
||
private System.Threading.CancellationTokenSource tokenSource;
|
||
public void RecoveryEnergy()
|
||
{
|
||
InitEnergy();
|
||
CoRecoveryEnergy((int)((ZZTimeHelper.UtcNow() - _lastEnergyRecoveryTime).TotalSeconds));
|
||
if (Energy < MaxEnergy)
|
||
{
|
||
SetRecoverNotification();
|
||
}
|
||
}
|
||
public void StopRecoveryEnergy()
|
||
{
|
||
tokenSource?.Cancel();
|
||
tokenSource = null;
|
||
}
|
||
public async void CoRecoveryEnergy(int energyRecoveryTime)
|
||
{
|
||
tokenSource?.Cancel();
|
||
tokenSource = new System.Threading.CancellationTokenSource();
|
||
var token = tokenSource.Token;
|
||
_isRecoveryEnergy = true;
|
||
int initEnergyRestorationSpeed = _tables.TbGlobalConfig.InitEnergyRestorationSpeed * 60;
|
||
|
||
while (Energy < MaxEnergy && !token.IsCancellationRequested)
|
||
{
|
||
if (energyRecoveryTime >= initEnergyRestorationSpeed)
|
||
{
|
||
int count = energyRecoveryTime / initEnergyRestorationSpeed * EnergyRecover;
|
||
int curEnergy = Energy;
|
||
Energy += count;
|
||
energyRecoveryTime %= initEnergyRestorationSpeed;
|
||
GameDebug.Log($"回复Energy:{Energy}");
|
||
|
||
if (Energy > MaxEnergy)
|
||
{
|
||
Energy = MaxEnergy;
|
||
}
|
||
int addEnergy = Energy - curEnergy;
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("auto_hook_revitalized"))
|
||
{
|
||
e.AddContent("map_id", lastMapId)
|
||
.AddContent("change_num", addEnergy);
|
||
}
|
||
using (var e = GEvent.GameEvent("item_change", gaSend: true))
|
||
{
|
||
e.AddContent("item_id", 1001)
|
||
.AddContent("state_info", "get")
|
||
.AddContent("change_num", addEnergy);
|
||
}
|
||
#endif
|
||
GContext.Publish(new ResAddEvent(1001));
|
||
_lastEnergyRecoveryTime = ZZTimeHelper.UtcNow().AddSeconds(-energyRecoveryTime);
|
||
SavePlayerData();
|
||
}
|
||
await Awaiters.Seconds(1);
|
||
if (token.IsCancellationRequested)
|
||
{
|
||
return;
|
||
}
|
||
energyRecoveryTime = (int)(ZZTimeHelper.UtcNow() - _lastEnergyRecoveryTime).TotalSeconds;
|
||
}
|
||
_isRecoveryEnergy = false;
|
||
}
|
||
|
||
public void ReduceEnergy(int reEnergy, bool remote = true)
|
||
{
|
||
if (reEnergy == 0)
|
||
{
|
||
reEnergy = GetMagnification();
|
||
}
|
||
int lastEnergy = Energy;
|
||
|
||
if (remote)
|
||
{
|
||
Energy = Mathf.Max(Energy - reEnergy, 0);
|
||
}
|
||
else
|
||
{
|
||
SetEnergy(Energy - reEnergy, false);
|
||
}
|
||
|
||
if (lastEnergy >= MaxEnergy && Energy < MaxEnergy)
|
||
{
|
||
RecoveryEnergy(0);
|
||
}
|
||
}
|
||
|
||
public void RecoverEnergy()
|
||
{
|
||
Energy += GetMagnification();
|
||
}
|
||
void SetRecoverNotification()
|
||
{
|
||
var item = _tables.TbNotification.GetOrDefault(RecoverNotificationID);
|
||
if (item != null)
|
||
{
|
||
int en = MaxEnergy - Energy - 1;
|
||
int count = (en / EnergyRecover) + 1;
|
||
DateTime dateTime = _lastEnergyRecoveryTime + TimeSpan.FromMinutes(count * _tables.TbGlobalConfig.InitEnergyRestorationSpeed);
|
||
GContext.container.Resolve<ILocalNotificationService>().
|
||
ScheduleOneTimeNotification(item.ID, dateTime, LocalizationMgr.GetText(item.Title_l10n_key), LocalizationMgr.GetText(item.Content_l10n_key));
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError($"TbNotification Not {RecoverNotificationID}");
|
||
}
|
||
}
|
||
public TimeSpan GetEnergyRecoveryTimeMAndS()
|
||
{
|
||
return _lastEnergyRecoveryTime + TimeSpan.FromMinutes(_tables.TbGlobalConfig.InitEnergyRestorationSpeed) - ZZTimeHelper.UtcNow();
|
||
}
|
||
public float GrtEscapeDistanceMag()
|
||
{
|
||
float ExtraPoint = 1;
|
||
//地图加成
|
||
MapData data = _tables.TbMapData.GetOrDefault(lastMapId);
|
||
if (data != null)
|
||
{
|
||
ExtraPoint = data.EscapeDistanceMag;
|
||
}
|
||
return ExtraPoint;
|
||
}
|
||
|
||
|
||
public async void OpenAppraisePopupPanel(int fishId)
|
||
{
|
||
if (lastMapId != _tables.TbMapData.DataList[0].ID && !IsOpenAppraise)
|
||
{
|
||
var fishData = _tables.TbFishData.GetOrDefault(fishId);
|
||
if (fishData != null && fishData.Quality >= 5)
|
||
{
|
||
await UIManager.Instance.ShowUI(UITypes.AppraisePopupPanel);
|
||
IsOpenAppraise = true;
|
||
PlayFabMgr.Instance.UpdateUserDataValue("IsOpenAppraise", "true");
|
||
}
|
||
}
|
||
}
|
||
|
||
#region GM相关
|
||
public int SupplyDropIndex = -1;
|
||
#endregion
|
||
}
|
||
}
|