Example #1
0
        /// <summary>
        /// 重新计算属性
        /// </summary>
        /// <param name="isInit"></param>
        public void Rebuild(bool isInit = false)
        {
            if (isInit)
            {
                finalAttr.Clear();
            }

            Dictionary <T, AttrChangeUnit> changeMap = new Dictionary <T, AttrChangeUnit>();

            //先计算一级属性
            foreach (var attrId in Config.OneLevelAttrs)
            {
                var value    = CalcLevelOneAttr(attrId);
                var oldValue = finalAttr[attrId];
                finalAttr.Set(attrId, value);
                if (!GAttr.Equal(value, oldValue))
                {
                    //有变化
                    if (Config.oneLevelRelationMap.TryGetValue(attrId, out Dictionary <T, double> relations))
                    {
                        foreach (var entry in relations)
                        {
                            AddChange(entry.Key);
                        }
                    }
                    changeMap.Add(attrId, new AttrChangeUnit(oldValue, value));
                }
            }

            //再计算二级属性
            foreach (var entry in changeAttrList)
            {
                var attrId = GAttr.GetAttrType(entry);
                //不是一级属性,并且不是属性类型,另外非初始化时不在变化列表里
                if (Config.IsLevelOneAttr(attrId) ||
                    (!isInit && !changeAttrList.Contains(attrId)))
                {
                    continue;
                }
                var value    = CalcLevelTwoAttr(attrId);
                var oldValue = finalAttr[attrId];
                finalAttr.Set(attrId, value);
                changeMap.Add(attrId, new AttrChangeUnit(oldValue, value));
            }
            changeAttrList.Clear();
            OnRebuildFinish(changeMap, isInit);
        }
Example #2
0
 protected void AddChange(T attrId)
 {
     changeAttrList.Add(GAttr.GetAttrType(attrId));
 }