using System; using LitJson; using System.Collections.Generic; namespace vnxbqy.UI { public class BoxGetItemModel : Model, IBeforePlayerDataInitialize { public string guid { get; private set; } public int itemId { get; private set; } PackModel playerPack { get { return ModelCenter.Instance.GetModel(); } } public Dictionary selectDict; public override void Init() { } void IBeforePlayerDataInitialize.OnBeforePlayerDataInitialize() { 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 RefreshGetItemAct; public void SetGetBoxItemInfo(HA810_tagMCNotifyUseItemGetItem boxItemInfo) { getItems = JsonMapper.ToObject(boxItemInfo.GetItemData); getCoinsType = boxItemInfo.MoneyType; getCoinsCnt = boxItemInfo.MoneyCount; if (!NewBieCenter.Instance.inGuiding) { List items = new List(); for (int i = 0; i < getItems.Length; i++) { BoxGetItemInfo info = getItems[i]; Dictionary> useDataDic = ConfigParse.Analysis(info.UserData); if (useDataDic != null && useDataDic.TryGetValue((int)ItemUseDataKey.itemCount, out List list) && list != null && list.Count > 0) { int count = list[0]; items.Add(new Item(info.ItemID, count)); } else { items.Add(new Item(info.ItemID, info.Count)); } } ItemLogicUtility.Instance.ShowGetItem(items, seconds: 0); } if (RefreshGetItemAct != null) { RefreshGetItemAct((int)boxItemInfo.UseItemID, (int)boxItemInfo.UseCount, getItems); } } public int GetUseCntByID(int itemId) { return playerPack.GetItemUsedTimesToday(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) { ModelCenter.Instance.GetModel().OpenChooseItemsWin(); //if (!WindowCenter.Instance.IsOpen()) //{ // WindowCenter.Instance.Open(); //} return; } ItemOperateUtility.Instance.UseItem(guid, 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> jobReplaceDic = new Dictionary>(); Dictionary selectlistDict = null; public bool IsSelectItemByID(int boxId, out Dictionary selectDict) { selectDict = new Dictionary(); jobReplaceDic.Clear(); ChestsAwardConfig awardConfig = ChestsAwardConfig.GetChestsAwardByID(boxId); if (string.IsNullOrEmpty(awardConfig.SelectList)) { return false; } else { selectlistDict = ConfigParse.GetDic(awardConfig.SelectList); JsonData jsonData = JsonMapper.ToObject(awardConfig.JobItem); if (jsonData.IsArray) { for (int i = 0; i < jsonData.Count; i++) { List idlist = new List(); 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.GetItemByGuid(guid); if (itemModel == null) return; ulong maxValue = 0; playerPack.IsReachUseLimit(guid, out maxValue); if (itemModel.config.BatchUse != 0 && maxValue > 1) { BatchUseModel.Instance.SetBatchModel(itemModel.guid); WindowCenter.Instance.Open(); return; } 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; } }