Merge pull request #85 from AttorneyOnline/switch-fix

Fix /switch and /randomchar
This commit is contained in:
Marisa P 2021-04-18 15:32:42 -05:00 committed by GitHub
commit 5b4b2d127e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 7 deletions

View File

@ -1298,8 +1298,6 @@ class AOClient : public QObject {
*
* @details No arguments.
*
* Can silently "fail" if the character picked is already being used by another client.
*
* @iscommand
*/
void cmdRandomChar(int argc, QStringList argv);

View File

@ -82,18 +82,33 @@ void AOClient::cmdNeed(int argc, QStringList argv)
void AOClient::cmdSwitch(int argc, QStringList argv)
{
int char_id = server->getCharID(argv.join(" "));
if (char_id == -1) {
int selected_char_id = server->getCharID(argv.join(" "));
if (selected_char_id == -1) {
sendServerMessage("That does not look like a valid character.");
return;
}
changeCharacter(char_id);
if (changeCharacter(selected_char_id)) {
char_id = selected_char_id;
}
else {
sendServerMessage("The character you picked is either taken or invalid.");
}
}
void AOClient::cmdRandomChar(int argc, QStringList argv)
{
int char_id = genRand(0, server->characters.size() - 1);
changeCharacter(char_id);
AreaData* area = server->areas[current_area];
int selected_char_id;
bool taken = true;
while (taken) {
selected_char_id = genRand(0, server->characters.size() - 1);
if (!area->characters_taken.contains(selected_char_id)) {
taken = false;
}
}
if (changeCharacter(selected_char_id)) {
char_id = selected_char_id;
}
}
void AOClient::cmdToggleGlobal(int argc, QStringList argv)