using UnityEngine; using asap.core; using cfg; using GameCore; using System; using System.Collections.Generic; using UnityEngine.Assertions; public class RodSelectionPackData { private GeneralEventPackData _data; private readonly TbEventPackManager _epm = GContext.container.Resolve().TbEventPackManager; private readonly Tables _tables = GContext.container.Resolve(); private readonly PlayerFishData _pfd = GContext.container.Resolve(); private TbRodData _rodData = GContext.container.Resolve().TbRodData; private TbRodLevelup _rodLvlUp = GContext.container.Resolve().TbRodLevelup; private readonly TbRodAscend _rodAscend = GContext.container.Resolve().TbRodAscend; private readonly TbSpecialPack _spp = GContext.container.Resolve().TbSpecialPack; private readonly PlayerItemData _pid = GContext.container.Resolve(); private readonly TbDrop _drop = GContext.container.Resolve().TbDrop; private readonly TbItem _item = GContext.container.Resolve().TbItem; public int CurrentEventID => _data.currentEventID; public TimeSpan RemainingTime => DateTime.Parse((_tables.TbFishingEvent[_data.currentEventID].TimeDefinition as LimitedTime).EndTime) - ZZTimeHelper.UtcNow(); public bool IsWithinEventTime { get { if (CurrentEventID == 0) return false; return RemainingTime.TotalSeconds > 0; } } public bool IsPackActivated { get { bool res = _tables.TbFishingEvent.DataMap.ContainsKey(_data.currentEventID) && _epm.DataMap.ContainsKey(_data.redirectID) && _epm[_data.redirectID].PackType == 4 && IsWithinEventTime && _data.purchaseCount < _epm[_data.redirectID].MaxCount; /*Debug.Log(_tables.TbFishingEvent.DataMap.ContainsKey(_data.currentEventID)); Debug.Log(_epm.DataMap.ContainsKey(_data.redirectID)); Debug.Log(_epm[_data.redirectID].PackType == 3); Debug.Log(IsWithinEventTime); Debug.Log(_data.isTriggered); Debug.Log(_data.purchaseCount < _epm[_data.redirectID].MaxCount);*/ return res; } } public int RedirectID => _data.redirectID; private List PackList => _epm[_data.redirectID].VIPPackList[0]; public List PackRodList => _drop[_item[_drop[_epm[_data.redirectID].VIPPackList[0][0]].DropList.DropIDList[0]].RedirectID].DropList .DropIDList; public List RewardList { get { Assert.AreNotEqual(_data.rodID, -1, "Default rod not found. Maybe loot pool is empty."); var rewards = _pid.GetItemDataByDropId(_spp[_data.packID].DropID[0]); rewards[0] = new ItemData(_data.rodID, (int)rewards[0].count); return rewards; } } public int DropID => _spp[_data.packID].DropID[0]; public int PurchaseCount => _data.purchaseCount; public int MaxPurchaseCount => _epm[RedirectID].MaxCount; public int IAPID => _spp[_data.packID].IAPID[0]; public int RodID { get => _data.rodID; set => _data.rodID = value; } public int FragmentID => _rodAscend[_item[RodID].RedirectID].FragmentID; public void SaveData() { //Debug.LogError("Testing, data not saved for debug purpose."); PlayFabMgr.Instance.UpdateUserDataValue("GeneralEventPackData", Newtonsoft.Json.JsonConvert.SerializeObject(_data)); } public void LoadData(GeneralEventPackData data) { _data = data; if (IsPackActivated) { GContext.container.Resolve().AddGiftFaceUI(_data.currentEventID, UITypes.GiftRodSelectionPopupPanel, _epm[RedirectID].PackType, true); } } public bool UpdateData(FishingEvent e) { if (_epm[_tables.TbFishingEvent[e.ID].RedirectID].PackType != 4) { Debug.LogError($"Fishing event ID {e.ID} is not a rod-select pack event"); return false; } if (_data.currentEventID != e.ID) { GeneralEventPackData oldData = _data; int r = GetDefaultRodID(e); _data = new GeneralEventPackData( eventID: e.ID, redirectID: e.RedirectID, rodID: r, lastPackIDBought: oldData.lastPackIDBought, packID: GetPackID(oldData.lastPackIDBought, r, e), purchaseCount: 0); SaveData(); return true; } return false; } int star, fragCount, lvl; private int GetDefaultRodID(FishingEvent e) { int defaultRodID, rid; List rodsInPack = _drop[_item[_drop[_epm[e.RedirectID].VIPPackList[0][0]].DropList.DropIDList[0]].RedirectID].DropList.DropIDList; defaultRodID = rodsInPack[0]; foreach (var rod in rodsInPack) { rid = _item[rod].RedirectID; GetRodActualStats(rod, out star, out fragCount, out lvl); //bool a = !_pfd.NotRod(rid); //int b = _pfd.GetRodPiece(rid); //int c = _rodAscend[rid].MaxAscent; if (!_pfd.NotRod(rid) && star < _rodAscend[rid].MaxAscent) { defaultRodID = rod; break; } } GetRodActualStats(defaultRodID, out star, out fragCount, out lvl); foreach (var rod in rodsInPack) { int currentStar, currentFragCount, currentLvl; //if (defaultRodID == rodsInPack[0]) // defaultRodID = rod; rid = _item[rod].RedirectID; GetRodActualStats(rod, out currentStar, out currentFragCount, out currentLvl); //Debug.Log($"{rod} debug!!!!!!!!!!!!!"); //Debug.Log(!_pfd.NotRod(rid)); //Debug.Log(_pfd.GetRodPiece(rid) < _rodAscend[rid].MaxAscent); //Debug.Log(_pfd.GetRodPiece(rid) > _pfd.GetRodPiece(GetRodRedirectID(defaultRodID))); if (!_pfd.NotRod(rid)//if player has this rod, its not fully enhanced and has higher stars than current && currentStar < _rodAscend[rid].MaxAscent && currentLvl > lvl) { defaultRodID = rod; GetRodActualStats(defaultRodID, out star, out fragCount, out lvl); } } return defaultRodID; } private int GetPackID(int lastPack, int defaultRodID, FishingEvent e = null) { List packList; if (e != null) packList = _epm[e.RedirectID].VIPPackList[0]; else packList = PackList; GetRodActualStats(defaultRodID, out star, out fragCount, out lvl); if (_pfd.NotRod(GetRodRedirectID(defaultRodID)) || star >= _rodAscend[GetRodRedirectID(defaultRodID)].MaxAscent) { return packList[0] > lastPack - 1 ? packList[0] : lastPack - 1; } //int starLvl = _pfd.GetRodPiece(GetRodRedirectID(defaultRodID)); int fragmentID = _rodAscend[GetRodRedirectID(defaultRodID)].FragmentID; //int fragCount = _pfd.GetRodPiece(fragmentID); //int nextLvlStarPieces = // _rodAscend[GetRodRedirectID(defaultRodID)].AscentTransformed[star + 1] - fragCount; foreach (int packID in packList) { if (fragCount <= _spp[packID].EventItemRequire[0]) { return packID > lastPack - 1 ? packID : lastPack - 1; } } Debug.LogWarning($"Get Pack ID error. Rod {defaultRodID} is neither owned nor needing enhancement."); return packList[0] > lastPack - 1 ? packList[0] : lastPack - 1; } public void AddPurchase() { _data.purchaseCount++; _data.lastPackIDBought = _data.packID; SaveData(); } private int GetRodRedirectID(int rodItemID) { return _item[rodItemID].RedirectID; } /// /// Get potential level and frags needed for next level of a rod. /// /// Rod id in Item table /// The potential star after spending all the fragments /// Fragments needed for next level. Means nothing /// if actualStar reaches maximum enhancement /// Get Actual rod level private void GetRodActualStats(int rodID, out int actualStar, out int actualNextStarFrag, out int level) { Assert.IsTrue(_item.DataMap.ContainsKey(rodID)); int rid = _item[rodID].RedirectID; int star = _pfd.GetRodPiece(rid); int lvl = _pfd.GetRodLevel(rid); if (star >= _rodAscend[rid].MaxAscent) { actualStar = star; actualNextStarFrag = 0; level = lvl; return; } int fragID = _rodAscend[rid].FragmentID; int fragCount = _pfd.GetRodPiece(fragID); int nextStarFrag = _rodAscend[rid].AscentTransformed[star + 1]; while (fragCount >= nextStarFrag) { fragCount -= nextStarFrag; star++; if (star >= _rodAscend[rid].MaxAscent) { //nextStarFrag = 0; break; } nextStarFrag = _rodAscend[rid].AscentTransformed[star + 1]; } actualStar = star; actualNextStarFrag = nextStarFrag - fragCount; level = lvl; return; } }