rework characters_taken to be a QList<int>

This commit is contained in:
in1tiate 2021-03-11 20:09:04 -06:00
parent eba21d9108
commit ee9ae6d7c6
4 changed files with 13 additions and 18 deletions

View File

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

View File

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

View File

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

View File

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