using asap.core; // using Assets.Scripts.UI.SocialRush; using cfg; // using DataCenter; using game; using LitJson; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using UniRx; using UnityEngine; public class LimitedTimeEvent { public int id; //持续时间分钟 public double duration; //开始时间 public string startTime; } public class FixedTimeEvent { public int id; //结束时间 public string endTime; } public struct TargetEvent { public TargetEvent(int id, int type, int subType) { this.id = id; this.type = type; this.subType = subType; } public int id; public int type; public int subType; } public struct ConditionTypeEvent { public ConditionTypeEvent(ConditionType conditionType, int count) { this.type = conditionType; this.count = count; } public ConditionType type; public int count; } namespace GameCore { public partial class FishingEventData : IDisposable { private cfg.Tables _tables; public FishingEventData(cfg.Tables tables) { this._tables = tables; } Dictionary limitedTimeEventDic = new Dictionary(); //固定时间开启事件的过期时间 Dictionary fixedTimeEventDic = new Dictionary(); public Dictionary FixedTimeEventDic => fixedTimeEventDic; private int collectingTargetEventID = -1; private int virtualCollectingTargetEventID = -1; private DateTime NewPlayerEvent = DateTime.MinValue; public CollectingTargetInit collectingTargetInit = null; public int collectingTargetInitTokenID; public int collectingTargetInitTaskID; public bool IsJoinUsPanelOpen = false; public bool collectingTargetResoure = true; public bool IsAquariumOpen = false; public bool IsOpenDrop = false; public int OpenAquariumID; public static string NextQueueKey = "CollectingTargetNextQueueKey"; List TargetList; public CollectingTargetReward collectingTarget = null; public Queue preCollectingTarget = null; public List targetItemDatas = null; public List preRankTarget = null; public List rankItemDatas = null; /// /// 0:rankEventID -1:isRankSendNotification -4 当前体力膨胀倍率(InflationRate*100) /// public Dictionary RankTargetCount = new Dictionary(); private FishingEvent rankEvent = null; public RankInit rankInit = null; public RankTargets rankTarget = null; /// ///-5 当前任务Index ///-4 当前体力膨胀倍率(InflationRate*100) ///-3:新手活动过期时间 ///-1:礼包购买数量 ///0:rankEventID ///1:新手引导数量 FishID :X 倍率 数量 ItemID: 钓鱼数量 TokenID:任务目标ID /// Dictionary ETDropAfterDropDic = new Dictionary(); bool _isTargetGuidance = true; private FishingEvent turntableEvent; public WheelInit wheelInit = null; public WheelLevel wheelLevel = null; /// /// Exp of each lvl. Key "-1" has expire time count. /// Key "-2" counts the purchase time in "lack of ticket" panel. /// LYNB. /// public Dictionary WheelLevelCount = new Dictionary(); public int TurntableCoupon { get; private set; } public int WheelOperateCount; public int AllWheelOperateCount; //public Dictionary WheelOperateCountDic = new Dictionary(); public int freecount; Dictionary SystemOpen = new Dictionary(); HashSet _unlocked = new HashSet(); //待释放 IDisposable disposable; public void InitData(Dictionary userDatas) { InitTurntableRoll(_tables.TbGlobalConfig.InitWheelTicket); string data_value; try { if (userDatas.TryGetValue("LimitedTimeEventDic", out data_value)) { var limitedTimeEventDic = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value); SetLimitedTimeEventDic(limitedTimeEventDic); } } catch (Exception e) { Debug.LogError(e); } if (userDatas.TryGetValue("FixedTimeEventDic", out data_value)) { fixedTimeEventDic = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value); } if (userDatas.TryGetValue("ETDropAfterDropDic", out data_value)) { ETDropAfterDropDic = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value); } if (userDatas.TryGetValue("RankTargetCount", out data_value)) { RankTargetCount = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value); } if (userDatas.TryGetValue("TurntableRoll", out data_value)) { InitTurntableRoll(GlobalUtils.TryParseInt(data_value)); } if (userDatas.TryGetValue("WheelLevelCount", out data_value)) { WheelLevelCount = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value); } if (userDatas.TryGetValue("WheelOperateCount", out data_value)) { WheelOperateCount = GlobalUtils.TryParseInt(data_value); } if (userDatas.TryGetValue("AllWheelOperateCount", out data_value)) { AllWheelOperateCount = GlobalUtils.TryParseInt(data_value); } if (userDatas.TryGetValue("WheelLevelFreeCount", out data_value)) { freecount = GlobalUtils.TryParseInt(data_value); } // TransitionData 已统一由 EventTokenService 管理,不再本地加载 // if (userDatas.TryGetValue("PVPToken", out data_value)) // { // PVPToken = GlobalUtils.TryParseInt(data_value); // } } public void SetLimitedTimeEventDic(Dictionary _limitedTimeEventDic) { limitedTimeEventDic.Clear(); var timer = ZZTimeHelper.UtcNow().UtcNowOffset(); foreach (var limitedTimeEvent in _limitedTimeEventDic) { if ((timer - GlobalUtils.TryParseDateTime(limitedTimeEvent.Value.startTime, timer)).TotalMinutes < limitedTimeEvent.Value.duration) { limitedTimeEventDic.Add(limitedTimeEvent.Key, limitedTimeEvent.Value); } } } public void Init() { List _dataList = _tables.TbFishingEvent.DataList; foreach (var t in _dataList) { switch (t.Type) { case 1: switch (t.SubType) { case 3: GContext.container.Resolve().vipTipforUnlocked = t.ID; break; case 4: GContext.container.Resolve().shopTipforUnlocked = t.ID; break; case 5: break; case 6: GContext.container.Resolve().MapTipforUnlocked = t.ID; break; case 17: GContext.container.Resolve().LockTipID = t.ID; break; case 18: GContext.container.Resolve().OpenGradeID = t.ID; break; case 20: OpenAquariumID = t.ID; break; //case 7: // //杆 // break; } break; //case 2: // switch (t.SubType) // { // case 1: // break; // case 2: // break; // } // break; //case 3: // switch (t.SubType) // { // //case 1: // // GContext.container.Resolve().TipforUnlocked = t.ID; // // break; // //case 2: // // break; // //case 3: // // break; // case 4: // break; // } // break; } SetEvent(t); } foreach (var limitedTimeEvent in limitedTimeEventDic) { FishingEvent fishingEvent = _tables.TbFishingEvent.GetOrDefault(limitedTimeEvent.Key); if (fishingEvent != null) { SetEvent(fishingEvent, false); } } if (disposable == null) { disposable = GContext.OnEvent().Subscribe(OnEventDataChange); } InitTransitionDataDic(); } public string GetTipforUnlocked(int id) { var t = _tables.TbFishingEvent.GetOrDefault(id); if (t != null) { int conditionCount = t.ConditionList.Count; if (conditionCount > 1) { for (int i = 0; i < conditionCount; i++) { if (!GetEventCondition(t.ConditionList[i])) { return GetEventConditionString(t.ConditionList[i]); } } } else { return GetEventConditionString(t.ConditionList[0]); } } return ""; } string GetEventConditionString(EventCondition eventCondition) { switch (eventCondition.Condition) { case ConditionType.GetFishCount: int count = int.Parse(eventCondition.Param[0]) - GContext.container.Resolve().GetAnglingCount(); if (count < 0) { count = 0; } return LocalizationMgr.GetFormatTextValue(eventCondition.TipforUnlocked_l10n_key, count); case ConditionType.AccountLevel: return LocalizationMgr.GetFormatTextValue(eventCondition.TipforUnlocked_l10n_key, eventCondition.Param[0]); default: return ""; } } void OnEventDataChange(ConditionTypeEvent conditionTypeEvent) { OnEventDataChange(conditionTypeEvent.type, conditionTypeEvent.count); } //事件数据改变 void OnEventDataChange(ConditionType type, int count) { List _dataList = _tables.TbFishingEvent.DataList; foreach (var t in _dataList) { List ConditionList = t.ConditionList; for (int i = 0; i < ConditionList.Count; i++) { if (ConditionList[i].Condition == type) { SetEvent(t); break; } } } } /// /// 时间跨天刷新 /// public void AllRefresh() { List _dataList = _tables.TbFishingEvent.DataList; List systemOpen = new List(); foreach (var t in _dataList) { int open = RedirectType(t.Type, t.SubType); if (t.Type > 1 && !systemOpen.Contains(open)) { try { if (SetEvent(t)) { systemOpen.Add(open); } } catch (Exception e) { Debug.LogError(e); } } } RefreshEvent(); } public void RefreshEvent() { } /// /// 检查某一类型活动是否开启,并初始化,用于活动到期检查刷新 /// /// /// public int GetEventAndInit(int type, int subType) { List _dataList = _tables.TbFishingEvent.GetAllDataByType(type, subType); foreach (var t in _dataList) { if (SetEvent(t)) { return t.ID; } } return -1; } /// /// 检查某一类型活动是否开启,不初始化 /// /// /// /// public int GetEvent(int type, int subType) { List _dataList = _tables.TbFishingEvent.GetAllDataByType(type, subType); foreach (var t in _dataList) { if (Condition(t)) { return t.ID; } } return -1; } /// /// 检查某一类型活动是否开启,不初始化 /// /// /// /// /// public int GetEventRedirectID(int type, int subType) { List _dataList = _tables.TbFishingEvent.GetAllDataByType(type, subType); foreach (var t in _dataList) { if (Condition(t)) { return t.RedirectID; } } return -1; } /// /// 检查某一类型活动是否开启,不初始化 /// /// /// /// /// public FishingEvent GetEventByTypeAndSubType(int type, int subType, bool isCheckCondition = true) { List _dataList = _tables.TbFishingEvent.GetAllDataByType(type, subType); foreach (var t in _dataList) { if (Condition(t) || !isCheckCondition) { return t; } } return null; } /// /// 检查某一类型活动是否开启,不初始化 /// /// /// /// public FishingEvent GetEventeByTimType(int type, int subType) { List _dataList = _tables.TbFishingEvent.GetAllDataByType(type, subType); foreach (var t in _dataList) { bool isOpen = true; if (t.TimeDefinition is UserRegistration) { UserRegistration userRegistrationEvent = (UserRegistration)t.TimeDefinition; double time = GContext.container.Resolve().CreateTotalSeconds(); isOpen = userRegistrationEvent.StartTime <= time && time < userRegistrationEvent.EndTime; } else if (t.TimeDefinition is FixedTime) { isOpen = FixedTimeEventExpired(t.ID); } else if (t.TimeDefinition is LimitedTime) { LimitedTime limitedTime = (LimitedTime)t.TimeDefinition; isOpen = GlobalUtils.TryParseDateTime(limitedTime.StartTime, ZZTimeHelper.UtcNow()) <= ZZTimeHelper.UtcNow() && ZZTimeHelper.UtcNow() < GlobalUtils.TryParseDateTime(limitedTime.EndTime, ZZTimeHelper.UtcNow()); } if (isOpen) { return t; } } return null; } /// /// 获取type开启活动数据,并确保活动初始化,用于活动代币转换 /// /// /// public FishingEvent GetEventTable(int type) { List _dataList = _tables.TbFishingEvent.GetAllDataByType(type); foreach (var t in _dataList) { if (Condition(t)) { if (!_unlocked.Contains(t.ID)) { Debug.Log($"Event {t.ID} unlocked"); SetEvent(t, false); _unlocked.Add(t.ID); } return t; } } return null; } /// /// 刷新活动 条件发生改变持续广播当前条件能开启哪些活动 /// 最好记一下活动ID t.ID,只要ID不同就初始化 /// /// /// /// bool SetEvent(FishingEvent t, bool condition = true) { //Assert.IsTrue(t.ID != 30801002); //bool b = Condition(t); //if (t.Type == 3) // Debug.Log($"condition of id: {t.ID} {t.Type} {t.SubType}: {b}"); if (!condition || Condition(t)) { if (t.TimeDefinition is FixedTime) { if (!fixedTimeEventDic.ContainsKey(t.ID)) { FixedTime fixedTime = (FixedTime)t.TimeDefinition; fixedTimeEventDic[t.ID] = new FixedTimeEvent() { id = t.ID, endTime = ZZTimeHelper.UtcNow().UtcNowOffset().AddSeconds(fixedTime.StartTime).ToString(), }; PlayFabMgr.Instance.UpdateUserDataValue("FixedTimeEventDic", JsonMapper.ToJson(fixedTimeEventDic)); } } switch (t.Type) { case 1: SetEvent1(t); break; case 2: SetEvent2(t); break; case 3: SetEvent3(t); break; case 4: // if (t.SubType == 1) //沙滩寻宝 // { // } // else if (t.SubType == 3) //鱼缸建造 // { // // Debug.Log($"[EventPartner]Event On, Try load data"); // // data.LoadData(t); // } // else if (t.SubType == 5) // 魔药 // { // } // else if (t.SubType == 6) // 弹珠 // { // } // else if (t.SubType == 7) // { // var pfData = EventBingoPlayfabData.Load(); // var ppData = EventBingoPlayerPreferenceData.Load(); // if (bingoModel == null) // { // if (pfData == null || pfData.EventId != t.ID) // { // // Debug.Log("[EventBingo] Reset bingo."); // bingoModel.Init(t); // bingoModel.ToPlayfabData().Save(); // bingoModel.ToPlayerPreferenceData().Save(); // } // else // { // // Debug.Log("[EventBingo] Load bingo."); // bingoModel.Load(pfData, ppData, t); // } // } // else if (bingoModel.EventId != t.ID) // { // bingoModel.Init(t); // bingoModel.ToPlayfabData().Save(); // bingoModel.ToPlayerPreferenceData().Save(); // } // else if (pfData == null) // { // Debug.LogWarning("[EventBingo] Playfab data empty but model exists."); // } // else if (bingoModel.EventId == t.ID && pfData.EventId == t.ID) // { // Debug.Log("[EventBingo] Redundant call. Skip."); // } // else // { // Debug.LogWarning($"[EventBingo] EventId mismatch! event: {t.ID}, pf: {pfData.EventId}, model: {bingoModel.EventId}"); // } // } // // else if (t.SubType == 8) // // { // // InitPartnerGatherData(t); // // } // else if (t.SubType == 11 || t.SubType == 16) // { // InitCubeMeltData(t); // } // else if (t.SubType == 12) // { // } // else if (t.SubType == 14) // { // } // break; // case 5: // if (t.SubType == 1) // { // InitSoloData(t); // } break; case 6: SetEvent6(t); break; case 7: SetEvent7(t); break; case 8: SetEvent8(t); break; case 9: SetEvent9(t); break; case 10: SetEvent10(t); break; case 11: SetEvent11(t); break; case 15: SetEvent15(t); break; } SystemOpen[RedirectType(t.Type, t.SubType)] = true; GContext.Publish(new TargetEvent(t.ID, t.Type, t.SubType)); return true; } return false; } public bool FixedTimeEventExpired(int eventId) { if (fixedTimeEventDic.TryGetValue(eventId, out FixedTimeEvent fixedTimeEvent)) { var endTime = GlobalUtils.TryParseDateTime(fixedTimeEvent.endTime, ZZTimeHelper.UtcNow().UtcNowOffset()); return endTime.Ticks > ZZTimeHelper.UtcNow().UtcNowOffset().Ticks; } return true; } public bool Condition(FishingEvent fishingEvent) { if (fishingEvent == null) { return false; } bool isOpen = true; if (fishingEvent.TimeDefinition is UserRegistration) { UserRegistration userRegistrationEvent = (UserRegistration)fishingEvent.TimeDefinition; double time = GContext.container.Resolve().CreateTotalSeconds(); isOpen = userRegistrationEvent.StartTime <= time && time < userRegistrationEvent.EndTime; } else if (fishingEvent.TimeDefinition is FixedTime) { isOpen = FixedTimeEventExpired(fishingEvent.ID); } else if (fishingEvent.TimeDefinition is LimitedTime) { LimitedTime limitedTime = (LimitedTime)fishingEvent.TimeDefinition; isOpen = GlobalUtils.TryParseDateTime(limitedTime.StartTime, ZZTimeHelper.UtcNow()) <= ZZTimeHelper.UtcNow() && ZZTimeHelper.UtcNow() < GlobalUtils.TryParseDateTime(limitedTime.EndTime, ZZTimeHelper.UtcNow()); } if (!isOpen) { if (fishingEvent.Type == 3 && fishingEvent.SubType == 3 && fishingEvent.TimeDefinition is LimitedTime) { if (GetOpenByConditionList(fishingEvent.ConditionList, fishingEvent.ConditionRelation)) { LimitedTime limitedTime = (LimitedTime)fishingEvent.TimeDefinition; RankInit rankInit = _tables.TbRankInit.GetOrDefault(fishingEvent.RedirectID); if (rankInit != null) { DateTime endTime = GlobalUtils.TryParseDateTime(limitedTime.StartTime, ZZTimeHelper.UtcNow().AddMonths(-1)).AddSeconds(rankInit.HoldTime); if (endTime > ZZTimeHelper.UtcNow()) { GContext.container.Resolve().lastEventRank = rankInit; GContext.container.Resolve().fishingEvent = fishingEvent; } } } } return false; } //ab测试影响 开启时间不一致 走单独逻辑 // if (fishingEvent.Type == 2 && fishingEvent.SubType == 4) // { // return ad.IsOpen(this, fishingEvent, GetEventCondition, Condition_NoRechargeSeconds); // } return GetOpenByConditionList(fishingEvent.ConditionList, fishingEvent.ConditionRelation); } bool GetOpenByConditionList(List ConditionList, int ConditionRelation) { bool isOpen = false; int conditionCount = ConditionList.Count; if (conditionCount > 1) { if (ConditionRelation == 0) { isOpen = false; //或 for (int i = 0; i < conditionCount; i++) { if (GetEventCondition(ConditionList[i])) { isOpen = true; break; } } } else { isOpen = true; // 1与 for (int i = 0; i < conditionCount; i++) { if (!GetEventCondition(ConditionList[i])) { isOpen = false; break; } } } } else { isOpen = GetEventCondition(ConditionList[0]); } return isOpen; } bool GetEventCondition(EventCondition eventCondition) { bool isOpen = false; switch (eventCondition.Condition) { case ConditionType.AccountLevel: isOpen = GContext.container.Resolve().lv >= int.Parse(eventCondition.Param[0]); break; case ConditionType.GetFishCount: isOpen = GContext.container.Resolve().GetAnglingCount() >= int.Parse(eventCondition.Param[0]); break; case ConditionType.RoleCreateTime: //isOpen = true; double time = GContext.container.Resolve().CreateTotalSeconds(); isOpen = (time >= int.Parse(eventCondition.Param[0]) * 3600); break; case ConditionType.RoleCreateTimeLessThan: //isOpen = true; double time1 = GContext.container.Resolve().CreateTotalSeconds(); isOpen = (time1 < int.Parse(eventCondition.Param[0]) * 3600); break; case ConditionType.AccountLevelAfterNoEnergy: isOpen = GContext.container.Resolve().lv > int.Parse(eventCondition.Param[0]); break; case ConditionType.NoRechargeSeconds: isOpen = Condition_NoRechargeSeconds(int.Parse(eventCondition.Param[0])); break; default: Debug.LogWarning($"Event {eventCondition.Condition} not registered."); break; } return isOpen; } private bool Condition_NoRechargeSeconds(int timeSeconds) { var lastPaymentStr = PlayFabMgr.Instance.GetLocalData("LastPaymentTime"); DateTime curTime = ZZTimeHelper.UtcNow().UtcNowOffset(); DateTime endTime = curTime; if (string.IsNullOrEmpty(lastPaymentStr) || !lastPaymentStr.Contains("__")) endTime = GContext.container.Resolve().CreateTime.UtcNowOffset(); //else //{ // var lastPaymentTimeStr = lastPaymentStr.Split('_')?.FirstOrDefault(); // if (string.IsNullOrEmpty(lastPaymentTimeStr)) return false; // endTime = GlobalUtils.TryParseDateTime(lastPaymentTimeStr, curTime); //} var curTimeSceond = new DateTimeOffset(curTime).ToUnixTimeSeconds(); var endTimeSceond = new DateTimeOffset(endTime).ToUnixTimeSeconds(); if (curTimeSceond - endTimeSceond >= timeSeconds) return true; return false; } public static bool Condition_NoRechargeDay(int timeDay = 7) { var lastPaymentStr = PlayFabMgr.Instance.GetLocalData("LastPaymentTime"); if (!string.IsNullOrEmpty(lastPaymentStr) && lastPaymentStr.Contains("__")) return false; DateTime curTime = ZZTimeHelper.UtcNow(); DateTime endTime = GContext.container.Resolve().CreateTime; if ((curTime - endTime).Days < timeDay) return false; return true; } void SetEvent1(FishingEvent t) { switch (t.SubType) { case 2: GContext.container.Resolve().IsOpenMagnification = true; break; case 3: GContext.container.Resolve().IsVIPOpen = true; break; case 4: GContext.container.Resolve().IsShopOpen = true; GContext.Publish(new SUnlockDiamondShopEvent { }); break; case 5: break; case 6: GContext.container.Resolve().IsOpenMap = true; break; case 7: GContext.container.Resolve().IsOpenRod = true; break; //case 8: // GContext.container.Resolve().IsOpenAutoFish = true; // break; case 9: GContext.container.Resolve().IsShopTopOpen = true; break; case 10: GContext.container.Resolve().OpenAdPack(); break; case 11: var dataProvider1 = GContext.container.Resolve(); dataProvider1.IsUnclocked = true; //var boxCount = dataProvider1.Data.GetBoxTotalCount(); //RedPointManager.Instance.SetRedPointState("Home.FishingBox", boxCount > 0, boxCount); break; case 13: GContext.container.Resolve().IsOpenPiercing = true; break; case 14: GContext.container.Resolve().IsUnlock = true; break; //case 15: // //GContext.container.Resolve().IsUnlock = true; // break; //case 17: // //GContext.container.Resolve().IsUnlock = true; // break; case 18: GContext.container.Resolve().OpenGrade = true; break; case 19: IsJoinUsPanelOpen = true; // Debug.Log("IsJoinUsPanelOpen True!!!!!!!!!!!"); break; case 20: IsAquariumOpen = true; break; case 21: GContext.container.Resolve().IsOpenleaderboard = true; break; case 22: IsOpenDrop = true; break; } } public bool GetSystemOpen(int id) { FishingEvent fishingEvent = _tables.TbFishingEvent.GetOrDefault(id); if (fishingEvent == null) { return false; } id = RedirectType(fishingEvent.Type, fishingEvent.SubType); return SystemOpen.TryGetValue(id, out bool isOpen) ? isOpen : false; } void SetEvent2(FishingEvent t) { switch (t.SubType) { case 1: //七日签到礼包 GContext.container.Resolve().SetDailySignEvent(t); break; case 2: //周任务 //GContext.container.Resolve().SetTaskToWeeklyEvent(t); break; case 3: //GContext.container.Resolve().SetEventSignEvent(t); break; } } void SetEvent3(FishingEvent t) { switch (t.SubType) { //case 1: // GContext.container.Resolve().SetAlbumEvent(t); // GContext.container.Resolve().AlbumEventID = t.ID; // break; case 2: SetCollectingTargetEvent(t); break; case 3: SetRankEvent(t); break; case 4: //转盘 SetTurntable(t); break; case 7: GContext.container.Resolve().RefreshBattlePassRecord(t); break; case 8: case 11: SetEventPackData(t); break; case 9: // Debug.Log("Black Friday update data!!"); var d = GContext.container.Resolve().CouponData; d.UpdateData(t); if (d.IsActive && d.DoesPop) { GContext.container.Resolve() .AddGiftFaceUIForce(t.ID, UITypes.BlackFridayPopupPanel); d.DoesPop = false; } break; case 10: GContext.container.Resolve().AddChainPack(t); break; } } void SetEvent6(FishingEvent t) { switch (t.SubType) { case 1: SetPack1A2(t); break; case 2: // Debug.Log($"Event Triggered Thanks Giving!"); // if (t.ID != data.EventId) // data.UpdateData(t); break; } } private void SetEvent7(FishingEvent e) { // switch (e.SubType) // { // case 1: // if (data == null) // { // } // data.UpdateData(e); // UITypes.EventWinterShootingPanel.SetType(data.MainPanelUrl); // UITypes.ShootingChainPackPanel.SetType(data.ChainPackPanelUrl); // UITypes.ShootingRangeFinalRewardPopup.SetType(data.RewardPanelUrl); // UITypes.ShootingRangeInfoPanel.SetType(data.InfoPanelUrl); // UITypes.ShootingNormalPackPanel.SetType(data.PackPanelUrl); // UITypes.ShootingRangeTransitionPanel.SetType(data.TransitionPanelUrl); // break; // case 2: // // Debug.Log($"[EventBreak] Id {e.ID} activated."); // EventBreakAct.Ctx = EventBreakTableContext.ReadTables(e.ID, GContext.container.Resolve()); // if (eventBreakModel == null) // { // } // if (eventBreakModel != null && eventBreakModel.EventId == e.ID) // return; // eventBreakModel.Update(e.ID, playfabData); // var uiData = EventBreakAct.Ctx.GetUIData(); // UITypes.EventBreakPanel.SetType(uiData.MainPanelUrl); // UITypes.EventBreakInfoPanel.SetType(uiData.InfoPanelUrl); // UITypes.EventBreakChainPackPanel.SetType(uiData.ChainPackPanelUrl); // UITypes.EventBreakNormalPackPanel.SetType(uiData.NormalPackPanelUrl); // UITypes.EventBreakRewardPopupPanel.SetType(uiData.RewardPanelUrl); // break; // case 3: // 刮刮乐 // break; // case 4: // var ecPpString = PlayerPrefs.GetString(EventCanPlayerPreferenceData.PlayerPrefsKey); // var ecPlayerPrefsData = EventCanPlayerPreferenceData.Deserialize(ecPpString); // var tableContext = GContext.container.Resolve(); // if (tableContext == null) // { // GContext.container.Register().AsSingleton(); // tableContext = GContext.container.Resolve(); // } // tableContext.ReadTables(e.ID); // if (canModel == null || canModel.EventId != e.ID) // { // if (canModel == null) // { // tableContext.ReadTables(e.ID); // } // canModel.InitializeModel(e.ID, ecPlayfabData, ecPlayerPrefsData); // } // if (chainPackData == null) // { // } // chainPackData.Init( // GContext.container.Resolve().GetPackData(canModel.ChainPackID), // e.ID, ref canModel.ChainPackProgress); // break; // case 5: // EventGatherCoreAct.Ctx = EventGatherCoreTableContext.ReadTables(e.ID); // var egcPfData = EventGatherCorePlayfabData.Load(); // if (gatherCoreData == null) // { // } // if (gatherCoreData != null && gatherCoreData.EventId == e.ID) // return; // if (egcPfData != null && egcPfData.EventId == e.ID) // gatherCoreData.LoadData(egcPfData); // else // gatherCoreData.InitNew(e.ID); // var gatherCoreUiData = EventGatherCoreAct.Ctx.GetUiData(); // UITypes.EventGatherCorePanel.SetType(gatherCoreUiData.MainPanelUrl); // UITypes.EventGatherCoreInfoPanel.SetType(gatherCoreUiData.InfoPanelUrl); // UITypes.EventGatherCoreChainPackPanel.SetType(gatherCoreUiData.ChainPackPanelUrl); // UITypes.EventGatherCoreNormalPackPanel.SetType(gatherCoreUiData.NormalPackPanelUrl); // UITypes.EventGatherCoreRewardPopupPanel.SetType(gatherCoreUiData.RewardPopupPanelUrl); // break; // case 6: // break; // case 10: // 砸罐子 // { // var smashMain = _tables.TbEventSmashMain.GetOrDefault(e.RedirectID); // if (smashMain != null && smashMain.BattlePassId > 0) // { // } // } // break; // } } void SetEvent8(FishingEvent t) { // switch (t.SubType) // { // case 2: // SetTurntable(t); // break; // case 3: // var pfString = PlayFabMgr.Instance.GetLocalData(EventLuckMagicPlayfabData.Key); // var pfData = EventLuckMagicPlayfabData.Deserialize(pfString); // var ppString = PlayerPrefs.GetString(EventLuckMagicPlayerPreferenceData.Key); // var ppData = EventLuckMagicPlayerPreferenceData.Deserialize(ppString); // // EventLuckMagicAct.TableContext = EventLuckMagicTableContext.ReadTables(t.ID); // if (eventLuckMagicModel == null) // { // if (pfData == null || pfData.EventId != t.ID) // eventLuckMagicModel.InitNew(t.ID); // else // eventLuckMagicModel.Load(pfData, ppData); // } // else if (eventLuckMagicModel.EventId != t.ID) // { // // Here, I'll assume that playfab data is consistent with the model in memory. // eventLuckMagicModel.InitNew(t.ID); // } // else // { // //In this situation, this is a redundant call. // } // EventLuckMagicAct.System = new EventLuckMagicSystem(); // var uiUrls = EventLuckMagicAct.TableContext.GetUiPanelUrls(); // UITypes.EventLuckMagicTriplePackPanel.SetType(uiUrls.TriplePackPanelUrl); // break; // case 4: // break; // } } /// /// 9-1 小战令 /// 9-5 offer journey /// 9-6 小马礼包 /// /// void SetEvent9(FishingEvent t) { // if (t.SubType == 4) // { // } // else if (t.SubType == 5) // { // var playerData = GContext.container.Resolve(); // var eventOfferJourneyLvlTriggerTableContext = new EventOfferJourneyLvlTriggerTableContext(); // var pfData = EventOfferJourneyLvlTriggerPlayfabData.Load(); // if (eventOfferJourneyLvlTriggerTableContext.IsEventActive && // (pfData == null || pfData.RoundCount < eventOfferJourneyLvlTriggerTableContext.MaxRoundCount)) // { // Debug.Log("[EventOfferJourney] Normal event suppressed. TriggerPack On the way."); // return; // } // else if (offerJourneyData == null) // { // if (!offerJourneyData.LoadDataFromPlayfab() || offerJourneyData.EventId != t.ID) // { // } // GContext.container.Resolve().AddGiftFaceUI(t.ID, UITypes.EventOfferJourneyPanel, 0); // } // else if (offerJourneyData.EventId != t.ID) // { // offerJourneyDataActual.Init(t.ID, playerData.PriceLv); // else // { // } // GContext.container.Resolve().AddGiftFaceUI(t.ID, UITypes.EventOfferJourneyPanel, 0); // } // else // { // Debug.Log("[EventOfferJourney] Redundant call, ignore."); // } // var uiData = offerJourneyData.GetUiData(); // UITypes.EventOfferJourneyPanel.SetType(uiData.PanelUrl); // UITypes.EventOfferJourneyInfoPanel.SetType(uiData.InfoPanelUrl); // } // else if (t.SubType == 6) // { // } // else if (t.SubType == 7) // { // } // else if (t.SubType == 8) // { // } // else if (t.SubType == 11) // { // } // else if (t.SubType == 1 || t.SubType == 2 || t.SubType == 3) // { // } // else if (t.SubType == 9) // { // } } void SetEvent10(FishingEvent t) { } void SetEvent11(FishingEvent t) { // switch (t.SubType) // { // case 1: // break; // } } private void InitPartnerGatherData(FishingEvent fishingEvent) { // manager.UpdateEventData(fishingEvent); // EventPartnerStatueTokenExchangeData.Load(fishingEvent); } public void InitCubeMeltData(FishingEvent fishingEvent) { } public void SetRankEvent(FishingEvent t) { rankEvent = t; if (!RankTargetCount.ContainsKey(0)) { RankTargetCount[0] = 0; } if (rankInit == null || RankTargetCount[0] != rankEvent.ID) { rankInit = _tables.TbRankInit.GetOrDefault(rankEvent.RedirectID); InitRankTarget(); //GContext.Publish(new TargetEvent(rankInit.ID, 3, 3)); } } void SetTurntable(FishingEvent t) { turntableEvent = t; if (!WheelLevelCount.ContainsKey(0)) { WheelLevelCount[0] = 0; } if (wheelInit == null || WheelLevelCount[0] != t.ID) { wheelInit = _tables.TbWheelInit.GetOrDefault(t.RedirectID); InitWheelLevel(); } //GContext.Publish(new TargetEvent(wheelInit.ID, 3, 4)); } public void InitTurntableRoll(int value) { TurntableCoupon = value; } public void AddTurntableCoupon(int value) { TurntableCoupon = TurntableCoupon + value; if (turntableEvent != null) { SaveTransitionData(turntableEvent.ID, TurntableCoupon); } TurntableRed(); PlayFabMgr.Instance.UpdateUserDataValue("TurntableRoll", TurntableCoupon.ToString()); } public void RewardTurntableRoll(int value, bool remote = true) { GContext.Publish(new ConditionTypeEvent { type = ConditionType.ConusumeTicketCount, count = value }); //Debug.Log($"Consume {value}"); TurntableCoupon = TurntableCoupon - value; if (turntableEvent != null) SaveTransitionData(turntableEvent.ID, TurntableCoupon); TurntableRed(); #if AGG using (var e = GEvent.GameEvent("item_change", gaSend: true)) { e.AddContent("item_id", 1004) .AddContent("state_info", "cost") .AddContent("change_num", value); } #endif PlayFabMgr.Instance.UpdateUserDataValue("TurntableRoll", TurntableCoupon.ToString(), remote); } public void TurntableRed() { int CostNumber = 10; if (wheelLevel != null) { CostNumber = wheelLevel.CostNumber; } RedPointManager.Instance.SetRedPointState(RedPointName.Home_Turntable, TurntableCoupon >= 10 && TurntableCoupon >= CostNumber); } public void GMSetEvent(int eventId) { FishingEvent fishingEvent = _tables.TbFishingEvent.GetOrDefault(eventId); if (fishingEvent == null) { return; } switch (fishingEvent.Type) { case 1: SetEvent1(fishingEvent); SystemOpen[RedirectType(fishingEvent.Type, fishingEvent.SubType)] = true; break; case 3: case 4: if (fishingEvent.TimeDefinition is LimitedTime) { LimitedTime limitedTime = (LimitedTime)fishingEvent.TimeDefinition; limitedTimeEventDic[eventId] = new LimitedTimeEvent() { id = eventId, duration = (GlobalUtils.TryParseDateTime(limitedTime.EndTime, ZZTimeHelper.UtcNow()) - GlobalUtils.TryParseDateTime(limitedTime.StartTime, ZZTimeHelper.UtcNow())).TotalMinutes, startTime = ZZTimeHelper.UtcNow().UtcNowOffset().ToString("yyyy-MM-dd HH:mm:ss") }; } else if (fishingEvent.TimeDefinition is FixedTime) { FixedTime fixedTime = (FixedTime)fishingEvent.TimeDefinition; limitedTimeEventDic[eventId] = new LimitedTimeEvent() { id = eventId, duration = fixedTime.StartTime / 60, startTime = ZZTimeHelper.UtcNow().UtcNowOffset().ToString("yyyy-MM-dd HH:mm:ss") }; } //保存到PlayFab SetLimitedTimeEventDic(); if (fishingEvent.Type == 3) { SetEvent3(fishingEvent); } else if (fishingEvent.Type == 4) { if (fishingEvent.SubType == 5) { } else if (fishingEvent.SubType == 6) { } } else if (fishingEvent.Type == 6) { SetEvent6(fishingEvent); } SystemOpen[RedirectType(fishingEvent.Type, fishingEvent.SubType)] = true; break; case 7: if (fishingEvent.SubType == 3) { } break; } GContext.Publish(new TargetEvent(eventId, fishingEvent.Type, fishingEvent.SubType)); } void SetLimitedTimeEventDic() { PlayFabMgr.Instance.UpdateUserDataValue("LimitedTimeEventDic", Newtonsoft.Json.JsonConvert.SerializeObject(limitedTimeEventDic)); } #region 目标奖励活动 #region 新目标奖励活动 public float OnFishReward(int mapId, int index, int fishCount) { float extraPoint = 0; if (collectingTargetInit != null) { EventTargetExtraDrop eventTargetExtraDrop = collectingTargetInit.FishingExtraDrop; int itemId = 0; if (eventTargetExtraDrop is ETKeepsake) { var eTKeepsake = eventTargetExtraDrop as ETKeepsake; itemId = eTKeepsake.FishIDList[index]; if (index == 0) { int curHour = ZZTimeHelper.UtcNow().UtcNowOffset().Hour; if (curHour >= 16) { curHour = 16; } else if (curHour >= 8) { curHour = 8; } else { curHour = 0; } //每日清空的数据 GContext.container.Resolve().AddShopPackDailyBuyCount("CTFishID0" + curHour); } } else if (eventTargetExtraDrop is ETNewItem) { var etNewItem = eventTargetExtraDrop as ETNewItem; itemId = etNewItem.NewItemID[index]; } if (itemId > 0) { var itemToFishID = _tables.TbItem[itemId].RedirectID; if (ETDropAfterDropDic.ContainsKey(itemToFishID)) { ETDropAfterDropDic[itemToFishID] += fishCount; ETDropAfterDropDic[itemId]++; } else { ETDropAfterDropDic.Add(itemId, 1); ETDropAfterDropDic.Add(itemToFishID, fishCount); } SaveCollectingTargetEvent(); extraPoint += GContext.container.Resolve().GetCollectionTargetExtraPointBuffValue(mapId); } } return extraPoint; } void SaveCollectingTargetEvent() { GContext.container.Resolve().SavePlayerData(); //PlayFabMgr.Instance.UpdateUserDataValue("ETDropAfterDropDic", JsonMapper.ToJson(ETDropAfterDropDic)); } public string CTSerialize() { if (ETDropAfterDropDic.Count > 0) { return ETDropAfterDropDic.Select(kv => kv.Key + ":" + kv.Value).Aggregate((a, b) => a + "," + b); } else { return ""; } } public void CTDeserialize(string data) { if (!string.IsNullOrEmpty(data)) { ETDropAfterDropDic.Clear(); var pairs = data.Split(','); foreach (var pair in pairs) { var kv = pair.Split(':'); if (kv.Length == 2 && int.TryParse(kv[0], out int key) && int.TryParse(kv[1], out int value)) { ETDropAfterDropDic[key] = value; } } } } #endregion void SetCollectingTargetEvent(FishingEvent t) { // int idOffset = _mmtService.GetEventTargetIDOffset(); int idOffset = 0; int RedirectID = t.RedirectID + idOffset; var curTime = ZZTimeHelper.UtcNow().UtcNowOffset(); //ETDropAfterDropDic.Clear(); if (!ETDropAfterDropDic.ContainsKey(0)) { //新手活动 NewPlayerEvent = curTime.AddSeconds(_tables.TbGlobalConfig.EventtargetNoviceMinTime); if (t.TimeDefinition is LimitedTime) { LimitedTime limitedTime = (LimitedTime)t.TimeDefinition; var endTime = GlobalUtils.TryParseDateTime(limitedTime.EndTime, ZZTimeHelper.UtcNow()).UtcNowOffset(); //下一个目标奖励活动为常规目标奖励活动,如果其剩余时间小于1天,则时间会被归并到本次目标奖励活动 if (endTime < NewPlayerEvent) { endTime = endTime.AddDays(3); } if (endTime < curTime.AddSeconds(_tables.TbGlobalConfig.EventtargetNextToNoviceMaxTime)) { NewPlayerEvent = endTime; } } ETDropAfterDropDic[0] = 0; ETDropAfterDropDic[-3] = (int)(NewPlayerEvent - new DateTime(2025, 10, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;//存储新手活动结束时间 SaveCollectingTargetEvent(); } else if (ETDropAfterDropDic.ContainsKey(-3)) { NewPlayerEvent = new DateTime(2025, 10, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(ETDropAfterDropDic[-3]); } if (NewPlayerEvent > curTime) { //随便输入一个不存在的ID collectingTargetEventID = virtualCollectingTargetEventID; RedirectID = _tables.TbGlobalConfig.EventtargetNoviceID + idOffset; } else { collectingTargetEventID = t.ID; } bool redirectIDChanged = ETDropAfterDropDic.TryGetValue(-6, out var savedRedirectID) && savedRedirectID != RedirectID; if (collectingTargetInit == null || ETDropAfterDropDic[0] != collectingTargetEventID || redirectIDChanged) { //new target event collectingTargetInit = _tables.TbCollectingTargetInit.GetOrDefault(RedirectID); if (collectingTargetInit == null && idOffset != 0) { Debug.LogError($"CollectingTargetInit not found with MMT offset, fallback: {RedirectID} -> {RedirectID - idOffset}"); RedirectID -= idOffset; collectingTargetInit = _tables.TbCollectingTargetInit.GetOrDefault(RedirectID); } if (collectingTargetInit == null) { Debug.LogError($"CollectingTargetInit Error Id == {RedirectID} EventId == {collectingTargetEventID}"); GContext.container.Resolve().ClearTargetBuff(); collectingTarget = null; collectingTargetResoure = false; } else { if (redirectIDChanged) { ETDropAfterDropDic.Clear(); ETDropAfterDropDic[0] = 0; } collectingTargetResoure = false; collectingTargetInitTokenID = collectingTargetInit.TokenID; collectingTargetInitTaskID = collectingTargetInit.TaskID; InitCollectingTarget(); ETDropAfterDropDic[-6] = RedirectID; SaveCollectingTargetEvent(); UITypes.FishingTargetPopupPanel.SetType(collectingTargetInit.BgDescPrefab); } } } public async Task CheckResourceLoadQueue(string key, List label) { if (!collectingTargetResoure) { ILoadResourceService loadResourceService = GContext.container.Resolve(); collectingTargetResoure = await loadResourceService.CheckResourceLoadQueue(key, label); } return collectingTargetResoure; } int requiredCount = 0; void InitCollectingTarget() { if (!ETDropAfterDropDic.ContainsKey(0)) { ETDropAfterDropDic[0] = 0; } //Event Still Launch if (collectingTargetEventID == ETDropAfterDropDic[0]) { SetTargetList(); ETDropAfterDropDic.TryGetValue(collectingTargetInitTokenID, out var progress); while (collectingTarget != null && collectingTarget.NextTarget > 0 && requiredCount <= progress) { collectingTarget = _tables.TbCollectingTargetReward.GetOrDefault(collectingTarget.NextTarget); requiredCount += collectingTarget.TokenRequiredB; ETDropAfterDropDic.TryGetValue(collectingTargetInitTokenID, out progress); } } //Event Still Launch else { RefreshTargetGuidance(); if (collectingTargetEventID == virtualCollectingTargetEventID) { ETDropAfterDropDic[0] = virtualCollectingTargetEventID; } else { ETDropAfterDropDic.Clear(); ETDropAfterDropDic[0] = collectingTargetEventID; } var TargetGroupByHook = collectingTargetInit.TargetGroupByHook; int hook = GContext.container.Resolve().Energy; for (int i = TargetGroupByHook.Count - 1; i >= 0; i--) { if (hook >= TargetGroupByHook[i]) { ETDropAfterDropDic[-5] = i; //记录当前钩子档位 break; } } ETDropAfterDropDic[-4] = (int)(GContext.container.Resolve().InflationRate * 100); SetTargetList(); GContext.container.Resolve().ClearTargetBuff(); } } void SetTargetList() { TargetList = GetIndexOfCollectingTargetHook(); collectingTarget = _tables.TbCollectingTargetReward.GetOrDefault(TargetList[0]); requiredCount = collectingTarget.TokenRequiredB; } public bool VirtualCollectingTargetEvent => collectingTargetEventID == virtualCollectingTargetEventID; /// /// 特殊鱼,技能新手引导数量 /// public bool TargetGuidance(string guidanceName) { if (_isTargetGuidance) { _isTargetGuidance = false; int SkillGuidanceRemainings = _tables.TbGlobalConfig.SkillGuidanceRemainings; if (SkillGuidanceRemainings > (ETDropAfterDropDic.TryGetValue(1, out var progress) ? progress : 0)) { bool isGuide = GContext.container.Resolve().TriggerGuide(guidanceName, "FishingPanel_Advanced", true); if (isGuide) { if (!ETDropAfterDropDic.ContainsKey(1)) { ETDropAfterDropDic[1] = 1; } else { ETDropAfterDropDic[1]++; } SaveCollectingTargetEvent(); } return isGuide; } } return false; } public void RefreshTargetGuidance() { _isTargetGuidance = true; } public int GetCollectingTargetCount() { return ETDropAfterDropDic.TryGetValue(-1, out var progress) ? progress : 0; } public void AddCollectingTarget(int progress) { if (collectingTarget != null) { preCollectingTarget = null; if (!ETDropAfterDropDic.ContainsKey(collectingTargetInitTokenID)) { ETDropAfterDropDic[collectingTargetInitTokenID] = 0; } //float Enhanced = GContext.container.Resolve().GetDoubleTokenEnhanced(); //if (Enhanced > UnityEngine.Random.value) //{ // progress += progress; //} int _progress; bool isMax = requiredCount <= (ETDropAfterDropDic.TryGetValue(collectingTargetInitTokenID, out _progress) ? _progress : 0); GContext.Publish(new TargetAddData(collectingTargetInitTokenID, GetCurCollectingTarget(), progress)); ETDropAfterDropDic[collectingTargetInitTokenID] += progress; targetItemDatas = null; if (!isMax && requiredCount <= (ETDropAfterDropDic.TryGetValue(collectingTargetInitTokenID, out _progress) ? _progress : 0)) { List dropIDs = new List(); preCollectingTarget = new Queue(); SetNextCollectingTarget(dropIDs); var fishingStage = GContext.container.ResolveStage("FishingStage") as FishingStage; if (fishingStage != null) { fishingStage.IsNextQueue = true; fishingStage.NextQueueKey = NextQueueKey; } PlayerItemData playerItemData = GContext.container.Resolve(); ChangeSource changeSource = new ChangeSource(ETDropAfterDropDic[0], "Event_CollectingTarget", "Event_CollectingTarget", "TaskReward"); targetItemDatas = playerItemData.AddItemByDropListLureInflation(CollectingTargetInflation, dropIDs, changeSource); if (fishingStage != null) { fishingStage.IsNextQueue = false; fishingStage.NextQueueKey = string.Empty; } //时间不同 特殊处理 GContext.Publish(new TargetEvent(collectingTargetInitTaskID, 3, 2)); } #if AGG using (var e = GEvent.GameEvent("target_event")) { e.AddContent("event_no", collectingTargetInitTaskID) .AddContent("reward_info", progress) .AddContent("group_index", ETDropAfterDropDic.GetValueOrDefault(-5)) .AddContent("range_no", collectingTarget.TaskID); if (targetItemDatas != null) { int reward_hook = 0; int hook_origin = 0; int reward_cash = 0; for (int i = 0; i < targetItemDatas.Count; i++) { if (targetItemDatas[i].id == 1001) { reward_hook += targetItemDatas[i].count; hook_origin += targetItemDatas[i].origin; } else if (targetItemDatas[i].id == 1002) { reward_cash += targetItemDatas[i].count; } } e.AddContent("reward_hook", reward_hook) .AddContent("hook_origin", hook_origin) .AddContent("reward_cash", reward_cash); } } #endif SaveCollectingTargetEvent(); } } void SetNextCollectingTarget(List dropIDs) { //掉落奖励 dropIDs.Add(collectingTarget.DropID); // GContext.container.Resolve().GetItemDataByDropId(collectingTarget.DropID); preCollectingTarget.Enqueue(collectingTarget); if (collectingTarget.NextTarget <= 0) { return; } collectingTarget = _tables.TbCollectingTargetReward.GetOrDefault(collectingTarget.NextTarget); requiredCount += collectingTarget.TokenRequiredB; if (requiredCount <= ETDropAfterDropDic[collectingTargetInitTokenID]) { SetNextCollectingTarget(dropIDs); } } public int GetAllCollectingTarget() { if (collectingTarget != null) { return GetEtDropAfterDropDic(collectingTargetInitTokenID); } return 0; } public int GetCurCollectingTarget() { if (collectingTarget != null) { int startNum = 0; int id = TargetList[0]; CollectingTargetReward localcollectingTarget = _tables.TbCollectingTargetReward.GetOrDefault(id); if (collectingTarget.TaskID != id) { startNum += localcollectingTarget.TokenRequiredB; ETDropAfterDropDic.TryGetValue(collectingTargetInitTokenID, out var progress); while (localcollectingTarget != null && startNum <= progress) { localcollectingTarget = _tables.TbCollectingTargetReward.GetOrDefault(localcollectingTarget.NextTarget); if (localcollectingTarget.NextTarget <= 0) { if (localcollectingTarget.NextTarget == 0) { Debug.LogError("CollectingTargetReward NextTarget == 0"); } break; } startNum += localcollectingTarget.TokenRequiredB; if (startNum > progress) { startNum -= localcollectingTarget.TokenRequiredB; break; } } } return GetAllCollectingTarget() - startNum; } return 0; } public void AddCollectingTarget(int id, int progress) { // int idOffset = _mmtService.GetEventTargetIDOffset(); int idOffset = 0; if (collectingTarget == null || (id != collectingTargetInitTaskID && id + idOffset != collectingTargetInitTaskID)) { return; } AddCollectingTarget(progress); } public void GetRankData() { if (IsOpenRank()) { _ = GContext.container.Resolve().GetLeaderboard(RankTargetCount[rankInit.TokenID]); } if (GContext.container.Resolve().IsOpenleaderboard) { //GContext.container.Resolve().SetLvData(); GContext.container.Resolve().GetLevelLeadboardData(); GContext.container.Resolve().GetLevelLeadboardData(true); } } public string RTSerialize() { if (RankTargetCount.Count > 0) { return RankTargetCount.Select(kv => kv.Key + ":" + kv.Value).Aggregate((a, b) => a + "," + b); } else { return ""; } } public void RTDeserialize(string data) { if (!string.IsNullOrEmpty(data)) { RankTargetCount.Clear(); var pairs = data.Split(','); foreach (var pair in pairs) { var kv = pair.Split(':'); if (kv.Length == 2 && int.TryParse(kv[0], out int key) && int.TryParse(kv[1], out int value)) { RankTargetCount[key] = value; } } } } public void AddRankTarget(int progress) { if (rankInit != null) { preRankTarget = null; if (!RankTargetCount.ContainsKey(rankInit.TokenID)) { RankTargetCount[rankInit.TokenID] = 0; } GContext.Publish(new TargetAddData(rankInit.TokenID, GetCurRankTarget(), progress)); bool isMax = requiredRankCount <= RankTargetCount[rankInit.TokenID]; RankTargetCount[rankInit.TokenID] += progress; if (IsOpenRank()) { GContext.container.Resolve().UpdateScore(RankTargetCount[rankInit.TokenID]); } GContext.container.Resolve().SavePlayerData(); //PlayFabMgr.Instance.UpdateUserDataValue("RankTargetCount", JsonMapper.ToJson(RankTargetCount)); rankItemDatas = null; if (!isMax && requiredRankCount <= RankTargetCount[rankInit.TokenID]) { List dropIDs = new List(); preRankTarget = new List(); //掉落奖励 SetNextRankTarget(dropIDs); ChangeSource changeSource = new ChangeSource(RankTargetCount[0], "Event_Rank", "Event_Rank", "TaskReward"); rankItemDatas = GContext.container.Resolve().AddItemByDropListLureInflation(RankTargetInflation, dropIDs, changeSource); } #if AGG using (var e = GEvent.GameEvent("rank_reward")) { e.AddContent("event_no", rankInit.ID) .AddContent("reward_info", progress) .AddContent("range_no", rankTarget.TaskID); if (rankItemDatas != null) { int reward_hook = 0; int hook_origin = 0; int reward_cash = 0; for (int i = 0; i < rankItemDatas.Count; i++) { if (rankItemDatas[i].id == 1001) { reward_hook += rankItemDatas[i].count; hook_origin += rankItemDatas[i].origin; } else if (rankItemDatas[i].id == 1002) { reward_cash += rankItemDatas[i].count; } } e.AddContent("reward_hook", reward_hook) .AddContent("hook_origin", hook_origin) .AddContent("reward_cash", reward_cash); } } #endif } } void SetNextRankTarget(List dropIDs) { preRankTarget.Add(rankTarget); //掉落奖励 dropIDs.Add(rankTarget.DropID); if (rankTarget.NextTarget <= 0) { return; } rankTarget = _tables.TbRankTargets.GetOrDefault(rankTarget.NextTarget); requiredRankCount += rankTarget.TokenRequiredB; if (requiredRankCount <= RankTargetCount[rankInit.TokenID]) { SetNextRankTarget(dropIDs); } } public int GetAllRankTarget() { if (rankInit != null) { return RankTargetCount.TryGetValue(rankInit.TokenID, out int progress) ? progress : 0; } return 0; } public int GetCurRankTarget() { if (rankInit != null) { int startNum = 0; int id = rankInit.TargetList[0]; RankTargets localRankTarget = _tables.TbRankTargets.GetOrDefault(id); if (rankTarget.TaskID != id) { startNum += localRankTarget.TokenRequiredB; RankTargetCount.TryGetValue(rankInit.TokenID, out int progress); while (localRankTarget != null && startNum <= progress) { localRankTarget = _tables.TbRankTargets.GetOrDefault(localRankTarget.NextTarget); if (localRankTarget.NextTarget <= 0) { if (localRankTarget.NextTarget == 0) { Debug.LogError("RankTargets NextTarget == 0"); } break; } startNum += localRankTarget.TokenRequiredB; if (startNum > progress) { startNum -= localRankTarget.TokenRequiredB; break; } } } return GetAllRankTarget() - startNum; } return 0; } public void AddRankTarget(int id, int progress) { if (rankTarget == null || id != rankInit.ID) { return; } AddRankTarget(progress); } /// /// 目标奖励活动相关 /// /// 0==eventID /// public int GetEtDropAfterDropDic(int id) { return ETDropAfterDropDic.TryGetValue(id, out int progress) ? progress : 0; } public List GetIndexOfCollectingTargetHook() { int index = ETDropAfterDropDic.GetValueOrDefault(-5); if (index >= collectingTargetInit.TargetList.Count) { Debug.LogError("TargetList.Count"); return collectingTargetInit.TargetList[0]; } return collectingTargetInit.TargetList[index]; } public float CollectingTargetInflation { get { return GetEtDropAfterDropDic(-4) / 100f; } } public int GetWheelLevelCount(int id) { return WheelLevelCount.TryGetValue(id, out int progress) ? progress : 0; } public DateTime GetCollectingTargetEndTime() { DateTime endTime = ZZTimeHelper.UtcNow().UtcNowOffset(); if (NewPlayerEvent > endTime) { return NewPlayerEvent; } return GetEventEndTime(collectingTargetEventID); } /// /// 统一计算 固定时间段时间计算 真实时间和配置时间全加偏移(其他配置是偏移后的时间) /// 计算的时候要使用 ZZTimeHelper.UtcNow()).UtcNowOffset() 时间 /// 也可以自己写代码计算结束时间 /// /// /// public DateTime GetEventEndTime(int eventId) { FishingEvent fishingEvent = _tables.TbFishingEvent.GetOrDefault(eventId); DateTime endTime = ZZTimeHelper.UtcNow().UtcNowOffset(); if (fishingEvent == null) { Debug.LogError($"FishingEvent not found for ID: {eventId}"); return endTime; } if (fishingEvent.TimeDefinition is LimitedTime) { //统一计算 固定时间段时间计算 真实时间和配置时间全加偏移(其他配置是偏移后的时间) LimitedTime limitedTime = (LimitedTime)fishingEvent.TimeDefinition; endTime = GlobalUtils.TryParseDateTime(limitedTime.EndTime, ZZTimeHelper.UtcNow()).UtcNowOffset(); } else if (fishingEvent.TimeDefinition is FixedTime) { if (fixedTimeEventDic.TryGetValue(fishingEvent.ID, out FixedTimeEvent fixedTimeEvent)) { endTime = GlobalUtils.TryParseDateTime(fixedTimeEvent.endTime, ZZTimeHelper.UtcNow().UtcNowOffset()); } } else if (fishingEvent.TimeDefinition is Weekly) { DateTime dateTime = ZZTimeHelper.UtcNow().UtcNowOffset().Date; Weekly weekly = (Weekly)fishingEvent.TimeDefinition; int offfset = (int)dateTime.DayOfWeek - weekly.StartTime; if (offfset < 0) { offfset = -offfset; } else { offfset = 7 - offfset; } endTime = dateTime.AddDays(offfset); //endTime = GlobalUtils.TryParseDateTime(time, ZZTimeHelper.UtcNow().UtcNowOffset()); } else if (fishingEvent.TimeDefinition is UserRegistration) { UserRegistration userRegistrationEvent = (UserRegistration)fishingEvent.TimeDefinition; endTime = GContext.container.Resolve().CreateTime.AddSeconds(userRegistrationEvent.EndTime).UtcNowOffset(); } if (limitedTimeEventDic.TryGetValue(fishingEvent.ID, out LimitedTimeEvent limitedTimeEvent)) { LimitedTime limitedTime = (LimitedTime)fishingEvent.TimeDefinition; var timer = ZZTimeHelper.UtcNow(); endTime = GlobalUtils.TryParseDateTime(limitedTimeEvent.startTime, timer.UtcNowOffset()) .Add((GlobalUtils.TryParseDateTime(limitedTime.EndTime, timer) - GlobalUtils.TryParseDateTime(limitedTime.StartTime, timer))); } return endTime; } //获取掉落的挂件 public EventTargetExtraDrop GetEventTargetExtraDrop() { if (collectingTargetInit != null) { return collectingTargetInit.FishingExtraDrop; } return null; } #endregion #region 排行榜事件 int requiredRankCount = 0; void InitRankTarget() { if (!RankTargetCount.ContainsKey(0)) { RankTargetCount[0] = 0; } if (rankInit != null && rankInit.TargetList.Count > 0) { rankTarget = _tables.TbRankTargets.GetOrDefault(rankInit.TargetList[0]); requiredRankCount = rankTarget.TokenRequiredB; if (rankTarget != null && rankEvent.ID == RankTargetCount[0]) { RankTargetCount.TryGetValue(rankInit.TokenID, out int progress); while (rankTarget != null && rankTarget.NextTarget > 0 && requiredRankCount <= progress) { rankTarget = _tables.TbRankTargets.GetOrDefault(rankTarget.NextTarget); requiredRankCount += rankTarget.TokenRequiredB; RankTargetCount.TryGetValue(rankInit.TokenID, out progress); } } else { RankTargetCount.Clear(); RankTargetCount[0] = rankEvent.ID; RankTargetCount[-4] = (int)(GContext.container.Resolve().InflationRate * 100); } if (!RankTargetCount.ContainsKey(rankInit.TokenID)) { RankTargetCount[rankInit.TokenID] = 0; } LeadboardData leadboardData = GContext.container.Resolve(); if (IsOpenRank()) { leadboardData.UpdateScore(RankTargetCount[rankInit.TokenID]); } else { leadboardData.rankTarget = null; leadboardData.GetRewards(); } } else rankTarget = null; } public float RankTargetInflation { get { return (RankTargetCount.TryGetValue(-4, out int progress) ? progress : 0) / 100f; } } public DateTime GetRankEndTime() { return GetEventEndTime(rankEvent.ID); } public bool IsOpenRank() { return (rankTarget != null && rankInit != null && GetAllRankTarget() >= rankInit.UnlockPoint); } #endregion #region 转盘事件 void InitWheelLevel() { if (wheelInit != null) { if (WheelLevelCount[0] != turntableEvent.ID) { int welcome = GetInitWelcomeGift(turntableEvent.ID); if (WheelLevelCount[0] != 0 || TurntableCoupon < welcome) { //不是第一次开启,代币归零 TurntableCoupon = welcome; } SaveTransitionData(turntableEvent.ID, TurntableCoupon); WheelLevelCount.Clear(); WheelLevelCount[0] = turntableEvent.ID; WheelLevelCount[-2] = 0; freecount = 0; wheelLevel = _tables.TbWheelLevel.DataList[0]; UpdateTurnTableData(); } else { int currentKey = WheelLevelCount.Keys.Max(); currentKey = currentKey < 1 ? 1 : currentKey; wheelLevel = _tables.TbWheelLevel.GetOrDefault(currentKey); } if (wheelLevel != null) { TurntableRed(); } } } public void UpdateTurnTableData() { PlayFabMgr.Instance.UpdateUserDataValue("WheelLevelCount", JsonMapper.ToJson(WheelLevelCount)); PlayFabMgr.Instance.UpdateUserDataValue("WheelLevelFreeCount", freecount.ToString()); } /// /// Add item by dropId and multiplier, or just return that item without giving to player, if doAdd is false. /// /// Drop ID. /// Multiplier of item. /// If true, items will actually be given to player. Otherwise, just resolve item. /// Item resolved. Potentially given to player, if doAdd is true. public ItemData UpdateWheel(int dropId, int magnification, bool doAdd = true) { ItemData itemData = GContext.container.Resolve().GetItemDataOne(dropId); itemData.count *= magnification; if (doAdd) GContext.container.Resolve().AddItem(itemData, null); return itemData; } public void AddIncreaseScore(int score, int multiplier) { IncreaseScore(score * multiplier); WheelOperateCount++; PlayFabMgr.Instance.UpdateUserDataValue("WheelOperateCount", WheelOperateCount.ToString()); AllWheelOperateCount += multiplier; PlayFabMgr.Instance.UpdateUserDataValue("AllWheelOperateCount", AllWheelOperateCount.ToString()); } public void IncreaseScore(int score) { // 获取当前转盘等级和积分进度 int progress = GetWheelLevelCount(wheelLevel.Level); // 增加对应积分 progress += score; WheelLevelCount[wheelLevel.Level] = progress; // 检查是否需要升级 if (progress >= wheelLevel.NextLevelPoint) { IncreaseWheelLevel(); } else { PlayFabMgr.Instance.UpdateUserDataValue("WheelLevelCount", JsonMapper.ToJson(WheelLevelCount)); } } public void AddFreecount(int count) { #if AGG if (count < 0) { using (var e = GEvent.GameEvent("item_change", gaSend: true)) { e.AddContent("item_id", 6002) .AddContent("state_info", "cost") .AddContent("change_num", count); } } #endif freecount += count; if (freecount < 0) { freecount = 0; } PlayFabMgr.Instance.UpdateUserDataValue("WheelLevelFreeCount", freecount.ToString()); } //转盘等级增加函数 public void IncreaseWheelLevel() { if (wheelLevel != null) { int progress = GetWheelLevelCount(wheelLevel.Level); int requiredPoints = wheelLevel.NextLevelPoint; // 循环检查是否需要升级到多个未来等级 while (wheelLevel.NextLevel > 0 && wheelLevel.NextLevel != wheelLevel.Level && progress >= requiredPoints && requiredPoints != -1) { WheelLevelCount[wheelLevel.Level] = wheelLevel.NextLevelPoint; wheelLevel = _tables.TbWheelLevel.GetOrDefault(wheelLevel.NextLevel); progress -= requiredPoints; requiredPoints = wheelLevel.NextLevelPoint; } // 更新积分进度 WheelLevelCount[wheelLevel.Level] = progress; TurntableRed(); PlayFabMgr.Instance.UpdateUserDataValue("WheelLevelCount", JsonMapper.ToJson(WheelLevelCount)); } } public DateTime GetTurntableEndTime() { return GetEventEndTime(turntableEvent.ID); } public bool IsShowTurntable() { if (turntableEvent == null) { return false; } var endTime = DateTime.Parse((turntableEvent.TimeDefinition as LimitedTime).EndTime); var startTime = DateTime.Parse((turntableEvent.TimeDefinition as LimitedTime).StartTime); var dateTime = ZZTimeHelper.UtcNow(); return wheelLevel != null && endTime > dateTime && startTime <= dateTime; } #endregion #region 事件驱动礼包 eventPack //private bool private void SetEventPackData(FishingEvent t) { //Debug.Log("I tried."); int packType = _tables.TbEventPackManager[t.RedirectID].PackType; switch (packType) { case 1: ActivateThreeChoseOnePack(t); break; case 2: ActivatePiggyBankPack(t); break; case 3: ActiavteBargainPack(t); break; case 6: SetPack1A1(t); break; //case 7: // SetPack1A2(t); // break; default: Debug.Log($"Pack Type {packType} of event {t.ID} unrecognized."); break; } } private void ActivateThreeChoseOnePack(FishingEvent t) { var eventPackDataSaved = GContext.container.Resolve();//pack data to be saved to remote server var eventPackDataRead = GContext.container.Resolve() .TbEventPackManager.DataMap[t.RedirectID];//pack data read from tables bool eventUpdated = eventPackDataSaved.UpdateEventData(t);//event is updated only when event changed or user login if (eventPackDataSaved.PurchaseCount < eventPackDataRead.MaxCount && eventUpdated) //TODO:change panel according to RedirecctID of current event GContext.container.Resolve().AddGiftFaceUI(t.ID, UITypes.GiftPopupPanel_9, eventPackDataRead.PackType); } private void ActivatePiggyBankPack(FishingEvent t) { } private void ActiavteBargainPack(FishingEvent t) { var eventPackDataSaved = GContext.container.Resolve();//pack data to be saved to remote server //var eventPackDataRead = GContext.container.Resolve() // .TbEventPackManager.DataMap[t.RedirectID];//pack data read from tables eventPackDataSaved.UpdateData(t);//event is updated only when event changed or user login } #endregion #region 获取事件礼包关于钓鱼的数据 public int curActivateItemId { get; set; } public int GetActivateItemId() { float BasicProb = UnityEngine.Random.Range(0, 1f); if (BasicProb <= _tables.TbGlobalConfig.CommercialFishParam) { try { // [REMOVED] PiggyBankPackData deleted BargainPackData barginPackData = GContext.container.Resolve(); if (barginPackData.DoNeedTrigger && barginPackData.IsWithinEventTime) { return barginPackData.ActivateItemId; } } catch (Exception e) { Debug.LogError($"GetActivateItemId Error: {e.Message}"); return 0; } } return 0; } public void AddProgress(int fishTier, int magnification) { // [REMOVED] PiggyBankPackData deleted BargainPackData barginPackData = GContext.container.Resolve(); if (barginPackData != null) { barginPackData.AddProgress(fishTier, magnification); } } #endregion public void Dispose() { disposable?.Dispose(); disposable = null; } #region 活动代币转换(已移除 EventTokenService,功能暂空) public Dictionary curTransitionData { get; private set; } = new Dictionary(); public void SaveTransitionData(int eventId, int count) { // if (eventId > 0) // { // TokenService.SetToken(eventId, count); // } } public int GetTransitionDataCount(int eventId) { // return TokenService.GetTokenCount(eventId); return 0; } void InitTransitionDataDic() { // GetTransitionData(); } int EVENT_END_TIME_EXTEND_DAYS = 9; void GetTransitionData() { // var allTokens = TokenService.GetAllTokens(); // if (allTokens != null && allTokens.Count > 0) // { // List removeKeys = new List(); // foreach (var item in allTokens) // { // FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(item.Key); // if (fe != null && (fe.Type == 4 || fe.Type == 8 || fe.Type == 7 || fe.Type == 15) && !Condition(fe)) // { // int count = item.Value; // if (count <= 0) // { // removeKeys.Add(item.Key); // continue; // } // var timeDefinition = fe.TimeDefinition; // if (timeDefinition is LimitedTime limitedTime) // { // DateTime endTime = DateTime.Parse(limitedTime.EndTime).AddDays(EVENT_END_TIME_EXTEND_DAYS); // if (endTime < ZZTimeHelper.UtcNow()) // { // removeKeys.Add(item.Key); // continue; // } // } // FishingEventCycleItem cycle = _tables.TbFishingEventCycleItem.GetOrDefault(fe.RedirectID); // if (cycle == null || cycle.EventEndSettlement.Count != 2) // { // removeKeys.Add(item.Key); // continue; // } // SetTransitionData(fe.ID, cycle.EventName_l10n_key, cycle.ItemId, cycle.EventEndSettlement); // } // } // if (removeKeys.Count > 0) // { // Debug.Log($"GetTransitionData removeKeys Count:{removeKeys.Count} IDs {string.Join(',', removeKeys)}"); // for (int i = 0; i < removeKeys.Count; i++) // { // Debug.Log($"GetTransitionData removeKeys :{removeKeys[i]} count : {allTokens.GetValueOrDefault(removeKeys[i], 0)}"); // } // TokenService.ClearTokens(removeKeys); // } // } } void SetTransitionData(int eventID, string eventName, int itemId, List EventEndSettlement) { TransitionData transitionData = new TransitionData(); // int sourceCount = TokenService.GetTokenCount(eventID); int sourceCount = 0; transitionData.eventID = eventID; transitionData.eventName = eventName; transitionData.sourceItemID = itemId; transitionData.sourceCount = sourceCount; transitionData.targetItemID = EventEndSettlement[0]; int targetCount = sourceCount * EventEndSettlement[1]; if (transitionData.targetItemID == 1002) { targetCount = GContext.container.Resolve().GetExtraCoinMag(targetCount); } if (targetCount < 0) { targetCount = int.MaxValue; Debug.LogError($"TransitionData targetCount overflow {eventID} {itemId} {transitionData.sourceCount} {EventEndSettlement[1]}"); } transitionData.targetCount = targetCount; curTransitionData[eventID] = transitionData; GContext.container.Resolve().AddFaceCustomUIData(UITypes.EventConvertedPopupPanel, true); } public void ClearTransitionData(TransitionData transitionData) { curTransitionData.Remove(transitionData.eventID); // if (TokenService.GetTokenCount(transitionData.eventID) > 0) // { #if AGG using (var e = GEvent.GameEvent("cycle_item_redemption")) { e.AddContent("event_id", transitionData.eventID) .AddContent("charge_count", GContext.container.Resolve().GetBuyPaymentAmount()) .AddContent("item_id", transitionData.sourceItemID) .AddContent("item_count", transitionData.sourceCount) .AddContent("change_item", transitionData.targetItemID) .AddContent("change_count", transitionData.targetCount); } #endif // TokenService.ClearToken(transitionData.eventID); // } } public int GetInitWelcomeGift(int eventID) { int welcomeGift = 0; if (eventID > 0) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(eventID); if (fe != null) { FishingEventCycleItem cycle = _tables.TbFishingEventCycleItem.GetOrDefault(fe.RedirectID); if (cycle != null) { welcomeGift = cycle.WelcomeGift; } } } return welcomeGift; } #endregion 代币转换 #region 事件礼包补单 public void OnBuyEventPack(int eventID) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(eventID); if (fe != null && fe.TimeDefinition is LimitedTime && (DateTime.Parse((fe.TimeDefinition as LimitedTime).EndTime) - ZZTimeHelper.UtcNow()).TotalSeconds > 1) { if (fe.Type == 3) { if (fe.SubType == 8 || fe.SubType == 11) { int packType = _tables.TbEventPackManager[fe.RedirectID].PackType; switch (packType) { case 1: GContext.container.Resolve().AddPurchaceCount(); break; case 2: break; case 3: GContext.container.Resolve().AddPurchase(); break; case 6: SetPack1A1Index(1); break; } } else if (fe.SubType == 10) { GContext.container.Resolve().AddOpenChainGifIndex(); } } else if (fe.Type == 4) { } else if (fe.Type == 6) { if (fe.SubType == 1) { SetPack1A2Index(); RedPointManager.Instance.SetRedPointState(HomeBtnOneTwoPack.redKey, false); } else if (fe.SubType == 2) { } } else if (fe.Type == 7) { // switch (fe.SubType) // { // case 1: // if (!shootingPackData.IsChainPackDepleted) // shootingPackData.OnBuySuccess(); // break; // case 2: // if (!breakPackData.IsChainPackDepleted) // breakPackData.OnBuySuccess(); // break; // case 3: // if (ScratchTicketData != null && !ScratchTicketData.IsChainPackDepleted) // ScratchTicketData.OnBuySuccess(); // break; // case 4: // if (chainPackData != null && !chainPackData.IsChainPackDepleted) // chainPackData.OnBuySuccess(); // break; // case 5: // if (gatherCoreData != null) // { // var gatherCoreChainData = gatherCoreData.ToChainPackData(); // if (gatherCoreChainData?.IsChainPackDepleted == false) // gatherCoreChainData.OnBuySuccess(); // } // break; // case 6: // break; // } } else if (fe.Type == 8) { // switch (fe.SubType) // { // case 3: // if (luckMagicChainPackData != null && !luckMagicChainPackData.IsChainPackDepleted) // luckMagicChainPackData.OnBuySuccess(); // break; // } } else if (fe.Type == 9) { switch (fe.SubType) { // case 4: // actManager?.OnBuySuccess(); // break; // case 5: // break; // case 7: // break; // case 9: // break; // case 11: // break; } } GContext.Publish(new TargetEvent(fe.ID, fe.Type, fe.SubType)); } } #endregion 事件礼包补单 void SetEvent15(FishingEvent t) { // if (t.Type != 15) // return; // switch (t.SubType) { // case 1: // InitPartnerGatherData(t); // break; // case 2: // // EventPartnerStatueTokenExchangeData.Load(t); // break; } } int RedirectType(int type, int subType) { return type * 1000 + subType; } } } public struct TransitionData { public int eventID; public string eventName; public int sourceItemID; public int sourceCount; public int targetItemID; public int targetCount; }