using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
namespace vnxbqy.UI
|
{
|
|
public class GatherSoulItem
|
{
|
public int soulID;
|
public int soulLevel;
|
public int soulCount;
|
|
public GatherSoulItem(int id, int lv, int count)
|
{
|
soulID = id;
|
soulLevel = lv;
|
soulCount = count;
|
}
|
}
|
|
public class GatheringSoulModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
public const int soulDustItemID = 37001; //魂尘物品ID
|
public const int xbItemID = 37000; //寻宝所需材料
|
public const int xbType = 4; //寻宝类型
|
public int selectSoulID = 0;
|
|
public float selectSoulTime = 0;
|
public int m_SelectEmptyHole; //选择的孔 从1开始
|
public int selectEmptyHole
|
{
|
get { return m_SelectEmptyHole; }
|
set
|
{
|
m_SelectEmptyHole = value;
|
selectSoulTime = Time.time;
|
if (m_SelectEmptyHole != 0)
|
OnSelectEmptyHoleChange?.Invoke();
|
}
|
}
|
public bool isOpenXBWin = false; //寻宝界面是否开启
|
public event Action OnSelectEmptyHoleChange; //触发格子重新排序
|
|
|
Dictionary<int, int> holeSoulDict = new Dictionary<int, int>(); //聚魂孔编号(1开始),聚魂ID
|
public event Action OnGatherSoulHoleRefresh;
|
|
Dictionary<int, GatherSoulItem> soulInfoDict = new Dictionary<int, GatherSoulItem>(); //拥有的聚魂信息 聚魂ID,等级;数量通过A206获取
|
List<int> soulPack = new List<int>(); //聚魂ID假背包列表,排除已出战的聚魂, 只用于界面显示,判断等需求用soulInfoDict
|
public event Action<bool> UpdateSoulInfos; //bool true表示聚魂种类不变,false表示有获得新的聚魂种类
|
|
public const int GATHERSOUL_REDPOINT_BASE = 10104;
|
public const int GATHERSOUL_REDPOINT_XB = 10107; //猎魂寻宝
|
|
Redpoint redpointpa = new Redpoint(MainRedDot.GatherSourRedpointEnter);
|
Redpoint redpoint = new Redpoint(MainRedDot.GatherSourRedpointEnter, GATHERSOUL_REDPOINT_BASE);
|
Redpoint redpointUp = new Redpoint(GATHERSOUL_REDPOINT_BASE, GATHERSOUL_REDPOINT_BASE * 10 + 9); //背包中可升级不需要公共材料
|
|
Redpoint redpointXB = new Redpoint(MainRedDot.GatherSourRedpointEnter, GATHERSOUL_REDPOINT_XB);
|
|
List<Redpoint> holeRepoints = new List<Redpoint>() {
|
new Redpoint(GATHERSOUL_REDPOINT_BASE, GATHERSOUL_REDPOINT_BASE * 10 + 0),
|
new Redpoint(GATHERSOUL_REDPOINT_BASE, GATHERSOUL_REDPOINT_BASE * 10 + 1),
|
new Redpoint(GATHERSOUL_REDPOINT_BASE, GATHERSOUL_REDPOINT_BASE * 10 + 2),
|
new Redpoint(GATHERSOUL_REDPOINT_BASE, GATHERSOUL_REDPOINT_BASE * 10 + 3),
|
new Redpoint(GATHERSOUL_REDPOINT_BASE, GATHERSOUL_REDPOINT_BASE * 10 + 4),
|
new Redpoint(GATHERSOUL_REDPOINT_BASE, GATHERSOUL_REDPOINT_BASE * 10 + 5),
|
};
|
|
VirtualPackModel virtualPackModel { get { return ModelCenter.Instance.GetModel<VirtualPackModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
public int[] baseAttrArray = new int[] { 7, 8, 6 };//攻防血
|
int totalSoulLV;
|
Dictionary<int, long> allAttrDict = new Dictionary<int, long>();
|
public List<int> attrIDList = new List<int>(); //排除攻防血的属性,排序显示
|
|
public int resetMoneyType;
|
public int resetMoney;
|
|
public override void Init()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
virtualPackModel.OnNoPackItemCountRefresh += VirtualPackModel_OnNoPackItemCountRefresh;
|
packModel.refreshItemCountEvent += OnRefreshItemCountEvent;
|
var arr = GeneralDefine.GetIntArray("GatherTheSoulHole", 2);
|
resetMoneyType = arr[0];
|
resetMoney = arr[1];
|
}
|
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
holeSoulDict.Clear();
|
soulInfoDict.Clear();
|
m_SelectEmptyHole = 0;
|
totalSoulLV = 0;
|
allAttrDict.Clear();
|
soulPack.Clear();
|
attrIDList.Clear();
|
selectSoulTime = 0;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
UpdateRedpointXB();
|
}
|
|
public override void UnInit()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
|
virtualPackModel.OnNoPackItemCountRefresh -= VirtualPackModel_OnNoPackItemCountRefresh;
|
packModel.refreshItemCountEvent -= OnRefreshItemCountEvent;
|
}
|
|
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
|
{
|
if (refreshType == PlayerDataType.default35)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
|
//孔红点:可升级,可出战;非出战的聚魂只要有一个可升级就只设置总标签红点,聚魂自身没有红点ID但有红点图片显示
|
void UpdateRedpoint()
|
{
|
for (int i = 0; i < holeRepoints.Count; i++)
|
{
|
holeRepoints[i].state = RedPointState.None;
|
}
|
redpointUp.state = RedPointState.None;
|
|
var keys = soulInfoDict.Keys.ToList();
|
for (int i = 0; i < holeRepoints.Count; i++)
|
{
|
int holeIndex = i + 1;
|
int soulID = GetHoleSoulID(holeIndex);
|
if (soulID == 0)
|
{
|
for (int j = 0; j < keys.Count; j++)
|
{
|
int soul = keys[j];
|
|
var config = GatherTheSoulConfig.Get(soul);
|
if (config.HoleNum == holeIndex)
|
{
|
var soulItem = soulInfoDict[soul];
|
if (soulItem.soulLevel > 0)
|
{
|
holeRepoints[i].state = RedPointState.Simple;
|
return;
|
}
|
|
if (CanLevelUp(soul))
|
{
|
holeRepoints[i].state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
}
|
else if (CanLevelUp(soulID))
|
{
|
holeRepoints[i].state = RedPointState.Simple;
|
return;
|
}
|
|
}
|
|
//背包中可升级不需要公共材料, 有一个可升级就显示红点
|
for (int j = 0; j < keys.Count; j++)
|
{
|
if (OnlyPieceCanLevelUp(keys[j]))
|
{
|
redpointUp.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
|
bool OnlyPieceCanLevelUp(int soulID)
|
{
|
int lv = GetSoulLevel(soulID);
|
var nextConfig = GatherTheSoulLVConfig.GetSoulLVConfig(soulID, lv + 1);
|
if (nextConfig == null)
|
return false;
|
|
if (nextConfig.NeedSoulValue > 0)
|
{
|
return false;
|
}
|
|
if (nextConfig.NeedPiece > 0 && GetSoulItemCount(soulID) < nextConfig.NeedPiece)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
|
void UpdateRedpointXB()
|
{
|
redpointXB.state = RedPointState.None;
|
if (packModel.GetItemCountByID(PackType.Item, xbItemID) > 0)
|
{
|
redpointXB.state = RedPointState.Simple;
|
}
|
}
|
|
//是否可以升级聚魂,includeSoulValue代表需要判断魂尘材料,false则不能升级
|
bool CanLevelUp(int soulID)
|
{
|
int lv = GetSoulLevel(soulID);
|
var nextConfig = GatherTheSoulLVConfig.GetSoulLVConfig(soulID, lv + 1);
|
if (nextConfig == null)
|
return false;
|
|
if (nextConfig.NeedSoulValue > 0 && UIHelper.GetMoneyCnt(44) < (ulong)nextConfig.NeedSoulValue)
|
{
|
return false;
|
}
|
|
if (nextConfig.NeedPiece > 0 && GetSoulItemCount(soulID) < nextConfig.NeedPiece)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
|
public void OnReceiveServerPack(HA361_tagMCGatherTheSoulHoleInfo package)
|
{
|
holeSoulDict.Clear();
|
for (int i = 0; i < package.Count; i++)
|
{
|
int soulID = (int)package.HoleSoulList[i];
|
GatherTheSoulConfig config = GatherTheSoulConfig.Get(soulID);
|
if (config == null)
|
continue;
|
holeSoulDict[config.HoleNum] = soulID;
|
}
|
|
SortGatherSoulPack();
|
OnGatherSoulHoleRefresh?.Invoke();
|
UpdateRedpoint();
|
}
|
|
//0代表未镶嵌,其他数字对应表中的聚魂ID品质
|
public void SetHoleBackGround(Image _image, int soulColor)
|
{
|
if (_image == null)
|
{
|
return;
|
}
|
_image.SetSprite(string.Format("GatherSoulHoleColor_{0}", soulColor));
|
}
|
|
|
public void UpdateSoulInfo(HA360_tagMCGatherTheSoulInfo vNetData)
|
{
|
int beforeCnt = soulInfoDict.Count;
|
for (int i = 0; i < vNetData.SoulList.Length; i++)
|
{
|
int soulID = (int)vNetData.SoulList[i].SoulID;
|
int lv = vNetData.SoulList[i].LV;
|
if (soulInfoDict.ContainsKey(soulID))
|
{
|
soulInfoDict[soulID].soulLevel = lv;
|
}
|
else
|
{
|
soulInfoDict[soulID] = new GatherSoulItem(soulID, lv, 0);
|
}
|
}
|
RefreshAllSoulAttr();
|
RefreshGatherSoulTotalLV();
|
UpdateSoulInfos?.Invoke(beforeCnt == soulInfoDict.Count);
|
UpdateRedpoint();
|
}
|
|
//获取聚魂孔已出战的魂ID,没有为0
|
public int GetHoleSoulID(int hole)
|
{
|
if (!holeSoulDict.ContainsKey(hole))
|
return 0;
|
return holeSoulDict[hole];
|
}
|
|
//获得某个聚魂ID的的等级
|
public int GetSoulLevel(int soulID)
|
{
|
if (!soulInfoDict.ContainsKey(soulID))
|
return 0;
|
return soulInfoDict[soulID].soulLevel;
|
}
|
|
//获取某个聚魂ID的当前物品数量
|
public int GetSoulItemCount(int soulID)
|
{
|
if (soulID == 0) return 0;
|
int itemID = GatherTheSoulConfig.Get(soulID).PieceItemID;
|
return virtualPackModel.GetNoPackItemCount(itemID);
|
}
|
|
//获取聚魂总等级
|
public int GetGatherSoulTotalLV()
|
{
|
return totalSoulLV;
|
}
|
|
public void RefreshGatherSoulTotalLV()
|
{
|
totalSoulLV = 0;
|
foreach (var item in soulInfoDict)
|
{
|
totalSoulLV += item.Value.soulLevel;
|
}
|
}
|
|
|
|
|
//所有聚魂的总属性
|
public Dictionary<int, long> GetAllSoulAttr()
|
{
|
return allAttrDict;
|
}
|
|
public void RefreshAllSoulAttr()
|
{
|
allAttrDict.Clear();
|
foreach (var item in soulInfoDict)
|
{
|
var config = GatherTheSoulLVConfig.GetSoulLVConfig(item.Key, item.Value.soulLevel);
|
if (config == null)
|
continue;
|
for (int i = 0; i < config.LVAttrType.Length; i++)
|
{
|
int attrType = config.LVAttrType[i];
|
long attrValue = config.LVAttrValue[i];
|
if (allAttrDict.ContainsKey(attrType))
|
{
|
allAttrDict[attrType] += attrValue;
|
}
|
else
|
{
|
allAttrDict[attrType] = attrValue;
|
}
|
}
|
}
|
|
attrIDList = allAttrDict.Keys.ToList();
|
foreach (var id in baseAttrArray)
|
{
|
if (attrIDList.Contains(id))
|
{
|
attrIDList.Remove(id);
|
}
|
}
|
if (!attrIDList.IsNullOrEmpty())
|
attrIDList.Sort((a, b) => {
|
PlayerPropertyConfig aConfig = PlayerPropertyConfig.Get(a);
|
PlayerPropertyConfig bConfig = PlayerPropertyConfig.Get(b);
|
if (aConfig.showSequence != bConfig.showSequence)
|
return aConfig.showSequence.CompareTo(bConfig.showSequence);
|
return a.CompareTo(b);
|
});
|
}
|
|
private void VirtualPackModel_OnNoPackItemCountRefresh()
|
{
|
int beforeCnt = soulInfoDict.Count;
|
var dict = virtualPackModel.GetAllNoPackItem();
|
foreach (var item in dict)
|
{
|
int soulID = GatherTheSoulConfig.GetSoulIDByItemID(item.Key);
|
if (soulID == 0)
|
continue;
|
|
if (soulInfoDict.ContainsKey(soulID))
|
{
|
soulInfoDict[soulID].soulCount = item.Value;
|
}
|
else
|
{
|
soulInfoDict[soulID] = new GatherSoulItem(soulID, 0, item.Value);
|
}
|
}
|
if (WindowCenter.Instance.IsOpen<GatherSoulWin>())
|
{
|
SortGatherSoulPack();
|
UpdateSoulInfos?.Invoke(beforeCnt == soulInfoDict.Count);
|
}
|
|
UpdateRedpoint();
|
}
|
|
|
//聚魂假背包列表排序,排除已出战的聚魂;第一次打开界面排序,点击聚魂孔后重新排序
|
//排序 选中的类型在前面 - 红点 - 孔顺序 - 品质高 - id顺序;已出战的不显示在队列中
|
public void SortGatherSoulPack()
|
{
|
soulPack.Clear();
|
soulPack = soulInfoDict.Keys.ToList();
|
|
foreach (var item in holeSoulDict)
|
{
|
if (soulPack.Contains(item.Value))
|
soulPack.Remove(item.Value);
|
}
|
|
|
soulPack.Sort((a, b) =>
|
{
|
var aConfig = GatherTheSoulConfig.Get(a);
|
var bConfig = GatherTheSoulConfig.Get(b);
|
bool isASelectHoleIndex = aConfig.HoleNum == m_SelectEmptyHole;
|
bool isBSelectHoleIndex = bConfig.HoleNum == m_SelectEmptyHole;
|
if (isASelectHoleIndex != isBSelectHoleIndex)
|
return isBSelectHoleIndex.CompareTo(isASelectHoleIndex);
|
|
bool canlvupA = OnlyPieceCanLevelUp(a);
|
bool canlvupB = OnlyPieceCanLevelUp(b);
|
|
if (canlvupA != canlvupB)
|
return canlvupB.CompareTo(canlvupA);
|
|
|
int aHole = aConfig.HoleNum;
|
int bHole = bConfig.HoleNum;
|
if (aHole != bHole)
|
return aHole.CompareTo(bHole);
|
|
int aQuality = aConfig.SoulColor;
|
int bQuality = bConfig.SoulColor;
|
if (aQuality != bQuality)
|
return bQuality.CompareTo(aQuality);
|
|
return a.CompareTo(b);
|
});
|
}
|
|
public List<int> GetGatherSoulPack()
|
{
|
return soulPack;
|
}
|
|
public void SendGatherTheSoulOP(int soulID, int opType)
|
{
|
CB225_tagCMGatherTheSoulOP package = new CB225_tagCMGatherTheSoulOP();
|
package.SoulID = (uint)soulID;
|
package.OpType = (byte)opType;
|
GameNetSystem.Instance.SendInfo(package);
|
}
|
|
//获取下一个技能激活的聚魂所需等级和达到技能等级, 0代表满级
|
public Int2 GetNextSkillLV(int soulID)
|
{
|
var config = GatherTheSoulConfig.Get(soulID);
|
int lv = GetSoulLevel(soulID);
|
int[] skillAttr = config.SoulSkillLVList; //技能激活所需的聚魂等级,索引代表技能等级从1开始
|
int nextSkillLV = 0;
|
int nextSoulLV = 0;
|
for (int i = 0; i < skillAttr.Length; i++)
|
{
|
if (lv < skillAttr[i])
|
{
|
nextSkillLV = i + 1;
|
nextSoulLV = skillAttr[i];
|
break;
|
}
|
}
|
|
return new Int2(nextSkillLV, nextSoulLV);
|
}
|
|
void OnRefreshItemCountEvent(PackType packType, int index, int itemID)
|
{
|
if (packType == PackType.Item && itemID == xbItemID)
|
{
|
UpdateRedpointXB();
|
}
|
}
|
}
|
}
|
|