Пример #1
0
        private List <Task> BroadcastEventAsyncHere(ILogicEvent logicEvent, IBroadcastEventRule rule, bool onlyPlayers)
        {
            if (onlyPlayers)
            {
                return(PlayerEntities.Select(s =>
                                             Task.Run(() =>
                                                      rule == null || rule.Match(s.Value)
                            ? s.Value.EmitEventAsync(logicEvent)
                            : Task.CompletedTask)).ToList());
            }

            return(SubstantialEntities.Select(s =>
                                              Task.Run(() =>
                                                       rule == null || rule.Match(s.Value)
                        ? s.Value.EmitEventAsync(logicEvent)
                        : Task.CompletedTask)).ToList());
        }
        protected override Task Handle(EntityTransferBetweenChunks logicEvent, CancellationToken cancellation)
        {
            ILogicEvent firstEvent  = null;
            ILogicEvent secondEvent = null;

            switch (logicEvent.Sender)
            {
            case IPlayerEntity playerEntity:
                firstEvent = new PlayerEntityDeclaration
                {
                    RealSender = playerEntity
                };

                secondEvent = new PlayerEntityRevocation
                {
                    RealSender = playerEntity
                };
                break;

            case ISubstantialEntity substantialEntity:
                firstEvent = new SubstantialEntityDeclaration
                {
                    RealSender = substantialEntity
                };

                secondEvent = new SubstantialEntityRevocation
                {
                    RealSender = substantialEntity
                };
                break;

            default:
                return(Task.CompletedTask);
            }

            logicEvent.ToHere.BroadcastEventAsync(firstEvent, logicEvent.FromHere.Id, GridHelper.MaxChunkDistanceView);

            logicEvent.FromHere.BroadcastEventAsync(secondEvent, logicEvent.ToHere.Id, GridHelper.MaxChunkDistanceView);

            return(Task.CompletedTask);
        }
Пример #3
0
 public EventSet(eEventType t, ILogicEvent evt)
 {
     Type = t; Event = evt;
 }
Пример #4
0
 public Task Handle(ILogicEvent logicEvent, CancellationToken cancellation)
 {
     return(logicEvent is TLogicEvent e?Handle(e, cancellation) : Task.CompletedTask);
 }