using System.Collections.Generic;
|
using UnityEngine;
|
using LitJson;
|
|
public partial class HeroConfig : ConfigBase<int, HeroConfig>
|
{
|
public Dictionary<HeroAttrType, int> inheritPropertiesDict = new Dictionary<HeroAttrType, int>();
|
|
protected override void OnConfigParseCompleted()
|
{
|
base.OnConfigParseCompleted();
|
|
inheritPropertiesDict.Clear();
|
|
inheritPropertiesDict.Add(HeroAttrType.attack, AtkInheritPer);
|
inheritPropertiesDict.Add(HeroAttrType.defense, DefInheritPer);
|
inheritPropertiesDict.Add(HeroAttrType.hp, HPInheritPer);
|
|
|
// json格式
|
// {"属性ID":值, ...}
|
// 属性ID对应属性条目表的ID
|
// 有值的配即可,没有配置的属性默认0
|
JsonData jsonData = JsonMapper.ToObject(BatAttrDict);
|
|
foreach (var attrId in jsonData.Keys)
|
{
|
if (int.TryParse(attrId.ToString(), out int attrTypeId))
|
{
|
HeroAttrType attrType = (HeroAttrType)attrTypeId;
|
if (jsonData[attrId] != null && int.TryParse(jsonData[attrId].ToString(), out int value))
|
{
|
if (inheritPropertiesDict.ContainsKey(attrType))
|
{
|
Debug.LogError($"HeroTalentConfig: 属性 {attrType} 已经存在,无法重复添加。请检查配置文件。");
|
}
|
else
|
{
|
inheritPropertiesDict.Add(attrType, value);
|
}
|
}
|
}
|
}
|
}
|
|
public int GetInheritPercent(HeroAttrType attrType)
|
{
|
if (inheritPropertiesDict.TryGetValue(attrType, out int perc))
|
{
|
return perc;
|
}
|
|
return 0;
|
}
|
}
|