本文整理汇总了C++中Portal::nameFromRoom方法的典型用法代码示例。如果您正苦于以下问题:C++ Portal::nameFromRoom方法的具体用法?C++ Portal::nameFromRoom怎么用?C++ Portal::nameFromRoom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portal
的用法示例。
在下文中一共展示了Portal::nameFromRoom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void CommandInterpreter::execute(Character *character, const QString &_command) {
static QRegExp whitespace("\\s+");
try {
QString command = _command.trimmed();
LogUtil::logCommand(character->name(), command);
QStringList words = command.split(whitespace);
QString commandName = words[0].toLower();
if (commandName.isEmpty()) {
return;
}
if (Util::isDirectionAbbreviation(commandName)) {
words[0] = Util::direction(commandName);
commandName = words[0];
}
if (Util::isDirection(commandName)) {
words.prepend("go");
m_registry->command("go")->execute(character, words.join(" "));
return;
} else {
Room *currentRoom = character->currentRoom().cast<Room *>();
bool matchedPortal = false;
for (const GameObjectPtr &portalPtr : currentRoom->portals()) {
Portal *portal = portalPtr.cast<Portal *>();
QString portalName = portal->nameFromRoom(character->currentRoom());
if (portalName == commandName) {
matchedPortal = true;
} else {
for (const QString &portalNamePart : portalName.split(' ')) {
if (portalNamePart == commandName) {
matchedPortal = true;
}
}
}
}
if (matchedPortal) {
words.prepend("go");
m_registry->command("go")->execute(character, words.join(" "));
return;
}
}
QStringList commands;
if (m_registry->contains(commandName)) {
m_registry->command(commandName)->execute(character, command);
return;
} else {
for (const QString &name : m_registry->commandNames()) {
if (name.startsWith(commandName)) {
commands.append(name);
}
}
}
if (character->isPlayer() && qobject_cast<Player *>(character)->isAdmin()) {
if (commandName.startsWith("api-")) {
if (m_registry->apiCommandsContains(commandName)) {
m_registry->apiCommand(commandName)->execute(character, command);
return;
}
} else {
if (m_registry->adminCommandsContains(commandName)) {
m_registry->adminCommand(commandName)->execute(character, command);
return;
} else {
for (const QString &name : m_registry->adminCommandNames()) {
if (name.startsWith(commandName)) {
commands.append(name);
}
}
}
}
}
if (commands.length() == 1) {
commandName = commands[0];
if (m_registry->contains(commandName)) {
m_registry->command(commandName)->execute(character, command);
} else if (m_registry->adminCommandsContains(commandName)) {
m_registry->adminCommand(commandName)->execute(character, command);
}
} else if (commands.length() > 1) {
character->send("Command is not unique.");
} else {
character->send(QString("Command \"%1\" does not exist.").arg(words[0]));
}
} catch (GameException &exception) {
if (character->isPlayer()) {
Player *player = qobject_cast<Player *>(character);
player->send(QString("Executing the command gave an exception: ") + exception.what());
if (!player->isAdmin()) {
player->send("This is not good. You may want to contact a game admin about this.");
}
}
} catch (...) {
if (character->isPlayer()) {
//.........这里部分代码省略.........