using System;
|
using LitJson;
|
|
using System.Collections.Generic;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class BoxGetItemModel : Model,IBeforePlayerDataInitialize
|
{
|
public string guid { get; private set; }
|
public int itemId { get; private set;}
|
public BoxShowType showType { get; private set; }
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
public Dictionary<int, int> selectDict;
|
|
public override void Init()
|
{
|
|
}
|
|
void IBeforePlayerDataInitialize.OnBeforePlayerDataInitialize()
|
{
|
showType = BoxShowType.NoShow;
|
selectDict = null;
|
guid = "";
|
getItems = null;
|
getCoinsType = 0;
|
getCoinsCnt = 0;
|
}
|
|
#region 处理服务器数据
|
|
public BoxGetItemInfo[] getItems { get; private set;}
|
public int getCoinsType { get; private set; }
|
public long getCoinsCnt { get; private set; }
|
public event Action<int,int,BoxGetItemInfo[]> RefreshGetItemAct;
|
public void SetGetBoxItemInfo(HA810_tagMCNotifyUseItemGetItem boxItemInfo)
|
{
|
getItems = JsonMapper.ToObject<BoxGetItemInfo[]>(boxItemInfo.GetItemData);
|
getCoinsType = boxItemInfo.MoneyType;
|
getCoinsCnt = boxItemInfo.MoneyCount;
|
if(!NewBieCenter.Instance.inGuiding)
|
{
|
switch (showType)
|
{
|
case BoxShowType.NoramalShow:
|
if (!WindowCenter.Instance.IsOpen<BoxGetItemWin>())
|
{
|
WindowCenter.Instance.Open<BoxGetItemWin>();
|
}
|
break;
|
case BoxShowType.PrefectShow:
|
if (!WindowCenter.Instance.IsOpen<BoxGetItemWin>())
|
{
|
WindowCenter.Instance.Open<BoxGetItemWin>();
|
}
|
break;
|
}
|
}
|
|
if (RefreshGetItemAct != null)
|
{
|
RefreshGetItemAct((int)boxItemInfo.UseItemID,(int)boxItemInfo.UseCount,getItems);
|
}
|
|
|
}
|
|
public int GetUseCntByID(int itemId)
|
{
|
return playerPack.GetDayUseCntByID(itemId);
|
}
|
|
#endregion
|
|
public void SetModel(string guid,int itemId)
|
{
|
ChestsConfig chestsConfig = ChestsConfig.Get(itemId);
|
this.guid = guid;
|
this.itemId = itemId;
|
if (guid == "" || chestsConfig == null) return;
|
|
ItemConfig boxConfig = ItemConfig.Get(itemId);
|
if(PlayerDatas.Instance.baseData.LV < boxConfig.UseLV)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("MakeUseItem101",boxConfig.UseLV));
|
return;
|
}
|
|
CheckBoxShowType(chestsConfig.OpenShow, guid);
|
}
|
|
public void CheckOpenBoxCondi(string guid, int itemId,int useCnt = 1)
|
{
|
ChestsConfig chestsConfig = ChestsConfig.Get(itemId);
|
if (chestsConfig == null) return;
|
|
ItemConfig boxConfig = ItemConfig.Get(itemId);
|
|
if (chestsConfig.ExpendItemID != 0)
|
{
|
ItemConfig itemConfig = ItemConfig.Get(chestsConfig.ExpendItemID);
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("OpenBoxTool", itemConfig.ItemName), (bool isOk) =>
|
{
|
if (isOk)
|
{
|
if (!IsEnoughTools(chestsConfig.ExpendItemID, chestsConfig.ExpendCount*useCnt))
|
{
|
SysNotifyMgr.Instance.ShowTip("OpenBoxToolNoEnough", itemConfig.ItemName);
|
return;
|
}
|
else
|
{
|
CheckOpenMoney(chestsConfig, boxConfig,useCnt);
|
}
|
}
|
});
|
}
|
else
|
{
|
CheckOpenMoney(chestsConfig, boxConfig,useCnt);
|
}
|
}
|
|
public void CheckOpenMoney(ChestsConfig chestsConfig, ItemConfig boxConfig,int useCnt)
|
{
|
if (!IsEnoughMoney(chestsConfig.OpenMoney*useCnt))
|
{
|
SysNotifyMgr.Instance.ShowTip("BoxOpenCostMoney", 1);
|
return;
|
}
|
else
|
{
|
if (chestsConfig.OpenMoney > 0)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("OpenBoxGold", chestsConfig.OpenMoney*useCnt), (bool isOk) =>
|
{
|
if (isOk)
|
{
|
CheckOtherCondi(chestsConfig,boxConfig,useCnt);
|
}
|
});
|
}
|
else
|
{
|
CheckOtherCondi(chestsConfig, boxConfig,useCnt);
|
}
|
}
|
}
|
|
public void CheckOtherCondi(ChestsConfig chestsConfig,ItemConfig boxConfig,int useCnt)
|
{
|
|
if (boxConfig.MaxSkillCnt > 0 && GetUseCntByID(itemId) >= boxConfig.MaxSkillCnt)
|
{
|
SysNotifyMgr.Instance.ShowTip("UseCntLimit");
|
return;
|
}
|
|
selectDict = null;
|
bool isSelectItem = IsSelectItemByID(itemId, out selectDict);
|
if (isSelectItem)
|
{
|
if (!WindowCenter.Instance.IsOpen<ChooseItemWin>())
|
{
|
WindowCenter.Instance.Open<ChooseItemWin>();
|
}
|
return;
|
}
|
|
ItemModel itemModel = playerPack.GetItemModelByGUID(guid);
|
if (itemModel != null)
|
{
|
ItemOperateUtility.Instance.UseItem(itemModel.itemPlace,useCnt);
|
}
|
}
|
|
public bool CheckOpenBoxCondition(int itemId,out bool isBox)
|
{
|
isBox = false;
|
ChestsConfig chestsConfig = ChestsConfig.Get(itemId);
|
if (chestsConfig == null) return false;
|
|
isBox = true;
|
bool isCanOpen = true;
|
ItemConfig boxConfig = ItemConfig.Get(itemId);
|
if (PlayerDatas.Instance.baseData.LV < boxConfig.UseLV)
|
{
|
isCanOpen = false;
|
return isCanOpen;
|
}
|
|
if (chestsConfig.ExpendItemID != 0)
|
{
|
ItemConfig itemConfig = ItemConfig.Get(chestsConfig.ExpendItemID);
|
if (!IsEnoughTools(chestsConfig.ExpendItemID, chestsConfig.ExpendCount))
|
{
|
isCanOpen = false;
|
return isCanOpen;
|
}
|
}
|
|
if (!IsEnoughMoney(chestsConfig.OpenMoney))
|
{
|
isCanOpen = false;
|
return isCanOpen;
|
}
|
|
if (boxConfig.MaxSkillCnt > 0 && GetUseCntByID(itemId) >= boxConfig.MaxSkillCnt)
|
{
|
isCanOpen = false;
|
return isCanOpen;
|
}
|
|
return isCanOpen;
|
}
|
|
private bool IsEnoughMoney(int moneyCnt)
|
{
|
ulong haveMoney = UIHelper.GetMoneyCnt(1);
|
DebugEx.Log("IsEnoughMoney" + haveMoney);
|
if(haveMoney >= (ulong)moneyCnt)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
private bool IsEnoughTools(int itemId,int toolCnt)
|
{
|
int count = playerPack.GetItemCountByID(PackType.Item,itemId);
|
if(count >= toolCnt)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
}
|
|
#region 得到宝箱选择的物品
|
Dictionary<int, List<int>> jobReplaceDic = new Dictionary<int, List<int>>();
|
Dictionary<int, int> selectlistDict = null;
|
public bool IsSelectItemByID(int boxId,out Dictionary<int,int> selectDict)
|
{
|
selectDict = new Dictionary<int, int>();
|
jobReplaceDic.Clear();
|
ChestsAwardConfig awardConfig = ChestsAwardConfig.GetChestsAwardByID(boxId);
|
if(string.IsNullOrEmpty(awardConfig.SelectList))
|
{
|
return false;
|
}
|
else
|
{
|
selectlistDict = ConfigParse.GetDic<int, int>(awardConfig.SelectList);
|
JsonData jsonData = JsonMapper.ToObject(awardConfig.JobItem);
|
if(jsonData.IsArray)
|
{
|
for(int i = 0; i < jsonData.Count; i++)
|
{
|
List<int> idlist = new List<int>();
|
jobReplaceDic.Add(i,idlist);
|
if(jsonData[i].IsArray)
|
{
|
for(int j = 0;j < jsonData[i].Count; j++)
|
{
|
int itemId = int.Parse(jsonData[i][j].ToString());
|
idlist.Add(itemId);
|
}
|
}
|
}
|
}
|
|
foreach(var itemId in selectlistDict.Keys)
|
{
|
int id = itemId;
|
foreach(var index in jobReplaceDic.Keys)
|
{
|
if(jobReplaceDic[index].Contains(itemId))
|
{
|
int replaceIndex = PlayerDatas.Instance.baseData.Job - 1;
|
id = jobReplaceDic[index][replaceIndex];
|
break;
|
}
|
}
|
selectDict.Add(id,selectlistDict[itemId]);
|
}
|
|
return true;
|
}
|
|
}
|
#endregion
|
|
private void CheckBoxShowType(int openShow,string guid)
|
{
|
ItemModel itemModel = playerPack.GetItemModelByGUID(guid);
|
if (itemModel == null) return;
|
|
switch ((BoxShowType)openShow)
|
{
|
case BoxShowType.NoShow:
|
showType = BoxShowType.NoShow;
|
ulong maxValue = 0;
|
playerPack.IsReachUseLimit(guid, out maxValue);
|
if (itemModel.config.BatchUse != 0 && maxValue > 1)
|
{
|
BatchUseModel.Instance.SetBatchModel(itemModel.guid);
|
WindowCenter.Instance.Open<BatchWin>();
|
return;
|
}
|
break;
|
case BoxShowType.NoramalShow:
|
showType = BoxShowType.NoramalShow;
|
break;
|
case BoxShowType.PrefectShow:
|
showType = BoxShowType.PrefectShow;
|
break;
|
}
|
CheckOpenBoxCondi(guid, itemModel.itemId);
|
}
|
|
|
public override void UnInit()
|
{
|
|
}
|
|
}
|
|
public enum BoxShowType
|
{
|
NoShow = 0, //无展示
|
NoramalShow = 1, //普通展现
|
PrefectShow = 2, // 有特效+展示
|
}
|
|
public class BoxGetItemInfo
|
{
|
public int ItemID;
|
public int Count;
|
public int IsBind;
|
public int IsSuite;
|
public string UserData;
|
}
|
}
|