コード例 #1
0
ファイル: ActorBehavior.cs プロジェクト: stantoxt/Orleankka
        public void Super(string behavior)
        {
            if (next == null)
            {
                throw new InvalidOperationException($"Super behavior can only be specified while behavior configuration is in progress. " +
                                                    $"Current: {Current}, Offending: {behavior}");
            }

            if (next.Includes(behavior))
            {
                throw new InvalidOperationException("Detected cyclic declaration of super behaviors. " +
                                                    $"'{behavior}' is already within super chain of {next.Name}");
            }

            var existent = current.FindSuper(behavior);

            if (existent != null)
            {
                next.Super(existent);
                return;
            }

            var prev = next;

            next = new CustomBehavior(behavior);

            prev.Super(next);
            var action = RegisteredAction(behavior);

            action(actor);

            next = prev;
        }
コード例 #2
0
 bool Includes(CustomBehavior behavior) =>
 this == behavior || (sub?.Includes(behavior) ?? false);