using System; using System.Collections.Generic; public class AdsManager : GameSystemManager { //<广告ID,今日已领取广告奖励次数> private Dictionary adsInfoDict = new Dictionary(); public event Action OnAdsInfoListUpdateEvent;//ADID type value public override void Init() { DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent; } public override void Release() { DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent; } public void OnBeforePlayerDataInitializeEvent() { adsInfoDict.Clear(); } void SendGetReward(int ADID) { var pack = new CA504_tagCMPlayerGetReward(); pack.RewardType = 81; // 广告奖励 81 pack.DataEx = (uint)ADID; // 广告奖励ID GameNetSystem.Instance.SendInfo(pack); } //如果有广告SDK接入,该函数改成回调触发 public void PlayAds(int ADID) { switch (ADID) { case 1: if (!DungeonManager.Instance.TryGetFBInfoByMapID(BoneFieldManager.Instance.DataMapID, out var fbInfo1)) return; SendGetReward(ADID); BoneFieldManager.Instance.SendBBeginFBWipeOut(BoneFieldManager.Instance.DataMapID, (int)fbInfo1.PassLineID); break; case 2: if (!DungeonManager.Instance.TryGetFBInfoByMapID(TianziBillboradManager.Instance.DataMapID, out var fbInfo2)) return; SendGetReward(ADID); break; case 3: HeroUIManager.Instance.selectCallIndex = 0; SendGetReward(ADID); break; case 4: SendGetReward(ADID); break; } } //已获取广告奖励次数 public int GetADCntByADID(int ADID) { if (adsInfoDict.IsNullOrEmpty() || !adsInfoDict.ContainsKey(ADID)) return 0; return adsInfoDict[ADID]; } public void UpdateAdsInfoList(HA722_tagSCADInfoList vNetData) { if (vNetData == null || vNetData.ADInfoList.IsNullOrEmpty()) return; foreach (var item in vNetData.ADInfoList) { adsInfoDict[item.ADID] = item.ADCnt; if (!ADAwardConfig.HasKey(item.ADID)) { continue; } ADAwardConfig aDAwardConfig = ADAwardConfig.Get(item.ADID); var value = aDAwardConfig.ADAwardValue; var type = aDAwardConfig.ADAwardType; OnAdsInfoListUpdateEvent?.Invoke(item.ADID, type, value); } } }