123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846 |
- #include "Quest.h"
- #include <Datei.h>
- #include <Fenster.h>
- #include <Logging.h>
- #include <TextFeld.h>
- #include "Game.h"
- QuestRequirementStorage::QuestRequirementStorage()
- : ReferenceCounter(),
- fulfilled(0)
- {}
- void QuestRequirementStorage::setFullfilled(bool fullfilled)
- {
- this->fulfilled = fullfilled;
- }
- bool QuestRequirementStorage::isFullfilled() const
- {
- return fulfilled;
- }
- void QuestRequirementStorage::setRequirementId(Framework::Text requirementId)
- {
- this->requirementId = requirementId;
- }
- const Framework::Text& QuestRequirementStorage::getRequirementId() const
- {
- return requirementId;
- }
- QuestRequirementStorageType::QuestRequirementStorageType()
- : TypeFactory<QuestRequirementStorage>()
- {}
- QuestRequirementStorage* QuestRequirementStorageType::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new QuestRequirementStorage();
- }
- void QuestRequirementStorageType::fromJson(
- QuestRequirementStorage* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setRequirementId(
- zJson->asObject()->zValue("requirementId")->asString()->getString());
- zResult->setFullfilled(
- zJson->asObject()->zValue("fulfilled")->asBool()->getBool());
- }
- void QuestRequirementStorageType::toJson(QuestRequirementStorage* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("requirementId",
- new Framework::JSON::JSONString(zObject->getRequirementId()));
- zResult->addValue(
- "fulfilled", new Framework::JSON::JSONBool(zObject->isFullfilled()));
- }
- JSONObjectValidationBuilder* QuestRequirementStorageType::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("requirementId")
- ->finishString()
- ->withRequiredBool("fulfilled")
- ->withDefault(false)
- ->finishBool();
- }
- QuestStorage::QuestStorage()
- : 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();
- result->setRequirementId(requirementId);
- requirements.add(result);
- return result;
- }
- void QuestStorage::setQuestId(Framework::Text questId)
- {
- this->questId = questId;
- }
- 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::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new QuestStorage();
- }
- void QuestStorageType::fromJson(
- QuestStorage* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setQuestId(
- zJson->asObject()->zValue("questId")->asString()->getString());
- zResult->setQuestFinished(
- zJson->asObject()->zValue("finished")->asBool()->getBool());
- zResult->setQuestRewarded(
- zJson->asObject()->zValue("rewarded")->asBool()->getBool());
- Framework::JSON::JSONArray* rewardsArray
- = zJson->asObject()->zValue("requirements")->asArray();
- for (int i = 0; i < rewardsArray->getLength(); i++)
- {
- zResult->requirements.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestRequirementStorage>(
- rewardsArray->zValue(i)->asObject()));
- }
- zResult->data->release();
- zResult->data = zJson->asObject()->getValue("data")->asObject();
- }
- void QuestStorageType::toJson(
- QuestStorage* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "questId", new Framework::JSON::JSONString(zObject->questId));
- zResult->addValue(
- "finished", new Framework::JSON::JSONBool(zObject->finished));
- zResult->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));
- }
- zResult->addValue("requirements", rewardsArray);
- Framework::Text dataString = zObject->data->toString();
- zResult->addValue("data", Framework::JSON::Parser::getValue(dataString));
- }
- JSONObjectValidationBuilder* QuestStorageType::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->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();
- }
- 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();
- result->setQuestId(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::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new QuestParty();
- }
- void QuestPartyType::fromJson(
- QuestParty* zResult, Framework::JSON::JSONObject* zJson) const
- {
- Framework::JSON::JSONArray* membersArray
- = zJson->asObject()->zValue("members")->asArray();
- for (int i = 0; i < membersArray->getLength(); i++)
- {
- zResult->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++)
- {
- zResult->questStorage.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestStorage>(
- storagesArray->zValue(i)->asObject()));
- }
- }
- void QuestPartyType::toJson(
- QuestParty* zObject, Framework::JSON::JSONObject* zResult) const
- {
- Framework::JSON::JSONArray* membersArray = new Framework::JSON::JSONArray();
- for (int memberEntityId : zObject->memberEntityIds)
- {
- membersArray->addValue(new Framework::JSON::JSONNumber(memberEntityId));
- }
- zResult->addValue("members", membersArray);
- Framework::JSON::JSONArray* storagesArray
- = new Framework::JSON::JSONArray();
- for (QuestStorage* storage : zObject->questStorage)
- {
- storagesArray->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson(storage));
- }
- zResult->addValue("quests", storagesArray);
- }
- JSONObjectValidationBuilder* QuestPartyType::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredArray("members")
- ->addAcceptedNumberInArray()
- ->finishNumber()
- ->removeInvalidEntries()
- ->finishArray()
- ->withRequiredArray("quests")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<QuestStorage>())
- ->removeInvalidEntries()
- ->finishArray();
- }
- Quest::Quest()
- : ReferenceCounter(),
- 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;
- }
- void Quest::setQuestId(Framework::Text questId)
- {
- this->questId = questId;
- }
- 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::createValue(Framework::JSON::JSONObject* zJson) const
- {
- return new Quest();
- }
- void QuestType::fromJson(
- Quest* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setQuestId(
- zJson->asObject()->zValue("questId")->asString()->getString());
- zResult->questName
- = zJson->asObject()->zValue("questName")->asString()->getString();
- zResult->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++)
- {
- zResult->requiredQuestsIds.add(new Framework::Text(
- requiredQuestIdsArray->zValue(j)->asString()->getString()));
- zResult->requiredQuestsGroups.add(i);
- }
- }
- Framework::JSON::JSONArray* requirementsArray
- = zJson->asObject()->zValue("requirements")->asArray();
- for (int i = 0; i < requirementsArray->getLength(); i++)
- {
- zResult->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++)
- {
- zResult->rewards.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<QuestReward>(
- rewardsArray->zValue(i)));
- }
- zResult->imagePath
- = zJson->asObject()->zValue("imagePath")->asString()->getString();
- }
- void QuestType::toJson(
- Quest* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue(
- "questId", new Framework::JSON::JSONString(zObject->questId));
- zResult->addValue(
- "questName", new Framework::JSON::JSONString(zObject->questName));
- zResult->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();
- }
- zResult->addValue("requiredQuestIds", requiredQuestGroupArray);
- Framework::JSON::JSONArray* requirementsArray
- = new Framework::JSON::JSONArray();
- for (QuestRequirement* requirement : zObject->requirements)
- {
- requirementsArray->addValue(
- Game::INSTANCE->zTypeRegistry()->toJson(requirement));
- }
- zResult->addValue("requirements", requirementsArray);
- Framework::JSON::JSONArray* rewardsArray = new Framework::JSON::JSONArray();
- for (QuestReward* reward : zObject->rewards)
- {
- rewardsArray->addValue(Game::INSTANCE->zTypeRegistry()->toJson(reward));
- }
- zResult->addValue("rewards", rewardsArray);
- zResult->addValue(
- "imagePath", new Framework::JSON::JSONString(zObject->imagePath));
- }
- JSONObjectValidationBuilder* QuestType::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->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();
- }
- QuestCollection::QuestCollection()
- : ReferenceCounter()
- {}
- 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);
- }
- void QuestCollection::setName(Framework::Text name)
- {
- this->name = name;
- }
- 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::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new QuestCollection();
- }
- void QuestCollectionType::fromJson(
- QuestCollection* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setName(
- zJson->asObject()->zValue("name")->asString()->getString());
- Framework::JSON::JSONArray* questsArray
- = zJson->asObject()->zValue("quests")->asArray();
- for (int i = 0; i < questsArray->getLength(); i++)
- {
- zResult->quests.add(Game::INSTANCE->zTypeRegistry()->fromJson<Quest>(
- questsArray->zValue(i)->asObject()));
- }
- }
- void QuestCollectionType::toJson(
- QuestCollection* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->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));
- }
- zResult->addValue("quests", questsArray);
- }
- JSONObjectValidationBuilder* QuestCollectionType::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredString("name")
- ->finishString()
- ->withRequiredArray("quests")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()->getValidator<Quest>())
- ->removeInvalidEntries()
- ->finishArray();
- }
- 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))
- {
- Framework::Logging::info()
- << "no quest data found in world save, using default data";
- questDir = "data/quests";
- }
- Framework::JSON::JSONValue* value
- = Framework::JSON::loadJSONFromFile(questDir + "/quests.json");
- if (!value || value->getType() == Framework::JSON::JSONType::NULL_)
- {
- Framework::Logging::warning()
- << "No valid quests.json found in " << questDir;
- if (value)
- {
- value->release();
- }
- }
- else
- {
- Framework::Logging::info() << "loading quests ...";
- 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)
- {
- Framework::Logging::error() << invalidPart->getInvalidInfo();
- }
- 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
- {
- Framework::Logging::info() << "loading quest parties ...";
- 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)
- {
- Framework::Logging::error() << invalidPart->getInvalidInfo();
- }
- value->release();
- for (Framework::JSON::JSONValue* validPart : *valid)
- {
- parties.add(Game::INSTANCE->zTypeRegistry()->fromJson<QuestParty>(
- validPart->asObject()));
- }
- valid->release();
- validator->release();
- }
- Framework::Logging::info()
- << "Loaded " << questCollections.getEintragAnzahl()
- << " Quest Collections and " << parties.getEintragAnzahl()
- << " Quest Parties";
- }
- 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));
- }
- Framework::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);
- }
- }
|