using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using LitJson;
|
|
using UnityEngine;
|
|
namespace vnxbqy.UI
|
{
|
|
public class ItemOverdueModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, ISwitchAccount
|
{
|
private List<ItemModel> overdueGuardPushlist = new List<ItemModel>();
|
private Dictionary<int, List<int>> itemOverdueDict;
|
public static event Action FirstGoldWPOver;//首冲试用结束
|
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
Dictionary<int, string> guardOverdueIconDict { get; 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>(); } }
|
bool isdelay = true;
|
|
public readonly int VipExperirnceID = 985;
|
public readonly int VipCardID = 978;
|
Dictionary<int, Dictionary<int, List<ItemModel>>> allGuardDict = new Dictionary<int, Dictionary<int, List<ItemModel>>>(); //守护类型,守护ID
|
|
public override void Init()
|
{
|
//SysNotifyMgr.Instance.sysNotifyEvent += GetSysNotify;
|
itemOverdueDict = new Dictionary<int, List<int>>();
|
FuncConfigConfig itemOverdueFunc = FuncConfigConfig.Get("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 = FuncConfigConfig.Get("GuardianOverDueImg");
|
guardOverdueIconDict = ConfigParse.GetDic<int, string>(guardOverdueIcon.Numerical1);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
isdelay = true;
|
//GlobalTimeEvent.Instance.secondEvent -= UpdateSecond;
|
playerPack.refreshItemCountEvent -= UpdateItemCount;
|
itemStack.Clear();
|
itemGuids.Clear();
|
currentShowItem = default(OverdueItem);
|
}
|
|
public void OnSwitchAccount()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
playerPack.refreshItemCountEvent += UpdateItemCount;
|
//GlobalTimeEvent.Instance.secondEvent += UpdateSecond;
|
time = 0;
|
}
|
|
float time = 0;
|
private void UpdateSecond()
|
{
|
if (isdelay)
|
{
|
time += 1;
|
if (time >= 5)
|
{
|
GetOverdueGuard();
|
isdelay = false;
|
time = 0;
|
}
|
}
|
}
|
|
public bool TryGetItem(string _guid, out OverdueItem _itemModel)
|
{
|
return itemStack.TryGetValue(_guid, out _itemModel);
|
}
|
|
public void ReportConfirmUseItem(string guid)
|
{
|
if (guid == null)
|
{
|
return;
|
}
|
|
if (itemGuids.Contains(guid))
|
{
|
itemGuids.Remove(guid);
|
}
|
|
if (itemStack.ContainsKey(guid))
|
{
|
itemStack.Remove(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.GetDungeonId(dungeonModel.GetDataMapIdByMapId(mapId), lineId);
|
if (dungeonId == 0)
|
{
|
return true;
|
}
|
else
|
{
|
var config = DungeonConfig.Get(dungeonId);
|
return config.ShowNewItemTip == 1;
|
}
|
}
|
|
private void UpdateItemCount(PackType type, int index, int id)
|
{
|
if (type != PackType.Item && type != PackType.Warehouse) return;
|
ItemConfig itemConfig = ItemConfig.Get(id);
|
if (itemConfig == null || itemConfig.EquipPlace != (int)RoleEquipType.Guard) return;
|
|
bool isRemove = false;
|
for (int i = 0; i < itemGuids.Count; i++)
|
{
|
string guid = itemGuids[i];
|
ItemModel itemModel = playerPack.GetItemByGuid(guid);
|
if (itemModel == null || itemModel.packType != PackType.Item)
|
{
|
isRemove = true;
|
if (itemGuids.Contains(guid))
|
{
|
itemGuids.Remove(guid);
|
}
|
|
if (itemStack.ContainsKey(guid))
|
{
|
itemStack.Remove(guid);
|
}
|
}
|
}
|
if (isRemove)
|
{
|
RefreshCurrrentShowUseItem();
|
}
|
}
|
|
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":
|
if (list.Count > 1)
|
{
|
SetAllGuardIdlist();
|
int index = int.Parse(list[1].ToString());
|
ItemModel itemModel = playerPack.GetItemByIndex(PackType.Item, index);
|
if (itemModel != null)
|
{
|
List<int> renewallist = GetRenewallist(itemModel.itemId);
|
if (renewallist != null && allGuardDict.ContainsKey(renewallist[0]))
|
{
|
Dictionary<int, List<ItemModel>> pairs = allGuardDict[renewallist[0]];
|
bool isOverdue = true;
|
List<int> idlist = pairs.Keys.ToList();
|
idlist.Sort();
|
List<ItemModel> models = null;
|
for (int i = idlist.Count - 1; i > -1; i--)
|
{
|
models = pairs[idlist[i]];
|
for (int j = 0; j < models.Count; j++)
|
{
|
if (!ItemLogicUtility.Instance.IsOverdue(models[j].guid))
|
{
|
isOverdue = false;
|
break;
|
}
|
}
|
}
|
if (isOverdue)
|
{
|
for (int i = idlist.Count - 1; i > -1; i--)
|
{
|
models = pairs[idlist[i]];
|
if (models != null && models.Count > 0)
|
{
|
ItemModel overdueModel = models[0];
|
OnGetOverdueItem(overdueModel.itemId, overdueModel.guid, overdueModel.gridIndex);
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
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)
|
{
|
var tagCMItemRenew = new CA307_tagCMItemRenew();
|
tagCMItemRenew.ItemIndex = (byte)index;
|
tagCMItemRenew.MoneyType = (byte)moneyType;
|
GameNetSystem.Instance.SendInfo(tagCMItemRenew);
|
}
|
|
void GetOverdueGuard()
|
{
|
SetAllGuardIdlist();
|
overdueGuardPushlist.Clear();
|
foreach (var type in allGuardDict.Keys)
|
{
|
bool isOverdue = true;
|
List<int> idlist = allGuardDict[type].Keys.ToList();
|
idlist.Sort();
|
List<ItemModel> models = null;
|
for (int i = idlist.Count - 1; i > -1; i--)
|
{
|
models = allGuardDict[type][idlist[i]];
|
for (int j = 0; j < models.Count; j++)
|
{
|
if (!ItemLogicUtility.Instance.IsOverdue(models[j].guid))
|
{
|
isOverdue = false;
|
break;
|
}
|
}
|
}
|
|
if (isOverdue)
|
{
|
for (int i = idlist.Count - 1; i > -1; i--)
|
{
|
models = allGuardDict[type][idlist[i]];
|
if (models != null)
|
{
|
bool isHave = false;
|
for (int j = 0; j < models.Count; j++)
|
{
|
ItemModel itemModel = models[j];
|
if (itemModel.packType == PackType.Item)
|
{
|
isHave = true;
|
if (!overdueGuardPushlist.Contains(itemModel))
|
{
|
overdueGuardPushlist.Add(itemModel);
|
}
|
break;
|
}
|
}
|
if (isHave)
|
{
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
for (int i = 0; i < overdueGuardPushlist.Count; i++)
|
{
|
OnGetOverdueItem(overdueGuardPushlist[i].itemId, overdueGuardPushlist[i].guid, overdueGuardPushlist[i].gridIndex);
|
}
|
}
|
|
public bool IsMoneyEnough(int moneyType, int needMoney)
|
{
|
if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)needMoney)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
void SetAllGuardIdlist()
|
{
|
allGuardDict.Clear();
|
foreach (var id in itemOverdueDict.Keys)
|
{
|
SetGurdIdlistByPack(PackType.Item, id);
|
SetGurdIdlistByPack(PackType.Equip, id);
|
SetGurdIdlistByPack(PackType.Warehouse, id);
|
}
|
}
|
|
private void SetGurdIdlistByPack(PackType type, int itemId)
|
{
|
SinglePack singlePack = playerPack.GetSinglePack(type);
|
if (singlePack == null) return;
|
|
List<int> renewallist = GetRenewallist(itemId);
|
if (renewallist == null) return;
|
|
var itemModels = singlePack.GetItemsById(itemId);
|
if (!allGuardDict.ContainsKey(renewallist[0]))
|
{
|
Dictionary<int, List<ItemModel>> pairs = new Dictionary<int, List<ItemModel>>();
|
List<ItemModel> modellist = new List<ItemModel>();
|
modellist.AddRange(itemModels);
|
pairs.Add(itemId, modellist);
|
allGuardDict.Add(renewallist[0], pairs);
|
}
|
else
|
{
|
if (!allGuardDict[renewallist[0]].ContainsKey(itemId))
|
{
|
List<ItemModel> modellist = new List<ItemModel>();
|
modellist.AddRange(itemModels);
|
allGuardDict[renewallist[0]].Add(itemId, modellist);
|
}
|
else
|
{
|
allGuardDict[renewallist[0]][itemId].AddRange(itemModels);
|
}
|
}
|
}
|
|
public bool CanRenewal(int itemId)
|
{
|
return itemOverdueDict.ContainsKey(itemId);
|
}
|
|
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;
|
}
|
|
}
|
}
|
}
|