fix card moving on server (#4413)

* wip fix card moving on server

* fix flipped cards being moved as -1
This commit is contained in:
ebbit1q 2021-09-14 21:48:46 +02:00 committed by GitHub
parent affc288144
commit c25bf491e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 132 deletions

View file

@ -44,6 +44,8 @@ Server_CardZone::~Server_CardZone()
void Server_CardZone::shuffle(int start, int end)
{
cardsBeingLookedAt = 0;
// Size 0 or 1 decks are sorted
if (cards.size() < 2)
return;
@ -121,11 +123,22 @@ void Server_CardZone::insertCardIntoCoordMap(Server_Card *card, int x, int y)
}
int Server_CardZone::removeCard(Server_Card *card)
{
bool wasLookedAt;
return removeCard(card, wasLookedAt);
}
int Server_CardZone::removeCard(Server_Card *card, bool &wasLookedAt)
{
int index = cards.indexOf(card);
wasLookedAt = isCardAtPosLookedAt(index);
if (wasLookedAt && cardsBeingLookedAt > 0) {
cardsBeingLookedAt -= 1;
}
cards.removeAt(index);
if (has_coords)
if (has_coords) {
removeCardFromCoordMap(card, card->getX(), card->getY());
}
card->setZone(nullptr);
return index;
@ -161,6 +174,11 @@ Server_Card *Server_CardZone::getCard(int id, int *position, bool remove)
}
}
bool Server_CardZone::isCardAtPosLookedAt(int pos) const
{
return type == ServerInfo_Zone::HiddenZone && (cardsBeingLookedAt == -1 || cardsBeingLookedAt > pos);
}
int Server_CardZone::getFreeGridColumn(int x, int y, const QString &cardName, bool dontStackSameName) const
{
const QMap<int, Server_Card *> &coordMap = coordinateMap.value(y);
@ -274,10 +292,11 @@ void Server_CardZone::insertCard(Server_Card *card, int x, int y)
insertCardIntoCoordMap(card, x, y);
} else {
card->setCoords(0, 0);
if (x == -1)
if (x == -1) {
cards.append(card);
else
} else {
cards.insert(x, card);
}
}
card->setZone(this);
}
@ -291,6 +310,7 @@ void Server_CardZone::clear()
freePilesMap.clear();
freeSpaceMap.clear();
playersWithWritePermission.clear();
cardsBeingLookedAt = 0;
}
void Server_CardZone::addWritePermission(int playerId)