summaryrefslogtreecommitdiff
path: root/src/game-server/charactercomponent.cpp
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-09-23 22:37:15 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-09-26 18:09:32 +0200
commit73f1933f94bcadb8c3b3f9763e6afad5f02891f4 (patch)
tree6cd028fcfe3d4a8675f00d5a4a6566d62f3f679a /src/game-server/charactercomponent.cpp
parent825bc65e0328367c26bebbf68066de3800372f84 (diff)
downloadmanaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.tar.gz
manaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.tar.bz2
manaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.tar.xz
manaserv-73f1933f94bcadb8c3b3f9763e6afad5f02891f4.zip
Store questlog values in the database
Diffstat (limited to 'src/game-server/charactercomponent.cpp')
-rw-r--r--src/game-server/charactercomponent.cpp112
1 files changed, 111 insertions, 1 deletions
diff --git a/src/game-server/charactercomponent.cpp b/src/game-server/charactercomponent.cpp
index 11e90a65..344a8959 100644
--- a/src/game-server/charactercomponent.cpp
+++ b/src/game-server/charactercomponent.cpp
@@ -176,6 +176,16 @@ void CharacterComponent::deserialize(Entity &entity, MessageIn &msg)
entity.getComponent<AbilityComponent>()->giveAbility(id);
}
+ // questlog
+ int questlogSize = msg.readInt16();
+ for (int i = 0; i < questlogSize; ++i) {
+ unsigned id = msg.readInt16();
+ QuestState state = (QuestState) msg.readInt8();
+ std::string title = msg.readString();
+ std::string description = msg.readString();
+
+ setQuestlog(id, state, title, description);
+ }
Possessions &poss = getPossessions();
@@ -256,6 +266,16 @@ void CharacterComponent::serialize(Entity &entity, MessageOut &msg)
msg.writeInt32(abilityIt.first);
}
+ // questlog
+ msg.writeInt16(mQuestlog.size());
+ for (auto questlogIt : mQuestlog) {
+ QuestInfo &quest = questlogIt.second;
+ msg.writeInt16(quest.id);
+ msg.writeInt8(quest.state);
+ msg.writeString(quest.title);
+ msg.writeString(quest.description);
+ }
+
// inventory - must be last because size isn't transmitted
const Possessions &poss = getPossessions();
const EquipData &equipData = poss.getEquipment();
@@ -359,6 +379,44 @@ void CharacterComponent::sendAttributePointsStatus(Entity &entity)
mSendAttributePointsStatus = false;
}
+void CharacterComponent::sendQuestUpdate()
+{
+ MessageOut msg(GPMSG_QUESTLOG_STATUS);
+ for (auto &questIt : mModifiedQuests) {
+ const QuestInfo *quest = questIt.first;
+ bool notify = questIt.second;
+ msg.writeInt16(quest->id);
+ int flags = QUESTLOG_UPDATE_STATE |
+ QUESTLOG_UPDATE_TITLE |
+ QUESTLOG_UPDATE_DESCRIPTION;
+ if (notify)
+ flags |= QUESTLOG_SHOW_NOTIFICATION;
+ msg.writeInt8(flags);
+ msg.writeInt8(quest->state);
+ msg.writeString(quest->title);
+ msg.writeString(quest->description);
+ }
+ mModifiedQuests.clear();
+ gameHandler->sendTo(mClient, msg);
+}
+
+void CharacterComponent::markQuestAsModified(const QuestInfo *quest,
+ bool sendNotification)
+{
+ const auto &it = mModifiedQuests.find(quest);
+ if (it == mModifiedQuests.end()) {
+ mModifiedQuests.insert(std::make_pair(quest, sendNotification));
+ return;
+ }
+ it->second = sendNotification;
+}
+void CharacterComponent::markAllQuestsAsModified()
+{
+ for (auto &questIt : mQuestlog) {
+ mModifiedQuests[&questIt.second] = false;
+ }
+}
+
void CharacterComponent::cancelTransaction()
{
TransactionType t = mTransaction;
@@ -428,7 +486,8 @@ void CharacterComponent::sendStatus(Entity &entity)
attribMsg.writeInt32(beingComponent->getAttributeBase(attribute) * 256);
attribMsg.writeInt32(beingComponent->getModifiedAttribute(attribute) * 256);
}
- if (attribMsg.getLength() > 2) gameHandler->sendTo(mClient, attribMsg);
+ if (attribMsg.getLength() > 2)
+ gameHandler->sendTo(mClient, attribMsg);
mModifiedAttributes.clear();
if (!mModifiedAbilities.empty())
@@ -439,6 +498,9 @@ void CharacterComponent::sendStatus(Entity &entity)
if (mSendAttributePointsStatus)
sendAttributePointsStatus(entity);
+
+ if (!mModifiedQuests.empty())
+ sendQuestUpdate();
}
void CharacterComponent::modifiedAllAbilities(Entity &entity)
@@ -581,4 +643,52 @@ void CharacterComponent::markAllInfoAsChanged(Entity &entity)
{
modifiedAllAbilities(entity);
modifiedAllAttributes(entity);
+ markAllQuestsAsModified();
+}
+
+void CharacterComponent::setQuestlog(unsigned id, QuestState state,
+ const std::string &title,
+ const std::string &description,
+ bool sendNotification)
+{
+ auto &quest = mQuestlog[id];
+ quest.id = id;
+ quest.state = state;
+ quest.title = title;
+ quest.description = description;
+
+ markQuestAsModified(&quest, sendNotification);
+}
+
+void CharacterComponent::setQuestlogState(unsigned id,
+ QuestState state,
+ bool sendNotification)
+{
+ auto &quest = mQuestlog[id];
+ quest.id = id;
+ quest.state = state;
+
+ markQuestAsModified(&quest, sendNotification);
+}
+
+void CharacterComponent::setQuestlogTitle(unsigned id,
+ const std::string &title,
+ bool sendNotification)
+{
+ auto &quest = mQuestlog[id];
+ quest.id = id;
+ quest.title = title;
+
+ markQuestAsModified(&quest, sendNotification);
+}
+
+void CharacterComponent::setQuestlogDescription(unsigned id,
+ const std::string &description,
+ bool sendNotification)
+{
+ auto &quest = mQuestlog[id];
+ quest.id = id;
+ quest.description = description;
+
+ markQuestAsModified(&quest, sendNotification);
}