Exemple #1
0
    //同id的buff不能叠加,只能覆盖
    public bool AddBuff(Creature target, BuffId id)
    {
        BaseBuff newBuff = null;

        switch (id)
        {
        case BuffId.Invincible:
            newBuff = new InvincibleBuff();
            break;
        }
        if (newBuff != null)
        {
            if (buffDict.ContainsKey(id))
            {   //移除原来的buff
                if (buffDict[id] != null)
                {
                    buffDict[id].Stop();
                }
                buffDict[id] = newBuff;
            }
            else
            {
                buffDict.Add(id, newBuff);
            }

            newBuff.Start(target);
        }


        return(true);
    }
Exemple #2
0
 /// <summary>
 /// Returns buff with given id, or null if it didn't
 /// exist.
 /// </summary>
 /// <param name="buffId"></param>
 /// <returns></returns>
 public Buff Get(BuffId buffId)
 {
     lock (_buffs)
     {
         _buffs.TryGetValue(buffId, out var result);
         return(result);
     }
 }
Exemple #3
0
    public void RemoveBuff(IBuff.BuffType type, int insId)
    {
        BuffId id = new BuffId();

        id.mType   = type;
        id.mTypeId = insId;
        mDeathBuffList.Add(id);
    }
Exemple #4
0
        /// <summary>
        /// Removes buff with given id, returns false if it
        /// didn't exist. Updates the client on success.
        /// </summary>
        /// <param name="buffId"></param>
        /// <returns></returns>
        public bool Remove(BuffId buffId)
        {
            if (!this.TryGet(buffId, out var buff))
            {
                return(false);
            }

            return(this.Remove(buff));
        }
Exemple #5
0
        /// <summary>
        /// Returns the buff handler for the given buff. Returns null if
        /// no handler was found.
        /// </summary>
        /// <param name="buffId"></param>
        /// <returns></returns>
        public IBuffHandler GetHandler(BuffId buffId)
        {
            if (_buffHandlers.TryGetValue(buffId, out var handler))
            {
                return(handler);
            }

            return(null);
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Buff"/> structure with the specified buff <paramref name="id"/>
        /// and <paramref name="ticks"/>.
        /// </summary>
        /// <param name="id">The buff ID.</param>
        /// <param name="ticks">The buff duration, in ticks.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="ticks"/> is negative.</exception>
        public Buff(BuffId id, int ticks)
        {
            if (ticks < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(ticks), "Ticks is negative");
            }

            Id    = id;
            Ticks = ticks;
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Buff"/> structure with the specified buff <paramref name="id"/>
        /// and <paramref name="duration"/>.
        /// </summary>
        /// <param name="id">The buff ID.</param>
        /// <param name="duration">The buff duration.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="duration"/> is negative.</exception>
        public Buff(BuffId id, TimeSpan duration)
        {
            if (duration < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(duration), "Duration is negative");
            }

            Id    = id;
            Ticks = (int)(duration.TotalSeconds * 60.0);
        }
Exemple #8
0
        /// <summary>
        /// Starts the buff with the given id. If the buff is already active,
        /// it gets overbuffed. Returns the created or modified buff.
        /// </summary>
        /// <param name="buffId"></param>
        /// <param name="caster">The entity that casted the buff.</param>
        /// <param name="duration">Custom duration of the buff.</param>
        /// <returns></returns>
        public Buff Start(BuffId buffId, ICombatEntity caster, TimeSpan duration)
        {
            if (!this.TryGet(buffId, out var buff))
            {
                buff = new Buff(caster, this.Entity, buffId, duration);
                this.Add(buff);
            }
            else
            {
                this.Overbuff(buff);
            }

            return(buff);
        }
Exemple #9
0
        static ABuff GetBuff(TargetBuffs target, BuffId buffId)
        {
            if (!BuffsMap.ContainsKey(target))
            {
                BuffsMap.Add(target, new List <ABuff>());
            }

            var buff = BuffsMap[target].Find(b => b.Id == buffId);

            if (buff == null)
            {
                buff = Buffs[buffId].Clone();
                BuffsMap[target].Add(buff);
            }
            return(buff);
        }
