public static ServerResponse AdvanceStory(string characterName, string playerId, string input) { Command command = new AdvanceStory(characterName, playerId, input); 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); }
private Event[] AdvanceStory(AdvanceStory command) { if (this.id == Aggregate.NullId) { throw new ValidationException("id", "Character not found"); } if (this.currentNode == null) { throw new ValidationException("", "No dialogue initiated."); } string formattedInput = FormatUserInput(command.input); if (formattedInput.Length == 0) { throw new ValidationException("input", "Input can't be empty."); } if (this.currentNode.IsLeaf()) { //todo it makes sense for storylines to have id, not sure about story nodes within stryline (unless each node has the id of the story) stories should be queued. StoryCompleted storylineCompleted = new StoryCompleted(command.characterName, "TEMP-REPLACE WITH STORYLINE ID", command.playerId); if (!this.completedStoryIds.Contains(storylineCompleted.storylineId)) { return(new Event[] { storylineCompleted, new StoryPrizeAwarded(command.playerId, command.characterName, currentNode.prizeId) }); } return(new Event[] { storylineCompleted }); } List <StoryNode> children = this.currentNode.GetChildren(formattedInput); if (children == null) { throw new ValidationException("input", $"No response for {command.input}"); } int random = RandomNumberGenerator.Instance.Range(0, children.Count); StoryNode newNode = children [random]; Event[] result = new Event[1 + currentNode.eventsToPublishOnReaching.Length]; result [0] = new StoryAdvanced( command.characterName, command.playerId, command.input, newNode ); for (int i = 1; i < result.Length; i++) { result [i] = currentNode.eventsToPublishOnReaching [i - 1]; } return(result); }