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";
///
/// "Diamond"==>"Pearl"(不改名是因为数据已经通过Diamond键存储到云端了)
///
public const string Pearl = "Diamond";
public const string RodLevel = "RodLevel";
public const string WeightScore = "WeightScore";
public const string Diamond = "DiamondTrue";
Dictionary NewPlayerDataDic = new Dictionary();
public IReadOnlyDictionary 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 newRodList = new List();
public List showNewRodList = new List();
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 benefitsLevel;
public int OpenGradeID = 0;
public bool OpenGrade = false;
public int MagnificationCount
{
get
{
List DataList = _tables.TbEnergyDef.DataList;
var buffTimeData = GContext.container.Resolve().GetWeelyBuffTimeData();
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().GetWeelyBuffTimeData();
bool isSuperEnergy = buffTimeData != null;
List 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;
}
///
/// buff 过期
///
public void CheckSuperEnergyBuff()
{
List 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().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().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().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 itemDatas = new List();
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().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 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();
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 = new List() { 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().AddItemByDrop(isRewards);
}
//if (isRewards != 0 || !string.IsNullOrEmpty(Img))
//{
// CurRewardQCount curRewardQCount = new CurRewardQCount();
// GContext.Publish(curRewardQCount);
// if (curRewardQCount.count > 0)
// {
// GContext.container.Resolve().curQRewardCount = curRewardQCount.count + 1;
// }
// else
// {
// GContext.container.Resolve().curQRewardCount = 0;
// }
//}
//if (GContext.container.Resolve().IsOpenClubJoined)
{
GContext.container.Resolve().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().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
{
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();
var mapData = _tables.TbMapData.GetOrDefault(lastMapId);
if (mapData != null && mapData.DownloadPkg != null && mapData.DownloadPkg.Count > 0)
{
var fishList = _tables.TbAquariumConfig.AquariumSpFishList;
List strings = new List();
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 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().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 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().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().InitData(userDatas);
GContext.container.Resolve().InitData(userDatas);
GContext.container.Resolve().InitData(userDatas);
GContext.container.Resolve().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>(data_value);
break;
case "Picture":
var fishAlbumData = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
GContext.container.Resolve().fishAlbumData = fishAlbumData.ToDictionary(i => GlobalUtils.TryParseInt(i.Key), i => i.Value);
break;
case "NewAlbum":
GContext.container.Resolve().newAlbum = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
break;
case "PictureExchangeCD":
var exchangeCd = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
GContext.container.Resolve().exchangeCD =
exchangeCd.ToDictionary(i => GlobalUtils.TryParseInt(i.Key), i => i.Value);
break;
case "PhotoRequestCountByDay":
var photoRequestCountByDay = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
GContext.container.Resolve().InitGiftToFriendsDay(photoRequestCountByDay);
break;
case "SeasonId":
GContext.container.Resolve().seasonId = GlobalUtils.TryParseInt(data_value);
break;
case "MonthlySignEvent":
GContext.container.Resolve().monthlySignEvent = Newtonsoft.Json.JsonConvert.DeserializeObject(data_value);
break;
case "NewSignEvent":
GContext.container.Resolve().newSignEvent = Newtonsoft.Json.JsonConvert.DeserializeObject(data_value);
break;
//case "DailyTaskToWeeklyEvent":
// GContext.container.Resolve().SetDailyTaskToWeeklyEvent(data_value);
// break;
case "TriggerPackDataList":
GContext.container.Resolve().triggerPackList = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
break;
case "GiftVIPDData":
var giftVIPDData = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
GContext.container.Resolve().giftVIPDData = giftVIPDData;
break;
case "FixedTimeShopDic":
var FixedTimeshopDic = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
GContext.container.Resolve().SetFixedTimeShopDic(FixedTimeshopDic);
break;
case "GuideSaveData":
try
{
var guideSaveData = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value);
if (guideSaveData != null)
{
GContext.container.Resolve().GuideSaveDataDic = guideSaveData;
}
}
catch (Exception)
{
GameDebug.LogWarning($"[PlayerData]LoadPlayerData: Fail to parse GuideSaveData {data_value}!");
}
break;
case "HeistGameCount":
GContext.container.Resolve().SetHeistGameCount(GlobalUtils.TryParseInt(data_value));
break;
case "BombGameCount":
GContext.container.Resolve().SetBombGameCount(GlobalUtils.TryParseInt(data_value));
break;
case "FishHuntGameCount":
GContext.container.Resolve().SetFishHuntGameCount(GlobalUtils.TryParseInt(data_value));
break;
case "ClubSignin":
GContext.container.Resolve().SetClubSignin(data_value);
break;
case "LureDonateData":
GContext.container.Resolve().SetLureDonateData(data_value);
break;
case "FishingBoxData":
GContext.container.Resolve().InitData(data_value);
break;
case "IsOpenAppraise":
IsOpenAppraise = true;
break;
//case "MonthCardData":
// GContext.container.Resolve().InitMonthCardData(data_value);
// break;
// case "ChallengeData":
// GContext.container.Resolve().InitChallengeData(data_value);
// break;
case "FishingChallengeData":
GContext.container.Resolve().InitChallengeData(data_value);
break;
case OfferChainsChestManager.SaveKey:
GContext.container.Resolve().LoadChainsChestData(data_value);
break;
case HexMapDataManager.SaveKey:
GContext.container.Resolve().LoadUserData(data_value);
break;
//case "TargetEventPackData":
// GContext.container.Resolve().InitTargetEventData(data_value);
// break;
case "BattlePassRecord":
GContext.container.Resolve().LoadBattlePassRecord(data_value);
break;
case "BattleTask":
GContext.container.Resolve().LoadBattleTask(data_value);
break;
case "IsOpenClubRed":
GContext.container.Resolve().IsOpenClubRed = false;
break;
//case "PokerScoreData":
// GContext.container.Resolve().InitPockerScore(data_value);
// break;
case "EventPackData":
GContext.container.Resolve().LoadEventPackData(data_value);
break;
case "AchievementData":
GContext.container.Resolve().LoadAchievementData(data_value);
break;
case "PiggyBankPackData":
GContext.container.Resolve().LoadData(data_value);
break;
case "GeneralEventPackData":
var tempData = JsonConvert.DeserializeObject(data_value);
int packType = _tables.TbEventPackManager[tempData.redirectID].PackType;
switch (packType)
{
case 3:
GContext.container.Resolve().LoadData(tempData);
break;
case 4:
GContext.container.Resolve().LoadData(tempData);
break;
case 5:
GContext.container.Resolve().LoadData(tempData);
break;
}
break;
case "InfiniteBuildingData":
InfiniteBuildingData = data_value;
break;
/* case "EventPartnerData":
GContext.container.Resolve().LoadPlayfabData(data_value);
break; */
case EventWashingConfig.SAVE_DATA_KEY:
GContext.container.Resolve().GetDataFromServer(data_value);
break;
case "FootPrint":
GContext.container.Resolve().LoadData(data_value);
break;
case EventShootingRangeData.Key:
var data = GContext.container.Resolve();
if (data == null)
{
GContext.container.Register().AsSingleton();
data = GContext.container.Resolve();
}
data.LoadData(data_value);
break;
case EventPotionConfig.SAVE_DATA_KEY:
GContext.container.Resolve().GetDataFromServer(data_value);
break;
case EventPinballConfig.SAVE_DATA_KEY:
GContext.container.Resolve().GetDataFromServer(data_value);
break;
case EventScratchTicketConfig.SAVE_DATA_KEY:
GContext.container.Resolve().GetDataFromServer(data_value);
break;
case ThanksGivingPackData.Key:
GContext.container.Resolve().ThanksGivingPackData.LoadData(data_value);
break;
case ChainPackWithProgressMigrationData.Key:
GContext.container.Resolve().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().InitServerData(userDatas);
if (userDatas.TryGetValue("NewPlayerDataDic", out string newPlayerDataDic))
{
NewPlayerDataDic = Newtonsoft.Json.JsonConvert.DeserializeObject>(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 DataList = _tables.TbEnergyDef.DataList;
if (magnification >= DataList.Count)
{
magnification = 0;
}
EnergyDef energyDef = DataList[magnification];
if (energyDef.Energy >= 0)
{
return;
}
var buffTimeData = GContext.container.Resolve().GetWeelyBuffTimeData();
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 DataList = _tables.TbEnergyDef.DataList;
var buffTimeData = GContext.container.Resolve().GetWeelyBuffTimeData();
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 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().
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
}
}