Merge pull request #28 from AttorneyOnline/fix/characters-taken

Fix characters not being correctly marked as taken
This commit is contained in:
in1tiate 2021-03-11 21:44:44 -06:00 committed by GitHub
commit 027876a6ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 18 deletions

View File

@ -31,7 +31,7 @@ class Logger;
class AreaData : public QObject {
Q_OBJECT
public:
AreaData(QStringList p_characters, QString p_name, int p_index);
AreaData(QString p_name, int p_index);
struct Evidence {
QString name;
@ -41,7 +41,7 @@ class AreaData : public QObject {
QList<QTimer*> timers;
QString name;
int index;
QMap<QString, bool> characters_taken;
QList<int> characters_taken;
QList<Evidence> evidence;
int player_count;
enum Status {

View File

@ -64,8 +64,7 @@ void AOClient::clientDisconnected()
arup(ARUPType::PLAYER_COUNT, true);
}
if (current_char != "") {
server->areas[current_area]->characters_taken[current_char] =
false;
server->areas[current_area]->characters_taken.removeAll(server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]);
}
bool update_locks;
@ -116,8 +115,7 @@ void AOClient::changeArea(int new_area)
}
if (current_char != "") {
server->areas[current_area]->characters_taken[current_char] =
false;
server->areas[current_area]->characters_taken.removeAll(server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]);
}
server->areas[new_area]->player_count++;
@ -128,13 +126,13 @@ void AOClient::changeArea(int new_area)
sendPacket("HP", {"1", QString::number(server->areas[new_area]->def_hp)});
sendPacket("HP", {"2", QString::number(server->areas[new_area]->pro_hp)});
sendPacket("BN", {server->areas[new_area]->background});
if (server->areas[current_area]->characters_taken[current_char]) {
if (server->areas[current_area]->characters_taken.contains(server->getCharID(current_char))) {
server->updateCharsTaken(server->areas[current_area]);
current_char = "";
sendPacket("DONE");
}
else {
server->areas[current_area]->characters_taken[current_char] = true;
server->areas[current_area]->characters_taken.append(server->getCharID(current_char));
server->updateCharsTaken(server->areas[current_area]);
}
for (QTimer* timer : server->areas[current_area]->timers) {
@ -157,7 +155,7 @@ void AOClient::changeCharacter(int char_id)
AreaData* area = server->areas[current_area];
if (current_char != "") {
area->characters_taken[current_char] = false;
area->characters_taken.removeAll(server->getCharID(current_char));
}
if(char_id > server->characters.length())
@ -165,11 +163,11 @@ void AOClient::changeCharacter(int char_id)
if (char_id >= 0) {
QString char_selected = server->characters[char_id];
bool taken = area->characters_taken.value(char_selected);
bool taken = area->characters_taken.contains(char_id);
if (taken || char_selected == "")
return;
area->characters_taken[char_selected] = true;
area->characters_taken.append(char_id);
current_char = char_selected;
}
else {

View File

@ -17,13 +17,10 @@
//////////////////////////////////////////////////////////////////////////////////////
#include "include/area_data.h"
AreaData::AreaData(QStringList characters, QString p_name, int p_index)
AreaData::AreaData(QString p_name, int p_index)
{
name = p_name;
index = p_index;
for (QString cur_char : characters) {
characters_taken.insert(cur_char, false);
}
QSettings areas_ini("config/areas.ini", QSettings::IniFormat);
areas_ini.beginGroup(p_name);
background = areas_ini.value("background", "gs4").toString();

View File

@ -91,7 +91,7 @@ void Server::start()
area_names = sanitized_area_names;
for (int i = 0; i < area_names.length(); i++) {
QString area_name = area_names[i];
areas.insert(i, new AreaData(characters, area_name, i));
areas.insert(i, new AreaData(area_name, i));
}
}
@ -139,8 +139,8 @@ void Server::clientConnected()
void Server::updateCharsTaken(AreaData* area)
{
QStringList chars_taken;
for (QString cur_char : area->characters_taken.keys()) {
chars_taken.append(area->characters_taken.value(cur_char)
for (QString cur_char : characters) {
chars_taken.append(area->characters_taken.contains(getCharID(cur_char))
? QStringLiteral("-1")
: QStringLiteral("0"));
}