Oskar1121

Untitled

Oct 2nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.38 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17. #include "otpch.h"
  18. #include "talkaction.h"
  19.  
  20. #include <boost/config.hpp>
  21. #include <boost/version.hpp>
  22.  
  23. #include "iologindata.h"
  24. #include "ioban.h"
  25.  
  26. #include "player.h"
  27. #include "npc.h"
  28.  
  29. #include "house.h"
  30. #include "town.h"
  31.  
  32. #include "teleport.h"
  33. #include "status.h"
  34. #include "textlogger.h"
  35.  
  36. #include "configmanager.h"
  37. #include "game.h"
  38. #include "chat.h"
  39. #include "tools.h"
  40.  
  41. extern ConfigManager g_config;
  42. extern Game g_game;
  43. extern Chat g_chat;
  44. extern TalkActions* g_talkActions;
  45.  
  46. TalkActions::TalkActions() :
  47. m_interface("TalkAction Interface")
  48. {
  49. m_interface.initState();
  50. }
  51.  
  52. TalkActions::~TalkActions()
  53. {
  54. clear();
  55. }
  56.  
  57. void TalkActions::clear()
  58. {
  59. for(TalkActionsMap::iterator it = talksMap.begin(); it != talksMap.end(); ++it)
  60. delete it->second;
  61.  
  62. talksMap.clear();
  63. m_interface.reInitState();
  64. }
  65.  
  66. Event* TalkActions::getEvent(const std::string& nodeName)
  67. {
  68. if(asLowerCaseString(nodeName) == "talkaction")
  69. return new TalkAction(&m_interface);
  70.  
  71. return NULL;
  72. }
  73.  
  74. bool TalkActions::registerEvent(Event* event, xmlNodePtr p, bool override)
  75. {
  76. TalkAction* talkAction = dynamic_cast<TalkAction*>(event);
  77. if(!talkAction)
  78. return false;
  79.  
  80. std::string sep;
  81. if(!readXMLString(p, "separator", sep) || sep.empty())
  82. sep = ";";
  83.  
  84. StringVec strVector = explodeString(talkAction->getWords(), sep);
  85. for(StringVec::iterator it = strVector.begin(); it != strVector.end(); ++it)
  86. {
  87. trimString(*it);
  88. talkAction->setWords(*it);
  89. if(talksMap.find(*it) != talksMap.end())
  90. {
  91. if(!override)
  92. {
  93. std::cout << "[Warning - TalkAction::configureEvent] Duplicate registered talkaction with words: " << (*it) << std::endl;
  94. continue;
  95. }
  96. else
  97. delete talksMap[(*it)];
  98. }
  99.  
  100. talksMap[(*it)] = new TalkAction(talkAction);
  101. }
  102.  
  103. delete talkAction;
  104. return true;
  105. }
  106.  
  107. bool TalkActions::onPlayerSay(Creature* creature, uint16_t channelId, const std::string& words, bool ignoreAccess)
  108. {
  109. std::string cmdstring[TALKFILTER_LAST] = words, paramstring[TALKFILTER_LAST] = "";
  110. size_t loc = words.find('"', 0);
  111. if(loc != std::string::npos && loc >= 0)
  112. {
  113. cmdstring[TALKFILTER_QUOTATION] = std::string(words, 0, loc);
  114. paramstring[TALKFILTER_QUOTATION] = std::string(words, (loc + 1), (words.size() - (loc - 1)));
  115. trimString(cmdstring[TALKFILTER_QUOTATION]);
  116. }
  117.  
  118. loc = words.find(" ", 0);
  119. if(loc != std::string::npos && loc >= 0)
  120. {
  121. cmdstring[TALKFILTER_WORD] = std::string(words, 0, loc);
  122. paramstring[TALKFILTER_WORD] = std::string(words, (loc + 1), (words.size() - (loc - 1)));
  123.  
  124. size_t sloc = words.find(" ", ++loc);
  125. if(sloc != std::string::npos && sloc >= 0)
  126. {
  127. cmdstring[TALKFILTER_WORD_SPACED] = std::string(words, 0, sloc);
  128. paramstring[TALKFILTER_WORD_SPACED] = std::string(words, (sloc + 1), (words.size() - (sloc - 1)));
  129. }
  130. }
  131.  
  132. TalkAction* talkAction = NULL;
  133. for(TalkActionsMap::iterator it = talksMap.begin(); it != talksMap.end(); ++it)
  134. {
  135. if(it->first == cmdstring[it->second->getFilter()] || (!it->second->isSensitive() &&
  136. !strcasecmp(it->first.c_str(), cmdstring[it->second->getFilter()].c_str())))
  137. {
  138. talkAction = it->second;
  139. break;
  140. }
  141. }
  142.  
  143. if(!talkAction || (talkAction->getChannel() != -1 && talkAction->getChannel() != channelId))
  144. return false;
  145.  
  146. Player* player = creature->getPlayer();
  147. StringVec exceptions = talkAction->getExceptions();
  148. if(player && ((!ignoreAccess && std::find(exceptions.begin(), exceptions.end(), asLowerCaseString(
  149. player->getName())) == exceptions.end() && talkAction->getAccess() > player->getAccess())
  150. || player->isAccountManager()))
  151. {
  152. if(player->hasCustomFlag(PlayerCustomFlag_GamemasterPrivileges))
  153. {
  154. player->sendTextMessage(MSG_STATUS_SMALL, "You cannot execute this talkaction.");
  155. return true;
  156. }
  157.  
  158. return false;
  159. }
  160.  
  161. if(talkAction->isLogged())
  162. {
  163. if(player)
  164. player->sendTextMessage(MSG_STATUS_CONSOLE_RED, words.c_str());
  165.  
  166. Logger::getInstance()->eFile("talkactions/" + creature->getName() + ".log", words, true);
  167. }
  168.  
  169. if(talkAction->isScripted())
  170. return talkAction->executeSay(creature, cmdstring[talkAction->getFilter()], paramstring[talkAction->getFilter()], channelId);
  171.  
  172. if(TalkFunction* function = talkAction->getFunction())
  173. return function(creature, cmdstring[talkAction->getFilter()], paramstring[talkAction->getFilter()]);
  174.  
  175. return false;
  176. }
  177.  
  178. TalkAction::TalkAction(LuaScriptInterface* _interface):
  179. Event(_interface)
  180. {
  181. m_function = NULL;
  182. m_filter = TALKFILTER_WORD;
  183. m_access = 0;
  184. m_channel = -1;
  185. m_logged = m_hidden = false;
  186. m_sensitive = true;
  187. }
  188.  
  189. TalkAction::TalkAction(const TalkAction* copy):
  190. Event(copy)
  191. {
  192. m_words = copy->m_words;
  193. m_function = copy->m_function;
  194. m_filter = copy->m_filter;
  195. m_access = copy->m_access;
  196. m_channel = copy->m_channel;
  197. m_logged = copy->m_logged;
  198. m_hidden = copy->m_hidden;
  199. m_sensitive = copy->m_sensitive;
  200. m_exceptions = copy->m_exceptions;
  201. }
  202.  
  203. bool TalkAction::configureEvent(xmlNodePtr p)
  204. {
  205. std::string strValue;
  206. if(readXMLString(p, "words", strValue))
  207. m_words = strValue;
  208. else
  209. {
  210. std::cout << "[Error - TalkAction::configureEvent] No words for TalkAction." << std::endl;
  211. return false;
  212. }
  213.  
  214. if(readXMLString(p, "filter", strValue))
  215. {
  216. std::string tmpStrValue = asLowerCaseString(strValue);
  217. if(tmpStrValue == "quotation")
  218. m_filter = TALKFILTER_QUOTATION;
  219. else if(tmpStrValue == "word")
  220. m_filter = TALKFILTER_WORD;
  221. else if(tmpStrValue == "word-spaced")
  222. m_filter = TALKFILTER_WORD_SPACED;
  223. else
  224. std::cout << "[Warning - TalkAction::configureEvent] Unknown filter for TalkAction: " << strValue << ", using default." << std::endl;
  225. }
  226.  
  227. int32_t intValue;
  228. if(readXMLInteger(p, "access", intValue))
  229. m_access = intValue;
  230.  
  231. if(readXMLInteger(p, "channel", intValue))
  232. m_channel = intValue;
  233.  
  234. if(readXMLString(p, "log", strValue) || readXMLString(p, "logged", strValue))
  235. m_logged = booleanString(strValue);
  236.  
  237. if(readXMLString(p, "hide", strValue) || readXMLString(p, "hidden", strValue))
  238. m_hidden = booleanString(strValue);
  239.  
  240. if(readXMLString(p, "case-sensitive", strValue) || readXMLString(p, "casesensitive", strValue) || readXMLString(p, "sensitive", strValue))
  241. m_sensitive = booleanString(strValue);
  242.  
  243. if(readXMLString(p, "exception", strValue))
  244. m_exceptions = explodeString(asLowerCaseString(strValue), ";");
  245.  
  246. return true;
  247. }
  248.  
  249. bool TalkAction::loadFunction(const std::string& functionName)
  250. {
  251. std::string tmpFunctionName = asLowerCaseString(functionName);
  252. if(tmpFunctionName == "housebuy")
  253. m_function = houseBuy;
  254. else if(tmpFunctionName == "housesell")
  255. m_function = houseSell;
  256. else if(tmpFunctionName == "housekick")
  257. m_function = houseKick;
  258. else if(tmpFunctionName == "housedoorlist")
  259. m_function = houseDoorList;
  260. else if(tmpFunctionName == "houseguestlist")
  261. m_function = houseGuestList;
  262. else if(tmpFunctionName == "housesubownerlist")
  263. m_function = houseSubOwnerList;
  264. else if(tmpFunctionName == "thingproporties")
  265. m_function = thingProporties;
  266. else if(tmpFunctionName == "banishmentinfo")
  267. m_function = banishmentInfo;
  268. else if(tmpFunctionName == "diagnostics")
  269. m_function = diagnostics;
  270. else if(tmpFunctionName == "addskill")
  271. m_function = addSkill;
  272. else if(tmpFunctionName == "ghost")
  273. m_function = ghost;
  274. else if(tmpFunctionName == "addloot")
  275. m_function = lootAdd;
  276. else if(tmpFunctionName == "removeloot")
  277. m_function = lootRemove;
  278. else if(tmpFunctionName == "visionloot")
  279. m_function = lootVision;
  280. else if(tmpFunctionName == "autoheal")
  281. m_function = autoHeal;
  282. else
  283. {
  284. std::cout << "[Warning - TalkAction::loadFunction] Function \"" << functionName << "\" does not exist." << std::endl;
  285. return false;
  286. }
  287.  
  288. m_scripted = EVENT_SCRIPT_FALSE;
  289. return true;
  290. }
  291.  
  292. int32_t TalkAction::executeSay(Creature* creature, const std::string& words, std::string param, uint16_t channel)
  293. {
  294. //onSay(cid, words, param, channel)
  295. if(m_interface->reserveEnv())
  296. {
  297. trimString(param);
  298. ScriptEnviroment* env = m_interface->getEnv();
  299. if(m_scripted == EVENT_SCRIPT_BUFFER)
  300. {
  301. env->setRealPos(creature->getPosition());
  302. std::stringstream scriptstream;
  303. scriptstream << "local cid = " << env->addThing(creature) << std::endl;
  304.  
  305. scriptstream << "local words = \"" << words << "\"" << std::endl;
  306. scriptstream << "local param = \"" << param << "\"" << std::endl;
  307. scriptstream << "local channel = " << channel << std::endl;
  308.  
  309. scriptstream << m_scriptData;
  310. bool result = true;
  311. if(m_interface->loadBuffer(scriptstream.str()))
  312. {
  313. lua_State* L = m_interface->getState();
  314. result = m_interface->getGlobalBool(L, "_result", true);
  315. }
  316.  
  317. m_interface->releaseEnv();
  318. return result;
  319. }
  320. else
  321. {
  322. env->setScriptId(m_scriptId, m_interface);
  323. env->setRealPos(creature->getPosition());
  324.  
  325. lua_State* L = m_interface->getState();
  326. m_interface->pushFunction(m_scriptId);
  327. lua_pushnumber(L, env->addThing(creature));
  328.  
  329. lua_pushstring(L, words.c_str());
  330. lua_pushstring(L, param.c_str());
  331. lua_pushnumber(L, channel);
  332.  
  333. bool result = m_interface->callFunction(4);
  334. m_interface->releaseEnv();
  335. return result;
  336. }
  337. }
  338. else
  339. {
  340. std::cout << "[Error - TalkAction::executeSay] Call stack overflow." << std::endl;
  341. return 0;
  342. }
  343. }
  344.  
  345. bool TalkAction::houseBuy(Creature* creature, const std::string& cmd, const std::string& param)
  346. {
  347. Player* player = creature->getPlayer();
  348. if(!player || !g_config.getBool(ConfigManager::HOUSE_BUY_AND_SELL))
  349. return false;
  350.  
  351. const Position& pos = getNextPosition(player->getDirection(), player->getPosition());
  352. Tile* tile = g_game.getTile(pos);
  353. if(!tile)
  354. {
  355. player->sendCancel("You have to be looking at door of flat you would like to purchase.");
  356. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  357. return false;
  358. }
  359.  
  360. HouseTile* houseTile = tile->getHouseTile();
  361. if(!houseTile)
  362. {
  363. player->sendCancel("You have to be looking at door of flat you would like to purchase.");
  364. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  365. return false;
  366. }
  367.  
  368. House* house = houseTile->getHouse();
  369. if(!house)
  370. {
  371. player->sendCancel("You have to be looking at door of flat you would like to purchase.");
  372. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  373. return false;
  374. }
  375.  
  376. if(!house->getDoorByPosition(pos))
  377. {
  378. player->sendCancel("You have to be looking at door of flat you would like to purchase.");
  379. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  380. return false;
  381. }
  382.  
  383. if(!house->isGuild())
  384. {
  385. if(Houses::getInstance()->getHouseByPlayerId(player->getGUID()))
  386. {
  387. player->sendCancel("You already rent another house.");
  388. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  389. return false;
  390. }
  391.  
  392. uint16_t accountHouses = g_config.getNumber(ConfigManager::HOUSES_PER_ACCOUNT);
  393. if(accountHouses > 0 && Houses::getInstance()->getHousesCount(player->getAccount()) >= accountHouses)
  394. {
  395. char buffer[80];
  396. sprintf(buffer, "You may own only %d house%s per account.", accountHouses, (accountHouses != 1 ? "s" : ""));
  397.  
  398. player->sendCancel(buffer);
  399. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  400. return false;
  401. }
  402.  
  403. if(g_config.getBool(ConfigManager::HOUSE_NEED_PREMIUM) && !player->isPremium())
  404. {
  405. player->sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT);
  406. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  407. return false;
  408. }
  409.  
  410. uint32_t levelToBuyHouse = g_config.getNumber(ConfigManager::LEVEL_TO_BUY_HOUSE);
  411. if(player->getLevel() < levelToBuyHouse)
  412. {
  413. char buffer[90];
  414. sprintf(buffer, "You have to be at least Level %d to purchase a house.", levelToBuyHouse);
  415. player->sendCancel(buffer);
  416. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  417. return false;
  418. }
  419. }
  420. else
  421. {
  422. if(!player->getGuildId() || player->getGuildLevel() != GUILDLEVEL_LEADER)
  423. {
  424. player->sendCancel("You have to be at least a guild leader to purchase a hall.");
  425. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  426. return false;
  427. }
  428.  
  429. if(Houses::getInstance()->getHouseByGuildId(player->getGuildId()))
  430. {
  431. player->sendCancel("Your guild rents already another hall.");
  432. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  433. return false;
  434. }
  435. }
  436.  
  437. if(house->getOwner())
  438. {
  439. player->sendCancel("This flat is already owned by someone else.");
  440. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  441. return false;
  442. }
  443.  
  444. if(g_game.getMoney(player) < house->getPrice() || !g_game.removeMoney(player, house->getPrice()))
  445. {
  446. player->sendCancel("You do not have enough money.");
  447. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  448. return false;
  449. }
  450.  
  451. house->setOwnerEx(player->getGUID(), true);
  452. std::string ret = "You have successfully bought this ";
  453. if(house->isGuild())
  454. ret += "hall";
  455. else
  456. ret += "house";
  457.  
  458. ret += ", remember to leave money at ";
  459. if(house->isGuild())
  460. ret += "guild owner ";
  461.  
  462. if(g_config.getBool(ConfigManager::BANK_SYSTEM))
  463. ret += "bank or ";
  464.  
  465. ret += "depot of this town for rent.";
  466. player->sendTextMessage(MSG_INFO_DESCR, ret.c_str());
  467.  
  468. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  469. return false;
  470. }
  471.  
  472. bool TalkAction::houseSell(Creature* creature, const std::string& cmd, const std::string& param)
  473. {
  474. Player* player = creature->getPlayer();
  475. if(!player || !g_config.getBool(ConfigManager::HOUSE_BUY_AND_SELL))
  476. return false;
  477.  
  478. House* house = Houses::getInstance()->getHouseByPlayerId(player->getGUID());
  479. if(!house && (!player->getGuildId() || !(house = Houses::getInstance()->getHouseByGuildId(player->getGuildId()))))
  480. {
  481. player->sendCancel("You do not rent any flat.");
  482. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  483. return false;
  484. }
  485.  
  486. if(house->isGuild() && player->getGuildLevel() != GUILDLEVEL_LEADER)
  487. {
  488. player->sendCancel("You have to be at least a guild leader to sell this hall.");
  489. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  490. return false;
  491. }
  492.  
  493. Player* tradePartner = NULL;
  494. ReturnValue ret = g_game.getPlayerByNameWildcard(param, tradePartner);
  495. if(ret != RET_NOERROR)
  496. {
  497. player->sendCancelMessage(ret);
  498. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  499. return false;
  500. }
  501.  
  502. if(tradePartner == player)
  503. {
  504. player->sendCancel("You cannot trade with yourself.");
  505. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  506. return false;
  507. }
  508.  
  509. if(!house->isGuild())
  510. {
  511. if(Houses::getInstance()->getHouseByPlayerId(tradePartner->getGUID()))
  512. {
  513. player->sendCancel("Trade player already rents another house.");
  514. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  515. return false;
  516. }
  517.  
  518. uint16_t housesPerAccount = g_config.getNumber(ConfigManager::HOUSES_PER_ACCOUNT);
  519. if(housesPerAccount > 0 && Houses::getInstance()->getHousesCount(tradePartner->getAccount()) >= housesPerAccount)
  520. {
  521. char buffer[100];
  522. sprintf(buffer, "Trade player has reached limit of %d house%s per account.", housesPerAccount, (housesPerAccount != 1 ? "s" : ""));
  523.  
  524. player->sendCancel(buffer);
  525. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  526. return false;
  527. }
  528.  
  529. if(!tradePartner->isPremium() && !g_config.getBool(ConfigManager::HOUSE_NEED_PREMIUM))
  530. {
  531. player->sendCancel("Trade player does not have a premium account.");
  532. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  533. return false;
  534. }
  535.  
  536. uint32_t levelToBuyHouse = g_config.getNumber(ConfigManager::LEVEL_TO_BUY_HOUSE);
  537. if(tradePartner->getLevel() < levelToBuyHouse)
  538. {
  539. char buffer[100];
  540. sprintf(buffer, "Trade player has to be at least Level %d to buy house.", levelToBuyHouse);
  541.  
  542. player->sendCancel(buffer);
  543. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  544. return false;
  545. }
  546. }
  547. else
  548. {
  549. if(!tradePartner->getGuildId() || tradePartner->getGuildLevel() != GUILDLEVEL_LEADER)
  550. {
  551. player->sendCancel("Trade player has to be at least a guild leader to buy a hall.");
  552. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  553. return false;
  554. }
  555.  
  556. if(Houses::getInstance()->getHouseByGuildId(tradePartner->getGuildId()))
  557. {
  558. player->sendCancel("Trade player's guild already rents another hall.");
  559. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  560. return false;
  561. }
  562. }
  563.  
  564. if(!Position::areInRange<3,3,0>(tradePartner->getPosition(), player->getPosition()))
  565. {
  566. player->sendCancel("Trade player is too far away.");
  567. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  568. return false;
  569. }
  570.  
  571. if(!Houses::getInstance()->payRent(player, house, 0))
  572. {
  573. player->sendCancel("You have to pay a pre-rent first.");
  574. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  575. return false;
  576. }
  577.  
  578. Item* transferItem = TransferItem::createTransferItem(house);
  579. player->transferContainer.__addThing(NULL, transferItem);
  580.  
  581. player->transferContainer.setParent(player);
  582. if(!g_game.internalStartTrade(player, tradePartner, transferItem))
  583. transferItem->onTradeEvent(ON_TRADE_CANCEL, player, NULL);
  584.  
  585. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  586. return false;
  587. }
  588.  
  589. bool TalkAction::houseKick(Creature* creature, const std::string& cmd, const std::string& param)
  590. {
  591. Player* player = creature->getPlayer();
  592. if(!player)
  593. return false;
  594.  
  595. Player* targetPlayer = NULL;
  596. if(g_game.getPlayerByNameWildcard(param, targetPlayer) != RET_NOERROR)
  597. targetPlayer = player;
  598.  
  599. House* house = Houses::getInstance()->getHouseByPlayer(targetPlayer);
  600. if(!house || !house->kickPlayer(player, targetPlayer))
  601. {
  602. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  603. player->sendCancelMessage(RET_NOTPOSSIBLE);
  604. }
  605. else
  606. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  607.  
  608. return false;
  609. }
  610.  
  611. bool TalkAction::houseDoorList(Creature* creature, const std::string& cmd, const std::string& param)
  612. {
  613. Player* player = creature->getPlayer();
  614. if(!player)
  615. return false;
  616.  
  617. House* house = Houses::getInstance()->getHouseByPlayer(player);
  618. if(!house)
  619. {
  620. player->sendCancelMessage(RET_NOTPOSSIBLE);
  621. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  622. return false;
  623. }
  624.  
  625. Door* door = house->getDoorByPosition(getNextPosition(player->getDirection(), player->getPosition()));
  626. if(door && house->canEditAccessList(door->getDoorId(), player))
  627. {
  628. player->setEditHouse(house, door->getDoorId());
  629. player->sendHouseWindow(house, door->getDoorId());
  630. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  631. }
  632. else
  633. {
  634. player->sendCancelMessage(RET_NOTPOSSIBLE);
  635. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  636. }
  637.  
  638. return false;
  639. }
  640.  
  641. bool TalkAction::houseGuestList(Creature* creature, const std::string& cmd, const std::string& param)
  642. {
  643. Player* player = creature->getPlayer();
  644. if(!player)
  645. return false;
  646.  
  647. House* house = Houses::getInstance()->getHouseByPlayer(player);
  648. if(house && house->canEditAccessList(GUEST_LIST, player))
  649. {
  650. player->setEditHouse(house, GUEST_LIST);
  651. player->sendHouseWindow(house, GUEST_LIST);
  652. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  653. }
  654. else
  655. {
  656. player->sendCancelMessage(RET_NOTPOSSIBLE);
  657. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  658. }
  659.  
  660. return false;
  661. }
  662.  
  663. bool TalkAction::houseSubOwnerList(Creature* creature, const std::string& cmd, const std::string& param)
  664. {
  665. Player* player = creature->getPlayer();
  666. if(!player)
  667. return false;
  668.  
  669. House* house = Houses::getInstance()->getHouseByPlayer(player);
  670. if(house && house->canEditAccessList(SUBOWNER_LIST, player))
  671. {
  672. player->setEditHouse(house, SUBOWNER_LIST);
  673. player->sendHouseWindow(house, SUBOWNER_LIST);
  674. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
  675. }
  676. else
  677. {
  678. player->sendCancelMessage(RET_NOTPOSSIBLE);
  679. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  680. }
  681.  
  682. return false;
  683. }
  684.  
  685. bool TalkAction::thingProporties(Creature* creature, const std::string& cmd, const std::string& param)
  686. {
  687. Player* player = creature->getPlayer();
  688. if(!player)
  689. return false;
  690.  
  691. const Position& pos = getNextPosition(player->getDirection(), player->getPosition());
  692. Tile* tile = g_game.getTile(pos);
  693. if(!tile)
  694. {
  695. player->sendTextMessage(MSG_STATUS_SMALL, "No tile found.");
  696. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  697. return true;
  698. }
  699.  
  700. Thing* thing = tile->getTopVisibleThing(creature);
  701. if(!thing)
  702. {
  703. player->sendTextMessage(MSG_STATUS_SMALL, "No object found.");
  704. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  705. return true;
  706. }
  707.  
  708. boost::char_separator<char> sep(" ");
  709. tokenizer tokens(param, sep);
  710.  
  711. std::string invalid;
  712. for(tokenizer::iterator it = tokens.begin(); it != tokens.end();)
  713. {
  714. std::string action = parseParams(it, tokens.end());
  715. toLowerCaseString(action);
  716. if(Item* item = thing->getItem())
  717. {
  718. if(action == "set")
  719. {
  720. std::string key = parseParams(it, tokens.end()), value = parseParams(it, tokens.end());
  721. if(atoi(value.c_str()) || value == "0")
  722. item->setAttribute(key, atoi(value.c_str()));
  723. else
  724. item->setAttribute(key, value);
  725. }
  726. else if(action == "erase" || action == "remove")
  727. item->eraseAttribute(parseParams(it, tokens.end()));
  728. else if(action == "action" || action == "actionid" || action == "aid")
  729. {
  730. int32_t tmp = atoi(parseParams(it, tokens.end()).c_str());
  731. if(tmp > 0)
  732. item->setActionId(tmp);
  733. else
  734. item->resetActionId();
  735. }
  736. else if(action == "unique" || action == "uniqueid" || action == "uid")
  737. {
  738. int32_t tmp = atoi(parseParams(it, tokens.end()).c_str());
  739. if(tmp >= 1000 || tmp <= 0xFFFF)
  740. item->setUniqueId(tmp);
  741. }
  742. else if(action == "destination" || action == "position"
  743. || action == "pos" || action == "dest") //TODO: doesn't work
  744. {
  745. if(Teleport* teleport = item->getTeleport())
  746. teleport->setDestination(Position(atoi(parseParams(it,
  747. tokens.end()).c_str()), atoi(parseParams(it, tokens.end()).c_str()),
  748. atoi(parseParams(it, tokens.end()).c_str())));
  749. }
  750. else
  751. {
  752. std::stringstream s;
  753. s << action << " (" << parseParams(it, tokens.end()) << ")";
  754. invalid += s.str();
  755. break;
  756. }
  757. }
  758. else if(Creature* _creature = thing->getCreature())
  759. {
  760. if(action == "health")
  761. _creature->changeHealth(atoi(parseParams(it, tokens.end()).c_str()));
  762. else if(action == "maxhealth")
  763. _creature->changeMaxHealth(atoi(parseParams(it, tokens.end()).c_str()));
  764. else if(action == "mana")
  765. _creature->changeMana(atoi(parseParams(it, tokens.end()).c_str()));
  766. else if(action == "maxmana")
  767. _creature->changeMaxMana(atoi(parseParams(it, tokens.end()).c_str()));
  768. else if(action == "basespeed")
  769. _creature->setBaseSpeed(atoi(parseParams(it, tokens.end()).c_str()));
  770. else if(action == "droploot")
  771. _creature->setDropLoot((lootDrop_t)atoi(parseParams(it, tokens.end()).c_str()));
  772. else if(action == "lossskill")
  773. _creature->setLossSkill(booleanString(parseParams(it, tokens.end())));
  774. else if(action == "cannotmove")
  775. _creature->setNoMove(booleanString(parseParams(it, tokens.end())));
  776. else if(action == "skull")
  777. {
  778. _creature->setSkull(getSkull(parseParams(it, tokens.end())));
  779. g_game.updateCreatureSkull(_creature);
  780. }
  781. else if(action == "speaktype")
  782. _creature->setSpeakType((SpeakClasses)atoi(parseParams(it, tokens.end()).c_str()));
  783. else if(Player* _player = _creature->getPlayer())
  784. {
  785. if(action == "fyi")
  786. _player->sendFYIBox(parseParams(it, tokens.end()).c_str());
  787. else if(action == "tutorial")
  788. _player->sendTutorial(atoi(parseParams(it, tokens.end()).c_str()));
  789. else if(action == "guildlevel")
  790. _player->setGuildLevel((GuildLevel_t)atoi(parseParams(it, tokens.end()).c_str()));
  791. else if(action == "guildrank")
  792. _player->setRankId(atoi(parseParams(it, tokens.end()).c_str()));
  793. else if(action == "guildnick")
  794. _player->setGuildNick(parseParams(it, tokens.end()).c_str());
  795. else if(action == "group")
  796. _player->setGroupId(atoi(parseParams(it, tokens.end()).c_str()));
  797. else if(action == "vocation")
  798. _player->setVocation(atoi(parseParams(it, tokens.end()).c_str()));
  799. else if(action == "sex" || action == "gender")
  800. _player->setSex(atoi(parseParams(it, tokens.end()).c_str()));
  801. else if(action == "stamina")
  802. _player->setStaminaMinutes(atoi(parseParams(it, tokens.end()).c_str()));
  803. else if(action == "town" || action == "temple")
  804. {
  805. if(Town* town = Towns::getInstance()->getTown(parseParams(it, tokens.end())))
  806. {
  807. _player->setMasterPosition(town->getPosition());
  808. _player->setTown(town->getID());
  809. }
  810. }
  811. else if(action == "balance")
  812. _player->balance = atoi(parseParams(it, tokens.end()).c_str());
  813. else if(action == "marriage" || action == "partner")
  814. _player->marriage = atoi(parseParams(it, tokens.end()).c_str());
  815. else if(action == "rates")
  816. _player->rates[atoi(parseParams(it, tokens.end()).c_str())] = atof(
  817. parseParams(it, tokens.end()).c_str());
  818. else if(action == "idle")
  819. _player->setIdleTime(atoi(parseParams(it, tokens.end()).c_str()));
  820. else if(action == "capacity" || action == "cap")
  821. _player->setCapacity(atoi(parseParams(it, tokens.end()).c_str()));
  822. else if(action == "execute")
  823. g_talkActions->onPlayerSay(_player, atoi(parseParams(it, tokens.end()).c_str()),
  824. parseParams(it, tokens.end()), booleanString(parseParams(it, tokens.end())));
  825. else if(action == "saving" || action == "save")
  826. _player->switchSaving();
  827. else
  828. {
  829. std::stringstream s;
  830. s << action << " (" << parseParams(it, tokens.end()) << ")";
  831. invalid += s.str();
  832. break;
  833. }
  834. }
  835. else
  836. {
  837. std::stringstream s;
  838. s << action << " (" << parseParams(it, tokens.end()) << ")";
  839. invalid += s.str();
  840. break;
  841. }
  842. }
  843. }
  844.  
  845. const SpectatorVec& list = g_game.getSpectators(pos);
  846. SpectatorVec::const_iterator it;
  847.  
  848. Player* tmpPlayer = NULL;
  849. for(it = list.begin(); it != list.end(); ++it)
  850. {
  851. if((tmpPlayer = (*it)->getPlayer()))
  852. tmpPlayer->sendUpdateTile(tile, pos);
  853. }
  854.  
  855. for(it = list.begin(); it != list.end(); ++it)
  856. (*it)->onUpdateTile(tile, pos);
  857.  
  858. g_game.addMagicEffect(pos, MAGIC_EFFECT_WRAPS_GREEN);
  859. if(invalid.empty())
  860. return true;
  861.  
  862. std::string tmp = "Following action was invalid: " + invalid;
  863. player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, tmp.c_str());
  864. return true;
  865. }
  866.  
  867. bool TalkAction::banishmentInfo(Creature* creature, const std::string& cmd, const std::string& param)
  868. {
  869. Player* player = creature->getPlayer();
  870. if(!player)
  871. return false;
  872.  
  873. StringVec params = explodeString(param, ",");
  874. std::string what = "Account";
  875. trimString(params[0]);
  876.  
  877. Ban ban;
  878. ban.type = BAN_ACCOUNT;
  879. if(params.size() > 1)
  880. {
  881. trimString(params[1]);
  882. if(params[0].substr(0, 1) == "p")
  883. {
  884. what = "Character";
  885. ban.type = BAN_PLAYER;
  886. ban.param = PLAYERBAN_BANISHMENT;
  887.  
  888. ban.value = atoi(params[1].c_str());
  889. if(!ban.value)
  890. {
  891. IOLoginData::getInstance()->getGuidByName(ban.value, params[1], true);
  892. if(!ban.value)
  893. ban.value = IOLoginData::getInstance()->getAccountIdByName(params[1]);
  894. }
  895. }
  896. else
  897. {
  898. ban.value = atoi(params[1].c_str());
  899. if(!ban.value)
  900. {
  901. IOLoginData::getInstance()->getAccountId(params[1], ban.value);
  902. if(!ban.value)
  903. ban.value = IOLoginData::getInstance()->getAccountIdByName(params[1]);
  904. }
  905. }
  906. }
  907. else
  908. {
  909. ban.value = atoi(params[0].c_str());
  910. if(!ban.value)
  911. {
  912. IOLoginData::getInstance()->getAccountId(params[0], ban.value);
  913. if(!ban.value)
  914. ban.value = IOLoginData::getInstance()->getAccountIdByName(params[0]);
  915. }
  916. }
  917.  
  918. if(!ban.value)
  919. {
  920. toLowerCaseString(what);
  921. player->sendCancel("Invalid " + what + (std::string)" name or id.");
  922. return true;
  923. }
  924.  
  925. if(!IOBan::getInstance()->getData(ban))
  926. {
  927. player->sendCancel("That player or account is not banished or deleted.");
  928. return true;
  929. }
  930.  
  931. bool deletion = ban.expires < 0;
  932. std::string admin = "Automatic ";
  933. if(!ban.adminId)
  934. admin += (deletion ? "deletion" : "banishment");
  935. else
  936. IOLoginData::getInstance()->getNameByGuid(ban.adminId, admin, true);
  937.  
  938. std::string end = "Banishment will be lifted at:\n";
  939. if(deletion)
  940. end = what + (std::string)" won't be undeleted";
  941.  
  942. char buffer[500 + ban.comment.length()];
  943. sprintf(buffer, "%s has been %s at:\n%s by: %s,\nfor the following reason:\n%s.\nThe action taken was:\n%s.\nThe comment given was:\n%s.\n%s%s.",
  944. what.c_str(), (deletion ? "deleted" : "banished"), formatDateShort(ban.added).c_str(), admin.c_str(), getReason(ban.reason).c_str(),
  945. getAction(ban.action, false).c_str(), ban.comment.c_str(), end.c_str(), (deletion ? "." : formatDateShort(ban.expires, true).c_str()));
  946.  
  947. player->sendFYIBox(buffer);
  948. return true;
  949. }
  950.  
  951. bool TalkAction::diagnostics(Creature* creature, const std::string& cmd, const std::string& param)
  952. {
  953. Player* player = creature->getPlayer();
  954. if(!player)
  955. return false;
  956.  
  957. return true;
  958. }
  959.  
  960. bool TalkAction::addSkill(Creature* creature, const std::string& cmd, const std::string& param)
  961. {
  962. Player* player = creature->getPlayer();
  963. if(!player)
  964. return false;
  965.  
  966. StringVec params = explodeString(param, ",");
  967. if(params.size() < 2)
  968. {
  969. player->sendTextMessage(MSG_STATUS_SMALL, "Command requires at least 2 parameters.");
  970. return true;
  971. }
  972.  
  973. uint32_t amount = 1;
  974. if(params.size() > 2)
  975. {
  976. std::string tmp = params[2];
  977. trimString(tmp);
  978. amount = (uint32_t)std::max(1, atoi(tmp.c_str()));
  979. }
  980.  
  981. std::string name = params[0], skill = params[1];
  982. trimString(name);
  983. trimString(skill);
  984.  
  985. Player* target = NULL;
  986. ReturnValue ret = g_game.getPlayerByNameWildcard(name, target);
  987. if(ret != RET_NOERROR)
  988. {
  989. player->sendCancelMessage(ret);
  990. return true;
  991. }
  992.  
  993. if(skill[0] == 'l' || skill[0] == 'e')
  994. target->addExperience(uint64_t(Player::getExpForLevel(target->getLevel() + amount) - target->getExperience()));
  995. else if(skill[0] == 'm')
  996. target->addManaSpent((uint64_t)(target->getVocation()->getReqMana(target->getMagicLevel() +
  997. amount) - target->getSpentMana()), false);
  998. else
  999. {
  1000. skills_t skillId = getSkillId(skill);
  1001. target->addSkillAdvance(skillId, (uint32_t)(target->getVocation()->getReqSkillTries(skillId, target->getSkill(skillId,
  1002. SKILL_LEVEL) + amount) - target->getSkill(skillId, SKILL_TRIES)), false);
  1003. }
  1004.  
  1005. return true;
  1006. }
  1007.  
  1008. bool TalkAction::ghost(Creature* creature, const std::string& cmd, const std::string& param)
  1009. {
  1010. Player* player = creature->getPlayer();
  1011. if(!player)
  1012. return false;
  1013.  
  1014. if(player->hasFlag(PlayerFlag_CannotBeSeen))
  1015. {
  1016. player->sendTextMessage(MSG_INFO_DESCR, "Command disabled for players with special, invisibility flag.");
  1017. return true;
  1018. }
  1019.  
  1020. SpectatorVec::iterator it;
  1021. SpectatorVec list = g_game.getSpectators(player->getPosition());
  1022. Player* tmpPlayer = NULL;
  1023.  
  1024. Condition* condition = NULL;
  1025. if((condition = player->getCondition(CONDITION_GAMEMASTER, CONDITIONID_DEFAULT, GAMEMASTER_INVISIBLE)))
  1026. {
  1027. player->sendTextMessage(MSG_INFO_DESCR, "You are visible again.");
  1028. IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), true);
  1029. for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
  1030. {
  1031. if(!pit->second->canSeeCreature(player))
  1032. pit->second->notifyLogIn(player);
  1033. }
  1034.  
  1035. for(it = list.begin(); it != list.end(); ++it)
  1036. {
  1037. if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
  1038. tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_TELEPORT);
  1039. }
  1040.  
  1041. player->removeCondition(condition);
  1042. g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_APPEAR);
  1043. }
  1044. else if((condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_GAMEMASTER, -1, 0, false, GAMEMASTER_INVISIBLE)))
  1045. {
  1046. player->addCondition(condition);
  1047. g_game.internalCreatureChangeVisible(creature, VISIBLE_GHOST_DISAPPEAR);
  1048. for(it = list.begin(); it != list.end(); ++it)
  1049. {
  1050. if((tmpPlayer = (*it)->getPlayer()) && !tmpPlayer->canSeeCreature(player))
  1051. tmpPlayer->sendMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1052. }
  1053.  
  1054. for(AutoList<Player>::iterator pit = Player::autoList.begin(); pit != Player::autoList.end(); ++pit)
  1055. {
  1056. if(!pit->second->canSeeCreature(player))
  1057. pit->second->notifyLogOut(player);
  1058. }
  1059.  
  1060. IOLoginData::getInstance()->updateOnlineStatus(player->getGUID(), false);
  1061. if(player->isTrading())
  1062. g_game.internalCloseTrade(player);
  1063.  
  1064. player->clearPartyInvitations();
  1065. if(player->getParty())
  1066. player->getParty()->leave(player);
  1067.  
  1068. player->sendTextMessage(MSG_INFO_DESCR, "You are now invisible.");
  1069. }
  1070.  
  1071. return true;
  1072. }
  1073.  
  1074. bool TalkAction::lootAdd(Creature* creature, const std::string& cmd, const std::string& param)
  1075. {
  1076. if(param.empty())
  1077. return true;
  1078.  
  1079. assert(creature);
  1080. Player* player = creature->getPlayer();
  1081. if(!player || player->isRemoved())
  1082. return true;
  1083.  
  1084. // if(!player->isPremium())
  1085. // {
  1086. // player->sendTextMessage(MSG_INFO_DESCR, "Only players with premium account can use this command.");
  1087. // g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1088. // return true;
  1089. // }
  1090.  
  1091. int32_t itemId = Item::items.getItemIdByName(param);
  1092. const ItemType* item = Item::items.getElement(itemId);
  1093. if(!item)
  1094. {
  1095. player->sendTextMessage(MSG_INFO_DESCR, "This item are not exist.");
  1096. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1097. return true;
  1098. }
  1099.  
  1100. std::string itemList;
  1101. player->getStorage(AUTOLOOT_STORAGE, itemList);
  1102. if(itemList == "-1")
  1103. itemList.clear();
  1104.  
  1105. if(!itemList.empty())
  1106. {
  1107. StringVec itemsList = explodeString(itemList, ";");
  1108. if(itemsList.size() >= (player->isPremium() ? 20 : 5))
  1109. {
  1110. player->sendTextMessage(MSG_INFO_DESCR, "You can't add more items to list.");
  1111. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1112. return true;
  1113. }
  1114.  
  1115. for(uint16_t i = 0; i < itemsList.size(); ++i)
  1116. {
  1117. if(atoi(itemsList[i].c_str()) == itemId)
  1118. {
  1119. player->sendTextMessage(MSG_INFO_DESCR, "You already have this item in your auto loot list.");
  1120. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1121. return true;
  1122. }
  1123. }
  1124. }
  1125.  
  1126. std::ostringstream itemVector;
  1127. itemVector << itemList << (itemList.empty() ? "" : ";") << itemId;
  1128.  
  1129. player->sendTextMessage(MSG_INFO_DESCR, "Your list are updated.");
  1130. player->setStorage(AUTOLOOT_STORAGE, itemVector.str());
  1131. return true;
  1132. }
  1133.  
  1134. bool TalkAction::lootRemove(Creature* creature, const std::string& cmd, const std::string& param)
  1135. {
  1136. if(param.empty())
  1137. return true;
  1138.  
  1139. assert(creature);
  1140. Player* player = creature->getPlayer();
  1141. if(!player || player->isRemoved())
  1142. return true;
  1143.  
  1144. // if(!player->isPremium())
  1145. // {
  1146. // player->sendTextMessage(MSG_INFO_DESCR, "Only players with premium account can use this command.");
  1147. // g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1148. // return true;
  1149. // }
  1150.  
  1151. if(param == "all")
  1152. {
  1153. player->setStorage(AUTOLOOT_STORAGE, "-1");
  1154. player->sendTextMessage(MSG_INFO_DESCR, "Your is cleared.");
  1155. }
  1156. else
  1157. {
  1158. int32_t itemId = Item::items.getItemIdByName(param);
  1159. const ItemType* item = Item::items.getElement(itemId);
  1160. if(!item)
  1161. {
  1162. player->sendTextMessage(MSG_INFO_DESCR, "This item is not exist.");
  1163. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1164. return true;
  1165. }
  1166.  
  1167. std::string itemList, newItemList;
  1168. player->getStorage(AUTOLOOT_STORAGE, itemList);
  1169. if(itemList == "-1")
  1170. itemList.clear();
  1171.  
  1172. if(itemList.empty())
  1173. {
  1174. player->sendTextMessage(MSG_INFO_DESCR, "Your list is empty.");
  1175. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1176. return true;
  1177. }
  1178.  
  1179. StringVec itemsList = explodeString(itemList, ";");
  1180. bool foundItem = false;
  1181. for(uint16_t i = 0; i < itemsList.size(); ++i)
  1182. {
  1183. if(atoi(itemsList[i].c_str()) == itemId)
  1184. {
  1185. foundItem = true;
  1186. continue;
  1187. }
  1188.  
  1189. newItemList += (newItemList.empty() ? "" : ";") + itemsList[i];
  1190. }
  1191.  
  1192. if(foundItem)
  1193. player->sendTextMessage(MSG_INFO_DESCR, "Your list is updated.");
  1194. else
  1195. player->sendTextMessage(MSG_INFO_DESCR, "You no have this item in your list.");
  1196.  
  1197. player->setStorage(AUTOLOOT_STORAGE, newItemList);
  1198. }
  1199.  
  1200. return true;
  1201. }
  1202.  
  1203. bool TalkAction::lootVision(Creature* creature, const std::string& cmd, const std::string& param)
  1204. {
  1205. assert(creature);
  1206. Player* player = creature->getPlayer();
  1207. if(!player || player->isRemoved())
  1208. return true;
  1209.  
  1210. // if(!player->isPremium())
  1211. // {
  1212. // player->sendTextMessage(MSG_INFO_DESCR, "Only players with premium account can use this command.");
  1213. // g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1214. // return true;
  1215. // }
  1216.  
  1217. std::string itemList;
  1218. player->getStorage(AUTOLOOT_STORAGE, itemList);
  1219. if(itemList == "-1")
  1220. itemList.clear();
  1221.  
  1222. if(itemList.empty())
  1223. {
  1224. player->sendTextMessage(MSG_INFO_DESCR, "Your list are empty.");
  1225. g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
  1226. return true;
  1227. }
  1228.  
  1229. std::ostringstream message;
  1230. StringVec itemsList = explodeString(itemList, ";");
  1231. for(uint16_t i = 0; i < itemsList.size(); ++i)
  1232. {
  1233. const ItemType* item = Item::items.getElement(atoi(itemsList[i].c_str()));
  1234. if(!item)
  1235. continue;
  1236.  
  1237. message << (message.str().empty() ? "" : "\n") << item->name;
  1238. }
  1239.  
  1240. player->sendFYIBox(message.str());
  1241. return true;
  1242. }
  1243.  
  1244. bool TalkAction::autoHeal(Creature* creature, const std::string& cmd, const std::string& param)
  1245. {
  1246. Player* player = creature->getPlayer();
  1247. if(!player)
  1248. return false;
  1249.  
  1250. if(param.empty())
  1251. return false;
  1252.  
  1253. StringVec autoHeal = explodeString(param, ",");
  1254. if(autoHeal.size() < 3)
  1255. return false;
  1256.  
  1257. std::string name = asLowerCaseString(autoHeal[0]);
  1258. uint16_t id = 0;
  1259. AutoHealPriority_t priority = PRIORITY_STATUS_NONE;
  1260. if(name == "herowater")
  1261. {
  1262. id = 11372;
  1263. priority = PRIORITY_STATUS_LOW;
  1264. }
  1265. else if(name == "premiumherowater")
  1266. {
  1267. id = 11373;
  1268. priority = PRIORITY_STATUS_MEDIUM;
  1269. }
  1270. else if(name == "pill")
  1271. {
  1272. id = 11394;
  1273. priority = PRIORITY_STATUS_HIGH;
  1274. }
  1275. else if(name == "sake")
  1276. {
  1277. id = 11393;
  1278. priority = PRIORITY_STATUS_TOP;
  1279. }
  1280.  
  1281. if(id == 0)
  1282. return false;
  1283.  
  1284. std::string type = autoHeal[1];
  1285. AutoHealMode_t mode = HEAL_STATUS_NONE;
  1286. if(type == "health" || type == "hp")
  1287. mode = HEAL_STATUS_HEALTH;
  1288. else if(type == "mana" || type == "mp")
  1289. mode = HEAL_STATUS_MANA;
  1290.  
  1291. if(mode == HEAL_STATUS_NONE)
  1292. return false;
  1293.  
  1294. uint16_t value = atoi(autoHeal[2].c_str());
  1295. if(value > 100)
  1296. value = 100;
  1297.  
  1298. AutoHealVector autoHealVector = player->getAutoHealVector();
  1299. if(autoHealVector.empty())
  1300. autoHealVector.push_back(AutoHeal_t(id, value, priority, mode));
  1301. else
  1302. {
  1303. bool found = false;
  1304. for(AutoHealVector::iterator it = autoHealVector.begin(); it != autoHealVector.end(); ++it)
  1305. {
  1306. if((*it).id == id)
  1307. {
  1308. (*it).health = value;
  1309. (*it).status = mode;
  1310. found = true;
  1311. break;
  1312. }
  1313. }
  1314.  
  1315. if(!found)
  1316. autoHealVector.push_back(AutoHeal_t(id, value, priority, mode));
  1317. }
  1318.  
  1319. std::ostringstream stringValue;
  1320. for(AutoHealVector::iterator it = autoHealVector.begin(); it != autoHealVector.end(); ++it)
  1321. {
  1322. if(!stringValue.str().empty())
  1323. stringValue << ",";
  1324.  
  1325. stringValue << (*it).id << "," << (*it).health << "," << (*it).priority << "," << (*it).status;
  1326. }
  1327.  
  1328. player->setStorage(AUTO_HEAL_STORAGE, stringValue.str());
  1329. player->setAutoHealVector(autoHealVector);
  1330. return true;
  1331. }
Advertisement
Add Comment
Please, Sign In to add comment