/// <summary> /// 同步背包解锁格子 /// </summary> /// <param name="unlockInfos"></param> public void OnSycnUnlockKnapsackGrid(List <UnlockInfo> unlockInfos) { if (null == unlockInfos || unlockInfos.Count == 0) { Engine.Utility.Log.Error(CLASS_NAME + "->OnSycnUnlockKnapsackGrid failed,unlockinfo null"); return; } m_localUnlockInfo.Clear(); //获取上一次解锁格子数量(用于刷新UI) KnapsackDefine.LocalUnlockInfo localUnlockInfo = null; foreach (UnlockInfo info in unlockInfos) { if (m_localUnlockInfo.ContainsKey(info.type)) { Engine.Utility.Log.Error(CLASS_NAME + "->OnSycnUnlockKnapsackGrid Error,already exist unlockinfo with packageType = {0}", ((PACKAGETYPE)info.type).ToString()); continue; } localUnlockInfo = KnapsackDefine.LocalUnlockInfo.Create((GameCmd.PACKAGETYPE)info.type, info); if (null == localUnlockInfo) { continue; } m_localUnlockInfo.Add(info.type, localUnlockInfo); //刷新UI Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENT_KNAPSACKUNLOCKINFOCHANGED, new UnlockPassData() { Type = info.type, IsReconnect = m_IsNetWorkClose, }); } m_IsNetWorkClose = false; }
/// <summary> /// 仓库格子点击实现 /// </summary> /// <param name="eventType"></param> /// <param name="data"></param> /// <param name="param"></param> public void OnWareHouseGridUIEvent(UIEventType eventType, object data, object param) { switch (eventType) { case UIEventType.Click: { if (data is UIItemGrid) { UIItemGrid grid = data as UIItemGrid; if (!grid.Empty) { DataManager.Manager <KnapsackManager>().MoveItems(grid.Data.QWThisID, GameCmd.PACKAGETYPE.PACKAGETYPE_MAIN); } else if (grid.IsLock) { KnapsackDefine.LocalUnlockInfo unlcokInfo = m_kmgr.GetUnlockInfoByPackageType(m_em_activeWareHouse); int unlockNum = ((int)ItemDefine.TransformServerLocation2Local(grid.Location).Position.y + 1) - unlcokInfo.UnlockNum; if (unlockNum == 0) { Engine.Utility.Log.Warning(CLASS_NAME + "-> unlock grid failed,num = {0} data error!", unlockNum); return; } //解锁格子 DoUnlocKnapsackGrid(unlockNum, m_em_activeWareHouse); } } else if (data is UITabGrid) { UITabGrid tabGrid = data as UITabGrid; KnapsackDefine.LocalUnlockInfo localInfo = m_kmgr.GetUnlockInfoByPackageType((GameCmd.PACKAGETYPE)tabGrid.Data); if (null != localInfo && localInfo.IsUnlock) { SetWareHousePackage((GameCmd.PACKAGETYPE)tabGrid.Data); } else { TipsManager.Instance.ShowTips("购买皇令解锁仓库"); } } } break; case UIEventType.LongPress: { if (data is UIItemGrid) { UIItemGrid grid = data as UIItemGrid; if (!grid.Empty) { imgr.OnUIItemGridClicked(grid.Data.QWThisID); } } } break; } }
private void UpdateWareHouseStatus() { if (!IsInitMode(KnapsackStatus.WareHouse)) { return; } if (IsKnapsackStatus(KnapsackStatus.WareHouseNPC) || IsKnapsackStatus(KnapsackStatus.WareHouse)) { if (null != m_dic_wareHouseTabs) { UITabGrid tab = null; KnapsackDefine.LocalUnlockInfo localInfo = null; GameObject obj = null; bool visible = false; if (m_dic_wareHouseTabs.TryGetValue(GameCmd.PACKAGETYPE.PACKAGETYPE_STORE1, out tab)) { obj = tab.CacheTransform.Find("Content/Toggle/Lock").gameObject; if (null != obj) { localInfo = m_kmgr.GetUnlockInfoByPackageType(GameCmd.PACKAGETYPE.PACKAGETYPE_STORE1); visible = (null != localInfo) ? localInfo.IsUnlock : false; if (obj.activeSelf == visible) { obj.SetActive(!visible); } } } if (m_dic_wareHouseTabs.TryGetValue(GameCmd.PACKAGETYPE.PACKAGETYPE_STORE2, out tab)) { obj = tab.CacheTransform.Find("Content/Toggle/Lock").gameObject; if (null != obj) { localInfo = m_kmgr.GetUnlockInfoByPackageType(GameCmd.PACKAGETYPE.PACKAGETYPE_STORE2); visible = (null != localInfo) ? localInfo.IsUnlock : false; if (obj.activeSelf == visible) { obj.SetActive(!visible); } } } if (m_dic_wareHouseTabs.TryGetValue(GameCmd.PACKAGETYPE.PACKAGETYPE_STORE3, out tab)) { obj = tab.CacheTransform.Find("Content/Toggle/Lock").gameObject; if (null != obj) { localInfo = m_kmgr.GetUnlockInfoByPackageType(GameCmd.PACKAGETYPE.PACKAGETYPE_STORE3); visible = (null != localInfo) ? localInfo.IsUnlock : false; if (obj.activeSelf == visible) { obj.SetActive(!visible); } } } } } }
/// <summary> /// 解锁长裤 /// </summary> /// <param name="wareHouse"></param> private void UnlockWareHouse(GameCmd.PACKAGETYPE wareHouse) { KnapsackDefine.LocalUnlockInfo info = null; if (null != m_localUnlockInfo && m_localUnlockInfo.TryGetValue((uint)wareHouse, out info)) { info.IsUnlock = true; Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENT_UNLOCKWAREHOSUE, wareHouse); } }
/// <summary> /// 更新容量 /// </summary> private void UpdateWareHouseCapcity() { if (null != m_label_WareHouseCapacityNum) { KnapsackDefine.LocalUnlockInfo wareHouseUnlockInfo = m_kmgr.GetUnlockInfoByPackageType(m_em_activeWareHouse); if (null == wareHouseUnlockInfo) { return; } int mainPackMaxGridHave = m_kmgr.GetMaxGridHaveByPackageType(m_em_activeWareHouse); int unlockNum = wareHouseUnlockInfo.UnlockNum; m_label_WareHouseCapacityNum.text = string.Format("{0}/{1}", unlockNum, mainPackMaxGridHave); } }
/// <summary> /// 解锁背包格子回调 /// </summary> /// <param name="num">解锁数量</param> /// <param name="pType">背包类型</param> public void OnUnlockKnapsackGrid(uint num, uint pType) { KnapsackDefine.LocalUnlockInfo info = null; if (!m_localUnlockInfo.TryGetValue(pType, out info)) { Engine.Utility.Log.Error("Unlock Info Error"); return; } int oldCount = info.UnlockNum; info.UnlockNum = (int)(oldCount + num); //刷新UI Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENT_KNAPSACKUNLOCKINFOCHANGED, new UnlockPassData() { Type = pType, }); }
/// <summary> /// 当前背包位置是否已经解锁 /// </summary> /// <param name="location">服务端中背包位置</param> /// <returns></returns> public bool IsGridUnlock(uint location) { ItemDefine.ItemLocation itemLocation = ItemDefine.TransformServerLocation2Local(location); if (null == itemLocation || !(itemLocation.PackType == PACKAGETYPE.PACKAGETYPE_MAIN || IsWareHosue(itemLocation.PackType))) { //不是背包,仓库忽略 return(false); } KnapsackDefine.LocalUnlockInfo localUnlockInfo = GetUnlockInfoByPackageType(itemLocation.PackType); if (null == localUnlockInfo) { Engine.Utility.Log.Error("GetUnlockInfoByPackageType null ,packtype = {0}", itemLocation.PackType); return(false); } int packUnlockGrid = localUnlockInfo.UnlockNum; uint maxLocation = ItemDefine.TransformLocal2ServerLocation(itemLocation.PackType, new UnityEngine.Vector2(0f, Math.Max(packUnlockGrid - 1, 0))); return((maxLocation >= location && packUnlockGrid != 0) ? true : false); }
/// <summary> /// 获取解锁背包格消耗钱币 /// </summary> /// <param name="pType">背包类型</param> /// <param name="needUnlockNum">当前需要解锁的数量</param> /// <returns></returns> public Dictionary <uint, uint> GetUnlockGridCost(GameCmd.PACKAGETYPE pType, int needUnlockNum) { Dictionary <uint, uint> costDic = new Dictionary <uint, uint>(); if (needUnlockNum <= 0) { return(costDic); } KnapsackDefine.LocalUnlockInfo unlockInfo = GetUnlockInfoByPackageType(pType); int initNum = GetInitGridByPackageType(pType); if (null != unlockInfo) { if (unlockInfo.UnlockNum - initNum >= 0) { int startIndex = unlockInfo.UnlockNum - initNum + 1; uint cost = 0; table.UnlockStoreDataBase storeTableData = null; for (int i = startIndex; i < startIndex + needUnlockNum; i++) { storeTableData = GetUnlockStoreDataBase((uint)pType, i); if (null != storeTableData) { if (costDic.ContainsKey(storeTableData.moneyType)) { costDic[storeTableData.moneyType] += storeTableData.moneyNum; } else { costDic.Add(storeTableData.moneyType, storeTableData.moneyNum); } } } } } return(costDic); }
/// <summary> /// 刷新仓库 /// </summary> private void CreateWareHouse() { if (!(IsInitMode(KnapsackStatus.WareHouse) || IsInitMode(KnapsackStatus.WareHouseNPC)) || null == m_ctor_WareHouseItemGridScrollView) { return; } wareHouseItems.Clear(); List <uint> wareHouseItemDatas = imgr.GetItemDataByPackageType(m_em_activeWareHouse); Dictionary <uint, uint> gridDataDic = new Dictionary <uint, uint>(); BaseItem data = null; if (null != wareHouseItemDatas && wareHouseItemDatas.Count > 0) { for (int i = 0; i < wareHouseItemDatas.Count; i++) { data = imgr.GetBaseItemByQwThisId(wareHouseItemDatas[i]); if (null == data || data.Num == 0) { continue; } if (gridDataDic.ContainsKey(data.ServerLocaltion)) { Engine.Utility.Log.Warning(CLASS_NAME + "->CreateItemDataUI add to temp Dic Faield,Have same key = {0}", data.QWThisID); continue; } else { gridDataDic.Add(data.ServerLocaltion, data.QWThisID); } } } //重新构建格子列表 KnapsackDefine.LocalUnlockInfo wareHouseUnlockInfo = m_kmgr.GetUnlockInfoByPackageType(m_em_activeWareHouse); if (null == wareHouseUnlockInfo) { Engine.Utility.Log.Error("CreateWareHouse failed,wareHouseUnlockInfo null"); m_ctor_WareHouseItemGridScrollView.CreateGrids(0); return; } int mainPackMaxGridHave = m_kmgr.GetMaxGridHaveByPackageType(m_em_activeWareHouse); int max = wareHouseUnlockInfo.UnlockNum; int mod = max % KnapsackManager.KNAPSACK_GRID_COLUMN_MAX; int lockNum = ((mod != 0) ? (KnapsackManager.KNAPSACK_GRID_COLUMN_MAX * 2 - mod) : KnapsackManager.KNAPSACK_GRID_COLUMN_MAX); lockNum = Math.Min(lockNum, mainPackMaxGridHave - max); uint combineLocation = 0; int needNum = max + lockNum; if (needNum < 25) { needNum = 25; } for (int i = 0; i < needNum; i++) { combineLocation = ItemDefine.TransformLocal2ServerLocation(m_em_activeWareHouse, new Vector2(0, i)); wareHouseItems.Add((gridDataDic.ContainsKey(combineLocation)) ? gridDataDic[combineLocation] : 0); } //创建格子数据 m_ctor_WareHouseItemGridScrollView.CreateGrids(wareHouseItems.Count); UpdateWareHouseStatus(); if (m_dic_cacheOldUnlock.ContainsKey(m_em_activeWareHouse)) { m_dic_cacheOldUnlock[m_em_activeWareHouse] = wareHouseUnlockInfo.UnlockNum; } else { m_dic_cacheOldUnlock.Add(m_em_activeWareHouse, wareHouseUnlockInfo.UnlockNum); } }
/// <summary> /// 获取pType背包等级解锁的格子数量 /// </summary> /// <param name="pType"></param> /// <returns></returns> public int GetLevelUnlockGridByPackType(GameCmd.PACKAGETYPE pType) { KnapsackDefine.LocalUnlockInfo info = GetUnlockInfoByPackageType(pType); return((null != info) ? info.LvUnlockNum : 0); }