lcy
3 小时以前 e2e187e1ec82f4fe2979883318fc59278c05bca3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System.Collections.Generic;
 
public class AttributeManager : GameSystemManager<AttributeManager>
{
    public Dictionary<int, long> totalAttrDict = new Dictionary<int, long>();
    public void OpenTotalAttributeWin(Dictionary<int, long> totalAttrDict, int functionOrder = 0)
    {
        this.totalAttrDict = totalAttrDict;
        if (!UIManager.Instance.IsOpened<TotalAttributeWin>())
        {
            UIManager.Instance.OpenWindow<TotalAttributeWin>(functionOrder);
        }
    }
 
    public readonly int SimpleAttributeMaxRowCnt = 2;
    public Dictionary<int, long> simpleAttrDict = new Dictionary<int, long>();
    public List<int> simpleAttrSortList = new List<int>();
    public string simpleAttrTitleName = string.Empty;
    public void OpenSimpleAttributeWin(Dictionary<int, long> simpleAttrs, string titleNameKey = "")
    {
        simpleAttrDict = FilterValidAttributes(simpleAttrs);
        simpleAttrSortList = SortAttrId(simpleAttrDict);
        simpleAttrTitleName = Language.Get(string.IsNullOrEmpty(titleNameKey) ? "AttributeTitle00" : titleNameKey);
        if (!UIManager.Instance.IsOpened<SimpleAttributeWin>())
        {
            UIManager.Instance.OpenWindow<SimpleAttributeWin>();
        }
    }
 
    // 命格专用
    public Dictionary<int, int> skillDic = new Dictionary<int, int>();
    public List<int> skillList = new List<int>();
    public void OpenMinggeSimpleAttributeWin(Dictionary<int, long> simpleAttrs, Dictionary<int, int> skills)
    {
 
        if (skills.IsNullOrEmpty())
        {
            OpenSimpleAttributeWin(simpleAttrs, "AttributeTitle03");
            return;
        }
        simpleAttrDict = FilterValidAttributes(simpleAttrs);
        simpleAttrSortList = SortAttrId(simpleAttrDict);
        simpleAttrTitleName = Language.Get("AttributeTitle03");
        skillDic = skills;
        skillList = new List<int>(skillDic.Keys);
        skillList.Sort();
        if (!UIManager.Instance.IsOpened<SimpleMinggeAttributeWin>())
        {
            UIManager.Instance.OpenWindow<SimpleMinggeAttributeWin>();
        }
    }
 
 
    public bool TryGetInfoBySkillID(int skillTypeID, int lv, out string name, out string desc)
    {
        name = string.Empty;
        desc = string.Empty;
        if (!SkillConfig.HasKey(skillTypeID))
            return false;
        SkillConfig config = SkillConfig.Get(skillTypeID + lv - 1);
        name = Language.Get("OtherPlayerDetail14", Language.Get($"MinggeSkillType_{skillTypeID}"), lv);
        desc = config.Description;
        return true;
    }
 
 
    /// <summary>
    /// 过滤有效的属性:移除value<=0或showType<=0或不在配置表中的项
    /// </summary>
    private Dictionary<int, long> FilterValidAttributes(Dictionary<int, long> dict)
    {
        if (dict == null)
            return null;
 
        var result = new Dictionary<int, long>();
        foreach (var kvp in dict)
        {
            if (!PlayerPropertyConfig.HasKey(kvp.Key))
                continue;
            PlayerPropertyConfig config = PlayerPropertyConfig.Get(kvp.Key);
            if (kvp.Value > 0 && config.showType > 0 && config.showType < 5)
            {
                result.Add(kvp.Key, kvp.Value);
            }
        }
        return result;
    }
 
    /// <summary>
    /// 根据PlayerPropertyConfig的showType和showSequence对属性ID进行排序
    /// 排序规则:先按showType升序,showType相同按showSequence升序,showSequence相同按ID升序
    /// </summary>
    private List<int> SortAttrId(Dictionary<int, long> dict)
    {
        if (dict == null)
            return null;
        var list = new List<int>(dict.Keys);
        list.Sort((a, b) =>
        {
            bool hasKeyA = PlayerPropertyConfig.HasKey(a);
            bool hasKeyB = PlayerPropertyConfig.HasKey(b);
            // 如果一个在表中一个不在,将不在表的排在后面
            if (hasKeyA != hasKeyB)
                return hasKeyA.CompareTo(hasKeyB);
 
            var configA = PlayerPropertyConfig.Get(a);
            var configB = PlayerPropertyConfig.Get(b);
            int showTypeA = configA?.showType ?? 0;
            int showTypeB = configB?.showType ?? 0;
 
            if (showTypeA != showTypeB)
                return showTypeA.CompareTo(showTypeB);
 
            int showSequenceA = configA?.showSequence ?? 0;
            int showSequenceB = configB?.showSequence ?? 0;
            if (showSequenceA != showSequenceB)
                return showSequenceA.CompareTo(showSequenceB);
 
            return a.CompareTo(b);
        });
        return list;
    }
}