Exemple #1
0
        /// <summary>
        /// Remove a Buff from the Monster
        /// </summary>
        /// <param name="buff">The buff to remove</param>
        /// <returns>Whether or not the Buff existed before removal</returns>
        public bool RemoveBuff(Buff buff)
        {
            bool retBool = Buffs.ContainsKey(buff);

            Buffs.Remove(buff);
            return(retBool);
        }
Exemple #2
0
 //todo: use statmods
 public Buff GetBuff(string name)
 {
     lock (BuffsLock)
     {
         if (Buffs.ContainsKey(name))
         {
             return(Buffs[name]);
         }
         return(null);
     }
 }
Exemple #3
0
 public IBuff GetBuffWithName(string name)
 {
     lock (_buffsLock)
     {
         if (Buffs.ContainsKey(name))
         {
             return(Buffs[name]);
         }
         return(null);
     }
 }
Exemple #4
0
 public void AddBuff(Buff b)
 {
     lock (BuffsLock)
     {
         if (!Buffs.ContainsKey(b.Name))
         {
             Buffs.Add(b.Name, b);
         }
         else
         {
             Buffs[b.Name].TimeElapsed = 0; // if buff already exists, just restart its timer
         }
     }
 }
Exemple #5
0
 public void AddBuff(IBuff b)
 {
     lock (BuffsLock)
     {
         if (!Buffs.ContainsKey(b.Name))
         {
             Buffs.Add(b.Name, b);
         }
         else
         {
             Buffs[b.Name].ResetDuration(); // if buff already exists, just restart its timer
         }
     }
 }
Exemple #6
0
        public void AddBuff(IBuff b)
        {
            lock (_buffsLock)
            {
                if (!Buffs.ContainsKey(b.Name))
                {
                    if (HasBuff(b.Name))
                    {
                        var buff = GetBuffsWithName(b.Name)[0];
                        Buffs.Add(b.Name, buff);
                        return;
                    }
                    Buffs.Add(b.Name, b);
                    BuffList.Add(b);
                    if (!b.IsHidden)
                    {
                        _game.PacketNotifier.NotifyNPC_BuffAdd2(b);
                    }
                    b.ActivateBuff();
                }
                else if (b.BuffAddType == BuffAddType.REPLACE_EXISTING)
                {
                    var prevbuff = Buffs[b.Name];

                    prevbuff.DeactivateBuff();
                    RemoveBuff(b.Name);
                    BuffList.Remove(prevbuff);
                    RemoveBuffSlot(b);

                    BuffSlots[prevbuff.Slot] = b;
                    b.SetSlot(prevbuff.Slot);

                    Buffs.Add(b.Name, b);
                    BuffList.Add(b);

                    if (!b.IsHidden)
                    {
                        _game.PacketNotifier.NotifyNPC_BuffReplace(b);
                    }
                    b.ActivateBuff();
                }
                else if (b.BuffAddType == BuffAddType.RENEW_EXISTING)
                {
                    Buffs[b.Name].ResetTimeElapsed();

                    if (!b.IsHidden)
                    {
                        _game.PacketNotifier.NotifyNPC_BuffReplace(Buffs[b.Name]);
                    }
                    RemoveStatModifier(Buffs[b.Name].GetStatsModifier()); // TODO: Replace with a better method that unloads -> reloads all data of a script
                    Buffs[b.Name].ActivateBuff();
                }
                else if (b.BuffAddType == BuffAddType.STACKS_AND_OVERLAPS)
                {
                    if (Buffs[b.Name].StackCount >= Buffs[b.Name].MaxStacks)
                    {
                        var tempbuffs  = GetBuffsWithName(b.Name);
                        var oldestbuff = tempbuffs[0];

                        oldestbuff.DeactivateBuff();
                        RemoveBuff(b.Name);
                        BuffList.Remove(oldestbuff);
                        RemoveBuffSlot(oldestbuff);

                        tempbuffs = GetBuffsWithName(b.Name);

                        BuffSlots[oldestbuff.Slot] = tempbuffs[0];
                        Buffs.Add(oldestbuff.Name, tempbuffs[0]);
                        BuffList.Add(b);

                        if (!b.IsHidden)
                        {
                            if (Buffs[b.Name].BuffType == BuffType.COUNTER)
                            {
                                _game.PacketNotifier.NotifyNPC_BuffUpdateNumCounter(Buffs[b.Name]);
                            }
                            else
                            {
                                _game.PacketNotifier.NotifyNPC_BuffUpdateCount(b, b.Duration, b.TimeElapsed);
                            }
                        }
                        b.ActivateBuff();

                        return;
                    }
                    BuffList.Add(b);

                    Buffs[b.Name].IncrementStackCount();

                    GetBuffsWithName(b.Name).ForEach(buff => buff.SetStacks(Buffs[b.Name].StackCount));

                    if (!b.IsHidden)
                    {
                        if (b.BuffType == BuffType.COUNTER)
                        {
                            _game.PacketNotifier.NotifyNPC_BuffUpdateNumCounter(Buffs[b.Name]);
                        }
                        else
                        {
                            _game.PacketNotifier.NotifyNPC_BuffUpdateCount(b, b.Duration, b.TimeElapsed);
                        }
                    }
                    b.ActivateBuff();
                }
                else if (Buffs[b.Name].BuffAddType == BuffAddType.STACKS_AND_RENEWS)
                {
                    RemoveBuffSlot(b);

                    Buffs[b.Name].ResetTimeElapsed();
                    Buffs[b.Name].IncrementStackCount();

                    if (!b.IsHidden)
                    {
                        if (Buffs[b.Name].BuffType == BuffType.COUNTER)
                        {
                            _game.PacketNotifier.NotifyNPC_BuffUpdateNumCounter(Buffs[b.Name]);
                        }
                        else
                        {
                            _game.PacketNotifier.NotifyNPC_BuffUpdateCount(Buffs[b.Name], Buffs[b.Name].Duration, Buffs[b.Name].TimeElapsed);
                        }
                    }

                    RemoveStatModifier(Buffs[b.Name].GetStatsModifier()); // TODO: Replace with a better method that unloads -> reloads all data of a script
                    Buffs[b.Name].ActivateBuff();
                }
            }
        }
