コード例 #1
0
ファイル: PropsCacheManager.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 添加基础属性
        /// </summary>
        /// <param name="index"></param>
        /// <param name="value"></param>
        public void SetExtProp(int index, double value)
        {
            double         change = 0;
            PropsCacheItem parent = ParentPropsCacheItem;

            lock (this)
            {
                change = value - ExtProps[index];
                if (change != 0)
                {
                    ExtProps[index] = value;

                    do
                    {
                        parent.ExtProps[index] += change;
                        if (null == parent.ParentPropsCacheItem)
                        {
                            parent.Age++;
                            break;
                        }
                        parent = parent.ParentPropsCacheItem;
                    } while (true);
                }
            }
        }
コード例 #2
0
ファイル: PropsCacheManager.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 获取所有的叶节点属性缓存项
        /// </summary>
        /// <returns></returns>
        public List <PropsCacheItem> GetAllPropsCacheItems(PropsCacheItem parent = null)
        {
            List <PropsCacheItem> list = new List <PropsCacheItem>();

            if (null == parent)
            {
                parent = PropsCacheRoot;
            }

            lock (PropsCacheRoot)
            {
                if (parent.SubPropsItemDict.Count > 0)
                {
                    foreach (var item in parent.SubPropsItemDict.Values)
                    {
                        list.AddRange(GetAllPropsCacheItems(item));
                    }
                }
                else
                {
                    list.Add(parent);
                }
            }

            return(list);
        }
コード例 #3
0
        public void SetExtProp(int index, double value)
        {
            PropsCacheItem parent = this.ParentPropsCacheItem;

            lock (this)
            {
                double change = value - this.ExtProps[index];
                if (change != 0.0)
                {
                    bool enable = this.nowkg;
                    this.ExtProps[index] = value;
                    while (enable && null != parent)
                    {
                        parent.ExtProps[index] += change;
                        if (null == parent.ParentPropsCacheItem)
                        {
                            parent.Age++;
                            this.UpdateExtPropCache(index, parent);
                            break;
                        }
                        enable = parent.nowkg;
                        parent = parent.ParentPropsCacheItem;
                    }
                }
            }
        }
コード例 #4
0
ファイル: PropsCacheManager.cs プロジェクト: chenchungit/ky
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="parent"></param>
 public PropsCacheItem(PropsCacheItem parent, int type)
 {
     ParentPropsCacheItem = parent;
     if (parent != null)
     {
         Path.AddRange(parent.Path);
         Path.Add(type);
     }
 }
コード例 #5
0
ファイル: PropsCacheManager.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 设置基础属性的值(数组)
        /// </summary>
        /// <param name="args"></param>
        public void SetBaseProps(params object[] args)
        {
            PropsCacheItem parent = PropsCacheRoot;
            PropsCacheItem child  = null;

            double[] props       = null;
            object   propsObject = null;

            if (args.Length > 1)
            {
                propsObject = args[args.Length - 1];
                EquipPropItem equipPropItem = args[args.Length - 1] as EquipPropItem;
                if (null != equipPropItem)
                {
                    props = equipPropItem.BaseProps;
                }
                else
                {
                    props = args[args.Length - 1] as double[];
                }
            }

            if (null == props)
            {
                return;
            }

            lock (PropsCacheRoot)
            {
                foreach (var obj in args)
                {
                    if (obj == propsObject)
                    {
                        if (child != null)
                        {
                            Contract.Assert(child.SubPropsItemDict.Count == 0, "only leaf node can set props!");
                            for (int i = 0; i < (int)UnitPropIndexes.Max && i < props.Length; i++)
                            {
                                child.SetBaseProp(i, props[i]);
                            }
                        }
                        break;
                    }
                    else
                    {
                        if (!parent.SubPropsItemDict.TryGetValue((int)obj, out child))
                        {
                            child = new PropsCacheItem(parent, Convert.ToInt32(obj));
                            parent.SubPropsItemDict.Add((int)obj, child);
                        }

                        parent = child;
                    }
                }
            }
        }
コード例 #6
0
 private void UpdateBasePropCache(int BaseProp, PropsCacheItem item)
 {
     if (null != RoleAlgorithm.BaseListArray[BaseProp])
     {
         int count = RoleAlgorithm.BaseListArray[BaseProp].Count;
         for (int i = 0; i < count; i++)
         {
             double value = RoleAlgorithm.GetExtProp(item.Client, (int)RoleAlgorithm.BaseListArray[BaseProp][i]);
             item.ExtPropsCache[(int)RoleAlgorithm.BaseListArray[BaseProp][i]] = value;
         }
     }
 }
