using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
|
|
public class FaQiLVUPModel : ILModel<FaQiLVUPModel>
|
{
|
public int faqiLVUPItemID;
|
public int faqiLVUPStoreID;
|
public int faqiLV; //等阶
|
public int eatItemCount; //当前阶已吃丹个数
|
public event Action onFaqiUpdateEvent; //变化时
|
public event Action onFaqiLVChangeEvent; //升级时
|
|
public Dictionary<int, int> faqiLVUPAttr = new Dictionary<int, int>();
|
|
public List<int> attrSort = new List<int>() { 6, 7, 8, 18, 49 }; //面板显示顺序
|
public const int onceItemExp = 10; //一个材料的经验值
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModelEx<PackModel>(); } }
|
protected override void Init()
|
{
|
ParseConfig();
|
GameEvent.playerLoginOkEvent += OnPlayerLoginOk;
|
packModel.refreshItemCountEvent += RefreshItemCount;
|
}
|
|
protected override void UnInit()
|
{
|
GameEvent.playerLoginOkEvent -= OnPlayerLoginOk;
|
packModel.refreshItemCountEvent -= RefreshItemCount;
|
}
|
|
|
void ParseConfig()
|
{
|
faqiLVUPItemID = int.Parse(FuncConfigConfig.Get("FaQiUpItem").Numerical1);
|
faqiLVUPStoreID = int.Parse(FuncConfigConfig.Get("FaQiUpItem").Numerical2);
|
}
|
|
|
public void UpdateFaQiInfo(IL_HA354_tagMCFaQiInfo netPack)
|
{
|
bool isLVUP = false;
|
if (netPack.LV > faqiLV)
|
{
|
isLVUP = true;
|
}
|
faqiLV = netPack.LV;
|
eatItemCount = (int)netPack.EatItemCount;
|
RefreshFaQiLVUPAttr();
|
if (isLVUP)
|
{
|
onFaqiLVChangeEvent?.Invoke();
|
UpdateRedpoint();
|
}
|
onFaqiUpdateEvent?.Invoke();
|
}
|
|
|
private void RefreshItemCount(PackType type, int index, int id)
|
{
|
if (id == faqiLVUPItemID)
|
{
|
UpdateRedpoint();
|
}
|
|
}
|
|
public void RefreshFaQiLVUPAttr()
|
{
|
faqiLVUPAttr.Clear();
|
//丹经验属性
|
for (int i = 1; i <= faqiLV; i++)
|
{
|
var config = ILFaQiLVUpConfig.Get(i);
|
var eatCnt = 0;
|
if (config.useCnt == 0)
|
{
|
//最高级不计算
|
continue;
|
}
|
else if (i == faqiLV)
|
{
|
//当前等级取封包数量
|
eatCnt = eatItemCount / config.useCnt;
|
}
|
else
|
{
|
eatCnt = config.NeedEatCount / config.useCnt;
|
}
|
|
for (int j = 0; j < config.UpItemAttrType.Length; j++)
|
{
|
var upKey = config.UpItemAttrType[j];
|
if (!faqiLVUPAttr.ContainsKey(upKey))
|
{
|
faqiLVUPAttr[upKey] = 0;
|
}
|
|
faqiLVUPAttr[upKey] = faqiLVUPAttr[upKey] + eatCnt * config.UpItemAttrValue[j];
|
}
|
|
|
}
|
|
//升阶属性
|
for (int k = 1; k <= faqiLV; k++)
|
{
|
var config = ILFaQiLVUpConfig.Get(k);
|
for (int i = 0; i < config.LVAttrType.Length; i++)
|
{
|
var upKey = config.LVAttrType[i];
|
if (!faqiLVUPAttr.ContainsKey(upKey))
|
{
|
faqiLVUPAttr[upKey] = 0;
|
}
|
|
faqiLVUPAttr[upKey] = faqiLVUPAttr[upKey] + config.LVAttrValue[i];
|
}
|
}
|
}
|
|
//增加属性预览
|
public Dictionary<int, int> GetNextTrainAttr()
|
{
|
Dictionary<int, int> nextTrainAttr = new Dictionary<int, int>();
|
var NextTrainCount = GetTrainCount();
|
if (NextTrainCount == 0)
|
{
|
return nextTrainAttr;
|
}
|
var config = ILFaQiLVUpConfig.Get(faqiLV);
|
for (int i = 0; i < config.UpItemAttrType.Length; i++)
|
{
|
nextTrainAttr[config.UpItemAttrType[i]] = config.UpItemAttrValue[i];
|
}
|
|
if (eatItemCount + NextTrainCount >= config.NeedEatCount)
|
{
|
//有升阶的情况
|
var Nextconfig = ILFaQiLVUpConfig.Get(faqiLV + 1);
|
|
for (int i = 0; i < Nextconfig.LVAttrType.Length; i++)
|
{
|
if (!nextTrainAttr.ContainsKey(Nextconfig.LVAttrType[i]))
|
{
|
nextTrainAttr[Nextconfig.LVAttrType[i]] = 0;
|
}
|
nextTrainAttr[Nextconfig.LVAttrType[i]] = nextTrainAttr[Nextconfig.LVAttrType[i]] + Nextconfig.LVAttrValue[i];
|
}
|
}
|
|
return nextTrainAttr;
|
}
|
|
//单次培养所需个数
|
public int GetTrainCount()
|
{
|
var config = ILFaQiLVUpConfig.Get(faqiLV);
|
if (config.NeedEatCount == 0)
|
{
|
//已满级
|
return 0;
|
}
|
|
//var nextConfig = ILFaQiLVUpConfig.Get(faqiLV + 1);
|
//if (nextConfig.NeedEatCount == 0)
|
//{
|
// // 下一阶满级,只扣剩余所需不超过单次的材料数量
|
// if (config.NeedEatCount - eatItemCount < config.useCnt)
|
// {
|
// return config.NeedEatCount - eatItemCount;
|
// }
|
//}
|
|
return config.useCnt;
|
}
|
|
public void UpgradeFaqi(int Number, bool IsAutoBuy = false)//是否自动购买
|
{
|
IL_CA532_tagCMFaQiLVUp pack = new IL_CA532_tagCMFaQiLVUp();//向服务端发包坐骑经验单
|
pack.UseItemCnt = (ushort)Number;
|
pack.IsAutoBuy = (byte)(IsAutoBuy ? 1 : 0);
|
GameNetSystem.Instance.SendInfo(pack);
|
|
}
|
|
void OnPlayerLoginOk()
|
{
|
|
UpdateRedpoint();
|
}
|
|
public Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_key, MainRedPoint.faqiRedPoint);
|
public Redpoint redpoint1 = new Redpoint(MainRedPoint.faqiRedPoint, MainRedPoint.faqiRedPoint * 10 + 1);
|
void UpdateRedpoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(199)) return;
|
redpoint1.state = RedPointState.None;
|
var count = packModel.GetItemCountByID(PackType.Item, faqiLVUPItemID);
|
var onceCnt = GetTrainCount();
|
if (onceCnt == 0)
|
{
|
return;
|
}
|
if (count >= onceCnt)
|
{
|
redpoint1.state = RedPointState.Simple;
|
}
|
}
|
}
|