Пример #1
0
        /// <summary>
        /// Fired, when new buff added or old deleted.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ActiveBuffs_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (ActiveBuff newBuff in e.NewItems)
                {
                    newBuff.OnReset += Buff_OnReset;
                }

                // Case, when we are starting up and all skills are added with AddRange call.
                if (e.NewItems.Count != 1)
                {
                    return;
                }

                if (Client != null) // check for tests.
                {
                    SendAddBuff((ActiveBuff)e.NewItems[0]);
                }
                OnBuffAdded?.Invoke(this, (ActiveBuff)e.NewItems[0]);
            }

            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                if (Client != null)
                {
                    SendRemoveBuff((ActiveBuff)e.OldItems[0]);
                }
                OnBuffRemoved?.Invoke(this, (ActiveBuff)e.OldItems[0]);
            }
        }
Пример #2
0
        public virtual void RemoveBuff(Buff buff)
        {
            var target = buff is ISkillWithOwner ? (buff as ISkillWithOwner).Owner : null;

            BeforeBuffRemoved?.Invoke(buff, target);

            if (target != null)
            {
                Debug.Assert(target.Buffs.Contains(buff), "buff " + buff.ID + " has not been attached to target (" + target.AvatarID + "," + target.IDInMap + ")");
                target.RemoveBuffInternal(buff);
            }
            else
            {
                Debug.Assert(GroundBuffs.Contains(buff), "buff " + buff.ID + " has not been attached to ground)");
                GroundBuffs.Remove(buff);
            }

            buff.OnDetached();

            OnBuffRemoved?.Invoke(buff, target);
            AfterBuffRemoved?.Invoke(buff, target);
        }