/// <summary> /// 尝试获取各背包中的空位置 /// </summary> /// <param name="pType"></param> /// <param name="pileLocation"></param> /// <returns></returns> public bool TryGetPileGridInPackage(uint qwThisId, out uint targetQwThisID, GameCmd.PACKAGETYPE pType, out uint pileLocation) { pileLocation = 0; targetQwThisID = 0; bool success = false; BaseItem baseItem = DataManager.Manager <ItemManager>().GetBaseItemByQwThisId <BaseItem>(qwThisId); if (null == baseItem || !baseItem.CanPile || !(pType == PACKAGETYPE.PACKAGETYPE_MAIN || IsWareHosue(pType))) { return(success); } List <BaseItem> items = DataManager.Manager <ItemManager>().GetItemByBaseId(baseItem.BaseId, pType); uint pileNum = baseItem.MaxPileNum; if (null != items) { for (int i = 0, max = items.Count; i < max; i++) { if (baseItem.Num + items[i].Num <= pileNum) { pileLocation = items[i].ServerLocaltion; targetQwThisID = items[i].QWThisID; success = true; break; } } } return(success); }
/// <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); } }
public void Reset(bool depthClearData = false) { if (depthClearData) { wareHouseStoreCopperNum = 0; m_localUnlockInfo.Clear(); storageType = GameCmd.PACKAGETYPE.PACKAGETYPE_MAIN; m_dicTidyCD.Clear(); m_IsNetWorkClose = false; } }
public bool IsTidyCD(GameCmd.PACKAGETYPE pType) { long lastTidyTime = 0; if (m_dicTidyCD.TryGetValue(pType, out lastTidyTime) && DateTimeHelper.Instance.Now - lastTidyTime < TidyCDTime) { return(true); } return(false); }
/// <summary> /// 记录上一次整理时间 /// </summary> /// <param name="pType"></param> public void DoTidyCDRecord(GameCmd.PACKAGETYPE pType) { if (!m_dicTidyCD.ContainsKey(pType)) { m_dicTidyCD.Add(pType, DateTimeHelper.Instance.Now); } else { m_dicTidyCD[pType] = DateTimeHelper.Instance.Now; } }
/// <summary> /// 整理背包 /// </summary> /// <param name="pType">背包类型</param> public void Tidy(GameCmd.PACKAGETYPE pType = GameCmd.PACKAGETYPE.PACKAGETYPE_MAIN) { if (IsTidyCD(pType)) { TipsManager.Instance.ShowTips("整理功能冷却中,请稍后再试!"); return; } if (null != DataManager.Instance.Sender) { DataManager.Instance.Sender.TidyRequest(pType); } }
/// <summary> /// 整理 /// </summary> /// <param name="pType"></param> public void OnTidy(GameCmd.PACKAGETYPE pType) { if (pType != PACKAGETYPE.PACKAGETYPE_MAIN && pType != PACKAGETYPE.PACKAGETYPE_STORE1 && pType != PACKAGETYPE.PACKAGETYPE_STORE2 && pType != PACKAGETYPE.PACKAGETYPE_STORE3) { return; } TipsManager.Instance.ShowTips("整理完成"); DoTidyCDRecord(pType); }
/// <summary> /// 移动列表到目标背包中 /// </summary> /// <param name="moveList">需要移动的物品列表</param> /// <param name="targetPackage">目标背包</param> public void MoveItems(List <uint> moveList, GameCmd.PACKAGETYPE targetPackage) { if (null == moveList || moveList.Count == 0) { return; } for (int i = 0; i < moveList.Count; i++) { if (moveList[i] == 0) { continue; } MoveItems(moveList[i], targetPackage); } }
/// <summary> /// 尝试获取各背包中的空位置 /// </summary> /// <param name="pType"></param> /// <param name="emptyLocation"></param> /// <returns></returns> public bool TryGetEmptyGridInPackage(GameCmd.PACKAGETYPE pType, out uint emptyLocation) { emptyLocation = 0; if (!(pType == PACKAGETYPE.PACKAGETYPE_MAIN || IsWareHosue(pType))) { return(false); } List <uint> emptyList = GetEmptyGridInPackage(pType); if (null != emptyList && emptyList.Count != 0) { emptyLocation = emptyList[0]; return(true); } return(false); }
/// <summary> /// 移动物品到目标背包2 /// </summary> /// <param name="qwThisId"></param> /// <param name="targetPackage"></param> public void MoveItems(uint qwThisId, GameCmd.PACKAGETYPE targetPackage) { uint targetLocation = 0; BaseItem data = DataManager.Manager <ItemManager>().GetBaseItemByQwThisId(qwThisId); if (null == data) { Engine.Utility.Log.Error(CLASS_NAME + "-> Fail move item={0} to {1} data null", qwThisId, targetPackage.ToString()); return; } uint targetQwThisID = 0; if (TryGetPileGridInPackage(qwThisId, out targetQwThisID, targetPackage, out targetLocation) || TryGetEmptyGridInPackage(targetPackage, out targetLocation)) { DataManager.Instance.Sender.SwapItemReq(data.QWThisID, targetQwThisID, new tItemLocation() { loc = data.ServerLocaltion, }, new tItemLocation() { loc = targetLocation, }); } else { if (targetPackage == PACKAGETYPE.PACKAGETYPE_STORE1 || targetPackage == PACKAGETYPE.PACKAGETYPE_STORE2 || targetPackage == PACKAGETYPE.PACKAGETYPE_STORE3) { TipsManager.Instance.ShowTips("仓库已满"); } else if (targetPackage == PACKAGETYPE.PACKAGETYPE_MAIN) { TipsManager.Instance.ShowTips("背包空间不足,无法取出"); } } }
/// <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> /// <param name="pType"></param> /// <returns></returns> public List <uint> GetEmptyGridInPackage(GameCmd.PACKAGETYPE pType) { List <uint> emptyGridPosList = new List <uint>(); int max = GetUnlockGridByPackageType(pType); List <uint> itemsInPackage = DataManager.Manager <ItemManager>().GetItemDataByPackageType(pType); BaseItem data = null; uint tempLocation = 0; for (int i = 0; i < max; i++) { data = null; tempLocation = ItemDefine.TransformLocal2ServerLocation(pType, new UnityEngine.Vector2(0f, i)); if (null != itemsInPackage && itemsInPackage.Count > 0) { uint matchId = 0; for (int j = 0; j < itemsInPackage.Count; j++) { matchId = 0; data = DataManager.Manager <ItemManager>().GetBaseItemByQwThisId(itemsInPackage[j]); if (null != data && data.ServerLocaltion == tempLocation) { matchId = data.QWThisID; break; } } if (matchId != 0) { itemsInPackage.Remove(matchId); continue; } } emptyGridPosList.Add(tempLocation); } return(emptyGridPosList); }
/// <summary> /// 获取解锁花费描述 /// </summary> /// <param name="pType"></param> /// <param name="needUnlockNum"></param> /// <returns></returns> public string GetUnlockGridCostString(GameCmd.PACKAGETYPE pType, int needUnlockNum) { Dictionary <uint, uint> costDic = GetUnlockGridCost(pType, needUnlockNum); if (null == costDic || costDic.Count == 0) { return(string.Empty); } StringBuilder builder = new StringBuilder(); List <uint> moneyType = new List <uint>(); moneyType.AddRange(costDic.Keys); moneyType.Sort((left, right) => { return((int)right - (int)left); }); for (int i = 0; i < moneyType.Count; i++) { builder.Append(string.Format("{0}{1}" , costDic[moneyType[i]] , DataManager.Manager <TextManager>().GetCurrencyNameByType((MoneyType)moneyType[i]))); } return(builder.ToString()); }
/// <summary> /// 获取背包剩余空间 /// </summary> /// <param name="pType">背包类型 (默认为主背包)</param> /// <returns></returns> public int GetKnapsackEmptyGrid(GameCmd.PACKAGETYPE pType = PACKAGETYPE.PACKAGETYPE_MAIN) { List <uint> emptyList = GetEmptyGridInPackage(pType); return((null != emptyList) ? emptyList.Count : 0); }
/// <summary> /// pType是否为仓库 /// </summary> /// <param name="pType"></param> /// <returns></returns> public bool IsWareHosue(GameCmd.PACKAGETYPE pType) { return(pType == PACKAGETYPE.PACKAGETYPE_STORE1 || pType == PACKAGETYPE.PACKAGETYPE_STORE2 || pType == PACKAGETYPE.PACKAGETYPE_STORE3); }
/// <summary> /// 获取背包初始解锁数量 /// </summary> /// <param name="pType"></param> /// <returns></returns> public int GetInitGridByPackageType(GameCmd.PACKAGETYPE pType) { table.UnlockStoreDataBase firstData = GetUnlockStoreDataBase((uint)pType, 0); return((int)((null != firstData) ? firstData.initNum : 0)); }
/// <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); }