| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 | 
							- using System.Collections.Generic;
 
- using System.Linq;
 
- using Common.Utility.CombatEvent;
 
- using Core.Utility;
 
- using Fort23.Core;
 
- using Fort23.UTool;
 
- using GameLogic.Hero;
 
- using UnityEngine;
 
- namespace GameLogic.Bag
 
- {
 
-     public class BagController
 
-     {
 
-         /// <summary>
 
-         /// 玩家的所有道具(包含货币)
 
-         /// </summary>
 
-         // private List<ItemInfo> m_bagList = new List<ItemInfo>();
 
-         private Dictionary<string, ItemInfo> m_allBagDic = new Dictionary<string, ItemInfo>();
 
-         /// <summary>
 
-         /// 外部访问用
 
-         /// </summary>
 
-         public Dictionary<string, ItemInfo> allBagDic => m_allBagDic;
 
-         public void Init()
 
-         {
 
-             foreach (var itemData in AccountFileInfo.Instance.playerData.ItemListData)
 
-             {
 
-                 ItemInfo itemInfo = new ItemInfo(itemData);
 
-                 // m_bagList.Add(itemInfo);
 
-                 LogTool.Log(itemInfo.guid);
 
-                 m_allBagDic.Add(itemInfo.guid, itemInfo);
 
-                 // PlayerManager.Instance.eqController.Init(itemInfo);
 
-             }
 
-         }
 
-         #region 快速添加和扣除常用道具
 
-         /// <summary>
 
-         /// 加金币
 
-         /// </summary>
 
-         /// <param name="count"></param>
 
-         public void AddCoin(long count)
 
-         {
 
-             AddItem(GlobalParam.Item_Coin_ID, count);
 
-         }
 
-         /// <summary>
 
-         /// 扣金币
 
-         /// </summary>
 
-         /// <param name="count"></param>
 
-         public bool DeductCoin(long count)
 
-         {
 
-             return DeductItem(GlobalParam.Item_Coin_ID, count);
 
-         }
 
-         /// <summary>
 
-         /// 加钻石
 
-         /// </summary>
 
-         /// <param name="count"></param>
 
-         public void AddDiamond(long count)
 
-         {
 
-             AddItem(GlobalParam.Item_Diamond_ID, count);
 
-         }
 
-         /// <summary>
 
-         /// 扣钻石
 
-         /// </summary>
 
-         /// <param name="count"></param>
 
-         public bool DeductDiamond(long count)
 
-         {
 
-             return DeductItem(GlobalParam.Item_Diamond_ID, count);
 
-         }
 
-         /// <summary>
 
-         /// 加英雄经验
 
-         /// </summary>
 
-         /// <param name="count"></param>
 
-         public void AddHeroExp(long count)
 
-         {
 
-             AddItem(GlobalParam.Item_HeroExp_ID, count);
 
-         }
 
-         /// <summary>
 
-         /// 扣英雄经验
 
-         /// </summary>
 
-         /// <param name="count"></param>
 
-         public bool DuctHeroExp(long count)
 
-         {
 
-             return DeductItem(GlobalParam.Item_HeroExp_ID, count);
 
-         }
 
-         /// <summary>
 
-         /// 道具是否足够
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="count"></param>
 
-         /// <returns></returns>
 
-         public bool IsEnough(ItemInfo item, long count)
 
-         {
 
-             if (item.config.ID <= 0)
 
-             {
 
-                 return false;
 
-             }
 
-             if (item.count >= count)
 
-             {
 
-                 return true;
 
-             }
 
-             else
 
-             {
 
-                 return false;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 道具是否足够
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="count"></param>
 
-         /// <returns></returns>
 
-         public bool IsEnough(int itemId, long count)
 
-         {
 
-             ItemInfo item = GetItemInfo(itemId);
 
-             return IsEnough(item, count);
 
-         }
 
-         #endregion
 
-         public bool AddItem(int itemId, long count, string guid = "")
 
-         {
 
-             string guidStr = string.IsNullOrEmpty(guid) ? itemId.ToString() : guid;
 
-             if (count <= 0)
 
-                 return false;
 
-             ItemInfo item = GetItemInfo(itemId, guidStr);
 
-             return AddItemCount(item, count);
 
-         }
 
-         /// <summary>
 
-         /// 添加道具,装备和普通道具都可以
 
-         /// </summary>
 
-         /// <param name="itemInfos"></param>
 
-         public void AddItem(List<ItemInfo> itemInfos)
 
-         {
 
-             for (int i = 0; i < itemInfos.Count; i++)
 
-             {
 
-                 ItemInfo item = itemInfos[i];
 
-                 LogTool.Log("获得了道具" + item.itemID);
 
-                 AddItem(item);
 
-                 // //掉落的数量
 
-                 // long count = itemInfo.count.Value;
 
-                 // ItemInfo item = GetItemInfo(itemInfo);
 
-                 //
 
-                 // if (item.IsEquipItem())
 
-                 // {
 
-                 //     PlayerManager.Instance.eqController.AddEquipment(item);
 
-                 // }
 
-                 //
 
-                 // AddItemCount(item, count);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 添加道具数量,最后都走这里
 
-         /// </summary>
 
-         /// <param name="item"></param>
 
-         /// <param name="count"></param>
 
-         /// <returns></returns>
 
-         private bool AddItemCount(ItemInfo item, long count)
 
-         {
 
-             if (item.config.ID <= 0 && string.IsNullOrEmpty(item.guid))
 
-             {
 
-                 return false;
 
-             }
 
-             if (count <= 0)
 
-                 return false;
 
-             //法宝
 
-             if (item.config.itemTag == 11)
 
-             {
 
-                 AccountFileInfo.FaBaoData faaData = AccountFileInfo.Instance.playerData.AllFaBaoDatas.FirstOrDefault(
 
-                     f =>
 
-                         f.id == item.config.associateVlaue[1]);
 
-                 if (faaData != null)
 
-                 {
 
-                     return AddItem(item.config.associateVlaue[0], item.config.associateVlaue[2] *count);
 
-                 }
 
-                 else
 
-                 {
 
-                     faaData = new AccountFileInfo.FaBaoData();
 
-                     faaData.id = item.config.associateVlaue[1];
 
-                     faaData.level = 1;
 
-                     faaData.useIndex = -1;
 
-                     AccountFileInfo.Instance.playerData.AllFaBaoDatas.Add(faaData);
 
-                     FaBaoInfo faBaoInfo = new FaBaoInfo(faaData);
 
-                     PlayerManager.Instance.FaBaoControl.AddFaBao(faBaoInfo);
 
-                     return true;
 
-                 }
 
-             }
 
-             //功法
 
-             else if (item.config.itemTag == 13)
 
-             {
 
-                 AccountFileInfo.SkillData skillData = AccountFileInfo.Instance.playerData.AllSkillDatas.FirstOrDefault(
 
-                     s =>
 
-                         s.id == item.config.associateVlaue[1]);
 
-                 if (skillData != null)
 
-                 {
 
-                     return AddItem(item.config.associateVlaue[0], item.config.associateVlaue[2]* count);
 
-                 }
 
-                 else
 
-                 {
 
-                     skillData = new AccountFileInfo.SkillData();
 
-                     skillData.id = item.config.associateVlaue[1];
 
-                     skillData.star = 1;
 
-                     skillData.level = 1;
 
-                     skillData.useIndex = -1;
 
-                     AccountFileInfo.Instance.playerData.AllSkillDatas.Add(skillData);
 
-                     SkillInfo skillInfo = new SkillInfo(skillData);
 
-                     skillInfo.index = skillData.useIndex;
 
-                     PlayerManager.Instance.GongFaControl.AddSkillInfo(skillInfo);
 
-                     return true;
 
-                 }
 
-             }
 
-             else if (item.config.associateID == 13)
 
-             {
 
-                 PlayerManager.Instance.myHero.heroData.exp += count;
 
-                 AccountFileInfo.Instance.SavePlayerData();
 
-                 return true;
 
-             }
 
-             else if (item.config.itemTag == 9)
 
-             {
 
-                 return AddItem(item.config.associateVlaue[0], item.config.associateVlaue[1]);
 
-             }
 
-             item.count += count;
 
-             EventManager.Instance.Dispatch(CustomEventType.ItemUpdate,
 
-                 new ItemUpdateData() { ItemInfo = item, Count = (int)count });
 
-             EventManager.Instance.Dispatch(CustomEventType.AddItem,
 
-                 new ItemUpdateData() { ItemInfo = item, Count = (int)count });
 
-             AccountFileInfo.Instance.SaveItemData(item);
 
-             RedDotManager.Instance.AllRedDotUpDate();
 
-             return true;
 
-         }
 
-         // private void AddEqToDic(ItemInfo eqItemInfo)
 
-         // {
 
-         //     if (eqItemInfo.eqInfo == null)
 
-         //     {
 
-         //         return;
 
-         //     }
 
-         //     
 
-         //     int pro = eqItemInfo.eqInfo.basicEquipConfig.profession;
 
-         //     
 
-         //     if (m_EqDic.ContainsKey(pro))
 
-         //     {
 
-         //         m_EqDic[pro].Add(eqItemInfo);
 
-         //     }
 
-         //     else
 
-         //     {
 
-         //         m_EqDic.Add(pro, new List<ItemInfo>());
 
-         //         m_EqDic[pro].Add(eqItemInfo);
 
-         //     }
 
-         // }
 
-         /// <summary>
 
-         /// 添加道具,装备和普通道具都可以
 
-         /// </summary>
 
-         /// <param name="item"></param>
 
-         public void AddItem(ItemInfo item)
 
-         {
 
-             //掉落的数量
 
-             long count = item.count.Value;
 
-             ItemInfo itemInfo = GetItemInfo(item);
 
-             // if (itemInfo.IsEquipItem())
 
-             // {
 
-             //     PlayerManager.Instance.eqController.AddEquipment(itemInfo);    
 
-             // }
 
-             AddItemCount(itemInfo, count);
 
-         }
 
-         // /// <summary>
 
-         // /// 重新加载一次所有装备
 
-         // /// 一般用于,分解装备之后
 
-         // /// </summary>
 
-         // public void ReInitAllEqItem()
 
-         // {
 
-         //     PlayerManager.Instance.eqController.allZyEqDic.Clear();
 
-         //     foreach (KeyValuePair<string,ItemInfo> keyValuePair in m_allBagDic)
 
-         //     {
 
-         //         PlayerManager.Instance.eqController.AddEquipment(keyValuePair.Value);
 
-         //     }
 
-         // }
 
-         public void RemoveItem(ItemInfo itemInfo, bool saveNow, bool zeroDel)
 
-         {
 
-             itemInfo.count.Value = 0;
 
-             if (zeroDel)
 
-             {
 
-                 m_allBagDic.Remove(itemInfo.guid);
 
-             }
 
-             AccountFileInfo.Instance.SaveItemData(itemInfo, saveNow);
 
-         }
 
-         public void ModifyItem(ItemInfo itemInfo, bool saveNow)
 
-         {
 
-             itemInfo.count.Value -= itemInfo.count.Value;
 
-             AccountFileInfo.Instance.SaveItemData(itemInfo, saveNow);
 
-         }
 
-         /// <summary>
 
-         /// 获取道具信息
 
-         /// 不传guid,默认itemId就是guid
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="guid"></param>
 
-         /// <returns></returns>
 
-         // public ItemInfo GetItemInfo(ItemInfo itemInfo)
 
-         // {
 
-         //     string guidStr = string.IsNullOrEmpty(itemInfo.guid) ? itemInfo.itemID.ToString() : itemInfo.guid;
 
-         //
 
-         //     if (m_allBagDic.TryGetValue(guidStr, out ItemInfo item))
 
-         //     {
 
-         //         return item;
 
-         //     }
 
-         //
 
-         //     m_allBagDic.Add(itemInfo.guid, itemInfo);
 
-         //
 
-         //     return itemInfo;
 
-         // }
 
-         /// <summary>
 
-         /// 一般是掉了(随机)一个东西(ItemInfo),然后来背包找,是否之前掉过一样的
 
-         /// 之前有,就把有的返回回去,加数量
 
-         /// 之前无,就返回这个新东西
 
-         /// /// 重要:加入背包管理都是通过这个方法(后续看是否优)
 
-         /// </summary>
 
-         /// <param name="itemInfo"></param>
 
-         /// <returns></returns>
 
-         public ItemInfo GetItemInfo(ItemInfo itemInfo)
 
-         {
 
-             string guidStr = string.IsNullOrEmpty(itemInfo.guid) ? itemInfo.itemID.ToString() : itemInfo.guid;
 
-             if (m_allBagDic.TryGetValue(guidStr, out ItemInfo item))
 
-             {
 
-                 return item;
 
-             }
 
-             //这里要设成0是因为,随机掉落的东西,第一次进背包时,先把数量去掉(否则会掉会多加1个)
 
-             //该方法结束后,有统一加数量的代码,看后续代码。
 
-             itemInfo.count.Value = 0l;
 
-             m_allBagDic.Add(itemInfo.guid, itemInfo);
 
-             return itemInfo;
 
-         }
 
-         public long GetItemCount(int itemId)
 
-         {
 
-             ItemInfo itemInfo = GetItemInfo(itemId);
 
-             if (itemInfo == null)
 
-             {
 
-                 return 0;
 
-             }
 
-             return itemInfo.count.Value;
 
-         }
 
-         /// <summary>
 
-         /// 获取道具信息
 
-         /// 不传guid,默认itemId就是guid
 
-         /// </summary>
 
-         /// <param name="itemId"></param>
 
-         /// <param name="guid"></param>
 
-         /// <returns></returns>
 
-         public ItemInfo GetItemInfo(int itemId, string guid = "")
 
-         {
 
-             string guidStr = string.IsNullOrEmpty(guid) ? itemId.ToString() : guid;
 
-             if (m_allBagDic.TryGetValue(guidStr, out ItemInfo item))
 
-             {
 
-                 return item;
 
-             }
 
-             ItemInfo newItem = new ItemInfo(itemId);
 
-             if (newItem.config.ID > 0)
 
-             {
 
-                 m_allBagDic.Add(newItem.guid, newItem);
 
-             }
 
-             else
 
-             {
 
-                 LogTool.Error("没有找到这个道具:" + itemId);
 
-                 return null;
 
-             }
 
-             return newItem;
 
-         }
 
-         /// <summary>
 
-         /// 扣除道具,最后都这里
 
-         /// </summary>
 
-         /// <param name="item"></param>
 
-         /// <param name="count"></param>
 
-         /// <returns></returns>
 
-         public bool DeductItem(ItemInfo item, long count)
 
-         {
 
-             if (item == null)
 
-             {
 
-                 return false;
 
-             }
 
-             if (item.config.ID <= 0)
 
-             {
 
-                 return false;
 
-             }
 
-             if (item.count >= count)
 
-             {
 
-                 item.count -= count;
 
-             }
 
-             else
 
-             {
 
-                 return false;
 
-             }
 
-             EventManager.Instance.Dispatch(CustomEventType.ItemUpdate, new ItemUpdateData() { ItemInfo = item });
 
-             AccountFileInfo.Instance.SaveItemData(item);
 
-             RedDotManager.Instance.AllRedDotUpDate();
 
-             return true;
 
-         }
 
-         public bool DeductItem(int itemId, long count)
 
-         {
 
-             ItemInfo item = GetItemInfo(itemId);
 
-             return DeductItem(item, count);
 
-         }
 
-         public void DropHeroExp(Vector3 startPos_WorldPos, int showCount, int itemCount)
 
-         {
 
-             CombatItemShowEventData combatItemShowEventData = CombatItemShowEventData.Create();
 
-             combatItemShowEventData.count = showCount;
 
-             combatItemShowEventData.startPos_WorldPos = startPos_WorldPos;
 
-             combatItemShowEventData.showName = "icon_res_upgrade_1";
 
-             combatItemShowEventData.showType = CombatItemShowEventData.ShowType.HeroExp;
 
-             combatItemShowEventData.addValue = itemCount;
 
-             EventManager.Instance.Dispatch(CustomEventType.Combat_ItemShow, combatItemShowEventData);
 
-         }
 
-         public void DropLevelExp(Vector3 startPos_WorldPos, int showCount, int itemCount)
 
-         {
 
-             CombatItemShowEventData combatItemShowEventData = CombatItemShowEventData.Create();
 
-             combatItemShowEventData.count = showCount;
 
-             combatItemShowEventData.startPos_WorldPos = startPos_WorldPos;
 
-             combatItemShowEventData.showName = "icon_Energy";
 
-             combatItemShowEventData.showType = CombatItemShowEventData.ShowType.LevelExp;
 
-             combatItemShowEventData.addValue = itemCount;
 
-             EventManager.Instance.Dispatch(CustomEventType.Combat_ItemShow, combatItemShowEventData);
 
-         }
 
-         public void DropMonsterGold(Vector3 startPos_WorldPos, int showCount, int itemCount)
 
-         {
 
-             CombatItemShowEventData combatItemShowEventData = CombatItemShowEventData.Create();
 
-             combatItemShowEventData.count = showCount;
 
-             combatItemShowEventData.startPos_WorldPos = startPos_WorldPos;
 
-             combatItemShowEventData.showName = "icon_Coin";
 
-             combatItemShowEventData.showType = CombatItemShowEventData.ShowType.MonsterGold;
 
-             combatItemShowEventData.addValue = itemCount;
 
-             EventManager.Instance.Dispatch(CustomEventType.Combat_ItemShow, combatItemShowEventData);
 
-         }
 
-     }
 
- }
 
 
  |