diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-12-09 15:22:23 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-12-09 15:22:23 +0300 |
commit | 7dcc42c841005c5e475bfcb37e78bc7bc15b4a9d (patch) | |
tree | df944f29b257ebc695ca2f21b663ef57b120aab9 /src/actions | |
parent | 4a6ffbd08067b64143e0535518a3822953943d80 (diff) | |
download | mv-7dcc42c841005c5e475bfcb37e78bc7bc15b4a9d.tar.gz mv-7dcc42c841005c5e475bfcb37e78bc7bc15b4a9d.tar.bz2 mv-7dcc42c841005c5e475bfcb37e78bc7bc15b4a9d.tar.xz mv-7dcc42c841005c5e475bfcb37e78bc7bc15b4a9d.zip |
Add sell action.
New chat command: /sell [name]
Diffstat (limited to 'src/actions')
-rw-r--r-- | src/actions/commands.cpp | 42 | ||||
-rw-r--r-- | src/actions/commands.h | 1 |
2 files changed, 39 insertions, 4 deletions
diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index cd35ba9aa..eafd0b82b 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -713,19 +713,34 @@ impHandler0(fireHomunculus) return true; } -impHandler(buy) +static Being *findBeing(const std::string &name) { - const std::string args = event.args; Being *being = nullptr; - if (args.empty()) + if (name.empty()) { being = localPlayer->getTarget(); } else { being = actorManager->findBeingByName( - args, ActorType::Unknown); + name, ActorType::Unknown); + } + if (!being) + { + being = actorManager->findNearestLivingBeing( + localPlayer, 1, ActorType::Npc, true); + } + if (!being) + { + being = actorManager->findNearestLivingBeing( + localPlayer, 1, ActorType::Player, true); } + return being; +} + +impHandler(buy) +{ + Being *being = findBeing(event.args); if (!being) return false; @@ -742,4 +757,23 @@ impHandler(buy) return false; } +impHandler(sell) +{ + Being *being = findBeing(event.args); + if (!being) + return false; + + if (being->getType() == ActorType::Npc) + { + npcHandler->sell(being->getId()); + return true; + } + else if (being->getType() == ActorType::Player) + { + buySellHandler->requestBuyList(being->getName()); + return true; + } + return false; +} + } // namespace Actions diff --git a/src/actions/commands.h b/src/actions/commands.h index 29fa6ef27..8f55b023e 100644 --- a/src/actions/commands.h +++ b/src/actions/commands.h @@ -77,6 +77,7 @@ namespace Actions decHandler(setHomunculusName); decHandler(fireHomunculus); decHandler(buy); + decHandler(sell); } // namespace Actions #undef decHandler |