summaryrefslogtreecommitdiff
path: root/src/actions/actions.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-12-09 15:46:24 +0300
committerAndrei Karas <akaras@inbox.ru>2014-12-09 15:46:24 +0300
commit7e437604c8de0784f1343e6e8aa01612a194c466 (patch)
tree99d295c3708955440051197ad64c16e4cbc4c3c4 /src/actions/actions.cpp
parent6737c33ffb89262a76bee80cdc9afeeebddbc2f7 (diff)
downloadplus-7e437604c8de0784f1343e6e8aa01612a194c466.tar.gz
plus-7e437604c8de0784f1343e6e8aa01612a194c466.tar.bz2
plus-7e437604c8de0784f1343e6e8aa01612a194c466.tar.xz
plus-7e437604c8de0784f1343e6e8aa01612a194c466.zip
Extend talk chat command like buy and sell commands.
Diffstat (limited to 'src/actions/actions.cpp')
-rw-r--r--src/actions/actions.cpp52
1 files changed, 29 insertions, 23 deletions
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;