Exemple #10
0
 public bool RemoveBuff(BuffId id)
 {
     if (buffDict.ContainsKey(id))
     {
         if (buffDict[id] != null)
         {
             buffDict[id].Stop();
         }
         buffDict.Remove(id);
     }
     else
     {   //not exist
         return(false);
     }
     return(true);
 }
Exemple #11
0
 static public void ParseBuffString(ref List <BuffId> outList, string info, IBuff.BuffType type)
 {
     string[] sArray = info.Split(';');
     for (int i = 0; i < sArray.Length; ++i)
     {
         if (sArray[i] != string.Empty)
         {
             string[] sArrayTrigger = sArray[i].Split(',');
             BuffId   buff          = new BuffId();
             buff.mType       = type;
             buff.mBuffAttach = (IBuff.BuffAttach) int.Parse(sArrayTrigger[0]);
             buff.mTrigger    = (IBuff.BuffStage) int.Parse(sArrayTrigger[1]);
             buff.mTypeId     = int.Parse(sArrayTrigger[2]);
             outList.Add(buff);
         }
     }
 }
Exemple #12
0
 public override string ToString()
 {
     return(string.Format($"{BuffId.ToString()}: Exp tick: {ExpirationTick} Attr: {OnApplyStatusEffect.ToString()} Value: {OnApplyStatusEffectValue}| {OnTickStatusEffect.ToString()}:{ OnTickStatusEffectValue}"));
 }
Exemple #13
0
 /// <summary>
 /// Returns true if the buff exists.
 /// </summary>
 /// <param name="buffId"></param>
 /// <returns></returns>
 public bool Has(BuffId buffId)
 {
     lock (_buffs)
         return(_buffs.ContainsKey(buffId));
 }
Exemple #14
0
 public static void PlayBuff(TargetBuffs target, BuffId buffId)
 => GetBuff(target, buffId).Play(target);
Exemple #15
0
 public bool CheckByIid(BuffId bid)
 {
     return(bid._iid == _iid);
 }
Exemple #16
0
 public static void SetBuff(TargetBuffs target, BuffId buffId, bool isOn)
 => GetBuff(target, buffId).Set(target, isOn);
Exemple #17
0
 /// <summary>
 /// Returns buff with given id via out, returns false if the
 /// buff wasn't found.
 /// </summary>
 /// <param name="buffId"></param>
 /// <param name="buff"></param>
 /// <returns></returns>
 public bool TryGet(BuffId buffId, out Buff buff)
 {
     buff = this.Get(buffId);
     return(buff != null);
 }
Exemple #18
0
 /// <summary>
 /// Returns a value indicating whether the buff ID is a debuff.
 /// </summary>
 /// <param name="id">The buff ID.</param>
 /// <returns><see langword="true"/> if the buff ID is a debuff; otherwise, <see langword="false"/>.</returns>
 public static bool IsDebuff(this BuffId id) => _debuffs.Contains(id);
Exemple #19
0
 /// <summary>
 /// Starts the buff with the given id. If the buff is already active,
 /// it gets overbuffed. Returns the created or modified buff.
 /// </summary>
 /// <param name="buffId"></param>
 /// <param name="duration">Custom duration of the buff.</param>
 /// <returns></returns>
 public Buff Start(BuffId buffId, TimeSpan duration)
 => this.Start(buffId, this.Entity, duration);
Exemple #20
0
 /// <summary>
 /// Starts the buff with the given id, returns the created buff.
 /// If the buff was already active, it gets overbuffed.
 /// </summary>
 /// <remarks>
 /// Uses the duration from the buff's data by default.
 /// </remarks>
 /// <param name="buffId"></param>
 /// <returns></returns>
 public Buff Start(BuffId buffId)
 => this.Start(buffId, TimeSpan.MinValue);