Beispiel #1
0
 /// <summary>
 /// Check if a Buff exists on the monster. Returns stack value of the buff, 0 if not found.
 /// </summary>
 /// <param name="buff">The Buff to check for</param>
 /// <returns>Stack value of the buff, 0 if not found.</returns>
 public int GetBuffStacks(Buff buff)
 {
     if (Buffs.TryGetValue(buff, out int value))
     {
         return(value % 256); // Overflow
     }
     return(0);
 }
Beispiel #2
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);
        }