Пример #1
0
        public ProxySource Generate(LibraryDescription libraryDescription)
        {
            var toProxyClasses  = new Queue <ClassDescription>();
            var proxyClassNames = new HashSet <string>();
            var namespaceUnits  = new Dictionary <string, NamespaceUnit>();

            var classes = libraryDescription.GetClasses();

            toProxyClasses.EnqueueRange(classes);
            proxyClassNames.AddMany(classes.Select(libraryDescription.GetFullName));

            while (toProxyClasses.Count != 0)
            {
                var classDescription = toProxyClasses.Dequeue();

                if (classDescription.IsNested)
                {
                    continue;
                }

                ProcessClassDescription(classDescription, proxyClassNames, libraryDescription, toProxyClasses, namespaceUnits);
            }

            return(new ProxySource(namespaceUnits.Values));
        }
Пример #2
0
        public override HashSet <Cell> GetTargetedCells(Entity caster, Cell target)
        {
            Line           line = Bresenhams.GetLine(caster.Level, caster.Cell, target);
            HashSet <Cell> ret  = new HashSet <Cell>();

            ret.AddMany(line);
            return(ret);
        }
Пример #3
0
        public void UnmarkTargeted()
        {
            HashSet <Cell> cells = new HashSet <Cell>();

            cells.AddMany(talent.Behaviour.GetTargetedCells(Entity, target));
            foreach (Cell c in cells)
            {
                Locator.Scheduler.UnmarkCell(c.Position);
            }
        }
Пример #4
0
    /// <summary>
    /// Gets the types that the specified type can be enumerated for.
    /// </summary>
    /// <param name="type">The type.</param>
    /// <returns>An array of all the types that the specified type can be enumerated for.</returns>
    public static Type[] GetEnumerableTypes(this Type type)
    {
        Contracts.Requires.That(type != null);

        ISet <Type> results = new HashSet <Type>();

        if (type.IsArray)
        {
            results.Add(type.GetElementType());
        }

        // GetGenericArguments()[0] returns the first generic argument of IEnumerable<>, the type being enumerated
        results.AddMany(type.GetImplementationsOfGenericType(typeof(IEnumerable <>))
                        .Select(value => value.GetGenericArguments()[0]));

        return(results.ToArray());
    }
Пример #5
0
        public HangfireMonitorTests()
        {
            _expectedStats    = _fixture.Create <StatisticsDto>();
            _expectedRetrySet = new HashSet <string>();
            _expectedRetrySet.AddMany(() => _fixture.Create <string>(), new Random().Next(100));

            Mock <IStorageConnection> storageConnection = new Mock <IStorageConnection>();

            storageConnection.Setup(x => x.GetAllItemsFromSet(retryKey)).Returns(_expectedRetrySet);

            Mock <IMonitoringApi> mockMonitoringApi = new Mock <IMonitoringApi>();

            mockMonitoringApi.Setup(x => x.GetStatistics()).Returns(_expectedStats);

            _mockStorage = new Mock <JobStorage>();
            _mockStorage.Setup(x => x.GetConnection()).Returns(storageConnection.Object);
            _mockStorage.Setup(x => x.GetMonitoringApi()).Returns(mockMonitoringApi.Object);

            _hangfireMonitorService = new HangfireMonitorService(_mockStorage.Object);
        }
Пример #6
0
        /// <summary>
        /// Change visibility and reveal new cells.
        /// <param name="level"></param>
        /// </summary>
        /// <returns>A HashSet of all cells affected by the refresh.</returns>
        public static HashSet <Cell> RefreshFOV(Level level, Cell origin,
                                                bool drawChanges)
        {
            // Hide cells at the last refresh position
            if (prev != null && level.Distance(prev, origin) > 1)
            {
                List <Cell> cells = level.GetSquare(prev, FOVRadius);
                foreach (Cell c in cells)
                {
                    if (c.SetVisibility(false, -1))
                    {
                        level.DrawTile(c);
                    }
                }
            }

            HashSet <Cell> changed = new HashSet <Cell>();

            for (int octant = 0; octant < 8; octant++)
            {
                List <Cell> refreshed = ShadowOctant(level,
                                                     origin.Position, octant);

                changed.AddMany(refreshed);
            }

            if (drawChanges)
            {
                level.Draw(changed);
            }

            prev = origin;

            HashSet <Cell> visibles = Floodfill.StackFillIf(
                level, origin, (Cell c) => c.Visible);

            Locator.Player.UpdateVisibles(visibles);

            return(changed);
        }
