using System;
|
using LitJson;
|
|
using System.Collections.Generic;
|
using System.Linq;
|
|
public class HorseManager : GameSystemManager<HorseManager>
|
{
|
public int classLV; //当前阶级,从0开始
|
public int horseLV; //当前阶等级,从1开始
|
public int exp; //当前阶等级经验,每级从0开始
|
public event Action OnHorseUpdateEvent;
|
|
public Dictionary<int, HorseSkin> skinDic = new Dictionary<int, HorseSkin>();
|
|
//升级/升阶属性
|
public Dictionary<int, long> specialAttrDic = new Dictionary<int, long>();
|
public Dictionary<int, long> attrDic = new Dictionary<int, long>();
|
public Dictionary<int, long> skinAttrDic = new Dictionary<int, long>();
|
|
//配置
|
public int lvUPItemID;
|
public int rankUPItemID;
|
public int quickRankLV;
|
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
|
PackManager.Instance.RefreshItemEvent += OnRefreshItemEvent;
|
|
ParseConfig();
|
}
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
|
PackManager.Instance.RefreshItemEvent -= OnRefreshItemEvent;
|
}
|
|
void ParseConfig()
|
{
|
var config = FuncConfigConfig.Get("HorseUpItem");
|
lvUPItemID = int.Parse(config.Numerical1);
|
rankUPItemID = int.Parse(config.Numerical2);
|
quickRankLV = int.Parse(config.Numerical3);
|
}
|
|
void OnBeforePlayerDataInitialize()
|
{
|
classLV = 0;
|
horseLV = 0;
|
exp = 0;
|
skinDic.Clear();
|
}
|
|
void OnRefreshItemEvent(PackType type, int index, int itemID)
|
{
|
if (type == PackType.Item)
|
{
|
if (itemID == lvUPItemID || itemID == rankUPItemID)
|
{
|
UpdateRedpoint();
|
}
|
}
|
}
|
|
public int GetHorseSkinID()
|
{
|
return (int)PlayerDatas.Instance.baseData.equipShowSwitch%100;
|
}
|
|
public void UpdateHorseInfo(HA303_tagSCHorseClassInfo netPack)
|
{
|
classLV = netPack.ClassLV;
|
horseLV = netPack.HorseLV;
|
exp = netPack.Exp;
|
UpdateRedpoint();
|
RefreshAttr();
|
OnHorseUpdateEvent?.Invoke();
|
}
|
|
|
public void UpdateHorseSkinInfo(HA304_tagSCHorseSkinInfo netPack)
|
{
|
for (int i = 0; i < netPack.HorseSkinList.Length; i++)
|
{
|
skinDic[netPack.HorseSkinList[i].HorseSkinID] = new HorseSkin()
|
{
|
State = netPack.HorseSkinList[i].State,
|
EndTime = (int)netPack.HorseSkinList[i].EndTime,
|
Star = netPack.HorseSkinList[i].Star
|
};
|
}
|
|
RefreshSkinAttr();
|
UpdateRedpoint();
|
OnHorseUpdateEvent?.Invoke();
|
}
|
|
Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_HorseKey);
|
void UpdateRedpoint()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Horse))
|
{
|
return;
|
}
|
|
redpoint.state = RedPointState.None;
|
var state = GetHorseState();
|
if (state == 0)
|
{
|
if (PackManager.Instance.GetItemCountByID(PackType.Item, lvUPItemID) > 0)
|
{
|
redpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
else if (state == 1)
|
{
|
var config = HorseClassConfig.Get(classLV);
|
if (PackManager.Instance.GetItemCountByID(PackType.Item, rankUPItemID) >= config.ClassUPItemCnt)
|
{
|
redpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
|
//0 升级 1 升阶 2 满级
|
public int GetHorseState()
|
{
|
if (HorseClassConfig.maxLVDict.TryGetValue(classLV, out int maxLV))
|
{
|
if (horseLV < maxLV)
|
{
|
return 0;
|
}
|
else if (horseLV >= maxLV)
|
{
|
if (classLV == HorseClassConfig.maxLVDict.Count - 1)
|
{
|
//从0阶级开始
|
return 2;
|
}
|
return 1;
|
}
|
}
|
|
return 2;
|
|
}
|
|
|
public void RefreshAttr()
|
{
|
specialAttrDic.Clear();
|
attrDic.Clear();
|
for (int lv = 0; lv <= classLV; lv++)
|
{
|
//按阶加成
|
var config = HorseClassConfig.Get(lv);
|
if (!config.ClassSpecAttrIDList.IsNullOrEmpty())
|
{
|
for (int i = 0; i < config.ClassSpecAttrIDList.Length; i++)
|
{
|
if (!specialAttrDic.ContainsKey(config.ClassSpecAttrIDList[i]))
|
{
|
specialAttrDic[config.ClassSpecAttrIDList[i]] = 0;
|
}
|
specialAttrDic[config.ClassSpecAttrIDList[i]] += config.ClassSpecAttrValueList[i];
|
}
|
}
|
|
if (!config.ClassAttrValueList.IsNullOrEmpty())
|
{
|
for (int i = 0; i < config.AttrIDList.Length; i++)
|
{
|
if (!attrDic.ContainsKey(config.AttrIDList[i]))
|
{
|
attrDic[config.AttrIDList[i]] = 0;
|
}
|
attrDic[config.AttrIDList[i]] += config.ClassAttrValueList[i];
|
}
|
}
|
|
//按等级加成
|
if (!config.PerLVAttrValueList.IsNullOrEmpty())
|
{
|
for (int i = 0; i < config.AttrIDList.Length; i++)
|
{
|
if (!attrDic.ContainsKey(config.AttrIDList[i]))
|
{
|
attrDic[config.AttrIDList[i]] = 0;
|
}
|
var tmpHorseLV = lv != classLV ? config.MaxLV :horseLV;
|
|
attrDic[config.AttrIDList[i]] += config.PerLVAttrValueList[i]*tmpHorseLV;
|
}
|
}
|
}
|
}
|
|
//刷新皮肤属性
|
void RefreshSkinAttr()
|
{
|
skinAttrDic.Clear();
|
foreach(var skinID in skinDic.Keys)
|
{
|
var skin = skinDic[skinID];
|
if (skin.State != 1)
|
{
|
continue;
|
}
|
|
var config = HorseSkinConfig.Get(skinID);
|
|
if (config.AttrIDList.IsNullOrEmpty())
|
{
|
continue;
|
}
|
if (!config.InitAttrValueList.IsNullOrEmpty())
|
{
|
for (int i = 0; i < config.AttrIDList.Length; i++)
|
{
|
if (!skinAttrDic.ContainsKey(config.AttrIDList[i]))
|
{
|
skinAttrDic[config.AttrIDList[i]] = 0;
|
}
|
skinAttrDic[config.AttrIDList[i]] += config.InitAttrValueList[i];
|
}
|
}
|
|
if (!config.AttrPerStarAddList.IsNullOrEmpty())
|
{
|
for (int i = 0; i < config.AttrIDList.Length; i++)
|
{
|
if (!skinAttrDic.ContainsKey(config.AttrIDList[i]))
|
{
|
skinAttrDic[config.AttrIDList[i]] = 0;
|
}
|
skinAttrDic[config.AttrIDList[i]] += config.AttrPerStarAddList[i]*skin.Star;
|
}
|
}
|
}
|
}
|
|
public long GetAttrValue(int attrID)
|
{
|
attrDic.TryGetValue(attrID, out long value);
|
specialAttrDic.TryGetValue(attrID, out long specialValue);
|
skinAttrDic.TryGetValue(attrID, out long skinValue);
|
return value + specialValue + skinValue;
|
}
|
|
public int GetAttrPer(int attrID)
|
{
|
if (PlayerPropertyConfig.baseAttr2perDict.ContainsKey(attrID))
|
{
|
var pertype = PlayerPropertyConfig.baseAttr2perDict[attrID];
|
attrDic.TryGetValue(pertype, out long value);
|
specialAttrDic.TryGetValue(pertype, out long specialValue);
|
skinAttrDic.TryGetValue(pertype, out long skinValue);
|
|
return (int)(value + specialValue + skinValue);
|
}
|
|
return 0;
|
}
|
}
|
|
public class HorseSkin {
|
public int State; //是否已激活
|
public int EndTime; //到期时间戳,0为永久
|
public int Star; //星级
|
}
|
|