//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Sunday, January 21, 2018
|
//--------------------------------------------------------
|
using System;
|
using System.Collections.Generic;
|
|
|
namespace vnxbqy.UI
|
{
|
|
|
public class PreciousItemGetModel : Model, IBeforePlayerDataInitialize, ISwitchAccount, IPlayerLoginOk
|
{
|
Dictionary<string, PreciousItem> itemStack = new Dictionary<string, PreciousItem>();
|
List<string> itemGuids = new List<string>();
|
List<string> itemExpGuids = new List<string>();
|
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
CrossServerOneVsOneModel crossOneVsOneModel { get { return ModelCenter.Instance.GetModel<CrossServerOneVsOneModel>(); } }
|
|
public PreciousItem currentShowItem { get; private set; }
|
public event Action showItemRefreshEvent;
|
public bool isGetNewItem { get; set; }
|
|
bool isServerPrepare { get; set; }
|
public override void Init()
|
{
|
ItemLogicUtility.Instance.GetPreciousItemEvent += OnGetPreciousItem;
|
ItemLogicUtility.Instance.GetExpItemEvent += OnGetPreciousExpItem;
|
playerPack.refrechPackEvent += OnPackageRefresh;
|
playerPack.refreshItemCountEvent += OnPackageItemRefresh;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
}
|
|
public override void UnInit()
|
{
|
ItemLogicUtility.Instance.GetPreciousItemEvent -= OnGetPreciousItem;
|
ItemLogicUtility.Instance.GetExpItemEvent -= OnGetPreciousExpItem;
|
playerPack.refrechPackEvent -= OnPackageRefresh;
|
playerPack.refreshItemCountEvent -= OnPackageItemRefresh;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
isGetNewItem = false;
|
isServerPrepare = false;
|
PlayerDatas.Instance.playerDataRefreshEvent -= RefreshRealm;
|
CrossServerOneVsOnePlayerInfo.Instance.UpdateMatchNumEvent -= UpdateCrossOneVsOneMatchNum;
|
}
|
|
public void OnSwitchAccount()
|
{
|
currentShowItem = default(PreciousItem);
|
}
|
|
|
public void OnPlayerLoginOk()
|
{
|
isServerPrepare = true;
|
PlayerDatas.Instance.playerDataRefreshEvent += RefreshRealm;
|
CrossServerOneVsOnePlayerInfo.Instance.UpdateMatchNumEvent += UpdateCrossOneVsOneMatchNum;
|
}
|
|
|
public bool TryGetItem(string _guid, out PreciousItem _itemModel)
|
{
|
return itemStack.TryGetValue(_guid, out _itemModel);
|
}
|
|
public void ReportConfirmPreciousItem(PreciousItem _preciousItem)
|
{
|
if (string.IsNullOrEmpty(_preciousItem.guid))
|
{
|
return;
|
}
|
|
if (itemExpGuids.Contains(_preciousItem.guid))
|
{
|
itemExpGuids.Remove(_preciousItem.guid);
|
}
|
|
if (itemGuids.Contains(_preciousItem.guid))
|
{
|
itemGuids.Remove(_preciousItem.guid);
|
}
|
|
if (itemStack.ContainsKey(_preciousItem.guid))
|
{
|
itemStack.Remove(_preciousItem.guid);
|
}
|
|
RefreshCurrrentShowPreciousItem();
|
}
|
|
public int GetShowItemId()
|
{
|
if (currentShowItem == default(PreciousItem))
|
{
|
return 0;
|
}
|
else
|
{
|
var item = playerPack.GetItemByGuid(currentShowItem.guid);
|
return item == null ? 0 : item.config.ID;
|
}
|
}
|
|
private void UpdateCrossOneVsOneMatchNum()
|
{
|
if (!TryRemindMatchTick()) return;
|
|
var itemModels = playerPack.GetItemsById(PackType.Item, 1506);
|
if (itemModels != null && itemModels.Count > 0)
|
{
|
var itemModel = itemModels[0];
|
var error = 0;
|
var isHaveMakeNum = ItemOperateUtility.Instance.CanUseItem(itemModel.guid, 1, out error);
|
if (isHaveMakeNum)
|
{
|
OnGetPreciousItem(PackType.Item, itemModel.guid);
|
}
|
}
|
}
|
|
private bool TryRemindMatchTick()
|
{
|
if (NewBieCenter.Instance.inGuiding || !CrossServerOneVsOnePKSeason.Instance.isSatisfyMatch) return false;
|
int remainNum = CrossServerOneVsOnePlayerInfo.Instance.GetDayRemainNum();
|
if (remainNum > 0) return false;
|
return true;
|
}
|
|
private void RefreshRealm(PlayerDataType type)
|
{
|
int realmLv = PlayerDatas.Instance.baseData.realmLevel;
|
if (type != PlayerDataType.RealmLevel
|
|| NewBieCenter.Instance.inGuiding)
|
{
|
return;
|
}
|
|
List<ItemModel> druglist = ItemLogicUtility.Instance.GetDruglistByRealm();
|
for (int i = 0; i < druglist.Count; i++)
|
{
|
OnGetPreciousItem(druglist[i].packType, druglist[i].guid);
|
}
|
}
|
|
private void OnGetPreciousItem(PackType type, string guid)
|
{
|
var preciousItem = new PreciousItem(type, guid);
|
if (!itemGuids.Contains(guid))
|
{
|
itemGuids.Add(guid);
|
}
|
|
itemStack[guid] = preciousItem;
|
|
RefreshCurrrentShowPreciousItem();
|
}
|
|
private void OnGetPreciousExpItem(PackType type, string guid)
|
{
|
var preciousItem = new PreciousItem(type, guid);
|
if (!itemExpGuids.Contains(guid))
|
{
|
itemExpGuids.Add(guid);
|
}
|
|
itemStack[guid] = preciousItem;
|
|
RefreshCurrrentShowPreciousItem();
|
}
|
|
private void OnPackageRefresh(PackType _type)
|
{
|
if (_type != PackType.Item)
|
{
|
return;
|
}
|
|
RefreshCurrrentShowPreciousItem();
|
}
|
|
private void OnPackageItemRefresh(PackType _type, int _index, int _itemId)
|
{
|
OnPackageRefresh(_type);
|
}
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if (id == (int)FuncOpenEnum.BlastFurnace && FuncOpen.Instance.IsFuncOpen(id))
|
{
|
if (isServerPrepare)
|
{
|
RecommandAlchemyStudyItems();
|
RecommandAlchemyDrugs();
|
}
|
}
|
}
|
|
private bool FindLatestItem(out PreciousItem _item)
|
{
|
string guid;
|
if (itemExpGuids.Count == 0)
|
{
|
if (itemGuids.Count == 0)
|
{
|
_item = default(PreciousItem);
|
return false;
|
}
|
else
|
guid = itemGuids[itemGuids.Count - 1];
|
|
}
|
else
|
guid = itemExpGuids[itemExpGuids.Count - 1];
|
|
|
_item = itemStack[guid];
|
return true;
|
}
|
|
private void RecommandAlchemyDrugs()
|
{
|
var items = playerPack.GetItems(PackType.Item, new SinglePack.FilterParams());
|
if (items != null)
|
{
|
foreach (var item in items)
|
{
|
var config = AttrFruitConfig.Get(item.itemId);
|
if (config != null && config.FuncID == 2)
|
{
|
ItemLogicUtility.Instance.RecommendItem(item);
|
}
|
}
|
}
|
}
|
|
private void RecommandAlchemyStudyItems()
|
{
|
var items = playerPack.GetItems(PackType.Item, new SinglePack.FilterParams()
|
{
|
itemTypes = new List<int>() { 55 },
|
});
|
if (items != null)
|
{
|
foreach (var item in items)
|
{
|
ItemLogicUtility.Instance.RecommendItem(item);
|
}
|
}
|
}
|
|
private void Trim()
|
{
|
for (int i = itemExpGuids.Count - 1; i >= 0; i--)
|
{
|
var item = itemStack[itemExpGuids[i]];
|
if (playerPack.GetItemByGuid(item.guid) == null
|
|| playerPack.GetItemByGuid(item.guid).packType != PackType.Item)
|
{
|
itemExpGuids.RemoveAt(i);
|
}
|
}
|
|
for (int i = itemGuids.Count - 1; i >= 0; i--)
|
{
|
var item = itemStack[itemGuids[i]];
|
if (playerPack.GetItemByGuid(item.guid) == null
|
|| playerPack.GetItemByGuid(item.guid).packType != PackType.Item)
|
{
|
itemGuids.RemoveAt(i);
|
}
|
}
|
}
|
|
private void RefreshCurrrentShowPreciousItem()
|
{
|
Trim();
|
|
PreciousItem tempItem;
|
if (FindLatestItem(out tempItem))
|
{
|
if (tempItem != currentShowItem)
|
{
|
currentShowItem = tempItem;
|
}
|
}
|
else
|
{
|
currentShowItem = default(PreciousItem);
|
}
|
|
if (showItemRefreshEvent != null)
|
{
|
isGetNewItem = true;
|
showItemRefreshEvent();
|
}
|
}
|
|
public bool ShowPreciousItemAble()
|
{
|
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;
|
}
|
}
|
|
public struct PreciousItem
|
{
|
public PackType packType;
|
public string guid;
|
|
public PreciousItem(PackType _packType, string _guid)
|
{
|
this.packType = _packType;
|
this.guid = _guid;
|
}
|
|
public static bool operator ==(PreciousItem _lhs, PreciousItem _rhs)
|
{
|
return _lhs.packType == _rhs.packType && _lhs.guid == _rhs.guid;
|
}
|
|
public static bool operator !=(PreciousItem _lhs, PreciousItem _rhs)
|
{
|
return _lhs.packType != _rhs.packType || _lhs.guid != _rhs.guid;
|
}
|
|
|
}
|
|
}
|
|
}
|
|
|
|