예제 #1
0
        protected void DoInteractions(ITopic currentTopic)
        {
            if (currentTopic is null)
            {
                this.OnClose?.Invoke();
                this.CurrentTopics = new ITopic[0];
                this.Listener      = null;
                this.Instigator    = null;
                return;
            }

            ITopic[] next = currentTopic.Interact(this.Instigator, this.Listener);

            next = this.SanitiseTopics(next);

            if (next.Length == 0)
            {
                this.OnClose?.Invoke();
                this.CurrentTopics = next;
                this.Listener      = null;
                this.Instigator    = null;
                return;
            }

            switch (currentTopic.Speaker)
            {
            case Speaker.LISTENER:
                this.LastSaid      = currentTopic;
                this.LastSaidWords = this.LastSaid.Words;
                break;

            case Speaker.INSTIGATOR:
                currentTopic = next[0];
                if (currentTopic.Speaker == Speaker.LISTENER)
                {
                    next               = currentTopic.Interact(this.Instigator, this.Listener);
                    next               = this.SanitiseTopics(next);
                    this.LastSaid      = currentTopic;
                    this.LastSaidWords = this.LastSaid.Words;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.CurrentTopics = next;

            if (next.Length == 0)
            {
                this.OnClose?.Invoke();
                this.CurrentTopics = next;
                this.Listener      = null;
                this.Instigator    = null;
            }
        }