using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using vnxbqy.UI;
|
|
using LitJson;
|
|
|
public class ComposeWinModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public event Action UpdateSendComposeEvent;
|
public event Action ResetModelEvent;
|
|
SelectEquipModel selectModel { get { return ModelCenter.Instance.GetModel<SelectEquipModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
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 Dictionary<int, List<int>> composeJobLimitDict = new Dictionary<int, List<int>>();
|
public void ParseFuncConfig()
|
{
|
composeJobLimitDict.Clear();
|
FuncConfigConfig funcConfig = FuncConfigConfig.Get("ComposeJobLimit");
|
JsonData limitData = JsonMapper.ToObject(funcConfig.Numerical1);
|
foreach (var job in limitData.Keys)
|
{
|
List<int> idlist = new List<int>();
|
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<int, ComposeFirstTypeData> composeDataDict = new Dictionary<int, ComposeFirstTypeData>();
|
public Dictionary<int, ItemCompoundConfig> ComposeDataDictByMakeID = new Dictionary<int, ItemCompoundConfig>();
|
public void ParseItemComoundConfig()
|
{
|
composeDataDict.Clear();
|
List<ItemCompoundConfig> itemCompounds = ItemCompoundConfig.GetValues();
|
for (int i = 0; i < itemCompounds.Count; i++)
|
{
|
AddComposeData(itemCompounds[i], composeDataDict);
|
|
foreach (int makeID in itemCompounds[i].makeID)
|
{
|
ComposeDataDictByMakeID[makeID] = itemCompounds[i];
|
}
|
}
|
}
|
|
public void AddComposeData(ItemCompoundConfig itemCompound, Dictionary<int, ComposeFirstTypeData> keyValues)
|
{
|
if (itemCompound == null) return;
|
|
if (!keyValues.ContainsKey(itemCompound.firstType))
|
{
|
var firstData = new ComposeFirstTypeData();
|
firstData.firstType = itemCompound.firstType;
|
firstData.secondTypeDict = new Dictionary<int, ComposeSecondTypeData>();
|
ComposeSecondTypeData secondData = new ComposeSecondTypeData();
|
secondData.secondType = itemCompound.secondType;
|
secondData.thirdTypeDict = new Dictionary<int, List<ComposeThirdTypeData>>();
|
List<ComposeThirdTypeData> thirdTypeDatas = new List<ComposeThirdTypeData>();
|
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<int, List<ComposeThirdTypeData>>();
|
List<ComposeThirdTypeData> thirdTypeDatas = new List<ComposeThirdTypeData>();
|
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<ComposeThirdTypeData> thirdTypeDatas = new List<ComposeThirdTypeData>();
|
thirdTypeDatas.Add(thirdData);
|
thirdTypeDict.Add(thirdData.thirdType, thirdTypeDatas);
|
}
|
else
|
{
|
thirdTypeDict[thirdData.thirdType].Add(thirdData);
|
}
|
}
|
}
|
}
|
|
public class ComposeFirstTypeData
|
{
|
public int firstType;
|
public Dictionary<int, ComposeSecondTypeData> secondTypeDict = null;
|
}
|
public class ComposeSecondTypeData
|
{
|
public int secondType;
|
public Dictionary<int, List<ComposeThirdTypeData>> thirdTypeDict = null;
|
}
|
public class ComposeThirdTypeData
|
{
|
public int thirdType;
|
public ItemCompoundConfig itemCompound = null;
|
|
}
|
#endregion
|
|
#region 数据变动
|
public Dictionary<int, ComposeFirstTypeData> composeOpenDataDict = new Dictionary<int, ComposeFirstTypeData>();
|
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<ComposeThirdTypeData> 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<ComposeThirdTypeData> 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<int> UpdateThirdTypeEvent;
|
public void UpdateThirdType(int thirdType)
|
{
|
if (UpdateThirdTypeEvent != null)
|
{
|
UpdateThirdTypeEvent(thirdType);
|
}
|
}
|
public event Action<int> UpdateSecondTypeEvent;
|
public void UpdateSecondType(int secondType)
|
{
|
if (UpdateSecondTypeEvent != null)
|
{
|
UpdateSecondTypeEvent(secondType);
|
}
|
}
|
|
public event Action<ComposeMatCell, NeedMatType> UpdateReduceEvent;
|
public void UpdateReduce(ComposeMatCell matCell, NeedMatType matType)
|
{
|
if (UpdateReduceEvent != null)
|
{
|
UpdateReduceEvent(matCell, matType);
|
}
|
}
|
|
public event Action<ItemCompoundConfig, int> UpdateEquipTypeEvent;
|
public void UpdateComposeEquipPlace(ItemCompoundConfig itemCompound, int equipIndex)
|
{
|
if (UpdateEquipTypeEvent != null)
|
{
|
UpdateEquipTypeEvent(itemCompound, equipIndex);
|
}
|
}
|
|
public bool TryGetIncreaseRateItemIndex(ItemCompoundConfig itemCompound, bool IsIncrease, out List<int> 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;
|
}
|
/// <summary>
|
/// 发送合成请求
|
/// </summary>
|
private byte[] fixedIndexArray = null;
|
private byte[] addonsReduceArray = null;
|
private byte[] unfixedIndexArray = null;
|
Dictionary<int, Dictionary<int, int>> fixedMatIsBindDict = new Dictionary<int, Dictionary<int, int>>(); //id , isBind, count
|
Dictionary<int, Dictionary<int, int>> unfixedMatIsBindDict = new Dictionary<int, Dictionary<int, int>>();
|
|
public void SendComposeRequest(ItemCompoundConfig compoundModel, Dictionary<int, List<int>> 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])
|
{
|
ItemTipUtility.Show(fixedIds[i]);
|
return;
|
}
|
}
|
|
if (!IsEnoughMoney(compoundModel))
|
{
|
ItemTipUtility.Show(2100);
|
return;
|
}
|
|
fixedIndexArray = DictToArray(fixedItemIndexDict);
|
addonsReduceArray = new byte[selectModel.GetHaveAddSelectItem().Count];
|
for (i = 0; i < addonsReduceArray.Length; i++)
|
{
|
addonsReduceArray[i] = 1;
|
}
|
|
if (compoundModel.unfixedItemCount > 0)
|
{
|
unfixedIndexArray = DictToArray(selectModel.GetHaveUnfixedSelectItem());
|
}
|
else
|
{
|
unfixedIndexArray = null;
|
}
|
|
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<int> 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()),
|
(bool isCompose) =>
|
{
|
if (isCompose)
|
{
|
SendComposeQuest(compoundModel, composEffect, unfixedIndexArray, composeCount, isIncrease);
|
}
|
});
|
}
|
else
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("Compose107", GetComposeInfoStr()),
|
(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<int> 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<int, Dictionary<int, int>> fixedMat, Dictionary<int, Dictionary<int, int>> 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<int, ItemModel> 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 string GetComposeInfoStr()
|
{
|
if (CurComposeModel == null) return string.Empty;
|
int[] makeIds = CurComposeModel.makeID;
|
ItemConfig config = ItemConfig.Get(makeIds[0]);
|
return config.ItemName;
|
}
|
|
private byte[] DictToArray(Dictionary<int, ItemModel> 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<int> 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<int, List<int>> itemDict)
|
{
|
int itemArrayLength = 0;
|
foreach (List<int> list in itemDict.Values)
|
{
|
itemArrayLength += list.Count;
|
}
|
byte[] itemArray = new byte[itemArrayLength];
|
int i = 0;
|
foreach (List<int> list in itemDict.Values)
|
{
|
int j = 0;
|
for (j = 0; j < list.Count; j++)
|
{
|
itemArray[i] = (byte)list[j];
|
i++;
|
}
|
|
|
}
|
return itemArray;
|
}
|
|
/// <summary>
|
/// 判断是否可以合成门票
|
/// </summary>
|
/// <param name="composeItemID"></param>
|
/// <returns></returns
|
public bool IsComposeTicketByType(int secondType)
|
{
|
bool isEnough = true;
|
ComposeThirdTypeData thirdTypeData = null;
|
TryGetThirdTypeData((int)ComposeFuncType.Ticket, secondType, 0, out thirdTypeData);
|
if (thirdTypeData != null)
|
{
|
var itemCompound = thirdTypeData.itemCompound;
|
int[] fixedIDs = itemCompound.itemID;
|
int[] fixedCnt = itemCompound.itemCount;
|
for (int i = 0; i < fixedIDs.Length; i++)
|
{
|
int haveCnt = playerPack.GetItemCountByID(PackType.Item, fixedIDs[i]);
|
if (fixedCnt[i] > 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;
|
//}
|
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 COMPOSETICKET_REDKEY = 10903;
|
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 Redpoint composeTicketRed = new Redpoint(COMPOSE_REDKEY, COMPOSETICKET_REDKEY);
|
public Dictionary<int, Redpoint> secondTypeRedDict = new Dictionary<int, Redpoint>();
|
public Dictionary<string, Redpoint> thirdTypeRedDict = new Dictionary<string, Redpoint>();
|
public List<Int3> composeRedpointCategories = new List<Int3>();
|
public void SetComposeTypeRed()
|
{
|
var funcConfig = FuncConfigConfig.Get("ComposeRedpoint");
|
var stringArray = funcConfig.Numerical1.Split('|');
|
for (int i = 0; i < stringArray.Length; i++)
|
{
|
Int3 category;
|
if (Int3.TryParse(stringArray[i], out category))
|
{
|
composeRedpointCategories.Add(category);
|
}
|
}
|
|
secondTypeRedDict.Clear();
|
thirdTypeRedDict.Clear();
|
|
var firstType = (int)ComposeFuncType.Item;
|
if (composeDataDict.ContainsKey(firstType))
|
{
|
var firstTypeData = composeDataDict[firstType];
|
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);
|
var secondKey = firstType * 100 + second;
|
secondTypeRedDict.Add(secondKey, secondRed);
|
foreach (var third in thirdTypeDict.Keys)
|
{
|
int thirdRedKey = secondRedKey * 100 + third;
|
Redpoint thirdRed = new Redpoint(secondRedKey, thirdRedKey);
|
string key = (secondKey * 100 + third).ToString();
|
thirdTypeRedDict.Add(key, thirdRed);
|
}
|
}
|
}
|
|
foreach (var category in composeRedpointCategories)
|
{
|
if (composeDataDict.ContainsKey(category.x))
|
{
|
var firstTypeData = composeDataDict[category.x];
|
var secondTypeDict = firstTypeData.secondTypeDict;
|
foreach (var second in secondTypeDict.Keys)
|
{
|
var thirdTypeDict = secondTypeDict[second].thirdTypeDict;
|
int secondRedKey = COMPOSETICKET_REDKEY * 100 + second;
|
Redpoint secondRed = new Redpoint(COMPOSETICKET_REDKEY, secondRedKey);
|
var secondKey = category.x * 100 + second;
|
secondTypeRedDict.Add(secondKey, secondRed);
|
foreach (var third in thirdTypeDict.Keys)
|
{
|
int thirdRedKey = secondRedKey * 100 + third;
|
Redpoint thirdRed = new Redpoint(secondRedKey, thirdRedKey);
|
string key = (secondKey * 100 + third).ToString();
|
thirdTypeRedDict.Add(key, thirdRed);
|
}
|
}
|
}
|
}
|
}
|
|
readonly List<int> redpointItemTypes = new List<int>()
|
{
|
35,
|
44,
|
};
|
|
private void OnItemCntRefresh(PackType type, int index, int id)
|
{
|
if (type != PackType.Item) return;
|
|
ItemConfig itemConfig = ItemConfig.Get(id);
|
if (itemConfig != null && redpointItemTypes.Contains(itemConfig.Type))
|
{
|
RefreshComposeRed();
|
}
|
}
|
|
public void RefreshComposeRed()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Compose))
|
{
|
return;
|
}
|
|
foreach (var category in composeRedpointCategories)
|
{
|
ComposeSecondTypeData secondTypeData = null;
|
TryGetSecondTypeData(category.x, category.y, out secondTypeData);
|
if (secondTypeData != null)
|
{
|
var thirdTypeDict = secondTypeData.thirdTypeDict;
|
foreach (var third in thirdTypeDict.Keys)
|
{
|
List<ComposeThirdTypeData> thirdTypeDatas = thirdTypeDict[third];
|
for (int i = 0; i < thirdTypeDatas.Count; i++)
|
{
|
var itemCompound = thirdTypeDatas[i].itemCompound;
|
int makeID = itemCompound.makeID[0];
|
var secondKey = category.x * 100 + category.y;
|
string key = (secondKey * 100 + third).ToString();
|
if (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, //红装
|
Equip = 4, //装备
|
Item = 5, //道具
|
MountDogz = 6, //神兽(废弃) 独立的界面和配置
|
GatherSoul = 7, //聚魂 配置另外的表,界面在合成界面里
|
//后续IL开发添加预设
|
default1,
|
default2,
|
default3,
|
default4,
|
default5,
|
default6,
|
default7,
|
default8,
|
default9,
|
default10,
|
}
|
|
public enum NeedMatType
|
{
|
Nothing,
|
MakeItem,
|
fixedItem,
|
unfixedItem,
|
addItem,
|
IncreaseItem,
|
//后续IL开发添加预设
|
default1,
|
default2,
|
default3,
|
default4,
|
default5,
|
default6,
|
default7,
|
default8,
|
default9,
|
default10,
|
}
|
|
public enum DisplayItemArray
|
{
|
MakeIds,
|
UnfixedIds,
|
FixedIds,
|
FixedCounts,
|
UnfixedDisplay,
|
FixedDisplay,
|
//后续IL开发添加预设
|
default1,
|
default2,
|
default3,
|
default4,
|
default5,
|
default6,
|
default7,
|
default8,
|
default9,
|
default10,
|
}
|
|