using Snxxz.UI; using System; using System.Collections.Generic; using System.Linq; using UnityEngine; using TableConfig; using LitJson; namespace Snxxz.UI { public class PlayerPackModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk { public Dictionary DrugToDungeonDict { get; private set; } //key 丹药ID,value副本ID public Dictionary DungeonToDrugDict { get; private set; } //key 副本ID,value丹药ID列表 public List makeDruglist { get; private set; } public Dictionary> decomposeAttrDict = new Dictionary>(); public static string StrengthAttrShift_RecordKey = "StrengthAttrShift"; public const string RecordKnapsackTitle = "RecordKnapsackTitle"; public int MaxBagGridCnt { get; private set; } public int InitBagGridCnt { get; private set; } public int MaxDepotGridCnt { get; private set; } public int InitDepotGridCnt { get; private set; } BlastFurnaceModel FurnaceModel { get { return ModelCenter.Instance.GetModel(); } } public override void Init() { List dungeonlist = Config.Instance.GetAllValues(); if (dungeonlist != null) { DrugToDungeonDict = new Dictionary(); DungeonToDrugDict = new Dictionary(); for (int i = 0; i < dungeonlist.Count; i++) { int[] drugIdlist = dungeonlist[i].ElixirHint; if (drugIdlist != null && drugIdlist.Length > 0) { DungeonToDrugDict.Add(dungeonlist[i].DataMapID, drugIdlist); for (int j = 0; j < drugIdlist.Length; j++) { DrugToDungeonDict.Add(drugIdlist[j], dungeonlist[i].DataMapID); } } } } makeDruglist = new List(); List fruitlist = Config.Instance.GetAllValues(); for(int i = 0; i < fruitlist.Count; i++) { if(fruitlist[i].FuncID == 2) { makeDruglist.Add(fruitlist[i]); } } makeDruglist.Sort(CompareMakeDrug); StageManager.Instance.onStageLoadFinish += OnStageLoadFinish; SetDevourEquipPlace(); decomposeAttrDict.Clear(); List decomlist = Config.Instance.GetAllValues(); for(int i = 0; i < decomlist.Count;i++) { JsonData attrData = JsonMapper.ToObject(decomlist[i].Attr); Dictionary attrDict = new Dictionary(); decomposeAttrDict.Add(decomlist[i].LV,attrDict); foreach (var id in attrData.Keys) { attrDict.Add(int.Parse(id),int.Parse(attrData[id].ToString())); } } FuncConfigConfig equipDecompose = Config.Instance.Get("EquipDevourCount"); minDecomposeNum = int.Parse(equipDecompose.Numerical1); defaultUnSelectlist = ConfigParse.GetMultipleStr(equipDecompose.Numerical2); InitDepotGridCnt = int.Parse(Config.Instance.Get("InitDepotCellCount").Numerical1); InitBagGridCnt = int.Parse(Config.Instance.Get("InitBagCellCount").Numerical1); MaxBagGridCnt = int.Parse(Config.Instance.Get("MaxBagCellCount").Numerical1); MaxDepotGridCnt = int.Parse(Config.Instance.Get("MaxDepotCellCount").Numerical1); } public void OnBeforePlayerDataInitialize() { LocalSave.DeleteKey(RecordKnapsackTitle); cacheMapId = 0; playerPackDict.Clear(); itemDayUseCntDict.Clear(); itemSumUseCntDict.Clear(); itemGUIDDict.Clear(); showDropItem = false; isPlayBetterEquipEffect = false; equipAttrActiveDict.Clear(); colorType = EquipColorType.Purple; lvType = EquipLvType.All; starType = EquipStarType.None; decomposeLv = 1; decomposeExp = 0; decomposeProgress = 0; isAutoDecompose = false; } public void OnAfterPlayerDataInitialize() { } public void OnPlayerLoginOk() { PackSendQuestMgr.Instance.SendOpenWarehouse(); SetPlayerAttrActiveRedPoint(); EquipDecomRedCtrl(); StrengthAttrShift_RecordKey = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID,StrengthAttrShift_RecordKey); } public override void UnInit() { } PackModelInterface _modelInterface; PackModelInterface modelInterface { get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel()); } } ItemTipsModel _itemTipsModel; ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel()); } } public event Action RefreshPackAct; //刷新整个背包数据 public event Action RefreshItemCountAct; //(单个)最新物品数量刷新(旧的弃用)在得到新物品、物品数量的改变,清理该物品时均会触发 int 位置索引 int物品id public event Action GridRefreshEvent; //背包空格刷新 public event Action ItemCntAddAct; //物品数量增加 int 位置索引 int物品id public event Action ItemCntReduceAct; //物品数量减少的改变 int 位置索引 int物品id public event Action UseItemSuccessAct; //物品使用成功 int 位置索引 int物品id public event Action RefreshItemDayUseCntAct; //刷新物品每日使用数量 public event Action RefreshItemSumUseCntAct; //刷新物品总使用数量 public bool isPlayBetterEquipEffect { get;set;} //整理背包时是否播放特效 #region 接收服务端数据 public bool showDropItem { get; private set; } private Dictionary playerPackDict = new Dictionary(); private Dictionary itemGUIDDict = new Dictionary(); public void SetPlayerPackModel(H0725_tagRolePackRefreshEx packInfo) { showDropItem = false; SetLookIndex(null); PackType type = (PackType)packInfo.PackType; if (!playerPackDict.ContainsKey(type)) { SinglePackModel packModel = new SinglePackModel(type); playerPackDict.Add(type, packModel); } if(isPlayBetterEquipEffect) { modelInterface.itemModelDict.Clear(); } for (int i = 0; i < packInfo.ItemCount; i++) { ItemInfo itemInfo = new ItemInfo(); itemInfo.ItemID = (int)packInfo.ItemInfo[i].ItemID; itemInfo.ItemPlace = packInfo.ItemInfo[i].ItemPlace; itemInfo.ItemCount = packInfo.ItemInfo[i].ItemCount; itemInfo.RemainHour = (int)packInfo.ItemInfo[i].RemainHour; itemInfo.IsBind = packInfo.ItemInfo[i].IsBind; itemInfo.IsSuite = packInfo.ItemInfo[i].IsSuite; itemInfo.UserData = packInfo.ItemInfo[i].UserData; itemInfo.IsLocked = packInfo.ItemInfo[i].IsLocked; itemInfo.ItemGUID = packInfo.ItemInfo[i].ItemGUID; playerPackDict[type].SetPackModel(itemInfo); if (isPlayBetterEquipEffect) { modelInterface.SetBagSortBetterEquipList(GetItemModelByGUID(itemInfo.ItemGUID)); } //try //{ // if (RefreshItemCountAct != null) // { // RefreshItemCountAct(type, itemInfo.ItemPlace, itemInfo.ItemID); // } //} //catch (Exception ex) //{ // DesignDebug.Log(ex); //} } if (RefreshPackAct != null) { RefreshPackAct(type); } RedPointPackCtrl(type); } public void SetItemModel(H0704_tagRolePackRefresh item) { isPlayBetterEquipEffect = false; SetLookIndex(null); showDropItem = true; PackType type = (PackType)item.PackType; if (!playerPackDict.ContainsKey(type)) { SinglePackModel packModel = new SinglePackModel(type); playerPackDict.Add(type, packModel); } ItemInfo itemInfo = new ItemInfo(); itemInfo.ItemID = (int)item.ItemID; itemInfo.ItemPlace = item.ItemPlace; itemInfo.ItemCount = item.ItemCount; itemInfo.RemainHour = (int)item.RemainHour; itemInfo.IsBind = item.IsBind; itemInfo.IsSuite = item.IsSuite; itemInfo.UserData = item.UserData; itemInfo.IsLocked = item.IsLocked; itemInfo.ItemGUID = item.ItemGUID; playerPackDict[type].SetPackModel(itemInfo); DebugEx.Log("Add:" + item.ItemGUID); if(RefreshItemCountAct != null) { RefreshItemCountAct(type, itemInfo.ItemPlace, itemInfo.ItemID); } if (ItemCntAddAct != null) { ItemCntAddAct(type, itemInfo.ItemPlace, itemInfo.ItemID); } if (type == PackType.rptEquip) { SetPlayerAttrActiveRedPoint(); } RedPointPackCtrl(type); EquipDecomRedCtrl(); } public void SetOpenGridCount(H0724_tagRolePackCanUseCount useCount) { PackType type = (PackType)useCount.PackType; if (!playerPackDict.ContainsKey(type)) { SinglePackModel packModel = new SinglePackModel(type); playerPackDict.Add(type, packModel); } playerPackDict[type].SetOpenGridCount(useCount.CanUseCount); if(GridRefreshEvent != null) { GridRefreshEvent(type); } RedPointPackCtrl(type); } public void RefreshItemCount(H0707_tagItemCountRefresh refresh) { SetLookIndex(null); isPlayBetterEquipEffect = false; PackType type = (PackType)refresh.PackType; SinglePackModel singlePack = null; playerPackDict.TryGetValue(type,out singlePack); if(singlePack != null) { ItemModel itemModel = singlePack.GetItemModelByIndex(refresh.ItemIndex); if (itemModel != null) { bool isAddItemCount = false; if (refresh.ItemCount > itemModel.itemInfo.ItemCount) { isAddItemCount = true; } itemModel.RefreshItemCount(refresh.ItemCount); if(isAddItemCount) { if (ItemCntAddAct != null) { ItemCntAddAct(type,itemModel.itemInfo.ItemPlace, itemModel.itemInfo.ItemID); } modelInterface.GetPreciousItem(itemModel); modelInterface.RefreshPickItem(type,itemModel.itemInfo.ItemGUID); } else { if (ItemCntReduceAct != null) { ItemCntReduceAct(type, itemModel.itemInfo.ItemPlace, itemModel.itemInfo.ItemID); } } if (RefreshItemCountAct != null) { RefreshItemCountAct(type, itemModel.itemInfo.ItemPlace, itemModel.itemInfo.ItemID); } } } } public void ClearPackModel(H0711_tagClearItemPack clearPack) { PackType type = (PackType)clearPack.PackIndex; SinglePackModel singlePack = null; playerPackDict.TryGetValue(type, out singlePack); if(singlePack != null) { singlePack.ClearPackModel(); } if (type == PackType.rptEquip) { SetPlayerAttrActiveRedPoint(); } //if (RefreshPackAct != null) //{ // RefreshPackAct(type); //} //RedPointPackCtrl(type); } public void ClearItemModel(H0709_tagClearItem clearItem) { isPlayBetterEquipEffect = false; SetLookIndex(null); PackType type = (PackType)clearItem.PackType; SinglePackModel singlePack = null; playerPackDict.TryGetValue(type, out singlePack); string guid = ""; if (singlePack != null) { ItemModel itemModel = singlePack.GetItemModelByIndex(clearItem.ItemIndex); guid = itemModel.itemInfo.ItemGUID; int itemId = itemModel.itemInfo.ItemID; DeleteItemDictByGUID(type,itemModel.itemInfo.ItemGUID); singlePack.ClearItemModelByIndex(clearItem.ItemIndex); if (RefreshItemCountAct != null) { RefreshItemCountAct(type, clearItem.ItemIndex,itemId); } if (ItemCntReduceAct != null) { ItemCntReduceAct(type,clearItem.ItemIndex, itemId); } } if (type == PackType.rptEquip) { SetPlayerAttrActiveRedPoint(); } RedPointPackCtrl(type); EquipDecomRedCtrl(); if (GetItemModelByGUID(guid) == null) { KnapsackTimeCDMgr.Instance.UnRegister(guid); } } public void PackResetOk(H0316_tagPackResetOK packreset) { modelInterface.isPackResetOk = true; } public void UseItemSuccess(H0706_tagUseItemSuccess success) { isPlayBetterEquipEffect = false; SetLookIndex(null); if (success.PlayerID != PlayerDatas.Instance.baseData.PlayerID) return; ItemConfig itemConfig = Config.Instance.Get((int)success.ItemID); MakeUseItemSuccess(success.ItemIndex,(int)success.ItemID); switch (success.ItemID) { case 221: if (WindowCenter.Instance.CheckOpen()) { WindowCenter.Instance.CloseImmediately(); } break; } if (UseItemSuccessAct != null) { UseItemSuccessAct(success.ItemIndex,(int)success.ItemID); } } private void MakeUseItemSuccess(int index, int id) { ItemConfig itemConfig = Config.Instance.Get(id); if (itemConfig.CDType != 0) { float cdTime = (float)Math.Round((double)itemConfig.CDTime / 1000, 1); List modellist = null; GetSinglePackModel(PackType.rptItem).GetItemCountByType((int)ItemType.Buff, out modellist); for (int i = 0; i < modellist.Count; i++) { if (modellist[i].itemId == 901 || modellist[i].itemId == 902 || modellist[i].itemId == 903 || modellist[i].itemId == 904) { KnapsackTimeCDMgr.Instance.Register(modellist[i].itemInfo.ItemGUID, modellist[i].itemInfo.ItemID, cdTime); break; } } } } public void SetItemGUIDDict(ItemModel itemModel) { if(!itemGUIDDict.ContainsKey(itemModel.itemInfo.ItemGUID)) { itemGUIDDict.Add(itemModel.itemInfo.ItemGUID,itemModel); GetItemEventCtrl(itemModel); } else { PackType prePack = itemGUIDDict[itemModel.itemInfo.ItemGUID].packType; itemGUIDDict[itemModel.itemInfo.ItemGUID] = itemModel; if (prePack != itemModel.packType) { GetItemEventCtrl(itemModel); } } } public void DeleteItemDictByGUID(PackType type,string guid) { if(itemGUIDDict.ContainsKey(guid)) { if(itemGUIDDict[guid].packType == type) { itemGUIDDict.Remove(guid); } } } /// /// 物品每日使用的次数 /// private Dictionary itemDayUseCntDict = new Dictionary(); public void SetItemUseCnt(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(RefreshItemDayUseCntAct != null) { RefreshItemDayUseCntAct(itemId); } } } private Dictionary itemSumUseCntDict = new Dictionary(); public void SetItemSumUseCnt(HA339_tagMCAttrFruitEatCntList useCntInfo) { for (int i = 0; i < useCntInfo.count; i++) { int itemId = (int)useCntInfo.EatCntList[i].ItemID; int cnt = useCntInfo.EatCntList[i].EatCnt; if (!itemSumUseCntDict.ContainsKey(itemId)) { itemSumUseCntDict.Add(itemId, cnt); } else { itemSumUseCntDict[itemId] = cnt; } if (RefreshItemSumUseCntAct != null) { RefreshItemSumUseCntAct(itemId); } } } #region 接收全身星级,强化属性激活 public event Action RefreshActiveAttrAct; private Dictionary equipAttrActiveDict = new Dictionary(); public void SetPlayerEquipAttrActiveInfo(HA317_tagMCAllEquipAttrActiveInfo info) { for(int i = 0;i < info.Count; i++) { int type = info.ActiveInfo[i].Type; int cnt = (int)info.ActiveInfo[i].Cnt; if(!equipAttrActiveDict.ContainsKey(type)) { equipAttrActiveDict.Add(type,cnt); } else { equipAttrActiveDict[type] = cnt; } } if(RefreshActiveAttrAct != null) { RefreshActiveAttrAct(); } SetPlayerAttrActiveRedPoint(); } public void SendActiveAttrQuest(int type,int cnt) { CA503_tagCMActiveAllEquipAttr equipAttr = new CA503_tagCMActiveAllEquipAttr(); equipAttr.Type = (byte)type; equipAttr.Cnt = (uint)cnt; GameNetSystem.Instance.SendInfo(equipAttr); } public int GetActiveCntByType(int type) { int cnt = 0; equipAttrActiveDict.TryGetValue(type,out cnt); return cnt; } #endregion #endregion private void GetItemEventCtrl(ItemModel itemModel) { if (showDropItem) { bool isOverdue = false; if (itemModel.chinItemModel.ExpireTime > 0) { ItemCDCool cool = KnapsackTimeCDMgr.Instance.GetItemCoolById(itemModel.itemInfo.ItemGUID); switch ((EquipReduceType)itemModel.chinItemModel.EndureReduceType) { case EquipReduceType.Def_EquipReduceType_Time: List itemEffectTime = itemModel.GetUseDataModel((int)ItemUseDataKey.Def_IudetCreateTime); if (itemEffectTime != null && itemEffectTime[0] != 0) { if (cool == null || cool.GetRemainTime()<= 0) { isOverdue = true; } } break; case EquipReduceType.Def_EquipReduceType_RTimeItem: if (cool == null || cool.GetRemainTime() <= 0) { isOverdue = true; } break; } } if (!isOverdue) { modelInterface.GetPreciousItem(itemModel); modelInterface.OnGetEquip(itemModel); modelInterface.RefreshPickItem(itemModel.packType,itemModel.itemInfo.ItemGUID); } } } /// /// 得到某个包裹的所有数据 /// /// /// public SinglePackModel GetSinglePackModel(PackType type) { SinglePackModel singlePack = null; playerPackDict.TryGetValue(type, out singlePack); return singlePack; } public ItemModel GetItemModelByGUID(string guid) { ItemModel itemModel = null; itemGUIDDict.TryGetValue(guid, out itemModel); return itemModel; } public ItemModel GetItemModelByIndex(PackType type,int index) { ItemModel itemModel = null; if (playerPackDict.ContainsKey(type)) { itemModel = playerPackDict[type].GetItemModelByIndex(index); } return itemModel; } public string GetItemGUIDByID(int itemId) { string guid = string.Empty; foreach(var key in itemGUIDDict.Keys) { if(itemGUIDDict[key].itemId == itemId) { guid = key; return guid; } } return guid; } /// /// 得到ID相同的物品数量 /// /// /// /// public int GetItemCountByID(PackType type, int id) { int count = 0; SinglePackModel singlePack = GetSinglePackModel(type); if (singlePack != null) { count = singlePack.GetItemCountByID(id); } return count; } public bool CheckBagIsPutNewItem(int itemId) { SinglePackModel singlePack = GetSinglePackModel(PackType.rptItem); if (singlePack == null) return false; List modellist = null; int haveCnt = singlePack.GetItemCountByID(itemId,out modellist); ItemConfig config = Config.Instance.Get(itemId); int sumPutCnt = config.PackCount * modellist.Count; if(sumPutCnt > haveCnt) { return true; } else if(GetReaminGridCount(PackType.rptItem) > 0) { return true; } return false; } public int GetReaminGridCount(PackType type) { int count = 0; SinglePackModel singlePack = GetSinglePackModel(type); if (singlePack != null) { count = singlePack.GetRemainGridCount(); } return count; } /// /// 得到物品今日使用次数 /// /// /// public int GetDayUseCntByID(int itemId) { int useCnt = 0; itemDayUseCntDict.TryGetValue(itemId, out useCnt); return useCnt; } /// /// 得到物品总使用次数 /// /// /// public int GetSumUseCntByID(int itemId) { int useCnt = 0; itemSumUseCntDict.TryGetValue(itemId, out useCnt); return useCnt; } public void SetWashAttrPointModel(string guid) { ItemModel itemModel = GetItemModelByGUID(guid); if (itemModel == null) return; WashAttrPointWin.itemModel = itemModel; WindowCenter.Instance.Open(); } #region 红点逻辑判断 public const int ITEMPACK_REDKEY = 102011003; public Redpoint redpointItemPack = new Redpoint(MainRedDot.RedPoint_BagFuncKey, ITEMPACK_REDKEY); private void RedPointPackCtrl(PackType type) { SinglePackModel singlePack = GetSinglePackModel(type); if (singlePack == null) return; switch (type) { case PackType.rptItem: if (singlePack.GetRemainGridCount() <= 0) { redpointItemPack.state = RedPointState.Full; SysNotifyMgr.Instance.ShowTip("BagFull"); } else { redpointItemPack.state = RedPointState.None; } break; case PackType.rptWarehouse: if (singlePack.GetRemainGridCount() <= 0) { MainRedDot.Instance.redPointDepotFunc.state = RedPointState.Full; } else { MainRedDot.Instance.redPointDepotFunc.state = RedPointState.None; } break; } } //public const int PLAYERSUMSTR_REDKEY = 102011001; public const int PLAYERSUMSTAR_REDKEY = 102011002; // public Redpoint redpointSTR = new Redpoint(MainRedDot.RedPoint_BagFuncKey, PLAYERSUMSTR_REDKEY); public Redpoint redpointSTAR = new Redpoint(MainRedDot.RedPoint_BagFuncKey, PLAYERSUMSTAR_REDKEY); public event Action RefreshAttrActiveAct; public void SetPlayerAttrActiveRedPoint() { if(IsActiveStarAttr()) { if (redpointSTAR.state != RedPointState.Simple) { redpointSTAR.state = RedPointState.Simple; if (RefreshAttrActiveAct != null) { RefreshAttrActiveAct(1, true); } } } else { if (redpointSTAR.state != RedPointState.None) { redpointSTAR.state = RedPointState.None; if (RefreshAttrActiveAct != null) { RefreshAttrActiveAct(1, false); } } } } public bool IsActiveStarAttr() { List starslist = RoleEquipStarsConfig.GetEquipStarsCntlist(); SinglePackModel singlePack = GetSinglePackModel(PackType.rptEquip); if (singlePack == null || starslist == null || starslist.Count < 1) return false; Dictionary _itemDict = singlePack.GetPackModelIndexDict(); int playerSumStars = 0; foreach (var model in _itemDict.Values) { playerSumStars += model.chinItemModel.StarLevel; } int cnt = GetActiveCntByType(1); int nextActiveStars = 0; for (int i = 0; i < starslist.Count; i++) { if(cnt == 0) { nextActiveStars = starslist[0]; break; } else { if (starslist[i] == cnt) { if (i < starslist.Count - 1) { nextActiveStars = starslist[i + 1]; } break; } } } if(nextActiveStars != 0 && playerSumStars >= nextActiveStars) { return true; } return false; } public bool IsActiveSTRAttr() { List strenlist = Config.Instance.GetAllKeys(); if (strenlist == null || strenlist.Count < 1) return false; int playerSumSTR = 0; Dictionary strenInfoDict = ModelCenter.Instance.GetModel()._EqInfo; foreach (var value in strenInfoDict.Values) { ItemModel itemModel = GetItemModelByIndex(PackType.rptEquip, value.EquipIndex); if (itemModel != null) { playerSumSTR += value.EquipPartStarLV; } } int cnt = GetActiveCntByType(0); int nextActiveSTR = 0; for (int i = 0; i < strenlist.Count; i++) { if(cnt == 0) { nextActiveSTR = int.Parse(strenlist[0]); break; } else { if (int.Parse(strenlist[i]) == cnt) { if (i < strenlist.Count - 1) { nextActiveSTR = int.Parse(strenlist[i + 1]); } break; } } } if (nextActiveSTR != 0 && playerSumSTR >= nextActiveSTR) { return true; } return false; } public const int EquipDecompose_RedKey = 10205; public Redpoint redpointEquipDecom = new Redpoint(MainRedDot.RedPoint_MainPackKey, EquipDecompose_RedKey); public void EquipDecomRedCtrl() { if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.EquipDecompose)) return; if(GetCanDevourModellist() != null && GetCanDevourModellist().Count > 0) { redpointEquipDecom.state = RedPointState.Simple; } else { redpointEquipDecom.state = RedPointState.None; } } #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) { if (string.IsNullOrEmpty(guid) || guid == "") { lookLineIndex = -1; } else { int index = GetItemModelByGUID(guid).itemInfo.ItemPlace; lookLineIndex = index / singleRowCount; lookItemGUID = guid; } if (lookEquipEvent != null) { lookEquipEvent(); } } #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 itemUseAct; private Dictionary itemUseTypeDict = new Dictionary(); //key SkillTypeID,value 使用物品的ID private void OnStageLoadFinish() { itemUseTypeDict.Clear(); if (PlayerDatas.Instance.baseData.MapID == cacheMapId) { return; } cacheMapId = PlayerDatas.Instance.baseData.MapID; int[] useDrugs = GetDrugIDListByDungeonID(cacheMapId); if (useDrugs == null) return; SinglePackModel singlePack = GetSinglePackModel(PackType.rptItem); for(int i = 0; i < useDrugs.Length; i++) { SkillConfig skillConfig = GetSkillConfig(useDrugs[i]); if(skillConfig != null) { if(!itemUseTypeDict.ContainsKey(skillConfig.SkillTypeID)) { itemUseTypeDict.Add(skillConfig.SkillTypeID,useDrugs[i]); } else { SkillConfig preSkillConfig = GetSkillConfig(itemUseTypeDict[skillConfig.SkillTypeID]); if(skillConfig.SkillLV > preSkillConfig.SkillLV) { itemUseTypeDict[skillConfig.SkillTypeID] = useDrugs[i]; } } } } foreach(int itemId in itemUseTypeDict.Values) { List modellist = null; singlePack.GetItemCountByID(itemId, out modellist); if (modellist.Count > 0) { ItemModel itemModel = modellist[0]; bool isExist = StatusMgr.Instance.IsExist(PlayerDatas.Instance.hero.ServerInstID, itemModel.chinItemModel.AddSkill1); DebugEx.Log("Buff是否存在" + isExist); if (itemUseAct != null && !isExist) { itemUseAct(PackType.rptItem, itemModel.itemInfo.ItemGUID); } } } } public SkillConfig GetSkillConfig(int itemId) { ItemConfig itemConfig = Config.Instance.Get(itemId); SkillConfig skillConfig = Config.Instance.Get(itemConfig.AddSkill1); return skillConfig; } public int GetDungeonIDByDrugID(int drugID) { int dungeonID = 0; DrugToDungeonDict.TryGetValue(drugID, out dungeonID); return dungeonID; } public int[] GetDrugIDListByDungeonID(int dungeonID) { int[] drugIDlist = null; DungeonToDrugDict.TryGetValue(dungeonID, out drugIDlist); return drugIDlist; } #endregion #region 判断物品是否达到使用上限 public bool IsReachUseLimit(string guid,out ulong count) { count = 0; ItemModel itemModel = GetItemModelByGUID(guid); if (itemModel == null) return false; AttrFruitConfig fruitConfig = Config.Instance.Get(itemModel.itemInfo.ItemID); int haveUseCnt = GetDayUseCntByID(itemModel.itemInfo.ItemID); int sumHaveUseCnt = GetSumUseCntByID(itemModel.itemInfo.ItemID); count = (ulong)itemModel.itemInfo.ItemCount; bool isReach = false; int remainDayCnt = 0; if (itemModel.chinItemModel.MaxSkillCnt > 0) { remainDayCnt = itemModel.chinItemModel.MaxSkillCnt - haveUseCnt; if (itemModel.itemInfo.ItemCount > remainDayCnt) { count = (ulong)remainDayCnt; } } int remainSumCnt = 0; if (fruitConfig != null) { remainSumCnt = fruitConfig.MaxUseCnt - sumHaveUseCnt; if (remainSumCnt <= remainDayCnt && itemModel.itemInfo.ItemCount > remainSumCnt) { count = (ulong)remainSumCnt; } } if(count < (ulong)itemModel.itemInfo.ItemCount) { isReach = true; } return isReach; } #endregion #region 物品吞噬逻辑处理 public EquipColorType colorType { get; private set; } public EquipLvType lvType { get; private set; } public EquipStarType starType { get; private set; } public event Action RefreshColorSelectAct; public event Action RefreshLvSelectAct; public event Action RefreshStarSelectAct; public event Action RefreshEquipDecomNumAct; public int[] defaultUnSelectlist { get; private set; } public bool ContainPreciousItem(List itemModels,out int betterEquipCnt,out int preciousCnt) { betterEquipCnt = 0; preciousCnt = 0; if (itemModels == null) return false; for(int i = 0; i < itemModels.Count; i++) { if(defaultUnSelectlist.Contains(itemModels[i].itemId)) { preciousCnt += itemModels[i].itemInfo.ItemCount; } else if(modelInterface.IsFightUp(itemModels[i].itemId,itemModels[i].equipScore) == 1) { betterEquipCnt += itemModels[i].itemInfo.ItemCount; } } if(betterEquipCnt > 0 || preciousCnt > 0) { return true; } return false; } public bool ContainTwoStarEquip(List itemModels, out int twoStarEquipCnt) { twoStarEquipCnt = 0; if (itemModels == null) return false; for (int i = 0; i < itemModels.Count; i++) { if(itemModels[i].chinItemModel.StarLevel >= 2 && itemModels[i].chinItemModel.ItemColor >= (int)E_ItemColor.Orange) { twoStarEquipCnt += itemModels[i].itemInfo.ItemCount; } } if (twoStarEquipCnt > 0) { return true; } return false; } public void SetColorSelect(EquipColorType type) { colorType = type; if (colorType == EquipColorType.None) { if(lvType != EquipLvType.None) { SetLvSelect(EquipLvType.None); } } else { if (lvType == EquipLvType.None) { SetLvSelect(EquipLvType.All); } } if (RefreshColorSelectAct != null) { RefreshColorSelectAct(type); } SendEquipDevourRecordQuest(); EquipDecomRedCtrl(); } public void SetLvSelect(EquipLvType type) { lvType = type; if (lvType == EquipLvType.None) { if (colorType != EquipColorType.None) { SetColorSelect(EquipColorType.None); } } else { if (colorType == EquipColorType.None) { SetColorSelect(EquipColorType.Purple); } } if (RefreshLvSelectAct != null) { RefreshLvSelectAct(type); } SendEquipDevourRecordQuest(); EquipDecomRedCtrl(); } public void SetStarSelect(EquipStarType type) { starType = type; if (RefreshStarSelectAct != null) { RefreshStarSelectAct(type); } SendEquipDevourRecordQuest(); EquipDecomRedCtrl(); } public List devourPlacelist { get; private set; } public int MaxDevourEquipNum { get; private set; } public void SetDevourEquipPlace() { devourPlacelist = new List(); FuncConfigConfig funcConfig = Config.Instance.Get("PetAbsorbType"); int[] placeArray = ConfigParse.GetMultipleStr(funcConfig.Numerical1); for(int i = 0; i < placeArray.Length;i++ ) { devourPlacelist.Add(placeArray[i]); } MaxDevourEquipNum = int.Parse(funcConfig.Numerical2); } List devourModellist = new List(); List orderDevourModellist = new List(); public List GetDevourModellist() { SinglePackModel singlePack = GetSinglePackModel(PackType.rptItem); if (singlePack == null) return null; devourModellist.Clear(); orderDevourModellist.Clear(); foreach (var model in singlePack.GetPackModelIndexDict().Values) { if(model.chinItemModel.Type == 29) { devourModellist.Add(model); } else { if (devourPlacelist.Contains(model.chinItemModel.EquipPlace)) { if (model.chinItemModel.ItemColor >= (int)E_ItemColor.Purple) { devourModellist.Add(model); } } } } orderDevourModellist.AddRange(devourModellist); orderDevourModellist.Sort(CompareByColor); return orderDevourModellist; } public int CompareByColor(ItemModel start, ItemModel next) { bool typeX = start.chinItemModel.Type == 29 ? true : false; bool typeY = next.chinItemModel.Type == 29 ? true : false; if (typeX.CompareTo(typeY) != 0) return -typeX.CompareTo(typeY); int colorX = start.chinItemModel.ItemColor; int colorY = next.chinItemModel.ItemColor; if (colorX.CompareTo(colorY) != 0) return colorX.CompareTo(colorY); int startIndex = devourModellist.IndexOf(start); int nextIndex = devourModellist.IndexOf(next); if (startIndex.CompareTo(nextIndex) != 0) return startIndex.CompareTo(nextIndex); return 0; } public List canDevourModellist = new List(); public List GetCanDevourModellist() { canDevourModellist.Clear(); SinglePackModel singlePack = GetSinglePackModel(PackType.rptItem); if (singlePack == null || colorType == EquipColorType.None || lvType == EquipLvType.None) { if (RefreshEquipDecomNumAct != null) { RefreshEquipDecomNumAct(); } return null; } foreach (var model in singlePack.GetPackModelIndexDict().Values) { if(model.chinItemModel.Type == 29) { if(!defaultUnSelectlist.Contains(model.itemId)) { canDevourModellist.Add(model); } } else { if (IsCanDevour(model)) { canDevourModellist.Add(model); } } } if(RefreshEquipDecomNumAct != null) { RefreshEquipDecomNumAct(); } return canDevourModellist; } public bool IsCanDevour(ItemModel model) { if (devourPlacelist.Contains(model.chinItemModel.EquipPlace)) { if (model.chinItemModel.ItemColor >= (int)E_ItemColor.Purple) { if (modelInterface.IsFightUp(model.itemId, model.equipScore) != 1) { if (model.chinItemModel.ItemColor <= (int)colorType && model.chinItemModel.LV <= (int)lvType && model.chinItemModel.StarLevel <= (int)starType) { return true; } } } } return false; } public bool IsMaxDecomLv(int decomLv,out int realLv) { realLv = decomLv; List decomlist = Config.Instance.GetAllValues(); if(decomLv > decomlist[decomlist.Count-1].LV) { realLv = decomlist[decomlist.Count - 1].LV; return true; } return false; } public List selectDevourlist = new List(); public void GetSelectDevourList() { GetCanDevourModellist(); selectDevourlist.Clear(); selectDevourlist.AddRange(canDevourModellist); } public void RefreshGetNewItem(ItemModel model) { if (model == null) return; if(CheckIsReachDevourCondi(model)) { selectDevourlist.Add(model); if (RefreshEquipDecomNumAct != null) { RefreshEquipDecomNumAct(); } } } public void AddSelectDevourModellist(ItemModel model) { selectDevourlist.Add(model); if (RefreshEquipDecomNumAct != null) { RefreshEquipDecomNumAct(); } } public bool CheckIsReachDevourCondi(ItemModel model) { if (model.chinItemModel.Type == 29) { if (!defaultUnSelectlist.Contains(model.itemId)) { return true; } return false; } else { if (IsCanDevour(model)) { return true; } } return false; } public void RemoveSelectDevourModellist(ItemModel model) { if(selectDevourlist.Contains(model)) { selectDevourlist.Remove(model); } if (RefreshEquipDecomNumAct != null) { RefreshEquipDecomNumAct(); } } public Dictionary GetDecomAttrDictByLv(int decomLv) { if(decomposeAttrDict.ContainsKey(decomLv)) { return decomposeAttrDict[decomLv]; } return null; } public void SendEquipdevourQuest() { if (canDevourModellist.Count < minDecomposeNum) return; isAutoDecompose = true; recordAutoDecomNum = canDevourModellist.Count; CA32C_tagCMEquipDecompose _petEat = new CA32C_tagCMEquipDecompose(); byte[] _petIndex = new byte[canDevourModellist.Count]; for (int i = 0; i < canDevourModellist.Count; i++) { _petIndex[i] = (byte)canDevourModellist[i].itemInfo.ItemPlace; } _petEat.IndexCount = (byte)_petIndex.Length; _petEat.IndexList = _petIndex; GameNetSystem.Instance.SendInfo(_petEat); } public void SendEquipDevourRecordQuest() { string record = StringUtility.Contact((int)colorType + 1,(int)lvType + 1,(int)starType + 1); CA32D_tagCMDecomposeSeting decomSet = new CA32D_tagCMDecomposeSeting(); decomSet.Seting = uint.Parse(record); GameNetSystem.Instance.SendInfo(decomSet); } public int decomposeLv { get; private set; } public int decomposeExp { get; private set; } public int decomposeProgress { get; private set; } public int addDecomposeExp { get; private set;} public int minDecomposeNum { get; private set; } public bool isAutoDecompose { get;set; } public int recordAutoDecomNum { get; private set;} public DecomposeGetMatInfo[] getItems { get; private set; } public event Action RefreshDecomAttrAct; public void GetServerDecomposeSet(HA31C_tagMCEquipDecomposeInfo info) { addDecomposeExp = 0; int realLv = info.LV + 1; bool isMax = IsMaxDecomLv(realLv,out realLv); if (realLv == decomposeLv) { addDecomposeExp = (int)info.Exp - decomposeExp; } else { for(int i = decomposeLv; i <= realLv; i++ ) { EquipDeComposeConfig deComposeConfig = Config.Instance.Get(i); if (i == decomposeLv) { addDecomposeExp = deComposeConfig.UpNeedExp - decomposeExp; } else if(i == realLv) { addDecomposeExp += (int)info.Exp; } else { addDecomposeExp += deComposeConfig.UpNeedExp; } } } decomposeLv = realLv; decomposeExp = (int)info.Exp; decomposeProgress = info.DecomposeCnt; getItems = JsonMapper.ToObject(info.GetItemData); if (info.Seting != 0) { string decomSetStr = info.Seting.ToString(); string colorStr = decomSetStr.Substring(0, 1); colorType = (EquipColorType)(int.Parse(colorStr) - 1); starType = (EquipStarType)((int)info.Seting % 10 - 1); string lvStr = decomSetStr.Substring(1, decomSetStr.Length - 2); lvType = (EquipLvType)(int.Parse(lvStr) - 1); } if(RefreshDecomAttrAct != null) { RefreshDecomAttrAct(); } } /// /// 设置获得炼丹材料的展示数据 /// /// /// private List getMatInfos = new List(); public List SetShowMatInfo() { getMatInfos.Clear(); int sumMatCnt = 0; if(getItems != null) { for(int i = 0; i < getItems.Length; i++) { if(getItems[i].Count > 0) { sumMatCnt += getItems[i].Count; } else { sumMatCnt += 1; } } } if(sumMatCnt > 5) { for (int i = 0; i < getItems.Length; i++) { getMatInfos.Add(getItems[i]); } } else { if (getItems != null) { for (int i = 0; i < getItems.Length; i++) { if (getItems[i].Count > 0) { for(int j = 0; j < getItems[i].Count; j++) { DecomposeGetMatInfo matInfo = new DecomposeGetMatInfo(); matInfo.ItemID = getItems[i].ItemID; matInfo.Count = 1; matInfo.IsBind = getItems[i].IsBind; matInfo.IsSuite = getItems[i].IsSuite; matInfo.UserData = getItems[i].UserData; getMatInfos.Add(matInfo); } } else { getMatInfos.Add(getItems[i]); } } } } return getMatInfos; } public enum EquipColorType { None = 0, Purple = 3, Orange = 4, Red = 5, All = 10, } public enum EquipLvType { None = 0, One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen, All, } public enum EquipStarType { None = 0, One, Two, Three, All, } public class DecomposeGetMatInfo { public int ItemID; public int Count; public int IsBind; public int IsSuite; public string UserData; } #endregion #region 丹药逻辑处理 private int CompareMakeDrug(AttrFruitConfig start, AttrFruitConfig end) { ItemConfig configS = Config.Instance.Get(start.ID); ItemConfig configE = Config.Instance.Get(end.ID); if (configS.RealmLimit.CompareTo(configE.RealmLimit) != 0) { return configS.RealmLimit.CompareTo(configE.RealmLimit); } if (configS.LV.CompareTo(configE.LV) != 0) { return configS.LV.CompareTo(configE.LV); } return 0; } List drugOrderlist = new List(); public List GetDrugOrderByCnt() { drugOrderlist.Clear(); drugOrderlist.AddRange(makeDruglist); drugOrderlist.Sort(CompareByIsHave); return drugOrderlist; } public bool CheckIsDrugById(int itemId) { for(int i = 0; i < makeDruglist.Count; i++) { if(makeDruglist[i].ID == itemId) { return true; } } return false; } public int CompareByIsHave(AttrFruitConfig start, AttrFruitConfig end) { bool isHaveStart = IsHaveDrugUse(start); bool isHaveEnd = IsHaveDrugUse(end); if (isHaveStart.CompareTo(isHaveEnd) != 0) return -isHaveStart.CompareTo(isHaveEnd); //isHaveStart = IsHaveDrugRecycle(start); //isHaveEnd = IsHaveDrugRecycle(end); //if (isHaveStart.CompareTo(isHaveEnd) != 0) return -isHaveStart.CompareTo(isHaveEnd); isHaveStart = GetItemCountByID(PackType.rptItem,start.ID) > 0 ? true : false; isHaveEnd = GetItemCountByID(PackType.rptItem, end.ID) > 0 ? true : false; if (isHaveStart.CompareTo(isHaveEnd) != 0) return isHaveStart.CompareTo(isHaveEnd); isHaveStart = IsReachMaxUseDrug(start); isHaveEnd = IsReachMaxUseDrug(end); if (isHaveStart.CompareTo(isHaveEnd) != 0) return isHaveStart.CompareTo(isHaveEnd); int x = makeDruglist.IndexOf(start); int y = makeDruglist.IndexOf(end); if (x.CompareTo(y) != 0) return x.CompareTo(y); return 0; } public bool IsHaveDrugUse(AttrFruitConfig fruitConfig) { if(!IsReachMaxUseDrug(fruitConfig)) { return GetItemCountByID(PackType.rptItem, fruitConfig.ID) > 0 ? true : false; } return false; } public bool IsHaveDrugRecycle(AttrFruitConfig fruitConfig) { if (IsReachMaxUseDrug(fruitConfig)) { return GetItemCountByID(PackType.rptItem, fruitConfig.ID) > 0 ? true : false; } return false; } public bool IsReachMaxUseDrug(AttrFruitConfig fruitConfig) { if (fruitConfig == null) return false; int useNum = GetSumUseCntByID(fruitConfig.ID); if(useNum >= fruitConfig.MaxUseCnt) { return true; } return false; } List limitlist = new List(); public float GetAlchemyProgress(AlchemyConfig alchemy) { var previewDanlist = FurnaceModel.GetPreviewMakeDruglist(alchemy).Keys.ToList(); float progress = 0; limitlist.Clear(); for (int i = 0; i < previewDanlist.Count; i++) { AttrFruitConfig fruitConfig = Config.Instance.Get(previewDanlist[i]); if(fruitConfig != null) { limitlist.Add(fruitConfig); } } for(int i = 0; i < limitlist.Count; i++) { progress += ((float)1 / limitlist.Count) *((float)GetSumUseCntByID(limitlist[i].ID)/limitlist[i].MaxUseCnt); } return progress*100; } #endregion } }