using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using LitJson;
|
using TableConfig;
|
using UnityEngine;
|
|
namespace Snxxz.UI
|
{
|
public class ItemOverdueModel : Model,IBeforePlayerDataInitialize,IPlayerLoginOk, ISwitchAccount
|
{
|
private List<ItemModel> guardItemlist = new List<ItemModel>();
|
private Dictionary<int, List<int>> itemOverdueDict;
|
public static event Action FirstGoldWPOver;//首冲试用结束
|
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
PackModelInterface _modelInterface;
|
PackModelInterface modelInterface
|
{
|
get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel<PackModelInterface>()); }
|
}
|
|
public int guardOverdueIndex { get; set; }
|
|
public Dictionary<int, string> guardOverdueIconDict { get; private set;}
|
|
Dictionary<string,OverdueItem> itemStack = new Dictionary<string,OverdueItem>();
|
List<string> itemGuids = new List<string>();
|
public event Action showItemRefreshEvent;
|
public OverdueItem currentShowItem { get; private set; }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public readonly int VipExperirnceID = 985;
|
public readonly int VipCardID = 978;
|
|
public override void Init()
|
{
|
SysNotifyMgr.Instance.sysNotifyEvent += GetSysNotify;
|
//TimeMgr.Instance.OnSyntonyEvent += OnSyntonyEvent;
|
itemOverdueDict = new Dictionary<int, List<int>>();
|
FuncConfigConfig itemOverdueFunc = Config.Instance.Get<FuncConfigConfig>("ItemTimeOut");
|
JsonData jsonData = JsonMapper.ToObject(itemOverdueFunc.Numerical1);
|
foreach (var key in jsonData.Keys)
|
{
|
int i = 0;
|
List<int> renewallist = new List<int>();
|
for (i = 0; i < jsonData[key].Count; i++)
|
{
|
renewallist.Add(int.Parse(jsonData[key][i].ToString()));
|
}
|
itemOverdueDict.Add(int.Parse(key), renewallist);
|
}
|
FuncConfigConfig guardOverdueIcon = Config.Instance.Get<FuncConfigConfig>("GuardianOverDueImg");
|
guardOverdueIconDict = ConfigParse.GetDic<int,string>(guardOverdueIcon.Numerical1);
|
}
|
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
guardOverdueIndex = -1;
|
itemStack.Clear();
|
itemGuids.Clear();
|
currentShowItem = default(OverdueItem);
|
}
|
|
public void OnSwitchAccount()
|
{
|
|
}
|
|
void IPlayerLoginOk.OnPlayerLoginOk()
|
{
|
GetOverdueGuard();
|
}
|
|
public bool TryGetItem(string _guid, out OverdueItem _itemModel)
|
{
|
return itemStack.TryGetValue(_guid, out _itemModel);
|
}
|
|
public void ReportConfirmUseItem(OverdueItem _UseItem)
|
{
|
if (itemGuids.Contains(_UseItem.guid))
|
{
|
itemGuids.Remove(_UseItem.guid);
|
}
|
|
if (itemStack.ContainsKey(_UseItem.guid))
|
{
|
itemStack.Remove(_UseItem.guid);
|
}
|
|
RefreshCurrrentShowUseItem();
|
}
|
|
private void RefreshCurrrentShowUseItem()
|
{
|
OverdueItem tempItem;
|
if (FindLatestItem(out tempItem))
|
{
|
if (tempItem != currentShowItem)
|
{
|
currentShowItem = tempItem;
|
}
|
}
|
else
|
{
|
currentShowItem = default(OverdueItem);
|
}
|
|
if (showItemRefreshEvent != null)
|
{
|
showItemRefreshEvent();
|
}
|
}
|
|
private bool FindLatestItem(out OverdueItem _item)
|
{
|
if (itemGuids.Count == 0)
|
{
|
_item = default(OverdueItem);
|
return false;
|
}
|
|
var guid = itemGuids[itemGuids.Count - 1];
|
_item = itemStack[guid];
|
return true;
|
}
|
|
public bool ShowUseItemAble()
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var lineId = PlayerDatas.Instance.baseData.dungeonLineId;
|
var dungeonId = dungeonModel.DungeonMap(dungeonModel.GetDungeonDataIdByMapId(mapId), lineId);
|
if (dungeonId == 0)
|
{
|
return true;
|
}
|
else
|
{
|
var config = Config.Instance.Get<DungeonConfig>(dungeonId);
|
return config.ShowNewItemTip == 1;
|
}
|
}
|
|
private void OnGetOverdueItem(int itemId, string guid,int index)
|
{
|
var overdueItem = new OverdueItem(itemId,guid,index);
|
if (!itemGuids.Contains(guid))
|
{
|
itemGuids.Add(guid);
|
}
|
|
itemStack[guid] = overdueItem;
|
|
RefreshCurrrentShowUseItem();
|
}
|
|
private void OnSyntonyEvent(TimeMgr.SyntonyType type)
|
{
|
switch (type)
|
{
|
case TimeMgr.SyntonyType.VipExperirnceOverdue:
|
OnGetOverdueItem(VipExperirnceID,"",-1);
|
break;
|
}
|
}
|
|
public override void UnInit()
|
{
|
SysNotifyMgr.Instance.sysNotifyEvent -= GetSysNotify;
|
}
|
|
private void GetSysNotify(string sysID, ArrayList list)
|
{
|
if(showItemRefreshEvent != null)
|
{
|
showItemRefreshEvent();
|
}
|
SnxxzGame.Instance.StartCoroutine(DelayShowOverdue(sysID, list));
|
}
|
|
IEnumerator DelayShowOverdue(string sysID, ArrayList list)
|
{
|
yield return WaitingForSecondConst.WaitMS1000;
|
switch (sysID)
|
{
|
case "Guardian_Timeout":
|
DebugEx.Log("Guardian_Timeout:" + list.Count);
|
if (list.Count > 1)
|
{
|
guardOverdueIndex = int.Parse(list[1].ToString());
|
ItemModel itemModel = playerPack.GetItemModelByIndex(PackType.rptItem, guardOverdueIndex);
|
if (itemModel != null)
|
{
|
if (itemModel.chinItemModel.EquipPlace == (int)RoleEquipType.retSpiritAnimal)
|
{
|
OnGetOverdueItem(itemModel.itemInfo.ItemID,itemModel.itemInfo.ItemGUID,itemModel.itemInfo.ItemPlace);
|
}
|
}
|
}
|
|
break;
|
case "VipTiyan_Timeout":
|
|
OnGetOverdueItem(VipExperirnceID, "", -1);
|
break;
|
case "Vip_Timeout":
|
OnGetOverdueItem(VipCardID, "", -1);
|
break;
|
case "FirstGoldWPOver"://首冲试用
|
if (FirstGoldWPOver != null)
|
{
|
FirstGoldWPOver();
|
}
|
break;
|
}
|
}
|
|
public void SendRenewalQuest(int index, int moneyType)
|
{
|
CA307_tagCMItemRenew tagCMItemRenew = new CA307_tagCMItemRenew();
|
tagCMItemRenew.ItemIndex = (byte)index;
|
tagCMItemRenew.MoneyType = (byte)moneyType;
|
GameNetSystem.Instance.SendInfo(tagCMItemRenew);
|
}
|
|
public void GetOverdueGuard()
|
{
|
guardItemlist.Clear();
|
List<string> itemEffectlist = modelInterface.GetItemEffectTimelist();
|
int i = 0;
|
for (i = 0; i < itemEffectlist.Count; i++)
|
{
|
ItemModel itemModel = playerPack.GetItemModelByGUID(itemEffectlist[i]);
|
if (itemModel != null && itemModel.packType == PackType.rptItem)
|
{
|
if (itemModel.chinItemModel.EquipPlace == (int)RoleEquipType.retSpiritAnimal)
|
{
|
bool isOverdue = false;
|
ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(itemModel.itemInfo.ItemGUID);
|
if (itemModel.chinItemModel.ExpireTime > 0)
|
{
|
switch ((EquipReduceType)itemModel.chinItemModel.EndureReduceType)
|
{
|
case EquipReduceType.Def_EquipReduceType_Time:
|
List<int> itemEffectTime = itemModel.GetUseDataModel((int)ItemUseDataKey.Def_IudetCreateTime);
|
if (itemEffectTime != null && itemEffectTime[0] != 0)
|
{
|
if (cool == null || cool.GetRemainTime() <= 0)
|
{
|
isOverdue = true;
|
}
|
}
|
break;
|
|
case EquipReduceType.Def_EquipReduceType_RTimeItem:
|
if (cool == null || cool.GetRemainTime() <= 0)
|
{
|
isOverdue = true;
|
}
|
break;
|
}
|
}
|
|
if (isOverdue)
|
{
|
guardItemlist.Add(itemModel);
|
}
|
}
|
}
|
}
|
|
if (guardItemlist.Count > 0)
|
{
|
guardItemlist.Sort(CompareItemID);
|
OnGetOverdueItem(guardItemlist[0].itemInfo.ItemID, guardItemlist[0].itemInfo.ItemGUID, guardItemlist[0].itemInfo.ItemPlace);
|
}
|
}
|
|
public int CompareItemID(ItemModel start, ItemModel end)
|
{
|
int startId = start.itemInfo.ItemID;
|
int endId = end.itemInfo.ItemID;
|
if (startId.CompareTo(endId) != 0)
|
return -startId.CompareTo(endId);
|
|
return 0;
|
}
|
|
public bool IsMoneyEnough(int moneyType, int needMoney)
|
{
|
if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)needMoney)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
public List<int> GetRenewallist(int itemID)
|
{
|
List<int> renewallist = null;
|
itemOverdueDict.TryGetValue(itemID, out renewallist);
|
return renewallist;
|
}
|
|
public string GetGuardOverdueIcon(int itemId)
|
{
|
string s = "";
|
guardOverdueIconDict.TryGetValue(itemId,out s);
|
return s;
|
}
|
|
public struct OverdueItem
|
{
|
public int itemId { get; private set; }
|
public int index { get; private set; }
|
public string guid { get; private set; }
|
|
public OverdueItem(int itemId, string guid = "", int index = -1)
|
{
|
this.itemId = itemId;
|
this.index = index;
|
this.guid = guid;
|
}
|
|
public static bool operator ==(OverdueItem _lhs, OverdueItem _rhs)
|
{
|
return _lhs.itemId == _rhs.itemId && _lhs.guid == _rhs.guid && _lhs.index == _rhs.index;
|
}
|
|
public static bool operator !=(OverdueItem _lhs, OverdueItem _rhs)
|
{
|
return _lhs.itemId != _rhs.itemId || _lhs.guid != _rhs.guid || _lhs.index == _rhs.index;
|
}
|
|
}
|
}
|
}
|