using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using LitJson;
|
using System.Collections;
|
using System.IO;
|
|
public class PackManager : GameSystemManager<PackManager>
|
{
|
public event Action<PackType> refrechPackEvent; //刷新整个背包数据
|
|
//物品(创建)刷新,可能批量创建注意效率; bool:true代表创建 false 刷新; 注意0707物品数量刷新不包含在此事件
|
public event Action<PackType, string, bool> ChangeItemEvent; // 背包类型,GUID,是否创建
|
|
//删除物品,可能批量删除注意效率
|
public event Action<PackType, string, int, int, int> DeleteItemEvent; // 背包类型,GUID, 物品ID,索引, 删除原因
|
|
// 单物品刷新 在得到新物品、物品数量的改变,清理该物品时均会触发 ; 但0725整个背包刷新不触发,如果有需要单独数量刷新事件另外处理
|
// 触发比较频繁,界面使用时可以做个汇总后延迟刷新
|
public event Action<PackType, int, int> RefreshItemEvent; //背包类型,位置索引,物品id
|
public event Action<PackType> gridRefreshEvent; //背包可用格子数刷新
|
public event Action<int, int> useItemSuccessEvent; //物品使用成功 int 位置索引 int物品id
|
|
public event Action<int> refreshItemDayUseCountEvent; //刷新物品每日使用数量
|
public event Action<int> refreshItemSumUseCountEvent; //刷新物品总使用数量
|
public event Action<PackType, string, bool> RefreshItemLockEvent; //物品锁定刷新 背包类型,guid,锁定状态
|
|
|
private Dictionary<PackType, SinglePack> playerPackDict = new Dictionary<PackType, SinglePack>();
|
private Dictionary<string, ItemModel> itemGUIDDict = new Dictionary<string, ItemModel>();
|
|
private Dictionary<int, int> PackGirdServerBuyCountDict = new Dictionary<int, int>(); //背包类型:购买格子的次数
|
|
//读表数据
|
public Dictionary<int, int> PackMaxCountDict = new Dictionary<int, int>(); //背包类型:背包格子最大数量
|
public int initBagGridCount { get; private set; } //初始物品背包格子数
|
public int[] itemPackSortTyps { get; private set; } //背包物品的按类型排序
|
public List<string> composeItemGuidList = new List<string>(); //合成列表物品guid
|
|
//开格子
|
public Dictionary<int, int> openGirdMoneyDict = new Dictionary<int, int>(); //背包类型:消耗货币类型
|
public Dictionary<int, int[]> openGirdMoneyValueDict = new Dictionary<int, int[]>(); //背包类型:消耗货币值(按次数定价)
|
public Dictionary<int, int[]> openGirdCountDict = new Dictionary<int, int[]>(); //背包类型:每次开的格子数量
|
public static string StrengthAttrShift_RecordKey = "";
|
public const string RecordKnapsackTitle = "RecordKnapsackTitle";
|
|
|
string RoleEquipLocalSave = "";
|
List<int> LocalSavePlaceArray { get; set; }
|
Dictionary<int, List<int>> sharedUseCountItemDict { get; set; }
|
bool isUpdatePlayerLv = false;
|
|
public int[] gameCashShow; //代金券特殊显示 除以100
|
public int[] autoUseItemIDs;
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
|
ParseConfig();
|
//SysNotifyMgr.Instance.sysNotifyEvent += RefreshSysInfo;
|
|
|
|
// FuncConfigConfig ShareUseCntItem = FuncConfigConfig.Get("ShareUseCntItem");
|
// sharedUseCountItemDict = new Dictionary<int, List<int>>();
|
// JsonData shareUseJson = JsonMapper.ToObject(ShareUseCntItem.Numerical1);
|
// if (shareUseJson.IsArray)
|
// {
|
// for (int i = 0; i < shareUseJson.Count; i++)
|
// {
|
// var idListJson = shareUseJson[i];
|
// var idlist = new List<int>();
|
// sharedUseCountItemDict.Add(i, idlist);
|
// foreach (var id in idListJson)
|
// {
|
// idlist.Add(int.Parse(id.ToString()));
|
// }
|
// }
|
// }
|
|
|
|
}
|
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
// SysNotifyMgr.Instance.sysNotifyEvent -= RefreshSysInfo;
|
}
|
|
|
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
|
}
|
public void OnBeforePlayerDataInitialize()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= UpdateSecond;
|
PlayerDatas.Instance.playerDataRefreshEvent -= UpdatePlayerLv;
|
LocalSave.DeleteKey(RecordKnapsackTitle);
|
playerPackDict.Clear();
|
itemDayUseCntDict.Clear();
|
itemSumUseCntDict.Clear();
|
itemGUIDDict.Clear();
|
PackGirdServerBuyCountDict.Clear();
|
}
|
|
|
|
public void OnPlayerLoginOk()
|
{
|
//ItemOperateUtility.Instance.RequestWarehouseData();
|
RoleEquipLocalSave = StringUtility.Contact("RoleEquipLocalSave", PlayerDatas.Instance.baseData.PlayerID);
|
StrengthAttrShift_RecordKey = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "StrengthAttrShift");
|
if (LocalSave.GetIntArray(RoleEquipLocalSave) != null)
|
{
|
LocalSavePlaceArray = LocalSave.GetIntArray(RoleEquipLocalSave).ToList();
|
}
|
else
|
{
|
LocalSavePlaceArray = null;
|
}
|
GlobalTimeEvent.Instance.secondEvent += UpdateSecond;
|
PlayerDatas.Instance.playerDataRefreshEvent += UpdatePlayerLv;
|
isUpdatePlayerLv = true;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
}
|
|
private void RefreshSysInfo(string key, ArrayList infolist)
|
{
|
// if (key != "GetMoney") return;
|
// if (ItemLogicUtility.Instance.hidePickItem)
|
// return;
|
|
// if (PlayerDatas.Instance.baseData.LV < 3)
|
// return;
|
|
// var type = 0;
|
// int.TryParse(infolist[0].ToString(), out type);
|
// if (type == 1)
|
// {
|
// Vector3 pos = new Vector3(-100, 0, 0);
|
// Vector3 rot = new Vector3(0, 0, 0);
|
// if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
// {
|
// pos = new Vector3(0, 50, 0);
|
// rot = new Vector3(180, 180, 0);
|
// }
|
// EffectMgr.Instance.PlayUIEffect(1204, 3000, WindowCenter.Instance.uiRoot.tipsCanvas, pos, rot, false);
|
// }
|
// else if (type == 2)
|
// {
|
// Vector3 pos = new Vector3(-100, 0, 0);
|
// Vector3 rot = new Vector3(0, 0, 0);
|
// if (!WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
// {
|
// pos = new Vector3(150, 50, 0);
|
// rot = new Vector3(180, 180, 0);
|
// }
|
// lingshiEffect = EffectMgr.Instance.PlayUIEffect(1158, 3000, WindowCenter.Instance.uiRoot.tipsCanvas, pos, rot, false);
|
// }
|
}
|
|
|
|
public void UpdatePack(H0725_tagRolePackRefreshEx packInfo)
|
{
|
SetLookIndex(null);
|
var packType = (PackType)packInfo.PackType;
|
if (!playerPackDict.ContainsKey(packType))
|
{
|
playerPackDict.Add(packType, new SinglePack(packType));
|
}
|
|
|
for (int i = 0; i < packInfo.ItemCount; i++)
|
{
|
var itemInfo = new ItemInfo(packInfo.ItemInfo[i]);
|
var item = playerPackDict[packType].UpdateItem(itemInfo);
|
AddItemGUIDDict(item, true);
|
|
|
}
|
|
if (refrechPackEvent != null)
|
{
|
refrechPackEvent(packType);
|
}
|
|
UpdatePackRedpoint(packType);
|
}
|
|
public void UpdateItem(H0704_tagRolePackRefresh serverItem)
|
{
|
SetLookIndex(null);
|
PackType type = (PackType)serverItem.PackType;
|
if (!playerPackDict.ContainsKey(type))
|
{
|
playerPackDict.Add(type, new SinglePack(type));
|
}
|
|
var showNewItem = false;
|
if (itemGUIDDict.ContainsKey(serverItem.ItemGUID))
|
{
|
var prePack = itemGUIDDict[serverItem.ItemGUID].packType;
|
var preAuction = itemGUIDDict[serverItem.ItemGUID].isAuction;
|
var nowPackType = type;
|
var nowAcution = serverItem.IsBind == 1;
|
showNewItem = preAuction != nowAcution || prePack != nowPackType;
|
}
|
else
|
{
|
showNewItem = true;
|
}
|
|
var itemInfo = new ItemInfo(serverItem);
|
var item = playerPackDict[type].UpdateItem(itemInfo);
|
AddItemGUIDDict(item, showNewItem);
|
|
if (RefreshItemEvent != null)
|
{
|
RefreshItemEvent(type, itemInfo.index, itemInfo.itemId);
|
}
|
|
|
// if (type == PackType.Equip)
|
// {
|
// if (ItemLogicUtility.Instance.IsRealmEquip(itemInfo.itemId))
|
// {
|
// ItemOperateUtility.Instance.ShowPutOnNewEquipRemind(itemInfo.itemId);
|
// }
|
// }
|
|
UpdatePackRedpoint(type);
|
//EquipDecomRedCtrl();
|
AutoUseItem(itemInfo.itemId, serverItem.ItemGUID);
|
}
|
|
|
public void UpdateItemLockState(H0722_tagItemDeadLockRefresh netPack)
|
{
|
var singlePack = GetSinglePack((PackType)netPack.PackType);
|
var item = singlePack.GetItemByIndex(netPack.ItemIndex);
|
if (item == null)
|
{
|
return;
|
}
|
item.itemInfo.isLock = netPack.IsLock == 1;
|
RefreshItemLockEvent?.Invoke((PackType)netPack.PackType, item.guid, item.itemInfo.isLock);
|
}
|
|
public void UpdateBuyPackGirdCount(HA207_tagSCPackBuyInfo netPack)
|
{
|
for (int i = 0; i < netPack.BuyInfoList.Length; i++)
|
{
|
PackGirdServerBuyCountDict[netPack.BuyInfoList[i].PackType] = netPack.BuyInfoList[i].BuyCnt;
|
}
|
}
|
|
//购买所需信息 [货币类型,货币数量,购买格数]
|
public int[] BuyPackGirdNeedData(PackType packType)
|
{
|
var curPackGirdCnt = GetSinglePack(packType).unlockedGridCount;
|
if (curPackGirdCnt >= PackMaxCountDict[(int)packType])
|
return null;
|
|
int buyTimes = 0;
|
PackGirdServerBuyCountDict.TryGetValue((int)packType, out buyTimes);
|
var moneyType = openGirdMoneyDict[(int)packType];
|
var moneyCntList = openGirdMoneyValueDict[(int)packType];
|
var money = moneyCntList[Math.Min(buyTimes, moneyCntList.Length - 1)];
|
var girdCntList = openGirdCountDict[(int)packType];
|
var buyGirdCnt = girdCntList[Math.Min(buyTimes, girdCntList.Length - 1)];
|
return new[] {moneyType, money, buyGirdCnt};
|
}
|
|
public void BuyPackGird(PackType packType)
|
{
|
var netPack = new C0741_tagCOpenPackCount();
|
netPack.PackType = (byte)packType;
|
GameNetSystem.Instance.SendInfo(netPack);
|
}
|
|
public void UpdateUnlockedGridCount(H0724_tagRolePackCanUseCount useCount)
|
{
|
PackType type = (PackType)useCount.PackType;
|
if (!playerPackDict.ContainsKey(type))
|
{
|
playerPackDict.Add(type, new SinglePack(type));
|
}
|
|
playerPackDict[type].SetOpenGridCount(useCount.CanUseCount);
|
|
if (gridRefreshEvent != null)
|
{
|
gridRefreshEvent(type);
|
}
|
|
UpdatePackRedpoint(type);
|
}
|
|
|
|
public void RefreshItemCount(H0707_tagItemCountRefresh refresh)
|
{
|
SetLookIndex(null);
|
PackType type = (PackType)refresh.PackType;
|
SinglePack singlePack = null;
|
playerPackDict.TryGetValue(type, out singlePack);
|
|
if (singlePack != null)
|
{
|
ItemModel itemModel = singlePack.GetItemByIndex(refresh.ItemIndex);
|
if (itemModel != null)
|
{
|
|
itemModel.RefreshCount((int)refresh.ItemCount);
|
|
if (RefreshItemEvent != null)
|
{
|
RefreshItemEvent(type, itemModel.gridIndex, itemModel.itemId);
|
}
|
|
}
|
}
|
|
}
|
|
public void ClearPack(H0711_tagClearItemPack clearPack)
|
{
|
PackType type = (PackType)clearPack.PackIndex;
|
SinglePack singlePack = null;
|
playerPackDict.TryGetValue(type, out singlePack);
|
List<string> guidList = new List<string>();
|
if (singlePack != null)
|
{
|
foreach (var item in singlePack.GetAllItems().Values)
|
{
|
guidList.Add(item.guid);
|
}
|
singlePack.Clear();
|
foreach (var guid in guidList)
|
{
|
DeleteItemDictByGUID(type, guid);
|
}
|
}
|
refrechPackEvent?.Invoke(type);
|
}
|
|
public void RemoveItem(H0709_tagClearItem clearItem)
|
{
|
SetLookIndex(null);
|
PackType type = (PackType)clearItem.PackType;
|
|
SinglePack singlePack = null;
|
playerPackDict.TryGetValue(type, out singlePack);
|
string guid = "";
|
if (singlePack != null)
|
{
|
ItemModel itemModel = singlePack.GetItemByIndex(clearItem.ItemIndex);
|
if (itemModel == null)
|
{
|
Debug.LogErrorFormat("删除不存在的物品索引:{0}", clearItem.ItemIndex);
|
return;
|
}
|
guid = itemModel.guid;
|
int itemId = itemModel.itemId;
|
|
singlePack.RemoveItem(clearItem.ItemIndex);
|
DeleteItemDictByGUID(type, itemModel.guid,itemId, clearItem.ItemIndex, clearItem.ClearType);
|
|
if (RefreshItemEvent != null)
|
{
|
RefreshItemEvent(type, clearItem.ItemIndex, itemId);
|
}
|
|
}
|
|
UpdatePackRedpoint(type);
|
|
if (GetItemByGuid(guid) == null)
|
{
|
KnapsackTimeCDMgr.Instance.UnRegister(guid);
|
}
|
|
}
|
|
public void PackResetOk(H0316_tagPackResetOK packreset)
|
{
|
ItemLogicUtility.Instance.isPackResetOk = true;
|
}
|
|
public void UseItemSuccess(H0706_tagUseItemSuccess success)
|
{
|
SetLookIndex(null);
|
if (success.PlayerID != PlayerDatas.Instance.baseData.PlayerID)
|
{
|
return;
|
}
|
|
|
if (useItemSuccessEvent != null)
|
{
|
useItemSuccessEvent(success.ItemIndex, (int)success.ItemID);
|
}
|
}
|
|
void AutoUseItem(int itemID, string guid)
|
{
|
// if (autoUseItemIDs.Contains(itemID))
|
// {
|
// ItemOperateUtility.Instance.GotoUseItem(guid);
|
// }
|
}
|
|
|
void AddItemGUIDDict(ItemModel itemModel, bool showNewItem)
|
{
|
itemGUIDDict[itemModel.guid] = itemModel;
|
GetItemEventCtrl(itemModel, showNewItem);
|
ChangeItemEvent?.Invoke(itemModel.packType, itemModel.guid, showNewItem);
|
}
|
|
void DeleteItemDictByGUID(PackType type, string guid, int itemID = 0, int index = 0, int clearType = -1)
|
{
|
if (itemGUIDDict.ContainsKey(guid))
|
{
|
if (itemGUIDDict[guid].packType == type)
|
{
|
itemGUIDDict.Remove(guid);
|
DeleteItemEvent?.Invoke(type, guid, itemID, index, clearType);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 物品每日使用的次数
|
/// </summary>
|
private Dictionary<int, int> itemDayUseCntDict = new Dictionary<int, int>();
|
public void UpdateItemUseCnt(HA809_tagMCItemDayUseCntInfo useCntInfo)
|
{
|
for (int i = 0; i < useCntInfo.Count; i++)
|
{
|
int itemId = (int)useCntInfo.ItemUseCntList[i].ItemID;
|
int cnt = useCntInfo.ItemUseCntList[i].UseCnt;
|
if (!itemDayUseCntDict.ContainsKey(itemId))
|
{
|
itemDayUseCntDict.Add(itemId, cnt);
|
}
|
else
|
{
|
itemDayUseCntDict[itemId] = cnt;
|
}
|
|
if (refreshItemDayUseCountEvent != null)
|
{
|
refreshItemDayUseCountEvent(itemId);
|
}
|
|
}
|
}
|
|
private Dictionary<int, int> itemSumUseCntDict = new Dictionary<int, int>();
|
// public void UpdateItemSumUseCnt(HA339_tagMCAttrFruitEatCntList useCntInfo)
|
// {
|
// for (int i = 0; i < useCntInfo.count; i++)
|
// {
|
// int itemId = (int)useCntInfo.EatCntList[i].ItemID;
|
// int cnt = (int)useCntInfo.EatCntList[i].EatCnt;
|
// if (!itemSumUseCntDict.ContainsKey(itemId))
|
// {
|
// itemSumUseCntDict.Add(itemId, cnt);
|
// }
|
// else
|
// {
|
// itemSumUseCntDict[itemId] = cnt;
|
// }
|
|
// if (refreshItemSumUseCountEvent != null)
|
// {
|
// refreshItemSumUseCountEvent(itemId);
|
// }
|
// }
|
// }
|
|
|
#region 玩家装备特殊逻辑
|
void ParseConfig()
|
{
|
|
ParsePackConfigIni();
|
autoUseItemIDs = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("AutoUseItem").Numerical1);
|
var config= FuncConfigConfig.Get("InitBagCellCount");
|
initBagGridCount = int.Parse(config.Numerical1);
|
|
config = FuncConfigConfig.Get("PackageSortPriority");
|
itemPackSortTyps = ConfigParse.GetMultipleStr<int>(config.Numerical1);
|
|
config = FuncConfigConfig.Get("OpenPack");
|
openGirdMoneyDict = ConfigParse.ParseIntDict(config.Numerical1);
|
openGirdMoneyValueDict = ConfigParse.ParseIntArrayDict(config.Numerical2);
|
openGirdCountDict = ConfigParse.ParseIntArrayDict(config.Numerical3);
|
|
config = FuncConfigConfig.Get("ItemCountShow");
|
gameCashShow = JsonMapper.ToObject<int[]>(config.Numerical1);
|
}
|
|
void ParsePackConfigIni()
|
{
|
string[] lines = LoadConfigIni("MapServerConfig");
|
foreach (string line in lines)
|
{
|
if (line.StartsWith("PackCnt") && line.Contains("="))
|
{
|
string[] parts = line.Split('=');
|
if (parts.Length == 2 && int.TryParse(parts[1], out int count))
|
{
|
string packTypeStr = parts[0].Replace("PackCnt", "");
|
if (int.TryParse(packTypeStr, out int packTypeIndex))
|
{
|
PackMaxCountDict[packTypeIndex] = count;
|
}
|
}
|
}
|
}
|
}
|
|
public string[] LoadConfigIni(string name)
|
{
|
string path = string.Empty;
|
#if UNITY_EDITOR
|
if (!AssetSource.isUseAssetBundle)
|
{
|
path = ResourcesPath.CONFIG_FODLER + "/" + name + ".ini";
|
}
|
else
|
#endif
|
{
|
path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.ini");
|
}
|
|
return File.ReadAllLines(path);
|
}
|
|
public int GetCanBuyPackGirdCount(PackType type)
|
{
|
if (!PackMaxCountDict.ContainsKey((int)type))
|
{
|
return 0;
|
}
|
return PackMaxCountDict[(int)type] - GetSinglePack(type).unlockedGridCount;
|
}
|
|
|
private void UpdateSecond()
|
{
|
if (isUpdatePlayerLv)
|
{
|
isUpdatePlayerLv = false;
|
}
|
}
|
|
private void UpdatePlayerLv(PlayerDataType type)
|
{
|
if (type != PlayerDataType.LV) return;
|
|
isUpdatePlayerLv = true;
|
}
|
|
#endregion
|
|
|
private void GetItemEventCtrl(ItemModel itemModel, bool showNewItem)
|
{
|
// if (showNewItem)
|
// {
|
// bool isOverdue = false;
|
// if (itemModel.config.ExpireTime > 0)
|
// {
|
// ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(itemModel.guid);
|
// switch ((ItemTimeType)itemModel.config.EndureReduceType)
|
// {
|
// case ItemTimeType.EquipedTime:
|
// List<int> itemEffectTime = itemModel.GetUseData((int)ItemUseDataKey.createTime);
|
// if (itemEffectTime != null && itemEffectTime[0] != 0)
|
// {
|
// if (cool == null || cool.GetRemainTime() <= 0)
|
// {
|
// isOverdue = true;
|
// }
|
// }
|
// break;
|
|
// case ItemTimeType.RealityTime:
|
// if (cool == null || cool.GetRemainTime() <= 0)
|
// {
|
// isOverdue = true;
|
// }
|
// break;
|
|
// }
|
// }
|
|
// if (!isOverdue)
|
// {
|
// ItemLogicUtility.Instance.RecommendItem(itemModel);
|
// ItemLogicUtility.Instance.OnGetEquip(itemModel);
|
// ItemLogicUtility.Instance.RefreshPickItem(itemModel.packType, itemModel.itemId.ToString());
|
// }
|
// }
|
|
}
|
|
/// <summary>
|
/// 得到某个包裹的所有数据
|
/// </summary>
|
/// <param name="type"></param>
|
/// <returns></returns>
|
public SinglePack GetSinglePack(PackType type)
|
{
|
SinglePack singlePack = null;
|
if (!playerPackDict.TryGetValue(type, out singlePack))
|
{
|
singlePack = new SinglePack(type);
|
playerPackDict.Add(type, singlePack);
|
}
|
return singlePack;
|
}
|
|
public void UnLockPackGrid(int chooseGridCount, PackType type)
|
{
|
// var singlePack = GetSinglePack(type);
|
// int openCount = chooseGridCount - singlePack.unlockedGridCount;
|
// int index = 0;
|
// switch (type)
|
// {
|
// case PackType.Item:
|
// index = chooseGridCount - GeneralDefine.initBagGridCount;
|
// break;
|
// case PackType.Warehouse:
|
// index = chooseGridCount - GeneralDefine.initDepotGridCount;
|
// break;
|
// }
|
|
// itemTipsModel.SetExtendGirdModel(openCount, index, type);
|
// WindowCenter.Instance.Open<ExtendWin>();
|
}
|
|
public ItemModel GetItemByGuid(string guid)
|
{
|
if (string.IsNullOrEmpty(guid))
|
{
|
return null;
|
}
|
|
ItemModel itemModel = null;
|
itemGUIDDict.TryGetValue(guid, out itemModel);
|
return itemModel;
|
}
|
|
public ItemModel GetItemByIndex(PackType type, int index)
|
{
|
ItemModel itemModel = null;
|
if (playerPackDict.ContainsKey(type))
|
{
|
itemModel = playerPackDict[type].GetItemByIndex(index);
|
}
|
return itemModel;
|
}
|
|
/// <summary>
|
/// 获取指定背包内 指定ID的所有物品
|
/// </summary>
|
/// <param name="type"></param>
|
/// <param name="id"></param>
|
/// <param name="includeAuction"></param>
|
/// <returns></returns>
|
public List<ItemModel> GetItemsById(PackType type, int id, bool includeAuction = true)
|
{
|
if (playerPackDict.ContainsKey(type))
|
{
|
var singlePack = playerPackDict[type];
|
return singlePack.GetItemsById(id, includeAuction);
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// 获取指定背包内指定ID的一个物品
|
/// </summary>
|
/// <param name="type"></param>
|
/// <param name="id"></param>
|
/// <param name="includeAuction"></param>
|
/// <returns></returns>
|
public ItemModel GetItemByID(PackType type, int id, bool includeAuction = true)
|
{
|
if (playerPackDict.ContainsKey(type))
|
{
|
var singlePack = playerPackDict[type];
|
return singlePack.GetItemByID(id, includeAuction);
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
public List<ItemModel> GetItems(PackType packType, SinglePack.FilterParams param)
|
{
|
if (playerPackDict.ContainsKey(packType))
|
{
|
return playerPackDict[packType].GetItems(param);
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
public List<ItemModel> GetItems(PackType packType)
|
{
|
if (playerPackDict.ContainsKey(packType))
|
{
|
return playerPackDict[packType].GetItems();
|
}
|
else
|
{
|
return null;
|
}
|
}
|
|
//通过id找物品,注意检查是否指定背包
|
public string GetItemGUIDByID(int itemId, bool includeAuction = true, PackType packType = PackType.Item)
|
{
|
string guid = string.Empty;
|
foreach (var key in itemGUIDDict.Keys)
|
{
|
if (!includeAuction && itemGUIDDict[key].isAuction)
|
{
|
continue;
|
}
|
|
if (itemGUIDDict[key].itemId == itemId && packType == itemGUIDDict[key].packType)
|
{
|
guid = key;
|
return guid;
|
}
|
}
|
|
return guid;
|
}
|
|
//通过index找GUID
|
public string GetItemGUIDByIndex(PackType packType, int index)
|
{
|
string guid = string.Empty;
|
if (playerPackDict.ContainsKey(packType))
|
{
|
var items = playerPackDict[packType].GetAllItems();
|
guid = items[index].guid;
|
}
|
|
return guid;
|
}
|
|
|
/// <summary>
|
/// 得到ID相同的物品数量; 也可以获得部分货币和物品绑定的数量
|
/// </summary>
|
/// <param name="type"></param>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public long GetItemCountByID(PackType type, int id, bool includeAuction = true)
|
{
|
long count = 0;
|
var singlePack = GetSinglePack(type);
|
if (singlePack != null)
|
{
|
count = singlePack.GetCountById(id, includeAuction);
|
}
|
|
return count;
|
}
|
|
public int GetEmptyGridCount(PackType type)
|
{
|
int count = 0;
|
SinglePack singlePack = GetSinglePack(type);
|
if (singlePack != null)
|
{
|
count = singlePack.GetEmptyGridCount();
|
}
|
|
return count;
|
}
|
|
public bool TryGetShareNumItem(int itemId, out List<int> idlist)
|
{
|
idlist = new List<int>();
|
foreach (var list in sharedUseCountItemDict.Values)
|
{
|
if (list.Contains(itemId))
|
{
|
idlist = list;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 得到物品今日使用次数
|
/// </summary>
|
/// <param name="itemId"></param>
|
/// <returns></returns>
|
public int GetItemUsedTimesToday(int itemId)
|
{
|
int useCnt = 0;
|
List<int> shareIdlist = null;
|
// bool isShare = TryGetShareNumItem(itemId, out shareIdlist);
|
// if (isShare)
|
// {
|
// foreach (var id in shareIdlist)
|
// {
|
// int singleUseCnt = 0;
|
// itemDayUseCntDict.TryGetValue(id, out singleUseCnt);
|
// useCnt += singleUseCnt;
|
// }
|
// }
|
// else
|
{
|
itemDayUseCntDict.TryGetValue(itemId, out useCnt);
|
}
|
return useCnt;
|
}
|
|
/// <summary>
|
/// 得到物品总使用次数
|
/// </summary>
|
/// <param name="itemId"></param>
|
/// <returns></returns>
|
public int GetItemTotalUsedTimes(int itemId)
|
{
|
int useCnt = 0;
|
List<int> shareIdlist = null;
|
bool isShare = TryGetShareNumItem(itemId, out shareIdlist);
|
if (isShare)
|
{
|
foreach (var id in shareIdlist)
|
{
|
int singleUseCnt = 0;
|
itemDayUseCntDict.TryGetValue(id, out singleUseCnt);
|
useCnt += singleUseCnt;
|
}
|
}
|
else
|
{
|
itemSumUseCntDict.TryGetValue(itemId, out useCnt);
|
}
|
return useCnt;
|
}
|
|
public void GotoWashAttributePoint(string guid)
|
{
|
// ItemModel itemModel = GetItemByGuid(guid);
|
// if (itemModel == null) return;
|
|
// WashAttrPointWin.itemModel = itemModel;
|
// WindowCenter.Instance.Open<WashAttrPointWin>();
|
}
|
|
#region 红点逻辑判断
|
|
const int ITEMPACK_REDKEY = 102011003;
|
Redpoint redpointItemPack = new Redpoint(MainRedDot.RedPoint_BagFuncKey, ITEMPACK_REDKEY);
|
|
|
private void UpdatePackRedpoint(PackType type)
|
{
|
var singlePack = GetSinglePack(type);
|
if (singlePack == null)
|
{
|
return;
|
}
|
|
switch (type)
|
{
|
case PackType.Item:
|
if (singlePack.GetEmptyGridCount() <= 0)
|
{
|
redpointItemPack.state = RedPointState.Full;
|
//SysNotifyMgr.Instance.ShowTip("BagFull");
|
}
|
else
|
{
|
redpointItemPack.state = RedPointState.None;
|
}
|
|
break;
|
|
}
|
}
|
|
|
#endregion
|
|
#region 查看某个位置的物品
|
public event Action lookEquipEvent;
|
private int _lookLineIndex = -1;
|
public int lookLineIndex { get { return _lookLineIndex; } private set { _lookLineIndex = value; } }
|
|
public string lookItemGUID { get; private set; }
|
|
public void SetLookIndex(string guid, int singleRowCount = 5)
|
{
|
return;
|
// if (string.IsNullOrEmpty(guid) || guid == "")
|
// {
|
// lookLineIndex = -1;
|
// lookItemGUID = "";
|
// }
|
// else
|
// {
|
// int index = GetItemByGuid(guid).gridIndex;
|
// lookLineIndex = index / singleRowCount;
|
// lookItemGUID = guid;
|
// }
|
|
// if (lookEquipEvent != null)
|
// {
|
// lookEquipEvent();
|
// }
|
}
|
|
public event Action RefreshBagEvent;
|
public void RefreshBagInfo()
|
{
|
if (RefreshBagEvent != null)
|
{
|
RefreshBagEvent();
|
}
|
}
|
#endregion
|
|
public void SetJumpToOneKeySell(Transform parent)
|
{
|
// var goEffect = AchievementGuideEffectPool.Require(1);
|
// goEffect.transform.SetParentEx(parent, Vector3.zero, Quaternion.identity, Vector3.one);
|
// AchievementGoto.guideAchievementId = 0;
|
}
|
|
#region 物品使用快捷提示
|
|
private int cacheMapId = 0;
|
public event Action<PackType, string> itemUseAct;
|
private Dictionary<int, int> itemUseTypeDict = new Dictionary<int, int>(); //key SkillTypeID,value 使用物品的ID
|
|
|
private void AddItemUseTypeDict(int id)
|
{
|
// SkillConfig skillConfig = GetSkillConfig(id);
|
// int itemCount = GetItemCountByID(PackType.Item, id);
|
// if (skillConfig != null && itemCount > 0)
|
// {
|
// if (!itemUseTypeDict.ContainsKey(skillConfig.SkillTypeID))
|
// {
|
// itemUseTypeDict.Add(skillConfig.SkillTypeID, id);
|
// }
|
// else
|
// {
|
// SkillConfig preSkillConfig = GetSkillConfig(itemUseTypeDict[skillConfig.SkillTypeID]);
|
// if (skillConfig.SkillLV > preSkillConfig.SkillLV)
|
// {
|
// itemUseTypeDict[skillConfig.SkillTypeID] = id;
|
// }
|
// }
|
// }
|
}
|
|
|
|
|
public SkillConfig GetSkillConfig(int itemId)
|
{
|
ItemConfig itemConfig = ItemConfig.Get(itemId);
|
SkillConfig skillConfig = SkillConfig.Get(itemConfig.AddSkill1);
|
return skillConfig;
|
}
|
|
|
|
#endregion
|
|
#region 判断物品是否达到使用上限
|
public bool IsReachUseLimit(string guid, out ulong count)
|
{
|
count = 0;
|
ItemModel itemModel = GetItemByGuid(guid);
|
if (itemModel == null) return false;
|
|
// AttrFruitConfig fruitConfig = AttrFruitConfig.Get(itemModel.itemId);
|
int haveUseCnt = GetItemUsedTimesToday(itemModel.itemId);
|
int sumHaveUseCnt = GetItemTotalUsedTimes(itemModel.itemId);
|
count = (ulong)itemModel.count;
|
bool isReach = false;
|
int remainDayCnt = 0;
|
if (itemModel.config.MaxSkillCnt > 0)
|
{
|
remainDayCnt = itemModel.config.MaxSkillCnt - haveUseCnt;
|
if (itemModel.count > remainDayCnt)
|
{
|
count = (ulong)remainDayCnt;
|
}
|
}
|
|
int remainSumCnt = 0;
|
// if (fruitConfig != null)
|
// {
|
// remainSumCnt = fruitConfig.basicUseLimit - sumHaveUseCnt;
|
// if (remainSumCnt <= remainDayCnt && itemModel.count > remainSumCnt)
|
// {
|
// count = (ulong)remainSumCnt;
|
// }
|
// }
|
|
if (count < (ulong)itemModel.count)
|
{
|
isReach = true;
|
}
|
|
return isReach;
|
}
|
#endregion
|
|
|
|
|
|
public enum EquipColorType
|
{
|
None = 0,
|
White = 1,
|
Blue = 2,
|
Purple = 3,
|
Orange = 4,
|
Red = 5,
|
|
}
|
|
|
}
|