bool TalkActions::registerEvent(Event* event, xmlNodePtr p) { TalkAction* talkAction = dynamic_cast<TalkAction*>(event); if(!talkAction) return false; wordsMap.push_back(std::make_pair(talkAction->getWords(), talkAction)); return true; }
bool TalkActions::registerEvent(Event* event, const pugi::xml_node& node) { TalkAction* talkAction = dynamic_cast<TalkAction*>(event); if (!talkAction) { return false; } wordsMap.emplace_back(talkAction->getWords(), talkAction); return true; }
TalkActionResult_t TalkActions::playerSaySpell(Player* player, SpeakClasses type, const std::string& words) { if (type != SPEAK_SAY) { return TALKACTION_CONTINUE; } std::string str_words; std::string str_param; size_t loc = words.find('"', 0); if (loc != std::string::npos) { str_words = std::string(words, 0, loc); str_param = std::string(words, (loc + 1), words.size() - loc - 1); } else { str_words = words; str_param = std::string(""); } trim_left(str_words, " "); trim_right(str_words, " "); TalkActionList::iterator it; for (it = wordsMap.begin(); it != wordsMap.end(); ++it) { if (it->first == str_words) { TalkAction* talkAction = it->second; int32_t ret = talkAction->executeSay(player, str_words, str_param); if (ret == 1) { return TALKACTION_CONTINUE; } else { return TALKACTION_BREAK; } } } return TALKACTION_CONTINUE; }
TalkActionResult_t TalkActions::onPlayerSpeak(Player* player, SpeakClasses type, const std::string& words) { if(type != SPEAK_SAY){ return TALKACTION_CONTINUE; } std::string str_words_quote; std::string str_param_quote; std::string str_words_first_word; std::string str_param_first_word; // With quotation filtering size_t loc = words.find( '"', 0 ); if(loc != std::string::npos && loc >= 0){ str_words_quote = std::string(words, 0, loc); str_param_quote = std::string(words, (loc+1), words.size()-loc-1); } else { str_words_quote = words; str_param_quote = std::string(""); } trim_left(str_words_quote, " "); trim_right(str_param_quote, " "); // With whitespace filtering loc = words.find( ' ', 0 ); if(loc != std::string::npos && loc >= 0){ str_words_first_word = std::string(words, 0, loc); str_param_first_word = std::string(words, (loc+1), words.size()-loc-1); } else { str_words_first_word = words; str_param_first_word = std::string(""); } TalkActionList::iterator it; for(it = wordsMap.begin(); it != wordsMap.end(); ++it){ std::string cmdstring; std::string paramstring; if(it->second->getFilterType() == TALKACTION_MATCH_QUOTATION) { cmdstring = str_words_quote; paramstring = str_param_quote; } else if(it->second->getFilterType() == TALKACTION_MATCH_FIRST_WORD) { cmdstring = str_words_first_word; paramstring = str_param_first_word; } else { continue; } if(cmdstring == it->first || (!it->second->isCaseSensitive() && boost::algorithm::iequals(it->first, cmdstring))) { bool ret = true; if(player->getAccessLevel() < it->second->getAccessLevel()){ if(player->getAccessLevel() > 0){ player->sendTextMessage(MSG_STATUS_SMALL, "You can not execute this command."); ret = false; } } else{ TalkAction* talkAction = it->second; if(talkAction->isScripted()){ ret = talkAction->executeSay(player, cmdstring, paramstring); } else{ TalkActionFunction* func = talkAction->getFunction(); if(func){ func(player, cmdstring, paramstring); ret = false; } } } if(ret){ return TALKACTION_CONTINUE; } else{ return TALKACTION_BREAK; } } } return TALKACTION_CONTINUE; }