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:
parent
17ab971e85
commit
44519c0db3
@ -113,7 +113,7 @@ void AOClient::changeArea(int new_area)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (current_char != "") {
|
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->updateCharsTaken(server->areas[current_area]);
|
||||||
}
|
}
|
||||||
server->areas[new_area]->clientJoinedArea(char_id);
|
server->areas[new_area]->clientJoinedArea(char_id);
|
||||||
@ -130,7 +130,7 @@ void AOClient::changeArea(int new_area)
|
|||||||
sendPacket("DONE");
|
sendPacket("DONE");
|
||||||
}
|
}
|
||||||
else {
|
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]);
|
server->updateCharsTaken(server->areas[current_area]);
|
||||||
}
|
}
|
||||||
for (QTimer* timer : server->areas[current_area]->timers()) {
|
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);
|
bool l_successfulChange = area->changeCharacter(server->getCharID(current_char), char_id);
|
||||||
|
|
||||||
current_char = "";
|
if (char_id < 0) {
|
||||||
|
current_char = "";
|
||||||
if (l_successfulChange) {
|
|
||||||
QString char_selected = server->characters[char_id];
|
|
||||||
current_char = char_selected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = "";
|
if (l_successfulChange == true) {
|
||||||
|
QString char_selected = server->characters[char_id];
|
||||||
server->updateCharsTaken(area);
|
current_char = char_selected;
|
||||||
sendPacket("PV", {QString::number(id), "CID", QString::number(char_id)});
|
pos = "";
|
||||||
return true;
|
server->updateCharsTaken(area);
|
||||||
|
sendPacket("PV", {QString::number(id), "CID", QString::number(char_id)});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOClient::changePosition(QString new_pos)
|
void AOClient::changePosition(QString new_pos)
|
||||||
|
@ -210,19 +210,22 @@ QList<int> AreaData::charactersTaken() const
|
|||||||
|
|
||||||
bool AreaData::changeCharacter(int f_from, int f_to)
|
bool AreaData::changeCharacter(int f_from, int f_to)
|
||||||
{
|
{
|
||||||
if (f_from != -1) {
|
|
||||||
m_charactersTaken.removeAll(f_from);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_charactersTaken.contains(f_to)) {
|
if (m_charactersTaken.contains(f_to)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f_to != -1) {
|
if (f_to != -1) {
|
||||||
|
if (f_from != -1) {
|
||||||
|
m_charactersTaken.removeAll(f_from);
|
||||||
|
}
|
||||||
m_charactersTaken.append(f_to);
|
m_charactersTaken.append(f_to);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (f_to == -1 && f_from != -1) {
|
||||||
|
m_charactersTaken.removeAll(f_from);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +177,17 @@ void Area::changeCharacter()
|
|||||||
QCOMPARE(m_area->charactersTaken().at(0), 7);
|
QCOMPARE(m_area->charactersTaken().at(0), 7);
|
||||||
QCOMPARE(m_area->charactersTaken().at(1), 8);
|
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 7 is unlocked for use.
|
||||||
// Charid 8 is taken.
|
// Charid 8 is taken.
|
||||||
|
Loading…
Reference in New Issue
Block a user