Esempio n. 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());
        }
Esempio n. 2
0
        public Task BroadcastEventAsync <T>(T logicEvent, IBroadcastEventRule rule, Grid fromHere, byte chunkDistance = 0, bool onlyPlayers = false) where T : ILogicEvent
        {
            //var temTaskList = BroadcastEventAsyncHere(logicEvent, rule, onlyPlayers);

            if (chunkDistance == 0)
            {
                return(Task.WhenAll(BroadcastEventAsyncHere(logicEvent, rule, onlyPlayers)));
            }

            List <Task> tempTaskList = new List <Task>();

            foreach (var grid in GridHelper.GetNonEqualGridsByDistanceOriginAndDestination(chunkDistance, fromHere, Id))
            {
                if (Map.Chunks.TryGetValue(grid, out var chunk))
                {
                    tempTaskList.Add(chunk.BroadcastEventAsync(logicEvent, rule));
                }
            }

            return(Task.WhenAll(tempTaskList));
        }