QuestRequirement.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. QuestRequirementOpenDialogType::QuestRequirementOpenDialogType()
  35. : SubTypeFactory()
  36. {}
  37. QuestRequirementOpenDialog* QuestRequirementOpenDialogType::fromJson(
  38. Framework::JSON::JSONObject* zJson) const
  39. {
  40. return new QuestRequirementOpenDialog(
  41. zJson->zValue("id")->asString()->getString(),
  42. zJson->zValue("description")->asString()->getString(),
  43. zJson->zValue("dialogId")->asString()->getString());
  44. }
  45. Framework::JSON::JSONObject* QuestRequirementOpenDialogType::toJson(
  46. QuestRequirementOpenDialog* zObject) const
  47. {
  48. Framework::JSON::JSONObject* json = new Framework::JSON::JSONObject();
  49. json->addValue(
  50. "id", new Framework::JSON::JSONString(zObject->getRequirementId()));
  51. json->addValue(
  52. "description", new Framework::JSON::JSONString(zObject->getDescription()));
  53. json->addValue(
  54. "dialogId", new Framework::JSON::JSONString(zObject->dialogId));
  55. return json;
  56. }
  57. Framework::JSON::Validator::JSONValidator*
  58. QuestRequirementOpenDialogType::getValidator(
  59. Framework::JSON::Validator::ObjectValidationBuilder<
  60. Framework::JSON::Validator::JSONValidator>* builder) const
  61. {
  62. return builder->withRequiredString("id")
  63. ->finishString()
  64. ->withRequiredString("description")
  65. ->finishString()
  66. ->withRequiredString("dialogId")
  67. ->finishString()
  68. ->finishObject();
  69. }
  70. Framework::Text QuestRequirementOpenDialogType::getTypeToken() const
  71. {
  72. return "open_dialog";
  73. }