Exemple #1
0
        /// <summary>
        /// Returns true if spell is currently cooling down.
        /// Removes expired cooldowns of that spell.
        /// </summary>
        public override bool IsReady(Spell spell)
        {
            // check for individual cooldown
            ISpellIdCooldown idCooldown = null;

            if (spell.CooldownTime > 0)
            {
                for (var i = 0; i < m_idCooldowns.Count; i++)
                {
                    idCooldown = m_idCooldowns[i];
                    if (idCooldown.SpellId == spell.Id)
                    {
                        if (idCooldown.Until > DateTime.Now)
                        {
                            return(false);
                        }
                        m_idCooldowns.RemoveAt(i);
                        break;
                    }
                }
            }

            /*// enqueue task to delete persistent cooldowns
             * if (idCooldown is PersistentSpellIdCooldown )//|| catCooldown is PersistentSpellCategoryCooldown)
             * {
             *      var removedId = idCooldown as PersistentSpellIdCooldown;
             *      //var removedCat = catCooldown as PersistentSpellCategoryCooldown;
             *      RealmServer.IOQueue.AddMessage(new Message(() =>
             *      {
             *              if (removedId != null)
             *              {
             *                      removedId.Delete();
             *              }
             *              /*if (removedCat != null)
             *              {
             *                      removedCat.Delete();
             *              }#1#
             *      }));
             * }*/
            return(true);
        }
        /// <summary>
        /// Returns true if spell is currently cooling down.
        /// Removes expired cooldowns of that spell.
        /// </summary>
        public override bool IsReady(Spell spell)
        {
            if (spell.CooldownTime > 0)
            {
                for (int index = 0; index < this.m_idCooldowns.Count; ++index)
                {
                    ISpellIdCooldown idCooldown = this.m_idCooldowns[index];
                    if ((int)idCooldown.SpellId == (int)spell.Id)
                    {
                        if (idCooldown.Until > DateTime.Now)
                        {
                            return(false);
                        }
                        this.m_idCooldowns.RemoveAt(index);
                        break;
                    }
                }
            }

            return(true);
        }
        /// <summary>Clears the cooldown for this spell</summary>
        public override void ClearCooldown(Spell cooldownSpell, bool alsoCategory = true)
        {
            Character ownerChar = this.OwnerChar;

            Asda2SpellHandler.SendClearCoolDown(ownerChar, cooldownSpell.SpellId);
            if (alsoCategory && cooldownSpell.Category != 0U)
            {
                foreach (Spell spell in this.m_byId.Values)
                {
                    if ((int)spell.Category == (int)cooldownSpell.Category)
                    {
                        Asda2SpellHandler.SendClearCoolDown(ownerChar, spell.SpellId);
                    }
                }
            }

            ISpellIdCooldown idCooldown =
                this.m_idCooldowns.RemoveFirst <ISpellIdCooldown>(
                    (Func <ISpellIdCooldown, bool>)(cd => (int)cd.SpellId == (int)cooldownSpell.Id));
            ISpellCategoryCooldown catCooldown = this.m_categoryCooldowns.RemoveFirst <ISpellCategoryCooldown>(
                (Func <ISpellCategoryCooldown, bool>)(cd => (int)cd.CategoryId == (int)cooldownSpell.Category));

            if (!(idCooldown is ActiveRecordBase) && !(catCooldown is ActiveRecordBase))
            {
                return;
            }
            ServerApp <WCell.RealmServer.RealmServer> .IOQueue.AddMessage((IMessage) new Message((Action)(() =>
            {
                if (idCooldown is ActiveRecordBase)
                {
                    ((ActiveRecordBase)idCooldown).Delete();
                }
                if (!(catCooldown is ActiveRecordBase))
                {
                    return;
                }
                ((ActiveRecordBase)catCooldown).Delete();
            })));
        }
Exemple #4
0
        /// <summary>
        /// Clears the cooldown for this spell
        /// </summary>
        public override void ClearCooldown(Spell cooldownSpell, bool alsoCategory = true)
        {
            var ownerChar = OwnerChar;

            // send cooldown update to client
            SpellHandler.SendClearCoolDown(ownerChar, cooldownSpell.SpellId);
            if (alsoCategory && cooldownSpell.Category != 0)
            {
                foreach (var spell in m_byId.Values)
                {
                    if (spell.Category == cooldownSpell.Category)
                    {
                        SpellHandler.SendClearCoolDown(ownerChar, spell.SpellId);
                    }
                }
            }

            // remove and delete
            ISpellIdCooldown       idCooldown  = m_idCooldowns.RemoveFirst(cd => cd.SpellId == cooldownSpell.Id);
            ISpellCategoryCooldown catCooldown = m_categoryCooldowns.RemoveFirst(cd => cd.CategoryId == cooldownSpell.Category);

            // enqueue task
            if (idCooldown is ActiveRecordBase || catCooldown is ActiveRecordBase)
            {
                RealmServer.IOQueue.AddMessage(new Message(() =>
                {
                    if (idCooldown is ActiveRecordBase)
                    {
                        ((ActiveRecordBase)idCooldown).Delete();
                    }
                    if (catCooldown is ActiveRecordBase)
                    {
                        ((ActiveRecordBase)catCooldown).Delete();
                    }
                }
                                                           ));
            }
        }