From 7e437604c8de0784f1343e6e8aa01612a194c466 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 9 Dec 2014 15:46:24 +0300 Subject: Extend talk chat command like buy and sell commands. --- src/actions/actions.cpp | 52 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'src/actions') diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index f86b08a88..3ee65a396 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -161,7 +161,11 @@ static void uploadFile(const std::string &str, static Being *findBeing(const std::string &name) { + if (!localPlayer || !actorManager) + return nullptr; + Being *being = nullptr; + if (name.empty()) { being = localPlayer->getTarget(); @@ -175,11 +179,27 @@ static Being *findBeing(const std::string &name) { being = actorManager->findNearestLivingBeing( localPlayer, 1, ActorType::Npc, true); + if (being) + { + if (abs(being->getTileX() - localPlayer->getTileX()) > 1 + || abs(being->getTileY() - localPlayer->getTileY()) > 1) + { + being = nullptr; + } + } } if (!being) { being = actorManager->findNearestLivingBeing( localPlayer, 1, ActorType::Player, true); + if (being) + { + if (abs(being->getTileX() - localPlayer->getTileX()) > 1 + || abs(being->getTileY() - localPlayer->getTileY()) > 1) + { + being = nullptr; + } + } } return being; } @@ -497,30 +517,16 @@ impHandler(sell) impHandler0(talk) { - if (localPlayer) + Being *being = findBeing(event.args); + if (!being) + return false; + + if (being) { - Being *target = localPlayer->getTarget(); - if (!target && actorManager) - { - target = actorManager->findNearestLivingBeing( - localPlayer, 1, ActorType::Npc, true); - // ignore closest target if distance in each direction more than 1 - if (target) - { - if (abs(target->getTileX() - localPlayer->getTileX()) > 1 - || abs(target->getTileY() - localPlayer->getTileY()) > 1) - { - return true; - } - } - } - if (target) - { - if (target->canTalk()) - target->talkTo(); - else if (target->getType() == ActorType::Player) - new BuySellDialog(target->getName()); - } + if (being->canTalk()) + being->talkTo(); + else if (being->getType() == ActorType::Player) + new BuySellDialog(being->getName()); return true; } return false; -- cgit v1.2.3-70-g09d2