コード例 #7
0
ファイル: PropsCacheManager.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 设置扩展属性的值(数组)
        /// </summary>
        /// <param name="args">系统类型(int),子系统类型(int),...,属性类型索引(int),属性值(double)</param>
        public void SetExtPropsSingle(params object[] args)
        {
            PropsCacheItem parent    = PropsCacheRoot;
            PropsCacheItem child     = null;
            double         propValue = 0;
            int            propIndex = -1;

            try
            {
                if (args.Length <= 2)
                {
                    return;
                }

                propIndex = (int)args[args.Length - 2];
                propValue = Convert.ToDouble(args[args.Length - 1]);
            }
            catch (System.Exception ex)
            {
                LogManager.WriteException(ex.ToString());
                return;
            }

            if (propIndex < 0 || propIndex >= (int)ExtPropIndexes.Max)
            {
                return;
            }

            lock (PropsCacheRoot)
            {
                for (int i = 0; i < args.Length - 2; i++)
                {
                    if (!parent.SubPropsItemDict.TryGetValue((int)args[i], out child))
                    {
                        child = new PropsCacheItem(parent, Convert.ToInt32(args[i]));
                        parent.SubPropsItemDict.Add((int)args[i], child);
                    }

                    parent = child;
                }

                if (child != null)
                {
                    Contract.Assert(child.SubPropsItemDict.Count == 0, "only leaf node can set props!");
                    child.SetExtProp(propIndex, propValue);
                }
            }
        }
コード例 #8
0
        public void SetNodeBool(bool kg)
        {
            PropsCacheItem parent = this.ParentPropsCacheItem;

            lock (this)
            {
                if (this.nowkg != kg)
                {
                    if (this.nowkg)
                    {
                        for (int i = 0; i < 177; i++)
                        {
                            if (this.ExtProps[i] != 0.0)
                            {
                                parent.SetExtProp(i, parent.ExtProps[i] - this.ExtProps[i]);
                            }
                        }
                        for (int i = 0; i < 4; i++)
                        {
                            if (this.BaseProps[i] != 0.0)
                            {
                                parent.SetBaseProp(i, parent.BaseProps[i] - this.BaseProps[i]);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 177; i++)
                        {
                            if (this.ExtProps[i] != 0.0)
                            {
                                parent.SetExtProp(i, parent.ExtProps[i] + this.ExtProps[i]);
                            }
                        }
                        for (int i = 0; i < 4; i++)
                        {
                            if (this.BaseProps[i] != 0.0)
                            {
                                parent.SetBaseProp(i, parent.BaseProps[i] + this.BaseProps[i]);
                            }
                        }
                    }
                }
                this.nowkg = kg;
            }
        }
コード例 #9
0
        public void SetNodeState(params object[] args)
        {
            PropsCacheItem parent = this.PropsCacheRoot;
            bool           enable;

            try
            {
                if (args.Length <= 1)
                {
                    return;
                }
                enable = (bool)args[args.Length - 1];
            }
            catch (Exception ex)
            {
                LogManager.WriteException(ex.ToString());
                return;
            }
            lock (this.PropsCacheRoot)
            {
                PropsCacheItem child = null;
                for (int i = 0; i < args.Length - 1; i++)
                {
                    if (!parent.SubPropsItemDict.TryGetValue((int)args[i], out child))
                    {
                        child = new PropsCacheItem(parent, Convert.ToInt32(args[i]));
                        parent.SubPropsItemDict.Add((int)args[i], child);
                    }
                    parent = child;
                }
                if (child != null)
                {
                    child.SetNodeBool(enable);
                }
            }
        }
コード例 #10
0
ファイル: PropsCacheManager.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 设置扩展属性的值(数组)
        /// </summary>
        /// <param name="args">系统类型(int),子系统类型(int),...,属性值数组(double[])</param>
        public void SetExtProps(params object[] args)
        {
            PropsCacheItem parent = PropsCacheRoot;

            PropsCacheItem child = null;

            double[] props       = null;
            object   propsObject = null;

            try
            {
                if (args.Length > 1)
                {
                    propsObject = args[args.Length - 1];
                    EquipPropItem equipPropItem = propsObject as EquipPropItem;
                    if (null != equipPropItem)
                    {
                        props = equipPropItem.ExtProps;
                    }
                    else
                    {
                        props = args[args.Length - 1] as double[];
                    }
                }

                lock (PropsCacheRoot)
                {
                    foreach (var obj in args)
                    {
                        if (obj == propsObject)
                        {
                            if (child != null)
                            {
                                Contract.Assert(child.SubPropsItemDict.Count == 0, "only leaf node can set props!");
                                if (null != props)
                                {
                                    for (int i = 0; i < (int)ExtPropIndexes.Max && i < props.Length; i++)
                                    {
                                        child.SetExtProp(i, props[i]);
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < (int)ExtPropIndexes.Max; i++)
                                    {
                                        child.SetExtProp(i, 0);
                                    }
                                }
                            }

                            break;
                        }
                        else
                        {
                            if (!parent.SubPropsItemDict.TryGetValue((int)obj, out child))
                            {
                                child = new PropsCacheItem(parent, Convert.ToInt32(obj));
                                parent.SubPropsItemDict.Add((int)obj, child);
                            }

                            parent = child;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogManager.WriteException(ex.ToString());
            }
        }