using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text.RegularExpressions;
|
|
public partial class PlayerPropertyConfig : ConfigBase<int, PlayerPropertyConfig>
|
{
|
private static Dictionary<int, List<PlayerPropertyConfig>> m_PropCfgs = new Dictionary<int, List<PlayerPropertyConfig>>();
|
private static Dictionary<int, List<int>> outputDict = new Dictionary<int, List<int>>();
|
|
protected override void OnConfigParseCompleted()
|
{
|
List<PlayerPropertyConfig> list = null;
|
m_PropCfgs.TryGetValue(type, out list);
|
if (list != null)
|
{
|
list.Add(this);
|
}
|
else
|
{
|
list = new List<PlayerPropertyConfig>();
|
list.Add(this);
|
m_PropCfgs.Add(type, list);
|
}
|
}
|
public static Dictionary<int, List<int>> GetShowDict()
|
{
|
if (outputDict.IsNullOrEmpty())
|
{
|
var keys = GetKeys();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
int id = keys[i];
|
int showType = Get(id).showType;
|
if (showType == 0) //为0时不显示
|
continue;
|
if (!outputDict.ContainsKey(showType))
|
{
|
outputDict[showType] = new List<int> { id };
|
}
|
else
|
{
|
outputDict[showType].Add(id);
|
}
|
}
|
var outputList = outputDict.Keys.ToList();
|
for (int i = 0; i < outputList.Count; i++)
|
{
|
int showType = outputList[i];
|
outputDict[showType].Sort(cmp);
|
}
|
}
|
return outputDict;
|
}
|
|
static int cmp(int id1, int id2)
|
{
|
var config1 = Get(id1);
|
var config2 = Get(id2);
|
|
return config1.showSequence.CompareTo(config2.showSequence);
|
}
|
|
public static List<PlayerPropertyConfig> GetPropByType(int type)
|
{
|
List<PlayerPropertyConfig> list = null;
|
m_PropCfgs.TryGetValue(type, out list);
|
return list;
|
}
|
|
|
public static string GetFullDescription(Int2 property)
|
{
|
return GetFullDescription(property.x, property.y);
|
}
|
|
public static string GetFullDescription(int id, long value)
|
{
|
var config = Get(id);
|
if (config == null)
|
{
|
return string.Empty;
|
}
|
|
if (config.Name.Contains("%s"))
|
{
|
if (id == 52)
|
{
|
return Regex.Replace(config.Name, "%s", (value * 0.0001f).ToString("f2"));
|
}
|
else
|
{
|
return Regex.Replace(config.Name, "%s", value.ToString());
|
}
|
}
|
else
|
{
|
return string.Format("{0} +{1}", config.Name, GetValueDescription(id, value));
|
}
|
}
|
|
public static string GetValueDescription(int id, long value)
|
{
|
return GetValueDescription(id, value, false);
|
}
|
|
public static string GetValueDescription(int id, long value, bool largeValue)
|
{
|
var config = Get(id);
|
if (config == null)
|
{
|
return string.Empty;
|
}
|
|
double result = 0f;
|
if (config.ISPercentage == 0)
|
{
|
result = value;
|
}
|
else if (config.ISPercentage == 1)
|
{
|
result = (double)Math.Round(value / 100f, config.decimalCount);
|
}
|
else if (config.ISPercentage == 2)
|
{
|
result = (double)Math.Round(value / 100f, config.decimalCount);
|
}
|
|
var label = string.Empty;
|
if (largeValue)
|
{
|
label = UIHelper.ReplaceLargeNum(result);
|
}
|
else
|
{
|
label = result.ToString();
|
}
|
|
return config.ISPercentage == 1 ? (label + "%") : label;
|
}
|
}
|