123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815 |
- #include "Quest.h"
- #include <Fenster.h>
- #include <TextFeld.h>
- #include "Game.h"
- QuestRequirementStorage::QuestRequirementStorage(Framework::Text requirementId)
- : ReferenceCounter(),
- requirementId(requirementId),
- fulfilled(0)
- {}
- void QuestRequirementStorage::setFullfilled(bool fullfilled)
- {
- this->fulfilled = fullfilled;
- }
- bool QuestRequirementStorage::isFullfilled() const
- {
- return fulfilled;
- }
- const Framework::Text& QuestRequirementStorage::getRequirementId() const
- {
- return requirementId;
- }
- QuestRequirementStorageType::QuestRequirementStorageType()
- : TypeFactory<QuestRequirementStorage>()
- {}
- QuestRequirementStorage* QuestRequirementStorageType::fromJson(
- Framework::JSON::JSONValue* zJson) const
- {
- QuestRequirementStorage* result = new QuestRequirementStorage(
- zJson->asObject()->zValue("requirementId")->asString()->getString());
- result->setFullfilled(
- zJson->asObject()->zValue("fulfilled")->asBool()->getBool());
- return result;
- }
- Framework::JSON::JSONValue* QuestRequirementStorageType::toJson(
- QuestRequirementStorage* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("requirementId",
- new Framework::JSON::JSONString(zObject->getRequirementId()));
- result->addValue(
- "fulfilled", new Framework::JSON::JSONBool(zObject->isFullfilled()));
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- QuestRequirementStorageType::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredString("requirementId")
- ->finishString()
- ->withRequiredBool("fulfilled")
- ->withDefault(false)
- ->finishBool()
- ->finishObject();
- }
- QuestStorage::QuestStorage(Framework::Text questId)
- : questId(questId),
- finished(0),
- rewarded(0),
- data(new Framework::JSON::JSONObject())
- {}
- QuestStorage::~QuestStorage()
- {
- data->release();
- }
- void QuestStorage::setQuestFinished(bool finished)
- {
- this->finished = finished;
- }
- void QuestStorage::setQuestRewarded(bool rewarded)
- {
- this->rewarded = rewarded;
- }
- bool QuestStorage::isQuestFinished() const
- {
- return finished;
- }
- bool QuestStorage::isQuestRewarded() const
- {
- return rewarded;
- }
- QuestRequirementStorage* QuestStorage::zStorage(Framework::Text requirementId)
- {
- for (QuestRequirementStorage* storage : requirements)
- {
- if (storage->getRequirementId().istGleich(requirementId))
- {
- return storage;
- }
- }
- QuestRequirementStorage* result
- = new QuestRequirementStorage(requirementId);
- requirements.add(result);
- return result;
- }
- const Framework::Text& QuestStorage::getQuestId() const
- {
- return questId;
- }
- bool QuestStorage::isVisible() const
- {
- return visible;
- }
- void QuestStorage::setVisible(bool visible)
- {
- this->visible = visible;
- }
- void QuestStorage::putValue(
- Framework::Text key, Framework::JSON::JSONValue* value)
- {
- data->removeValue(key);
- data->addValue(key, value);
- }
- Framework::JSON::JSONValue* QuestStorage::getValue(Framework::Text key) const
- {
- return data->getValue(key);
- }
- Framework::JSON::JSONValue* QuestStorage::zValue(Framework::Text key) const
- {
- return data->zValue(key);
- }
- bool QuestStorage::containsKey(Framework::Text key) const
- {
- return data->hasValue(key);
- }
- QuestStorageType::QuestStorageType()
- : TypeFactory<QuestStorage>()
- {}
- QuestStorage* QuestStorageType::fromJson(
- Framework::JSON::JSONValue* zJson) const
- {
- QuestStorage* result = new QuestStorage(
- zJson->asObject()->zValue("questId")->asString()->getString());
- result->finished
- = zJson->asObject()->zValue("finished")->asBool()->getBool();
- result->rewarded
- = zJson->asObject()->zValue("rewarded")->asBool()->getBool();
- Framework::JSON::JSONArray* rewardsArray
- = zJson->asObject()->zValue("requirements")->asArray();
- for (int i = 0; i < rewardsArray->getLength(); i++)
- {
- result->requirements.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestRequirementStorage>(
- rewardsArray->zValue(i)->asObject()));
- }
- result->data->release();
- result->data = zJson->asObject()->getValue("data")->asObject();
- return result;
- }
- Framework::JSON::JSONValue* QuestStorageType::toJson(
- QuestStorage* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue(
- "questId", new Framework::JSON::JSONString(zObject->questId));
- result->addValue(
- "finished", new Framework::JSON::JSONBool(zObject->finished));
- result->addValue(
- "rewarded", new Framework::JSON::JSONBool(zObject->rewarded));
- Framework::JSON::JSONArray* rewardsArray = new Framework::JSON::JSONArray();
- for (QuestRequirementStorage* storage : zObject->requirements)
- {
- rewardsArray->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson(storage));
- }
- result->addValue("requirements", rewardsArray);
- Framework::Text dataString = zObject->data->toString();
- result->addValue("data", Framework::JSON::Parser::getValue(dataString));
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- QuestStorageType::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredString("questId")
- ->finishString()
- ->withRequiredBool("finished")
- ->withDefault(false)
- ->finishBool()
- ->withRequiredBool("rewarded")
- ->withDefault(false)
- ->finishBool()
- ->withRequiredArray("requirements")
- ->addAcceptedTypeInArray(Game::INSTANCE->zTypeRegistry()
- ->getValidator<QuestRequirementStorage>())
- ->finishArray()
- ->withRequiredObject("data")
- ->allowAdditionalAttriutes()
- ->finishObject()
- ->finishObject();
- }
- QuestParty::QuestParty()
- : ReferenceCounter()
- {}
- void QuestParty::addMember(int memberEntityId)
- {
- memberEntityIds.add(memberEntityId);
- }
- void QuestParty::removeMember(int memberEntityId)
- {
- memberEntityIds.removeValue(memberEntityId);
- }
- bool QuestParty::isMember(int memberEntityId) const
- {
- return memberEntityIds.hat(memberEntityId);
- }
- bool QuestParty::isEmpty() const
- {
- return memberEntityIds.getEintragAnzahl() == 0;
- }
- QuestStorage* QuestParty::zQuestStorage(Framework::Text questId)
- {
- for (QuestStorage* storage : questStorage)
- {
- if (storage->getQuestId().istGleich(questId))
- {
- return storage;
- }
- }
- QuestStorage* result = new QuestStorage(questId);
- questStorage.add(result);
- return result;
- }
- QuestParty* QuestParty::clone() const
- {
- QuestParty* result = new QuestParty();
- for (QuestStorage* storage : questStorage)
- {
- Framework::JSON::JSONValue* value
- = Game::INSTANCE->zTypeRegistry()->toJson(storage);
- result->questStorage.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestStorage>(value));
- value->release();
- }
- return result;
- }
- QuestPartyType::QuestPartyType()
- : TypeFactory<QuestParty>()
- {}
- QuestParty* QuestPartyType::fromJson(Framework::JSON::JSONValue* zJson) const
- {
- QuestParty* result = new QuestParty();
- Framework::JSON::JSONArray* membersArray
- = zJson->asObject()->zValue("members")->asArray();
- for (int i = 0; i < membersArray->getLength(); i++)
- {
- result->memberEntityIds.add(
- (int)membersArray->zValue(i)->asNumber()->getNumber());
- }
- Framework::JSON::JSONArray* storagesArray
- = zJson->asObject()->zValue("quests")->asArray();
- for (int i = 0; i < storagesArray->getLength(); i++)
- {
- result->questStorage.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestStorage>(
- storagesArray->zValue(i)->asObject()));
- }
- return result;
- }
- Framework::JSON::JSONValue* QuestPartyType::toJson(QuestParty* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- Framework::JSON::JSONArray* membersArray = new Framework::JSON::JSONArray();
- for (int memberEntityId : zObject->memberEntityIds)
- {
- membersArray->addValue(new Framework::JSON::JSONNumber(memberEntityId));
- }
- result->addValue("members", membersArray);
- Framework::JSON::JSONArray* storagesArray
- = new Framework::JSON::JSONArray();
- for (QuestStorage* storage : zObject->questStorage)
- {
- storagesArray->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson(storage));
- }
- result->addValue("quests", storagesArray);
- return result;
- }
- Framework::JSON::Validator::JSONValidator* QuestPartyType::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredArray("members")
- ->addAcceptedNumberInArray()
- ->finishNumber()
- ->removeInvalidEntries()
- ->finishArray()
- ->withRequiredArray("quests")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<QuestStorage>())
- ->removeInvalidEntries()
- ->finishArray()
- ->finishObject();
- }
- Quest::Quest(Framework::Text questId)
- : ReferenceCounter(),
- questId(questId),
- mainQuest(0)
- {}
- void Quest::processEvent(QuestEvent* zEvent, QuestStorage* zStorage)
- {
- bool finished = 1;
- for (QuestRequirement* requirement : requirements)
- {
- QuestRequirementStorage* zRequirementStorage
- = zStorage->zStorage(requirement->getRequirementId());
- if (!zRequirementStorage->isFullfilled())
- {
- requirement->processEvent(zEvent, zStorage);
- finished &= zRequirementStorage->isFullfilled();
- }
- }
- if (finished)
- {
- zStorage->setQuestFinished(1);
- }
- }
- bool Quest::isVisible(QuestParty* zParty, QuestManager* zManager)
- {
- if (zParty->zQuestStorage(questId)->isVisible())
- {
- return 1;
- }
- bool visible = 0;
- for (Framework::Text* requiredQuestId : requiredQuestsIds)
- {
- visible |= zParty->zQuestStorage(*requiredQuestId)->isQuestFinished();
- }
- if (visible)
- {
- zParty->zQuestStorage(questId)->setVisible(visible);
- }
- for (Framework::Text* requiredQuestId : requiredQuestsIds)
- {
- zManager->setQuestVisible(true, *requiredQuestId, zParty);
- }
- return visible;
- }
- bool Quest::isActive(QuestParty* zParty)
- {
- bool active = 1;
- for (Framework::Text* requiredQuestId : requiredQuestsIds)
- {
- active &= zParty->zQuestStorage(*requiredQuestId)->isQuestFinished();
- }
- return active;
- }
- const Framework::Text& Quest::getQuestId() const
- {
- return questId;
- }
- void Quest::setVisible(bool visible, QuestParty* zParty, QuestManager* zManager)
- {
- if (zParty->zQuestStorage(questId)->isVisible() == visible)
- {
- return;
- }
- zParty->zQuestStorage(questId)->setVisible(visible);
- if (visible)
- {
- for (Framework::Text* requiredQuestId : requiredQuestsIds)
- {
- zManager->setQuestVisible(visible, *requiredQuestId, zParty);
- }
- }
- }
- QuestType::QuestType()
- : TypeFactory<Quest>()
- {}
- Quest* QuestType::fromJson(Framework::JSON::JSONValue* zJson) const
- {
- Quest* result = new Quest(
- zJson->asObject()->zValue("questId")->asString()->getString());
- result->questName
- = zJson->asObject()->zValue("questName")->asString()->getString();
- result->description
- = zJson->asObject()->zValue("description")->asString()->getString();
- Framework::JSON::JSONArray* requiredQuestGroups
- = zJson->asObject()->zValue("requiredQuestIds")->asArray();
- for (int i = 0; i < requiredQuestGroups->getLength(); i++)
- {
- Framework::JSON::JSONArray* requiredQuestIdsArray
- = requiredQuestGroups->zValue(i)->asArray();
- for (int j = 0; j < requiredQuestIdsArray->getLength(); j++)
- {
- result->requiredQuestsIds.add(new Framework::Text(
- requiredQuestIdsArray->zValue(j)->asString()->getString()));
- result->requiredQuestsGroups.add(i);
- }
- }
- Framework::JSON::JSONArray* requirementsArray
- = zJson->asObject()->zValue("requirements")->asArray();
- for (int i = 0; i < requirementsArray->getLength(); i++)
- {
- result->requirements.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestRequirement>(
- requirementsArray->zValue(i)));
- }
- Framework::JSON::JSONArray* rewardsArray
- = zJson->asObject()->zValue("rewards")->asArray();
- for (int i = 0; i < rewardsArray->getLength(); i++)
- {
- result->rewards.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestReward>(
- rewardsArray->zValue(i)));
- }
- result->imagePath
- = zJson->asObject()->zValue("imagePath")->asString()->getString();
- return result;
- }
- Framework::JSON::JSONValue* QuestType::toJson(Quest* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue(
- "questId", new Framework::JSON::JSONString(zObject->questId));
- result->addValue(
- "questName", new Framework::JSON::JSONString(zObject->questName));
- result->addValue(
- "description", new Framework::JSON::JSONString(zObject->description));
- Framework::JSON::JSONArray* requiredQuestGroupArray
- = new Framework::JSON::JSONArray();
- Framework::JSON::JSONArray* requiredQuestIdsArray
- = new Framework::JSON::JSONArray();
- int index = 0;
- int lastGroup = 0;
- for (Framework::Text* requiredQuestId : zObject->requiredQuestsIds)
- {
- int group = zObject->requiredQuestsGroups.get(index);
- if (lastGroup != group)
- {
- if (requiredQuestIdsArray->getLength())
- {
- requiredQuestGroupArray->addValue(requiredQuestIdsArray);
- requiredQuestIdsArray = new Framework::JSON::JSONArray();
- }
- lastGroup = group;
- }
- requiredQuestIdsArray->addValue(
- new Framework::JSON::JSONString(*requiredQuestId));
- index++;
- }
- if (requiredQuestIdsArray->getLength())
- {
- requiredQuestGroupArray->addValue(requiredQuestIdsArray);
- requiredQuestIdsArray = new Framework::JSON::JSONArray();
- }
- result->addValue("requiredQuestIds", requiredQuestGroupArray);
- Framework::JSON::JSONArray* requirementsArray
- = new Framework::JSON::JSONArray();
- for (QuestRequirement* requirement : zObject->requirements)
- {
- requirementsArray->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson(requirement));
- }
- result->addValue("requirements", requirementsArray);
- Framework::JSON::JSONArray* rewardsArray = new Framework::JSON::JSONArray();
- for (QuestReward* reward : zObject->rewards)
- {
- rewardsArray->addValue(Game::INSTANCE->zTypeRegistry()->toJson(reward));
- }
- result->addValue("rewards", rewardsArray);
- result->addValue(
- "imagePath", new Framework::JSON::JSONString(zObject->imagePath));
- return result;
- }
- Framework::JSON::Validator::JSONValidator* QuestType::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredString("questId")
- ->finishString()
- ->withRequiredString("questName")
- ->finishString()
- ->withRequiredString("description")
- ->finishString()
- ->withRequiredArray("requiredQuestIds")
- ->addAcceptedArrayInArray()
- ->addAcceptedStringInArray()
- ->finishString()
- ->finishArray()
- ->withDefault(new Framework::JSON::JSONArray())
- ->finishArray()
- ->withRequiredArray("requirements")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<QuestRequirement>())
- ->finishArray()
- ->withRequiredArray("rewards")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<QuestReward>())
- ->finishArray()
- ->withRequiredString("imagePath")
- ->finishString()
- ->finishObject();
- }
- QuestCollection::QuestCollection(Framework::Text name)
- : ReferenceCounter(),
- name(name)
- {}
- void QuestCollection::processEvent(QuestEvent* zEvent, QuestParty* zParty)
- {
- for (Quest* quest : quests)
- {
- QuestStorage* zStorage = zParty->zQuestStorage(quest->getQuestId());
- if (quest->isActive(zParty) && !zStorage->isQuestFinished())
- {
- quest->processEvent(zEvent, zStorage);
- }
- }
- }
- bool QuestCollection::isVisible(QuestParty* zParty, QuestManager* zManager)
- {
- bool visible = 1;
- for (Quest* quest : quests)
- {
- visible &= quest->isVisible(zParty, zManager);
- }
- return visible;
- }
- void QuestCollection::addQuest(Quest* zQuest)
- {
- quests.add(zQuest);
- }
- const Framework::Text& QuestCollection::getName() const
- {
- return name;
- }
- void QuestCollection::setQuestVisible(bool visible,
- Framework::Text questId,
- QuestParty* zParty,
- QuestManager* zManager)
- {
- for (Quest* quest : quests)
- {
- if (quest->getQuestId().istGleich(questId))
- {
- return quest->setVisible(visible, zParty, zManager);
- }
- }
- }
- QuestCollectionType::QuestCollectionType()
- : TypeFactory<QuestCollection>()
- {}
- QuestCollection* QuestCollectionType::fromJson(
- Framework::JSON::JSONValue* zJson) const
- {
- QuestCollection* result = new QuestCollection(
- zJson->asObject()->zValue("name")->asString()->getString());
- Framework::JSON::JSONArray* questsArray
- = zJson->asObject()->zValue("quests")->asArray();
- for (int i = 0; i < questsArray->getLength(); i++)
- {
- result->quests.add(Game::INSTANCE->zTypeRegistry()->fromJson<Quest>(
- questsArray->zValue(i)->asObject()));
- }
- return result;
- }
- Framework::JSON::JSONValue* QuestCollectionType::toJson(
- QuestCollection* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("name", new Framework::JSON::JSONString(zObject->name));
- Framework::JSON::JSONArray* questsArray = new Framework::JSON::JSONArray();
- for (Quest* quest : zObject->quests)
- {
- questsArray->addValue(Game::INSTANCE->zTypeRegistry()->toJson(quest));
- }
- result->addValue("quests", questsArray);
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- QuestCollectionType::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredString("name")
- ->finishString()
- ->withRequiredArray("quests")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<Quest>())
- ->removeInvalidEntries()
- ->finishArray()
- ->finishObject();
- }
- QuestManager::QuestManager()
- : ReferenceCounter()
- {}
- QuestParty* QuestManager::zParty(int entityId)
- {
- for (QuestParty* party : parties)
- {
- if (party->isMember(entityId))
- {
- return party;
- }
- }
- QuestParty* result = new QuestParty();
- result->addMember(entityId);
- parties.add(result);
- return result;
- }
- QuestCollection* QuestManager::zCollection(Framework::Text collectionName)
- {
- for (QuestCollection* collection : questCollections)
- {
- if (collection->getName().istGleich(collectionName))
- {
- return collection;
- }
- }
- return 0;
- }
- void QuestManager::loadQuests()
- {
- Framework::Text worldDir = Game::INSTANCE->getWorldDirectory();
- Framework::Text questDir = worldDir + "/quests";
- if (!Framework::DateiExistiert(questDir))
- {
- std::cout << "no quest data found in world save, using default data\n";
- questDir = "data/quests";
- }
- Framework::JSON::JSONValue* value
- = Framework::JSON::loadJSONFromFile(questDir + "/quests.json");
- if (!value || value->getType() == Framework::JSON::JSONType::NULL_)
- {
- std::cout << "No valid quests.json found in " << questDir << "\n";
- if (value)
- {
- value->release();
- }
- }
- else
- {
- std::cout << "loading quests ...\n";
- Framework::JSON::Validator::JSONValidator* validator
- = Framework::JSON::Validator::JSONValidator::buildForArray()
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<QuestCollection>())
- ->removeInvalidEntries()
- ->finishArray();
- Framework::RCArray<Framework::JSON::Validator::JSONValidationResult>
- validationResult;
- Framework::JSON::JSONArray* valid
- = validator->getValidParts(value, &validationResult)->asArray();
- for (Framework::JSON::Validator::JSONValidationResult* invalidPart :
- validationResult)
- {
- invalidPart->printInvalidInfo();
- }
- value->release();
- for (Framework::JSON::JSONValue* validPart : *valid)
- {
- questCollections.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestCollection>(
- validPart->asObject()));
- }
- valid->release();
- validator->release();
- }
- value = Framework::JSON::loadJSONFromFile(questDir + "/parties.json");
- if (!value || value->getType() == Framework::JSON::JSONType::NULL_)
- {
- if (value)
- {
- value->release();
- }
- }
- else
- {
- std::cout << "loading quest parties ...\n";
- Framework::JSON::Validator::JSONValidator* validator
- = Framework::JSON::Validator::JSONValidator::buildForArray()
- ->addAcceptedTypeInArray(Game::INSTANCE->zTypeRegistry()
- ->getValidator<QuestParty>())
- ->removeInvalidEntries()
- ->finishArray();
- Framework::RCArray<Framework::JSON::Validator::JSONValidationResult>
- validationResult;
- Framework::JSON::JSONArray* valid
- = validator->getValidParts(value, &validationResult)->asArray();
- for (Framework::JSON::Validator::JSONValidationResult* invalidPart :
- validationResult)
- {
- invalidPart->printInvalidInfo();
- }
- value->release();
- for (Framework::JSON::JSONValue* validPart : *valid)
- {
- parties.add(Game::INSTANCE->zTypeRegistry()->fromJson<QuestParty>(
- validPart->asObject()));
- }
- valid->release();
- validator->release();
- }
- std::cout << "Loaded " << questCollections.getEintragAnzahl()
- << " Quest Collections and " << parties.getEintragAnzahl()
- << " Quest Parties\n";
- }
- void QuestManager::saveQuests()
- {
- Framework::Text worldDir = Game::INSTANCE->getWorldDirectory();
- Framework::Text questDir = worldDir + "/quests";
- if (!Framework::DateiExistiert(questDir))
- {
- Framework::DateiPfadErstellen(questDir + "/");
- }
- Framework::JSON::JSONArray* questCollectionsArray
- = new Framework::JSON::JSONArray();
- for (QuestCollection* questCollection : questCollections)
- {
- questCollectionsArray->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson(questCollection));
- }
- Datei datei(questDir + "/quests.json");
- if (!datei.existiert()) datei.erstellen();
- datei.open(Framework::Datei::Style::schreiben);
- Framework::Text jsonStr = questCollectionsArray->toString();
- datei.schreibe(jsonStr.getText(), jsonStr.getLength());
- datei.close();
- questCollectionsArray->release();
- Framework::JSON::JSONArray* partiesArray = new Framework::JSON::JSONArray();
- for (QuestParty* party : parties)
- {
- partiesArray->addValue(Game::INSTANCE->zTypeRegistry()->toJson(party));
- }
- datei.setDatei(questDir + "/parties.json");
- if (!datei.existiert()) datei.erstellen();
- datei.open(Framework::Datei::Style::schreiben);
- jsonStr = partiesArray->toString();
- datei.schreibe(jsonStr.getText(), jsonStr.getLength());
- datei.close();
- partiesArray->release();
- }
- void QuestManager::processEvent(QuestEvent* event)
- {
- QuestParty* party = zParty(event->zActingEntity()->getId());
- if (party)
- {
- for (QuestCollection* questCollection : questCollections)
- {
- questCollection->processEvent(event, party);
- }
- }
- event->release();
- }
- void QuestManager::setQuestVisible(
- bool visible, Framework::Text questId, QuestParty* zParty)
- {
- for (QuestCollection* questCollection : questCollections)
- {
- questCollection->setQuestVisible(visible, questId, zParty, this);
- }
- }
|