using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace vnxbqy.UI
|
{
|
public class FairyAffinityZhanLingModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public int ZhanLingType = 9;
|
public int FuncId = 240;
|
public int buyValue;//Õ½Áî¼ÛÖµÏÉÓñ
|
|
// Õ½ÁîÀàÐͶÔÓ¦µÄ³äÖµIDÁбí
|
public Dictionary<int, int> ctgIdDict = new Dictionary<int, int>();
|
|
//ÊÕµ½µÄËùÓзþÎñÆ÷Õ½Áî°ü×Öµä
|
public Dictionary<int, ZhanlingInfo> zhanLingInfoDict = new Dictionary<int, ZhanlingInfo>();
|
|
//Õ½ÁîÀàÐÍ: ËùÐèÖµ :key
|
public Dictionary<int, Dictionary<int, int>> typeToIDListDict = new Dictionary<int, Dictionary<int, int>>();
|
|
public event Action UpdateGiftStateEvent;
|
public Redpoint redpoint = new Redpoint(MainRedDot.FairyAffinityRepoint, MainRedDot.FairyAffinityRepoint * 10 + 1);
|
List<ZhanLingGiftItemInfo> allGiftItemList = new List<ZhanLingGiftItemInfo>();
|
|
//ͬ²½²¥·Å°Ú¶¯¶¯»
|
public Action PlayAnimationSync;
|
|
private bool isPlayAnimation = false;
|
public bool IsPlayAnimation
|
{
|
get
|
{
|
return isPlayAnimation;
|
}
|
set
|
{
|
isPlayAnimation = value;
|
if (isPlayAnimation)
|
{
|
PlayAnimationSync?.Invoke();
|
}
|
isPlayAnimation = false;
|
}
|
}
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
public override void Init()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent += OnplayerDataRefreshEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionStateChange;
|
ctgIdDict = GeneralDefine.OldZhanLingCtgIdDict;
|
typeToIDListDict = ILZhanlingConfig.GetAllTypeToIDListDict();
|
buyValue = int.Parse(FuncConfigConfig.Get("FairyAffinity").Numerical1);
|
}
|
|
public override void UnInit()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnplayerDataRefreshEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionStateChange;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
zhanLingInfoDict.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
private void OnplayerDataRefreshEvent(PlayerDataType type)
|
{
|
if (type == PlayerDataType.default42)
|
{
|
UpdateRedpoint(ZhanLingType);
|
}
|
}
|
|
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<int, int>();
|
zhanlingInfo.paidZhanHaveDict = new Dictionary<int, int>();
|
zhanlingInfo.paidZhanHaveHDict = new Dictionary<int, int>();
|
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 == ZhanLingType)
|
{
|
UpdateGiftStateEvent?.Invoke();
|
UpdateRedpoint(ZhanLingType);
|
}
|
}
|
|
private void OnFunctionStateChange(int id)
|
{
|
if (id == FuncId)
|
{
|
UpdateRedpoint(ZhanLingType);
|
}
|
}
|
|
public ulong GetNowValue()
|
{
|
return UIHelper.GetMoneyCnt(49);
|
}
|
|
// »ñµÃµ±Ç°°´Å¥ÏÔʾµÄ״̬
|
// 0 ²»ÄÜÁì 1 δÁìÈ¡ 2 ÒÑÁìÈ¡
|
public int GetGiftState(int zhanLingType, int needValue, bool isFreeGift)
|
{
|
if (GetNowValue() >= (ulong)needValue)
|
{
|
//ÊDz»ÊÇÃâ·ÑÀñ°ü
|
if (isFreeGift)
|
{
|
return IsHaveZhanLingGift(zhanLingType, needValue, true) ? 2 : 1;
|
}
|
else
|
{
|
//ÂòûÂò¹ý¸¶·ÑÕ½Áî
|
if (IsBuy())
|
{
|
return IsHaveZhanLingGift(zhanLingType, needValue, false) ? 2 : 1;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
public bool IsBuy()
|
{
|
return zhanLingInfoDict[ZhanLingType].isActivite > 0;
|
}
|
|
//·¢°ü
|
public void HaveGift(int zhanLingType, int needValue, bool isFreeGift)
|
{
|
var pak = new IL_CA504_tagCMPlayerGetReward();
|
string dataExStr = isFreeGift ? (needValue * 10 + 0).ToString() : (needValue * 10 + 1).ToString();
|
pak.RewardType = (byte)65;
|
pak.DataEx = (uint)zhanLingType;
|
pak.DataExStrLen = (byte)dataExStr.Length;
|
pak.DataExStr = dataExStr;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
//ÊÇ·ñÁìÈ¡Á˵±Ç°ÕâµµµÄÎïÆ·
|
public bool IsHaveZhanLingGift(int zhanLingType, int needValue, bool isFreeGift)
|
{
|
return isFreeGift ? zhanLingInfoDict[zhanLingType].freeZhanHaveDict[needValue] > 0 : zhanLingInfoDict[zhanLingType].paidZhanHaveDict[needValue] > 0;
|
}
|
|
//»ñÈ¡ItemCellµÄID
|
public int GetItemCellID(int zhanLingType, int needValue, bool isFreeGift, int loopIndedx = 0)
|
{
|
return isFreeGift ? ILZhanlingConfig.Get(typeToIDListDict[zhanLingType][needValue]).FreeRewardItemList[0][0] : ILZhanlingConfig.Get(typeToIDListDict[zhanLingType][needValue]).ZLRewardItemList[loopIndedx][0];
|
}
|
|
//»ñÈ¡ItemCellµÄÊýÁ¿
|
public int GetItemCellCount(int zhanLingType, int needValue, bool isFreeGift, int loopIndedx = 0)
|
{
|
return isFreeGift ? ILZhanlingConfig.Get(typeToIDListDict[zhanLingType][needValue]).FreeRewardItemList[0][1] : ILZhanlingConfig.Get(typeToIDListDict[zhanLingType][needValue]).ZLRewardItemList[loopIndedx][1];
|
}
|
|
//»ñÈ¡×îСδÁìÈ¡µÄÎïÆ·Ë÷Òý
|
public int GetJumpStartIndex(int zhanLingType)
|
{
|
var infoDict = ILZhanlingConfig.GetTypeToIDDict(zhanLingType);
|
if (infoDict.IsNullOrEmpty())
|
return 0;
|
|
List<int> 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;
|
|
if (!isHaveFree || !isHavePaid)
|
{
|
allItemsClaimed = false;
|
if (!isHaveFree)
|
{
|
index = i;
|
break;
|
}
|
|
if (zhanLingInfo.isActivite > 0 && !isHavePaid)
|
{
|
index = i;
|
break;
|
}
|
}
|
}
|
|
if (allItemsClaimed && zhanLingInfo.isActivite > 0)
|
{
|
return infoList.Count - 1;
|
}
|
|
return Math.Max(0, index - 2);
|
}
|
|
//Ò»¼ü»ñÈ¡ËùÓпÉÁìÈ¡µÄÀñÆ·,µ¯³öչʾ´°¿Ú
|
public void HaveAllZhanLingGift(int zhanLingType)
|
{
|
//ûÓиñ×Ó
|
if (ModelCenter.Instance.GetModelEx<PackModel>().GetEmptyGridCount(PackType.Item) < 1)
|
{
|
SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
|
return;
|
}
|
List<int> haveFreeRewardItemList = new List<int>(); //Óû§Áìµ½µÄÃâ·ÑÎïÆ·µÄËùÐèÖµÁбí
|
List<int> havePaidRewardItemList = new List<int>(); //Óû§Áìµ½µÄ¸¶·ÑÎïÆ·µÄËùÐèÖµÁбí
|
var needValueList = ILZhanlingConfig.GetTypeToIDDict(zhanLingType).Keys.ToList();
|
for (int i = 0; i < needValueList.Count; i++)
|
{
|
int freeState = GetGiftState(zhanLingType, needValueList[i], true);
|
int paidState = GetGiftState(zhanLingType, needValueList[i], false);
|
if (freeState == 1)
|
{
|
haveFreeRewardItemList.Add(needValueList[i]);
|
}
|
if (paidState == 1)
|
{
|
havePaidRewardItemList.Add(needValueList[i]);
|
}
|
}
|
MergeAllHaveZhanLingGift(zhanLingType, haveFreeRewardItemList, havePaidRewardItemList);
|
DebugEx.Log($"±³°ü¿Õ¸ñ {ModelCenter.Instance.GetModelEx<PackModel>().GetEmptyGridCount(PackType.Item)} ÐèÒª¸ñ×Ó {allGiftItemList.Count}");
|
if (ModelCenter.Instance.GetModelEx<PackModel>().GetEmptyGridCount(PackType.Item) >= allGiftItemList.Count)
|
{
|
for (int i = 0; i < needValueList.Count; i++)
|
{
|
int freeState = GetGiftState(zhanLingType, needValueList[i], true);
|
int paidState = GetGiftState(zhanLingType, needValueList[i], false);
|
if (freeState == 1)
|
{
|
HaveGift(zhanLingType, needValueList[i], true);
|
}
|
if (paidState == 1)
|
{
|
HaveGift(zhanLingType, needValueList[i], false);
|
}
|
}
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
|
return;
|
}
|
}
|
|
public void MergeAllHaveZhanLingGift(int zhanLingType, List<int> haveFreeRewardItemList, List<int> havePaidRewardItemList)
|
{
|
for (int i = 0; i < haveFreeRewardItemList.Count; i++)
|
{
|
for (int j = 0; j < ILZhanlingConfig.Get(typeToIDListDict[zhanLingType][haveFreeRewardItemList[i]]).FreeRewardItemList.Length; j++)
|
{
|
ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo();
|
tempAllGiftItems.id = ILZhanlingConfig.Get(typeToIDListDict[zhanLingType][haveFreeRewardItemList[i]]).FreeRewardItemList[j][0];
|
tempAllGiftItems.count = ILZhanlingConfig.Get(typeToIDListDict[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(typeToIDListDict[zhanLingType][havePaidRewardItemList[i]]).ZLRewardItemList.Length; j++)
|
{
|
ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo();
|
tempAllGiftItems.id = ILZhanlingConfig.Get(typeToIDListDict[zhanLingType][havePaidRewardItemList[i]]).ZLRewardItemList[j][0];
|
tempAllGiftItems.count = ILZhanlingConfig.Get(typeToIDListDict[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);
|
}
|
}
|
}
|
}
|
}
|
|
private int SortGift(ZhanLingGiftItemInfo a, ZhanLingGiftItemInfo b)
|
{
|
return b.quality.CompareTo(a.quality);
|
}
|
|
//°´Æ·ÖÊÅÅÐò
|
public List<ZhanLingGiftItemInfo> SortAllHaveZhanLingGift()
|
{
|
allGiftItemList.Sort(SortGift);
|
return allGiftItemList;
|
}
|
|
private void UpdateRedpoint(int zhanLingType)
|
{
|
redpoint.state = RedPointState.None;
|
if (zhanLingInfoDict == null || !zhanLingInfoDict.ContainsKey(zhanLingType) || zhanLingInfoDict[zhanLingType].freeZhanHaveDict == null || !FuncOpen.Instance.IsFuncOpen(217))
|
return;
|
var needValueList = zhanLingInfoDict[zhanLingType].freeZhanHaveDict.Keys.ToList();
|
for (int i = 0; i < zhanLingInfoDict[zhanLingType].freeZhanHaveDict.Count; i++)
|
{
|
if (GetGiftState(zhanLingType, needValueList[i], true) == 1 || GetGiftState(zhanLingType, needValueList[i], false) == 1)
|
{
|
redpoint.state = RedPointState.Simple;
|
break;
|
}
|
}
|
}
|
|
//ÒѾ¹ºÂò²¢ÁìÈ¡ËùÓÐÎïÆ·
|
public bool IsFinish()
|
{
|
if (zhanLingInfoDict.IsNullOrEmpty() || !zhanLingInfoDict.TryGetValue(ZhanLingType, out var zhanlingInfo) ||
|
zhanlingInfo == null || zhanlingInfo.freeZhanHaveDict == null || zhanlingInfo.paidZhanHaveDict == null)
|
return false;
|
//ÓÐû¹ºÂòµÄ
|
if (zhanlingInfo.isActivite == 0)
|
return false;
|
//ÓÐûÁìÈ¡µÄÎïÆ·
|
var arr = zhanlingInfo.freeZhanHaveDict.Keys.ToArray();
|
for (int i = 0; i < arr.Length; i++)
|
{
|
int needValue = arr[i];
|
if (!IsHaveZhanLingGift(ZhanLingType, needValue, false) || !IsHaveZhanLingGift(ZhanLingType, needValue, true))
|
return false;
|
}
|
return true;
|
}
|
}
|
}
|