using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
|
|
public class EquipGemModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, int[]> m_EquipGems = new Dictionary<int, int[]>();
|
Dictionary<int, List<int>> m_EquipGemTypes = new Dictionary<int, List<int>>();
|
Dictionary<int, GemHoleCondition> m_GemHoleConditions = new Dictionary<int, GemHoleCondition>();
|
Dictionary<int, GemType> m_GemTypes = new Dictionary<int, GemType>();
|
Dictionary<int, EquipGemRedpoint> m_EquipGemRedpoints = new Dictionary<int, EquipGemRedpoint>();
|
Dictionary<int, Redpoint> m_EquipSetRedpoints = new Dictionary<int, Redpoint>();
|
|
List<int> m_EquipPlaces = new List<int>();
|
|
readonly List<int> m_GemHoleItemIds = new List<int> { 0, 0, 0, 0 };
|
public List<EquipSetSelect> EquipSetList = new List<EquipSetSelect>();
|
public readonly Redpoint redpoint = new Redpoint(106, 10602);
|
int m_SelectHoleIndex = 0;
|
public int SelectHoleIndex
|
{
|
get { return m_SelectHoleIndex; }
|
set
|
{
|
m_SelectHoleIndex = value;
|
if (selectHoleRefresh != null)
|
{
|
selectHoleRefresh();
|
}
|
}
|
}
|
|
public const int EQUIPGEM_HOLE_COUNT = 4;
|
public static int REDPOINTBASE = 106020000;
|
|
int m_SelectLevel = 0;
|
public int selectLevel
|
{
|
get { return m_SelectLevel; }
|
set
|
{
|
if (m_SelectLevel != value)
|
{
|
m_SelectLevel = value;
|
if (selectLevelRefresh != null)
|
{
|
selectLevelRefresh();
|
}
|
}
|
}
|
}
|
|
int m_SelectEquipPlace = 0;
|
public int selectEquipPlace
|
{
|
get { return m_SelectEquipPlace; }
|
set
|
{
|
if (m_SelectEquipPlace != value)
|
{
|
m_SelectEquipPlace = value;
|
if (selectEquipRefresh != null)
|
{
|
selectEquipRefresh();
|
}
|
}
|
}
|
}
|
|
public Int2 jumpEquipPosition { get; set; }
|
|
public event Action selectLevelRefresh;
|
public event Action selectEquipRefresh;
|
public event Action<int, int> equipGemRefresh;
|
public event Action<int, int, int> equipGemLevelUp;
|
public event Action selectHoleRefresh;
|
|
EquipModel equipModel
|
{
|
get { return ModelCenter.Instance.GetModel<EquipModel>(); }
|
}
|
|
EquipStarModel equipStarModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
ComposeWinModel composeModel { get { return ModelCenter.Instance.GetModel<ComposeWinModel>(); } }
|
|
public bool serverInited { get; private set; }
|
|
public override void Init()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
packModel.refreshItemCountEvent += RefreshItemCountEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
equipModel.OnSelectFuncSetEvent += OnSelect;
|
ParseConfig();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
serverInited = false;
|
m_EquipGems.Clear();
|
|
foreach (var instance in EquipSetList)
|
{
|
GameObject.Destroy(instance.gameObject);
|
}
|
EquipSetList.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
serverInited = true;
|
}
|
|
public override void UnInit()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
packModel.refreshItemCountEvent -= RefreshItemCountEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
|
equipModel.OnSelectFuncSetEvent -= OnSelect;
|
}
|
|
private void OnSelect(int equipLevel)
|
{
|
if (selectLevel == equipLevel)
|
{
|
return;
|
}
|
else
|
{
|
selectLevel = equipLevel;
|
}
|
}
|
|
void ParseConfig()
|
{
|
var gemTypeConfig = FuncConfigConfig.Get("GemTypeCount");
|
var gemTypeCount = int.Parse(gemTypeConfig.Numerical1);
|
|
var gemCostConfig = FuncConfigConfig.Get("GemUpCostFormula");
|
var shopDict = ConfigParse.GetDic<int, int>(gemCostConfig.Numerical1);
|
var composeCount = int.Parse(gemCostConfig.Numerical2);
|
|
Dictionary<int, Item> composeItems = new Dictionary<int, Item>();
|
var composeItemJson = LitJson.JsonMapper.ToObject(gemCostConfig.Numerical3);
|
foreach (var levelKey in composeItemJson.Keys)
|
{
|
var itemArray = LitJson.JsonMapper.ToObject<int[]>(composeItemJson[levelKey].ToJson());
|
composeItems.Add(int.Parse(levelKey), new Item()
|
{
|
id = itemArray[0],
|
count = itemArray[1],
|
});
|
}
|
|
for (int i = 1; i <= gemTypeCount; i++)
|
{
|
int[] getWays = null;
|
string description = string.Empty;
|
var gemConfig = FuncConfigConfig.Get("GemType" + i);
|
if (gemConfig != null)
|
{
|
var equips = ConfigParse.GetMultipleStr<int>(gemConfig.Numerical1);
|
for (int k = 0; k < equips.Length; k++)
|
{
|
List<int> gemTypes = null;
|
if (!m_EquipGemTypes.TryGetValue(equips[k], out gemTypes))
|
{
|
gemTypes = new List<int>();
|
m_EquipGemTypes.Add(equips[k], gemTypes);
|
}
|
gemTypes.Add(i);
|
}
|
|
if (!string.IsNullOrEmpty(gemConfig.Numerical3))
|
{
|
getWays = ConfigParse.GetMultipleStr<int>(gemConfig.Numerical3);
|
}
|
|
description = gemConfig.Numerical2;
|
}
|
|
var level = 1;
|
var maxLevel = level;
|
var itemType = 0;
|
var itemConfig = ItemConfig.GetGemDataByLevelAndType(level, i);
|
if (itemConfig != null)
|
{
|
itemType = itemConfig.Type;
|
}
|
while (itemConfig != null && itemConfig.EffectValueA1 == i)
|
{
|
maxLevel = level;
|
level++;
|
itemConfig = ItemConfig.Get(itemConfig.EffectValueC1);
|
}
|
|
m_GemTypes.Add(i, new GemType()
|
{
|
maxLevel = maxLevel,
|
getWays = getWays,
|
description = description,
|
itemType = itemType,
|
shopItemId = shopDict.ContainsKey(i) ? shopDict[i] : 0,
|
composeCount = composeCount,
|
composeItems = composeItems,
|
filterParams = new SinglePack.FilterParams()
|
{
|
itemTypes = new List<int>() { itemType },
|
}
|
});
|
}
|
|
m_EquipPlaces.AddRange(m_EquipGemTypes.Keys);
|
m_EquipPlaces.Sort();
|
|
var commonHoleConfig = FuncConfigConfig.Get("GemOpen");
|
var vipHoleConfig = FuncConfigConfig.Get("GemOpenVip");
|
var commonOpens = ConfigParse.GetMultipleStr<int>(commonHoleConfig.Numerical1);
|
for (int i = 0; i < commonOpens.Length; i++)
|
{
|
m_GemHoleConditions.Add(i, new GemHoleCondition()
|
{
|
equipStar = commonOpens[i],
|
vipLevel = 0,
|
});
|
}
|
m_GemHoleConditions.Add(3, new GemHoleCondition()
|
{
|
equipStar = commonOpens[0],
|
vipLevel = int.Parse(vipHoleConfig.Numerical1),
|
});
|
|
var configs = EquipControlConfig.GetValues();
|
var totalEquipLevels = new List<int>();
|
foreach (var item in configs)
|
{
|
var level = item.level;
|
if (!totalEquipLevels.Contains(level))
|
{
|
totalEquipLevels.Add(level);
|
}
|
}
|
|
foreach (var level in totalEquipLevels)
|
{
|
var equipSetRedpointBase = REDPOINTBASE++;
|
m_EquipSetRedpoints[level] = new Redpoint(redpoint.id, equipSetRedpointBase);
|
foreach (var place in m_EquipPlaces)
|
{
|
var packIndex = EquipPlaceMapConfig.GetServerPlace(level, place);
|
if (!m_EquipGemRedpoints.ContainsKey(packIndex))
|
{
|
EquipGemRedpoint _redpoint = new EquipGemRedpoint(equipSetRedpointBase);
|
m_EquipGemRedpoints.Add(packIndex, _redpoint);
|
}
|
}
|
}
|
}
|
|
|
|
public bool TryGetGemHoleCondition(int hole, out GemHoleCondition condition)
|
{
|
return m_GemHoleConditions.TryGetValue(hole, out condition);
|
}
|
|
public bool TryGetEquipGems(int packIndex, out int[] gems)
|
{
|
return m_EquipGems.TryGetValue(packIndex, out gems);
|
}
|
|
public bool TryGetEquipGems(int level, int place, out int[] gems)
|
{
|
var packIndex = EquipPlaceMapConfig.GetServerPlace(level, place);
|
return TryGetEquipGems(packIndex, out gems);
|
}
|
|
//获取某阶的装备宝石总等级
|
public int GetGemLevelByEquipLevel(int level, int placeCount = 12)
|
{
|
int findCount = 0;
|
for (int i = 1; i <= placeCount; i++)
|
{
|
int[] gems;
|
if (TryGetEquipGems(level, i, out gems))
|
{
|
foreach (var equipGem in gems)
|
{
|
if (equipGem == 0)
|
{
|
continue;
|
}
|
findCount += GetGemLevel(equipGem);
|
}
|
}
|
}
|
|
return findCount;
|
}
|
|
public bool TryGetEquipGem(int level, int place, int hole, out int equipGem)
|
{
|
equipGem = 0;
|
int[] equipGems;
|
if (TryGetEquipGems(level, place, out equipGems))
|
{
|
if (hole < equipGems.Length)
|
{
|
equipGem = equipGems[hole];
|
return equipGem != 0;
|
}
|
}
|
return false;
|
}
|
|
public bool TryGetGemTypes(int place, out List<int> types)
|
{
|
return m_EquipGemTypes.TryGetValue(place, out types);
|
}
|
|
public bool TryGetGemType(int type, out GemType gemType)
|
{
|
return m_GemTypes.TryGetValue(type, out gemType);
|
}
|
|
public bool TryGetRedpoint(int level, int place, out EquipGemRedpoint _redpoint)
|
{
|
var packIndex = EquipPlaceMapConfig.GetServerPlace(level, place);
|
return m_EquipGemRedpoints.TryGetValue(packIndex, out _redpoint);
|
}
|
|
public bool TryGetRedpoint(int level, out Redpoint _redpoint)
|
{
|
return m_EquipSetRedpoints.TryGetValue(level, out _redpoint);
|
}
|
|
public Int2 TryGotoUseGem(int itemId)
|
{
|
var config = ItemConfig.Get(itemId);
|
if (config == null)
|
{
|
return Int2.zero;
|
}
|
GemType gemType;
|
if (!TryGetGemType(config.EffectValueA1, out gemType))
|
{
|
return Int2.zero;
|
}
|
Int2 equipPosition = Int2.zero;
|
foreach (var level in cacheEquipSets)
|
{
|
foreach (var place in m_EquipPlaces)
|
{
|
var gemTypes = m_EquipGemTypes[place];
|
if (!gemTypes.Contains(config.EffectValueA1))
|
{
|
continue;
|
}
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
if (!IsEquipGemHoleOpen(level, place, i))
|
{
|
continue;
|
}
|
if (equipPosition.Equals(Int2.zero))
|
{
|
equipPosition.x = level;
|
equipPosition.y = place;
|
}
|
var equipGem = 0;
|
if (TryGetEquipGem(level, place, i, out equipGem))
|
{
|
var compareConfig = ItemConfig.Get(equipGem);
|
if(config.EffectValueB1 > compareConfig.EffectValueB1)
|
{
|
return new Int2(level, place);
|
}
|
}
|
else
|
{
|
return new Int2(level, place);
|
}
|
}
|
}
|
}
|
return equipPosition;
|
}
|
|
public bool IsEquipGemHoleOpen(int level, int place, int hole)
|
{
|
var equipPosition = new Int2(level, place);
|
var equipGuid = equipModel.GetEquip(equipPosition);
|
if (string.IsNullOrEmpty(equipGuid))
|
{
|
return false;
|
}
|
var equip = packModel.GetItemByGuid(equipGuid);
|
GemHoleCondition condition;
|
if (TryGetGemHoleCondition(hole, out condition))
|
{
|
var starLimit = 0;
|
if (GeneralDefine.equipStarLimit.ContainsKey(equip.config.ItemColor))
|
{
|
var itemLevelStars = GeneralDefine.equipStarLimit[equip.config.ItemColor];
|
if (itemLevelStars.ContainsKey(equip.config.LV))
|
{
|
starLimit = itemLevelStars[equip.config.LV];
|
}
|
}
|
var star = Mathf.Min(starLimit, equipStarModel.GetStarLevel(equipPosition));
|
if (star < condition.equipStar)
|
{
|
return false;
|
}
|
var vipLevel = PlayerDatas.Instance.baseData.VIPLv;
|
if (vipLevel < condition.vipLevel)
|
{
|
return false;
|
}
|
}
|
return true;
|
}
|
|
public bool IsGemHoleOpen(int hole, int starLevel)
|
{
|
GemHoleCondition condition;
|
if (TryGetGemHoleCondition(hole, out condition))
|
{
|
if (starLevel < condition.equipStar)
|
{
|
return false;
|
}
|
}
|
return true;
|
}
|
|
//宝石合成需要总材料信息
|
public Dictionary<int, List<int>> GetComposeNeedGemList(int makeSrcID, int itemID)
|
{
|
//{合成需要的物品ID:[背包中数量,需要数量]}
|
Dictionary<int, List<int>> needGemDict = new Dictionary<int, List<int>>();
|
if (makeSrcID == 0)
|
{
|
return needGemDict;
|
}
|
int makeID = makeSrcID;
|
int makeCnt = 1; //默认扣除已镶嵌的宝石
|
// 此处逻辑只考虑了每次合成只有一种新合成物,比如不会出现3级宝石 需要两种不同的2级宝石合成
|
while (makeCnt > 0)
|
{
|
var composeConfig = composeModel.ComposeDataDictByMakeID[makeID];
|
int nextMakeCnt = 0;
|
int nextMakeID = 0;
|
for (int i = 0; i < composeConfig.itemID.Length; i++)
|
{
|
int needCnt = composeConfig.itemCount[i] * makeCnt;
|
int needItemID = composeConfig.itemID[i];
|
if (needItemID == itemID)
|
{
|
needCnt--;
|
if (needCnt == 0)
|
continue;
|
}
|
|
//非合成物处理
|
if (!composeModel.ComposeDataDictByMakeID.ContainsKey(needItemID))
|
{
|
if (needGemDict.ContainsKey(needItemID))
|
{
|
needGemDict[needItemID][1] = needGemDict[needItemID][1] + needCnt;
|
}
|
else
|
{
|
needGemDict[needItemID] = new List<int>() {
|
packModel.GetItemCountByID(PackType.Item, needItemID),
|
needCnt
|
};
|
}
|
}
|
else
|
{
|
var hasCnt = packModel.GetItemCountByID(PackType.Item, needItemID);
|
if (hasCnt > 0)
|
{
|
needGemDict[needItemID] = new List<int>() {hasCnt, Math.Min(hasCnt, needCnt) };
|
needCnt = Math.Max(needCnt - hasCnt, 0);
|
}
|
nextMakeCnt = nextMakeCnt + needCnt;
|
nextMakeID = needItemID;
|
}
|
}
|
|
makeID = nextMakeID;
|
makeCnt = nextMakeCnt;
|
}
|
return needGemDict;
|
}
|
|
public bool IsEquipGemHoleOpen(int packIndex, int hole)
|
{
|
var config = EquipPlaceMapConfig.Get(packIndex);
|
if (config != null)
|
{
|
return IsEquipGemHoleOpen(config.LV, config.EquipPlace, hole);
|
}
|
return false;
|
}
|
|
public bool IsEquipGemMaxLevel(int id)
|
{
|
var itemConfig = ItemConfig.Get(id);
|
if (itemConfig == null)
|
{
|
return true;
|
}
|
var gemType = itemConfig.EffectValueA1;
|
if (m_GemTypes.ContainsKey(gemType))
|
{
|
return itemConfig.EffectValueB1 >= m_GemTypes[gemType].maxLevel;
|
}
|
return true;
|
}
|
|
public bool IsBetterGem(int itemId)
|
{
|
var config = ItemConfig.Get(itemId);
|
if (config == null)
|
{
|
return false;
|
}
|
foreach (var level in cacheEquipSets)
|
{
|
foreach (var place in m_EquipPlaces)
|
{
|
var gemTypes = m_EquipGemTypes[place];
|
if (!gemTypes.Contains(config.EffectValueA1))
|
{
|
continue;
|
}
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
if (!IsEquipGemHoleOpen(level, place, i))
|
{
|
continue;
|
}
|
var equipGem = 0;
|
if (TryGetEquipGem(level, place, i, out equipGem))
|
{
|
var compareConfig = ItemConfig.Get(equipGem);
|
return config.EffectValueB1 > compareConfig.EffectValueB1;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
}
|
}
|
return false;
|
}
|
|
public ICollection<int> GetMosaicEquipPlaces()
|
{
|
return m_EquipPlaces;
|
}
|
|
public int GetUnlockEquipSlotCount(int level)
|
{
|
var equipSet = equipModel.GetEquipSet(level);
|
if (equipSet == null || !equipSet.unLocked)
|
{
|
return 0;
|
}
|
var count = 0;
|
var places = GetMosaicEquipPlaces();
|
foreach (var place in places)
|
{
|
if (equipSet.IsSlotUnLocked(place))
|
{
|
count++;
|
}
|
}
|
return count;
|
}
|
|
public List<string> GetSatisfyEquipGemGuids(int place)
|
{
|
if (!m_EquipGemTypes.ContainsKey(place))
|
{
|
return null;
|
}
|
List<string> items = new List<string>();
|
var types = m_EquipGemTypes[place];
|
foreach (var type in types)
|
{
|
var gemType = m_GemTypes[type];
|
var itemModels = packModel.GetItems(PackType.Item, gemType.filterParams);
|
if (itemModels != null)
|
{
|
foreach (var itemModel in itemModels)
|
{
|
if (itemModel.config.EffectValueA1 == type)
|
{
|
items.Add(itemModel.guid);
|
}
|
}
|
}
|
}
|
return items;
|
}
|
|
public ItemConfig GetNextLevelConfig(int id)
|
{
|
if (IsEquipGemMaxLevel(id))
|
{
|
return null;
|
}
|
var config = ItemConfig.Get(id);
|
if (config == null)
|
{
|
return null;
|
}
|
return ItemConfig.GetGemDataByLevelAndType(config.EffectValueB1 + 1, config.EffectValueA1);
|
}
|
|
public int GetGemLevelUpCost(int type, int level)
|
{
|
var cost = 0;
|
GemType gemType;
|
if (TryGetGemType(type, out gemType))
|
{
|
cost += GetGemComposeCost(type, level);
|
for (int i = 1; i < level; i++)
|
{
|
if (gemType.composeItems.ContainsKey(i + 1))
|
{
|
var item = gemType.composeItems[i + 1];
|
var shopConfig = StoreConfig.GetStoreCfg(item.id, 1);
|
if (shopConfig != null)
|
{
|
cost += shopConfig.MoneyNumber * item.count * (1 << (level - 1 - i));
|
}
|
}
|
}
|
if (gemType.composeItems.ContainsKey(level + 1))
|
{
|
var item = gemType.composeItems[level + 1];
|
var shopConfig = StoreConfig.GetStoreCfg(item.id, 1);
|
if (shopConfig != null)
|
{
|
cost += shopConfig.MoneyNumber * item.count;
|
}
|
}
|
}
|
return cost;
|
}
|
|
public int GetGemComposeCost(int type, int level)
|
{
|
var cost = 0;
|
GemType gemType;
|
if (TryGetGemType(type, out gemType))
|
{
|
if (level > 1)
|
{
|
cost += gemType.composeCount * GetGemComposeCost(type, level - 1);
|
}
|
else
|
{
|
var singlePrice = 0;
|
if (gemType.shopItemId != 0)
|
{
|
var shopConfig = StoreConfig.GetStoreCfg(gemType.shopItemId, 1);
|
if (shopConfig != null)
|
{
|
singlePrice = shopConfig.MoneyNumber;
|
}
|
}
|
cost = singlePrice;
|
}
|
}
|
return cost;
|
}
|
|
public int GetGemCount(int type, int level)
|
{
|
GemType gemType;
|
TryGetGemType(type, out gemType);
|
var count = 0;
|
var items = packModel.GetItems(PackType.Item, gemType.filterParams);
|
if (items == null)
|
{
|
return 0;
|
}
|
for (int i = 0; i < items.Count; i++)
|
{
|
var item = items[i];
|
var config = ItemConfig.Get(item.itemId);
|
if (config.EffectValueA1 == type && config.EffectValueB1 == level)
|
{
|
count += item.count;
|
}
|
}
|
return count;
|
}
|
|
public int GetBetterGemCount(int type, int level)
|
{
|
GemType gemType;
|
TryGetGemType(type, out gemType);
|
var count = 0;
|
var items = packModel.GetItems(PackType.Item, gemType.filterParams);
|
if (items == null)
|
{
|
return 0;
|
}
|
for (int i = 0; i < items.Count; i++)
|
{
|
var item = items[i];
|
var config = ItemConfig.Get(item.itemId);
|
if (config.EffectValueA1 == type && config.EffectValueB1 > level)
|
{
|
count += item.count;
|
}
|
}
|
return count;
|
}
|
|
public int GetSameLevelGemCount(int type, int level)
|
{
|
GemType gemType;
|
TryGetGemType(type, out gemType);
|
var count = 0;
|
var items = packModel.GetItems(PackType.Item, gemType.filterParams);
|
if (items == null)
|
{
|
return 0;
|
}
|
for (int i = 0; i < items.Count; i++)
|
{
|
var item = items[i];
|
var config = ItemConfig.Get(item.itemId);
|
if (config.EffectValueA1 == type && config.EffectValueB1 == level)
|
{
|
count += item.count;
|
}
|
}
|
return count;
|
}
|
|
public int GetSameTypeEmptyUnlockHole(List<int> equipSets, int type)
|
{
|
var count = 0;
|
foreach (var level in equipSets)
|
{
|
foreach (var place in m_EquipPlaces)
|
{
|
if (!m_EquipGemTypes[place].Contains(type))
|
{
|
continue;
|
}
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
if (!IsEquipGemHoleOpen(level, place, i))
|
{
|
continue;
|
}
|
int equipGem;
|
if (!TryGetEquipGem(level, place, i, out equipGem))
|
{
|
count++;
|
}
|
}
|
}
|
}
|
return count;
|
}
|
|
public int GetAllGemsLevel()
|
{
|
var level = 0;
|
foreach (var key in m_EquipGems.Keys)
|
{
|
var equipGems = m_EquipGems[key];
|
foreach (var equipGem in equipGems)
|
{
|
if (equipGem == 0)
|
{
|
continue;
|
}
|
level += GetGemLevel(equipGem);
|
}
|
}
|
return level;
|
}
|
|
public int GetEmptyGemHoleCount(int level, int place)
|
{
|
var count = 0;
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
var itemId = 0;
|
if (IsEquipGemHoleOpen(level, place, i)
|
&& !TryGetEquipGem(level, place, i, out itemId))
|
{
|
count++;
|
}
|
}
|
return count;
|
}
|
|
public int GetGemLevel(int itemId)
|
{
|
var config = ItemConfig.Get(itemId);
|
return config == null ? 0 : config.EffectValueB1;
|
}
|
|
public int Compare(string lhs, string rhs)
|
{
|
var lhsItem = packModel.GetItemByGuid(lhs);
|
var rhsItem = packModel.GetItemByGuid(rhs);
|
if (lhsItem == null || rhsItem == null)
|
{
|
return 0;
|
}
|
var lhsConfig = ItemConfig.Get(lhsItem.itemId);
|
var rhsConfig = ItemConfig.Get(rhsItem.itemId);
|
if (lhsConfig.EffectValueB1 != rhsConfig.EffectValueB1)
|
{
|
return -lhsConfig.EffectValueB1.CompareTo(rhsConfig.EffectValueB1);
|
}
|
return lhsItem.itemId.CompareTo(rhsItem.itemId);
|
}
|
|
public void ReceivePackage(HA3BC_tagMCStoneInfo package)
|
{
|
for (int i = 0; i < package.EquipCount; i++)
|
{
|
var data = package.InfoList[i];
|
var config = EquipPlaceMapConfig.Get(data.EquipPlace);
|
if (config == null)
|
{
|
continue;
|
}
|
|
for (int k = 0; k < m_GemHoleItemIds.Count; k++)
|
{
|
int equipGem;
|
TryGetEquipGem(config.LV, config.EquipPlace, k, out equipGem);
|
m_GemHoleItemIds[k] = equipGem;
|
}
|
|
int[] gems = null;
|
if (!m_EquipGems.TryGetValue(data.EquipPlace, out gems))
|
{
|
gems = new int[EQUIPGEM_HOLE_COUNT];
|
m_EquipGems.Add(data.EquipPlace, gems);
|
}
|
for (int k = 0; k < data.MaxStoneCount; k++)
|
{
|
gems[k] = (int)data.StoneInfo[k];
|
if (data.StoneInfo[k] > m_GemHoleItemIds[k])
|
{
|
if (serverInited && equipGemLevelUp != null)
|
{
|
equipGemLevelUp(config.LV, config.EquipPlace, k);
|
}
|
}
|
}
|
if (equipGemRefresh != null)
|
{
|
equipGemRefresh(config.LV, config.EquipPlace);
|
}
|
}
|
RefreshRedpoint();
|
}
|
|
public void SendGemLevelUp(int level, int place, int hole, int levelUpType)
|
{
|
CA306_tagCMEquipStoneUpgrade levelUp = new CA306_tagCMEquipStoneUpgrade();
|
levelUp.EquipIndex = (byte)EquipPlaceMapConfig.GetServerPlace(level, place);
|
if (hole == 3)
|
{
|
levelUp.HoleIndex = 10;
|
}
|
else
|
{
|
levelUp.HoleIndex = (byte)hole;
|
}
|
levelUp.UpWay = (byte)levelUpType;
|
GameNetSystem.Instance.SendInfo(levelUp);
|
}
|
|
List<int> m_CacheEquipSets;
|
List<int> cacheEquipSets
|
{
|
get
|
{
|
if (m_CacheEquipSets == null)
|
{
|
m_CacheEquipSets = equipModel.GetAllEquipSets();
|
}
|
return m_CacheEquipSets;
|
}
|
}
|
|
void RefreshRedpoint()
|
{
|
//宝石镶嵌功能和强化一起开放,避免红点问题
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Strength))
|
{
|
return;
|
}
|
|
List<int> places = new List<int>(m_EquipPlaces);
|
|
#region 检查空的孔位
|
places.Sort((int x, int y) =>
|
{
|
List<int> x_types;
|
List<int> y_types;
|
if (TryGetGemTypes(x, out x_types)
|
&& TryGetGemTypes(y, out y_types))
|
{
|
if (x_types[0] != y_types[0])
|
{
|
return -x_types[0].CompareTo(y_types[0]);
|
}
|
}
|
return x.CompareTo(y);
|
});
|
|
foreach (var level in cacheEquipSets)
|
{
|
foreach (var place in places)
|
{
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
int equipGem;
|
if (!TryGetEquipGem(level, place, i, out equipGem))
|
{
|
if (SatisfyInlayBetterGem(level, place, i))
|
{
|
SetRedpoint(new Int2(level, place), i, 1);
|
return;
|
}
|
}
|
}
|
}
|
}
|
#endregion
|
|
#region 检查所有孔位
|
foreach (var level in cacheEquipSets)
|
{
|
foreach (var place in places)
|
{
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
if (SatisfyInlayBetterGem(level, place, i))
|
{
|
SetRedpoint(new Int2(level, place), i, 1);
|
return;
|
}
|
}
|
}
|
}
|
#endregion
|
|
#region 检查非空孔位
|
int cacheLevel = 0;
|
Int2 position = Int2.zero;
|
int hole = 0;
|
int type = 0;
|
foreach (var level in cacheEquipSets)
|
{
|
foreach (var place in places)
|
{
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
int equipGem;
|
if (TryGetEquipGem(level, place, i, out equipGem))
|
{
|
if (SatisfyComposeGem(level, place, i))
|
{
|
if (cacheLevel == 0 || cacheLevel > GetGemLevel(equipGem))
|
{
|
cacheLevel = GetGemLevel(equipGem);
|
position.x = level;
|
position.y = place;
|
hole = i;
|
type = 2;
|
}
|
}
|
}
|
}
|
}
|
}
|
#endregion
|
|
SetRedpoint(position, hole, type);
|
}
|
|
void SetRedpoint(Int2 position, int hole, int type)
|
{
|
foreach (var level in cacheEquipSets)
|
{
|
foreach (var place in m_EquipPlaces)
|
{
|
var packIndex = EquipPlaceMapConfig.GetServerPlace(level, place);
|
EquipGemRedpoint equipGemRedpoint;
|
TryGetRedpoint(level, place, out equipGemRedpoint);
|
for (int i = 0; i < EQUIPGEM_HOLE_COUNT; i++)
|
{
|
var inlayAble = position.x == level && position.y == place && hole == i && type == 1;
|
var composeAble = position.x == level && position.y == place && hole == i && type == 2;
|
equipGemRedpoint.SetInlayRedpoint(i, inlayAble);
|
equipGemRedpoint.SetComposeRedpoint(i, composeAble);
|
}
|
}
|
}
|
}
|
|
//只处理空孔的红点,更好的不处理
|
public bool SatisfyInlayBetterGem(int level, int place, int hole)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Gem))
|
{
|
return false;
|
}
|
if (!IsEquipGemHoleOpen(level, place, hole))
|
{
|
return false;
|
}
|
int equipGem;
|
TryGetEquipGem(level, place, hole, out equipGem);
|
var equipGemLevel = 0;
|
if (equipGem != 0)
|
{
|
// var config = ItemConfig.Get(equipGem);
|
// equipGemLevel = config.EffectValueB1;
|
//只处理未镶嵌,不比较更好
|
return false;
|
}
|
List<int> gemTypes = m_EquipGemTypes[place];
|
foreach (var type in gemTypes)
|
{
|
var count = GetBetterGemCount(type, equipGemLevel);
|
if (count > 0)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool SatisfyComposeGem(int level, int place, int hole)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Gem))
|
{
|
return false;
|
}
|
if (!IsEquipGemHoleOpen(level, place, hole))
|
{
|
return false;
|
}
|
int equipGem;
|
TryGetEquipGem(level, place, hole, out equipGem);
|
if (equipGem == 0)
|
{
|
return false;
|
}
|
if (IsEquipGemMaxLevel(equipGem))
|
{
|
return false;
|
}
|
var config = ItemConfig.Get(equipGem);
|
var type = config.EffectValueA1;
|
var emptyHoleCount = GetSameTypeEmptyUnlockHole(cacheEquipSets, type);
|
var sameLevelCount = GetSameLevelGemCount(type, config.EffectValueB1);
|
sameLevelCount -= emptyHoleCount;
|
GemType gemType;
|
TryGetGemType(type, out gemType);
|
if (sameLevelCount < gemType.composeCount - 1)
|
{
|
return false;
|
}
|
if (gemType.composeItems.ContainsKey(config.EffectValueB1 + 1))
|
{
|
var item = gemType.composeItems[config.EffectValueB1 + 1];
|
var count = packModel.GetItemCountByID(PackType.Item, item.id);
|
if (count < item.count)
|
{
|
return false;
|
}
|
}
|
return true;
|
}
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if ((int)FuncOpenEnum.Gem == id)
|
{
|
RefreshRedpoint();
|
}
|
}
|
|
private void RefreshItemCountEvent(PackType packType, int arg2, int itemId)
|
{
|
if (packType == PackType.Equip)
|
{
|
RefreshRedpoint();
|
}
|
if (packType == PackType.Item)
|
{
|
var config = ItemConfig.Get(itemId);
|
if (m_GemTypes.ContainsKey(config.EffectValueA1)
|
&& m_GemTypes[config.EffectValueA1].itemType == config.Type)
|
{
|
RefreshRedpoint();
|
}
|
}
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
|
{
|
if (refreshType == PlayerDataType.VIPLv)
|
{
|
RefreshRedpoint();
|
}
|
}
|
}
|
|
public struct GemHoleCondition
|
{
|
public int equipStar;
|
public int vipLevel;
|
}
|
|
public struct GemType
|
{
|
public int maxLevel;
|
public int[] getWays;
|
public string description;
|
public int itemType;
|
public int shopItemId;
|
public int composeCount;
|
public Dictionary<int, Item> composeItems;
|
public SinglePack.FilterParams filterParams;
|
}
|
|
public class EquipGemRedpoint
|
{
|
public readonly Redpoint repoint;
|
readonly List<Redpoint> holeRedpooints;
|
readonly List<Redpoint> holeInlayRedpoints;
|
readonly List<Redpoint> holeComposeRedpoints;
|
|
public EquipGemRedpoint(int baseId)
|
{
|
repoint = new Redpoint(baseId, EquipGemModel.REDPOINTBASE++);
|
holeRedpooints = new List<Redpoint>(EquipGemModel.EQUIPGEM_HOLE_COUNT);
|
holeInlayRedpoints = new List<Redpoint>(EquipGemModel.EQUIPGEM_HOLE_COUNT);
|
holeComposeRedpoints = new List<Redpoint>(EquipGemModel.EQUIPGEM_HOLE_COUNT);
|
for (int i = 0; i < EquipGemModel.EQUIPGEM_HOLE_COUNT; i++)
|
{
|
holeRedpooints.Add(new Redpoint(repoint.id, EquipGemModel.REDPOINTBASE++));
|
holeInlayRedpoints.Add(new Redpoint(holeRedpooints[i].id, EquipGemModel.REDPOINTBASE++));
|
holeComposeRedpoints.Add(new Redpoint(holeRedpooints[i].id, EquipGemModel.REDPOINTBASE++));
|
}
|
}
|
|
public void SetInlayRedpoint(int hole, bool inlayable)
|
{
|
if (hole < holeInlayRedpoints.Count)
|
{
|
holeInlayRedpoints[hole].state = inlayable ? RedPointState.Simple : RedPointState.None;
|
}
|
}
|
|
public void SetComposeRedpoint(int hole, bool composeAble)
|
{
|
if (hole < holeComposeRedpoints.Count)
|
{
|
holeComposeRedpoints[hole].state = composeAble ? RedPointState.Simple : RedPointState.None;
|
}
|
}
|
|
public Redpoint GetInlayRedpoint(int hole)
|
{
|
if (hole < holeInlayRedpoints.Count)
|
{
|
return holeInlayRedpoints[hole];
|
}
|
return null;
|
}
|
|
public Redpoint GetComposeRedpoint(int hole)
|
{
|
if (hole < holeComposeRedpoints.Count)
|
{
|
return holeComposeRedpoints[hole];
|
}
|
return null;
|
}
|
|
public Redpoint GetHoleRedpoint(int hole)
|
{
|
if (hole < holeRedpooints.Count)
|
{
|
return holeRedpooints[hole];
|
}
|
return null;
|
}
|
}
|
|
public enum GemEquipType
|
{
|
MultiEquip,
|
}
|
}
|
|