Example #1
0
    //todo rename to add story node
    private Event[] AddNodeToStory(AddNodeToStory command)
    {
        if (this.id == Aggregate.NullId)
        {
            throw new ValidationException("id", "Character not found");
        }
        if (command.playerResponses.Length != command.characterResponses.Length)
        {
            throw new ValidationException("responses", "Each possible player response must match to one charaterResponse. Did you forget to define one in the text file?");
        }
        if (command.introductoryText.Length == 0)
        {
            throw new ValidationException("introductoryText", "introductory text can't be empty.");
        }
        if (!ReferenceEquals(this.rootNode, null) && ReferenceEquals(rootNode.Find(command.introductoryText), null))
        {
            throw new ValidationException("introductoryText", "introductory text is neither the root nor an existing line in this story.");
        }

        for (int i = 0; i < command.playerResponses.Length; i++)
        {
            string playerResponse    = command.playerResponses [i];
            string characterResponse = command.characterResponses [i];
            if (playerResponse.Length == 0 || characterResponse.Length == 0)
            {
                throw new ValidationException("response", $"Response can't be empty; check the values for response {i+1}; introductory text '{command.introductoryText}'");
            }
        }


        string[] playerResponses = ConvertPlayerResponsesToRegexes(command.playerResponses);


        return(new Event[] {
            new NodeAddedToStory(command.characterName, command.storylineId,
                                 command.introductoryText, playerResponses, command.characterResponses, command.eventsToPublishOnReaching)//stub for now
        });
    }