public static ServerResponse AddNodeToStory(string characterName, string storyLineId, string introductoryText, string[] playerResponses, string[] characterResponses, Event[] eventsToPublishOnReaching = null)
    {
        Command        command   = new AddNodeToStory(characterName, storyLineId, introductoryText, playerResponses, characterResponses, eventsToPublishOnReaching);
        Aggregate      character = AggregateRepository.GetOrCreate(typeof(CharacterAggregate), characterName);
        bool           success   = CommandHandler.HandleCommand(character, characterName, command);
        ServerResponse response  = new ServerResponse(characterName, ModelNameGetter.GetModelName(character.GetType()), !success);

        return(response);
    }
Example #2
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
        });
    }