using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using asap.core; using cfg; using DataCenter; using game; using LitJson; using Script.RuntimeScript; 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 FishingEvent collectingTargetEvent = null; public CollectingTargetInit collectingTargetInit = null; public int collectingTargetInitTokenID; public int collectingTargetInitTaskID; public bool IsJoinUsPanelOpen = false; public bool collectingTargetResoure = true; public bool IsAquariumOpen = false; public int OpenAquariumID; public List> VIPPackList { get { int TriggerPackID = collectingTargetInit.TriggerPackID; if (GContext.container.Resolve().mmc) { MMTRodPack mmt = _tables.TbMMTRodPack.GetOrDefault(TriggerPackID); if (mmt != null) { TriggerPackID = mmt.NewPackID; } } var PackManager = _tables.TbEventPackManager.GetOrDefault(TriggerPackID); if (PackManager != null) { return PackManager.VIPPackList; } else { return null; } } } 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 /// public Dictionary RankTargetCount = new Dictionary(); private FishingEvent rankEvent = null; public RankInit rankInit = null; public RankTargets rankTarget = null; /// /// -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); } if (userDatas.TryGetValue(TransitionDataKey, out data_value)) { transitionDataDic = Newtonsoft.Json.JsonConvert.DeserializeObject>(data_value); } 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: GContext.container.Resolve().socialTipforUnlocked = t.ID; break; case 6: GContext.container.Resolve().MapTipforUnlocked = t.ID; break; case 11: GContext.container.Resolve().EventTipID = 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 = t.Type * 100 + t.SubType; if (t.Type > 1 && !systemOpen.Contains(open)) { if (SetEvent(t)) { systemOpen.Add(open); } } } } /// /// 检查某一类型活动是否开启,并初始化,用于活动到期检查刷新 /// /// /// public int GetEventAndInit(int type, int subType) { List _dataList = _tables.TbFishingEvent.DataList; foreach (var t in _dataList) { if (t.Type == type && t.SubType == subType) { if (SetEvent(t)) { return t.ID; } } } return -1; } /// /// 检查某一类型活动是否开启,不初始化 /// /// /// /// public int GetEvent(int type, int subType) { List _dataList = _tables.TbFishingEvent.DataList; foreach (var t in _dataList) { if (t.Type == type && t.SubType == subType) { if (Condition(t)) { return t.ID; } } } return -1; } /// /// 检查某一类型活动是否开启,不初始化 /// /// /// /// /// public int GetEventRedirectID(int type, int subType, bool isCheckCondition = true) { List _dataList = _tables.TbFishingEvent.DataList; foreach (var t in _dataList) { if (t.Type == type && t.SubType == subType) { if (Condition(t) || !isCheckCondition) { return t.RedirectID; } } } return -1; } /// /// 检查某一类型活动是否开启,不初始化 /// /// /// /// /// public FishingEvent GetEventByTypeAndSubType(int type, int subType, bool isCheckCondition = true) { List _dataList = _tables.TbFishingEvent.DataList; foreach (var t in _dataList) { if (t.Type == type && t.SubType == subType) { if (Condition(t) || !isCheckCondition) { return t; } } } return null; } /// /// 获取type开启活动数据,并确保活动初始化,用于活动代币转换 /// /// /// public FishingEvent GetEventTable(int type) { List _dataList = _tables.TbFishingEvent.DataList; foreach (var t in _dataList) { if (t.Type == type) { 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) //沙滩寻宝 { GContext.container.Resolve().DataModel.ActivityOpen(t); } else if (t.SubType == 3) //鱼缸建造 { var data = GContext.container.Resolve(); Debug.Log($"[EventPartner]Event On, Try load data"); data.LoadData(t); } else if (t.SubType == 4) // 洗游艇 { GContext.container.Resolve().ActivateEvent(t); } else if (t.SubType == 5) // 魔药 { GContext.container.Resolve().ActivateEvent(t); } else if (t.SubType == 6) // 弹珠 { GContext.container.Resolve().ActivateEvent(t); } else if (t.SubType == 7) { var bingoModel = GContext.container.Resolve(); var pfData = EventBingoPlayfabData.Load(); var ppData = EventBingoPlayerPreferenceData.Load(); var chainPackData = GContext.container.Resolve().ChainPackWithProgressMigrationData; if (bingoModel == null) { GContext.container.Register().AsSingleton(); bingoModel = GContext.container.Resolve(); 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}"); } if (chainPackData == null || chainPackData.EventId != t.ID) { var packId = GContext.container.Resolve().TbEventBingoInit.GetOrDefault(t.RedirectID).PackId; chainPackData.UpdateData(t.ID, packId); } } 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; } SystemOpen[t.Type * 100 + t.SubType] = true; if (t.FaceID > 0) { GContext.container.Resolve().AddFaceUIData(t.FaceID, t.RedirectID, 1); } 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; } 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; default: Debug.LogWarning($"Event {eventCondition.Condition} not registered."); break; } return isOpen; } 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: GContext.container.Resolve().IsOpenClubJoined = true; 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; } } public bool GetSystemOpen(int id) { FishingEvent fishingEvent = _tables.TbFishingEvent.GetOrDefault(id); if (fishingEvent == null) { return false; } id = fishingEvent.Type * 100 + 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); // GContext.container.Resolve().IsOpen = true; 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 5: //GContext.container.Resolve().SetSmallGame(t); break; case 6: GContext.container.Resolve().SetNewSignEvent(t); break; case 7: GContext.container.Resolve().RefreshBattlePassRecord(t); GContext.container.Resolve().AlbumEventID = t.ID; break; case 8: 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() .AddGiftFaceUI(t.ID, UITypes.BlackFridayPopupPanel, 0, true); 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!"); var data = GContext.container.Resolve().ThanksGivingPackData; if (t.ID != data.EventId) data.UpdateData(t); break; } } private void SetEvent7(FishingEvent e) { switch (e.SubType) { case 1: var data = GContext.container.Resolve(); if (data == null) { GContext.container.Register().AsSingleton(); data = GContext.container.Resolve(); } 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()); var playfabData = EventBreakPfData.Deserialize(PlayFabMgr.Instance.GetLocalData(EventBreakPfData.PfKey)); var eventBreakModel = GContext.container.Resolve(); if (eventBreakModel == null) { GContext.container.Register().AsSingleton(); eventBreakModel = GContext.container.Resolve(); } 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: // 刮刮乐 GContext.container.Resolve().ActivateEvent(e); break; case 4: var canModel = GContext.container.Resolve(); var ecPlayfabString = PlayFabMgr.Instance.GetLocalData(EventCanPlayfabData.PlayFabKey); var ecPpString = PlayerPrefs.GetString(EventCanPlayerPreferenceData.PlayerPrefsKey); var ecPlayfabData = EventCanPlayfabData.Deserialize(ecPlayfabString); var ecPlayerPrefsData = EventCanPlayerPreferenceData.Deserialize(ecPpString); if (canModel == null || canModel.EventId != e.ID) { if (canModel == null) { GContext.container.Register().AsSingleton(); var tableContext = GContext.container.Resolve(); tableContext.ReadTables(e.ID); GContext.container.Register().AsSingleton(); canModel = GContext.container.Resolve(); } canModel.InitializeModel(e.ID, ecPlayfabData, ecPlayerPrefsData); } var chainPackData = GContext.container.Resolve(); if (chainPackData == null) { GContext.container.Register().AsSingleton(); chainPackData = GContext.container.Resolve(); } chainPackData.Init( GContext.container.Resolve().GetPackData(), e.ID, ref canModel.ChainPackProgress); break; case 5: EventGatherCoreAct.Ctx = EventGatherCoreTableContext.ReadTables(e.ID); var gatherCoreData = GContext.container.Resolve(); var egcPfData = EventGatherCorePlayfabData.Load(); if (gatherCoreData == null) { GContext.container.Register().AsSingleton(); gatherCoreData = GContext.container.Resolve(); } 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; } } 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); var eventLuckMagicModel = GContext.container.Resolve(); if (eventLuckMagicModel == null) { GContext.container.Register().AsSingleton(); eventLuckMagicModel = GContext.container.Resolve(); 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; default: EventLuckyGameModel.Get().OnEvent(t); break; } } /// /// 9-1 小战令 /// /// void SetEvent9(FishingEvent t) { if (t.SubType == 4) { GContext.container.Resolve().UpdateEventData(t); } else if (t.SubType < 4) { GContext.container.Resolve().Refresh(t); } } void SetEvent10(FishingEvent t) { // GContext.container.Resolve().IsOpen = true; GContext.container.Resolve().SetupEventData(t); } 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: false)) { 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); if (fishingEvent.FaceID > 0) { GContext.container.Resolve().AddFaceUIData(fishingEvent.FaceID, fishingEvent.RedirectID, 1); } SystemOpen[fishingEvent.Type * 100 + 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 == 4) { GContext.container.Resolve().ActivateEvent(fishingEvent); } else if (fishingEvent.SubType == 5) { GContext.container.Resolve().ActivateEvent(fishingEvent); } else if (fishingEvent.SubType == 6) { GContext.container.Resolve().ActivateEvent(fishingEvent); } } else if (fishingEvent.Type == 6) { SetEvent6(fishingEvent); } if (fishingEvent.FaceID > 0) { GContext.container.Resolve().AddFaceUIData(fishingEvent.FaceID, fishingEvent.RedirectID, 1); } SystemOpen[fishingEvent.Type * 100 + fishingEvent.SubType] = true; break; case 7: if (fishingEvent.SubType == 3) { GContext.container.Resolve().ActivateEvent(fishingEvent); } 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); } PlayFabMgr.Instance.UpdateUserDataValue("ETDropAfterDropDic", JsonMapper.ToJson(ETDropAfterDropDic)); extraPoint += GContext.container.Resolve().GetCollectionTargetExtraPointBuffValue(mapId); } } return extraPoint; } #endregion void SetCollectingTargetEvent(FishingEvent t) { collectingTargetEvent = t; if (!ETDropAfterDropDic.ContainsKey(0)) { ETDropAfterDropDic[0] = 0; } if (collectingTargetInit == null || ETDropAfterDropDic[0] != collectingTargetEvent.ID) { //new target event collectingTargetInit = _tables.TbCollectingTargetInit.GetOrDefault(t.RedirectID); if (collectingTargetInit == null || collectingTargetInit.TargetList.Count == 0) { Debug.LogError($"CollectingTargetInit Error Id == {t.RedirectID} EventId == {t.ID}"); GContext.container.Resolve().ClearTargetBuff(); collectingTarget = null; collectingTargetResoure = true; } else { collectingTargetResoure = false; collectingTargetInitTokenID = collectingTargetInit.TokenID; collectingTargetInitTaskID = collectingTargetInit.TaskID; TargetList = collectingTargetInit.TargetList; InitCollectingTarget(); UITypes.FishingTargetPopupPanel.SetType(collectingTargetInit.BgDescPrefab); UITypes.GiftPopupPanel_7.SetType(collectingTargetInit.GiftPrefab); //GContext.Publish(new TargetEvent(collectingTargetInit.TaskID, 3, 2)); DownloadPkg(); } } } async void DownloadPkg() { var loadResourceService = GContext.container.Resolve(); var resourceName = new List() { collectingTargetInit.GiftPrefab, collectingTargetInit.GiftIcon }; if (await loadResourceService.CheckResourceLoadQueue(resourceName)) { ShowCTGift(); } } public async Task IsDownLoadPkg() { if (!collectingTargetResoure) { ILoadResourceService loadResourceService = GContext.container.Resolve(); collectingTargetResoure = await loadResourceService.Load(collectingTargetInit.DownloadPkg); } return collectingTargetResoure; } int requiredCount = 0; void InitCollectingTarget() { if (!ETDropAfterDropDic.ContainsKey(0)) { ETDropAfterDropDic[0] = 0; } collectingTarget = _tables.TbCollectingTargetReward.GetOrDefault(TargetList[0]); requiredCount = collectingTarget.TokenRequired; //Event Still Launch if (collectingTarget != null && collectingTargetEvent.ID == ETDropAfterDropDic[0]) { ETDropAfterDropDic.TryGetValue(collectingTargetInitTokenID, out var progress); while (collectingTarget != null && collectingTarget.NextTarget > 0 && requiredCount <= progress) { collectingTarget = _tables.TbCollectingTargetReward.GetOrDefault(collectingTarget.NextTarget); requiredCount += collectingTarget.TokenRequired; ETDropAfterDropDic.TryGetValue(collectingTargetInitTokenID, out progress); } } //Event Still Launch else { RefreshTargetGuidance(); ETDropAfterDropDic.Clear(); ETDropAfterDropDic[0] = collectingTargetEvent.ID; GContext.container.Resolve().ClearTargetBuff(); PlayFabMgr.Instance.UpdateUserDataValue("ETDropAfterDropDic", JsonMapper.ToJson(ETDropAfterDropDic)); } } public void ShowCTGift() { var pack = IsShowCTGift(); if (pack != null) { string userID = GContext.container.Resolve().UserId; PlayerPrefs.DeleteKey($"{collectingTargetInitTaskID}_{userID}"); GContext.container.Resolve().AddGiftFaceUI(collectingTargetInitTaskID, UITypes.GiftPopupPanel_7, collectingTargetInitTaskID); } } public void AddCollectingTargetCount() { if (!ETDropAfterDropDic.ContainsKey(-1)) { ETDropAfterDropDic[-1] = 1; } else { ETDropAfterDropDic[-1]++; } //特殊处理 更新礼包显示 GContext.Publish(new TargetEvent(collectingTargetInitTaskID, 3, 2)); PlayFabMgr.Instance.UpdateUserDataValue("ETDropAfterDropDic", JsonMapper.ToJson(ETDropAfterDropDic)); } /// /// 特殊鱼,技能新手引导数量 /// 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]++; } PlayFabMgr.Instance.UpdateUserDataValue("ETDropAfterDropDic", JsonMapper.ToJson(ETDropAfterDropDic)); } return isGuide; } } return false; } public void RefreshTargetGuidance() { _isTargetGuidance = true; } public Pack IsShowCTGift() { int vipLevel = GContext.container.Resolve().GetVIPLevel("CollectingTarget"); int buyCount = GetCollectingTargetCount(); var vipPackList = VIPPackList; if (vipPackList != null && vipPackList.Count > vipLevel) { var packList = vipPackList[vipLevel]; if (packList.Count > buyCount) { Pack pack = _tables.TbPack.GetOrDefault(vipPackList[vipLevel][buyCount]); return pack; } } return null; } 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; } targetItemDatas = GContext.container.Resolve().AddItemByDropList(dropIDs); 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("range_no", collectingTarget.TaskID); if (targetItemDatas != null) { for (int i = 0; i < targetItemDatas.Count; i++) { if (targetItemDatas[i].id == 1001) { e.AddContent("reward_hook", targetItemDatas[i].count); } else if (targetItemDatas[i].id == 1002) { e.AddContent("reward_cash", targetItemDatas[i].count); } } } } #endif PlayFabMgr.Instance.UpdateUserDataValue("ETDropAfterDropDic", JsonMapper.ToJson(ETDropAfterDropDic)); } } 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.TokenRequired; 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.TokenRequired; 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.TokenRequired; if (startNum > progress) { startNum -= localcollectingTarget.TokenRequired; break; } } } return GetAllCollectingTarget() - startNum; } return 0; } public void AddCollectingTarget(int id, int progress) { if (collectingTarget == null || id != 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 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]); } PlayFabMgr.Instance.UpdateUserDataValue("RankTargetCount", JsonMapper.ToJson(RankTargetCount)); rankItemDatas = null; if (!isMax && requiredRankCount <= RankTargetCount[rankInit.TokenID]) { List dropIDs = new List(); preRankTarget = new List(); //掉落奖励 SetNextRankTarget(dropIDs); //GameEventMgr.Instance.Raise(GameEvents.FishingEvent, 3, 3); //GContext.Publish(new TargetEvent(lastEventRank.ID, 3, 3)); rankItemDatas = GContext.container.Resolve().AddItemByDropList(dropIDs); } #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) { for (int i = 0; i < rankItemDatas.Count; i++) { if (rankItemDatas[i].id == 1001) { e.AddContent("reward_hook", rankItemDatas[i].count); } else if (rankItemDatas[i].id == 1002) { e.AddContent("reward_cash", rankItemDatas[i].count); } } } } #endif } } void SetNextRankTarget(List dropIDs) { preRankTarget.Add(rankTarget); //掉落奖励 dropIDs.Add(rankTarget.DropID);// GContext.container.Resolve().AddItemByDrop(rankTarget.DropID); if (rankTarget.NextTarget <= 0) { return; } rankTarget = _tables.TbRankTargets.GetOrDefault(rankTarget.NextTarget); requiredRankCount += rankTarget.TokenRequired; 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.TokenRequired; 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.TokenRequired; if (startNum > progress) { startNum -= localRankTarget.TokenRequired; 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 int GetWheelLevelCount(int id) { return WheelLevelCount.TryGetValue(id, out int progress) ? progress : 0; } public DateTime GetCollectingTargetEndTime() { return GetEventEndTime(collectingTargetEvent.ID); } /// /// 统一计算 固定时间段时间计算 真实时间和配置时间全加偏移(其他配置是偏移后的时间) /// 计算的时候要使用 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.TokenRequired; 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.TokenRequired; RankTargetCount.TryGetValue(rankInit.TokenID, out progress); } } else { RankTargetCount.Clear(); RankTargetCount[0] = rankEvent.ID; } if (!RankTargetCount.ContainsKey(rankInit.TokenID)) { RankTargetCount[rankInit.TokenID] = 0; } if (IsOpenRank()) { GContext.container.Resolve().UpdateScore(RankTargetCount[rankInit.TokenID]); } } else rankTarget = null; } 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 = GetInitWelcomeGift3(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); 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: false)) { 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 4: ActivateRodSelectionPack(t); break; case 5: ActivateSelectionPack(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, true); } private void ActivatePiggyBankPack(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 } 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 } private void ActivateRodSelectionPack(FishingEvent t) { var eventPackDataSaved = GContext.container.Resolve();//pack data to be saved to remote server bool eventUpdated = eventPackDataSaved.UpdateData(t);//event is updated only when event changed or user login if (eventPackDataSaved.IsPackActivated && eventUpdated) GContext.container.Resolve(). AddGiftFaceUI(t.ID, UITypes.GiftRodSelectionPopupPanel, _tables.TbEventPackManager[eventPackDataSaved.RedirectID].PackType, true); } private void ActivateSelectionPack(FishingEvent t) { var eventPackDataSaved = GContext.container.Resolve();//pack data to be saved to remote server bool eventUpdated = eventPackDataSaved.UpdateData(t);//event is updated only when event changed or user login if (eventPackDataSaved.IsPackActivated && eventUpdated) GContext.container.Resolve(). AddGiftFaceUI(t.ID, UITypes.GiftSelectionPanel, _tables.TbEventPackManager[eventPackDataSaved.RedirectID].PackType, true); } #endregion #region 获取事件礼包关于钓鱼的数据 public int curActivateItemId { get; set; } public int GetActivateItemId() { float BasicProb = UnityEngine.Random.Range(0, 1f); if (BasicProb <= _tables.TbGlobalConfig.CommercialFishParam) { try { PiggyBankPackData piggyBankPackData = GContext.container.Resolve(); if (piggyBankPackData.DoNeedUpdate && piggyBankPackData.IsWithinEventTime) { return piggyBankPackData.ActivateItemId; } 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) { PiggyBankPackData piggyBankPackData = GContext.container.Resolve(); if (piggyBankPackData != null) { piggyBankPackData.AddProgress(fishTier, magnification); } BargainPackData barginPackData = GContext.container.Resolve(); if (barginPackData != null) { barginPackData.AddProgress(fishTier, magnification); } } #endregion public void Dispose() { disposable?.Dispose(); disposable = null; } #region 活动代币转换 const string TransitionDataKey = "TransitionData"; Dictionary transitionDataDic = new Dictionary(); public Dictionary curTransitionData { get; private set; } = new Dictionary(); public void SaveTransitionData(int eventId, int count) { if (eventId > 0) { transitionDataDic[eventId] = count; SaveTransitionData(); } } public int GetTransitionDataCount(int eventId) { if (transitionDataDic.TryGetValue(eventId, out int count)) { return count; } return 0; } void SaveTransitionData() { string json = Newtonsoft.Json.JsonConvert.SerializeObject(transitionDataDic); PlayFabMgr.Instance.UpdateUserDataValue(TransitionDataKey, json); } void InitTransitionDataDic() { //测试数据 //#if UNITY_EDITOR //SaveTransitionData(40000001, 3); //SaveTransitionData(70100002, 3); //#endif //测试数据 GetTransition4Data(); GetTransition7Data(); GetTransition8Data(); //GetTransitionDataPVP(); } void GetTransition4Data() { if (transitionDataDic != null) { foreach (var item in transitionDataDic) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(item.Key); if (fe != null && fe.Type == 4 && !Condition(fe)) { int count = transitionDataDic[fe.ID]; if (count > 0) { FishingEventCycleItem cycle = _tables.TbFishingEventCycleItem.DataList .Find(x => x.Type == fe.Type && x.SubType == fe.SubType && x.RedirectID == fe.RedirectID); if (cycle != null) { SetTransitionData(fe.ID, cycle.EventName_l10n_key, cycle.ItemId, cycle.EventEndSettlement); } } else { transitionDataDic.Remove(fe.ID); SaveTransitionData(); } break; } } } } void GetTransition7Data() { if (transitionDataDic != null) { foreach (var item in transitionDataDic) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(item.Key); if (fe != null && fe.Type == 7 && !Condition(fe)) { int count = transitionDataDic[fe.ID]; if (count > 0) { FishingEventCycleItem2 cycle = _tables.TbFishingEventCycleItem2.GetOrDefault(fe.RedirectID); if (cycle != null) { SetTransitionData(fe.ID, cycle.EventName_l10n_key, cycle.ItemId, cycle.EventEndSettlement); } } else { transitionDataDic.Remove(fe.ID); SaveTransitionData(); } break; } } } } void GetTransition8Data() { if (transitionDataDic != null) { foreach (var item in transitionDataDic) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(item.Key); if (fe != null && fe.Type == 8 && !Condition(fe)) { int count = transitionDataDic[fe.ID]; if (count > 0) { FishingEventCycleItem3 cycle = _tables.TbFishingEventCycleItem3.GetOrDefault(fe.RedirectID); if (cycle != null) { SetTransitionData(fe.ID, cycle.EventName_l10n_key, cycle.ItemId, cycle.EventEndSettlement); } } else { transitionDataDic.Remove(fe.ID); SaveTransitionData(); } break; } } } } void SetTransitionData(int eventID, string eventName, int itemId, List EventEndSettlement) { TransitionData transitionData = new TransitionData(); transitionData.eventID = eventID; transitionData.eventName = eventName; transitionData.sourceItemID = itemId; transitionData.sourceCount = transitionDataDic[eventID]; transitionData.targetItemID = EventEndSettlement[0]; int targetCount = transitionDataDic[eventID] * 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().AddGiftFaceUI(eventID, UITypes.EventConvertedPopupPanel, 0, true); } public void ClearTransitionData(TransitionData transitionData) { curTransitionData.Remove(transitionData.eventID); if (transitionDataDic != null && transitionDataDic.ContainsKey(transitionData.eventID)) { #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 //EventConvertedPopupPanel奖励弹窗 transitionDataDic.Remove(transitionData.eventID); SaveTransitionData(); } } public int GetInitWelcomeGift(int eventID) { int welcomeGift = 0; if (eventID > 0) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(eventID); if (fe != null) { FishingEventCycleItem cycle = _tables.TbFishingEventCycleItem.DataList. Find(x => x.Type == fe.Type && x.SubType == fe.SubType && x.RedirectID == fe.RedirectID); if (cycle != null) { welcomeGift = cycle.WelcomeGift; } } } return welcomeGift; } public int GetInitWelcomeGift2(int eventID) { int welcomeGift = 0; if (eventID > 0) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(eventID); if (fe != null) { FishingEventCycleItem2 cycle = _tables.TbFishingEventCycleItem2.GetOrDefault(fe.RedirectID); if (cycle != null) { welcomeGift = cycle.WelcomeGift; } } } return welcomeGift; } public int GetInitWelcomeGift3(int eventID) { int welcomeGift = 0; if (eventID > 0) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(eventID); if (fe != null) { FishingEventCycleItem3 cycle = _tables.TbFishingEventCycleItem3.GetOrDefault(fe.RedirectID); if (cycle != null) { welcomeGift = cycle.WelcomeGift; } } } return welcomeGift; } public int GetRedDot(int eventID) { int redDot = 10; if (eventID > 0) { FishingEvent fe = _tables.TbFishingEvent.GetOrDefault(eventID); if (fe != null) { FishingEventCycleItem cycle = _tables.TbFishingEventCycleItem.DataList. Find(x => x.Type == fe.Type && x.SubType == fe.SubType && x.RedirectID == fe.RedirectID); if (cycle != null) { redDot = cycle.RedDot; } } } return redDot; } #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 == 2) { AddCollectingTargetCount(); } else if (fe.SubType == 8) { int packType = _tables.TbEventPackManager[fe.RedirectID].PackType; switch (packType) { case 1: GContext.container.Resolve().AddPurchaceCount(); break; case 2: GContext.container.Resolve().AddPurchase(); break; case 3: GContext.container.Resolve().AddPurchase(); break; case 4: GContext.container.Resolve().AddPurchase(); break; case 5: GContext.container.Resolve().AddPurchase(); break; case 6: SetPack1A1Index(1); break; } } else if (fe.SubType == 10) { GContext.container.Resolve().AddOpenChainGifIndex(); } } else if (fe.Type == 4) { ChainPackWithProgressMigrationData.OnBuySuccess(); } else if (fe.Type == 6) { if (fe.SubType == 1) { SetPack1A2Index(); } else if (fe.SubType == 2) { ThanksGivingPackData.OnBuySuccess(); } } else if (fe.Type == 7) { switch (fe.SubType) { case 1: var shootingPackData = GContext.container.Resolve(); if (!shootingPackData.IsChainPackDepleted) shootingPackData.OnBuySuccess(); break; case 2: var breakPackData = GContext.container.Resolve().ToChainPackData(); if (!breakPackData.IsChainPackDepleted) breakPackData.OnBuySuccess(); break; case 3: var ScratchTicketData = GContext.container.Resolve().GetChainPackData(); if (ScratchTicketData != null && !ScratchTicketData.IsChainPackDepleted) ScratchTicketData.OnBuySuccess(); break; case 4: var chainPackData = GContext.container.Resolve(); if (chainPackData != null && !chainPackData.IsChainPackDepleted) chainPackData.OnBuySuccess(); break; case 5: var gatherCoreData = GContext.container.Resolve(); if (gatherCoreData != null) { var gatherCoreChainData = gatherCoreData.ToChainPackData(); if (gatherCoreChainData?.IsChainPackDepleted == false) gatherCoreChainData.OnBuySuccess(); } break; } } else if (fe.Type == 8) { switch (fe.SubType) { case 3: var luckMagicChainPackData = GContext.container.Resolve().ToChainPackData(); if (luckMagicChainPackData != null && !luckMagicChainPackData.IsChainPackDepleted) luckMagicChainPackData.OnBuySuccess(); break; } } else if (fe.Type == 9) { switch (fe.SubType) { case 4: var actManager = GContext.container.Resolve(); actManager?.OnBuySuccess(); break; } } GContext.Publish(new TargetEvent(fe.ID, fe.Type, fe.SubType)); } } #endregion 事件礼包补单 } } public struct TransitionData { public int eventID; public string eventName; public int sourceItemID; public int sourceCount; public int targetItemID; public int targetCount; }