using vnxbqy.UI; using System.Collections.Generic; using System.Linq; using System; public class MountedPetZhanLingModel : Model, IBeforePlayerDataInitialize { public readonly int ZhanLingHType = 7; // 高级战令类型对应的充值ID列表 public Dictionary> ctgIdDictH = new Dictionary>(); public Dictionary> ctgIdDict = new Dictionary>(); //收到的所有服务器战令包字典 public Dictionary zhanLingInfoDict = new Dictionary(); public Action UpdateGiftStateEvent; public Redpoint redpoint = new Redpoint(MainRedDot.QCTrainActRedpoint, MainRedDot.QCTrainActRedpoint * 10); List allGiftItemList = new List(); //同步播放摆动动画 public Action PlayAnimationSync; private bool isPlayAnimation = false; public bool IsPlayAnimation { get { return isPlayAnimation; } set { isPlayAnimation = value; if (isPlayAnimation) { PlayAnimationSync?.Invoke(); } isPlayAnimation = false; } } GatheringSoulModel model { get { return ModelCenter.Instance.GetModel(); } } PetHorseActModel petHorseActModel { get { return ModelCenter.Instance.GetModel(); } } public override void Init() { petHorseActModel.OnPlayerInfo += OnPlayerInfoEvent; ctgIdDict = GeneralDefine.ZhanLingCtgIdDict; ctgIdDictH = GeneralDefine.ZhanLingCtgIdHDict; } public void OnBeforePlayerDataInitialize() { zhanLingInfoDict.Clear(); } public override void UnInit() { petHorseActModel.OnPlayerInfo -= OnPlayerInfoEvent; } private void OnPlayerInfoEvent() { UpdateRedpoint(ZhanLingHType); UpdateGiftStateEvent?.Invoke(); } public void UpdateGiftState(HB120_tagMCZhanlingInfo vNetData) { if (zhanLingInfoDict.ContainsKey(vNetData.ZhanlingType)) { zhanLingInfoDict[vNetData.ZhanlingType].isActivite = vNetData.IsActivite; zhanLingInfoDict[vNetData.ZhanlingType].isActiviteH = vNetData.IsActiviteH; if (vNetData.RewardCount != 0) { for (int i = 0; i < vNetData.RewardCount; i++) { zhanLingInfoDict[vNetData.ZhanlingType].freeZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = (int)vNetData.RewardList[i].FreeRewardState; zhanLingInfoDict[vNetData.ZhanlingType].paidZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = (int)vNetData.RewardList[i].ZLRewardState; zhanLingInfoDict[vNetData.ZhanlingType].paidZhanHaveHDict[(int)vNetData.RewardList[i].NeedValue] = (int)vNetData.RewardList[i].ZLRewardStateH; } } } else { ZhanlingInfo zhanlingInfo = new ZhanlingInfo(); zhanlingInfo.zhanLingType = vNetData.ZhanlingType; zhanlingInfo.isActivite = vNetData.IsActivite; zhanlingInfo.isActiviteH = vNetData.IsActiviteH; zhanlingInfo.rewardCount = vNetData.RewardCount; zhanlingInfo.value1 = (int)vNetData.Value1; zhanlingInfo.freeZhanHaveDict = new Dictionary(); zhanlingInfo.paidZhanHaveDict = new Dictionary(); zhanlingInfo.paidZhanHaveHDict = new Dictionary(); for (int i = 0; i < zhanlingInfo.rewardCount; i++) { zhanlingInfo.freeZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = vNetData.RewardList[i].FreeRewardState; zhanlingInfo.paidZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = vNetData.RewardList[i].ZLRewardState; zhanlingInfo.paidZhanHaveHDict[(int)vNetData.RewardList[i].NeedValue] = vNetData.RewardList[i].ZLRewardStateH; } zhanLingInfoDict[zhanlingInfo.zhanLingType] = zhanlingInfo; } if (vNetData.ZhanlingType == ZhanLingHType) { UpdateRedpoint(ZhanLingHType); UpdateGiftStateEvent?.Invoke(); } } public bool IsNeedValueOk(int needValue) { int nowNeedValue = petHorseActModel.actScore; return nowNeedValue >= needValue; } //0 没购买进阶和玄级 1 购买了进阶没买玄级 2 购买了玄级没买进阶 3 购买了进阶和玄级 public int GetBuyState(int zhanLingType) { bool isBuyPaid = zhanLingInfoDict[zhanLingType].isActivite > 0; bool isBuyPaidH = zhanLingInfoDict[zhanLingType].isActiviteH > 0; if (isBuyPaid && isBuyPaidH) { return 3; } else if (isBuyPaid && !isBuyPaidH) { return 1; } else if (!isBuyPaid && isBuyPaidH) { return 2; } else { return 0; } } // 0 不能领 1 未领取 2 已领取 public int GetFreeGiftState(int zhanLingType, int needValue) { if (IsNeedValueOk(needValue)) { return zhanLingInfoDict[zhanLingType].freeZhanHaveDict[needValue] > 0 ? 2 : 1; } else { return 0; } } // 0 不能领 1 未领取 2 已领取 public int GetPaidGiftState(int zhanLingType, int needValue) { if (IsNeedValueOk(needValue) && zhanLingInfoDict[zhanLingType].isActivite > 0) { return zhanLingInfoDict[zhanLingType].paidZhanHaveDict[needValue] > 0 ? 2 : 1; } else { return 0; } } // 0 不能领 1 未领取 2 已领取 public int GetPaidGiftHState(int zhanLingType, int needValue) { if (IsNeedValueOk(needValue) && zhanLingInfoDict[zhanLingType].isActiviteH > 0) { return zhanLingInfoDict[zhanLingType].paidZhanHaveHDict[needValue] > 0 ? 2 : 1; } else { return 0; } } //发包 type 0-免费;1-普通战令;2-高级战令 public void HaveGift(int zhanLingType, int needValue, int type) { var pak = new IL_CA504_tagCMPlayerGetReward(); string dataExStr = (needValue * 10 + type).ToString(); pak.RewardType = (byte)65; pak.DataEx = (uint)zhanLingType; pak.DataExStrLen = (byte)dataExStr.Length; pak.DataExStr = dataExStr; GameNetSystem.Instance.SendInfo(pak); } //获取最小未领取的物品索引 public int GetJumpStartIndex(int zhanLingType) { var infoDict = ILZhanlingConfig.GetTypeToIDDict(zhanLingType); if (infoDict.IsNullOrEmpty()) return 0; List infoList = infoDict.Keys.ToList(); if (infoList.IsNullOrEmpty()) return 0; if (zhanLingInfoDict.IsNullOrEmpty() || !zhanLingInfoDict.ContainsKey(zhanLingType)) return 0; var zhanLingInfo = zhanLingInfoDict[zhanLingType]; int index = 0; bool allItemsClaimed = true; for (int i = 0; i < infoList.Count; i++) { int needValue = infoList[i]; bool isHaveFree = zhanLingInfo.freeZhanHaveDict.GetValueOrDefault(needValue, 0) > 0; bool isHavePaid = zhanLingInfo.paidZhanHaveDict.GetValueOrDefault(needValue, 0) > 0; bool isHavePaidH = zhanLingInfo.paidZhanHaveHDict.GetValueOrDefault(needValue, 0) > 0; if (!isHaveFree || !isHavePaid || !isHavePaidH) { allItemsClaimed = false; if (!isHaveFree) { index = i; break; } if (zhanLingInfo.isActivite > 0 && !isHavePaid) { index = i; break; } if (zhanLingInfo.isActiviteH > 0 && !isHavePaidH) { index = i; break; } } } if (allItemsClaimed && zhanLingInfo.isActivite > 0 && zhanLingInfo.isActiviteH > 0) { return infoList.Count - 1; } return Math.Max(0, index - 2); } //一键获取所有可领取的礼品,弹出展示窗口 public void HaveAllZhanLingGift(int zhanLingType) { //没有格子 if (ModelCenter.Instance.GetModelEx().GetEmptyGridCount(PackType.Item) < 1) { SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580"); return; } List haveFreeRewardItemList = new List(); //用户领到的免费物品的所需值列表 List havePaidRewardItemList = new List(); //用户领到的付费物品的所需值列表 List havePaidRewardItemHList = new List(); //用户领到的付费物品的所需值列表 var needValueList = ILZhanlingConfig.GetTypeToIDDict(zhanLingType).Keys.ToList(); for (int i = 0; i < needValueList.Count; i++) { int needValue = needValueList[i]; int freeState = GetFreeGiftState(zhanLingType, needValue); int paidState = GetPaidGiftState(zhanLingType, needValue); int paidHState = GetPaidGiftHState(zhanLingType, needValue); if (freeState == 1) { haveFreeRewardItemList.Add(needValue); } if (paidState == 1) { havePaidRewardItemList.Add(needValue); } if (paidHState == 1) { havePaidRewardItemHList.Add(needValue); } } MergeAllHaveZhanLingGift(zhanLingType, haveFreeRewardItemList, havePaidRewardItemList, havePaidRewardItemHList); DebugEx.Log($"背包空格 {ModelCenter.Instance.GetModelEx().GetEmptyGridCount(PackType.Item)} 需要格子 {allGiftItemList.Count}"); if (ModelCenter.Instance.GetModelEx().GetEmptyGridCount(PackType.Item) >= allGiftItemList.Count) { for (int i = 0; i < needValueList.Count; i++) { int needValue = needValueList[i]; int freeState = GetFreeGiftState(zhanLingType, needValue); int paidState = GetPaidGiftState(zhanLingType, needValue); int paidHState = GetPaidGiftHState(zhanLingType, needValue); if (freeState == 1) { HaveGift(zhanLingType, needValue, 0); } if (paidState == 1) { HaveGift(zhanLingType, needValue, 1); } if (paidHState == 1) { HaveGift(zhanLingType, needValue, 2); } } } else { SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580"); return; } } //type 0 免费物品 1 进阶令物品 2 玄阶进阶令物品 public void MergeAllHaveZhanLingGift(int zhanLingType, List haveFreeRewardItemList, List havePaidRewardItemList, List havePaidRewardItemHList) { for (int i = 0; i < haveFreeRewardItemList.Count; i++) { for (int j = 0; j < ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[haveFreeRewardItemList[i]]).FreeRewardItemList.Length; j++) { ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo(); tempAllGiftItems.id = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[haveFreeRewardItemList[i]]).FreeRewardItemList[j][0]; tempAllGiftItems.count = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[haveFreeRewardItemList[i]]).FreeRewardItemList[j][1]; tempAllGiftItems.name = ItemConfig.Get(tempAllGiftItems.id).ItemName; tempAllGiftItems.quality = ItemConfig.Get(tempAllGiftItems.id).ItemColor; if (allGiftItemList.Count == 0) { allGiftItemList.Add(tempAllGiftItems); } else { bool isExist = false; for (int k = 0; k < allGiftItemList.Count; k++) { if (allGiftItemList[k].id == tempAllGiftItems.id) { isExist = true; allGiftItemList[k].count += tempAllGiftItems.count; break; } } if (!isExist) { allGiftItemList.Add(tempAllGiftItems); } } } } for (int i = 0; i < havePaidRewardItemList.Count; i++) { for (int j = 0; j < ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemList[i]]).ZLRewardItemList.Length; j++) { ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo(); tempAllGiftItems.id = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemList[i]]).ZLRewardItemList[j][0]; tempAllGiftItems.count = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemList[i]]).ZLRewardItemList[j][1]; tempAllGiftItems.name = ItemConfig.Get(tempAllGiftItems.id).ItemName; tempAllGiftItems.quality = ItemConfig.Get(tempAllGiftItems.id).ItemColor; if (allGiftItemList.Count == 0) { allGiftItemList.Add(tempAllGiftItems); } else { bool isExist = false; for (int k = 0; k < allGiftItemList.Count; k++) { if (allGiftItemList[k].id == tempAllGiftItems.id) { isExist = true; allGiftItemList[k].count += tempAllGiftItems.count; break; } } if (!isExist) { allGiftItemList.Add(tempAllGiftItems); } } } } for (int i = 0; i < havePaidRewardItemHList.Count; i++) { for (int j = 0; j < ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemHList[i]]).ZLRewardItemListH.Length; j++) { ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo(); tempAllGiftItems.id = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemHList[i]]).ZLRewardItemListH[j][0]; tempAllGiftItems.count = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemHList[i]]).ZLRewardItemListH[j][1]; tempAllGiftItems.name = ItemConfig.Get(tempAllGiftItems.id).ItemName; tempAllGiftItems.quality = ItemConfig.Get(tempAllGiftItems.id).ItemColor; if (allGiftItemList.Count == 0) { allGiftItemList.Add(tempAllGiftItems); } else { bool isExist = false; for (int k = 0; k < allGiftItemList.Count; k++) { if (allGiftItemList[k].id == tempAllGiftItems.id) { isExist = true; allGiftItemList[k].count += tempAllGiftItems.count; break; } } if (!isExist) { allGiftItemList.Add(tempAllGiftItems); } } } } } int SortGift(ZhanLingGiftItemInfo a, ZhanLingGiftItemInfo b) { return b.quality.CompareTo(a.quality); } //按品质排序 public List SortAllHaveZhanLingGift() { allGiftItemList.Sort(SortGift); return allGiftItemList; } void UpdateRedpoint(int zhanLingType) { redpoint.state = RedPointState.None; if (zhanLingInfoDict == null || !zhanLingInfoDict.ContainsKey(zhanLingType)) return; var needValueList = ILZhanlingConfig.GetTypeToIDDict(zhanLingType).Keys.ToList(); for (int i = 0; i < needValueList.Count; i++) { int freeState = GetFreeGiftState(zhanLingType, needValueList[i]); int paidState = GetPaidGiftState(zhanLingType, needValueList[i]); int paidHState = GetPaidGiftHState(zhanLingType, needValueList[i]); if (freeState == 1 || paidState == 1 || paidHState == 1) { redpoint.state = RedPointState.Simple; break; } } } //已经购买并领取所有物品 public bool IsFinish() { int zhanLingType = ZhanLingHType; if (zhanLingInfoDict.IsNullOrEmpty() || !zhanLingInfoDict.TryGetValue(zhanLingType, out var zhanlingInfo) || zhanlingInfo == null || zhanlingInfo.freeZhanHaveDict == null || zhanlingInfo.paidZhanHaveDict == null) return false; //有没购买的 if (GetBuyState(zhanLingType) != 3) return false; //有没领取的物品 var arr = zhanlingInfo.freeZhanHaveDict.Keys.ToArray(); for (int i = 0; i < arr.Length; i++) { int needValue = arr[i]; if (GetFreeGiftState(zhanLingType, needValue) != 2 || GetPaidGiftState(zhanLingType, needValue) != 2 || GetPaidGiftHState(zhanLingType, needValue) != 2) return false; } return true; } }