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;
|
|
|
Dictionary<int, HorseSkin> skinDic = new Dictionary<int, HorseSkin>();
|
public event Action OnSkinUpdateEvent;
|
|
//升级/升阶属性
|
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>();
|
|
int m_selectSkinID;
|
public event Action OnSelectEvent;
|
public int selectSkinID
|
{
|
get { return m_selectSkinID; }
|
set
|
{
|
m_selectSkinID = value;
|
OnSelectEvent?.Invoke();
|
}
|
}
|
//配置
|
public int lvUPItemID;
|
public int rankUPItemID;
|
public int quickRankLV;
|
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitialize;
|
PackManager.Instance.RefreshItemEvent += OnRefreshItemEvent;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
|
|
ParseConfig();
|
}
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitialize;
|
PackManager.Instance.RefreshItemEvent -= OnRefreshItemEvent;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
|
}
|
|
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 OnPlayerLoginOk()
|
{
|
UpdateSkinRedpoint();
|
}
|
|
void OnRefreshItemEvent(PackType type, int index, int itemID)
|
{
|
if (type == PackType.Item)
|
{
|
if (itemID == lvUPItemID || itemID == rankUPItemID)
|
{
|
UpdateRedpoint();
|
}
|
|
if (HorseSkinConfig.itemsList.Contains(itemID))
|
{
|
UpdateSkinRedpoint();
|
}
|
}
|
}
|
|
//获取当前使用坐骑皮肤ID
|
public int GetUsingHorseSkinID(bool useDefault = false)
|
{
|
var id = (int)PlayerDatas.Instance.baseData.equipShowSwitch % 1000;
|
if (id == 0)
|
{
|
if (useDefault)
|
{
|
return 1;
|
}
|
}
|
return id;
|
}
|
|
//获取其他玩家使用坐骑皮肤ID
|
public int GetOtherPlayerHorseSkinID(int value)
|
{
|
return value % 1000;
|
}
|
|
|
public void UpdateHorseInfo(HA303_tagSCHorseClassInfo netPack)
|
{
|
bool isOpenSuccess = false;
|
if (classLV != netPack.ClassLV && DTC0403_tagPlayerLoginLoadOK.finishedLogin)
|
{
|
isOpenSuccess = true;
|
}
|
classLV = netPack.ClassLV;
|
horseLV = netPack.HorseLV;
|
exp = netPack.Exp;
|
UpdateRedpoint();
|
UpdateSkinRedpoint();
|
RefreshAttr();
|
OnHorseUpdateEvent?.Invoke();
|
if (isOpenSuccess)
|
{
|
UIManager.Instance.OpenWindow<HorseSuccessWin>();
|
}
|
|
}
|
|
|
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();
|
UpdateSkinRedpoint();
|
OnSkinUpdateEvent?.Invoke();
|
|
if (DTC0403_tagPlayerLoginLoadOK.finishedLogin && netPack.HorseSkinList[0].Star == 0)
|
{
|
UIManager.Instance.OpenWindow<HorseSkinGetWin>(netPack.HorseSkinList[0].HorseSkinID);
|
}
|
|
}
|
|
#region 红点
|
Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_HorseKey, MainRedDot.RedPoint_HorseKey * 10 + 1);
|
Redpoint skinRedpoint = new Redpoint(MainRedDot.RedPoint_HorseKey, MainRedDot.RedPoint_HorseKey * 10 + 2);
|
|
|
void UpdateRedpoint()
|
{
|
redpoint.state = RedPointState.None;
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Horse))
|
{
|
return;
|
}
|
|
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;
|
}
|
}
|
}
|
|
//皮肤红点
|
void UpdateSkinRedpoint()
|
{
|
skinRedpoint.state = RedPointState.None;
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Horse))
|
{
|
return;
|
}
|
|
if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin)
|
{
|
return;
|
}
|
|
|
//升星/解锁红点
|
foreach (var skin in HorseSkinConfig.GetValues())
|
{
|
if (IsSkinActive(skin.SkinID))
|
{
|
if (skin.StarMax > 0)
|
{
|
//皮肤升星红点
|
int itemID = skin.UnlockValue;
|
var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
|
if (count >= skin.UpNeedCnt && skinDic[skin.SkinID].Star < skin.StarMax)
|
{
|
skinRedpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
else
|
{
|
|
if (skin.UnlockWay == 1)
|
{
|
if (classLV >= skin.UnlockValue && skin.UnlockValue > 0)
|
{
|
skinRedpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
else
|
{
|
//皮肤解锁红点
|
int itemID = skin.UnlockValue;
|
var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
|
if (count >= skin.UnlockNeedCnt)
|
{
|
skinRedpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
|
}
|
}
|
|
public bool IsSkinActive(int id)
|
{
|
if (skinDic.TryGetValue(id, out var skin))
|
{
|
if (skin.State == 1 && skin.EndTime == 0)
|
{
|
return true;
|
}
|
else if (skin.State == 1 && skin.EndTime > 0 && skin.EndTime > TimeUtility.AllSeconds)
|
{
|
return true;
|
}
|
}
|
var config = HorseSkinConfig.Get(id);
|
if (config.UnlockWay == 1 && config.UnlockValue == 0)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
public bool IsShowTheHorseRedImg(int skinID)
|
{
|
var skin = HorseSkinConfig.Get(skinID);
|
|
if (IsSkinActive(skin.SkinID))
|
{
|
if (skin.StarMax > 0)
|
{
|
//皮肤升星红点
|
int itemID = skin.UnlockValue;
|
var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
|
if (count >= skin.UpNeedCnt && skinDic[skinID].Star < skin.StarMax)
|
{
|
return true;
|
}
|
}
|
}
|
else
|
{
|
|
if (skin.UnlockWay == 1)
|
{
|
if (classLV >= skin.UnlockValue && skin.UnlockValue > 0)
|
{
|
return true;
|
}
|
}
|
else
|
{
|
//皮肤解锁红点
|
int itemID = skin.UnlockValue;
|
var count = PackManager.Instance.GetItemCountByID(PackType.Item, itemID);
|
if (count >= skin.UnlockNeedCnt)
|
{
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
|
|
//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;
|
|
}
|
#endregion
|
|
#region 属性
|
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;
|
}
|
#endregion
|
|
public List<int> sortSkinList = new List<int>();
|
public void SortHorseSkinList()
|
{
|
sortSkinList = HorseSkinConfig.GetKeys();
|
sortSkinList.Sort((a, b) =>
|
{
|
var isActiveA = IsSkinActive(a);
|
var isActiveB = IsSkinActive(b);
|
if (isActiveA != isActiveB)
|
{
|
return isActiveA ? -1 : 1;
|
}
|
var skinA = HorseSkinConfig.Get(a);
|
var skinB = HorseSkinConfig.Get(b);
|
return skinA.SkinID - skinB.SkinID;
|
});
|
}
|
|
public Dictionary<int, long> GetAttrBySkinID(HorseSkinConfig config)
|
{
|
Dictionary<int, long> tmpDict = new Dictionary<int, long>();
|
|
if (!config.InitAttrValueList.IsNullOrEmpty())
|
{
|
for (int i = 0; i < config.AttrIDList.Length; i++)
|
{
|
if (!tmpDict.ContainsKey(config.AttrIDList[i]))
|
{
|
tmpDict[config.AttrIDList[i]] = 0;
|
}
|
tmpDict[config.AttrIDList[i]] += config.InitAttrValueList[i];
|
}
|
}
|
|
if (!config.AttrPerStarAddList.IsNullOrEmpty())
|
{
|
var star = 0;
|
if (skinDic.TryGetValue(config.SkinID, out var skin))
|
{
|
star = skin.Star;
|
}
|
for (int i = 0; i < config.AttrIDList.Length; i++)
|
{
|
if (!tmpDict.ContainsKey(config.AttrIDList[i]))
|
{
|
tmpDict[config.AttrIDList[i]] = 0;
|
}
|
tmpDict[config.AttrIDList[i]] += config.AttrPerStarAddList[i] * star;
|
}
|
}
|
return tmpDict;
|
}
|
|
public HorseSkin GetSkinData(int skinID)
|
{
|
skinDic.TryGetValue(skinID, out var skin);
|
return skin;
|
}
|
|
//// 操作 1-激活;2-佩戴;3-升星
|
public void SendSkinOP(int opType, int skinID)
|
{
|
var pack = new CB203_tagCSHorseSkinOP();
|
pack.OPType = (byte)opType;
|
pack.SkinID = (ushort)skinID;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
}
|
|
public class HorseSkin {
|
public int State; //是否已激活
|
public int EndTime; //到期时间戳,0为永久
|
public int Star; //星级
|
}
|
|