using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
using System.Linq;
|
using LitJson;
|
|
//天帝礼包 - 独立入口
|
public class GodKingGiftModel : ILModel<GodKingGiftModel>
|
{
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_JCHD;
|
public const int activityID = 99; //不能与精彩活动ID重复,独立入口
|
public const Operation operationType = Operation.default22; //天帝礼包
|
public ILOpenServerActivityProxy activity;
|
|
public Redpoint redpoint = new Redpoint(MainRedPoint.TDLBRedPoint);
|
|
public byte ResetCount; // 本次活动已重置次数
|
public IL_HAA61_tagMCActGodGiftPlayerInfo.tagMCActGodGiftAwardItem[] AwardItemList; // 本次奖池已抽中物品列表
|
|
public event Action OnPlayerInfoEvent;
|
|
//奖池库类型
|
public event Action OnSelectUpdate;
|
int m_SelectType = 0;
|
public int selectType
|
{
|
get { return m_SelectType; }
|
set
|
{
|
if (m_SelectType != value)
|
{
|
m_SelectType = value;
|
OnSelectUpdate?.Invoke();
|
}
|
}
|
}
|
|
public IL_HAA60_tagMCActGodGiftInfo.tagMCActGodGiftItem[] itemsLib; //当前要展示的可选物品
|
|
public struct GodKingGiftItem
|
{
|
public byte itemNum; // 物品在本库中的编号
|
public uint itemID;
|
public ushort itemCount;
|
public byte libType; //奖池类型
|
}
|
|
//已选中的奖池物品(未确认),按选择的顺序倒序显示
|
public List<GodKingGiftItem> selectedItems = new List<GodKingGiftItem>();
|
//正在抽奖中的物品 AA61中为抽中物品,对比不相交部分就是未抽中
|
public List<GodKingGiftItem> godKingItems = new List<GodKingGiftItem>();
|
public int newItemIndex;
|
public int awardShowSetp = 0; //-1 默认正常显示 0 点按钮开始 1 开始物品聚集转圈 2 物品转圈结束 回到0刷新界面 显示得奖界面
|
|
public int SelectLimitedCnt = 0; //选满多少个才可以确认奖池
|
public event Action OnSelectItemEvent;
|
|
protected override void Init()
|
{
|
activity = new ILOpenServerActivityProxy(IsOpen, IsAdvance, priorityOpen);
|
OpenServerActivityCenter.Instance.Register(activityID, activity, activityType);
|
|
GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
ILOperationTimeHepler.Instance.operationTimeUpdateEvent += operationTimeUpdateEvent;
|
}
|
|
protected override void UnInit()
|
{
|
GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
ILOperationTimeHepler.Instance.operationTimeUpdateEvent -= operationTimeUpdateEvent;
|
}
|
|
public bool IsOpen()
|
{
|
return OperationTimeHepler.Instance.SatisfyOpenCondition(operationType);
|
}
|
|
public bool IsAdvance()
|
{
|
return false;
|
}
|
|
public bool priorityOpen()
|
{
|
//红点
|
return redpoint.state == RedPointState.Simple;
|
}
|
|
|
public void OnPlayerLoginOk()
|
{
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
selectedItems.Clear();
|
godKingItems.Clear();
|
awardShowSetp = -1;
|
}
|
|
|
private void operationTimeUpdateEvent(Operation type)
|
{
|
if (type == operationType)
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return;
|
}
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
|
if (operation.IsAwardPoolOK != 0 && WindowCenter.Instance.IsOpen("GodKingGiftWin"))
|
{
|
WindowCenter.Instance.CloseIL<GodKingGiftWin>();
|
WindowCenter.Instance.OpenIL<GodKingRandomGiftWin>();
|
}
|
else if (operation.IsAwardPoolOK == 0 && WindowCenter.Instance.IsOpen("GodKingRandomGiftWin"))
|
{
|
WindowCenter.Instance.CloseIL<GodKingRandomGiftWin>();
|
WindowCenter.Instance.OpenIL<GodKingGiftWin>();
|
}
|
UpdateRedpoint();
|
}
|
}
|
|
//免费次数未用(包含了奖池未选择的情况)
|
void UpdateRedpoint()
|
{
|
redpoint.state = RedPointState.None;
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return;
|
}
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
if (operation.IsAwardPoolOK == 0)
|
{
|
redpoint.state = RedPointState.Simple;
|
return;
|
}
|
else if (AwardItemList != null && operation.CostMoneyValueList[Math.Min(AwardItemList.Length, operation.CostMoneyValueList.Length - 1)] == 0)
|
{
|
redpoint.state = RedPointState.Simple;
|
}
|
|
}
|
|
public void UpdatePlayerInfo(IL_HAA61_tagMCActGodGiftPlayerInfo netPack)
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return;
|
}
|
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
if (operation.ActNum != netPack.ActNum)
|
{
|
return;
|
}
|
|
ResetCount = netPack.ResetCount;
|
|
//找出不同物品
|
if (AwardItemList != netPack.AwardItemList && awardShowSetp == 0)
|
{
|
newItemIndex = -1;
|
for (int i = 0; i < netPack.AwardItemList.Length; i++)
|
{
|
bool find = false;
|
if (AwardItemList != null)
|
{
|
for (int j = 0; j < AwardItemList.Length; j++)
|
{
|
if (netPack.AwardItemList[i].ItemLibType == AwardItemList[j].ItemLibType &&
|
netPack.AwardItemList[i].ItemNum == AwardItemList[j].ItemNum)
|
{
|
find = true;
|
break;
|
}
|
}
|
}
|
|
if (!find)
|
{
|
for (int k = 0; k < godKingItems.Count; k++)
|
{
|
if (godKingItems[k].itemNum == netPack.AwardItemList[i].ItemNum
|
&& godKingItems[k].libType == netPack.AwardItemList[i].ItemLibType)
|
{
|
newItemIndex = k;
|
awardShowSetp = 1;
|
}
|
}
|
break;
|
}
|
|
}
|
}
|
AwardItemList = netPack.AwardItemList;
|
|
OnPlayerInfoEvent?.Invoke();
|
UpdateRedpoint();
|
}
|
|
//根据奖池是否选择完毕来决定打开界面
|
public void OpenWindow()
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return;
|
}
|
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
if (operation.IsAwardPoolOK == 0)
|
{
|
WindowCenter.Instance.OpenIL<GodKingGiftWin>();
|
}
|
else
|
{
|
WindowCenter.Instance.OpenIL<GodKingRandomGiftWin>();
|
}
|
}
|
|
//当前要展示库的可选物品
|
public void RefreshItemsByType()
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
itemsLib = null;
|
return;
|
}
|
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
for (int i = 0; i < operation.ItemLibList.Length; i++)
|
{
|
if (operation.ItemLibList[i].ItemLibType == selectType + 1)
|
{
|
itemsLib = operation.ItemLibList[i].GodGiftItemList;
|
return;
|
}
|
}
|
|
itemsLib = null;
|
}
|
|
// 指定库的已选物品数量
|
public int SelectdCountByLib(int libType)
|
{
|
int cnt = 0;
|
for (int i = 0; i < selectedItems.Count; i++)
|
{
|
if (selectedItems[i].libType == libType)
|
{
|
cnt++;
|
}
|
}
|
return cnt;
|
}
|
|
public void OnSelectItem(int index, bool isAdd)
|
{
|
var itemInfo = itemsLib[index];
|
if (isAdd)
|
{
|
selectedItems.Add(new GodKingGiftItem()
|
{
|
itemNum = itemInfo.ItemNum,
|
itemID = itemInfo.ItemID,
|
itemCount = itemInfo.ItemCount,
|
libType = (byte)(selectType + 1),
|
});
|
}
|
else
|
{
|
int delIndex = -1;
|
for (int i = 0; i < selectedItems.Count; i++)
|
{
|
if (itemInfo.ItemNum == selectedItems[i].itemNum && selectedItems[i].libType == (selectType + 1))
|
{
|
delIndex = i;
|
break;
|
}
|
}
|
if (delIndex != -1)
|
{
|
selectedItems.RemoveAt(delIndex);
|
}
|
}
|
OnSelectItemEvent?.Invoke();
|
}
|
|
//库对应的选择数量
|
public Dictionary<int, int> libSelectCnt = new Dictionary<int, int>();
|
|
public int GetMaxSelectCnt()
|
{
|
if (SelectLimitedCnt == 0)
|
{
|
libSelectCnt.Clear();
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
itemsLib = null;
|
return SelectLimitedCnt;
|
}
|
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
|
for (int i = 0; i < operation.ItemLibList.Length; i++)
|
{
|
SelectLimitedCnt += operation.ItemLibList[i].NeedChooseCount;
|
libSelectCnt[operation.ItemLibList[i].ItemLibType] = operation.ItemLibList[i].NeedChooseCount;
|
}
|
return SelectLimitedCnt;
|
}
|
|
return SelectLimitedCnt;
|
}
|
|
public int GetLibSelectCnt(int libType)
|
{
|
return libSelectCnt[libType];
|
}
|
|
public int GetResetCnt()
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return 0;
|
}
|
|
OperationGodKingGift operation = operationBase as OperationGodKingGift;
|
|
return operation.ResetCountMax - ResetCount;
|
}
|
}
|