예제 #1
0
        /// <summary>
        /// Try activate the effects
        /// </summary>
        public bool TryActivate()
        {
            if (Data.IsActivated)
            {
                return(false);
            }

            Data.IsActivated = true;
            Data.ExpiresAt   = DateTime.Now.AddSeconds(Duration);
            EffectDao.UpdateEffect(Data);

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Process effect expiry
        /// </summary>
        public void ProcessEffectExpiry(QueuedEvent queuedEvent)
        {
            if (!(Entity is Player))
            {
                return;
            }

            var player = (Player)Entity;

            foreach (var effect in player.EffectManager.Effects.Where(x => x.Value.Data.IsActivated && x.Value.Data.ExpiresAt != null && DateTime.Now > x.Value.Data.ExpiresAt).ToList())
            {
                if (effect.Value.Data.Quantity > 0)
                {
                    effect.Value.Data.Quantity--;
                }

                effect.Value.Data.ExpiresAt = null;

                if (effect.Value.Data.Quantity == 0)
                {
                    player.EffectManager.Effects.Remove(effect.Value.Id);
                    EffectDao.DeleteEffect(effect.Value.Data);
                }
                else
                {
                    EffectDao.UpdateEffect(effect.Value.Data);
                }

                player.Send(new EffectExpiredMessageComposer(effect.Value.Id));

                if (player.RoomEntity.EffectId == effect.Value.Id)
                {
                    player.RoomEntity.UseEffect(0);
                }
            }
        }