1287 lines
51 KiB
C#
1287 lines
51 KiB
C#
using System.Collections.Generic;
|
||
using CodeStage.AntiCheat.ObscuredTypes;
|
||
using asap.core;
|
||
using LitJson;
|
||
using System;
|
||
using System.Linq;
|
||
using cfg;
|
||
using DataCenter;
|
||
using game;
|
||
using HexGrid;
|
||
using Newtonsoft.Json;
|
||
using Script.RuntimeScript;
|
||
using UnityEngine;
|
||
|
||
namespace GameCore
|
||
{
|
||
public class PlayerData
|
||
{
|
||
private cfg.Tables _tables;
|
||
MMTService _MMService;
|
||
public PlayerData(cfg.Tables tables, MMTService mmService)
|
||
{
|
||
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 ObscuredInt lv { get; set; }
|
||
public ObscuredInt vip { get; private set; }
|
||
public ObscuredInt vipScore { get; private set; }
|
||
public ObscuredInt vipAllScore { get; private set; }
|
||
#region 付费积分
|
||
public int initPackPoints = 0;
|
||
public int PriceLv { get; private set; }
|
||
//付费等级=f1(vip积分,地区积分)+f2(活跃积分)
|
||
public int AllPackPoints => initPackPoints + vipAllScore;
|
||
public PriceLevel priceLevel;
|
||
#endregion 付费积分
|
||
private ObscuredInt energy;
|
||
int energyRM;
|
||
public ObscuredULong gold { get; private set; }
|
||
ulong goldRM;
|
||
public ObscuredInt pearl { get; private set; }
|
||
public ObscuredInt diamond { get; private set; }
|
||
|
||
public ObscuredInt equipRodID = 10001;
|
||
public ObscuredInt magnification;
|
||
public ObscuredInt seasonId = 0;
|
||
public ObscuredInt rewardNewMap = 0;
|
||
bool IsOpenAppraise = false;
|
||
ObscuredInt _currentMapId = 0;
|
||
public string InfiniteBuildingData = "0";
|
||
public string InfiniteBuildingLevel => InfiniteBuildingData.Split(',')[0];
|
||
public ObscuredInt 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;
|
||
}
|
||
}
|
||
ObscuredInt _lastMapId = 0;
|
||
public ObscuredInt 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 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 AccountMM nextAccountData;
|
||
public VipLevel curVipData;
|
||
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;
|
||
}
|
||
|
||
/// <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 ObscuredInt Energy
|
||
{
|
||
get => energy;
|
||
private set { SetEnergy(value); }
|
||
}
|
||
int RecoverNotificationID = 1002;
|
||
public ObscuredInt 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;
|
||
int isRewards = 0;
|
||
string Img = "";
|
||
List<int> DisplaySwitch = null;
|
||
int nextAccountDataID = 0;
|
||
var account = nextAccountData;
|
||
if (lv < nextAccountData.ID && count >= nextAccountData.ID)
|
||
{
|
||
isRewards = nextAccountData.Rewards;
|
||
Img = nextAccountData.Img;
|
||
nextAccountDataID = nextAccountData.ID;
|
||
DisplaySwitch = nextAccountData.DisplaySwitch;
|
||
}
|
||
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();
|
||
|
||
if (DisplaySwitch != null)
|
||
{
|
||
var table = GContext.container.Resolve<cfg.Tables>();
|
||
int id;
|
||
Item item;
|
||
for (int i = 0; i < DisplaySwitch.Count; i++)
|
||
{
|
||
if (DisplaySwitch[i] > 0 && benefitsLevel[i] > 0 && i < benefitsLevel.Count)
|
||
{
|
||
id = 12001 + i;
|
||
item = table.TbItem.GetOrDefault(id);
|
||
List<ItemData> itemData = new List<ItemData>() { new ItemData { id = id, count = benefitsLevel[i] } };
|
||
GContext.Publish(new ShowData(itemData, RewardType.BenefitUpgrade));
|
||
}
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(Img))
|
||
{
|
||
//开启系统
|
||
GContext.Publish(new ShowData(RewardType.FeaturesUnlock, nextAccountDataID));
|
||
}
|
||
if (isRewards != 0)
|
||
{
|
||
var itemData = GContext.container.Resolve<PlayerItemData>().AddItemByDrop(isRewards);
|
||
}
|
||
//if (isRewards != 0 || !string.IsNullOrEmpty(Img))
|
||
//{
|
||
// CurRewardQCount curRewardQCount = new CurRewardQCount();
|
||
// GContext.Publish(curRewardQCount);
|
||
// if (curRewardQCount.count > 0)
|
||
// {
|
||
// GContext.container.Resolve<CampData>().curQRewardCount = curRewardQCount.count + 1;
|
||
// }
|
||
// else
|
||
// {
|
||
// GContext.container.Resolve<CampData>().curQRewardCount = 0;
|
||
// }
|
||
//}
|
||
//if (GContext.container.Resolve<ClubService>().IsOpenClubJoined)
|
||
{
|
||
GContext.container.Resolve<LeadboardData>().AwaitSetLvData();
|
||
}
|
||
}
|
||
//等级改变的时候
|
||
|
||
public void OnLvChange()
|
||
{
|
||
var account = _tables.TBAccount.DataList;
|
||
nextAccountData = account[^1];
|
||
|
||
AccountMM 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;
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
if (lv < dataList[i].LevelRequired)
|
||
{
|
||
unLockIndex = i;
|
||
mapData = dataList[i];
|
||
break;
|
||
}
|
||
}
|
||
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)
|
||
{
|
||
GContext.container.Resolve<ClubService>().SendSystemMessage2(unLockIndex);
|
||
AddNewMap(unLockIndex);
|
||
}
|
||
}
|
||
SavePlayerData();
|
||
GContext.Publish(new OnLvChangeEvent() { lvl = lv });
|
||
AiHelpManager.Instance.Update();
|
||
}
|
||
void SetBenefits(AccountMM 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);
|
||
|
||
loadResourceService.Load(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();
|
||
}
|
||
void SetVIP(int count)
|
||
{
|
||
if (vip != count)
|
||
{
|
||
int addLevel = count - vip;
|
||
vip = count;
|
||
curVipData = _tables.TbVipLevel.DataList[vip];
|
||
}
|
||
else
|
||
{
|
||
curVipData = _tables.TbVipLevel.DataList[vip];
|
||
}
|
||
#if AGG
|
||
GEvent.SetProp("vip_level", count);
|
||
GEvent.SetUserProp("vip_level", count);
|
||
#endif
|
||
SetPriceLv();
|
||
#if AGG
|
||
GEvent.SetProp("pay_level", PriceLv);
|
||
GEvent.SetUserProp("pay_level", PriceLv);
|
||
#endif
|
||
AiHelpManager.Instance.Update();
|
||
}
|
||
public void AddVIPScore(int count, bool isBuy = false)
|
||
{
|
||
vipAllScore += count;
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("getpoint_vip"))
|
||
{
|
||
e.AddContent("add_count", count).AddContent("all_count", vipAllScore);
|
||
}
|
||
#endif
|
||
VipChange();
|
||
SavePlayerData();
|
||
}
|
||
void VipChange()
|
||
{
|
||
int LevelScore = 0;
|
||
//设置vip等级
|
||
var vipData = _tables.TbVipLevel.DataList;
|
||
for (int i = 0; i < vipData.Count; i++)
|
||
{
|
||
LevelScore += vipData[i].LevelScore;
|
||
if (vipAllScore < LevelScore)
|
||
{
|
||
vipScore = vipAllScore - LevelScore + vipData[i].LevelScore;
|
||
SetVIP(i);
|
||
return;
|
||
}
|
||
}
|
||
vipScore = vipAllScore - LevelScore + vipData[^1].LevelScore;
|
||
SetVIP(vipData.Count - 1);
|
||
}
|
||
void SetPriceLv()
|
||
{
|
||
int LevelScore = 0;
|
||
//设置vip等级
|
||
var priceData = _tables.TbPriceLevel.DataList;
|
||
for (int i = 0; i < priceData.Count; i++)
|
||
{
|
||
LevelScore += priceData[i].LevelScore;
|
||
if (AllPackPoints < LevelScore)
|
||
{
|
||
PriceLv = i;
|
||
priceLevel = priceData[i];
|
||
return;
|
||
}
|
||
}
|
||
priceLevel = priceData[^1];
|
||
PriceLv = priceData.Count - 1;
|
||
}
|
||
void InitPackPoints()
|
||
{
|
||
string CountryCode = GContext.container.Resolve<IUserService>().CountryCode;
|
||
initPackPoints = 0;
|
||
if (string.IsNullOrEmpty(CountryCode))
|
||
{
|
||
CountryCode = "COUNTRY";
|
||
}
|
||
CountryPoints countryPoints = _tables.TbCountryPoints.GetOrDefault(CountryCode);
|
||
if (countryPoints == null)
|
||
{
|
||
CountryCode = "COUNTRY";
|
||
countryPoints = _tables.TbCountryPoints.GetOrDefault(CountryCode);
|
||
}
|
||
if (countryPoints != null)
|
||
{
|
||
#if UNITY_ANDROID
|
||
initPackPoints = countryPoints.AndroidInitPoints;
|
||
#else
|
||
initPackPoints = countryPoints.IosInitPoints;
|
||
#endif
|
||
}
|
||
|
||
Debug.Log($"CountryCode {CountryCode}");
|
||
}
|
||
|
||
public void LoadPlayerData(Dictionary<string, string> userDatas)
|
||
{
|
||
InitPackPoints();
|
||
lv = 1;
|
||
gold = (ulong)_tables.TbGlobalConfig.InitCash;
|
||
vipAllScore = 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;
|
||
#endregion 旧数据兼容
|
||
|
||
case "NewRodList":
|
||
newRodList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>(data_value);
|
||
break;
|
||
case "Picture":
|
||
var fishAlbumData = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, int>>(data_value);
|
||
GContext.container.Resolve<AlbumData>().fishAlbumData = fishAlbumData.ToDictionary(i => GlobalUtils.TryParseInt(i.Key), i => i.Value);
|
||
break;
|
||
case "NewAlbum":
|
||
GContext.container.Resolve<AlbumData>().newAlbum = Newtonsoft.Json.JsonConvert.DeserializeObject<List<int>>(data_value);
|
||
break;
|
||
case "PictureExchangeCD":
|
||
var exchangeCd = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, double>>(data_value);
|
||
GContext.container.Resolve<AlbumData>().exchangeCD =
|
||
exchangeCd.ToDictionary(i => GlobalUtils.TryParseInt(i.Key), i => i.Value);
|
||
break;
|
||
|
||
case "PhotoRequestCountByDay":
|
||
var photoRequestCountByDay = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, int>>(data_value);
|
||
GContext.container.Resolve<AlbumData>().InitGiftToFriendsDay(photoRequestCountByDay);
|
||
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 "NewSignEvent":
|
||
GContext.container.Resolve<SigninData>().newSignEvent = Newtonsoft.Json.JsonConvert.DeserializeObject<DailySignEvent>(data_value);
|
||
break;
|
||
//case "DailyTaskToWeeklyEvent":
|
||
// GContext.container.Resolve<TaskData>().SetDailyTaskToWeeklyEvent(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 "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;
|
||
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 "ClubSignin":
|
||
GContext.container.Resolve<ClubService>().SetClubSignin(data_value);
|
||
break;
|
||
case "LureDonateData":
|
||
GContext.container.Resolve<ClubService>().SetLureDonateData(data_value);
|
||
break;
|
||
case "FishingBoxData":
|
||
GContext.container.Resolve<FishingBoxData>().InitData(data_value);
|
||
break;
|
||
|
||
case "IsOpenAppraise":
|
||
IsOpenAppraise = true;
|
||
break;
|
||
|
||
//case "MonthCardData":
|
||
// GContext.container.Resolve<MonthCardDataConter>().InitMonthCardData(data_value);
|
||
// break;
|
||
// case "ChallengeData":
|
||
// GContext.container.Resolve<FishingChallengeCenter>().InitChallengeData(data_value);
|
||
// break;
|
||
case "FishingChallengeData":
|
||
GContext.container.Resolve<FishingChallengeManager>().InitChallengeData(data_value);
|
||
break;
|
||
case OfferChainsChestManager.SaveKey:
|
||
GContext.container.Resolve<OfferChainsChestManager>().LoadChainsChestData(data_value);
|
||
break;
|
||
case HexMapDataManager.SaveKey:
|
||
GContext.container.Resolve<HexMapDataManager>().LoadUserData(data_value);
|
||
break;
|
||
|
||
//case "TargetEventPackData":
|
||
// GContext.container.Resolve<PlayerShopData>().InitTargetEventData(data_value);
|
||
// break;
|
||
case "BattlePassRecord":
|
||
GContext.container.Resolve<BattlePassData>().LoadBattlePassRecord(data_value);
|
||
break;
|
||
case "BattleTask":
|
||
GContext.container.Resolve<BattlePassData>().LoadBattleTask(data_value);
|
||
break;
|
||
|
||
case "IsOpenClubRed":
|
||
GContext.container.Resolve<ClubService>().IsOpenClubRed = false;
|
||
break;
|
||
//case "PokerScoreData":
|
||
// GContext.container.Resolve<PokerScoreData>().InitPockerScore(data_value);
|
||
// break;
|
||
|
||
case "EventPackData":
|
||
GContext.container.Resolve<EventPackData>().LoadEventPackData(data_value);
|
||
break;
|
||
case "AchievementData":
|
||
GContext.container.Resolve<AchievementDataManager>().LoadAchievementData(data_value);
|
||
break;
|
||
|
||
case "PiggyBankPackData":
|
||
GContext.container.Resolve<PiggyBankPackData>().LoadData(data_value);
|
||
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;
|
||
case 4:
|
||
GContext.container.Resolve<RodSelectionPackData>().LoadData(tempData);
|
||
break;
|
||
case 5:
|
||
GContext.container.Resolve<SelectionPackData>().LoadData(tempData);
|
||
break;
|
||
}
|
||
break;
|
||
case "InfiniteBuildingData":
|
||
InfiniteBuildingData = data_value;
|
||
break;
|
||
/* case "EventPartnerData":
|
||
GContext.container.Resolve<EventPartnerData>().LoadPlayfabData(data_value);
|
||
break; */
|
||
case EventWashingConfig.SAVE_DATA_KEY:
|
||
GContext.container.Resolve<EventWashingDataManager>().GetDataFromServer(data_value);
|
||
break;
|
||
case "FootPrint":
|
||
GContext.container.Resolve<IFootPrintService>().LoadData(data_value);
|
||
break;
|
||
case EventShootingRangeData.Key:
|
||
var data = GContext.container.Resolve<EventShootingRangeData>();
|
||
if (data == null)
|
||
{
|
||
GContext.container.Register<EventShootingRangeData>().AsSingleton();
|
||
data = GContext.container.Resolve<EventShootingRangeData>();
|
||
}
|
||
data.LoadData(data_value);
|
||
break;
|
||
case EventPotionConfig.SAVE_DATA_KEY:
|
||
GContext.container.Resolve<EventPotionDataManager>().GetDataFromServer(data_value);
|
||
break;
|
||
case EventPinballConfig.SAVE_DATA_KEY:
|
||
GContext.container.Resolve<EventPinballDataManager>().GetDataFromServer(data_value);
|
||
break;
|
||
case EventScratchTicketConfig.SAVE_DATA_KEY:
|
||
GContext.container.Resolve<EventScratchTicketDataManager>().GetDataFromServer(data_value);
|
||
break;
|
||
case ThanksGivingPackData.Key:
|
||
GContext.container.Resolve<FishingEventData>().ThanksGivingPackData.LoadData(data_value);
|
||
break;
|
||
case ChainPackWithProgressMigrationData.Key:
|
||
GContext.container.Resolve<FishingEventData>().ChainPackWithProgressMigrationData.LoadData(data_value);
|
||
break;
|
||
// case EventBreakPfData.PfKey:
|
||
// EventBreakPfData.Stash = EventBreakPfData.Deserialize(data_value);
|
||
// break;
|
||
// case EventCanPlayfabData.PlayFabKey:
|
||
// EventCanPlayfabData.Deserialize(data_value).Save();
|
||
// break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
GContext.container.Resolve<DiggingGameManager>().InitServerData(userDatas);
|
||
if (userDatas.TryGetValue("NewPlayerDataDic", out string newPlayerDataDic))
|
||
{
|
||
NewPlayerDataDic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(newPlayerDataDic);
|
||
SetPlayerData();
|
||
}
|
||
}
|
||
void SetPlayerData()
|
||
{
|
||
string data_value;
|
||
if (NewPlayerDataDic.TryGetValue("lv", out data_value))
|
||
{
|
||
lv = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("gold", out data_value))
|
||
{
|
||
gold = GlobalUtils.TryParseUlong(data_value, (ulong)_tables.TbGlobalConfig.InitCash);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("vipS", out data_value))
|
||
{
|
||
vipAllScore = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("energy", out data_value))
|
||
{
|
||
energy = GlobalUtils.TryParseInt(data_value);
|
||
if (energy < 0)
|
||
{
|
||
energy = 0;
|
||
}
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("pearl", out data_value))
|
||
{
|
||
pearl = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("mag", out data_value))
|
||
{
|
||
magnification = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("rodID", out data_value))
|
||
{
|
||
equipRodID = GlobalUtils.TryParseInt(data_value);
|
||
if (!_tables.TbRodData.DataMap.ContainsKey(equipRodID))
|
||
{
|
||
equipRodID = _tables.TbGlobalConfig.InitRodID;
|
||
}
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("EnergyTime", out data_value))
|
||
{
|
||
_lastEnergyRecoveryTime = GlobalUtils.TryParseDateTime(data_value, ZZTimeHelper.UtcNow());
|
||
}
|
||
|
||
if (NewPlayerDataDic.TryGetValue("rewardNewMap", out data_value))
|
||
{
|
||
rewardNewMap = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("energyRM", out data_value))
|
||
{
|
||
energyRM = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("goldRM", out data_value))
|
||
{
|
||
goldRM = GlobalUtils.TryParseUlong(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("diamond", out data_value))
|
||
{
|
||
diamond = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
|
||
if (NewPlayerDataDic.TryGetValue("cMapID", out data_value))
|
||
{
|
||
currentMapId = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
if (NewPlayerDataDic.TryGetValue("lMapID", out data_value))
|
||
{
|
||
lastMapId = GlobalUtils.TryParseInt(data_value);
|
||
}
|
||
}
|
||
|
||
void SavePlayerData(bool remote = true)
|
||
{
|
||
NewPlayerDataDic["lv"] = lv.ToString();
|
||
NewPlayerDataDic["gold"] = gold.ToString();
|
||
NewPlayerDataDic["vipS"] = vipAllScore.ToString();
|
||
NewPlayerDataDic["energy"] = energy.ToString();
|
||
NewPlayerDataDic["pearl"] = pearl.ToString();
|
||
NewPlayerDataDic["mag"] = magnification.ToString();
|
||
NewPlayerDataDic["rodID"] = equipRodID.ToString();
|
||
NewPlayerDataDic["EnergyTime"] = _lastEnergyRecoveryTime.ToString();
|
||
NewPlayerDataDic["rewardNewMap"] = rewardNewMap.ToString();
|
||
NewPlayerDataDic["energyRM"] = energyRM.ToString();
|
||
NewPlayerDataDic["goldRM"] = goldRM.ToString();
|
||
NewPlayerDataDic["diamond"] = diamond.ToString();
|
||
NewPlayerDataDic["cMapID"] = currentMapId.ToString();
|
||
NewPlayerDataDic["lMapID"] = lastMapId.ToString();
|
||
|
||
PlayFabMgr.Instance.UpdateUserDataValue("NewPlayerDataDic", Newtonsoft.Json.JsonConvert.SerializeObject(NewPlayerDataDic), remote);
|
||
}
|
||
public void Init()
|
||
{
|
||
OnLvChange();
|
||
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 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: false))
|
||
{
|
||
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 = 0, bool remote = true)
|
||
{
|
||
if (reEnergy == 0)
|
||
{
|
||
reEnergy = GetMagnification();
|
||
}
|
||
int lastEnergy = Energy;
|
||
|
||
if (remote)
|
||
{
|
||
Energy = Mathf.Max(Energy - reEnergy, 0);
|
||
}
|
||
else
|
||
{
|
||
SetEnergy(Energy - reEnergy, false);
|
||
}
|
||
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.ConsumeEnergy, GetMagnification()));
|
||
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
|
||
}
|
||
}
|