Exemple #7
0
 public bool HasBuff(Buff buff)
 {
     return(Buffs.ContainsKey(buff));
 }
Exemple #8
0
        ///////////
        // Buffs //
        ///////////

        /// <summary>
        /// Attempt to add a Buff to the Monster
        /// </summary>
        /// <param name="buff">The Buff to add</param>
        /// <param name="stacks">How many times to add the Buff (1 to 16)</param>
        /// <returns>Whether or not the Buff was successfully added</returns>
        public bool AddBuff(Buff buff, int stacks)
        {
            if (stacks < 1 || stacks > 16)
            {
                throw new ArgumentOutOfRangeException("Stacks must be within range 1 - 16. Found: " + stacks);
            }

            // Ignore Spirit and Intelligence for now as they're irrelevant
            if (buff == Buff.Spirit || buff == Buff.Intelligence)
            {
                return(false);
            }

            // TODO: If wall exists and an instant KO spell is used, it succeeds

            // There are three types of Buffs: Stacking, Non-stackng, and HighestStack

            // Non-stacking
            Buff[] nonStackingBuffs = new Buff[] { Buff.Intelligence, Buff.Spirit };
            if (nonStackingBuffs.Contains(buff))
            {
                // Add the buff only if it doesn't exist currently
                if (Buffs.ContainsKey(buff))
                {
                    return(false);
                }

                Buffs.Add(buff, 0);
                return(true);
            }

            // Highest-stack
            Buff[] highestStack = new Buff[] { Buff.Haste, Buff.Aura, Buff.Barrier, Buff.Wall };
            if (highestStack.Contains(buff))
            {
                // Set the buff to the highest value between current and stacks
                if (Buffs.TryGetValue(buff, out int value))
                {
                    if (value < stacks)
                    {
                        Buffs[buff] = stacks;
                    }
                }
                else
                {
                    Buffs.Add(buff, stacks);
                }

                // Haste clears the Slow debuff
                if (buff == Buff.Haste)
                {
                    RemoveDebuff(Debuff.Slow);
                    if (Buffs[buff] > 16)
                    {
                        Buffs[buff] = 16;
                    }
                }

                // Enforce max stacks of 8 for Aura and Barrier
                if ((buff == Buff.Aura || buff == Buff.Barrier) && Buffs[buff] > 8)
                {
                    Buffs[buff] = 8;
                }

                // TODO: Determine what bool should be given if stacks is lower than the current value
                return(true);
            }

            // Stacking
            Buff[] stackingBuffs = new Buff[] { Buff.Berserk, Buff.Blink, Buff.Protect, Buff.Shell, Buff.Imbibe };
            if (stackingBuffs.Contains(buff))
            {
                // Add successes to existing buffs, else set it
                if (Buffs.TryGetValue(buff, out int value))
                {
                    Buffs[buff] += stacks;
                }
                else
                {
                    Buffs.Add(buff, stacks);
                }

                Buffs[buff] = (Buffs[buff] % 256); // Overflow
                return(true);
            }

            throw new ArgumentException("Invalid buff supplied: " + buff);
        }