diff options
Diffstat (limited to 'src/net/tmwa/playerhandler.cpp')
-rw-r--r-- | src/net/tmwa/playerhandler.cpp | 116 |
1 files changed, 108 insertions, 8 deletions
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index f6f6ef41..44b0efd3 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -21,8 +21,11 @@ #include "net/tmwa/playerhandler.h" +#include "actorspritemanager.h" +#include "being.h" #include "client.h" #include "configuration.h" +#include "effectmanager.h" #include "game.h" #include "localplayer.h" #include "log.h" @@ -55,7 +58,7 @@ const int MAP_TELEPORT_SCROLL_DISTANCE = 8; namespace { /** - * Listener used for handling the overweigth message. + * Listener used for handling the overweight message. */ struct WeightListener : public gcn::ActionListener { @@ -126,7 +129,7 @@ static const char *randomDeathMessage() N_("You're off the twig."), N_("You've kicked the bucket."), N_("You've shuffled off your mortal coil, run down the " - "curtain and joined the bleedin' choir invisibile."), + "curtain and joined the bleedin' choir invisible."), N_("You are an ex-player."), N_("You're pining for the fjords.") }; @@ -152,10 +155,14 @@ PlayerHandler::PlayerHandler() SMSG_PLAYER_STAT_UPDATE_6, SMSG_PLAYER_ARROW_MESSAGE, SMSG_MAP_MASK, + SMSG_QUEST_SET_VAR, + SMSG_QUEST_PLAYER_VARS, 0 }; handledMessages = _messages; playerHandler = this; + + listen(Event::GameChannel); } void PlayerHandler::handleMessage(MessageIn &msg) @@ -179,7 +186,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) int x = msg.readInt16(); int y = msg.readInt16(); - logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y); + Log::info("Warping to %s (%d, %d)", mapPath.c_str(), x, y); /* * We must clear the local player's target *before* the call @@ -217,8 +224,8 @@ void PlayerHandler::handleMessage(MessageIn &msg) // Stop movement local_player->setDestination(pos.x, pos.y); - logger->log("Adjust scrolling by %d:%d", (int) scrollOffsetX, - (int) scrollOffsetY); + Log::info("Adjust scrolling by %d:%d", (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -499,7 +506,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) serverNotice(_("Equip arrows first.")); break; default: - logger->log("0x013b: Unhandled message %i", type); + Log::info("0x013b: Unhandled message %i", type); break; } } @@ -514,6 +521,49 @@ void PlayerHandler::handleMessage(MessageIn &msg) map->setMask(mask); } break; + + case SMSG_QUEST_SET_VAR: + { + int variable = msg.readInt16(); + int value = msg.readInt32(); + int oldValue = mQuestVars.get(variable); + + mQuestVars.set(variable, value); + updateQuestStatusEffects(); + Event::trigger(Event::QuestsChannel, Event::QuestVarsChanged); + + if (effectManager && local_player) + { + switch (QuestDB::questChange(variable, oldValue, value)) + { + case QuestChange::None: + break; + case QuestChange::New: + effectManager->trigger(paths.getIntValue("newQuestEffectId"), local_player); + break; + case QuestChange::Completed: + effectManager->trigger(paths.getIntValue("completeQuestEffectId"), local_player); + break; + } + } + break; + } + + case SMSG_QUEST_PLAYER_VARS: + { + msg.readInt16(); // length + mQuestVars.clear(); + unsigned int count = (msg.getLength() - 4) / 6; + for (unsigned int i = 0; i < count; ++i) + { + int variable = msg.readInt16(); + int value = msg.readInt32(); + mQuestVars.set(variable, value); + } + updateQuestStatusEffects(); + Event::trigger(Event::QuestsChannel, Event::QuestVarsChanged); + break; + } } } @@ -649,8 +699,8 @@ Vector PlayerHandler::getPixelsPerSecondMoveSpeed(const Vector &speed, Map *map) if (!map || speed.x == 0 || speed.y == 0) { - logger->log("TmwAthena::PlayerHandler: Speed set to default: " - "Map not yet initialized or invalid speed."); + Log::info("TmwAthena::PlayerHandler: Speed set to default: " + "Map not yet initialized or invalid speed."); return getDefaultMoveSpeed(); } @@ -664,4 +714,54 @@ Vector PlayerHandler::getPixelsPerSecondMoveSpeed(const Vector &speed, Map *map) return pixelsPerSecond; } +void PlayerHandler::event(Event::Channel channel, const Event &event) +{ + if (channel == Event::GameChannel) + { + if (event.getType() == Event::MapLoaded) + { + updateQuestStatusEffects(); + } + } +} + +void PlayerHandler::applyQuestStatusEffects(Being *npc) +{ + const auto npcId = npc->getSubType(); + const auto effect = mActiveQuestEffects.get(npcId); + if (effect != 0) + npc->setStatusEffect(effect, true); +} + +void PlayerHandler::updateQuestStatusEffects() +{ + auto game = Game::instance(); + if (!game) + return; + + const auto ¤tMapName = game->getCurrentMapName(); + auto updatedQuestEffects = QuestDB::getActiveEffects(mQuestVars, currentMapName); + + // Loop over all NPCs, disabling no longer active effects and enabling new ones + for (auto actor : actorSpriteManager->getAll()) { + if (actor->getType() != ActorSprite::NPC) + continue; + + auto *npc = static_cast<Being *>(actor); + const auto npcId = npc->getSubType(); + const auto oldEffect = mActiveQuestEffects.get(npcId); + const auto newEffect = updatedQuestEffects.get(npcId); + + if (oldEffect != newEffect) + { + if (oldEffect != 0) + npc->setStatusEffect(oldEffect, false); + if (newEffect != 0) + npc->setStatusEffect(newEffect, true); + } + } + + std::swap(mActiveQuestEffects, updatedQuestEffects); +} + } // namespace TmwAthena |