public void Execute(IntentModel intentModel) { var value = base.GetSlotValue(intentModel.Request, SlotType); if (!string.IsNullOrEmpty(value)) { if (value == Verbosity.AreaDescription.GetDescription()) { intentModel.Player.Verbosity = intentModel.Player.Verbosity.HasFlag(Verbosity.AreaDescription) ? intentModel.Player.Verbosity -= Verbosity.AreaDescription : intentModel.Player.Verbosity |= Verbosity.AreaDescription; } if (value == Verbosity.Direction.GetDescription()) { intentModel.Player.Verbosity = intentModel.Player.Verbosity.HasFlag(Verbosity.Direction) ? intentModel.Player.Verbosity -= Verbosity.Direction : intentModel.Player.Verbosity |= Verbosity.Direction; } if (value == Verbosity.CellItems.GetDescription()) { intentModel.Player.Verbosity = intentModel.Player.Verbosity.HasFlag(Verbosity.CellItems) ? intentModel.Player.Verbosity -= Verbosity.CellItems : intentModel.Player.Verbosity |= Verbosity.CellItems; } } intentModel.Player = base.PlayerRepository.UpdatePlayer(intentModel.Player); }
public void Execute(IntentModel intentModel) { var value = base.GetSlotValue(intentModel.Request, SlotType); var item = base.MapRepository.GetItem(value); var inventory = intentModel.Player.Inventories.FirstOrDefault(o => o.ItemRefId == item.ItemId); var output = new StringBuilder(); if (inventory != null) { base.PlayerRepository.DeleteInventoryItem(inventory.InventoryId); var cellItem = Mapper.Map <CellItemDTO>(inventory); cellItem.CellRefId = intentModel.Cell.CellId; base.MapRepository.AddOrUpdateCellItem(cellItem); intentModel.Player = this.PlayerRepository .GetPlayer(intentModel.Player.PlayerId); intentModel.Cell = base.MapRepository .GetCell(intentModel.Player.MapRefId, intentModel.Player.LocationX, intentModel.Player.LocationY); output.Append(string.Format(StaticText.DropIntent_DroppedItem, value)); } else { output.Append(base.IsSlotValueValid(value) ? string.Format(StaticText.DropIntent_DontHaveItem, value) : StaticText.DropIntent_DropWhatItem); } intentModel.Output.Append(output); }
protected static StringBuilder BuildAreaDescription(IntentModel intentModel) { var output = new StringBuilder(); output.Append(!string.IsNullOrEmpty(intentModel.Cell.Description) ? intentModel.Cell.Description : intentModel.Map.Description); output.Append(" . . . "); return(output); }
public void Execute(IntentModel intentModel) { var value = base.GetSlotValue(intentModel.Request, SlotType) ?? string.Empty; var enumValue = Directions.None; Enum.TryParse(value.UpcaseFirst(), out enumValue); intentModel.Player = base.PlayerRepository.UpdatePlayer(intentModel.Player); intentModel.Cell = base.MapRepository.GetCell(intentModel.Player.MapRefId, intentModel.Player.LocationX, intentModel.Player.LocationY); intentModel.Output.Append(BuildMovementOutput(value, intentModel.Cell, false)); }
private void BuildOutput(IntentModel intentModel) { if (intentModel.Player.Verbosity.HasFlag(Verbosity.AreaDescription)) { intentModel.Output.Append(BuildAreaDescription(intentModel)); } if (intentModel.Player.Verbosity.HasFlag(Verbosity.Direction)) { intentModel.Output.Append(BuildDirectionOutput(intentModel)); } if (intentModel.Player.Verbosity.HasFlag(Verbosity.CellItems)) { intentModel.Output.Append(BuildCellItemsOutput(intentModel)); } }
public void Execute(IntentModel intentModel) { var value = base.GetSlotValue(intentModel.Request, SlotType); var valid = base.IsSlotValueValid(value); var output = new StringBuilder(); if (valid) { var item = base.MapRepository.GetItem(value); var inventoryName = item.Name.ToLower() ?? string.Empty; switch (inventoryName) { case "key": { output.Append("There is nothing to unlock here."); break; } case "rock": { output.Append("How do you use a rock?"); break; } case "knife": { output.Append("You're now holding the knife."); break; } default: { output.Append($"You don't have a {value}."); break; } } } else { output.Append(StaticText.UseIntent_UseWhatItem); } intentModel.Output.Append(output); }
protected static StringBuilder BuildDirectionOutput(IntentModel intentModel) { var output = new StringBuilder(); var directions = new List <string>(); directions.Add(intentModel.Cell.Directions.HasFlag(Directions.North) ? Directions.North.GetDescription() : string.Empty); directions.Add(intentModel.Cell.Directions.HasFlag(Directions.South) ? Directions.South.GetDescription() : string.Empty); directions.Add(intentModel.Cell.Directions.HasFlag(Directions.East) ? Directions.East.GetDescription() : string.Empty); directions.Add(intentModel.Cell.Directions.HasFlag(Directions.West) ? Directions.West.GetDescription() : string.Empty); directions.RemoveAll(o => o == string.Empty); for (var i = 0; i < directions.Count; i++) { var isLast = (i + 1) == directions.Count; var isTwoOrMore = directions.Count > 1; var isOnlyTwo = directions.Count == 2; if (i == 0) { output.Append($"The {intentModel.Cell.PathDescription} leads {directions[i]}"); } else { if (!isLast && isTwoOrMore) { output.Append($", {directions[i]}"); } } if (isLast && isTwoOrMore) { if (!isOnlyTwo) { output.Append($","); } output.Append($" and {directions[i]}"); } } output.Append(". "); output.Append(" . . "); return(output); }
private IntentModel BuildIntentModel(AlexaRequestModel alexaRequestModel, AlexaResponseModel alexaResponseModel) { var playerId = base.CustomPrincipal.PlayerId; var playerDto = base.PlayerRepository.GetPlayer(playerId); var mapDto = base.MapRepository.GetMap(playerDto.MapRefId); var cellDto = base.MapRepository.GetCell(playerDto.MapRefId, playerDto.LocationX, playerDto.LocationY); var intentModel = new IntentModel() { Request = alexaRequestModel, Response = alexaResponseModel, Player = playerDto, Map = mapDto, Cell = cellDto }; return(intentModel); }
public void Execute(IntentModel intentModel) { var value = base.GetSlotValue(intentModel.Request, SlotType) ?? string.Empty; var enumValue = Directions.None; Enum.TryParse(value.UpcaseFirst(), out enumValue); var hasMoved = EnteredPortal(enumValue, intentModel.Player, intentModel.Cell); if (hasMoved.HasValue && hasMoved.Value) { intentModel.Map = base.MapRepository.GetMap(intentModel.Player.MapRefId); } if (!hasMoved.HasValue || !hasMoved.Value) { hasMoved = MoveDirection(enumValue, intentModel.Player, intentModel.Cell); } intentModel.Player = base.PlayerRepository.UpdatePlayer(intentModel.Player); intentModel.Cell = base.MapRepository.GetCell(intentModel.Player.MapRefId, intentModel.Player.LocationX, intentModel.Player.LocationY); intentModel.Output.Append(BuildMovementOutput(value, intentModel.Cell, hasMoved)); }
protected StringBuilder BuildCellItemsOutput(IntentModel intentModel) { var output = new StringBuilder(); if (!intentModel.Cell.CellItems.Any()) { return(output); } if (intentModel.Cell.CellItems.Count == 1) { var item = this.MapRepository.GetItem(intentModel.Cell.CellItems[0].ItemRefId); output.Append($"You see a {item.Name} on the ground. "); } else { output.Append($"You see several items on the ground. "); } output.Append(" . . . "); return(output); }
private static void FinalizeOutput(IntentModel intentModel) { intentModel.Response.Response.Card.Content = intentModel.Output.ToString(); intentModel.Response.Response.OutputSpeech.Text = intentModel.Output.ToString(); }