Пример #7
0
        /*********
        ** Private methods
        *********/
        /// <summary>Parse the input arguments if valid.</summary>
        /// <param name="input">The input arguments.</param>
        /// <param name="playerIds">The parsed player IDs to populate, if any.</param>
        /// <param name="error">The error indicating why the input is invalid, if applicable.</param>
        /// <returns>Returns whether the input is valid.</returns>
        private bool TryParseInput(IInputArguments input, HashSet <long>?playerIds, [NotNullWhen(false)] out string?error)
        {
            foreach (string arg in input.PositionalArgs)
            {
                if (long.TryParse(arg, out long playerId))
                {
                    playerIds?.Add(playerId);
                }
                else if (Enum.TryParse(arg, ignoreCase: true, out PlayerType type))
                {
                    switch (type)
                    {
                    case PlayerType.HostPlayer:
                        playerIds?.Add(this.HostPlayerId);
                        break;

                    case PlayerType.CurrentPlayer:
                        playerIds?.Add(this.LocalPlayerId);
                        break;

                    case PlayerType.AnyPlayer:
                        playerIds?.AddMany(this.Values.Keys);
                        break;

                    default:
                        throw new InvalidOperationException($"Unknown player type {type}.");
                    }
                }
                else
                {
                    error = $"invalid input arguments ({input.TokenString}) for {this.Name} token, expected any combination of '{string.Join("', '", Enum.GetNames(typeof(PlayerType)))}', or player IDs.";
                    return(false);
                }
            }

            error = null;
            return(true);
        }
        public ProxySource Generate(LibraryDescription libraryDescription)
        {
            var toProxyClasses = new Queue<ClassDescription>();
            var proxyClassesNames = new HashSet<string>();
            var namespaceUnits = new Dictionary<string, NamespaceUnit>();

            var classes = libraryDescription.GetClasses().ToList();
            toProxyClasses.EnqueueRange(classes);
            proxyClassesNames.AddMany(classes.Select(libraryDescription.GetFullName));

            while (toProxyClasses.Count != 0)
            {
                var classDescription = toProxyClasses.Dequeue();

                if (classDescription.IsNested)
                    continue;

                var toProxyDependencies = classDescription
                    .DependenciesNames
                    .Where(el => !proxyClassesNames.Contains(el))
                    .Select(libraryDescription.GetClassDescription);

                toProxyClasses.EnqueueRange(toProxyDependencies);
                proxyClassesNames.Add(libraryDescription.GetFullName(classDescription));

                var classProxy = classProxyGenerator.Generate(classDescription);

                var nestedClassProxies = classDescription.NestedClassesDescriptions
                    .Select(el => classProxyGenerator.Generate(el))
                    .ToArray();

                classProxy = classProxy.AddMembers(nestedClassProxies);
                AddClassToNamespaceUnits(libraryDescription, classProxy, classDescription, namespaceUnits);
            }

            return new ProxySource(namespaceUnits.Values);
        }
Пример #9
0
        public TalentCommand(Entity entity, Talent talent, Cell target)
            : base(entity)
        {
            this.talent = talent;
            this.target = target;

            if (!Actor.PlayerControlled(Entity))
            {
                Cost = talent.NPCTime;
                HashSet <Cell> cells = new HashSet <Cell>();
                cells.AddMany(talent.Behaviour.GetTargetedCells(Entity, target));
                foreach (Cell c in cells)
                {
                    if (c.Visible)
                    {
                        Locator.Scheduler.MarkCell(c.Position);
                    }
                }
            }
            else
            {
                Cost = talent.PlayerTime;
            }
        }