using System; using System.Collections.Generic; using System.Linq; using System.Text; using Snxxz.UI; using LitJson; [XLua.LuaCallCSharp] public class ComposeWinModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { public event Action UpdateSendComposeEvent; public event Action ResetModelEvent; SelectEquipModel selectModel { get { return ModelCenter.Instance.GetModel(); } } PackModel playerPack { get { return ModelCenter.Instance.GetModel(); } } ItemTipsModel itemTipsModel { get { return ModelCenter.Instance.GetModel(); } } GetItemPathModel itemPathModel { get { return ModelCenter.Instance.GetModel(); } } private bool isUpdatePlayerLv; public override void Init() { ParseFuncConfig(); ParseItemComoundConfig(); SetComposeTypeRed(); } public override void UnInit() { } public void OnBeforePlayerDataInitialize() { isUpdatePlayerLv = false; secondType = 0; thirdType = 0; GlobalTimeEvent.Instance.secondEvent -= UpdateSecond; playerPack.refreshItemCountEvent -= OnItemCntRefresh; PlayerDatas.Instance.playerDataRefreshEvent -= PlayerLvUpdate; } public void OnPlayerLoginOk() { GlobalTimeEvent.Instance.secondEvent += UpdateSecond; playerPack.refreshItemCountEvent += OnItemCntRefresh; PlayerDatas.Instance.playerDataRefreshEvent += PlayerLvUpdate; UpdateComposeDataByLevel(); RefreshComposeRed(); } public void ResetModel() { if (ResetModelEvent != null) { ResetModelEvent(); } } private void UpdateSecond() { if (isUpdatePlayerLv) { UpdateComposeDataByLevel(); RefreshComposeRed(); isUpdatePlayerLv = false; } } private void PlayerLvUpdate(PlayerDataType type) { if (type != PlayerDataType.LV) return; isUpdatePlayerLv = true; } #region 解析本地数据 private FuncConfigConfig addonsFormulaModel; private Dictionary> composeJobLimitDict = new Dictionary>(); public void ParseFuncConfig() { addonsFormulaModel = FuncConfigConfig.Get("ComposeAddonsFormula"); composeJobLimitDict.Clear(); FuncConfigConfig funcConfig = FuncConfigConfig.Get("ComposeJobLimit"); JsonData limitData = JsonMapper.ToObject(funcConfig.Numerical1); foreach (var job in limitData.Keys) { List idlist = new List(); composeJobLimitDict.Add(int.Parse(job), idlist); if (limitData[job].IsArray) { for (int i = 0; i < limitData[job].Count; i++) { int id = int.Parse(limitData[job][i].ToString()); idlist.Add(id); } } } } public Dictionary composeDataDict = new Dictionary(); public void ParseItemComoundConfig() { composeDataDict.Clear(); List itemCompounds = ItemCompoundConfig.GetValues(); for (int i = 0; i < itemCompounds.Count; i++) { AddComposeData(itemCompounds[i], composeDataDict); } } public void AddComposeData(ItemCompoundConfig itemCompound, Dictionary keyValues) { if (itemCompound == null) return; if (!keyValues.ContainsKey(itemCompound.firstType)) { var firstData = new ComposeFirstTypeData(); firstData.firstType = itemCompound.firstType; firstData.secondTypeDict = new Dictionary(); ComposeSecondTypeData secondData = new ComposeSecondTypeData(); secondData.secondType = itemCompound.secondType; secondData.thirdTypeDict = new Dictionary>(); List thirdTypeDatas = new List(); ComposeThirdTypeData thirdData = new ComposeThirdTypeData(); thirdData.thirdType = itemCompound.thirdType; thirdData.itemCompound = itemCompound; thirdTypeDatas.Add(thirdData); firstData.secondTypeDict.Add(secondData.secondType, secondData); secondData.thirdTypeDict.Add(thirdData.thirdType, thirdTypeDatas); keyValues.Add(firstData.firstType, firstData); } else { ComposeSecondTypeData secondData = new ComposeSecondTypeData(); secondData.secondType = itemCompound.secondType; var secondTypeDict = keyValues[itemCompound.firstType].secondTypeDict; if (!secondTypeDict.ContainsKey(secondData.secondType)) { secondTypeDict.Add(secondData.secondType, secondData); secondData.thirdTypeDict = new Dictionary>(); List thirdTypeDatas = new List(); ComposeThirdTypeData thirdData = new ComposeThirdTypeData(); thirdData.thirdType = itemCompound.thirdType; thirdData.itemCompound = itemCompound; thirdTypeDatas.Add(thirdData); secondData.thirdTypeDict.Add(thirdData.thirdType, thirdTypeDatas); } else { ComposeThirdTypeData thirdData = new ComposeThirdTypeData(); thirdData.thirdType = itemCompound.thirdType; thirdData.itemCompound = itemCompound; var thirdTypeDict = secondTypeDict[secondData.secondType].thirdTypeDict; if (!thirdTypeDict.ContainsKey(thirdData.thirdType)) { List thirdTypeDatas = new List(); thirdTypeDatas.Add(thirdData); thirdTypeDict.Add(thirdData.thirdType, thirdTypeDatas); } else { thirdTypeDict[thirdData.thirdType].Add(thirdData); } } } } public class ComposeFirstTypeData { public int firstType; public Dictionary secondTypeDict = null; } public class ComposeSecondTypeData { public int secondType; public Dictionary> thirdTypeDict = null; } public class ComposeThirdTypeData { public int thirdType; public ItemCompoundConfig itemCompound = null; } #endregion #region 数据变动 public Dictionary composeOpenDataDict = new Dictionary(); public void UpdateComposeDataByLevel() { composeOpenDataDict.Clear(); int playerLv = PlayerDatas.Instance.baseData.LV; foreach (var first in composeDataDict.Keys) { var secondTypeDict = composeDataDict[first].secondTypeDict; foreach (var second in secondTypeDict.Keys) { var thirdTypeDict = secondTypeDict[second].thirdTypeDict; foreach (var third in thirdTypeDict.Keys) { for (int i = 0; i < thirdTypeDict[third].Count; i++) { var thirdData = thirdTypeDict[third][i]; if (playerLv >= thirdData.itemCompound.levelNeed || (thirdData.itemCompound.trailerLevel != 0 && playerLv >= thirdData.itemCompound.trailerLevel)) { AddComposeData(thirdData.itemCompound, composeOpenDataDict); } } } } } } public bool TryGetFirstTypeData(int firstType, out ComposeFirstTypeData firstTypeData) { firstTypeData = null; return composeOpenDataDict.TryGetValue(firstType, out firstTypeData); } public bool TryGetSecondTypeData(int firstType, int secondType, out ComposeSecondTypeData secondTypeData) { ComposeFirstTypeData firstTypeData = null; secondTypeData = null; bool isFirst = TryGetFirstTypeData(firstType, out firstTypeData); if (isFirst) { return firstTypeData.secondTypeDict.TryGetValue(secondType, out secondTypeData); } return false; } public bool TryGetThirdTypeData(int firstType, int secondType, int thirdType, out List thirdTypeDatas) { ComposeSecondTypeData secondTypeData = null; thirdTypeDatas = null; bool isSecond = TryGetSecondTypeData(firstType, secondType, out secondTypeData); if (isSecond) { return secondTypeData.thirdTypeDict.TryGetValue(thirdType, out thirdTypeDatas); } return false; } public bool TryGetThirdTypeData(int firstType, int secondType, int thirdType, out ComposeThirdTypeData thirdTypeData) { ComposeSecondTypeData secondTypeData = null; thirdTypeData = null; bool isSecond = TryGetSecondTypeData(firstType, secondType, out secondTypeData); if (isSecond) { List thirdTypeDatas = null; bool isThird = secondTypeData.thirdTypeDict.TryGetValue(thirdType, out thirdTypeDatas); if (isThird) { thirdTypeData = thirdTypeDatas[0]; return true; } } return false; } public ItemCompoundConfig CurComposeModel { get; private set; } public void SetCurComposeModel(ItemCompoundConfig compoundModel) { CurComposeModel = compoundModel; } public event Action UpdateThirdTypeEvent; public void UpdateThirdType(int thirdType) { if (UpdateThirdTypeEvent != null) { UpdateThirdTypeEvent(thirdType); } } public event Action UpdateSecondTypeEvent; public void UpdateSecondType(int secondType) { if (UpdateSecondTypeEvent != null) { UpdateSecondTypeEvent(secondType); } } public event Action UpdateReduceEvent; public void UpdateReduce(ComposeMatCell matCell, NeedMatType matType) { if (UpdateReduceEvent != null) { UpdateReduceEvent(matCell, matType); } } public event Action UpdateEquipTypeEvent; public void UpdateComposeEquipPlace(ItemCompoundConfig itemCompound, int equipIndex) { if (UpdateEquipTypeEvent != null) { UpdateEquipTypeEvent(itemCompound, equipIndex); } } public bool TryGetIncreaseRateItemIndex(ItemCompoundConfig itemCompound, bool IsIncrease, out List indexlist) { indexlist = null; if (!IsIncrease || itemCompound == null) return false; SinglePack singlePack = playerPack.GetSinglePack(PackType.Item); int[] increases = itemCompound.successRateIncrease; indexlist = singlePack.GetItemIndexsAppointedCount(increases[0], increases[1]); return true; } public bool TryGetCountById(NeedMatType matType, ItemCompoundConfig itemCompound, int itemId, out int itemCount) { itemCount = 0; if (itemCompound == null || itemId == 0) return false; switch (matType) { case NeedMatType.IncreaseItem: int[] increases = itemCompound.successRateIncrease; if (increases != null && increases.Length >= 3) { itemCount = increases[1]; return true; } break; case NeedMatType.fixedItem: int[] fixedIds = itemCompound.itemID; int[] fixedCounts = itemCompound.itemCount; int[] fixedDisplays = itemCompound.itemDisplay; if (fixedIds != null) { for (int i = 0; i < fixedIds.Length; i++) { if (fixedIds[i] == itemId) { itemCount = fixedCounts[i]; return true; } } } break; } return false; } public bool TryGetIdByDisplay(NeedMatType matType, ItemCompoundConfig itemCompound, int display, out int itemId) { itemId = 0; if (itemCompound == null || display == 0) return false; switch (matType) { case NeedMatType.fixedItem: int[] fixedIds = itemCompound.itemID; int[] fixedDisplays = itemCompound.itemDisplay; if (fixedDisplays != null) { for (int i = 0; i < fixedDisplays.Length; i++) { if (fixedDisplays[i] == display) { itemId = fixedIds[i]; return true; } } } break; } return false; } public bool TryGetItemCompoundByMakeId(int _ticketId, out ItemCompoundConfig itemCompound) { itemCompound = null; foreach (var first in composeOpenDataDict.Keys) { var secondTypeDic = composeOpenDataDict[first].secondTypeDict; foreach (var second in secondTypeDic.Keys) { var thirdTypeDic = secondTypeDic[second].thirdTypeDict; foreach (var third in thirdTypeDic.Keys) { var thirdTypeDatas = thirdTypeDic[third]; for (int i = 0; i < thirdTypeDatas.Count; i++) { var compound = thirdTypeDatas[i].itemCompound; if (compound.makeID.Contains(_ticketId)) { itemCompound = compound; return true; } } } } } return false; } #endregion public PackType GetPackTypeByMakerId(int[] makeIds) { if (makeIds == null || makeIds.Length < 1) return PackType.Deleted; int makeId = makeIds[0]; var itemConfig = ItemConfig.Get(makeId); return GeneralDefine.GetPackTypeByItemType(itemConfig.Type); } public void SetUpdateSendComposeEvent() { if (UpdateSendComposeEvent != null) { UpdateSendComposeEvent(); } } public bool IsComposeJobLimit(int composeId) { int playerJob = PlayerDatas.Instance.baseData.Job; if (composeJobLimitDict.ContainsKey(playerJob)) { if (composeJobLimitDict[playerJob].Contains(composeId)) { return true; } } return false; } public bool IsTrailerByLevel(ItemCompoundConfig itemCompound) { if (itemCompound.trailerLevel <= 0) return false; int playerLv = PlayerDatas.Instance.baseData.LV; if (playerLv >= itemCompound.trailerLevel && playerLv < itemCompound.levelNeed) { return true; } return false; } public int GetTicketId(int firstType, int secondType, int thirdType) { ComposeThirdTypeData thirdTypeData = null; TryGetThirdTypeData(firstType, secondType, thirdType, out thirdTypeData); if (thirdTypeData != null) { var itemCompound = thirdTypeData.itemCompound; return itemCompound.makeID[0]; } return 0; } public bool IsEnoughUnfixedMat(ItemCompoundConfig compoundModel) { if (selectModel.GetHaveUnfixedSelectItem().Count < compoundModel.unfixedItemCount) { return false; } return true; } public bool IsEnoughFixedMat(ItemCompoundConfig config) { if (config == null) return false; int[] fixedIds = config.itemID; int[] fixedCounts = config.itemCount; for (int i = 0; i < fixedCounts.Length; i++) { var fixedId = fixedIds[i]; var itemConfig = ItemConfig.Get(fixedId); var packType = GeneralDefine.GetPackTypeByItemType(itemConfig.Type); int haveCount = playerPack.GetItemCountByID(packType, fixedIds[i]); if (haveCount < fixedCounts[i]) { return false; } } return true; } public bool IsEnoughMoney(ItemCompoundConfig compoundModel) { ulong needMoney = (ulong)compoundModel.money; if (UIHelper.GetMoneyCnt(3) < needMoney) { return false; } return true; } /// /// 发送合成请求 /// private byte[] fixedIndexArray = null; private byte[] addonsReduceArray = null; private byte[] unfixedIndexArray = null; Dictionary> fixedMatIsBindDict = new Dictionary>(); //id , isBind, count Dictionary> unfixedMatIsBindDict = new Dictionary>(); public void SendComposeRequest(ItemCompoundConfig compoundModel, Dictionary> fixedItemIndexDict, UIEffect composEffect, int composeCount = 1, int successRate = 10000, bool isIncrease = false) { fixedMatIsBindDict.Clear(); unfixedMatIsBindDict.Clear(); if (compoundModel == null) { return; } int i = 0; if (!IsEnoughUnfixedMat(compoundModel)) { ServerTipDetails.DisplayNormalTip(Language.Get("Compose101")); return; } var packType = GetPackTypeByMakerId(compoundModel.makeID); int[] fixedIds = compoundModel.itemID; int[] fixedCounts = compoundModel.itemCount; for (i = 0; i < fixedCounts.Length; i++) { int haveCount = playerPack.GetItemCountByID(packType, fixedIds[i]); if (haveCount < fixedCounts[i]) { ItemConfig fixedConfig = ItemConfig.Get(fixedIds[i]); if (fixedConfig.GetWay.Length < 1) { ItemAttrData attrData = new ItemAttrData(fixedConfig.ID); itemTipsModel.SetItemTipsModel(attrData); } else { itemPathModel.SetChinItemModel(fixedConfig.ID); } return; } } if (!IsEnoughMoney(compoundModel)) { ItemConfig fixedConfig = ItemConfig.Get(2100); if (fixedConfig.GetWay.Length < 1) { ItemAttrData attrData = new ItemAttrData(fixedConfig.ID); itemTipsModel.SetItemTipsModel(attrData); } else { itemPathModel.SetChinItemModel(fixedConfig.ID); } return; } fixedIndexArray = DictToArray(fixedItemIndexDict); addonsReduceArray = new byte[selectModel.GetHaveAddSelectItem().Count]; for (i = 0; i < addonsReduceArray.Length; i++) { addonsReduceArray[i] = 1; } if (fixedIndexArray != null) { for (i = 0; i < fixedIndexArray.Length; i++) { ItemModel itemModel = playerPack.GetItemByIndex(packType, fixedIndexArray[i]); SetMatIsBindDict(itemModel, fixedMatIsBindDict); } } if (compoundModel.unfixedItemCount > 0) { unfixedIndexArray = DictToArray(selectModel.GetHaveUnfixedSelectItem()); } else { unfixedIndexArray = null; } if (unfixedIndexArray != null) { for (i = 0; i < unfixedIndexArray.Length; i++) { ItemModel itemModel = playerPack.GetItemByIndex(packType, unfixedIndexArray[i]); SetMatIsBindDict(itemModel, unfixedMatIsBindDict); } } if (composeCount < 2) { bool isBind = IsBindByFixedAndUnFixedMat(fixedMatIsBindDict, unfixedMatIsBindDict); bool isHaveRefineMat = IsEatHaveRefineMat(); if (compoundModel.successUpper > 0) { if (successRate < compoundModel.successUpper) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("ComposeSucRate"), (bool isOk) => { if (isOk) { if (isBind) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose104"), (bool isCompose) => { if (isCompose) { if (successRate < 10000) { if (isHaveRefineMat) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose108"), (bool sure) => { if (sure) { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } }); return; } else { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } } else { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } } }); return; } else { if (successRate < 10000) { if (isHaveRefineMat) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose108"), (bool sure) => { if (sure) { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } }); return; } else { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } } else { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } } } }); return; } } if (isBind) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose104"), (bool isCompose) => { if (isCompose) { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } }); } else { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } } else { List idlist = fixedMatIsBindDict.Keys.ToList(); if (idlist.Count > 1) { int minBindCnt = 0; int startBindCnt = 0; int nextBindCnt = 0; if (fixedMatIsBindDict[idlist[0]].ContainsKey(1)) { startBindCnt = fixedMatIsBindDict[idlist[0]][1]; } if (fixedMatIsBindDict[idlist[1]].ContainsKey(1)) { nextBindCnt = fixedMatIsBindDict[idlist[1]][1]; } minBindCnt = startBindCnt > nextBindCnt ? nextBindCnt : startBindCnt; int minNoBindCnt = 0; int startNoBindCnt = 0; int nextNoBindCnt = 0; if (fixedMatIsBindDict[idlist[0]].ContainsKey(0)) { startNoBindCnt = fixedMatIsBindDict[idlist[0]][0]; } if (fixedMatIsBindDict[idlist[1]].ContainsKey(0)) { nextNoBindCnt = fixedMatIsBindDict[idlist[1]][0]; } minNoBindCnt = startNoBindCnt > nextNoBindCnt ? nextNoBindCnt : startNoBindCnt; int remainNum = composeCount - minBindCnt - minNoBindCnt; if (startBindCnt > minBindCnt) { if (remainNum > startBindCnt - minBindCnt) { minBindCnt = startBindCnt; } else { minBindCnt += remainNum; } } else if (nextBindCnt > minBindCnt) { if (remainNum > nextBindCnt - minBindCnt) { minBindCnt = nextBindCnt; } else { minBindCnt += remainNum; } } minNoBindCnt = composeCount - minBindCnt; ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose107", GetComposeInfoStr(minBindCnt, minNoBindCnt)), (bool isCompose) => { if (isCompose) { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } }); } else { int bindCnt = 0; int noBindCnt = 0; if (fixedMatIsBindDict[idlist[0]].ContainsKey(1)) { bindCnt = fixedMatIsBindDict[idlist[0]][1]; } if (fixedMatIsBindDict[idlist[0]].ContainsKey(0)) { noBindCnt = fixedMatIsBindDict[idlist[0]][0]; } int remainBind = bindCnt % fixedCounts[0]; int remainNOBind = noBindCnt % fixedCounts[0]; bindCnt = bindCnt / fixedCounts[0]; noBindCnt = noBindCnt / fixedCounts[0]; if (bindCnt + noBindCnt < composeCount) { bindCnt = composeCount - noBindCnt; } ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose107", GetComposeInfoStr(bindCnt, noBindCnt)), (bool isCompose) => { if (isCompose) { SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease); } }); } } } public void SendComposeQuest(ItemCompoundConfig compoundModel, UIEffect composEffect, byte[] unfixedIndexArray, int composeCount, bool isIncrease) { composEffect.Play(); CA303_tagCMItemCompound itemCompose = null; itemCompose = new CA303_tagCMItemCompound(); itemCompose.ID = (uint)compoundModel.id; itemCompose.CompoundCnt = (ushort)composeCount; itemCompose.UnfixedItemIndexCnt = (byte)selectModel.GetHaveUnfixedSelectItem().Count; itemCompose.UnfixedItemIndex = unfixedIndexArray; itemCompose.FixedItemIndexCnt = (byte)fixedIndexArray.Length; itemCompose.FixedItemIndex = fixedIndexArray; itemCompose.AddonsItemIndexCnt = (byte)selectModel.GetHaveAddSelectItem().Count; itemCompose.AddonsItemIndex = DictToArray(selectModel.GetHaveAddSelectItem()); itemCompose.AddonsItemCount = addonsReduceArray; List increaseIndexlist = null; TryGetIncreaseRateItemIndex(compoundModel, isIncrease, out increaseIndexlist); byte[] increaseRateIndexArray = null; if (increaseIndexlist != null) { increaseRateIndexArray = ListToArray(increaseIndexlist); itemCompose.RateIncreaseItemIndexCnt = (byte)increaseRateIndexArray.Length; itemCompose.RateIncreaseItemIndex = increaseRateIndexArray; } else { itemCompose.RateIncreaseItemIndexCnt = 0; itemCompose.RateIncreaseItemIndex = new byte[0]; } GameNetSystem.Instance.SendInfo(itemCompose); } public bool IsBindByFixedAndUnFixedMat(Dictionary> fixedMat, Dictionary> unfixedMat) { bool isFixedBind = false; bool fixedNoBindRecord = false; foreach (var id in fixedMat.Keys) { foreach (var bind in fixedMat[id].Keys) { if (bind == 1) { isFixedBind = true; } else { fixedNoBindRecord = true; } } } bool isUnFixedBind = false; bool unfixedNoBindRecord = false; foreach (var id in unfixedMat.Keys) { foreach (var bind in unfixedMat[id].Keys) { if (bind == 1) { isUnFixedBind = true; } else { unfixedNoBindRecord = true; } } } if (fixedMat.Count > 0 && unfixedMat.Count > 0) { if (isFixedBind != isUnFixedBind || (isFixedBind == isUnFixedBind && fixedNoBindRecord != unfixedNoBindRecord)) { return true; } else { return false; } } else if (fixedMat.Count > 0) { if (isFixedBind && fixedNoBindRecord) { return true; } else { return false; } } else if (unfixedMat.Count > 0) { if (isUnFixedBind && unfixedNoBindRecord) { return true; } else { return false; } } return false; } private bool IsEatHaveRefineMat() { Dictionary unfixedDic = selectModel.GetHaveUnfixedSelectItem(); bool isRefineMat = false; foreach (var model in unfixedDic.Values) { if (model.GetUseData((int)ItemUseDataKey.wingMaterialItemID) != null) { isRefineMat = true; break; } } return isRefineMat; } private void SetMatIsBindDict(ItemModel itemModel, Dictionary> matDict) { if (itemModel == null) return; if (!matDict.ContainsKey(itemModel.itemId)) { Dictionary bindDict = new Dictionary(); //if (!bindDict.ContainsKey(itemModel.isBind)) //{ // bindDict.Add(itemModel.isBind, itemModel.count); //} matDict.Add(itemModel.itemId, bindDict); } else { matDict[itemModel.itemId][0] += itemModel.count; //if (!matDict[itemModel.itemId].ContainsKey(itemModel.isBind)) //{ // matDict[itemModel.itemId].Add(itemModel.isBind, itemModel.count); //} //else //{ //} } } private string GetComposeInfoStr(int bindCnt, int noBindCnt) { if (CurComposeModel == null) return string.Empty; int[] makeIds = CurComposeModel.makeID; ItemConfig config = ItemConfig.Get(makeIds[0]); StringBuilder stringBuilder = new StringBuilder(); if (bindCnt > 0) { string s = StringUtility.Contact(config.ItemName, Language.Get("Compose105"), "x", bindCnt, ""); stringBuilder.Append(s); } if (noBindCnt > 0) { string s = StringUtility.Contact(config.ItemName, Language.Get("Compose106"), "x", noBindCnt); stringBuilder.Append(s); } return stringBuilder.ToString(); } private byte[] DictToArray(Dictionary itemDict) { byte[] itemArray = new byte[itemDict.Count]; int[] itemIndexs = itemDict.Keys.ToArray(); int i = 0; for (i = 0; i < itemIndexs.Length; i++) { itemArray[i] = (byte)itemIndexs[i]; } return itemArray; } private byte[] ListToArray(List list) { byte[] itemArray = new byte[list.Count]; int i = 0; for (i = 0; i < list.Count; i++) { itemArray[i] = (byte)list[i]; } return itemArray; } private byte[] DictToArray(Dictionary> itemDict) { int itemArrayLength = 0; foreach (List list in itemDict.Values) { itemArrayLength += list.Count; } byte[] itemArray = new byte[itemArrayLength]; int i = 0; foreach (List list in itemDict.Values) { int j = 0; for (j = 0; j < list.Count; j++) { itemArray[i] = (byte)list[j]; i++; } } return itemArray; } /// /// 计算附加材料增加的成功率 /// /// /// /// /// /// public int GetComposeSuccessRate(ItemCompoundConfig tagItemCompound, ItemModel itemModel, int successRate) { Equation.Instance.Clear(); Equation.Instance.AddKeyValue("itemClassLV", itemModel.config.LV); Equation.Instance.AddKeyValue("itemColor", itemModel.config.ItemColor); int minRate = Equation.Instance.Eval(addonsFormulaModel.Numerical1); if (tagItemCompound.successUpper != 0) { if (successRate < tagItemCompound.successUpper) { successRate += minRate; } if (successRate >= tagItemCompound.successUpper) { successRate = tagItemCompound.successUpper; } } else { successRate += minRate; } return successRate; } /// /// 判断是否可以合成门票 /// /// /// haveCnt) { isEnough = false; } } } else { isEnough = false; } return isEnough; } #region 处理跳转界面数据 public bool CheckComposeItemById(int itemId, out int jumpId) { jumpId = 0; ItemConfig itemConfig = ItemConfig.Get(itemId); if (itemConfig == null) return false; int[] composeCondi = itemConfig.JumpComposeCondi; if (composeCondi.Length < 3) return false; int first = composeCondi[0]; int second = composeCondi[1]; int third = composeCondi[2]; ComposeThirdTypeData thirdTypeData = null; TryGetThirdTypeData(first, second, third, out thirdTypeData); if (thirdTypeData != null) { var itemCompound = thirdTypeData.itemCompound; if (itemCompound.levelNeed <= PlayerDatas.Instance.baseData.LV) { switch (itemCompound.firstType) { case 1: jumpId = (int)JumpUIType.ComposeFunc1; break; case 2: jumpId = (int)JumpUIType.ComposeFunc2; break; case 3: jumpId = (int)JumpUIType.ComposeFunc3; break; case 4: jumpId = (int)JumpUIType.ComposeFunc4; break; case 5: jumpId = (int)JumpUIType.ComposeFunc5; break; } this.secondType = itemCompound.secondType; if (itemCompound.firstType == 5 && itemCompound.secondType == 3) { this.thirdType = PlayerDatas.Instance.baseData.Job; } else { this.thirdType = itemCompound.thirdType; } return true; } else { SysNotifyMgr.Instance.ShowTip("TicketComposeUnlock", itemCompound.levelNeed, itemCompound.secondTypeName); return false; } } return false; } public bool CheckIsComposeByType(int firstType, int secondType, int thirdType) { ComposeThirdTypeData thirdTypeData = null; TryGetThirdTypeData(firstType, secondType, thirdType, out thirdTypeData); if (thirdTypeData == null) return false; var itemCompound = thirdTypeData.itemCompound; if (itemCompound.levelNeed <= PlayerDatas.Instance.baseData.LV) { return true; } else { SysNotifyMgr.Instance.ShowTip("TicketComposeUnlock", itemCompound.levelNeed, itemCompound.secondTypeName); return false; } } public int secondType { get; private set; } public int thirdType { get; private set; } public void SetJumpToModel(ComposeFuncType type, int secondType, int thirdType) { this.secondType = secondType; this.thirdType = thirdType; ComposeThirdTypeData thirdTypeData = null; TryGetThirdTypeData((int)type, secondType, thirdType, out thirdTypeData); if (thirdTypeData == null) { SysNotifyMgr.Instance.ShowTip("FuncLimit_Level"); ResetJumpToModel(); } } public void ResetJumpToModel() { this.secondType = 0; this.thirdType = 0; AchievementGoto.guideAchievementId = 0; } #endregion #region 红点逻辑 public const int COMPOSE_REDKEY = 109; public const int COMPOSETOOL_REDKEY = 10905; public const int COMPOSEBTN_REDKEY = 10910; public Redpoint composeRed = new Redpoint(MainRedDot.RedPoint_key, COMPOSE_REDKEY); public Redpoint composeBtnRed = new Redpoint(COMPOSEBTN_REDKEY); public Redpoint composeToolRed = new Redpoint(COMPOSE_REDKEY, COMPOSETOOL_REDKEY); public Dictionary secondTypeRedDict = new Dictionary(); public Dictionary thirdTypeRedDict = new Dictionary(); public void SetComposeTypeRed() { secondTypeRedDict.Clear(); thirdTypeRedDict.Clear(); if (composeDataDict.ContainsKey((int)ComposeFuncType.Item)) { var firstTypeData = composeDataDict[(int)ComposeFuncType.Item]; var secondTypeDict = firstTypeData.secondTypeDict; foreach (var second in secondTypeDict.Keys) { var thirdTypeDict = secondTypeDict[second].thirdTypeDict; int secondRedKey = COMPOSETOOL_REDKEY * 100 + second; Redpoint secondRed = new Redpoint(COMPOSETOOL_REDKEY, secondRedKey); secondTypeRedDict.Add(second, secondRed); foreach (var third in thirdTypeDict.Keys) { int thirdRedKey = secondRedKey * 100 + third; Redpoint thirdRed = new Redpoint(secondRedKey, thirdRedKey); string key = StringUtility.Contact(second, 10, third); thirdTypeRedDict.Add(key, thirdRed); } } } } private void OnItemCntRefresh(PackType type, int index, int id) { if (type != PackType.Item) return; ItemConfig itemConfig = ItemConfig.Get(id); if (itemConfig != null && itemConfig.Type == (int)ItemType.ComposeSuitStone) { RefreshComposeRed(); } } public void RefreshComposeRed() { ComposeFirstTypeData firstTypeData = null; TryGetFirstTypeData((int)ComposeFuncType.Item, out firstTypeData); if (firstTypeData == null || !FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Compose)) return; ComposeSecondTypeData secondTypeData = null; TryGetSecondTypeData((int)ComposeFuncType.Item, 3, out secondTypeData); if (secondTypeData != null) { var thirdTypeDict = secondTypeData.thirdTypeDict; foreach (var third in thirdTypeDict.Keys) { List thirdTypeDatas = thirdTypeDict[third]; for (int i = 0; i < thirdTypeDatas.Count; i++) { var itemCompound = thirdTypeDatas[i].itemCompound; int makeID = itemCompound.makeID[0]; string key = StringUtility.Contact(3, 10, third); if (IsComposeJobLimit(makeID) && IsEnoughFixedMat(itemCompound)) { if (thirdTypeRedDict[key].state != RedPointState.Simple) { thirdTypeRedDict[key].state = RedPointState.Simple; } } else { if (thirdTypeRedDict[key].state != RedPointState.None) { thirdTypeRedDict[key].state = RedPointState.None; } } } } } } #endregion } public enum ComposeFuncType { Wings = 1, Ticket = 2, Fairy = 3, Equip = 4, Item = 5, MountDogz = 6, GatherSoul = 7, } public enum NeedMatType { Nothing, MakeItem, fixedItem, unfixedItem, addItem, IncreaseItem, } public enum DisplayItemArray { MakeIds, UnfixedIds, FixedIds, FixedCounts, UnfixedDisplay, FixedDisplay, }