Fix character selection

- Fix an issue allowing you to select taken characters
- Fix a regression of #64

Co-Authored-By: Cerapter <43446478+Cerapter@users.noreply.github.com>
This commit is contained in:
MangosArentLiterature 2021-06-02 16:17:07 -05:00
parent 17ab971e85
commit 44519c0db3
3 changed files with 31 additions and 16 deletions

View File

@ -113,7 +113,7 @@ void AOClient::changeArea(int new_area)
}
if (current_char != "") {
server->areas[current_area]->charactersTaken().removeAll(server->getCharID(current_char));
server->areas[current_area]->changeCharacter(server->getCharID(current_char), -1);
server->updateCharsTaken(server->areas[current_area]);
}
server->areas[new_area]->clientJoinedArea(char_id);
@ -130,7 +130,7 @@ void AOClient::changeArea(int new_area)
sendPacket("DONE");
}
else {
server->areas[current_area]->charactersTaken().append(server->getCharID(current_char));
server->areas[current_area]->changeCharacter(-1, server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]);
}
for (QTimer* timer : server->areas[current_area]->timers()) {
@ -161,18 +161,19 @@ bool AOClient::changeCharacter(int char_id)
bool l_successfulChange = area->changeCharacter(server->getCharID(current_char), char_id);
current_char = "";
if (l_successfulChange) {
QString char_selected = server->characters[char_id];
current_char = char_selected;
if (char_id < 0) {
current_char = "";
}
pos = "";
server->updateCharsTaken(area);
sendPacket("PV", {QString::number(id), "CID", QString::number(char_id)});
return true;
if (l_successfulChange == true) {
QString char_selected = server->characters[char_id];
current_char = char_selected;
pos = "";
server->updateCharsTaken(area);
sendPacket("PV", {QString::number(id), "CID", QString::number(char_id)});
return true;
}
return false;
}
void AOClient::changePosition(QString new_pos)

View File

@ -210,19 +210,22 @@ QList<int> AreaData::charactersTaken() const
bool AreaData::changeCharacter(int f_from, int f_to)
{
if (f_from != -1) {
m_charactersTaken.removeAll(f_from);
}
if (m_charactersTaken.contains(f_to)) {
return false;
}
if (f_to != -1) {
if (f_from != -1) {
m_charactersTaken.removeAll(f_from);
}
m_charactersTaken.append(f_to);
return true;
}
if (f_to == -1 && f_from != -1) {
m_charactersTaken.removeAll(f_from);
}
return false;
}

View File

@ -177,6 +177,17 @@ void Area::changeCharacter()
QCOMPARE(m_area->charactersTaken().at(0), 7);
QCOMPARE(m_area->charactersTaken().at(1), 8);
}
{
// Client attempts to switch to 7.
// Nothing changes, as it is already taken.
m_area->changeCharacter(8, 7);
QCOMPARE(m_area->playerCount(), 1);
QCOMPARE(m_area->charactersTaken().size(), 2);
QCOMPARE(m_area->charactersTaken().at(0), 7);
QCOMPARE(m_area->charactersTaken().at(1), 8);
}
{
// Charid 7 is unlocked for use.
// Charid 8 is taken.