QuestRequirement.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "QuestRequirement.h"
  2. #include "Quest.h"
  3. QuestRequirement::QuestRequirement(
  4. Framework::Text id, Framework::Text description)
  5. : ReferenceCounter(),
  6. id(id),
  7. description(description)
  8. {}
  9. const Framework::Text& QuestRequirement::getRequirementId() const
  10. {
  11. return id;
  12. }
  13. const Framework::Text& QuestRequirement::getDescription() const
  14. {
  15. return description;
  16. }
  17. QuestRequirementOpenDialog::QuestRequirementOpenDialog(
  18. Framework::Text id, Framework::Text description, Framework::Text dialogId)
  19. : QuestRequirement(id, description),
  20. dialogId(dialogId)
  21. {}
  22. void QuestRequirementOpenDialog::processEvent(
  23. QuestEvent* zEvent, QuestRequirementStorage* zStorage)
  24. {
  25. QuestEventOpenDialog* event = dynamic_cast<QuestEventOpenDialog*>(zEvent);
  26. if (event)
  27. {
  28. if (event->getDialogId() == dialogId)
  29. {
  30. zStorage->setFullfilled(true);
  31. }
  32. }
  33. }
  34. Framework::Text QuestRequirementOpenDialog::getRequirementUIML(
  35. QuestRequirementStorage* zStorage)
  36. {
  37. Framework::Text result = "<questRequirement id=\"";
  38. result.append() << id << "\" fullfilled=\"" << zStorage->isFullfilled()
  39. << "\"><text>" << description
  40. << "</text></questRequirement>";
  41. return result;
  42. }
  43. QuestRequirementOpenDialogType::QuestRequirementOpenDialogType()
  44. : SubTypeFactory()
  45. {}
  46. QuestRequirementOpenDialog* QuestRequirementOpenDialogType::fromJson(
  47. Framework::JSON::JSONObject* zJson) const
  48. {
  49. return new QuestRequirementOpenDialog(
  50. zJson->zValue("id")->asString()->getString(),
  51. zJson->zValue("description")->asString()->getString(),
  52. zJson->zValue("dialogId")->asString()->getString());
  53. }
  54. Framework::JSON::JSONObject* QuestRequirementOpenDialogType::toJson(
  55. QuestRequirementOpenDialog* zObject) const
  56. {
  57. Framework::JSON::JSONObject* json = new Framework::JSON::JSONObject();
  58. json->addValue(
  59. "id", new Framework::JSON::JSONString(zObject->getRequirementId()));
  60. json->addValue("description",
  61. new Framework::JSON::JSONString(zObject->getDescription()));
  62. json->addValue(
  63. "dialogId", new Framework::JSON::JSONString(zObject->dialogId));
  64. return json;
  65. }
  66. Framework::JSON::Validator::JSONValidator*
  67. QuestRequirementOpenDialogType::getValidator(
  68. Framework::JSON::Validator::ObjectValidationBuilder<
  69. Framework::JSON::Validator::JSONValidator>* builder) const
  70. {
  71. return builder->withRequiredString("id")
  72. ->finishString()
  73. ->withRequiredString("description")
  74. ->finishString()
  75. ->withRequiredString("dialogId")
  76. ->finishString()
  77. ->finishObject();
  78. }
  79. Framework::Text QuestRequirementOpenDialogType::getTypeToken() const
  80. {
  81. return "open_dialog";
  82. }