예제 #1
0
        public static void Run(this BuffWatcherComponent self, int type, bool isAdd, Unit unit)
        {
            var key = isAdd ? type : -type;
            List <IBuffWatcher> list;

            if (!self.allWatchers.TryGetValue(key, out list))
            {
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                IBuffWatcher numericWatcher = list[i];
                numericWatcher.Run(unit);
            }
        }
예제 #2
0
        private static void Init(this BuffWatcherComponent self)
        {
            self.allWatchers = new Dictionary <int, List <IBuffWatcher> >();

            List <Type> types = Game.EventSystem.GetTypes(typeof(BuffWatcherAttribute));

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(BuffWatcherAttribute), false);

                for (int i = 0; i < attrs.Length; i++)
                {
                    BuffWatcherAttribute item = (BuffWatcherAttribute)attrs[i];
                    IBuffWatcher         obj  = (IBuffWatcher)Activator.CreateInstance(type);
                    var key = item.IsAdd ? item.BuffType : -item.BuffType;
                    if (!self.allWatchers.ContainsKey(key))
                    {
                        self.allWatchers.Add(key, new List <IBuffWatcher>());
                    }
                    self.allWatchers[key].Add(obj);
                }
            }
        }