Пример #1
0
 public async Task HandleAsync(IEventContext <IEvent> context)
 {
     if (_handlers.TryGetValue(context.GetType(), out var handler))
     {
         await handler(context);
     }
 }
Пример #2
0
        /// <summary>
        /// Executes the event logic.
        /// </summary>
        /// <param name="context">The execution context.</param>
        public override void Execute(IEventContext context)
        {
            context.ThrowIfNull(nameof(context));

            if (!typeof(IOperationContext).IsAssignableFrom(context.GetType()))
            {
                throw new ArgumentException($"{nameof(context)} must be an {nameof(IOperationContext)}.");
            }

            var operationContext = context as IOperationContext;

            // Reset the operation's Repeat property, to avoid implementations running perpetually.
            this.RepeatAfter = TimeSpan.MinValue;

            this.Execute(operationContext);

            // Add any associated exhaustion from this operation, the the requestor, if there was one.
            if (this.ExhaustionInfo.Any() && this.GetRequestor(operationContext.CreatureFinder) is ICreature requestor)
            {
                foreach (var(exhaustionType, duration) in this.ExhaustionInfo)
                {
                    var exhaustionCondition = new ExhaustionCondition(exhaustionType, context.CurrentTime + duration);

                    operationContext.GameApi.AddOrAggregateCondition(requestor, exhaustionCondition, duration);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Sends the notification to the players intented.
        /// </summary>
        /// <param name="context">The context for this notification.</param>
        public override void Execute(IEventContext context)
        {
            context.ThrowIfNull(nameof(context));

            if (!typeof(INotificationContext).IsAssignableFrom(context.GetType()) || !(context is INotificationContext notificationContext))
            {
                throw new ArgumentException($"{nameof(context)} must be an {nameof(INotificationContext)}.");
            }

            this.Send(notificationContext);
        }
Пример #4
0
        /// <summary>
        /// Executes the event logic.
        /// </summary>
        /// <param name="context">The execution context.</param>
        public override void Execute(IEventContext context)
        {
            context.ThrowIfNull(nameof(context));

            if (!typeof(IConditionContext).IsAssignableFrom(context.GetType()) || !(context is IConditionContext conditionContext))
            {
                throw new ArgumentException($"{nameof(context)} must be an {nameof(IConditionContext)}.");
            }

            // Reset the condition's Repeat property, to avoid implementations running perpetually.
            // It's the responsability of the implementation to extend or repeat duration by modifiying
            // this property each time the condition executes.
            this.RepeatAfter = TimeSpan.MinValue;

            // And execute as condition.
            this.Execute(conditionContext);
        }
Пример #5
0
        /// <summary>
        /// Executes the event logic.
        /// </summary>
        /// <param name="context">The execution context.</param>
        public override void Execute(IEventContext context)
        {
            context.ThrowIfNull(nameof(context));

            if (!typeof(IOperationContext).IsAssignableFrom(context.GetType()))
            {
                throw new ArgumentException($"{nameof(context)} must be an {nameof(IOperationContext)}.");
            }

            var operationContext = context as IOperationContext;

            // Reset the operation's Repeat property, to avoid implementations running perpetually.
            this.RepeatAfter = TimeSpan.MinValue;

            this.Execute(operationContext);

            // Add any exhaustion for the requestor of the operation, if any.
            if (this.GetRequestor(operationContext.CreatureFinder) is ICreatureWithExhaustion requestor)
            {
                requestor.AddExhaustion(this.ExhaustionType, operationContext.Scheduler.CurrentTime, this.ExhaustionCost);
            }
        }