Beispiel #1
0
        public bool AddBuff(ISkill skill, int buffId)
        {
            SkillUtil.LogWarning(string.Format(" [BUFFMANAGER]  [NAME]->{0}  AddBuff-> {1}",
                                               mContext.GetSelfActor().GetTransform().name, buffId));

            IBuff buff      = null;
            bool  canModify = true;
            float life      = 0;

            if (buffMap.ContainsKey(buffId))
            {
                buff      = buffMap[buffId];
                canModify = buff is IOverLayBuff;

                /*Buff
                 * 1.已经拥有 2.有持续时间 3.不可叠加
                 * -》直接刷新Buff的持续时间(Life)
                 */
                if (!canModify)
                {
                    RefreshTimerLife(buff);
                }
            }
            else
            {
                var  data      = SkillUtil.GetSkillBuffData(buffId);
                bool isOverLay = data.Attributes.Contains((int)EBuffAttributes.CanAdd);
                buff = isOverLay ? new OverlayBuff() : new Buff();
                buff.Create(skill, mContext.GetSelfActor(), buffId);
                buffMap.Add(buffId, buff);
            }

            if (canModify) //只有新加的和可叠加的Buff才能触发Modify
            {
                BuffModify(buffId);

                //1.先判定这个Buff 是不是一个循环定时器
                if (!TryAddLoopTimer(buffId))
                {
                    life = buff.GetDuringTime();
                    if (life > 0)
                    {
                        /* 可以执行到此处满足的条件:
                         * 1.不是循环定时器 2.有效的Buff生命周期life 3.可以叠加效果的老BUFF或者刚刚添加的新BUFF
                         * =》生成一个新的计时器
                         */
                        CreateNormalTimer(life, buffId);
                    }
                }
            }

            OnBuffEventDispatch(EBuffActionType.AddBuff);
            return(true);
        }
        public void RegisterService <T>() where T : class, IService
        {
            Type type = typeof(T);

            if (map.ContainsKey(type))
            {
                return;
            }

            var service = Activator.CreateInstance <T>();

            map.Add(type, service);
        }
Beispiel #3
0
        public T RegisterService <T>() where T : class, IService
        {
            Type type = typeof(T);

            if (_map.ContainsKey(type))
            {
                return(_map[type] as T);
            }

            var service = Activator.CreateInstance <T>();

            _map.Add(type, service);
            return(service);
        }
Beispiel #4
0
        /// <summary>
        ///  尝试移除Buff 1.移除Buff效果 2.移除定时器(如果Buff有) 3.从Buff Manager移除出字典
        /// A.普通Buff 直接走完1,2,3
        /// B.可以叠加的Buff 走完1,2 每次层数-1,如果层数==0,走3
        /// </summary>
        /// <param name="skill">拥有这个Buff的Skill载体</param>
        /// <param name="buffId">BuffId</param>
        /// <param name="forceClean">彻底清除</param>
        /// <returns></returns>
        public bool TryRemoveBuff(int buffId, bool forceClean)
        {
            SkillUtil.LogWarning(string.Format(" [BUFFMANAGER] [Target]->{0}  TryRemoveBuff -> {1}",
                                               this.mContext.GetSelfActor().GetTransform().name, buffId));
            if (buffMap.ContainsKey(buffId))
            {
                var buff = buffMap[buffId];
                if (buff.GetDuringTime() > 0)
                {
                    this.RemoveTimer(buffId, forceClean);
                }


                bool isOverLayBuff = buff is IOverLayBuff;
                if (isOverLayBuff) //可以叠加Buff
                {
                    IOverLayBuff overlayBuff = buff as IOverLayBuff;
                    int          time        = forceClean ? overlayBuff.GetOverlayTime() : 1;
                    for (int i = 0; i < time; i++)
                    {
                        this.EndBuffModify(buffId);
                    }

                    var result = overlayBuff.TryRemove();
                    if (result || forceClean)
                    {
                        this.RemoveBuff(buff);
                    }
                }
                else //普通Buff
                {
                    this.EndBuffModify(buffId);
                    this.RemoveBuff(buff);
                }
            }

            return(true);
        }
Beispiel #5
0
 public bool HasModule(int id)
 {
     return(m_mapModule.ContainsKey(id));
 }